From ed103822f5501f08c5d23216a1a505dbdd163f6c Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Wed, 1 Jun 2016 12:04:01 -0400 Subject: [PATCH] sched: Change sched_from_ms() to sched_from_us() Some code may require micro-second precision so update sched_from_ms() to use micro-seconds. Signed-off-by: Kevin O'Connor --- src/avr/timer.c | 10 +++++----- src/avr/timer.h | 2 +- src/basecmd.c | 2 +- src/sched.c | 12 ++++++------ src/sched.h | 2 +- src/simulator/main.c | 2 +- src/simulator/timer.h | 2 +- 7 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/avr/timer.c b/src/avr/timer.c index 8cc3d550..538f0b19 100644 --- a/src/avr/timer.c +++ b/src/avr/timer.c @@ -8,18 +8,18 @@ #include "command.h" // shutdown #include "irq.h" // irq_save #include "sched.h" // sched_timer_kick -#include "timer.h" // timer_from_ms +#include "timer.h" // timer_from_us /**************************************************************** * Low level timer code ****************************************************************/ -// Return the number of clock ticks for a given number of milliseconds +// Return the number of clock ticks for a given number of microseconds uint32_t -timer_from_ms(uint32_t ms) +timer_from_us(uint32_t us) { - return ms * (F_CPU / 1000); + return us * (F_CPU / 1000000); } static inline uint16_t @@ -156,7 +156,7 @@ timer_try_set_next(uint32_t target) // Too many repeat timers from a single interrupt - force a pause timer_repeat = TIMER_MAX_NEXT_REPEAT; next = now + TIMER_DEFER_REPEAT_TICKS; - if (diff < (int16_t)(-timer_from_ms(1))) + if (diff < (int16_t)(-timer_from_us(1000))) goto fail; done: diff --git a/src/avr/timer.h b/src/avr/timer.h index 2165fecd..188d8a98 100644 --- a/src/avr/timer.h +++ b/src/avr/timer.h @@ -3,7 +3,7 @@ #include -uint32_t timer_from_ms(uint32_t ms); +uint32_t timer_from_us(uint32_t us); void timer_periodic(void); uint32_t timer_read_time(void); uint8_t timer_set_next(uint32_t next); diff --git a/src/basecmd.c b/src/basecmd.c index b94c820a..113cc30e 100644 --- a/src/basecmd.c +++ b/src/basecmd.c @@ -205,7 +205,7 @@ stats_task(void) sumsq = nextsumsq; static uint32_t prev; - if (sched_is_before(cur, prev + sched_from_ms(5000))) + if (sched_is_before(cur, prev + sched_from_us(5000000))) return; sendf("stats count=%u sum=%u sumsq=%u", count, cur - prev, sumsq); prev = cur; diff --git a/src/sched.c b/src/sched.c index 2f51515c..a25f43e2 100644 --- a/src/sched.c +++ b/src/sched.c @@ -9,9 +9,9 @@ #include // NULL #include "autoconf.h" // CONFIG_* #include "board/irq.h" // irq_save -#include "board/timer.h" // timer_from_ms +#include "board/timer.h" // timer_from_us #include "command.h" // shutdown -#include "sched.h" // sched_from_ms +#include "sched.h" // sched_from_us #include "stepper.h" // stepper_event @@ -30,7 +30,7 @@ ms_event(struct timer *t) { millis++; timer_periodic(); - t->waketime += sched_from_ms(1); + t->waketime += sched_from_us(1000); return SF_RESCHEDULE; } @@ -52,11 +52,11 @@ sched_check_periodic(uint16_t time, uint16_t *pnext) return 1; } -// Return the number of clock ticks for a given number of milliseconds +// Return the number of clock ticks for a given number of microseconds uint32_t -sched_from_ms(uint32_t ms) +sched_from_us(uint32_t us) { - return timer_from_ms(ms); + return timer_from_us(us); } // Return the current time (in clock ticks) diff --git a/src/sched.h b/src/sched.h index 047ac1ce..be73ce65 100644 --- a/src/sched.h +++ b/src/sched.h @@ -23,7 +23,7 @@ enum { SF_DONE=0, SF_RESCHEDULE=1 }; // sched.c uint8_t sched_check_periodic(uint16_t time, uint16_t *pnext); -uint32_t sched_from_ms(uint32_t ms); +uint32_t sched_from_us(uint32_t us); uint32_t sched_read_time(void); uint8_t sched_is_before(uint32_t time1, uint32_t time2); void sched_timer(struct timer*); diff --git a/src/simulator/main.c b/src/simulator/main.c index 2d43a138..e871864a 100644 --- a/src/simulator/main.c +++ b/src/simulator/main.c @@ -17,7 +17,7 @@ uint8_t Interrupt_off; ****************************************************************/ uint32_t -timer_from_ms(uint32_t ms) +timer_from_us(uint32_t us) { return 0; // XXX } diff --git a/src/simulator/timer.h b/src/simulator/timer.h index f35b8278..71b64502 100644 --- a/src/simulator/timer.h +++ b/src/simulator/timer.h @@ -3,7 +3,7 @@ #include -uint32_t timer_from_ms(uint32_t ms); +uint32_t timer_from_us(uint32_t us); void timer_periodic(void); uint32_t timer_read_time(void); uint8_t timer_set_next(uint32_t next);