How to register sleep call back function to stack?

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

In Wiced SDK 2.0.1 with 20736,

I'm implementing sleep and deep sleep mode.

My scenario is to make the board sleep after connection is done and execute when wakeup.

I have several questions.

1. To enter sleep mode

    Documents and posts say the firmware automatically find a right power mode, so all I have to do is to add 2 functions in thread    

    creation - devlpm_init and devlpm_registerForLowPowerQueries.

    But after putting several more functions, then board goes to sleep.

    -bleprofile_PrepareHidOff,

      bleprofile_enteringDiscLowPowerMode(DEV_LPM_DISC_LOW_POWER_MODES_SLEEP);

      mia_enterHidOff(0xFFF, devLpmConfig.wakeFromHidoffRefClk); // for 4sec interval

     bleprofile_abortingDiscLowPowerMode(DEV_LPM_DISC_LOW_POWER_MODES_SLEEP);

    Is it right?

2. I saw the HELP BLOG which describes sleep/deep sleep mode .

    As I understood, created thread does not anything during sleep but wakeup which is registered in stack.

   what is the way to register the function which should be done during wakeup?

3. I want to make the board enter sleep mode after connection is done.

    Can you give me the guidance or document?

Thank you.

1 Solution
asridharan
Employee
Employee
10 comments on KBA 5 comments on KBA First comment on KBA

> To enter sleep mode

    Documents and posts say the firmware automatically find a right power mode, so all I have to do is to add 2 functions in thread

You don't have to do anything to enter sleep mode. If you don't prevent sleep (by registering the time to sleep callback) and the firmware determines that there is sufficient time to sleep before the next scheduled activity (connection event or advertisement event etc), it will sleep. The steps you describe here are related to deep sleep.

> As I understood, created thread does not anything during sleep but wakeup which is registered in stack.

   what is the way to register the function which should be done during wakeup?

There is no callback for a wake event. When the device sleeps, it is not just the application thread that goes to sleep but all threads, most HW blocks, CPU, anything that is not needed when sleeping. For example, if you are in a connection and there is no data to send from either side, the baseband firmware will still need to wake at every connection event instant (at the connection interval) and exchange poll-null packet to keep the connection alive. This will not generate any event/callback (and there is no way to register for one) for the application because this is not an application event. On the other hand, if there is a GPIO interrupt anytime between the connection event instances, the device will still wake up and invoke the application's GPIO interrupt handler because this is an application event. If a connection event needs to be scheduled during this time (when the application is handling the GPIO interrupt), this will be scheduled too in parallel).

> I want to make the board enter sleep mode after connection is done.

This is automatic and there is no application control for this. Take the example of a 30mS advertisement interval. If advs happen in all three channels and the adv data is 31 bytes, each TX will last ~400uS and say each RX immediately following the TX will take ~100uS. So for three channels, the RF activity is ~1.5mS. There is roughly 2mS overhead for waking up and going back to sleep on either side of this RF activity. So total active time in this 30mS period is ~3.5mS. The entire chip sleeps (with all state maintained) for the rest of the ~26.5mS. The same is true of any connection interval (the active time will be ~2.5mS for an empty packet in either direction) - so for a 7.5mS connection interval, the device will be asleep for ~5mS, for a 100mS connection interval, the device will be asleep for 97.5mS and so on.

View solution in original post

1 Reply
asridharan
Employee
Employee
10 comments on KBA 5 comments on KBA First comment on KBA

> To enter sleep mode

    Documents and posts say the firmware automatically find a right power mode, so all I have to do is to add 2 functions in thread

You don't have to do anything to enter sleep mode. If you don't prevent sleep (by registering the time to sleep callback) and the firmware determines that there is sufficient time to sleep before the next scheduled activity (connection event or advertisement event etc), it will sleep. The steps you describe here are related to deep sleep.

> As I understood, created thread does not anything during sleep but wakeup which is registered in stack.

   what is the way to register the function which should be done during wakeup?

There is no callback for a wake event. When the device sleeps, it is not just the application thread that goes to sleep but all threads, most HW blocks, CPU, anything that is not needed when sleeping. For example, if you are in a connection and there is no data to send from either side, the baseband firmware will still need to wake at every connection event instant (at the connection interval) and exchange poll-null packet to keep the connection alive. This will not generate any event/callback (and there is no way to register for one) for the application because this is not an application event. On the other hand, if there is a GPIO interrupt anytime between the connection event instances, the device will still wake up and invoke the application's GPIO interrupt handler because this is an application event. If a connection event needs to be scheduled during this time (when the application is handling the GPIO interrupt), this will be scheduled too in parallel).

> I want to make the board enter sleep mode after connection is done.

This is automatic and there is no application control for this. Take the example of a 30mS advertisement interval. If advs happen in all three channels and the adv data is 31 bytes, each TX will last ~400uS and say each RX immediately following the TX will take ~100uS. So for three channels, the RF activity is ~1.5mS. There is roughly 2mS overhead for waking up and going back to sleep on either side of this RF activity. So total active time in this 30mS period is ~3.5mS. The entire chip sleeps (with all state maintained) for the rest of the ~26.5mS. The same is true of any connection interval (the active time will be ~2.5mS for an empty packet in either direction) - so for a 7.5mS connection interval, the device will be asleep for ~5mS, for a 100mS connection interval, the device will be asleep for 97.5mS and so on.