21
21
#include " BaseApplication.h"
22
22
#include " OTAConfig.h"
23
23
#include < MatterConfig.h>
24
-
25
- #include < FreeRTOS.h>
24
+ #include < cmsis_os2.h>
26
25
27
26
#include < mbedtls/platform.h>
28
27
@@ -80,27 +79,16 @@ static chip::DeviceLayer::Internal::Efr32PsaOperationalKeystore gOperationalKeys
80
79
81
80
#include < platform/silabs/platformAbstraction/SilabsPlatform.h>
82
81
83
- #include " FreeRTOSConfig.h"
84
- #include " event_groups.h"
85
- #include " task.h"
86
-
87
82
/* *********************************************************
88
83
* Defines
89
84
*********************************************************/
90
85
91
- #define MAIN_TASK_STACK_SIZE (1024 * 5 )
92
- #define MAIN_TASK_PRIORITY (configMAX_PRIORITIES - 1 )
93
-
94
86
using namespace ::chip;
95
87
using namespace ::chip::Inet;
96
88
using namespace ::chip::DeviceLayer;
97
89
using namespace ::chip::Credentials::Silabs;
98
90
using namespace chip ::DeviceLayer::Silabs;
99
91
100
- TaskHandle_t main_Task;
101
- volatile int apperror_cnt;
102
- static chip::DeviceLayer::DeviceInfoProviderImpl gExampleDeviceInfoProvider ;
103
-
104
92
#if CHIP_ENABLE_OPENTHREAD
105
93
#include < inet/EndPointStateOpenThread.h>
106
94
#include < openthread/cli.h>
@@ -156,7 +144,20 @@ CHIP_ERROR SilabsMatterConfig::InitOpenThread(void)
156
144
#endif // CHIP_ENABLE_OPENTHREAD
157
145
158
146
namespace {
159
- void application_start (void * unused)
147
+
148
+ constexpr uint32_t kMainTaskStackSize = (1024 * 5 );
149
+ // Task is dynamically allocated with max priority. This task gets deleted once the inits are completed.
150
+ constexpr osThreadAttr_t kMainTaskAttr = { .name = " main" ,
151
+ .attr_bits = osThreadDetached,
152
+ .cb_mem = NULL ,
153
+ .cb_size = 0U ,
154
+ .stack_mem = NULL ,
155
+ .stack_size = kMainTaskStackSize ,
156
+ .priority = osPriorityRealtime7 };
157
+ osThreadId_t sMainTaskHandle ;
158
+ static chip::DeviceLayer::DeviceInfoProviderImpl gExampleDeviceInfoProvider ;
159
+
160
+ void ApplicationStart (void * unused)
160
161
{
161
162
CHIP_ERROR err = SilabsMatterConfig::InitMatter (BLE_DEV_NAME);
162
163
if (err != CHIP_NO_ERROR)
@@ -175,16 +176,18 @@ void application_start(void * unused)
175
176
if (err != CHIP_NO_ERROR)
176
177
appError (err);
177
178
178
- vTaskDelete (main_Task);
179
+ VerifyOrDie (osThreadTerminate (sMainTaskHandle ) == osOK); // Deleting the main task should never fail.
180
+ sMainTaskHandle = nullptr ;
179
181
}
180
182
} // namespace
181
183
182
184
void SilabsMatterConfig::AppInit ()
183
185
{
184
186
GetPlatform ().Init ();
185
187
186
- xTaskCreate (application_start, " main_task " , MAIN_TASK_STACK_SIZE, NULL , MAIN_TASK_PRIORITY, &main_Task );
188
+ sMainTaskHandle = osThreadNew (ApplicationStart, nullptr , & kMainTaskAttr );
187
189
SILABS_LOG (" Starting scheduler" );
190
+ VerifyOrDie (sMainTaskHandle ); // We can't proceed if the Main Task creation failed.
188
191
GetPlatform ().StartScheduler ();
189
192
190
193
// Should never get here.
0 commit comments