diff options
author | Kevin O'Connor <kevin@koconnor.net> | 2017-08-07 12:33:08 -0400 |
---|---|---|
committer | Kevin O'Connor <kevin@koconnor.net> | 2017-08-08 00:27:28 -0400 |
commit | 2c272f99a3fac49d8acd4b49a1aa3302225f17b8 (patch) | |
tree | 07998c722ed20fa812de26e1941daf57a030271f /src/avr/timer.c | |
parent | a9982beacf184ccdc4bf1221852c900b0809537d (diff) | |
download | kutter-2c272f99a3fac49d8acd4b49a1aa3302225f17b8.tar.gz kutter-2c272f99a3fac49d8acd4b49a1aa3302225f17b8.tar.xz kutter-2c272f99a3fac49d8acd4b49a1aa3302225f17b8.zip |
sched: Implement generic sleep mechanism based on tasks pending
Track when tasks are pending and spin in irq_wait() when no tasks are
pending. This improves the mechanism for sleeping the processor -
it's simpler for the board specific code and it reduces the
possibility of the processor sleeping when tasks are busy.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'src/avr/timer.c')
-rw-r--r-- | src/avr/timer.c | 23 |
1 files changed, 1 insertions, 22 deletions
diff --git a/src/avr/timer.c b/src/avr/timer.c index 17f3e913..a49d9e6d 100644 --- a/src/avr/timer.c +++ b/src/avr/timer.c @@ -6,7 +6,6 @@ #include <avr/interrupt.h> // TCNT1 #include "autoconf.h" // CONFIG_AVR_CLKPR -#include "basecmd.h" // stats_note_sleep #include "board/misc.h" // timer_from_us #include "command.h" // shutdown #include "irq.h" // irq_save @@ -63,12 +62,6 @@ timer_set(uint16_t next) OCR1A = next; } -static inline uint16_t -timer_get_next(void) -{ - return OCR1A; -} - static inline void timer_repeat_set(uint16_t next) { @@ -213,22 +206,8 @@ done: void timer_task(void) { - static uint16_t last_timer; - uint16_t lst = last_timer; irq_disable(); - uint16_t next = timer_get_next(), cur = timer_get(); - if (lst != next) { - timer_repeat_set(cur + TIMER_IDLE_REPEAT_TICKS); - irq_enable(); - last_timer = next; - return; - } - - // Sleep the processor - irq_wait(); - uint16_t post_sleep = timer_get(); - timer_repeat_set(post_sleep + TIMER_IDLE_REPEAT_TICKS); + timer_repeat_set(timer_get() + TIMER_IDLE_REPEAT_TICKS); irq_enable(); - stats_note_sleep(post_sleep - cur); } DECL_TASK(timer_task); |