|
21 | 21 |
|
22 | 22 | #include "AppConfig.h"
|
23 | 23 | #include "AppTask.h"
|
24 |
| -#include <FreeRTOS.h> |
25 | 24 |
|
26 | 25 | LightingManager LightingManager::sLight;
|
27 | 26 |
|
28 |
| -TimerHandle_t sLightTimer; |
29 |
| - |
30 | 27 | CHIP_ERROR LightingManager::Init()
|
31 | 28 | {
|
32 |
| - // Create FreeRTOS sw timer for light timer. |
33 |
| - sLightTimer = xTimerCreate("lightTmr", // Just a text name, not used by the RTOS kernel |
34 |
| - 1, // == default timer period (mS) |
35 |
| - false, // no timer reload (==one-shot) |
36 |
| - (void *) this, // init timer id = light obj context |
37 |
| - TimerEventHandler // timer callback handler |
38 |
| - ); |
39 |
| - |
40 |
| - if (sLightTimer == NULL) |
| 29 | + // Create cmsis os sw timer for light timer. |
| 30 | + mLightTimer = osTimerNew(TimerEventHandler, // timer callback handler |
| 31 | + osTimerOnce, // no timer reload (one-shot timer) |
| 32 | + (void *) this, // pass the app task obj context |
| 33 | + NULL // No osTimerAttr_t to provide. |
| 34 | + |
| 35 | + if (mLightTimer == NULL) |
41 | 36 | {
|
42 |
| - SILABS_LOG("sLightTimer timer create failed"); |
| 37 | + SILABS_LOG("mLightTimer timer create failed"); |
43 | 38 | return APP_ERROR_CREATE_TIMER_FAILED;
|
44 | 39 | }
|
45 | 40 |
|
@@ -123,38 +118,30 @@ bool LightingManager::InitiateAction(int32_t aActor, Action_t aAction)
|
123 | 118 |
|
124 | 119 | void LightingManager::StartTimer(uint32_t aTimeoutMs)
|
125 | 120 | {
|
126 |
| - if (xTimerIsTimerActive(sLightTimer)) |
127 |
| - { |
128 |
| - SILABS_LOG("app timer already started!"); |
129 |
| - CancelTimer(); |
130 |
| - } |
131 |
| - |
132 |
| - // timer is not active, change its period to required value (== restart). |
133 |
| - // FreeRTOS- Block for a maximum of 100 ticks if the change period command |
134 |
| - // cannot immediately be sent to the timer command queue. |
135 |
| - if (xTimerChangePeriod(sLightTimer, (aTimeoutMs / portTICK_PERIOD_MS), 100) != pdPASS) |
| 121 | + // Starts or restarts the function timer |
| 122 | + if (osTimerStart(mLightTimer, pdMS_TO_TICKS(aTimeoutMs)) != osOK) |
136 | 123 | {
|
137 |
| - SILABS_LOG("sLightTimer timer start() failed"); |
| 124 | + SILABS_LOG("mLightTimer timer start() failed"); |
138 | 125 | appError(APP_ERROR_START_TIMER_FAILED);
|
139 | 126 | }
|
140 | 127 | }
|
141 | 128 |
|
142 | 129 | void LightingManager::CancelTimer(void)
|
143 | 130 | {
|
144 |
| - if (xTimerStop(sLightTimer, 0) == pdFAIL) |
| 131 | + if (osTimerStop(mLightTimer) == osError) |
145 | 132 | {
|
146 |
| - SILABS_LOG("sLightTimer stop() failed"); |
| 133 | + SILABS_LOG("mLightTimer stop() failed"); |
147 | 134 | appError(APP_ERROR_STOP_TIMER_FAILED);
|
148 | 135 | }
|
149 | 136 | }
|
150 | 137 |
|
151 |
| -void LightingManager::TimerEventHandler(TimerHandle_t xTimer) |
| 138 | +void LightingManager::TimerEventHandler(void * timerCbArg) |
152 | 139 | {
|
153 |
| - // Get light obj context from timer id. |
154 |
| - LightingManager * light = static_cast<LightingManager *>(pvTimerGetTimerID(xTimer)); |
| 140 | + // The callback argument is the light obj context assigned at timer creation. |
| 141 | + LightingManager * light = static_cast<LightingManager *>(timerCbArg); |
155 | 142 |
|
156 | 143 | // The timer event handler will be called in the context of the timer task
|
157 |
| - // once sLightTimer expires. Post an event to apptask queue with the actual handler |
| 144 | + // once mLightTimer expires. Post an event to apptask queue with the actual handler |
158 | 145 | // so that the event can be handled in the context of the apptask.
|
159 | 146 | AppEvent event;
|
160 | 147 | event.Type = AppEvent::kEventType_Timer;
|
|
0 commit comments