From 5d8e866501ba29c68a00307c942fddc12ee7294e Mon Sep 17 00:00:00 2001 From: Markus Hitter Date: Sun, 2 Aug 2015 16:36:34 +0200 Subject: [PATCH] Move interrupt busy detection from dda_clock() to clock tick ISR. The reason is, interrupts can't be re-entered on ARM, so we need a different mechanism. --- dda.c | 11 ----------- timer-avr.c | 16 +++++++++++++++- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/dda.c b/dda.c index aba9608..8fdc780 100644 --- a/dda.c +++ b/dda.c @@ -749,7 +749,6 @@ void dda_step(DDA *dda) { accurate curves! */ void dda_clock() { - static volatile uint8_t busy = 0; DDA *dda; static DDA *last_dda = NULL; uint8_t endstop_trigger = 0; @@ -769,13 +768,6 @@ 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 @@ -923,9 +915,6 @@ void dda_clock() { ATOMIC_END } #endif - - cli(); // Compensate sei() above. - busy = 0; } /// update global current_position struct diff --git a/timer-avr.c b/timer-avr.c index d5cbc90..3fbeaaf 100644 --- a/timer-avr.c +++ b/timer-avr.c @@ -41,11 +41,25 @@ uint32_t step_extra_time = 0; Comparator B is the system clock, happens every TICK_TIME. */ ISR(TIMER1_COMPB_vect) { + static volatile uint8_t busy = 0; + // set output compare register to the next clock tick OCR1B = (OCR1B + TICK_TIME) & 0xFFFF; clock_tick(); - dda_clock(); + + /** + Lengthy calculations ahead! Make sure we didn't re-enter, then allow + nested interrupts. + */ + if ( ! busy) { + busy = 1; + sei(); + + dda_clock(); + + busy = 0; + } } #ifdef MOTHERBOARD