@@ -98,11 +98,10 @@ namespace {
98
98
* Variable declarations
99
99
*********************************************************/
100
100
101
- TimerHandle_t sFunctionTimer ; // FreeRTOS app sw timer.
102
- TimerHandle_t sLightTimer ;
103
-
104
- TaskHandle_t sAppTaskHandle ;
105
- QueueHandle_t sAppEventQueue ;
101
+ osTimerId_t sFunctionTimer ;
102
+ osTimerId_t sLightTimer ;
103
+ osThreadId_t sAppTaskHandle ;
104
+ osMessageQueueId_t sAppEventQueue ;
106
105
107
106
#if (defined(ENABLE_WSTK_LEDS) && (defined(SL_CATALOG_SIMPLE_LED_LED1_PRESENT)))
108
107
LEDWidget sStatusLED ;
@@ -119,11 +118,24 @@ bool sIsAttached = false;
119
118
bool sHaveBLEConnections = false ;
120
119
#endif // CHIP_CONFIG_ENABLE_ICD_SERVER
121
120
122
- uint8_t sAppEventQueueBuffer [APP_EVENT_QUEUE_SIZE * sizeof (AppEvent)];
123
- StaticQueue_t sAppEventQueueStruct ;
121
+ constexpr uint32_t kLightTimerPeriod = static_cast <uint32_t >(pdMS_TO_TICKS(10 ));
124
122
125
- StackType_t appStack[APP_TASK_STACK_SIZE / sizeof (StackType_t)];
126
- StaticTask_t appTaskStruct;
123
+ uint8_t sAppEventQueueBuffer [APP_EVENT_QUEUE_SIZE * sizeof (AppEvent)];
124
+ StaticQueue_t sAppEventQueueStruct ; // TODO abstract type for static controlblock
125
+ constexpr osMessageQueueAttr_t appEventQueueAttr = { .cb_mem = &sAppEventQueueStruct ,
126
+ .cb_size = sizeof (sAppEventQueueBuffer ),
127
+ .mq_mem = sAppEventQueueBuffer ,
128
+ .mq_size = sizeof (sAppEventQueueBuffer ) };
129
+
130
+ uint8_t appStack[APP_TASK_STACK_SIZE];
131
+ StaticTask_t appTaskStruct; // TODO abstract type for static controlblock
132
+ constexpr osThreadAttr_t appTaskAttr = { .name = APP_TASK_NAME,
133
+ .attr_bits = osThreadDetached,
134
+ .cb_mem = &appTaskStruct,
135
+ .cb_size = sizeof (appTaskStruct),
136
+ .stack_mem = appStack,
137
+ .stack_size = APP_TASK_STACK_SIZE,
138
+ .priority = osPriorityNormal };
127
139
128
140
#ifdef DISPLAY_ENABLED
129
141
SilabsLCD slLCD;
@@ -192,18 +204,17 @@ void BaseApplicationDelegate::OnCommissioningWindowClosed()
192
204
* AppTask Definitions
193
205
*********************************************************/
194
206
195
- CHIP_ERROR BaseApplication::StartAppTask (TaskFunction_t taskFunction)
207
+ CHIP_ERROR BaseApplication::StartAppTask (osThreadFunc_t taskFunction)
196
208
{
197
- sAppEventQueue = xQueueCreateStatic (APP_EVENT_QUEUE_SIZE, sizeof (AppEvent), sAppEventQueueBuffer , & sAppEventQueueStruct );
209
+ sAppEventQueue = osMessageQueueNew (APP_EVENT_QUEUE_SIZE, sizeof (AppEvent), &appEventQueueAttr );
198
210
if (sAppEventQueue == NULL )
199
211
{
200
212
SILABS_LOG (" Failed to allocate app event queue" );
201
213
appError (APP_ERROR_EVENT_QUEUE_FAILED);
202
214
}
203
215
204
216
// Start App task.
205
- sAppTaskHandle =
206
- xTaskCreateStatic (taskFunction, APP_TASK_NAME, ArraySize (appStack), &sAppEventQueue , 1 , appStack, &appTaskStruct);
217
+ sAppTaskHandle = osThreadNew (taskFunction, &sAppEventQueue , &appTaskAttr);
207
218
if (sAppTaskHandle == nullptr )
208
219
{
209
220
SILABS_LOG (" Failed to create app task" );
@@ -234,25 +245,23 @@ CHIP_ERROR BaseApplication::Init()
234
245
235
246
#endif
236
247
237
- // Create FreeRTOS sw timer for Function Selection.
238
- sFunctionTimer = xTimerCreate (" FnTmr" , // Just a text name, not used by the RTOS kernel
239
- pdMS_TO_TICKS (1 ), // == default timer period
240
- false , // no timer reload (==one-shot)
241
- (void *) this , // init timer id = app task obj context
242
- FunctionTimerEventHandler // timer callback handler
248
+ // Create cmsis os sw timer for Function Selection.
249
+ sFunctionTimer = osTimerNew (FunctionTimerEventHandler, // timer callback handler
250
+ osTimerOnce, // no timer reload (one-shot timer)
251
+ (void *) this , // pass the app task obj context
252
+ NULL // No osTimerAttr_t to provide.
243
253
);
244
254
if (sFunctionTimer == NULL )
245
255
{
246
256
SILABS_LOG (" funct timer create failed" );
247
257
appError (APP_ERROR_CREATE_TIMER_FAILED);
248
258
}
249
259
250
- // Create FreeRTOS sw timer for LED Management.
251
- sLightTimer = xTimerCreate (" LightTmr" , // Text Name
252
- pdMS_TO_TICKS (10 ), // Default timer period
253
- true , // reload timer
254
- (void *) this , // Timer Id
255
- LightTimerEventHandler // Timer callback handler
260
+ // Create cmsis os sw timer for LED Management.
261
+ sLightTimer = osTimerNew (LightTimerEventHandler, // Timer callback handler"LightTmr",
262
+ osTimerPeriodic, // timer repeats automatically
263
+ (void *) this , // pass the app task obj context
264
+ NULL // No osTimerAttr_t to provide.
256
265
);
257
266
if (sLightTimer == NULL )
258
267
{
@@ -289,7 +298,7 @@ CHIP_ERROR BaseApplication::Init()
289
298
return err;
290
299
}
291
300
292
- void BaseApplication::FunctionTimerEventHandler (TimerHandle_t xTimer)
301
+ void BaseApplication::FunctionTimerEventHandler (osTimerId_t xTimer)
293
302
{
294
303
AppEvent event;
295
304
event.Type = AppEvent::kEventType_Timer ;
@@ -524,7 +533,7 @@ void BaseApplication::UpdateDisplay()
524
533
525
534
void BaseApplication::CancelFunctionTimer ()
526
535
{
527
- if (xTimerStop (sFunctionTimer , pdMS_TO_TICKS ( 0 )) == pdFAIL )
536
+ if (osTimerStop (sFunctionTimer ) == osError )
528
537
{
529
538
SILABS_LOG (" app timer stop() failed" );
530
539
appError (APP_ERROR_STOP_TIMER_FAILED);
@@ -533,16 +542,8 @@ void BaseApplication::CancelFunctionTimer()
533
542
534
543
void BaseApplication::StartFunctionTimer (uint32_t aTimeoutInMs)
535
544
{
536
- if (xTimerIsTimerActive (sFunctionTimer ))
537
- {
538
- SILABS_LOG (" app timer already started!" );
539
- CancelFunctionTimer ();
540
- }
541
-
542
- // timer is not active, change its period to required value (== restart).
543
- // FreeRTOS- Block for a maximum of 100 ms if the change period command
544
- // cannot immediately be sent to the timer command queue.
545
- if (xTimerChangePeriod (sFunctionTimer , pdMS_TO_TICKS (aTimeoutInMs), pdMS_TO_TICKS (100 )) != pdPASS)
545
+ // Starts or restarts the function timer
546
+ if (osTimerStart (sFunctionTimer , pdMS_TO_TICKS (aTimeoutInMs)) != osOK)
546
547
{
547
548
SILABS_LOG (" app timer start() failed" );
548
549
appError (APP_ERROR_START_TIMER_FAILED);
@@ -587,7 +588,7 @@ void BaseApplication::CancelFactoryResetSequence()
587
588
588
589
void BaseApplication::StartStatusLEDTimer ()
589
590
{
590
- if (pdPASS != xTimerStart (sLightTimer , pdMS_TO_TICKS ( 0 )) )
591
+ if (osTimerStart (sLightTimer , kLightTimerPeriod ) != osOK )
591
592
{
592
593
SILABS_LOG (" Light Time start failed" );
593
594
appError (APP_ERROR_START_TIMER_FAILED);
@@ -600,10 +601,10 @@ void BaseApplication::StopStatusLEDTimer()
600
601
sStatusLED .Set (false );
601
602
#endif // ENABLE_WSTK_LEDS
602
603
603
- if (xTimerStop (sLightTimer , pdMS_TO_TICKS ( 100 )) != pdPASS )
604
+ if (osTimerStop (sLightTimer ) == osError )
604
605
{
605
606
SILABS_LOG (" Light Time start failed" );
606
- appError (APP_ERROR_START_TIMER_FAILED );
607
+ appError (APP_ERROR_STOP_TIMER_FAILED );
607
608
}
608
609
}
609
610
@@ -676,7 +677,7 @@ void BaseApplication::OnTriggerIdentifyEffect(Identify * identify)
676
677
}
677
678
#endif // MATTER_DM_PLUGIN_IDENTIFY_SERVER
678
679
679
- void BaseApplication::LightTimerEventHandler (TimerHandle_t xTimer)
680
+ void BaseApplication::LightTimerEventHandler (osTimerId_t xTimer)
680
681
{
681
682
LightEventHandler ();
682
683
}
@@ -715,35 +716,16 @@ void BaseApplication::UpdateLCDStatusScreen(void)
715
716
716
717
void BaseApplication::PostEvent (const AppEvent * aEvent)
717
718
{
718
- if (sAppEventQueue != NULL )
719
+ if (sAppEventQueue != nullptr )
719
720
{
720
- BaseType_t status;
721
- if (xPortIsInsideInterrupt ())
722
- {
723
- BaseType_t higherPrioTaskWoken = pdFALSE;
724
- status = xQueueSendFromISR (sAppEventQueue , aEvent, &higherPrioTaskWoken);
725
-
726
- #ifdef portYIELD_FROM_ISR
727
- portYIELD_FROM_ISR (higherPrioTaskWoken);
728
- #elif portEND_SWITCHING_ISR // portYIELD_FROM_ISR or portEND_SWITCHING_ISR
729
- portEND_SWITCHING_ISR (higherPrioTaskWoken);
730
- #else // portYIELD_FROM_ISR or portEND_SWITCHING_ISR
731
- #error "Must have portYIELD_FROM_ISR or portEND_SWITCHING_ISR"
732
- #endif // portYIELD_FROM_ISR or portEND_SWITCHING_ISR
733
- }
734
- else
735
- {
736
- status = xQueueSend (sAppEventQueue , aEvent, 1 );
737
- }
738
-
739
- if (!status)
721
+ if (osMessageQueuePut (sAppEventQueue , aEvent, osPriorityNormal, 0 ) != osOK)
740
722
{
741
723
SILABS_LOG (" Failed to post event to app task event queue" );
742
724
}
743
725
}
744
726
else
745
727
{
746
- SILABS_LOG (" Event Queue is NULL should never happen " );
728
+ SILABS_LOG (" App Event Queue is uninitialized " );
747
729
}
748
730
}
749
731
0 commit comments