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

BLE with FreeRTOS, user events

A plain question : we are using the BLE stack with FreeRTOS based observers.

Is it possible to send to some observer an application defined event from some other FreeRTOS task.

Parents
  • Hi,

    One of my colleagues who's experienced with Freertos said it was best to use existing OS module to achieve the event-observer communication between threads.

    https://www.freertos.org/Inter-Task-Communication.html

  • OK I see. So the way to make it would be to register some stack observer function the context of which would contain e.g. some FreeRTOS queue, and the function would peek this queue everytime the observer handler is called.

    Is this what you have in mind ?

    Then I understand that the definition of NRF_SDH_STACK_OBSERVER_PRIO_LEVELS by default to 2, while NRF_SDH_BLE_STACK_OBSERVER_PRIO is by default defined to 0, suggests that priority 1 can be used for application specific sdh stack observers.

    Is that correct ?

    But then we have limitation with nrf_sdh_freertos.c : m_softdevice_task is declared static (in C jargon local to this file), so it is not visible outside, so the task cannot be notified from another FreeRTOS task just by calling xTaskNotifyGive(m_softdevice_task), for our application specific SDH stack observer to come in action. Maybe the following patch could help:

    diff --git a/components/softdevice/common/nrf_sdh_freertos.c b/components/softdevice/common/nrf_sdh_freertos.c
    index dccb811..27b83a0 100644
    --- a/components/softdevice/common/nrf_sdh_freertos.c
    +++ b/components/softdevice/common/nrf_sdh_freertos.c
    @@ -57,6 +57,10 @@ NRF_LOG_MODULE_REGISTER();
     static TaskHandle_t                 m_softdevice_task;  //!< Reference to SoftDevice FreeRTOS task.
     static nrf_sdh_freertos_task_hook_t m_task_hook;        //!< A hook function run by the SoftDevice task before entering its loop.
     
    +void nrf_sdh_freertos_notify(void)
    +{
    +    xTaskNotifyGive(m_softdevice_task);
    +}
     
     void SD_EVT_IRQHandler(void)
     {
    diff --git a/components/softdevice/common/nrf_sdh_freertos.h b/components/softdevice/common/nrf_sdh_freertos.h
    index db1e9c4..8abb1cb 100644
    --- a/components/softdevice/common/nrf_sdh_freertos.h
    +++ b/components/softdevice/common/nrf_sdh_freertos.h
    @@ -60,6 +60,8 @@ typedef void (*nrf_sdh_freertos_task_hook_t)(void * p_context);
      */
     void nrf_sdh_freertos_init(nrf_sdh_freertos_task_hook_t hook, void * p_context);
     
    +void nrf_sdh_freertos_notify(void);
    +
     /**
      * @}
      */
    

  • I misread your question, I thought you were referring to custom app events defined by you, not Softdevice events from the Softdevice handler libary. Anyway. You can define as many observers as you like outside nrf_sdh_freertos.c  file(within reasonable limits of course), does that help?

    Then I understand that the definition of NRF_SDH_STACK_OBSERVER_PRIO_LEVELS by default to 2, while NRF_SDH_BLE_STACK_OBSERVER_PRIO is by default defined to 0, suggests that priority 1 can be used for application specific sdh stack observers.

     This defines the order of which the observers are stored in memory, and hence in what order they called. It's not related to OS task priorities (Registering section set variables, Assigning priorities).

  • Thank you  for the answer.

    I definitely was referring to custom app events.

    The only reason why I was mentioning SDH stack observers was to use an observer like a hook function to be processed within the nrf_sdh_freertos task main loop, and this hook function could be used to check for any suitable FreeRTOS inter-thread communication objects.

Reply Children
No Data
Related