From 81cffde4e9c245a6d03c6425fb4596e028426cda Mon Sep 17 00:00:00 2001 From: Markus Hitter Date: Sun, 27 Nov 2016 20:23:12 +0100 Subject: [PATCH] dda_queue.c/.h: eliminate queue_empty(). This is no longer needed, because mb_tail_dda gives the same information, just faster. Wanted side effect: better encapsulation. No stepping performance improvement, but binary size 36 bytes smaller: ATmega sizes '168 '328(P) '644(P) '1280 Program: 19398 bytes 136% 64% 31% 16% Data: 2179 bytes 213% 107% 54% 27% EEPROM: 32 bytes 4% 2% 2% 1% --- dda_queue.c | 21 ++++----------------- dda_queue.h | 1 - simulator/serial_sim.c | 2 +- 3 files changed, 5 insertions(+), 19 deletions(-) diff --git a/dda_queue.c b/dda_queue.c index e00d960..dd3486f 100644 --- a/dda_queue.c +++ b/dda_queue.c @@ -51,17 +51,6 @@ uint8_t queue_full() { return MB_NEXT(mb_head) == mb_tail; } -/// check if the queue is completely empty -uint8_t queue_empty() { - uint8_t result; - - ATOMIC_START - result = (mb_tail == mb_head && movebuffer[mb_tail].live == 0); - ATOMIC_END - - return result; -} - /// Return the current movement, or NULL, if there's no movement going on. DDA *queue_current_movement() { DDA* current; @@ -132,16 +121,13 @@ void enqueue_home(TARGET *t, uint8_t endstop_check, uint8_t endstop_stop_cond) { mb_head. Also kick off movements if it's the first movement after a pause. */ if ( ! new_movebuffer->nullmove) { - // Remember if the queue was empty before we complete the queueing. - uint8_t isdead = queue_empty(); - // make certain all writes to global memory // are flushed before modifying mb_head. MEMORY_BARRIER(); mb_head = h; - if (isdead) { + if (mb_tail_dda == NULL) { /** Go to the next move. @@ -161,7 +147,8 @@ void enqueue_home(TARGET *t, uint8_t endstop_check, uint8_t endstop_stop_cond) { /// DEBUG - print queue. /// Qt/hs format, t is tail, h is head, s is F/full, E/empty or neither void print_queue() { - sersendf_P(PSTR("Queue: %d/%d%c\n"), mb_tail, mb_head, (queue_full()?'F':(queue_empty()?'E':' '))); + sersendf_P(PSTR("Queue: %d/%d%c\n"), mb_tail, mb_head, + (queue_full() ? 'F' : (mb_tail_dda ? ' ' : 'E'))); } /// dump queue for emergency stop. @@ -178,6 +165,6 @@ void queue_flush() { /// wait for queue to empty void queue_wait() { - while (queue_empty() == 0) + while (mb_tail_dda) clock(); } diff --git a/dda_queue.h b/dda_queue.h index 9829fd1..b9943e0 100644 --- a/dda_queue.h +++ b/dda_queue.h @@ -22,7 +22,6 @@ extern DDA *mb_tail_dda; // queue status methods uint8_t queue_full(void); -uint8_t queue_empty(void); DDA *queue_current_movement(void); // take one step diff --git a/simulator/serial_sim.c b/simulator/serial_sim.c index 76cca49..e63acb2 100644 --- a/simulator/serial_sim.c +++ b/simulator/serial_sim.c @@ -101,7 +101,7 @@ uint8_t serial_rxchars(void) { if (gcode_fd) return 1; // No more gcode data; wait for DDA queue to drain - if (queue_empty()) { + if (mb_tail_dda == NULL) { sim_info("Gcode processing completed."); exit(0); }