X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;ds=sidebyside;f=ROM2%2Fsci.c;h=2346b28569b60332f84f04c28feb2feda1a9cb04;hb=c1fd53d73bce8779c822e3ed74de94f40714f9ca;hp=3241f23c2cd971b34b6a31f7705ebfe8b5ab1426;hpb=c34cbe163ce52f1d8fc553993701054f4942152f;p=uccvend-snackrom.git diff --git a/ROM2/sci.c b/ROM2/sci.c index 3241f23..2346b28 100644 --- a/ROM2/sci.c +++ b/ROM2/sci.c @@ -1,4 +1,5 @@ #include "vend.h" +#include "chime.h" #include "sci.h" char sci_tx_buf[BUFFER_LEN]; @@ -14,7 +15,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 +32,11 @@ void send_packet() { } } -void rx_int() { - if (sci_have_packet) return; - if (sci_rx_buf_ptr >= BUFFER_LEN) { +void sci_rx_int() { + /* XXX FIXME we should do something about errors. nack? */ + 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 +46,20 @@ 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() { + chime_start(); + + if (_io_ports[M6811_SCSR] & M6811_RDRF) sci_rx_int(); + + if (_io_ports[M6811_SCSR] & M6811_OR) + _io_ports[M6811_SCDR]; /* declare it a lost cause */ } void msg_clr() { @@ -54,10 +67,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';