summaryrefslogtreecommitdiffstats
path: root/protocol
diff options
context:
space:
mode:
authortmk <nobody@nowhere>2014-07-20 07:42:44 +0200
committertmk <nobody@nowhere>2014-07-30 07:38:26 +0200
commit3e7875455ed392ce5238efa0734e82995e1f8040 (patch)
tree57cec7eb223614680643afd7812db4553f8789ef /protocol
parent50bcaa66c468f350a538279667a0fa68090c55a9 (diff)
downloadqmk_firmware-3e7875455ed392ce5238efa0734e82995e1f8040.tar.gz
qmk_firmware-3e7875455ed392ce5238efa0734e82995e1f8040.tar.xz
Add flow control by firmware to serial_uart
Diffstat (limited to 'protocol')
-rw-r--r--protocol/serial_uart.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/protocol/serial_uart.c b/protocol/serial_uart.c
index 600340cd8..35df27fd6 100644
--- a/protocol/serial_uart.c
+++ b/protocol/serial_uart.c
@@ -41,6 +41,22 @@ POSSIBILITY OF SUCH DAMAGE.
#include "serial.h"
+#if defined(SERIAL_UART_RTS_LO) && defined(SERIAL_UART_RTS_HI)
+ // Buffer state
+ // Empty: RBUF_SPACE == RBUF_SIZE(head==tail)
+ // Last 1 space: RBUF_SPACE == 2
+ // Full: RBUF_SPACE == 1(last cell of rbuf be never used.)
+ #define RBUF_SPACE() (rbuf_head < rbuf_tail ? (rbuf_tail - rbuf_head) : (RBUF_SIZE - rbuf_head + rbuf_tail))
+ // allow to send
+ #define rbuf_check_rts_lo() do { if (RBUF_SPACE() > 2) SERIAL_UART_RTS_LO(); } while (0)
+ // prohibit to send
+ #define rbuf_check_rts_hi() do { if (RBUF_SPACE() <= 2) SERIAL_UART_RTS_HI(); } while (0)
+#else
+ #define rbuf_check_rts_lo()
+ #define rbuf_check_rts_hi()
+#endif
+
+
void serial_init(void)
{
SERIAL_UART_INIT();
@@ -61,6 +77,7 @@ uint8_t serial_recv(void)
data = rbuf[rbuf_tail];
rbuf_tail = (rbuf_tail + 1) % RBUF_SIZE;
+ rbuf_check_rts_lo();
return data;
}
@@ -73,6 +90,7 @@ int16_t serial_recv2(void)
data = rbuf[rbuf_tail];
rbuf_tail = (rbuf_tail + 1) % RBUF_SIZE;
+ rbuf_check_rts_lo();
return data;
}
@@ -90,4 +108,5 @@ ISR(SERIAL_UART_RXD_VECT)
rbuf[rbuf_head] = SERIAL_UART_DATA;
rbuf_head = next;
}
+ rbuf_check_rts_hi();
}