I'am currently porting an existing application that makes extensive use of the app_scheduler to FreeRTOS. To speed up the migration I have enabled the app_scheduler in the new project and created a scheduler thread that runs at lowest priority:
static void scheduler_thread(void * arg){ UNUSED_PARAMETER(arg); NRF_LOG_INFO("Starting scheduler thread") while(1) { app_sched_execute(); vTaskSuspend(NULL); } }
I am using the vApplicationIdleHook to resume this scheduler thread.
Furthermore I have added scheduler support to app_timer_freertos.c:
static void app_timer_callback(TimerHandle_t xTimer) { app_timer_info_t * pinfo = (app_timer_info_t*)(pvTimerGetTimerID(xTimer)); ASSERT(pinfo->osHandle == xTimer); ASSERT(pinfo->func != NULL); if (pinfo->active) { pinfo->active = (pinfo->single_shot) ? false : true; #if APP_TIMER_CONFIG_USE_SCHEDULER app_timer_event_t timer_event; timer_event.timeout_handler = pinfo->func; timer_event.p_context = pinfo->argument; uint32_t err_code = app_sched_event_put(&timer_event, sizeof(timer_event), timeout_handler_scheduled_exec); APP_ERROR_CHECK(err_code); #else pinfo->func(pinfo->argument); #endif } }
With these changes the old scheduler based application now seems to run flawlessly under FreeRTOS. Is this a smart way to go, or am I missing something?