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:
xYieldRequired = xTaskResumeFromISR( m_softdevice_task );
if( xYieldRequired == pdTRUE )
/* This function gets events from the SoftDevice and processes them. */
static void softdevice_task(void * pvParameter)
if (m_task_hook != NULL)
nrf_sdh_evts_poll(); // Let the handlers run first, in case the EVENT occured before creating this task.
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,
if (xReturned != pdPASS)
NRF_LOG_ERROR("SoftDevice task not created.");
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)?
Very nice questions CheMax,
1) You could have directly handled all the services from this IRQ like a non-RTOS standalone application, then you know, it doesn't look neat to process so much in the interrupts when we can do that better in the RTOS tasks. To answer you question, services are handled in the task.
2) You have pasted the code snippet exactly where this happens. The event handling is done in the task that suspends itself until the SWI interrupt resumes it to process incoming events.
Thank Aryan,I understand that if I want to pass the event of enabling a notification for this service to the task I need, I should use the api function for interrupts (with a suffix FromIsr).For example, this:
static void ads_cds_evt(cds_svc_t *cds_service, cds_svc_evt_t *p_evt)
NRF_LOG_INFO("Incoming event: %d", p_evt->evt_type);
xEventGroupSetBitsFromISR(eAdsFlags, eAdsEvtNtfEnable, NULL);
Is not it?
No, the event handler itself is not called from ISR context, it is called from the task context so you do not need FromISR postfix.
Many thanks, Aryan.In the near future, I may have new questions))).best regards,