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

How does softdevice work?

For a Non-RTOS application, take ble_app_blinky for example, the application is coded by us while SD is provided by Nordic.

My understanding is that the SD is running as a thread, just like a infinite loop running background focusing on managing the radio stuff.

The SD thread is started by nrf_sdh_ble_enable(), after this the thread is running  infinitely.

It receives instructions from application through SVC, and posts events to application by SWI.

But you know there is no RTOS, and NRF52 chip has only one core, how to make sure the application won't disturb the softdevice? 

Like application is playing many hardware interrupts, the interrupts will occupy cpu and  break SD thread.

Please correct me if I'm wrong.Thanks.

  • Hi,

    My understanding is that the SD is running as a thread, just like a infinite loop running background focusing on managing the radio stuff.

    SD is just a library with API implemented via SVC calls. Events are read by application using sd_ble_evt_get(). It has no running threads, all hardware activities are handled within interrupts.

    Like application is playing many hardware interrupts, the interrupts will occupy cpu and  break SD thread.

    Interrupts handled by SD have highest priority, so you cannot break SD if you aren't disabling inerrupts globally for a long time.

  • "Events are read by application using sd_ble_evt_get()." Is this true?

    What I see is that SD notify to application by SWI, not application read the event. Please clarify.

    If there is no thread running, when PHY layer receives air data, it will send to Link Layer, who is handling that?

    I suppose SD is a program  that process the low level data and implements the receiving and transimission.

    If SD have the highest priority, how to make sure application is able to play time-critical cases?

    So what does SD do exactly?

  • What I see is that SD notify to application by SWI, not application read the event. Please clarify.

    Yes, SD notifies application by SWI: "I have an event for you", then application should fetch an event with sd_ble_evt_get().

    If there is no thread running, when PHY layer receives air data, it will send to Link Layer, who is handling that?

    Non-time-critical tasks are scheduled as lower priority interrupts, see SoftDevice specification. Sorry, I have no information how it's implemented internally.

    If SD have the highest priority, how to make sure application is able to play time-critical cases?

    Actually, it's painful. For real-time tasks, you can use timeslot API to ask SD for an uninterrrupted slot, or radio notifications that notify applications at least 5500 usec before SD takes control. Or you can disable interrupts (run your code in a critical section) with a chance to get SD assertion right after. Or use dual-core nrf5340 Slight smile

Related