From: Bernard Blackham Date: Mon, 21 Jun 2004 16:40:16 +0000 (+0000) Subject: Bug fixes when buffer is full. X-Git-Tag: ROMW~30 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=47ccc4dcb3e35d80f402793e3715e4a6166b3629;p=uccvend-snackrom.git Bug fixes when buffer is full. --- diff --git a/ROM2/sci.c b/ROM2/sci.c index 3241f23..4ce0d36 100644 --- a/ROM2/sci.c +++ b/ROM2/sci.c @@ -14,7 +14,7 @@ void sci_init() { _io_ports[M6811_SCCR1] = 0; /* Enable reciever and transmitter & rx interrupt. */ - _io_ports[M6811_SCCR2] = 0x2c; + _io_ports[M6811_SCCR2] = M6811_RIE | M6811_TE | M6811_RE; sci_have_packet = 0; sci_rx_buf_ptr = 0; @@ -31,13 +31,10 @@ void send_packet() { } } -void rx_int() { - if (sci_have_packet) return; - if (sci_rx_buf_ptr >= BUFFER_LEN) { +void sci_rx_int() { + if (sci_have_packet) { /* overrun :( */ - sci_rx_buf[BUFFER_LEN] = '\0'; - sci_have_packet = 1; - sci_rx_buf_ptr = 0; + _io_ports[M6811_SCDR]; /* read it anyway */ return; } sci_rx_buf[sci_rx_buf_ptr] = _io_ports[M6811_SCDR]; @@ -47,6 +44,15 @@ void rx_int() { sci_rx_buf_ptr = 0; } sci_rx_buf_ptr++; + if (sci_rx_buf_ptr >= BUFFER_LEN) { + sci_rx_buf[BUFFER_LEN] = '\0'; /* this is as much as we could fit */ + sci_have_packet = 1; + sci_rx_buf_ptr = 0; + } +} + +void sci_interrupt_serial() { + if (_io_ports[M6811_SCSR] & M6811_RDRF) sci_rx_int(); } void msg_clr() { @@ -54,10 +60,6 @@ void msg_clr() { sci_rx_buf_ptr = 0; } -void sci_interrupt_serial() { - if (_io_ports[M6811_SCSR] & M6811_RDRF) rx_int(); -} - void send_ack() { sci_tx_buf[0] = '!'; sci_tx_buf[1] = '\n';