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.
This commit is contained in:
Markus Hitter 2016-11-27 20:13:37 +01:00
parent c181a813e7
commit 2e13d2bc9d
2 changed files with 16 additions and 3 deletions

View File

@ -36,6 +36,12 @@ uint8_t mb_tail = 0;
/// The size does not need to be a power of 2 anymore! /// The size does not need to be a power of 2 anymore!
DDA BSS movebuffer[MOVEBUFFER_SIZE]; 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 /// Find the next DDA index after 'x', where 0 <= x < MOVEBUFFER_SIZE
#define MB_NEXT(x) ((x) < MOVEBUFFER_SIZE - 1 ? (x) + 1 : 0) #define MB_NEXT(x) ((x) < MOVEBUFFER_SIZE - 1 ? (x) + 1 : 0)
@ -89,7 +95,11 @@ void queue_step() {
if ( ! movebuffer[mb_tail].live) { if ( ! movebuffer[mb_tail].live) {
if (mb_tail != mb_head) { if (mb_tail != mb_head) {
mb_tail = MB_NEXT(mb_tail); 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(); timer_reset();
mb_tail = mb_head; // Valid ONLY if the queue was empty before! 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(). // Compensate for the cli() in timer_set().
sei(); sei();
} }
@ -162,7 +173,7 @@ void queue_flush() {
// if the timer were running, this would require // if the timer were running, this would require
// wrapping in ATOMIC_START ... ATOMIC_END. // wrapping in ATOMIC_START ... ATOMIC_END.
mb_tail = mb_head; mb_tail = mb_head;
movebuffer[mb_head].live = 0; mb_tail_dda = NULL;
} }
/// wait for queue to empty /// wait for queue to empty

View File

@ -13,6 +13,8 @@
// this is the ringbuffer that holds the current and pending moves. // this is the ringbuffer that holds the current and pending moves.
extern uint8_t mb_tail; extern uint8_t mb_tail;
extern DDA movebuffer[MOVEBUFFER_SIZE]; extern DDA movebuffer[MOVEBUFFER_SIZE];
extern DDA *mb_tail_dda;
/* /*
methods methods