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

Know when softdevice takes control

Hi,

I got a unit based on NRF52 (No matter what SDK) which is connected via 1-wire (dallas protocol which is very time accurate) to other unit.

The other unit is the master and my unit is the slave

when the other unit start to communicate with my unit (asynchrony) every few seconds my unit gets an gpiote interrupt.

i want the unit to check how much time left to the next softdevice activity which will stop my application (and my interrupt) and takes control (and ruin the data).

(Something like to check (Compare value of RTC0 - current RTC0) 

if the time is too short for the next softdevice interrupt then my unit will not answer the master (which is ok by me !)

But if the time is OK (about 3-4ms or more) the unit should answer the master and then the unit must be sure there are NO interrupts by the softdevice or anything else !

(Btw: if needed, Is it possible to stop scanning when entering an interrupt and start it back when finish ?!) (In order not to get SCAN RADIO interrupt)

(I assume that all other BLE interrupt are based on RTC0 ?!)

What other interrupt except RTC0 and RADIO can stop my application gpiote interrupt ?

Again ! If the unit decides to answers the master , There must be no interrupts !!

B.r,

Yuval.

Parents
  • Hello,

    There is no way of "fetching" the remaining time before the softdevice will take over. 

    However, there is something called "Radio Notifications". Please check out the Radio Notification guide. Using this, you can set it up so that you get an event at up to 5.5ms before the softdevice will take control. You can use this event to start a timer that you can read to see if there is enough time left to handle your 1-wire protocol. 

    You can't set the radio notification events to whatever time you like, but you can choose from a set of predefined distances:

    NRF_RADIO_NOTIFICATION_DISTANCE_NONE = 0, /** The event does not have a notification. */
      NRF_RADIO_NOTIFICATION_DISTANCE_800US,    /** The distance from the active notification to start of radio activity. */
      NRF_RADIO_NOTIFICATION_DISTANCE_1740US,   /** The distance from the active notification to start of radio activity. */
      NRF_RADIO_NOTIFICATION_DISTANCE_2680US,   /** The distance from the active notification to start of radio activity. */
      NRF_RADIO_NOTIFICATION_DISTANCE_3620US,   /** The distance from the active notification to start of radio activity. */
      NRF_RADIO_NOTIFICATION_DISTANCE_4560US,   /** The distance from the active notification to start of radio activity. */
      NRF_RADIO_NOTIFICATION_DISTANCE_5500US    /** The distance from the active notification to start of radio activity. */
    };

    You would need to time these, because you will not get any events at the time of the event. But perhaps, if you know that you need more than 2680µs, you can set a flag in this event, saying you will ignore the 1-wire interrupt, but if you start a timer that will time out in 2680µs, you know that after this timeout, and before you get the next radio notification event, you can safely handle the 1-wire protocol interrupts. 

    Other than that, there is something called timeslot api, but I don't think this is as useful in your case. What it does is to request and handle timeslots that you know for sure that the softdevice will not interupt you. But you need to know in advance when you want to request these. So if you don't know this, it may be a bit tricky. You could of course request these timeslots all the time, and only respond to the 1-wire protocol interrupts if they occur in one of these timeslots. You can read about the Timeslot API here

    Best regards,

    Edvin

  • Thanks for the answer,

    I just want to know : If my unit is scanning (as central) and there is a peripheral who advertise. Do the softdevice will interrupt my application immediately when receiving the advertised packet ?! (If so, i can't count on the Radio notification !)

    B.r,

    Yuval.

  • That is a good question.

    In the case of scanning, the softdevice doesn't know when it will pick up an advertisement, as you say. I don't think you can use the radio notifications for this while you are scanning, I am afraid. Perhaps the only viable option is timeslots, then. In that case you need to ask for timeslots as often as you can, and then only process the 1-wire protocol interrupts if they are within a timeslot, and you see that there is enough time left of the timeslot. You can check out the Setting up Timeslot API guide.

    The radio notifications will only give an interrupt before the start of the scan window. The softdevice wouldn't be able to predict when an incoming advertising report will occur.

    Best regards,

    Edvin

  • The timeslots have a timer that will trigger an interrupt when there is 100µs left. You can at any point capture this timer and check how long much time you have left. From the guide:

    ----------------------------------------------

    NRF_RADIO_CALLBACK_SIGNAL_TYPE_START - The start of the timeslot. The application now has access to peripherals for the length of the timeslot. Before you start initializing your timeslot you must use a timer(for example TIMER0) that triggers an event 100 µs or so before the timeslot expires. TIMER0 is started automatically from zero by the SoftDevice at the start of the timeslot and is configured to run at 1 MHz. If you do not manage to do graceful shutdown by the end of the timeslot your application will hardfault.

    ----------------------------------------------

Reply
  • The timeslots have a timer that will trigger an interrupt when there is 100µs left. You can at any point capture this timer and check how long much time you have left. From the guide:

    ----------------------------------------------

    NRF_RADIO_CALLBACK_SIGNAL_TYPE_START - The start of the timeslot. The application now has access to peripherals for the length of the timeslot. Before you start initializing your timeslot you must use a timer(for example TIMER0) that triggers an event 100 µs or so before the timeslot expires. TIMER0 is started automatically from zero by the SoftDevice at the start of the timeslot and is configured to run at 1 MHz. If you do not manage to do graceful shutdown by the end of the timeslot your application will hardfault.

    ----------------------------------------------

Children
No Data
Related