4 char sci_tx_buf[BUFFER_LEN];
5 volatile char sci_rx_buf[BUFFER_LEN];
6 volatile bool sci_have_packet;
7 volatile u8 sci_rx_buf_ptr;
8 volatile bool sci_echo;
11 /* assumes clock of 4.91Mhz */
12 _io_ports[M6811_BAUD] = 0x03; /* 9600 baud */
14 /* Setup character format 1 start, 8-bits, 1 stop. */
15 _io_ports[M6811_SCCR1] = 0;
17 /* Enable reciever and transmitter & rx interrupt. */
18 _io_ports[M6811_SCCR2] = M6811_RIE | M6811_TE | M6811_RE;
25 void send_buffer(bool crlf) {
27 for (c = sci_tx_buf; *c; c++) {
28 /* wait for TX ready */
29 while (!(_io_ports[M6811_SCSR] & M6811_TDRE));
32 _io_ports[M6811_SCDR] = *c;
36 while (!(_io_ports[M6811_SCSR] & M6811_TDRE));
37 _io_ports[M6811_SCDR] = '\r';
38 while (!(_io_ports[M6811_SCSR] & M6811_TDRE));
39 _io_ports[M6811_SCDR] = '\n';
42 void send_string(char* c) {
44 while (!(_io_ports[M6811_SCSR] & M6811_TDRE)); /* wait for TX ready */
45 _io_ports[M6811_SCDR] = *c; /* send byte */
50 char buf = _io_ports[M6811_SCDR];
52 while (!(_io_ports[M6811_SCSR] & M6811_TDRE)); /* wait for TX ready */
53 _io_ports[M6811_SCDR] = buf; /* send byte */
56 /* XXX FIXME we should do something about errors. nack? */
57 if (sci_have_packet) {
61 sci_rx_buf[sci_rx_buf_ptr] = buf;
63 if (buf == '\n' || buf == '\r') {
64 sci_rx_buf[sci_rx_buf_ptr] = '\0';
68 if (sci_rx_buf_ptr+1 < BUFFER_LEN)
71 sci_rx_buf[BUFFER_LEN-1] = '\0'; /* this is as much as we could fit */
75 void sci_interrupt_serial() {
76 if (_io_ports[M6811_SCSR] & M6811_RDRF) sci_rx_int();
78 if (_io_ports[M6811_SCSR] & M6811_OR)
79 _io_ports[M6811_SCDR]; /* declare it a lost cause */
88 send_string("!" CRLF);
92 send_string("?" CRLF);