|
22 | 22 |
|
23 | 23 | #include "rtos_idle.h"
|
24 | 24 |
|
| 25 | +#if DEVICE_LOWPOWERTIMER && DEVICE_SLEEP |
| 26 | +#include "ticker_api.h" |
| 27 | +#include "critical.h" |
| 28 | +#include "lp_ticker_api.h" |
| 29 | +#include "cmsis_os.h" |
| 30 | +#include "sleep_api.h" |
| 31 | + |
| 32 | +static ticker_event_t delay_event; |
| 33 | +static volatile bool sleep_ended; |
| 34 | +extern uint32_t os_clockrate; |
| 35 | + |
| 36 | +void sleep_handler(uint32_t id) |
| 37 | +{ |
| 38 | + sleep_ended = true; |
| 39 | +} |
| 40 | +#endif /* DEVICE_LOWPOWERTIMER && DEVICE_SLEEP */ |
| 41 | + |
25 | 42 | static void default_idle_hook(void)
|
26 | 43 | {
|
| 44 | +#if DEVICE_LOWPOWERTIMER && DEVICE_SLEEP |
| 45 | + const ticker_data_t *lp_ticker_data = get_lp_ticker_data(); |
| 46 | + uint32_t delay_ticks = os_suspend(); |
| 47 | + uint32_t delay_us; |
| 48 | + sleep_ended = false; |
| 49 | + |
| 50 | + ticker_set_handler(lp_ticker_data, sleep_handler); |
| 51 | + |
| 52 | + ticker_remove_event(lp_ticker_data, &delay_event); |
| 53 | + delay_us = lp_ticker_read() + delay_ticks * os_clockrate; |
| 54 | + ticker_insert_event(lp_ticker_data, &delay_event, delay_us, (uint32_t)&delay_event); |
| 55 | + |
| 56 | + while(!sleep_ended) { |
| 57 | + sleep(); |
| 58 | + } |
| 59 | + |
| 60 | + os_resume(delay_ticks); |
| 61 | + |
| 62 | +#else /* DEVICE_LOWPOWERTIMER && DEVICE_SLEEP */ |
27 | 63 | /* Sleep: ideally, we should put the chip to sleep.
|
28 | 64 | Unfortunately, this usually requires disconnecting the interface chip (debugger).
|
29 | 65 | This can be done, but it would break the local file system.
|
30 | 66 | */
|
31 | 67 | // sleep();
|
| 68 | +#endif /* DEVICE_LOWPOWERTIMER && DEVICE_SLEEP */ |
32 | 69 | }
|
33 | 70 | static void (*idle_hook_fptr)(void) = &default_idle_hook;
|
34 | 71 |
|
|
0 commit comments