This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Is the ble_evt_handler reentrant

I'm using nRF51(822) with S130. I registered my event handler with:

softdevice_ble_evt_handler_set(ble_evt_dispatch);

In my main loop, I call sd_app_evt_wait();

Now, is it possible that my ble_evt_dispatch would get called while "it is already running"?

  • Hello Jonathan

    When the Softdevice generates an event an interrupt is executed, which calls SOFTDEVICE_EVT_IRQHandler. This again calls the intern_softdevice_events_execute, which will fetch events from the Softdevice. For every event it fetches it will call your ble_evt_dispatch function to handle the event. After your handler is finished dealing with the current event it will fetch the next one. It will continue to fetch events from the Softdevice until it gets a NRF_ERROR_NOT_FOUND, signaling there are no more events.

    As such it doesn't call your ble_evt_dispatch while it is running, but the Softdevice could generate more events, which would simply add to the queue.

    EDIT 28.04.17:

    On the Softdevice interrupt handling please see infocenter.nordicsemi.com/index.jsp

    When there are events for the application the Softdevice will trigger an interrupt, the softdevice's interrupt routine will inspect it, see it means there are BLE events for the application and then hand control over to the SOFTDEVICE_EVT_IRQHandler. From there you end up in the routine I described above where events are fetched with the sd_ble_evt_get() function and executed one by one, by your handler. Since the interrupt that calls the ble_evt_dispatch handler is always of the same priority, ble_evt_dispatch will never be called if it is already running. What can happen is an interrupt of higher priority can add events to the queue of events, that your dispatch is working on. So the queue can grow while you are handling it. Once the queue is empty the interrupt will finish. Only then can the interrupt that executes ble_evt_dispatch be called again.

    Best regards

    Jørn Frøysa

  • Thanks for your answer! However, I'm not sure I fully understand it. Does that mean, roughly, that the IRQ handler just queues the event, while event dispatching will be later performed outside of any IRQ handler? (And then, would the dispatching be done in sd_app_evt_wait ?)

  • I have updated my answer to provide more details.

Related