From 2e13d2bc9dbd874ce963acbc15a10f2fe969eb7b Mon Sep 17 00:00:00 2001 From: Markus Hitter Date: Sun, 27 Nov 2016 20:13:37 +0100 Subject: [PATCH] dda_queue.c/.h: introduce mb_tail_dda. For now, this costs 2 bytes RAM, 8 bytes binary size and slows down the slowest step by 4 clock cycles. We expect opportunities for improvements elsewhere, of course. ATmega sizes '168 '328(P) '644(P) '1280 Program: 19434 bytes 136% 64% 31% 16% Data: 2179 bytes 213% 107% 54% 27% EEPROM: 32 bytes 4% 2% 2% 1% short-moves.gcode statistics: LED on occurences: 888. LED on time minimum: 230 clock cycles. LED on time maximum: 407 clock cycles. LED on time average: 263.008 clock cycles. smooth-curves.gcode statistics: LED on occurences: 23648. LED on time minimum: 251 clock cycles. LED on time maximum: 450 clock cycles. LED on time average: 286.212 clock cycles. triangle-odd.gcode statistics: LED on occurences: 1636. LED on time minimum: 251 clock cycles. LED on time maximum: 407 clock cycles. LED on time average: 276.568 clock cycles. --- dda_queue.c | 17 ++++++++++++++--- dda_queue.h | 2 ++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/dda_queue.c b/dda_queue.c index a77f5a9..e00d960 100644 --- a/dda_queue.c +++ b/dda_queue.c @@ -36,6 +36,12 @@ uint8_t mb_tail = 0; /// The size does not need to be a power of 2 anymore! DDA BSS movebuffer[MOVEBUFFER_SIZE]; +/** + Pointer to the currently ongoing movement, or NULL, if there's no movement + ongoing. Actually a cache of movebuffer[mb_tail]. +*/ +DDA *mb_tail_dda; + /// Find the next DDA index after 'x', where 0 <= x < MOVEBUFFER_SIZE #define MB_NEXT(x) ((x) < MOVEBUFFER_SIZE - 1 ? (x) + 1 : 0) @@ -89,7 +95,11 @@ void queue_step() { if ( ! movebuffer[mb_tail].live) { if (mb_tail != mb_head) { mb_tail = MB_NEXT(mb_tail); - dda_start(&movebuffer[mb_tail]); + mb_tail_dda = &(movebuffer[mb_tail]); + dda_start(mb_tail_dda); + } + else { + mb_tail_dda = NULL; } } } @@ -140,7 +150,8 @@ void enqueue_home(TARGET *t, uint8_t endstop_check, uint8_t endstop_stop_cond) { */ timer_reset(); mb_tail = mb_head; // Valid ONLY if the queue was empty before! - dda_start(&movebuffer[mb_tail]); + mb_tail_dda = new_movebuffer; // Dito! + dda_start(mb_tail_dda); // Compensate for the cli() in timer_set(). sei(); } @@ -162,7 +173,7 @@ void queue_flush() { // if the timer were running, this would require // wrapping in ATOMIC_START ... ATOMIC_END. mb_tail = mb_head; - movebuffer[mb_head].live = 0; + mb_tail_dda = NULL; } /// wait for queue to empty diff --git a/dda_queue.h b/dda_queue.h index 3bca8c0..9829fd1 100644 --- a/dda_queue.h +++ b/dda_queue.h @@ -13,6 +13,8 @@ // this is the ringbuffer that holds the current and pending moves. extern uint8_t mb_tail; extern DDA movebuffer[MOVEBUFFER_SIZE]; +extern DDA *mb_tail_dda; + /* methods