Permalink
Browse files

slightly simplified and clarified xon/xoff

  • Loading branch information...
1 parent f1e318a commit a77986784e685facb3c3039fc80a91099b2a33bf @triffid committed Oct 8, 2010
Showing with 3 additions and 2 deletions.
  1. +3 −2 serial.c
View
5 serial.c
@@ -48,6 +48,7 @@ volatile uint8_t txbuf[BUFSIZE];
*/
#ifdef XONXOFF
+#define FLOWFLAG_STATE_XOFF 0
#define FLOWFLAG_SEND_XON 1
#define FLOWFLAG_SEND_XOFF 2
#define FLOWFLAG_STATE_XON 4
@@ -91,7 +92,7 @@ ISR(USART0_RX_vect)
}
#ifdef XONXOFF
- if (flowflags & FLOWFLAG_STATE_XON && buf_canread(rx) >= BUFSIZE - 16) {
+ if (flowflags & FLOWFLAG_STATE_XON && buf_canwrite(rx) <= 16) {
// the buffer has only 16 free characters left, so send an XOFF
// more characters might come in until the XOFF takes effect
flowflags = FLOWFLAG_SEND_XOFF | FLOWFLAG_STATE_XON;
@@ -114,7 +115,7 @@ ISR(USART0_UDRE_vect)
}
else if (flowflags & FLOWFLAG_SEND_XOFF) {
UDR0 = ASCII_XOFF;
- flowflags = 0;
+ flowflags = FLOWFLAG_STATE_XOFF;
}
else
#endif

0 comments on commit a779867

Please sign in to comment.