From 60e488eb177a35084669cb85d81131ce95eac959 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Fri, 24 Mar 2017 23:01:08 -0400 Subject: timer: Allow board code to define its own timer_is_before implementation Move sched_is_before() from sched.c to timer_is_before() in the board specific timer code. This allows the board code to provide its own definition. Also, remove the sched_from_us() and sched_read_time() wrapper functions and change the callers to directly invoke timer_from_us() / timer_read_time(). Signed-off-by: Kevin O'Connor --- src/stepper.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'src/stepper.c') diff --git a/src/stepper.c b/src/stepper.c index 0d7f490b..c1bdf275 100644 --- a/src/stepper.c +++ b/src/stepper.c @@ -8,6 +8,7 @@ #include "basecmd.h" // oid_alloc #include "board/gpio.h" // gpio_out_write #include "board/irq.h" // irq_disable +#include "board/misc.h" // timer_is_before #include "command.h" // DECL_COMMAND #include "sched.h" // struct timer #include "stepper.h" // command_config_stepper @@ -75,9 +76,9 @@ stepper_load_next(struct stepper *s, uint32_t min_next_time) // On faster mcus, it is necessary to schedule unstep events // and so there are twice as many events. Also check that the // next step event isn't too close to the last unstep. - if (unlikely(sched_is_before(s->next_step_time, min_next_time))) { + if (unlikely(timer_is_before(s->next_step_time, min_next_time))) { if ((int32_t)(s->next_step_time - min_next_time) - < (int32_t)(-sched_from_us(1000))) + < (int32_t)(-timer_from_us(1000))) shutdown("stepper too far in past"); s->time.waketime = min_next_time; } else { @@ -97,7 +98,7 @@ stepper_load_next(struct stepper *s, uint32_t min_next_time) return SF_RESCHEDULE; } -#define UNSTEP_TIME sched_from_us(1) +#define UNSTEP_TIME timer_from_us(1) // Timer callback - step the given stepper. uint_fast8_t @@ -123,7 +124,7 @@ stepper_event(struct timer *t) } // On faster mcus, it is necessary to schedule the unstep event - uint32_t min_next_time = sched_read_time() + UNSTEP_TIME; + uint32_t min_next_time = timer_read_time() + UNSTEP_TIME; gpio_out_toggle(s->step_pin); s->count--; if (likely(s->count & 1)) @@ -132,7 +133,7 @@ stepper_event(struct timer *t) if (likely(s->count)) { s->next_step_time += s->interval; s->interval += s->add; - if (unlikely(sched_is_before(s->next_step_time, min_next_time))) + if (unlikely(timer_is_before(s->next_step_time, min_next_time))) // The next step event is too close - push it back goto reschedule_min; s->time.waketime = s->next_step_time; -- cgit v1.2.3-70-g09d2