1 of 1 people found this helpful
> 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.