I have some functions that use FreeRTOS calls if the scheduler is running, and other calls if not.
While I certainly could set a global when I call vTaskStartScheduler
, is there a reliable way to ask FreeRTOS if its scheduler has been started?
I have some functions that use FreeRTOS calls if the scheduler is running, and other calls if not.
While I certainly could set a global when I call vTaskStartScheduler
, is there a reliable way to ask FreeRTOS if its scheduler has been started?
There is xTaskGetSchedulerState available if INCLUDE_xTaskGetSchedulerState
is enabled.
Perfect – that’s exactly what’s needed. In particular:
static void bsp_delay_ms(bsp_duration_t ms) {
if (xTaskGetSchedulerState() == taskSCHEDULER_NOT_STARTED) {
delay_ms(ms);
} else {
vTaskDelay(pdMS_TO_TICKS(ms));
}
}