Hallo,
currently I'm testing sleep variants for nRF52840. I'm using nRF52840-DK and Zephyr build v2.7.99-ncs1-1.
By means of the RTC timer one can handle sleeping quite comfortable:
z_nrf_rtc_timer_set((int32_t)rtc_chan, rtc_ticks, rtc_expiry_handler, NULL);
k_sleep(K_FOREVER);
will set the timer and after that line one can sleep forever. An expiring timer (after rtc_ticks) will call the rtc_expiry_handler function, where a wake-up of the main thread can be done.The value for rtc_ticks is calculated by means of:
rtc_ticks = z_nrf_rtc_timer_get_ticks(t);
"t" in the end is an uint32_t type.
My test implementation runs well in a small test app for sleep times up to 512 seconds. For longer times z_nrf_rtc_timer_get_ticks(..) comes up with error -22. First I thought that there is an issue of register length, since in z_nrf_rtc_timer_get_ticks(..) there is a COUNTER_SPAN, which is defined as
#define COUNTER_BIT_WIDTH 24U
#define COUNTER_SPAN BIT(COUNTER_BIT_WIDTH)
But I realised that for the 512 second case the number of ticks is 16851770, which is already more than a 24-bit-value. In general, much higher tick values should be possible - the return value of z_nrf_rtc_timer_get_ticks(..) is an uint64_t.
Therefore the question: What should I do to extend the sleep time of (much) more than 512 seconds?