diff options
author | tmk <nobody@nowhere> | 2014-07-20 14:42:44 +0900 |
---|---|---|
committer | tmk <nobody@nowhere> | 2014-07-30 14:38:26 +0900 |
commit | 3e7875455ed392ce5238efa0734e82995e1f8040 (patch) | |
tree | 57cec7eb223614680643afd7812db4553f8789ef /protocol/serial_uart.c | |
parent | 50bcaa66c468f350a538279667a0fa68090c55a9 (diff) |
Add flow control by firmware to serial_uart
Diffstat (limited to 'protocol/serial_uart.c')
-rw-r--r-- | protocol/serial_uart.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/protocol/serial_uart.c b/protocol/serial_uart.c index 600340cd8e..35df27fd6e 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(); } |