diff --git a/dda_queue.c b/dda_queue.c index 84a68e2..e5a0cc5 100644 --- a/dda_queue.c +++ b/dda_queue.c @@ -3,6 +3,7 @@ #include #include +#include "machine.h" // for XONXOFF #include "timer.h" #include "serial.h" #include "sermsg.h" @@ -70,9 +71,9 @@ void enqueue(TARGET *t) { mb_head = h; #ifdef XONXOFF - // if queue is full, stop transmition - if (queue_full()) - xoff(); + // if queue is full, stop transmission + if (queue_full()) + xoff(); #endif // fire up in case we're not running yet @@ -104,9 +105,9 @@ void enqueue_temp_wait() { mb_head = h; #ifdef XONXOFF - // if queue is full, stop transmition - if (queue_full()) - xoff(); + // if queue is full, stop transmission + if (queue_full()) + xoff(); #endif // fire up in case we're not running yet @@ -126,8 +127,8 @@ void next_move() { } #ifdef XONXOFF - // restart transmission - xon(); + // restart transmission + xon(); #endif } diff --git a/gcode.c b/gcode.c index ac03a53..a4770a3 100644 --- a/gcode.c +++ b/gcode.c @@ -414,7 +414,7 @@ void process_gcode_command(GCODE_COMMAND *gcmd) { // G4 - Dwell case 4: #ifdef XONXOFF - xoff(); + xoff(); #endif // wait for all moves to complete for (;queue_empty() == 0;) @@ -422,7 +422,7 @@ void process_gcode_command(GCODE_COMMAND *gcmd) { // delay delay_ms(gcmd->P); #ifdef XONXOFF - xon(); + xon(); #endif break; diff --git a/machine.h b/machine.h index 13ff441..033ec7c 100644 --- a/machine.h +++ b/machine.h @@ -60,7 +60,9 @@ // this should help immensely with dropped serial characters, but may also make debugging infuriating due to the complexities arising from nested interrupts #define STEP_INTERRUPT_INTERRUPTIBLE 1 -// Xon/Xoff flow control. Should be redundant +// Xon/Xoff flow control. Redundant when using RepRap Host for sending GCode, +// but mandatory when sending GCode files with a plain terminal emulator, +// like GtkTerm (Linux), CoolTerm (Mac) or HyperTerminal (Windows). // #define XONXOFF /* diff --git a/serial.c b/serial.c index 63d66e3..d094ee1 100644 --- a/serial.c +++ b/serial.c @@ -45,11 +45,14 @@ volatile uint8_t txbuf[BUFSIZE]; data = buf[tail++]; tail &= (BUFSIZE - 1); */ -volatile uint8_t flowflags = 0; -#define FLOWFLAG_SEND_XOFF 1 -#define FLOWFLAG_SEND_XON 2 -#define FLOWFLAG_SENT_XOFF 4 -#define FLOWFLAG_SENT_XON 8 +#ifdef XONXOFF +#define FLOWFLAG_SEND_XON 1 +#define FLOWFLAG_SEND_XOFF 2 +#define FLOWFLAG_SENT_XON 4 +#define FLOWFLAG_SENT_XOFF 8 +// initially, send an XON +volatile uint8_t flowflags = FLOWFLAG_SEND_XON; +#endif void serial_init() { @@ -82,15 +85,15 @@ ISR(USART_RX_vect) ISR(USART_UDRE_vect) { - #if XONXOFF - if (flowflags & FLOWFLAG_SEND_XOFF) { - UDR0 = ASCII_XOFF; - flowflags = (flowflags & ~FLOWFLAG_SEND_XOFF) | FLOWFLAG_SENT_XOFF; - } - else if (flowflags & FLOWFLAG_SEND_XON) { + #ifdef XONXOFF + if (flowflags & FLOWFLAG_SEND_XON) { UDR0 = ASCII_XON; flowflags = (flowflags & ~FLOWFLAG_SEND_XON) | FLOWFLAG_SENT_XON; } + else if (flowflags & FLOWFLAG_SEND_XOFF) { + UDR0 = ASCII_XOFF; + flowflags = (flowflags & ~FLOWFLAG_SEND_XOFF) | FLOWFLAG_SENT_XOFF; + } else #endif if (buf_canread(tx)) @@ -189,16 +192,16 @@ void serial_writestr_P(PGM_P data) } #ifdef XONXOFF - void xon() { - if (flowflags & FLOWFLAG_SENT_XOFF) - flowflags = FLOWFLAG_SEND_XON; - // enable TX interrupt so we can send this character - UCSR0B |= MASK(UDRIE0); - } +void xon() { + if (flowflags & FLOWFLAG_SENT_XOFF) + flowflags = FLOWFLAG_SEND_XON; + // enable TX interrupt so we can send this character + UCSR0B |= MASK(UDRIE0); +} - void xoff() { - flowflags = FLOWFLAG_SEND_XOFF; - // enable TX interrupt so we can send this character - UCSR0B |= MASK(UDRIE0); - } +void xoff() { + flowflags = FLOWFLAG_SEND_XOFF; + // enable TX interrupt so we can send this character + UCSR0B |= MASK(UDRIE0); +} #endif diff --git a/serial.h b/serial.h index 73a7b18..6deccf3 100644 --- a/serial.h +++ b/serial.h @@ -5,6 +5,8 @@ #include #include +#include "machine.h" // for XONXOFF + // initialise serial subsystem void serial_init(void); @@ -28,9 +30,9 @@ void serial_writeblock_P(PGM_P data, int datalen); void serial_writestr_P(PGM_P data); #ifdef XONXOFF - // XON/XOFF flow control - void xoff(void); - void xon(void); +// XON/XOFF flow control +void xon(void); +void xoff(void); #endif #endif /* _SERIAL_H */