Skip to content

Commit

Permalink
[Silabs] Change freertos tick to 1024Hz (project-chip#25499)
Browse files Browse the repository at this point in the history
* Change freeRTOS tick rate to 1024hz

* change missing timer calls

* Update timer calls

* restyle

* fix typo

* revert platform config change

* update semaphore calls
  • Loading branch information
mkardous-silabs authored and David Lechner committed Mar 22, 2023
1 parent d2d7443 commit 3b37e89
Show file tree
Hide file tree
Showing 17 changed files with 71 additions and 71 deletions.
8 changes: 4 additions & 4 deletions examples/lighting-app/silabs/SiWx917/src/LightingManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ 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)
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
Expand Down Expand Up @@ -164,9 +164,9 @@ void LightingManager::StartTimer(uint32_t aTimeoutMs)
}

// timer is not active, change its period to required value (== restart).
// FreeRTOS- Block for a maximum of 100 ticks if the change period command
// 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, (aTimeoutMs / portTICK_PERIOD_MS), 100) != pdPASS)
if (xTimerChangePeriod(sLightTimer, pdMS_TO_TICKS(aTimeoutMs), pdMS_TO_TICKS(100)) != pdPASS)
{
SILABS_LOG("sLightTimer timer start() failed");
appError(APP_ERROR_START_TIMER_FAILED);
Expand All @@ -175,7 +175,7 @@ void LightingManager::StartTimer(uint32_t aTimeoutMs)

void LightingManager::CancelTimer(void)
{
if (xTimerStop(sLightTimer, 0) == pdFAIL)
if (xTimerStop(sLightTimer, pdMS_TO_TICKS(0)) == pdFAIL)
{
SILABS_LOG("sLightTimer stop() failed");
appError(APP_ERROR_STOP_TIMER_FAILED);
Expand Down
8 changes: 4 additions & 4 deletions examples/lighting-app/silabs/efr32/src/LightingManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ 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)
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
Expand Down Expand Up @@ -164,9 +164,9 @@ void LightingManager::StartTimer(uint32_t aTimeoutMs)
}

// timer is not active, change its period to required value (== restart).
// FreeRTOS- Block for a maximum of 100 ticks if the change period command
// 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, (aTimeoutMs / portTICK_PERIOD_MS), 100) != pdPASS)
if (xTimerChangePeriod(sLightTimer, pdMS_TO_TICKS(aTimeoutMs), pdMS_TO_TICKS(100)) != pdPASS)
{
SILABS_LOG("sLightTimer timer start() failed");
appError(APP_ERROR_START_TIMER_FAILED);
Expand All @@ -175,7 +175,7 @@ void LightingManager::StartTimer(uint32_t aTimeoutMs)

void LightingManager::CancelTimer(void)
{
if (xTimerStop(sLightTimer, 0) == pdFAIL)
if (xTimerStop(sLightTimer, pdMS_TO_TICKS(0)) == pdFAIL)
{
SILABS_LOG("sLightTimer stop() failed");
appError(APP_ERROR_STOP_TIMER_FAILED);
Expand Down
8 changes: 4 additions & 4 deletions examples/lock-app/silabs/SiWx917/src/LockManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ CHIP_ERROR LockManager::Init(chip::app::DataModel::Nullable<chip::app::Clusters:

// Create FreeRTOS sw timer for lock timer.
sLockTimer = xTimerCreate("lockTmr", // Just a text name, not used by the RTOS kernel
1, // == default timer period (mS)
pdMS_TO_TICKS(1), // == default timer period
false, // no timer reload (==one-shot)
(void *) this, // init timer id = lock obj context
TimerEventHandler // timer callback handler
Expand Down Expand Up @@ -229,9 +229,9 @@ void LockManager::StartTimer(uint32_t aTimeoutMs)
}

// timer is not active, change its period to required value (== restart).
// FreeRTOS- Block for a maximum of 100 ticks if the change period command
// 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, (aTimeoutMs / portTICK_PERIOD_MS), 100) != pdPASS)
if (xTimerChangePeriod(sLockTimer, pdMS_TO_TICKS(aTimeoutMs), pdMS_TO_TICKS(100)) != pdPASS)
{
SILABS_LOG("sLockTimer timer start() failed");
appError(APP_ERROR_START_TIMER_FAILED);
Expand All @@ -240,7 +240,7 @@ void LockManager::StartTimer(uint32_t aTimeoutMs)

void LockManager::CancelTimer(void)
{
if (xTimerStop(sLockTimer, 0) == pdFAIL)
if (xTimerStop(sLockTimer, pdMS_TO_TICKS(0)) == pdFAIL)
{
SILABS_LOG("sLockTimer stop() failed");
appError(APP_ERROR_STOP_TIMER_FAILED);
Expand Down
8 changes: 4 additions & 4 deletions examples/lock-app/silabs/efr32/src/LockManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ CHIP_ERROR LockManager::Init(chip::app::DataModel::Nullable<chip::app::Clusters:

// Create FreeRTOS sw timer for lock timer.
sLockTimer = xTimerCreate("lockTmr", // Just a text name, not used by the RTOS kernel
1, // == default timer period (mS)
1, // == default timer period
false, // no timer reload (==one-shot)
(void *) this, // init timer id = lock obj context
TimerEventHandler // timer callback handler
Expand Down Expand Up @@ -229,9 +229,9 @@ void LockManager::StartTimer(uint32_t aTimeoutMs)
}

// timer is not active, change its period to required value (== restart).
// FreeRTOS- Block for a maximum of 100 ticks if the change period command
// 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, (aTimeoutMs / portTICK_PERIOD_MS), 100) != pdPASS)
if (xTimerChangePeriod(sLockTimer, pdMS_TO_TICKS(aTimeoutMs), pdMS_TO_TICKS(100)) != pdPASS)
{
SILABS_LOG("sLockTimer timer start() failed");
appError(APP_ERROR_START_TIMER_FAILED);
Expand All @@ -240,7 +240,7 @@ void LockManager::StartTimer(uint32_t aTimeoutMs)

void LockManager::CancelTimer(void)
{
if (xTimerStop(sLockTimer, 0) == pdFAIL)
if (xTimerStop(sLockTimer, pdMS_TO_TICKS(0)) == pdFAIL)
{
SILABS_LOG("sLockTimer stop() failed");
appError(APP_ERROR_STOP_TIMER_FAILED);
Expand Down
2 changes: 1 addition & 1 deletion examples/platform/silabs/Rpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class Efr32Device final : public Device
pw::Status Reboot(const pw_protobuf_Empty & request, pw_protobuf_Empty & response) override
{
mRebootTimer = xTimerCreateStatic("Reboot", kRebootTimerPeriodTicks, false, nullptr, RebootHandler, &mRebootTimerBuffer);
xTimerStart(mRebootTimer, 0);
xTimerStart(mRebootTimer, pdMS_TO_TICKS(0));
return pw::OkStatus();
}

Expand Down
14 changes: 7 additions & 7 deletions examples/platform/silabs/SiWx917/BaseApplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ CHIP_ERROR BaseApplication::Init(Identify * identifyObj)

// Create FreeRTOS sw timer for Function Selection.
sFunctionTimer = xTimerCreate("FnTmr", // Just a text name, not used by the RTOS kernel
1, // == default timer period (mS)
pdMS_TO_TICKS(1), // == default timer period
false, // no timer reload (==one-shot)
(void *) this, // init timer id = app task obj context
FunctionTimerEventHandler // timer callback handler
Expand All @@ -190,7 +190,7 @@ CHIP_ERROR BaseApplication::Init(Identify * identifyObj)

// Create FreeRTOS sw timer for LED Management.
sLightTimer = xTimerCreate("LightTmr", // Text Name
10, // Default timer period (mS)
pdMS_TO_TICKS(10), // Default timer period
true, // reload timer
(void *) this, // Timer Id
LightTimerEventHandler // Timer callback handler
Expand Down Expand Up @@ -426,7 +426,7 @@ void BaseApplication::ButtonHandler(AppEvent * aEvent)

void BaseApplication::CancelFunctionTimer()
{
if (xTimerStop(sFunctionTimer, 0) == pdFAIL)
if (xTimerStop(sFunctionTimer, pdMS_TO_TICKS(0)) == pdFAIL)
{
SILABS_LOG("app timer stop() failed");
appError(APP_ERROR_STOP_TIMER_FAILED);
Expand All @@ -444,9 +444,9 @@ void BaseApplication::StartFunctionTimer(uint32_t aTimeoutInMs)
}

// timer is not active, change its period to required value (== restart).
// FreeRTOS- Block for a maximum of 100 ticks if the change period command
// FreeRTOS- Block for a maximum of 100 ms if the change period command
// cannot immediately be sent to the timer command queue.
if (xTimerChangePeriod(sFunctionTimer, aTimeoutInMs / portTICK_PERIOD_MS, 100) != pdPASS)
if (xTimerChangePeriod(sFunctionTimer, pdMS_TO_TICKS(aTimeoutInMs), pdMS_TO_TICKS(100)) != pdPASS)
{
SILABS_LOG("app timer start() failed");
appError(APP_ERROR_START_TIMER_FAILED);
Expand All @@ -457,7 +457,7 @@ void BaseApplication::StartFunctionTimer(uint32_t aTimeoutInMs)

void BaseApplication::StartStatusLEDTimer()
{
if (pdPASS != xTimerStart(sLightTimer, 0))
if (pdPASS != xTimerStart(sLightTimer, pdMS_TO_TICKS(0)))
{
SILABS_LOG("Light Time start failed");
appError(APP_ERROR_START_TIMER_FAILED);
Expand All @@ -470,7 +470,7 @@ void BaseApplication::StopStatusLEDTimer()
sStatusLED.Set(false);
#endif // ENABLE_WSTK_LEDS

if (xTimerStop(sLightTimer, 100) != pdPASS)
if (xTimerStop(sLightTimer, pdMS_TO_TICKS(100)) != pdPASS)
{
SILABS_LOG("Light Time start failed");
appError(APP_ERROR_START_TIMER_FAILED);
Expand Down
14 changes: 7 additions & 7 deletions examples/platform/silabs/efr32/BaseApplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ CHIP_ERROR BaseApplication::Init(Identify * identifyObj)

// Create FreeRTOS sw timer for Function Selection.
sFunctionTimer = xTimerCreate("FnTmr", // Just a text name, not used by the RTOS kernel
1, // == default timer period (mS)
pdMS_TO_TICKS(1), // == default timer period
false, // no timer reload (==one-shot)
(void *) this, // init timer id = app task obj context
FunctionTimerEventHandler // timer callback handler
Expand All @@ -196,7 +196,7 @@ CHIP_ERROR BaseApplication::Init(Identify * identifyObj)

// Create FreeRTOS sw timer for LED Management.
sLightTimer = xTimerCreate("LightTmr", // Text Name
10, // Default timer period (mS)
pdMS_TO_TICKS(10), // Default timer period
true, // reload timer
(void *) this, // Timer Id
LightTimerEventHandler // Timer callback handler
Expand Down Expand Up @@ -463,7 +463,7 @@ void BaseApplication::ButtonHandler(AppEvent * aEvent)
#endif
void BaseApplication::CancelFunctionTimer()
{
if (xTimerStop(sFunctionTimer, 0) == pdFAIL)
if (xTimerStop(sFunctionTimer, pdMS_TO_TICKS(0)) == pdFAIL)
{
SILABS_LOG("app timer stop() failed");
appError(APP_ERROR_STOP_TIMER_FAILED);
Expand All @@ -481,9 +481,9 @@ void BaseApplication::StartFunctionTimer(uint32_t aTimeoutInMs)
}

// timer is not active, change its period to required value (== restart).
// FreeRTOS- Block for a maximum of 100 ticks if the change period command
// FreeRTOS- Block for a maximum of 100 ms if the change period command
// cannot immediately be sent to the timer command queue.
if (xTimerChangePeriod(sFunctionTimer, aTimeoutInMs / portTICK_PERIOD_MS, 100) != pdPASS)
if (xTimerChangePeriod(sFunctionTimer, pdMS_TO_TICKS(aTimeoutInMs), pdMS_TO_TICKS(100)) != pdPASS)
{
SILABS_LOG("app timer start() failed");
appError(APP_ERROR_START_TIMER_FAILED);
Expand All @@ -494,7 +494,7 @@ void BaseApplication::StartFunctionTimer(uint32_t aTimeoutInMs)

void BaseApplication::StartStatusLEDTimer()
{
if (pdPASS != xTimerStart(sLightTimer, 0))
if (pdPASS != xTimerStart(sLightTimer, pdMS_TO_TICKS(0)))
{
SILABS_LOG("Light Time start failed");
appError(APP_ERROR_START_TIMER_FAILED);
Expand All @@ -507,7 +507,7 @@ void BaseApplication::StopStatusLEDTimer()
sStatusLED.Set(false);
#endif // ENABLE_WSTK_LEDS

if (xTimerStop(sLightTimer, 100) != pdPASS)
if (xTimerStop(sLightTimer, pdMS_TO_TICKS(100)) != pdPASS)
{
SILABS_LOG("Light Time start failed");
appError(APP_ERROR_START_TIMER_FAILED);
Expand Down
2 changes: 1 addition & 1 deletion examples/platform/silabs/efr32/FreeRTOSConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ extern "C" {
#define configUSE_TICKLESS_IDLE 0
#endif // SL_CATALOG_POWER_MANAGER_PRESENT

#define configTICK_RATE_HZ (1000)
#define configTICK_RATE_HZ (1024)
/* Definition used by Keil to replace default system clock source. */
#define configOVERRIDE_DEFAULT_TICK_CONFIGURATION 1

Expand Down
6 changes: 3 additions & 3 deletions examples/platform/silabs/efr32/wf200/wf200_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +320,8 @@ sl_status_t sl_wfx_host_reset_chip(void)
*****************************************************************************/
sl_status_t sl_wfx_host_wait_for_wake_up(void)
{
xSemaphoreTake(wfx_wakeup_sem, TICKS_TO_WAIT_0);
xSemaphoreTake(wfx_wakeup_sem, TICKS_TO_WAIT_3 / portTICK_PERIOD_MS);
xSemaphoreTake(wfx_wakeup_sem, pdMS_TO_TICKS(TICKS_TO_WAIT_0));
xSemaphoreTake(wfx_wakeup_sem, pdMS_TO_TICKS(TICKS_TO_WAIT_3));

return SL_STATUS_OK;
}
Expand Down Expand Up @@ -418,7 +418,7 @@ sl_status_t sl_wfx_host_lock(void)

sl_status_t status = SL_STATUS_OK;

if (xSemaphoreTake(wfx_mutex, TICKS_TO_WAIT_500) != pdTRUE)
if (xSemaphoreTake(wfx_mutex, pdMS_TO_TICKS(TICKS_TO_WAIT_500)) != pdTRUE)
{
SILABS_LOG("*ERR*Wi-Fi driver mutex timo");
status = SL_STATUS_TIMEOUT;
Expand Down
2 changes: 1 addition & 1 deletion examples/platform/silabs/matter_shell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ void MatterShellTask(void * args)

extern "C" unsigned int sleep(unsigned int seconds)
{
const TickType_t xDelay = 1000 * seconds / portTICK_PERIOD_MS;
const TickType_t xDelay = pdMS_TO_TICKS(1000 * seconds);
vTaskDelay(xDelay);
return 0;
}
Expand Down
14 changes: 7 additions & 7 deletions examples/window-app/silabs/SiWx917/src/WindowAppImpl.cpp
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ chip::app::Clusters::NetworkCommissioning::Instance
WindowAppImpl::Timer::Timer(const char * name, uint32_t timeoutInMs, Callback callback, void * context) :
WindowApp::Timer(name, timeoutInMs, callback, context)
{
mHandler = xTimerCreate(name, // Just a text name, not used by the RTOS kernel
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 = xTimerCreate(name, // Just a text name, not used by the RTOS kernel
pdMS_TO_TICKS(timeoutInMs), // == default timer period
false, // no timer reload (==one-shot)
(void *) this, // init timer id = app task obj context
TimerCallback // timer callback handler
);
if (mHandler == NULL)
{
Expand All @@ -90,7 +90,7 @@ void WindowAppImpl::Timer::Start()
}

// Timer is not active
if (xTimerStart(mHandler, 100) != pdPASS)
if (xTimerStart(mHandler, pdMS_TO_TICKS(100)) != pdPASS)
{
SILABS_LOG("Timer start() failed");
appError(CHIP_ERROR_INTERNAL);
Expand All @@ -115,7 +115,7 @@ void WindowAppImpl::Timer::IsrStart()
void WindowAppImpl::Timer::Stop()
{
mIsActive = false;
if (xTimerStop(mHandler, 0) == pdFAIL)
if (xTimerStop(mHandler, pdMS_TO_TICKS(0)) == pdFAIL)
{
SILABS_LOG("Timer stop() failed");
appError(CHIP_ERROR_INTERNAL);
Expand Down
14 changes: 7 additions & 7 deletions examples/window-app/silabs/efr32/src/WindowAppImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ chip::app::Clusters::NetworkCommissioning::Instance
WindowAppImpl::Timer::Timer(const char * name, uint32_t timeoutInMs, Callback callback, void * context) :
WindowApp::Timer(name, timeoutInMs, callback, context)
{
mHandler = xTimerCreate(name, // Just a text name, not used by the RTOS kernel
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 = xTimerCreate(name, // 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
);
if (mHandler == NULL)
{
Expand All @@ -95,7 +95,7 @@ void WindowAppImpl::Timer::Start()
}

// Timer is not active
if (xTimerStart(mHandler, 100) != pdPASS)
if (xTimerStart(mHandler, pdMS_TO_TICKS(100)) != pdPASS)
{
SILABS_LOG("Timer start() failed");
appError(CHIP_ERROR_INTERNAL);
Expand All @@ -120,7 +120,7 @@ void WindowAppImpl::Timer::IsrStart()
void WindowAppImpl::Timer::Stop()
{
mIsActive = false;
if (xTimerStop(mHandler, 0) == pdFAIL)
if (xTimerStop(mHandler, pdMS_TO_TICKS(0)) == pdFAIL)
{
SILABS_LOG("Timer stop() failed");
appError(CHIP_ERROR_INTERNAL);
Expand Down
Loading

0 comments on commit 3b37e89

Please sign in to comment.