Skip to content

Commit 74b151e

Browse files
[silabs] reworked main.cpp (project-chip#32667)
* reworked silabs main.cpp to follow template. Moved functionality to matterconfig.cpp * restryled * restryled * minor fixes * minor fixes * using blank namespace for application_start() function * restyled * restyled * restyled
1 parent 04251f1 commit 74b151e

File tree

5 files changed

+76
-78
lines changed

5 files changed

+76
-78
lines changed

examples/platform/silabs/MatterConfig.cpp

+68-4
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,6 @@
4646
#include "wfx_rsi.h"
4747
#endif /* SLI_SI91X_MCU_INTERFACE */
4848

49-
using namespace ::chip;
50-
using namespace ::chip::Inet;
51-
using namespace ::chip::DeviceLayer;
52-
5349
#include <crypto/CHIPCryptoPAL.h>
5450
// If building with the EFR32-provided crypto backend, we can use the
5551
// opaque keystore
@@ -75,6 +71,36 @@ static chip::DeviceLayer::Internal::Efr32PsaOperationalKeystore gOperationalKeys
7571
#include <performance_test_commands.h>
7672
#endif
7773

74+
#include <AppTask.h>
75+
76+
#include <DeviceInfoProviderImpl.h>
77+
#include <app/server/Server.h>
78+
#include <credentials/DeviceAttestationCredsProvider.h>
79+
#include <examples/platform/silabs/SilabsDeviceAttestationCreds.h>
80+
81+
#include <platform/silabs/platformAbstraction/SilabsPlatform.h>
82+
83+
#include "FreeRTOSConfig.h"
84+
#include "event_groups.h"
85+
#include "task.h"
86+
87+
/**********************************************************
88+
* Defines
89+
*********************************************************/
90+
91+
#define MAIN_TASK_STACK_SIZE (1024 * 5)
92+
#define MAIN_TASK_PRIORITY (configMAX_PRIORITIES - 1)
93+
94+
using namespace ::chip;
95+
using namespace ::chip::Inet;
96+
using namespace ::chip::DeviceLayer;
97+
using namespace ::chip::Credentials::Silabs;
98+
using namespace chip::DeviceLayer::Silabs;
99+
100+
TaskHandle_t main_Task;
101+
volatile int apperror_cnt;
102+
static chip::DeviceLayer::DeviceInfoProviderImpl gExampleDeviceInfoProvider;
103+
78104
#if CHIP_ENABLE_OPENTHREAD
79105
#include <inet/EndPointStateOpenThread.h>
80106
#include <openthread/cli.h>
@@ -129,6 +155,44 @@ CHIP_ERROR SilabsMatterConfig::InitOpenThread(void)
129155
}
130156
#endif // CHIP_ENABLE_OPENTHREAD
131157

