Skip to content

Commit

Permalink
snek-duino: Add TX flow control
Browse files Browse the repository at this point in the history
Stop sending characters on ^S, start on ^Q

Signed-off-by: Keith Packard <keithp@keithp.com>
  • Loading branch information
keith-packard committed Feb 10, 2019
1 parent 8cf163b commit 07f2f9b
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions snek-duino/snek-duino-serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ typedef volatile struct uart_ring {

static uart_ring_t rx_ring, tx_ring;
static volatile uint8_t rx_flow;
static volatile uint8_t tx_flow;

/* Start at EMPTY state so we send a ^Q at startup time */
#define FLOW_EMPTY 0
Expand Down Expand Up @@ -81,7 +82,7 @@ next_flow(void)
static void
_snek_uart_tx_start(void)
{
if ((UCSR0A & (1 << UDRE0))) {
if ((UCSR0A & (1 << UDRE0)) && !tx_flow) {
uint8_t c;

if ((rx_flow & 1) == 0) {
Expand Down Expand Up @@ -134,8 +135,18 @@ ISR(USART_RX_vect)
{
uint8_t c = UDR0;

if (c == ('c' & 0x1f))
switch (c) {
case 'c' & 0x1f:
snek_abort = true;
break;
case 's' & 0x1f:
tx_flow = true;
return;
case 'q' & 0x1f:
tx_flow = false;
_snek_uart_tx_start();
return;
}

ring_put(&rx_ring, c);

Expand Down

0 comments on commit 07f2f9b

Please sign in to comment.