From ccec75d9f888c984f69e3a3d17901c9fb45d4be3 Mon Sep 17 00:00:00 2001 From: Markus Hitter Date: Sat, 19 Oct 2013 23:02:14 +0200 Subject: [PATCH] dda.c: allow protected re-entry for time based stepper calculations. This becomes more important when acceleration is calculated there, too. --- dda.c | 11 +++++++++++ timer.c | 4 ++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/dda.c b/dda.c index edabb81..103bbca 100644 --- a/dda.c +++ b/dda.c @@ -717,6 +717,7 @@ void dda_step(DDA *dda) { Updating speed 500 times a second is easily enough for smooth acceleration! */ void dda_clock() { + static volatile uint8_t busy = 0; DDA *dda; static DDA *last_dda = NULL; static uint8_t endstop_stop = 0; ///< Stop due to endstop trigger @@ -732,6 +733,13 @@ void dda_clock() { if (dda == NULL) return; + // Lengthy calculations ahead! + // Make sure we didn't re-enter, then allow nested interrupts. + if (busy) + return; + busy = 1; + sei(); + // Caution: we mangle step counters here without locking interrupts. This // means, we trust dda isn't changed behind our back, which could // in principle (but rarely) happen if endstops are checked not as @@ -808,6 +816,9 @@ void dda_clock() { } /* if (endstop_stop == 0) */ last_dda = dda; + + cli(); // Compensate sei() above. + busy = 0; } /// update global current_position struct diff --git a/timer.c b/timer.c index db6f597..be0f7f5 100644 --- a/timer.c +++ b/timer.c @@ -57,8 +57,6 @@ ISR(TIMER1_COMPB_vect) { /* clock stuff */ - dda_clock(); - clock_counter_10ms += TICK_TIME_MS; if (clock_counter_10ms >= 10) { clock_counter_10ms -= 10; @@ -77,6 +75,8 @@ ISR(TIMER1_COMPB_vect) { } } + dda_clock(); + // restore status register MEMORY_BARRIER(); SREG = sreg_save;