X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=ROM2%2Fsci.c;h=6ef3cd357acc2698c2eda1f7e90194cfe96caa77;hb=77f2f2b514bc8b3a5e4c23ab02afc16bdcedb3c6;hp=d7c9f287df6f4c84918681b88b159855b6ddaac0;hpb=f5bc521c83d95d35e852747402a44d1411252c2b;p=uccvend-snackrom.git diff --git a/ROM2/sci.c b/ROM2/sci.c index d7c9f28..6ef3cd3 100644 --- a/ROM2/sci.c +++ b/ROM2/sci.c @@ -5,7 +5,9 @@ char sci_tx_buf[BUFFER_LEN]; volatile char sci_rx_buf[BUFFER_LEN]; volatile bool sci_have_packet; volatile u8 sci_rx_buf_ptr; +volatile u8 sci_rx_buf_ptr_start; volatile bool sci_echo; +bool sci_doing_xmodem; void sci_init() { /* assumes clock of 4.91Mhz */ @@ -19,7 +21,9 @@ void sci_init() { sci_have_packet = 0; sci_rx_buf_ptr = 0; + sci_rx_buf_ptr_start = 0; sci_echo = 0; + sci_doing_xmodem = 0; } void send_buffer(bool crlf) { @@ -46,8 +50,23 @@ void send_string(char* c) { } } +char toupper(char c) { + if (c >= 'a' && c <= 'z') c -= 'a'-'A'; + return c; +} + void sci_rx_int() { char buf = _io_ports[M6811_SCDR]; + if (sci_doing_xmodem) { + if ((sci_rx_buf_ptr+1)%BUFFER_LEN == sci_rx_buf_ptr_start) { + /* we drop following bytes :( */ + return; + } + sci_rx_buf[sci_rx_buf_ptr] = buf; + sci_rx_buf_ptr++; + sci_rx_buf_ptr %= BUFFER_LEN; + return; + } if (sci_echo) { while (!(_io_ports[M6811_SCSR] & M6811_TDRE)); /* wait for TX ready */ _io_ports[M6811_SCDR] = buf; /* send byte */ @@ -58,7 +77,8 @@ void sci_rx_int() { /* overrun :( */ return; } - sci_rx_buf[sci_rx_buf_ptr] = buf; + /* we upper case because no commands care that things aren't */ + sci_rx_buf[sci_rx_buf_ptr] = toupper(buf); if (buf == '\n' || buf == '\r') { sci_rx_buf[sci_rx_buf_ptr] = '\0'; @@ -84,10 +104,29 @@ void msg_clr() { sci_rx_buf_ptr = 0; } -void send_ack() { - send_string("!" CRLF); +u16 sci_timer; +void serial_rti() { /* called every 6.6 ms */ + if (sci_timer) sci_timer--; } -void send_nack() { - send_string("?" CRLF); +/* for gdb compatibility */ +int serial_readchar(u8 timeout) { + int ret; + sci_timer = timeout * 152; + while (sci_timer && sci_rx_buf_ptr_start == sci_rx_buf_ptr); /* spin */ + if (sci_timer == 0) return SERIAL_TIMEOUT; + ret = sci_rx_buf[sci_rx_buf_ptr_start]; + sci_rx_buf_ptr_start++; + sci_rx_buf_ptr_start %= BUFFER_LEN; + return ret; } + +void serial_write(const char *str, int len) { + char *c, *end; + end = (char*)(str + len); + for (c = (char*)str; c < end; c++) { + while (!(_io_ports[M6811_SCSR] & M6811_TDRE)); /* wait for TX ready */ + _io_ports[M6811_SCDR] = *c; /* send byte */ + } +} +