In my project I would like to be able to put my MCU in deep sleep mode for a long period of time (about 1 day). In this mode the BLE loop is not even called. I am making use of the function :
So, after a certain amount of time, I call this script :
CORE_DECLARE_IRQ_STATE; CORE_ENTER_ATOMIC(); // Disable interrupts time_ms = gecko_can_sleep_ms(); gecko_sleep_for_ms(time_ms); CORE_EXIT_ATOMIC(); // Enable interrupts
This is the result :
- Whenever I ask for how long I can sleep, I always end up having "131071999" which is 0x7cfffff.
- The time which is actually slept is always smaller than 131072 ms = 0x20000.
- The time actually slept is modulo 131072 ms. For example : if I want to sleep 131073 ms, it will sleep for only 1 ms. If I want to sleep 131071 ms, I will sleep for 131071. If I want to sleep (y*131072)+x, it will always sleep x ms.
Is it the normal behavior ? I have not seen anything regarding the "maximum" time the stack can sleep in the datasheets. Is it intentional or is it a bug from my program ?
I think the gecko_sleep_for_ms() has not been designed to work with such long delays. If the upper limit is 131 s (around 2 minutes) then that should be more than enough for 99.99% of applications.
Have you considered using the blocking API (gecko_wait_event() ) when the device needs to sleep? And then use soft timer with the maximum delay to wake up from sleep. The max delay with soft timer is about 18 hours.
Another idea: since you want to sleep for very long time, what about going to EM4 to get maximal power savings? The downside is of course that you need to come out of EM4 via reset, meaning that your application needs to save and reload its state before/after the sleep period.
It isn't normal. I have reproduced the problem that the sleep time is always modulo 131072. I will report it to our R&D and let you know when the fix is available.