From ddd89887278c1402992c903b9e5aa7ef3243dcdf Mon Sep 17 00:00:00 2001 From: Phil Hord Date: Wed, 27 Nov 2013 21:49:42 -0500 Subject: [PATCH] dda_create(): store prev_dda locally. This obviously requires less place on the stack and accordingly a few CPU cycles less, but more importantly, it lets decide dda_start() whether a previous movement is to be taken into account or not. To make this decision more reliable, add a flag for movements done. Else it could happen we'd try to join with a movement done long before. --- dda.c | 10 +++++++++- dda.h | 5 +++-- dda_queue.c | 5 ++--- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/dda.c b/dda.c index 6772a4a..a1fed05 100644 --- a/dda.c +++ b/dda.c @@ -83,12 +83,16 @@ void dda_new_startpoint(void) { This algorithm is probably the main limiting factor to print speed in terms of firmware limitations */ -void dda_create(DDA *dda, TARGET *target, DDA *prev_dda) { +void dda_create(DDA *dda, TARGET *target) { uint32_t steps, x_delta_um, y_delta_um, z_delta_um, e_delta_um; uint32_t distance, c_limit, c_limit_calc; #ifdef LOOKAHEAD // Number the moves to identify them; allowed to overflow. static uint8_t idcnt = 0; + static DDA* prev_dda = NULL; + + if (prev_dda && prev_dda->done) + prev_dda = NULL; #endif // initialise DDA to a known state @@ -405,6 +409,9 @@ void dda_create(DDA *dda, TARGET *target, DDA *prev_dda) { // next dda starts where we finish memcpy(&startpoint, target, sizeof(TARGET)); + #ifdef LOOKAHEAD + prev_dda = dda; + #endif } /*! Start a prepared DDA @@ -637,6 +644,7 @@ void dda_step(DDA *dda) { #endif ) { dda->live = 0; + dda->done = 1; #ifdef LOOKAHEAD // If look-ahead was using this move, it could have missed our activation: // make sure the ids do not match. diff --git a/dda.h b/dda.h index 32cc893..59b84a4 100644 --- a/dda.h +++ b/dda.h @@ -103,6 +103,7 @@ typedef struct { // status fields uint8_t nullmove :1; ///< bool: no axes move, maybe we wait for temperatures or change speed uint8_t live :1; ///< bool: this DDA is running and still has steps to do + uint8_t done :1; ///< bool: this DDA is done. #ifdef ACCELERATION_REPRAP uint8_t accel :1; ///< bool: speed changes during this move, run accel code #endif @@ -116,7 +117,7 @@ typedef struct { uint8_t z_direction :1; ///< direction flag for Z axis uint8_t e_direction :1; ///< direction flag for E axis }; - uint8_t allflags; ///< used for clearing all flags + uint16_t allflags; ///< used for clearing all flags }; // distances @@ -198,7 +199,7 @@ void dda_init(void); void dda_new_startpoint(void); // create a DDA -void dda_create(DDA *dda, TARGET *target, DDA *prev_dda); +void dda_create(DDA *dda, TARGET *target); // start a created DDA (called from timer interrupt) void dda_start(DDA *dda) __attribute__ ((hot)); diff --git a/dda_queue.c b/dda_queue.c index 6e3c73b..d433d47 100644 --- a/dda_queue.c +++ b/dda_queue.c @@ -84,7 +84,7 @@ void queue_step() { if (current_movebuffer->waitfor_temp) { setTimer(HEATER_WAIT_TIMEOUT); if (temp_achieved()) { - current_movebuffer->live = current_movebuffer->waitfor_temp = 0; + current_movebuffer->live = current_movebuffer->done = 0; serial_writestr_P(PSTR("Temp achieved\n")); } } @@ -112,10 +112,9 @@ void enqueue_home(TARGET *t, uint8_t endstop_check, uint8_t endstop_stop_cond) { h &= (MOVEBUFFER_SIZE - 1); DDA* new_movebuffer = &(movebuffer[h]); - DDA* prev_movebuffer = (queue_empty() != 0) ? NULL : &movebuffer[mb_head]; if (t != NULL) { - dda_create(new_movebuffer, t, prev_movebuffer); + dda_create(new_movebuffer, t); new_movebuffer->endstop_check = endstop_check; new_movebuffer->endstop_stop_cond = endstop_stop_cond; }