diff --git a/examples/platform/silabs/MatterConfig.cpp b/examples/platform/silabs/MatterConfig.cpp index dd2368f566d252..d2e7fa89a9fe06 100644 --- a/examples/platform/silabs/MatterConfig.cpp +++ b/examples/platform/silabs/MatterConfig.cpp @@ -46,10 +46,6 @@ #include "wfx_rsi.h" #endif /* SLI_SI91X_MCU_INTERFACE */ -using namespace ::chip; -using namespace ::chip::Inet; -using namespace ::chip::DeviceLayer; - #include // If building with the EFR32-provided crypto backend, we can use the // opaque keystore @@ -75,6 +71,37 @@ static chip::DeviceLayer::Internal::Efr32PsaOperationalKeystore gOperationalKeys #include #endif +#include + +#include +#include +#include +#include + +#include + +#include "FreeRTOSConfig.h" +#include "event_groups.h" +#include "task.h" + +/********************************************************** + * Defines + *********************************************************/ + +#define MAIN_TASK_STACK_SIZE (1024 * 5) +#define MAIN_TASK_PRIORITY (configMAX_PRIORITIES - 1) + +using namespace ::chip; +using namespace ::chip::Inet; +using namespace ::chip::DeviceLayer; +using namespace ::chip::Credentials::Silabs; +using namespace chip::DeviceLayer::Silabs; + +TaskHandle_t main_Task; +void application_start(void * unused); +volatile int apperror_cnt; +static chip::DeviceLayer::DeviceInfoProviderImpl gExampleDeviceInfoProvider; + #if CHIP_ENABLE_OPENTHREAD #include #include @@ -129,6 +156,42 @@ CHIP_ERROR SilabsMatterConfig::InitOpenThread(void) } #endif // CHIP_ENABLE_OPENTHREAD +void SilabsMatterConfig::app_init() +{ + GetPlatform().Init(); + + xTaskCreate(application_start, "main_task", MAIN_TASK_STACK_SIZE, NULL, MAIN_TASK_PRIORITY, &main_Task); + SILABS_LOG("Starting scheduler"); + GetPlatform().StartScheduler(); + + // Should never get here. + chip::Platform::MemoryShutdown(); + SILABS_LOG("vTaskStartScheduler() failed"); + appError(CHIP_ERROR_INTERNAL); +} + +void application_start(void * unused) +{ + CHIP_ERROR err = SilabsMatterConfig::InitMatter(BLE_DEV_NAME); + if (err != CHIP_NO_ERROR) + appError(err); + + gExampleDeviceInfoProvider.SetStorageDelegate(&chip::Server::GetInstance().GetPersistentStorage()); + chip::DeviceLayer::SetDeviceInfoProvider(&gExampleDeviceInfoProvider); + + chip::DeviceLayer::PlatformMgr().LockChipStack(); + // Initialize device attestation config + SetDeviceAttestationCredentialsProvider(Credentials::Silabs::GetSilabsDacProvider()); + chip::DeviceLayer::PlatformMgr().UnlockChipStack(); + + SILABS_LOG("Starting App Task"); + err = AppTask::GetAppTask().StartAppTask(); + if (err != CHIP_NO_ERROR) + appError(err); + + vTaskDelete(main_Task); +} + #if SILABS_OTA_ENABLED void SilabsMatterConfig::InitOTARequestorHandler(System::Layer * systemLayer, void * appState) { diff --git a/examples/platform/silabs/MatterConfig.h b/examples/platform/silabs/MatterConfig.h index 86c8b7e0a66ba4..db0da27e20559e 100644 --- a/examples/platform/silabs/MatterConfig.h +++ b/examples/platform/silabs/MatterConfig.h @@ -26,6 +26,7 @@ class SilabsMatterConfig { public: static CHIP_ERROR InitMatter(const char * appName); + static void app_init(); private: static CHIP_ERROR InitOpenThread(void); diff --git a/examples/platform/silabs/main.cpp b/examples/platform/silabs/main.cpp index a3155194e8d1dd..975f5532ba6ecd 100644 --- a/examples/platform/silabs/main.cpp +++ b/examples/platform/silabs/main.cpp @@ -16,77 +16,17 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - -#include - -#include "AppConfig.h" - -#include +#include "sl_component_catalog.h" #include -#include -#include -#include - -#include - -#include "FreeRTOS.h" -#include "FreeRTOSConfig.h" -#include "event_groups.h" -#include "task.h" - -/********************************************************** - * Defines - *********************************************************/ - -#define MAIN_TASK_STACK_SIZE (1024 * 5) -#define MAIN_TASK_PRIORITY (configMAX_PRIORITIES - 1) - -using namespace ::chip; -using namespace ::chip::DeviceLayer; -using namespace ::chip::Credentials; -using namespace chip::DeviceLayer::Silabs; +#include "sl_system_kernel.h" +#include "sl_system_init.h" -TaskHandle_t main_Task; -void application_start(void * unused); -volatile int apperror_cnt; -static chip::DeviceLayer::DeviceInfoProviderImpl gExampleDeviceInfoProvider; - -// ================================================================================ -// Main Code -// ================================================================================ int main(void) { - GetPlatform().Init(); - - xTaskCreate(application_start, "main_task", MAIN_TASK_STACK_SIZE, NULL, MAIN_TASK_PRIORITY, &main_Task); - - SILABS_LOG("Starting scheduler"); - GetPlatform().StartScheduler(); - - // Should never get here. - chip::Platform::MemoryShutdown(); - SILABS_LOG("vTaskStartScheduler() failed"); - appError(CHIP_ERROR_INTERNAL); -} - -void application_start(void * unused) -{ - CHIP_ERROR err = SilabsMatterConfig::InitMatter(BLE_DEV_NAME); - if (err != CHIP_NO_ERROR) - appError(err); - - gExampleDeviceInfoProvider.SetStorageDelegate(&chip::Server::GetInstance().GetPersistentStorage()); - chip::DeviceLayer::SetDeviceInfoProvider(&gExampleDeviceInfoProvider); - - chip::DeviceLayer::PlatformMgr().LockChipStack(); - // Initialize device attestation config - SetDeviceAttestationCredentialsProvider(Credentials::Silabs::GetSilabsDacProvider()); - chip::DeviceLayer::PlatformMgr().UnlockChipStack(); + sl_system_init(); - SILABS_LOG("Starting App Task"); - err = AppTask::GetAppTask().StartAppTask(); - if (err != CHIP_NO_ERROR) - appError(err); + // Initialize the application. For example, create periodic timer(s) or + // task(s) if the kernel is present. + SilabsMatterConfig::app_init(); - vTaskDelete(main_Task); -} +} \ No newline at end of file diff --git a/src/platform/silabs/platformAbstraction/GsdkSpam.cpp b/src/platform/silabs/platformAbstraction/GsdkSpam.cpp index 5527fbfe90d73d..8bfce2f4dc487f 100644 --- a/src/platform/silabs/platformAbstraction/GsdkSpam.cpp +++ b/src/platform/silabs/platformAbstraction/GsdkSpam.cpp @@ -44,7 +44,6 @@ extern "C" { #include "sl_component_catalog.h" #include "sl_mbedtls.h" -#include "sl_system_init.h" #if SILABS_LOG_OUT_UART || ENABLE_CHIP_SHELL || CHIP_DEVICE_CONFIG_THREAD_ENABLE_CLI #include "uart.h" #endif @@ -68,8 +67,6 @@ SilabsPlatform::SilabsButtonCb SilabsPlatform::mButtonCallback = nullptr; CHIP_ERROR SilabsPlatform::Init(void) { - sl_system_init(); - mRebootCause = RMU_ResetCauseGet(); // Clear register so it does accumualate the causes of each reset RMU_ResetCauseClear(); diff --git a/src/platform/silabs/platformAbstraction/WiseMcuSpam.cpp b/src/platform/silabs/platformAbstraction/WiseMcuSpam.cpp index f57b73f0499d41..8a03e8a71a7cca 100644 --- a/src/platform/silabs/platformAbstraction/WiseMcuSpam.cpp +++ b/src/platform/silabs/platformAbstraction/WiseMcuSpam.cpp @@ -31,7 +31,6 @@ extern "C" { #include "sl_event_handler.h" #include "sl_si91x_led.h" #include "sl_si91x_led_config.h" -#include "sl_system_init.h" void soc_pll_config(void); } @@ -50,8 +49,6 @@ CHIP_ERROR SilabsPlatform::Init(void) { mButtonCallback = nullptr; - sl_system_init(); - // TODO: Setting the highest priority for SVCall_IRQn to avoid the HardFault issue NVIC_SetPriority(SVCall_IRQn, CORE_INTERRUPT_HIGHEST_PRIORITY);