21
21
22
22
#include " AppConfig.h"
23
23
#include " AppTask.h"
24
- #include < FreeRTOS.h>
25
24
26
25
#include < lib/support/TypeTraits.h>
27
26
@@ -30,9 +29,6 @@ using namespace ::chip::app::Clusters::OnOff;
30
29
using namespace ::chip::DeviceLayer;
31
30
32
31
LightingManager LightingManager::sLight ;
33
-
34
- TimerHandle_t sLightTimer ;
35
-
36
32
namespace {
37
33
38
34
/* *********************************************************
@@ -50,17 +46,16 @@ OnOffEffect gEffect = {
50
46
51
47
CHIP_ERROR LightingManager::Init ()
52
48
{
53
- // Create FreeRTOS sw timer for light timer.
54
- sLightTimer = xTimerCreate (" lightTmr" , // Just a text name, not used by the RTOS kernel
55
- pdMS_TO_TICKS (1 ), // == default timer period
56
- false , // no timer reload (==one-shot)
57
- (void *) this , // init timer id = light obj context
58
- TimerEventHandler // timer callback handler
49
+ // Create cmsis os sw timer for light timer.
50
+ mLightTimer = osTimerNew (TimerEventHandler, // timer callback handler
51
+ osTimerOnce, // no timer reload (one-shot timer)
52
+ (void *) this , // pass the app task obj context
53
+ NULL // No osTimerAttr_t to provide.
59
54
);
60
55
61
- if (sLightTimer == NULL )
56
+ if (mLightTimer == NULL )
62
57
{
63
- SILABS_LOG (" sLightTimer timer create failed" );
58
+ SILABS_LOG (" mLightTimer timer create failed" );
64
59
return APP_ERROR_CREATE_TIMER_FAILED;
65
60
}
66
61
@@ -157,38 +152,30 @@ bool LightingManager::InitiateAction(int32_t aActor, Action_t aAction)
157
152
158
153
void LightingManager::StartTimer (uint32_t aTimeoutMs)
159
154
{
160
- if (xTimerIsTimerActive (sLightTimer ))
161
- {
162
- SILABS_LOG (" app timer already started!" );
163
- CancelTimer ();
164
- }
165
-
166
- // timer is not active, change its period to required value (== restart).
167
- // FreeRTOS- Block for a maximum of 100 ms if the change period command
168
- // cannot immediately be sent to the timer command queue.
169
- if (xTimerChangePeriod (sLightTimer , pdMS_TO_TICKS (aTimeoutMs), pdMS_TO_TICKS (100 )) != pdPASS)
155
+ // Starts or restarts the function timer
156
+ if (osTimerStart (mLightTimer , pdMS_TO_TICKS (aTimeoutMs)) != osOK)
170
157
{
171
- SILABS_LOG (" sLightTimer timer start() failed" );
158
+ SILABS_LOG (" mLightTimer timer start() failed" );
172
159
appError (APP_ERROR_START_TIMER_FAILED);
173
160
}
174
161
}
175
162
176
163
void LightingManager::CancelTimer (void )
177
164
{
178
- if (xTimerStop ( sLightTimer , pdMS_TO_TICKS ( 0 )) == pdFAIL )
165
+ if (osTimerStop ( mLightTimer ) == osError )
179
166
{
180
- SILABS_LOG (" sLightTimer stop() failed" );
167
+ SILABS_LOG (" mLightTimer stop() failed" );
181
168
appError (APP_ERROR_STOP_TIMER_FAILED);
182
169
}
183
170
}
184
171
185
- void LightingManager::TimerEventHandler (TimerHandle_t xTimer )
172
+ void LightingManager::TimerEventHandler (void * timerCbArg )
186
173
{
187
- // Get light obj context from timer id .
188
- LightingManager * light = static_cast <LightingManager *>(pvTimerGetTimerID (xTimer) );
174
+ // The callback argument is the light obj context assigned at timer creation .
175
+ LightingManager * light = static_cast <LightingManager *>(timerCbArg );
189
176
190
177
// The timer event handler will be called in the context of the timer task
191
- // once sLightTimer expires. Post an event to apptask queue with the actual handler
178
+ // once mLightTimer expires. Post an event to apptask queue with the actual handler
192
179
// so that the event can be handled in the context of the apptask.
193
180
AppEvent event;
194
181
event.Type = AppEvent::kEventType_Timer ;
0 commit comments