diff options
author | Kevin O'Connor <kevin@koconnor.net> | 2018-05-15 17:04:30 -0400 |
---|---|---|
committer | Kevin O'Connor <kevin@koconnor.net> | 2018-05-15 17:09:11 -0400 |
commit | 70068985a7dc8f9beb0091f2a53b2fbdf359523c (patch) | |
tree | 8900af0be29376aa6e652f2219976fe12c5ffc96 /src/stepper.c | |
parent | 907cfb91053acdd6f751e7a03134295b29360a0f (diff) | |
download | kutter-70068985a7dc8f9beb0091f2a53b2fbdf359523c.tar.gz kutter-70068985a7dc8f9beb0091f2a53b2fbdf359523c.tar.xz kutter-70068985a7dc8f9beb0091f2a53b2fbdf359523c.zip |
stepper: Introduce and use gpio_out_toggle_noirq()
The gpio_out_toggle() function in the sam3x8e and stm32f1 code was
only valid if it was called with irqs disabled.
Commits 018c5daa and 9c52ad43 enabled the lcd code which called
gpio_out_toggle() with irqs enabled. This could cause corruption of
the gpio state.
Introduce a gpio_out_toggle_noirq() function that will only be invoked
with irqs disabled, and fix gpio_out_toggle() on sam3x8e and stm32f1
so that it safe to call even if irqs are enabled.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'src/stepper.c')
-rw-r--r-- | src/stepper.c | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/src/stepper.c b/src/stepper.c index 521e0ab8..2b967413 100644 --- a/src/stepper.c +++ b/src/stepper.c @@ -88,7 +88,7 @@ stepper_load_next(struct stepper *s, uint32_t min_next_time) } if (m->flags & MF_DIR) { s->position = -s->position + m->count; - gpio_out_toggle(s->dir_pin); + gpio_out_toggle_noirq(s->dir_pin); } else { s->position += m->count; } @@ -108,24 +108,24 @@ stepper_event(struct timer *t) if (CONFIG_NO_UNSTEP_DELAY) { // On slower mcus it is possible to simply step and unstep in // the same timer event. - gpio_out_toggle(s->step_pin); + gpio_out_toggle_noirq(s->step_pin); uint16_t count = s->count - 1; if (likely(count)) { s->count = count; s->time.waketime += s->interval; - gpio_out_toggle(s->step_pin); + gpio_out_toggle_noirq(s->step_pin); if (s->flags & SF_HAVE_ADD) s->interval += s->add; return SF_RESCHEDULE; } uint_fast8_t ret = stepper_load_next(s, 0); - gpio_out_toggle(s->step_pin); + gpio_out_toggle_noirq(s->step_pin); return ret; } // On faster mcus, it is necessary to schedule the unstep event uint32_t min_next_time = timer_read_time() + UNSTEP_TIME; - gpio_out_toggle(s->step_pin); + gpio_out_toggle_noirq(s->step_pin); s->count--; if (likely(s->count & 1)) // Schedule unstep event |