Migrate our <apps>Manager from freeRTOS api to CMSIS OS2 Api (#32705)
diff --git a/examples/chef/silabs/include/LightingManager.h b/examples/chef/silabs/include/LightingManager.h
index 3aa9871..6fe2b10 100644
--- a/examples/chef/silabs/include/LightingManager.h
+++ b/examples/chef/silabs/include/LightingManager.h
@@ -23,9 +23,7 @@
#include "AppEvent.h"
-#include "FreeRTOS.h"
-#include "timers.h" // provides FreeRTOS timer support
-
+#include <cmsis_os2.h>
#include <lib/core/CHIPError.h>
class LightingManager
@@ -68,11 +66,12 @@
bool mAutoTurnOff;
uint32_t mAutoTurnOffDuration;
bool mAutoTurnOffTimerArmed;
+ osTimerId_t mLightTimer;
void CancelTimer(void);
void StartTimer(uint32_t aTimeoutMs);
- static void TimerEventHandler(TimerHandle_t xTimer);
+ static void TimerEventHandler(void * timerCbArg);
static void AutoTurnOffTimerEventHandler(AppEvent * aEvent);
static void ActuatorMovementTimerEventHandler(AppEvent * aEvent);
diff --git a/examples/chef/silabs/src/LightingManager.cpp b/examples/chef/silabs/src/LightingManager.cpp
index d6684bf..1856f84 100644
--- a/examples/chef/silabs/src/LightingManager.cpp
+++ b/examples/chef/silabs/src/LightingManager.cpp
@@ -21,25 +21,20 @@
#include "AppConfig.h"
#include "AppTask.h"
-#include <FreeRTOS.h>
LightingManager LightingManager::sLight;
-TimerHandle_t sLightTimer;
-
CHIP_ERROR LightingManager::Init()
{
- // Create FreeRTOS sw timer for light timer.
- sLightTimer = xTimerCreate("lightTmr", // Just a text name, not used by the RTOS kernel
- 1, // == default timer period (mS)
- false, // no timer reload (==one-shot)
- (void *) this, // init timer id = light obj context
- TimerEventHandler // timer callback handler
- );
+ // Create cmsis os sw timer for light timer.
+ mLightTimer = osTimerNew(TimerEventHandler, // timer callback handler
+ osTimerOnce, // no timer reload (one-shot timer)
+ (void *) this, // pass the app task obj context
+ NULL // No osTimerAttr_t to provide.
- if (sLightTimer == NULL)
+ if (mLightTimer == NULL)
{
- SILABS_LOG("sLightTimer timer create failed");
+ SILABS_LOG("mLightTimer timer create failed");
return APP_ERROR_CREATE_TIMER_FAILED;
}
@@ -123,38 +118,30 @@
void LightingManager::StartTimer(uint32_t aTimeoutMs)
{
- if (xTimerIsTimerActive(sLightTimer))
+ // Starts or restarts the function timer
+ if (osTimerStart(mLightTimer, pdMS_TO_TICKS(aTimeoutMs)) != osOK)
{
- SILABS_LOG("app timer already started!");
- CancelTimer();
- }
-
- // timer is not active, change its period to required value (== restart).
- // FreeRTOS- Block for a maximum of 100 ticks if the change period command
- // cannot immediately be sent to the timer command queue.
- if (xTimerChangePeriod(sLightTimer, (aTimeoutMs / portTICK_PERIOD_MS), 100) != pdPASS)
- {
- SILABS_LOG("sLightTimer timer start() failed");
+ SILABS_LOG("mLightTimer timer start() failed");
appError(APP_ERROR_START_TIMER_FAILED);
}
}
void LightingManager::CancelTimer(void)
{
- if (xTimerStop(sLightTimer, 0) == pdFAIL)
+ if (osTimerStop(mLightTimer) == osError)
{
- SILABS_LOG("sLightTimer stop() failed");
+ SILABS_LOG("mLightTimer stop() failed");
appError(APP_ERROR_STOP_TIMER_FAILED);
}
}
-void LightingManager::TimerEventHandler(TimerHandle_t xTimer)
+void LightingManager::TimerEventHandler(void * timerCbArg)
{
- // Get light obj context from timer id.
- LightingManager * light = static_cast<LightingManager *>(pvTimerGetTimerID(xTimer));
+ // The callback argument is the light obj context assigned at timer creation.
+ LightingManager * light = static_cast<LightingManager *>(timerCbArg);
// The timer event handler will be called in the context of the timer task
- // once sLightTimer expires. Post an event to apptask queue with the actual handler
+ // once mLightTimer expires. Post an event to apptask queue with the actual handler
// so that the event can be handled in the context of the apptask.
AppEvent event;
event.Type = AppEvent::kEventType_Timer;
diff --git a/examples/lighting-app/silabs/include/LightingManager.h b/examples/lighting-app/silabs/include/LightingManager.h
index 6d286fa..00a1448 100644
--- a/examples/lighting-app/silabs/include/LightingManager.h
+++ b/examples/lighting-app/silabs/include/LightingManager.h
@@ -23,10 +23,8 @@
#include "AppEvent.h"
-#include "FreeRTOS.h"
-#include "timers.h" // provides FreeRTOS timer support
#include <app/clusters/on-off-server/on-off-server.h>
-
+#include <cmsis_os2.h>
#include <lib/core/CHIPError.h>
class LightingManager
@@ -72,11 +70,12 @@
uint32_t mAutoTurnOffDuration;
bool mAutoTurnOffTimerArmed;
bool mOffEffectArmed;
+ osTimerId_t mLightTimer;
void CancelTimer(void);
void StartTimer(uint32_t aTimeoutMs);
- static void TimerEventHandler(TimerHandle_t xTimer);
+ static void TimerEventHandler(void * timerCbArg);
static void AutoTurnOffTimerEventHandler(AppEvent * aEvent);
static void ActuatorMovementTimerEventHandler(AppEvent * aEvent);
static void OffEffectTimerEventHandler(AppEvent * aEvent);
diff --git a/examples/lighting-app/silabs/src/LightingManager.cpp b/examples/lighting-app/silabs/src/LightingManager.cpp
index 769dc00..d839c52 100644
--- a/examples/lighting-app/silabs/src/LightingManager.cpp
+++ b/examples/lighting-app/silabs/src/LightingManager.cpp
@@ -21,7 +21,6 @@
#include "AppConfig.h"
#include "AppTask.h"
-#include <FreeRTOS.h>
#include <lib/support/TypeTraits.h>
@@ -30,9 +29,6 @@
using namespace ::chip::DeviceLayer;
LightingManager LightingManager::sLight;
-
-TimerHandle_t sLightTimer;
-
namespace {
/**********************************************************
@@ -50,17 +46,16 @@
CHIP_ERROR LightingManager::Init()
{
- // Create FreeRTOS sw timer for light timer.
- sLightTimer = xTimerCreate("lightTmr", // Just a text name, not used by the RTOS kernel
- pdMS_TO_TICKS(1), // == default timer period
- false, // no timer reload (==one-shot)
- (void *) this, // init timer id = light obj context
- TimerEventHandler // timer callback handler
+ // Create cmsis os sw timer for light timer.
+ mLightTimer = osTimerNew(TimerEventHandler, // timer callback handler
+ osTimerOnce, // no timer reload (one-shot timer)
+ (void *) this, // pass the app task obj context
+ NULL // No osTimerAttr_t to provide.
);
- if (sLightTimer == NULL)
+ if (mLightTimer == NULL)
{
- SILABS_LOG("sLightTimer timer create failed");
+ SILABS_LOG("mLightTimer timer create failed");
return APP_ERROR_CREATE_TIMER_FAILED;
}
@@ -157,38 +152,30 @@
void LightingManager::StartTimer(uint32_t aTimeoutMs)
{
- if (xTimerIsTimerActive(sLightTimer))
+ // Starts or restarts the function timer
+ if (osTimerStart(mLightTimer, pdMS_TO_TICKS(aTimeoutMs)) != osOK)
{
- SILABS_LOG("app timer already started!");
- CancelTimer();
- }
-
- // timer is not active, change its period to required value (== restart).
- // FreeRTOS- Block for a maximum of 100 ms if the change period command
- // cannot immediately be sent to the timer command queue.
- if (xTimerChangePeriod(sLightTimer, pdMS_TO_TICKS(aTimeoutMs), pdMS_TO_TICKS(100)) != pdPASS)
- {
- SILABS_LOG("sLightTimer timer start() failed");
+ SILABS_LOG("mLightTimer timer start() failed");
appError(APP_ERROR_START_TIMER_FAILED);
}
}
void LightingManager::CancelTimer(void)
{
- if (xTimerStop(sLightTimer, pdMS_TO_TICKS(0)) == pdFAIL)
+ if (osTimerStop(mLightTimer) == osError)
{
- SILABS_LOG("sLightTimer stop() failed");
+ SILABS_LOG("mLightTimer stop() failed");
appError(APP_ERROR_STOP_TIMER_FAILED);
}
}
-void LightingManager::TimerEventHandler(TimerHandle_t xTimer)
+void LightingManager::TimerEventHandler(void * timerCbArg)
{
- // Get light obj context from timer id.
- LightingManager * light = static_cast<LightingManager *>(pvTimerGetTimerID(xTimer));
+ // The callback argument is the light obj context assigned at timer creation.
+ LightingManager * light = static_cast<LightingManager *>(timerCbArg);
// The timer event handler will be called in the context of the timer task
- // once sLightTimer expires. Post an event to apptask queue with the actual handler
+ // once mLightTimer expires. Post an event to apptask queue with the actual handler
// so that the event can be handled in the context of the apptask.
AppEvent event;
event.Type = AppEvent::kEventType_Timer;
diff --git a/examples/lock-app/silabs/include/LockManager.h b/examples/lock-app/silabs/include/LockManager.h
index 9adcc86..fb73d1d 100644
--- a/examples/lock-app/silabs/include/LockManager.h
+++ b/examples/lock-app/silabs/include/LockManager.h
@@ -24,9 +24,7 @@
#include "AppEvent.h"
-#include "FreeRTOS.h"
-#include "timers.h" // provides FreeRTOS timer support
-
+#include <cmsis_os2.h>
#include <lib/core/CHIPError.h>
struct WeekDaysScheduleInfo
@@ -203,10 +201,11 @@
void CancelTimer(void);
void StartTimer(uint32_t aTimeoutMs);
- static void TimerEventHandler(TimerHandle_t xTimer);
+ static void TimerEventHandler(void * timerCbArg);
static void AutoLockTimerEventHandler(AppEvent * aEvent);
static void ActuatorMovementTimerEventHandler(AppEvent * aEvent);
+ osTimerId_t mLockTimer;
EmberAfPluginDoorLockUserInfo mLockUsers[kMaxUsers];
EmberAfPluginDoorLockCredentialInfo mLockCredentials[kNumCredentialTypes][kMaxCredentials];
WeekDaysScheduleInfo mWeekdaySchedule[kMaxUsers][kMaxWeekdaySchedulesPerUser];
diff --git a/examples/lock-app/silabs/src/LockManager.cpp b/examples/lock-app/silabs/src/LockManager.cpp
index 8190dbd..3c376a2 100644
--- a/examples/lock-app/silabs/src/LockManager.cpp
+++ b/examples/lock-app/silabs/src/LockManager.cpp
@@ -21,15 +21,12 @@
#include "AppConfig.h"
#include "AppTask.h"
-#include <FreeRTOS.h>
#include <app-common/zap-generated/attributes/Accessors.h>
#include <cstring>
#include <lib/support/logging/CHIPLogging.h>
LockManager LockManager::sLock;
-TimerHandle_t sLockTimer;
-
using namespace ::chip::DeviceLayer::Internal;
using namespace EFR32DoorLock::LockInitParams;
@@ -77,17 +74,16 @@
return APP_ERROR_ALLOCATION_FAILED;
}
- // Create FreeRTOS sw timer for lock timer.
- sLockTimer = xTimerCreate("lockTmr", // Just a text name, not used by the RTOS kernel
- 1, // == default timer period
- false, // no timer reload (==one-shot)
- (void *) this, // init timer id = lock obj context
- TimerEventHandler // timer callback handler
+ // Create cmsis os sw timer for lock timer.
+ mLockTimer = osTimerNew(TimerEventHandler, // timer callback handler
+ osTimerOnce, // no timer reload (one-shot timer)
+ (void *) this, // pass the app task obj context
+ NULL // No osTimerAttr_t to provide.
);
- if (sLockTimer == NULL)
+ if (mLockTimer == NULL)
{
- SILABS_LOG("sLockTimer timer create failed");
+ SILABS_LOG("mLockTimer timer create failed");
return APP_ERROR_CREATE_TIMER_FAILED;
}
@@ -222,38 +218,30 @@
void LockManager::StartTimer(uint32_t aTimeoutMs)
{
- if (xTimerIsTimerActive(sLockTimer))
+ // Starts or restarts the function timer
+ if (osTimerStart(mLockTimer, pdMS_TO_TICKS(aTimeoutMs)) != osOK)
{
- SILABS_LOG("app timer already started!");
- CancelTimer();
- }
-
- // timer is not active, change its period to required value (== restart).
- // FreeRTOS- Block for a maximum of 100 ms if the change period command
- // cannot immediately be sent to the timer command queue.
- if (xTimerChangePeriod(sLockTimer, pdMS_TO_TICKS(aTimeoutMs), pdMS_TO_TICKS(100)) != pdPASS)
- {
- SILABS_LOG("sLockTimer timer start() failed");
+ SILABS_LOG("mLockTimer timer start() failed");
appError(APP_ERROR_START_TIMER_FAILED);
}
}
void LockManager::CancelTimer(void)
{
- if (xTimerStop(sLockTimer, pdMS_TO_TICKS(0)) == pdFAIL)
+ if (osTimerStop(mLockTimer) == osError)
{
- SILABS_LOG("sLockTimer stop() failed");
+ SILABS_LOG("mLockTimer stop() failed");
appError(APP_ERROR_STOP_TIMER_FAILED);
}
}
-void LockManager::TimerEventHandler(TimerHandle_t xTimer)
+void LockManager::TimerEventHandler(void * timerCbArg)
{
- // Get lock obj context from timer id.
- LockManager * lock = static_cast<LockManager *>(pvTimerGetTimerID(xTimer));
+ // The callback argument is the light obj context assigned at timer creation.
+ LockManager * lock = static_cast<LockManager *>(timerCbArg);
// The timer event handler will be called in the context of the timer task
- // once sLockTimer expires. Post an event to apptask queue with the actual handler
+ // once mLockTimer expires. Post an event to apptask queue with the actual handler
// so that the event can be handled in the context of the apptask.
AppEvent event;
event.Type = AppEvent::kEventType_Timer;
diff --git a/examples/platform/silabs/BaseApplication.cpp b/examples/platform/silabs/BaseApplication.cpp
index 3911047..d8df720 100644
--- a/examples/platform/silabs/BaseApplication.cpp
+++ b/examples/platform/silabs/BaseApplication.cpp
@@ -79,7 +79,9 @@
#define APP_TASK_STACK_SIZE (4096)
#endif
#define APP_TASK_PRIORITY 2
+#ifndef APP_EVENT_QUEUE_SIZE // Allow apps to define a different app queue size
#define APP_EVENT_QUEUE_SIZE 10
+#endif
#define EXAMPLE_VENDOR_ID 0xcafe
#if (defined(ENABLE_WSTK_LEDS) && (defined(SL_CATALOG_SIMPLE_LED_LED1_PRESENT)))
@@ -298,11 +300,11 @@
return err;
}
-void BaseApplication::FunctionTimerEventHandler(osTimerId_t xTimer)
+void BaseApplication::FunctionTimerEventHandler(void * timerCbArg)
{
AppEvent event;
event.Type = AppEvent::kEventType_Timer;
- event.TimerEvent.Context = (void *) xTimer;
+ event.TimerEvent.Context = timerCbArg;
event.Handler = FunctionEventHandler;
PostEvent(&event);
}
@@ -677,7 +679,7 @@
}
#endif // MATTER_DM_PLUGIN_IDENTIFY_SERVER
-void BaseApplication::LightTimerEventHandler(osTimerId_t xTimer)
+void BaseApplication::LightTimerEventHandler(void * timerCbArg)
{
LightEventHandler();
}
diff --git a/examples/platform/silabs/BaseApplication.h b/examples/platform/silabs/BaseApplication.h
index ffb1f24..e9ca6bf 100644
--- a/examples/platform/silabs/BaseApplication.h
+++ b/examples/platform/silabs/BaseApplication.h
@@ -182,9 +182,9 @@
* @brief Function Timer finished callback function
* Post an FunctionEventHandler event
*
- * @param xTimer timer that finished
+ * @param timerCbArg argument to the timer callback function assigned at timer creation
*/
- static void FunctionTimerEventHandler(osTimerId_t xTimer);
+ static void FunctionTimerEventHandler(void * timerCbArg);
/**
* @brief Timer Event processing function
@@ -207,9 +207,9 @@
* @brief Light Timer finished callback function
* Calls LED processing function
*
- * @param xTimer timer that finished
+ * @param timerCbArg argument to the timer callback function assigned at timer creation
*/
- static void LightTimerEventHandler(osTimerId_t xTimer);
+ static void LightTimerEventHandler(void * timerCbArg);
/**
* @brief Updates device LEDs
diff --git a/examples/pump-app/silabs/include/PumpManager.h b/examples/pump-app/silabs/include/PumpManager.h
index 9a0455d..f66a029 100644
--- a/examples/pump-app/silabs/include/PumpManager.h
+++ b/examples/pump-app/silabs/include/PumpManager.h
@@ -23,11 +23,9 @@
#include "AppEvent.h"
+#include <cmsis_os2.h>
#include <lib/core/CHIPError.h>
-#include <FreeRTOS.h>
-#include <timers.h>
-
#define PCC_CLUSTER_ENDPOINT 1
class PumpManager
@@ -66,13 +64,13 @@
Callback_fn_initiated mActionInitiated_CB;
Callback_fn_completed mActionCompleted_CB;
- TimerHandle_t mTimerHandle;
+ osTimerId_t mTimerHandle;
int32_t mCurrentActor;
void CancelTimer(void);
void PumpTimer(uint32_t aTimeoutMs);
- static void TimerEventHandler(TimerHandle_t aTimer);
+ static void TimerEventHandler(void * timerCbArg);
static void ActuatorMovementTimerEventHandler(AppEvent * aEvent);
static PumpManager sPump;
diff --git a/examples/pump-app/silabs/src/PumpManager.cpp b/examples/pump-app/silabs/src/PumpManager.cpp
index 25ef55a..9f404ff 100644
--- a/examples/pump-app/silabs/src/PumpManager.cpp
+++ b/examples/pump-app/silabs/src/PumpManager.cpp
@@ -21,7 +21,6 @@
#include "AppConfig.h"
#include "AppTask.h"
-#include "FreeRTOS.h"
#define ACTUATOR_MOVEMENT_PERIOS_MS 500
@@ -31,7 +30,7 @@
{
CHIP_ERROR ret = CHIP_NO_ERROR;
- mTimerHandle = xTimerCreate("PumpTmr", pdMS_TO_TICKS(ACTUATOR_MOVEMENT_PERIOS_MS), pdFALSE, this, TimerEventHandler);
+ mTimerHandle = osTimerNew(TimerEventHandler, osTimerOnce, this, NULL);
if (NULL == mTimerHandle)
{
return CHIP_ERROR_INTERNAL;
@@ -95,18 +94,17 @@
void PumpManager::PumpTimer(uint32_t aTimeoutMs)
{
- xTimerChangePeriod(mTimerHandle, pdMS_TO_TICKS(aTimeoutMs), 100);
- xTimerStart(mTimerHandle, 100);
+ osTimerStart(mTimerHandle, pdMS_TO_TICKS(aTimeoutMs));
}
void PumpManager::CancelTimer(void)
{
- xTimerStop(mTimerHandle, 100);
+ osTimerStop(mTimerHandle);
}
-void PumpManager::TimerEventHandler(TimerHandle_t aTimer)
+void PumpManager::TimerEventHandler(void * timerCbArg)
{
- PumpManager * pump = static_cast<PumpManager *>(pvTimerGetTimerID(aTimer));
+ PumpManager * pump = static_cast<PumpManager *>(timerCbArg);
// The timer event handler will be called in the context of the timer task
// once sPumpTimer expires. Post an event to apptask queue with the actual handler
diff --git a/examples/smoke-co-alarm-app/silabs/include/SmokeCoAlarmManager.h b/examples/smoke-co-alarm-app/silabs/include/SmokeCoAlarmManager.h
index b44bbf1..423ca1c 100644
--- a/examples/smoke-co-alarm-app/silabs/include/SmokeCoAlarmManager.h
+++ b/examples/smoke-co-alarm-app/silabs/include/SmokeCoAlarmManager.h
@@ -22,10 +22,8 @@
#include "AppEvent.h"
-#include "FreeRTOS.h"
-#include "timers.h" // provides FreeRTOS timer support
#include <app/clusters/smoke-co-alarm-server/smoke-co-alarm-server.h>
-
+#include <cmsis_os2.h>
#include <lib/core/CHIPError.h>
class SmokeCoAlarmManager
@@ -43,11 +41,12 @@
friend SmokeCoAlarmManager & AlarmMgr(void);
bool mEndSelfTesting;
+ osTimerId_t mAlarmTimer;
void CancelTimer(void);
void StartTimer(uint32_t aTimeoutMs);
- static void TimerEventHandler(TimerHandle_t xTimer);
+ static void TimerEventHandler(void * timerCbArg);
static void EndSelfTestingEventHandler(AppEvent * aEvent);
static SmokeCoAlarmManager sAlarm;
diff --git a/examples/smoke-co-alarm-app/silabs/src/SmokeCoAlarmManager.cpp b/examples/smoke-co-alarm-app/silabs/src/SmokeCoAlarmManager.cpp
index 7d64a03..66eef8a 100644
--- a/examples/smoke-co-alarm-app/silabs/src/SmokeCoAlarmManager.cpp
+++ b/examples/smoke-co-alarm-app/silabs/src/SmokeCoAlarmManager.cpp
@@ -19,7 +19,6 @@
#include "AppConfig.h"
#include "AppTask.h"
-#include <FreeRTOS.h>
#include <app/clusters/smoke-co-alarm-server/SmokeCOTestEventTriggerHandler.h>
#include <lib/support/TypeTraits.h>
@@ -30,8 +29,6 @@
SmokeCoAlarmManager SmokeCoAlarmManager::sAlarm;
-TimerHandle_t sAlarmTimer;
-
static std::array<ExpressedStateEnum, SmokeCoAlarmServer::kPriorityOrderLength> sPriorityOrder = {
ExpressedStateEnum::kSmokeAlarm, ExpressedStateEnum::kInterconnectSmoke, ExpressedStateEnum::kCOAlarm,
ExpressedStateEnum::kInterconnectCO, ExpressedStateEnum::kHardwareFault, ExpressedStateEnum::kTesting,
@@ -40,17 +37,16 @@
CHIP_ERROR SmokeCoAlarmManager::Init()
{
- // Create FreeRTOS sw timer for alarm timer.
- sAlarmTimer = xTimerCreate("alarmTmr", // Just a text name, not used by the RTOS kernel
- pdMS_TO_TICKS(1), // == default timer period
- false, // no timer reload (==one-shot)
- (void *) this, // init timer id = alarm obj context
- TimerEventHandler // timer callback handler
+ // Create cmsisos sw timer for alarm timer.
+ mAlarmTimer = osTimerNew(TimerEventHandler, // timer callback handler
+ osTimerOnce, // no timer reload (one-shot timer)
+ this, // pass the app task obj context
+ NULL // No osTimerAttr_t to provide.
);
- if (sAlarmTimer == NULL)
+ if (mAlarmTimer == NULL)
{
- SILABS_LOG("sAlarmTimer timer create failed");
+ SILABS_LOG("mAlarmTimer timer create failed");
return APP_ERROR_CREATE_TIMER_FAILED;
}
@@ -66,38 +62,30 @@
void SmokeCoAlarmManager::StartTimer(uint32_t aTimeoutMs)
{
- if (xTimerIsTimerActive(sAlarmTimer))
+ // Starts or restarts the function timer
+ if (osTimerStart(mAlarmTimer, pdMS_TO_TICKS(aTimeoutMs)) != osOK)
{
- SILABS_LOG("app timer already started!");
- CancelTimer();
- }
-
- // timer is not active, change its period to required value (== restart).
- // FreeRTOS- Block for a maximum of 100 ms if the change period command
- // cannot immediately be sent to the timer command queue.
- if (xTimerChangePeriod(sAlarmTimer, pdMS_TO_TICKS(aTimeoutMs), pdMS_TO_TICKS(100)) != pdPASS)
- {
- SILABS_LOG("sAlarmTimer timer start() failed");
+ SILABS_LOG("mAlarmTimer timer start() failed");
appError(APP_ERROR_START_TIMER_FAILED);
}
}
void SmokeCoAlarmManager::CancelTimer(void)
{
- if (xTimerStop(sAlarmTimer, pdMS_TO_TICKS(0)) == pdFAIL)
+ if (osTimerStop(mAlarmTimer) == osError)
{
- SILABS_LOG("sAlarmTimer stop() failed");
+ SILABS_LOG("mAlarmTimer stop() failed");
appError(APP_ERROR_STOP_TIMER_FAILED);
}
}
-void SmokeCoAlarmManager::TimerEventHandler(TimerHandle_t xTimer)
+void SmokeCoAlarmManager::TimerEventHandler(void * timerCbArg)
{
// Get alarm obj context from timer id.
- SmokeCoAlarmManager * alarm = static_cast<SmokeCoAlarmManager *>(pvTimerGetTimerID(xTimer));
+ SmokeCoAlarmManager * alarm = static_cast<SmokeCoAlarmManager *>(timerCbArg);
// The timer event handler will be called in the context of the timer task
- // once sAlarmTimer expires. Post an event to apptask queue with the actual handler
+ // once mAlarmTimer expires. Post an event to apptask queue with the actual handler
// so that the event can be handled in the context of the apptask.
AppEvent event;
event.Type = AppEvent::kEventType_Timer;
diff --git a/examples/thermostat/silabs/include/SensorManager.h b/examples/thermostat/silabs/include/SensorManager.h
index 9c910ab..03b916d 100644
--- a/examples/thermostat/silabs/include/SensorManager.h
+++ b/examples/thermostat/silabs/include/SensorManager.h
@@ -23,9 +23,8 @@
#include "AppEvent.h"
-#include "FreeRTOS.h"
-#include "timers.h" // provides FreeRTOS timer support
#include <app-common/zap-generated/attributes/Accessors.h>
+#include <cmsis_os2.h>
#include <lib/core/CHIPError.h>
class SensorManager
@@ -36,8 +35,10 @@
private:
friend SensorManager & SensorMgr();
+ osTimerId_t mSensorTimer;
+
// Reads new generated sensor value, stores it, and updates local temperature attribute
- static void SensorTimerEventHandler(TimerHandle_t xTimer);
+ static void SensorTimerEventHandler(void * arg);
static SensorManager sSensorManager;
};
diff --git a/examples/thermostat/silabs/src/SensorManager.cpp b/examples/thermostat/silabs/src/SensorManager.cpp
index 2d2246a..abecd89 100644
--- a/examples/thermostat/silabs/src/SensorManager.cpp
+++ b/examples/thermostat/silabs/src/SensorManager.cpp
@@ -43,10 +43,6 @@
/**********************************************************
* Variable declarations
*********************************************************/
-
-TimerHandle_t sSensorTimer;
-StaticTimer_t sStaticSensorTimerStruct;
-
SensorManager SensorManager::sSensorManager;
#ifndef USE_TEMP_SENSOR
@@ -56,13 +52,12 @@
CHIP_ERROR SensorManager::Init()
{
- // Create FreeRTOS sw timer for temp sensor timer.
- sSensorTimer = xTimerCreateStatic("sensorTmr", pdMS_TO_TICKS(kSensorTImerPeriodMs), true, nullptr, SensorTimerEventHandler,
- &sStaticSensorTimerStruct);
+ // Create cmsisos sw timer for temp sensor timer.
+ mSensorTimer = osTimerNew(SensorTimerEventHandler, osTimerPeriodic, nullptr, nullptr);
- if (sSensorTimer == NULL)
+ if (mSensorTimer == NULL)
{
- SILABS_LOG("sSensorTimer timer create failed");
+ SILABS_LOG("mSensorTimer timer create failed");
return APP_ERROR_CREATE_TIMER_FAILED;
}
@@ -75,15 +70,13 @@
#endif
// Update Temp immediatly at bootup
- SensorTimerEventHandler(sSensorTimer);
-
+ SensorTimerEventHandler(nullptr);
// Trigger periodic update
- xTimerStart(sSensorTimer, portMAX_DELAY);
-
+ osTimerStart(mSensorTimer, pdMS_TO_TICKS(kSensorTImerPeriodMs));
return CHIP_NO_ERROR;
}
-void SensorManager::SensorTimerEventHandler(TimerHandle_t xTimer)
+void SensorManager::SensorTimerEventHandler(void * arg)
{
int16_t temperature = 0;
static int16_t lastTemperature = 0;
diff --git a/examples/window-app/silabs/include/AppConfig.h b/examples/window-app/silabs/include/AppConfig.h
index fce020a..578861f 100644
--- a/examples/window-app/silabs/include/AppConfig.h
+++ b/examples/window-app/silabs/include/AppConfig.h
@@ -23,7 +23,7 @@
// ---- Window Example App Config ----
#define APP_TASK_NAME "APP"
-
+#define APP_EVENT_QUEUE_SIZE 20
#define BLE_DEV_NAME "SiLabs-Window"
#define LCD_SIZE 128
diff --git a/examples/window-app/silabs/include/WindowManager.h b/examples/window-app/silabs/include/WindowManager.h
index bed448d..9faf669 100644
--- a/examples/window-app/silabs/include/WindowManager.h
+++ b/examples/window-app/silabs/include/WindowManager.h
@@ -23,10 +23,8 @@
#include "AppEvent.h"
#include "LEDWidget.h"
-#include <FreeRTOS.h>
+#include <cmsis_os2.h>
#include <string>
-#include <task.h>
-#include <timers.h>
#ifdef DISPLAY_ENABLED
#include <LcdPainter.h>
#endif
@@ -51,10 +49,10 @@
void * mContext = nullptr;
bool mIsActive = false;
- TimerHandle_t mHandler = nullptr;
+ osTimerId_t mHandler = nullptr;
private:
- static void TimerCallback(TimerHandle_t xTimer);
+ static void TimerCallback(void * timerCbArg);
};
struct Cover
diff --git a/examples/window-app/silabs/src/WindowManager.cpp b/examples/window-app/silabs/src/WindowManager.cpp
index 58716b8..197836f 100644
--- a/examples/window-app/silabs/src/WindowManager.cpp
+++ b/examples/window-app/silabs/src/WindowManager.cpp
@@ -29,6 +29,7 @@
#include <app/clusters/window-covering-server/window-covering-server.h>
#include <app/server/OnboardingCodesUtil.h>
+#include <cmsis_os2.h>
#include <lib/core/CHIPError.h>
#include <lib/dnssd/Advertiser.h>
#include <lib/support/CodeUtils.h>
@@ -78,13 +79,8 @@
void WindowManager::Timer::Start()
{
- if (xTimerIsTimerActive(mHandler))
- {
- Stop();
- }
-
- // Timer is not active
- if (xTimerStart(mHandler, pdMS_TO_TICKS(100)) != pdPASS)
+ // Starts or restarts the function timer
+ if (osTimerStart(mHandler, pdMS_TO_TICKS(100)) != osOK)
{
SILABS_LOG("Timer start() failed");
appError(CHIP_ERROR_INTERNAL);
@@ -546,12 +542,12 @@
WindowManager::Timer::Timer(uint32_t timeoutInMs, Callback callback, void * context) : mCallback(callback), mContext(context)
{
- mHandler = xTimerCreate("", // Just a text name, not used by the RTOS kernel
- pdMS_TO_TICKS(timeoutInMs), // == default timer period (mS)
- false, // no timer reload (==one-shot)
- (void *) this, // init timer id = app task obj context
- TimerCallback // timer callback handler
+ mHandler = osTimerNew(TimerCallback, // timer callback handler
+ osTimerOnce, // no timer reload (one-shot timer)
+ this, // pass the app task obj context
+ NULL // No osTimerAttr_t to provide.
);
+
if (mHandler == NULL)
{
SILABS_LOG("Timer create failed");
@@ -562,16 +558,16 @@
void WindowManager::Timer::Stop()
{
mIsActive = false;
- if (xTimerStop(mHandler, pdMS_TO_TICKS(0)) == pdFAIL)
+ if (osTimerStop(mHandler) == osError)
{
SILABS_LOG("Timer stop() failed");
appError(CHIP_ERROR_INTERNAL);
}
}
-void WindowManager::Timer::TimerCallback(TimerHandle_t xTimer)
+void WindowManager::Timer::TimerCallback(void * timerCbArg)
{
- Timer * timer = (Timer *) pvTimerGetTimerID(xTimer);
+ Timer * timer = static_cast<Timer *>(timerCbArg);
if (timer)
{
timer->Timeout();