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

Service event handler: IRQ callback or FreeRTOS task?

I want to fully understand the use of RTOS in conjunction with the stack.

As an example, I took an example ble_app_hrs_freertos (SDK v15.0).

Add a service, for example, BAS.

Event handler for this service:

void ble_bas_on_ble_evt(ble_evt_t const * p_ble_evt, void * p_context)
{ 
    ... 
}

When start the project, a task is created to handle the SD events:

void SD_EVT_IRQHandler(void)
{
     BaseType_t xYieldRequired;

     xYieldRequired = xTaskResumeFromISR( m_softdevice_task );

     if( xYieldRequired == pdTRUE )
     {
         portYIELD_FROM_ISR(xYieldRequired);
     }
}


/* This function gets events from the SoftDevice and processes them. */
static void softdevice_task(void * pvParameter)
{
    NRF_LOG_DEBUG("Enter softdevice_task.");

    if (m_task_hook != NULL)
    {
        m_task_hook(pvParameter);
    }

    while (true)
    {
        nrf_sdh_evts_poll(); // Let the handlers run first, in case the EVENT occured before creating this task.
        vTaskSuspend(NULL);
    }
}


void nrf_sdh_freertos_init(nrf_sdh_freertos_task_hook_t hook_fn, void * p_context)
{
    NRF_LOG_DEBUG("Creating a SoftDevice task.");

    m_task_hook = hook_fn;

    BaseType_t xReturned = xTaskCreate(softdevice_task,
                                       "BLE",
                                       NRF_BLE_FREERTOS_SDH_TASK_STACK,
                                       p_context,
                                       2,
                                       &m_softdevice_task);
    if (xReturned != pdPASS)
    {
        NRF_LOG_ERROR("SoftDevice task not created.");
        APP_ERROR_HANDLER(NRF_ERROR_NO_MEM);
    }
}

So, question:


1. Handlers for services are called from this task or earlier, from an interrupt?

2. Event handler for service it's IRQ callback or RTOS callback (callback from softdevice_task)?

Thanks,

Parents Reply Children
  • Many thanks,

    In the near future, I may have new questions))).

    best regards,

    Max

  • Hello Aryan,

    I'm facing the same questions as - Do all interrupts captured by the softdevice and serviced by the application in the event handlers in a (freertos) task context ?

    Specifically I would like to verify that:

    • GPIO interrupts - serviced in freertos task context in a callback registered by nrf_drv_gpiote_in_init() ?
    • UART interrupts - serviced in freertos task context in a callback registered by NRF_SERIAL_CONFIG_DEF() macro ?
    • TWI interrupts - serviced in freertos task context in a callback registered in nrf_drv_twi_init() ?
    • SPI interrupt - serviced in freertos task context in a callback registered by NRF_SPI_MNGR_TRANSACTION_SET_DEFAULT() macro ?

    If this is indeed the case, in what scenario will callback run in a 'true' interrupt context (ISR)with/without softdevice. On what conditions should I use freertos'  _fromISR() api ?

    Many thanks in advance

  • Hi  ;

    Can you find any answer about this question? I got error during freertos and spi?

    Thanks.

  • My question was not connected with the periphery, but with callback functions for services. this is essentially part of the stack. And in my case, I do not use the library from NRF to work with peripherals. so I can not say exactly how it will be with interrupts.

    I independently fully configure and control the periphery, including enabling and describing the interrupt vector. in this case I am forced to use the function _FromISR.

    I can assume that the callback functions you describe are not called in the context of the operating system. and therefore it is necessary to use the suffix _FromISR.

Related