aboutsummaryrefslogtreecommitdiffstats
path: root/src/generic/timer_irq.c
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2017-07-12 22:16:16 -0400
committerKevin O'Connor <kevin@koconnor.net>2017-07-17 15:02:43 -0400
commit118fd21cb815d1c27e7e5bd6b394369bdf095919 (patch)
tree78ceda354491dfb66419f0a7e892017a05319a73 /src/generic/timer_irq.c
parent969485c754731183f357e6fef23c6180f59d4cb6 (diff)
downloadkutter-118fd21cb815d1c27e7e5bd6b394369bdf095919.tar.gz
kutter-118fd21cb815d1c27e7e5bd6b394369bdf095919.tar.xz
kutter-118fd21cb815d1c27e7e5bd6b394369bdf095919.zip
irq: Support sleeping when mcu is idle
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'src/generic/timer_irq.c')
-rw-r--r--src/generic/timer_irq.c17
1 files changed, 16 insertions, 1 deletions
diff --git a/src/generic/timer_irq.c b/src/generic/timer_irq.c
index 07161eee..6c14f9ae 100644
--- a/src/generic/timer_irq.c
+++ b/src/generic/timer_irq.c
@@ -8,6 +8,7 @@
#include "board/irq.h" // irq_disable
#include "board/misc.h" // timer_from_us
#include "board/timer_irq.h" // timer_dispatch_many
+#include "basecmd.h" // stats_note_sleep
#include "command.h" // shutdown
#include "sched.h" // sched_timer_kick
@@ -85,9 +86,23 @@ timer_dispatch_many(void)
void
timer_task(void)
{
+ static uint32_t last_timer;
+ uint32_t lst = last_timer;
irq_disable();
- timer_repeat_until = timer_read_time() + TIMER_IDLE_REPEAT_TICKS;
+ uint32_t next = timer_get_next(), cur = timer_read_time();
+ if (lst != next) {
+ timer_repeat_until = cur + TIMER_IDLE_REPEAT_TICKS;
+ irq_enable();
+ last_timer = next;
+ return;
+ }
+
+ // Sleep the processor
+ irq_wait();
+ uint32_t post_sleep = timer_read_time();
+ timer_repeat_until = post_sleep + TIMER_IDLE_REPEAT_TICKS;
irq_enable();
+ stats_note_sleep(post_sleep - cur);
}
DECL_TASK(timer_task);