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 <avr/interrupt.h>
#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
}

View File

@ -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;

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
#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
/*

View File

@ -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

View File

@ -5,6 +5,8 @@
#include <avr/io.h>
#include <avr/pgmspace.h>
#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 */