Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Questions about freertos examples

Hi, 

I have couple of question regarding ble_app_hrs_freertos example (sdk 14.2)

  • Possible bug - in main() , erase_bonds is a local variable (defined on the  stack). Its pointer is passed as a  task context to the softdevice_task (through nrf_sdh_freertos_init() --> xTaskCreate())
    However, Task handler run is deferred and one can not assure that this pointer is still valid as it is not static/global.

    Its ppossible that its being used this way intentionally as main() never exits and its local variables are never popped out of stack. I'll appreciate if this could be confirmed/corrected.


  • During initialization a logger_thread task is created. This task has priority of 1 but its suspended in its while(1) loop.
    It only resumes in vApplicationIdleHook() which runs in Idle task context with priority 0.

    Doesn't this make logger_thread() practically priority 0 ? Can its logic run within vApplicationIdleHook() context with the same effect in order to save task creation and its associated resources ? How/whether it will affect power optimization ?

    To turn current code-
    static void logger_thread(void * arg)
    {
        UNUSED_PARAMETER(arg);
    
        while (1)
        {
            NRF_LOG_FLUSH();
    
            vTaskSuspend(NULL); // Suspend myself
        }
    }
    #endif //NRF_LOG_ENABLED
    
    /**@brief A function which is hooked to idle task.
     * @note Idle hook must be enabled in FreeRTOS configuration (configUSE_IDLE_HOOK).
     */
    void vApplicationIdleHook( void )
    {
         vTaskResume(m_logger_thread);
    }
    


    To this code
    // remove static void logger_thread(void * arg)
    
    void vApplicationIdleHook( void )
    {
        NRF_LOG_FLUSH();    // Is this one blocking?
    }
    


Thanks

Parents
  • Hi,

    1) You are right, erase_bonds is allocated on stack space but never released as main function never returns. So we can safely pass its address pointer in the whole application after main has started.

    2)  The idea is that the logger thread will run in background only when there are no runnable tasks, hence this was found to be a good way that the ApplicationIdleHook will resume it. But when resumed, it will be running unless any other tasks with priority > 1 becomes runnable. So in short, it is practically a priority 0 task when suspended (Since priority 0 task can only resume it) but once it is resumed, it behaves as priority 1 task until preempted or suspended.

Reply
  • Hi,

    1) You are right, erase_bonds is allocated on stack space but never released as main function never returns. So we can safely pass its address pointer in the whole application after main has started.

    2)  The idea is that the logger thread will run in background only when there are no runnable tasks, hence this was found to be a good way that the ApplicationIdleHook will resume it. But when resumed, it will be running unless any other tasks with priority > 1 becomes runnable. So in short, it is practically a priority 0 task when suspended (Since priority 0 task can only resume it) but once it is resumed, it behaves as priority 1 task until preempted or suspended.

Children
No Data
Related