From 8209e6e9a79982684e617d386505952a338b15f2 Mon Sep 17 00:00:00 2001 From: Bernard Blackham Date: Mon, 21 Jun 2004 17:59:59 +0000 Subject: [PATCH] Accept both CR and LF to denote newline. Ignore empty packets. Use my_strncpy for cleanliness. --- ROM2/main_basic.c | 10 +++------- ROM2/sci.c | 12 +++++------- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/ROM2/main_basic.c b/ROM2/main_basic.c index 3e88648..888932e 100644 --- a/ROM2/main_basic.c +++ b/ROM2/main_basic.c @@ -123,18 +123,14 @@ void ping_pong() { /* make sure it's really a ping */ if (sci_rx_buf[1] != 'I' || sci_rx_buf[2] != 'N' || - sci_rx_buf[3] != 'G') { + sci_rx_buf[3] != 'G' || + sci_rx_buf[4] != '\0') { send_nack(); return; } /* respond with ack & pong */ wait_for_tx_free(); - sci_tx_buf[0] = 'P'; - sci_tx_buf[1] = 'O'; - sci_tx_buf[2] = 'N'; - sci_tx_buf[3] = 'G'; - sci_tx_buf[4] = '\n'; - sci_tx_buf[5] = 0; + my_strncpy(sci_tx_buf, "PONG\n", BUFFER_LEN); send_packet(); } diff --git a/ROM2/sci.c b/ROM2/sci.c index 2346b28..739d706 100644 --- a/ROM2/sci.c +++ b/ROM2/sci.c @@ -40,7 +40,9 @@ void sci_rx_int() { return; } sci_rx_buf[sci_rx_buf_ptr] = _io_ports[M6811_SCDR]; - if (sci_rx_buf[sci_rx_buf_ptr] == '\n') { + if (sci_rx_buf[sci_rx_buf_ptr] == '\n' || + sci_rx_buf[sci_rx_buf_ptr] == '\r') { + if (sci_rx_buf_ptr == 0) return; /* we've read a blank packet in */ sci_rx_buf[sci_rx_buf_ptr] = '\0'; sci_have_packet = 1; sci_rx_buf_ptr = 0; @@ -68,15 +70,11 @@ void msg_clr() { } void send_ack() { - sci_tx_buf[0] = '!'; - sci_tx_buf[1] = '\n'; - sci_tx_buf[2] = '\0'; + my_strncpy(sci_tx_buf, "!\n", BUFFER_LEN); send_packet(); } void send_nack() { - sci_tx_buf[0] = '?'; - sci_tx_buf[1] = '\n'; - sci_tx_buf[2] = '\0'; + my_strncpy(sci_tx_buf, "?\n", BUFFER_LEN); send_packet(); } -- 2.20.1