Make XON/XOFF flow control compile.

This commit is contained in:
Markus Hitter 2010-09-06 17:26:43 +02:00
parent 548b79f3d6
commit b2e1cfd8b5
5 changed files with 44 additions and 36 deletions

View File

@ -3,6 +3,7 @@
#include <string.h> #include <string.h>
#include <avr/interrupt.h> #include <avr/interrupt.h>
#include "machine.h" // for XONXOFF
#include "timer.h" #include "timer.h"
#include "serial.h" #include "serial.h"
#include "sermsg.h" #include "sermsg.h"
@ -70,7 +71,7 @@ void enqueue(TARGET *t) {
mb_head = h; mb_head = h;
#ifdef XONXOFF #ifdef XONXOFF
// if queue is full, stop transmition // if queue is full, stop transmission
if (queue_full()) if (queue_full())
xoff(); xoff();
#endif #endif
@ -104,7 +105,7 @@ void enqueue_temp_wait() {
mb_head = h; mb_head = h;
#ifdef XONXOFF #ifdef XONXOFF
// if queue is full, stop transmition // if queue is full, stop transmission
if (queue_full()) if (queue_full())
xoff(); xoff();
#endif #endif

View File

@ -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 // 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 #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 // #define XONXOFF
/* /*

View File

@ -45,11 +45,14 @@ volatile uint8_t txbuf[BUFSIZE];
data = buf[tail++]; tail &= (BUFSIZE - 1); data = buf[tail++]; tail &= (BUFSIZE - 1);
*/ */
volatile uint8_t flowflags = 0; #ifdef XONXOFF
#define FLOWFLAG_SEND_XOFF 1 #define FLOWFLAG_SEND_XON 1
#define FLOWFLAG_SEND_XON 2 #define FLOWFLAG_SEND_XOFF 2
#define FLOWFLAG_SENT_XOFF 4 #define FLOWFLAG_SENT_XON 4
#define FLOWFLAG_SENT_XON 8 #define FLOWFLAG_SENT_XOFF 8
// initially, send an XON
volatile uint8_t flowflags = FLOWFLAG_SEND_XON;
#endif
void serial_init() void serial_init()
{ {
@ -82,15 +85,15 @@ ISR(USART_RX_vect)
ISR(USART_UDRE_vect) ISR(USART_UDRE_vect)
{ {
#if XONXOFF #ifdef XONXOFF
if (flowflags & FLOWFLAG_SEND_XOFF) { if (flowflags & FLOWFLAG_SEND_XON) {
UDR0 = ASCII_XOFF;
flowflags = (flowflags & ~FLOWFLAG_SEND_XOFF) | FLOWFLAG_SENT_XOFF;
}
else if (flowflags & FLOWFLAG_SEND_XON) {
UDR0 = ASCII_XON; UDR0 = ASCII_XON;
flowflags = (flowflags & ~FLOWFLAG_SEND_XON) | FLOWFLAG_SENT_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 else
#endif #endif
if (buf_canread(tx)) if (buf_canread(tx))

View File

@ -5,6 +5,8 @@
#include <avr/io.h> #include <avr/io.h>
#include <avr/pgmspace.h> #include <avr/pgmspace.h>
#include "machine.h" // for XONXOFF
// initialise serial subsystem // initialise serial subsystem
void serial_init(void); void serial_init(void);
@ -29,8 +31,8 @@ void serial_writestr_P(PGM_P data);
#ifdef XONXOFF #ifdef XONXOFF
// XON/XOFF flow control // XON/XOFF flow control
void xoff(void);
void xon(void); void xon(void);
void xoff(void);
#endif #endif
#endif /* _SERIAL_H */ #endif /* _SERIAL_H */