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

NRF_SDH_DISPATCH_MODEL_APPSH and sync access to flash results.

We are using NRF_SDH_DISPATCH_MODEL_APPSH, and are generally very happy with it (especially for BLE events). However, I'm trying to retrofit error handling around complex code that uses iflash_erase_page, iflash_write without ever checking the results (normally delivered via sys events), and which expects flash to be synchronous (our wrapper functions sleep long enough for operations to complete, and just assumes they worked).

Given that we use NRF_SDH_DISPATCH_MODEL_APPSH, is there any way to poll for the system events that deliver flash results in a busy loop? Or to get the flash operation results in an IRQ context that could be used to release a spin lock?

If I could have BLE events delivered via the APPSH model, and system events delivered via the INTERRUPT model, this would be straight forward for me.

  • Hi,

    The SDH implementation is quite simple and not so flexible, and does not support this. All events are handled the same and must use the same method. On the bright side, the SDH is also quite simple, so if you look at the implementation you can see that the various dispatch models really only impact how nrf_sdh_evts_poll() is called:

    • Using the scheduler dispatch model, it is called by the scheduler.
    • Using interrupt model, it is called by the ISR itself.
    • Using the polling model it is not called by SDH, but instead is called by the application itself.

    If you want to split BLE and system events, you could make a new method, where you check in the ISR if it is a BLE event or a system event. If it is a BLE event, put it in a queue of some sort for later handling. If it is a system event, call the registered event handler immediately (from the ISR).

  • What you are saying makes sense, but the reason that we went to MODEL_APPSH in the first place was that many of our BLE events are large, and there isn't enough space to enqueue them to a safe depth. Is there any way to pull some events out of whereever nrf_sdh_evts_poll() is pulling them from without pulling everything?

    nrf_sdh_evts_poll
  • Hi,

    You could make a split between BLE events and SoC events since this has different queues in the SoftDevice. So you could use separate approaches for sd_evt_get() and sd_ble_evt_get(). But this is the only way. There is no other way to selectively pick events from the SoftDevice.

    I do not immediately see how this can be most easily done, but it is definitely possible. Either by modifying the SDH, or by writing something new.

Related