aboutsummaryrefslogtreecommitdiffstats
path: root/src/stepper.c
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2017-03-24 23:01:08 -0400
committerKevin O'Connor <kevin@koconnor.net>2017-03-26 22:45:58 -0400
commit60e488eb177a35084669cb85d81131ce95eac959 (patch)
tree2a0b406f4e0b6e54ef495140573daf6426ca6b0e /src/stepper.c
parent14340ac4df4c58bab4b5fc4c9e4746e33958c081 (diff)
downloadkutter-60e488eb177a35084669cb85d81131ce95eac959.tar.gz
kutter-60e488eb177a35084669cb85d81131ce95eac959.tar.xz
kutter-60e488eb177a35084669cb85d81131ce95eac959.zip
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 <kevin@koconnor.net>
Diffstat (limited to 'src/stepper.c')
-rw-r--r--src/stepper.c11
1 files changed, 6 insertions, 5 deletions
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;