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>
This commit is contained in:
Kevin O'Connor 2018-05-15 17:04:30 -04:00
parent 907cfb9105
commit 70068985a7
13 changed files with 46 additions and 10 deletions

View file

@ -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