158+
namespace {
159+
void application_start(void * unused)
160+
{
161+
CHIP_ERROR err = SilabsMatterConfig::InitMatter(BLE_DEV_NAME);
162+
if (err != CHIP_NO_ERROR)
163+
appError(err);
164+
165+
gExampleDeviceInfoProvider.SetStorageDelegate(&chip::Server::GetInstance().GetPersistentStorage());
166+
chip::DeviceLayer::SetDeviceInfoProvider(&gExampleDeviceInfoProvider);
167+
168+
chip::DeviceLayer::PlatformMgr().LockChipStack();
169+
// Initialize device attestation config
170+
SetDeviceAttestationCredentialsProvider(Credentials::Silabs::GetSilabsDacProvider());
171+
chip::DeviceLayer::PlatformMgr().UnlockChipStack();
172+
173+
SILABS_LOG("Starting App Task");
174+
err = AppTask::GetAppTask().StartAppTask();
175+
if (err != CHIP_NO_ERROR)
176+
appError(err);
177+
178+
vTaskDelete(main_Task);
179+
}
180+
} // namespace
181+
182+
void SilabsMatterConfig::AppInit()
183+
{
184+
GetPlatform().Init();
185+
186+
xTaskCreate(application_start, "main_task", MAIN_TASK_STACK_SIZE, NULL, MAIN_TASK_PRIORITY, &main_Task);
187+
SILABS_LOG("Starting scheduler");
188+
GetPlatform().StartScheduler();
189+
190+
// Should never get here.
191+
chip::Platform::MemoryShutdown();
192+
SILABS_LOG("Start Scheduler Failed");
193+
appError(CHIP_ERROR_INTERNAL);
194+
}
195+
132196
#if SILABS_OTA_ENABLED
133197
void SilabsMatterConfig::InitOTARequestorHandler(System::Layer * systemLayer, void * appState)
134198
{

examples/platform/silabs/MatterConfig.h

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class SilabsMatterConfig
2626
{
2727
public:
2828
static CHIP_ERROR InitMatter(const char * appName);
29+
static void AppInit();
2930

3031
private:
3132
static CHIP_ERROR InitOpenThread(void);

examples/platform/silabs/main.cpp

+7-68
Original file line numberDiff line numberDiff line change
@@ -16,77 +16,16 @@
1616
* See the License for the specific language governing permissions and
1717
* limitations under the License.
1818
*/
19-
20-
#include <AppTask.h>
21-
22-
#include "AppConfig.h"
23-
24-
#include <DeviceInfoProviderImpl.h>
19+
#include "sl_component_catalog.h"
20+
#include "sl_system_init.h"
21+
#include "sl_system_kernel.h"
2522
#include <MatterConfig.h>
26-
#include <app/server/Server.h>
27-
#include <credentials/DeviceAttestationCredsProvider.h>
28-
#include <examples/platform/silabs/SilabsDeviceAttestationCreds.h>
29-
30-
#include <platform/silabs/platformAbstraction/SilabsPlatform.h>
31-
32-
#include "FreeRTOS.h"
33-
#include "FreeRTOSConfig.h"
34-
#include "event_groups.h"
35-
#include "task.h"
36-
37-
/**********************************************************
38-
* Defines
39-
*********************************************************/
40-
41-
#define MAIN_TASK_STACK_SIZE (1024 * 5)
42-
#define MAIN_TASK_PRIORITY (configMAX_PRIORITIES - 1)
43-
44-
using namespace ::chip;
45-
using namespace ::chip::DeviceLayer;
46-
using namespace ::chip::Credentials;
47-
using namespace chip::DeviceLayer::Silabs;
48-
49-
TaskHandle_t main_Task;
50-
void application_start(void * unused);
51-
volatile int apperror_cnt;
52-
static chip::DeviceLayer::DeviceInfoProviderImpl gExampleDeviceInfoProvider;
5323

54-
// ================================================================================
55-
// Main Code
56-
// ================================================================================
5724
int main(void)
5825
{
59-
GetPlatform().Init();
60-
61-
xTaskCreate(application_start, "main_task", MAIN_TASK_STACK_SIZE, NULL, MAIN_TASK_PRIORITY, &main_Task);
62-
63-
SILABS_LOG("Starting scheduler");
64-
GetPlatform().StartScheduler();
65-
66-
// Should never get here.
67-
chip::Platform::MemoryShutdown();
68-
SILABS_LOG("vTaskStartScheduler() failed");
69-
appError(CHIP_ERROR_INTERNAL);
70-
}
71-
72-
void application_start(void * unused)
73-
{
74-
CHIP_ERROR err = SilabsMatterConfig::InitMatter(BLE_DEV_NAME);
75-
if (err != CHIP_NO_ERROR)
76-
appError(err);
77-
78-
gExampleDeviceInfoProvider.SetStorageDelegate(&chip::Server::GetInstance().GetPersistentStorage());
79-
chip::DeviceLayer::SetDeviceInfoProvider(&gExampleDeviceInfoProvider);
80-
81-
chip::DeviceLayer::PlatformMgr().LockChipStack();
82-
// Initialize device attestation config
83-
SetDeviceAttestationCredentialsProvider(Credentials::Silabs::GetSilabsDacProvider());
84-
chip::DeviceLayer::PlatformMgr().UnlockChipStack();
85-
86-
SILABS_LOG("Starting App Task");
87-
err = AppTask::GetAppTask().StartAppTask();
88-
if (err != CHIP_NO_ERROR)
89-
appError(err);
26+
sl_system_init();
9027

91-
vTaskDelete(main_Task);
28+
// Initialize the application. For example, create periodic timer(s) or
29+
// task(s) if the kernel is present.
30+
SilabsMatterConfig::AppInit();
9231
}

src/platform/silabs/platformAbstraction/GsdkSpam.cpp

-3
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ extern "C" {
4444

4545
#include "sl_component_catalog.h"
4646
#include "sl_mbedtls.h"
47-
#include "sl_system_init.h"
4847
#if SILABS_LOG_OUT_UART || ENABLE_CHIP_SHELL || CHIP_DEVICE_CONFIG_THREAD_ENABLE_CLI
4948
#include "uart.h"
5049
#endif
@@ -68,8 +67,6 @@ SilabsPlatform::SilabsButtonCb SilabsPlatform::mButtonCallback = nullptr;
6867

6968
CHIP_ERROR SilabsPlatform::Init(void)
7069
{
71-
sl_system_init();
72-
7370
mRebootCause = RMU_ResetCauseGet();
7471
// Clear register so it does accumualate the causes of each reset
7572
RMU_ResetCauseClear();

src/platform/silabs/platformAbstraction/WiseMcuSpam.cpp

-3
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ extern "C" {
3131
#include "sl_event_handler.h"
3232
#include "sl_si91x_led.h"
3333
#include "sl_si91x_led_config.h"
34-
#include "sl_system_init.h"
3534
void soc_pll_config(void);
3635
}
3736

@@ -50,8 +49,6 @@ CHIP_ERROR SilabsPlatform::Init(void)
5049
{
5150
mButtonCallback = nullptr;
5251

53-
sl_system_init();
54-
5552
// TODO: Setting the highest priority for SVCall_IRQn to avoid the HardFault issue
5653
NVIC_SetPriority(SVCall_IRQn, CORE_INTERRUPT_HIGHEST_PRIORITY);
5754

0 commit comments

Comments
 (0)