From d0c3744f927782565d14b47184781e889c09d74e Mon Sep 17 00:00:00 2001 From: Michael Moon Date: Mon, 18 Oct 2010 18:43:03 +1100 Subject: [PATCH] add flush queue for emergency stop --- dda_queue.c | 15 +++++++++++++++ dda_queue.h | 3 +++ gcode_process.c | 1 + 3 files changed, 19 insertions(+) diff --git a/dda_queue.c b/dda_queue.c index 71e3c3a..fb3edb2 100644 --- a/dda_queue.c +++ b/dda_queue.c @@ -106,3 +106,18 @@ void print_queue() { serial_writechar('E'); serial_writechar('\n'); } + +void queue_flush() { + // save interrupt flag + uint8_t sreg = SREG; + + // disable interrupts + cli(); + + // flush queue + mb_tail = mb_head; + movebuffer[mb_head].live = 0; + + // restore interrupt flag + SREG = sreg; +} diff --git a/dda_queue.h b/dda_queue.h index 9edf865..46b4a4f 100644 --- a/dda_queue.h +++ b/dda_queue.h @@ -33,4 +33,7 @@ void next_move(void) __attribute__ ((hot)); // print queue status void print_queue(void); +// flush the queue for eg; emergency stop +void queue_flush(void); + #endif /* _DDA_QUEUE */ diff --git a/gcode_process.c b/gcode_process.c index 2ced51b..789fd12 100644 --- a/gcode_process.c +++ b/gcode_process.c @@ -249,6 +249,7 @@ void process_gcode_command() { // M112- immediate stop case 112: disableTimerInterrupt(); + queue_flush(); power_off(); break; // M113- extruder PWM