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;
10 /* assumes clock of 4.91Mhz */
11 _io_ports[M6811_BAUD] = 0x03; /* 9600 baud */
13 /* Setup character format 1 start, 8-bits, 1 stop. */
14 _io_ports[M6811_SCCR1] = 0;
16 /* Enable reciever and transmitter & rx interrupt. */
17 _io_ports[M6811_SCCR2] = M6811_RIE | M6811_TE | M6811_RE;
25 for (c = sci_tx_buf; *c; c++) {
26 /* wait for TX ready */
27 while (!(_io_ports[M6811_SCSR] & M6811_TDRE));
30 _io_ports[M6811_SCDR] = *c;
35 /* XXX FIXME we should do something about errors. nack? */
36 if (sci_have_packet) {
38 _io_ports[M6811_SCDR]; /* read it anyway */
41 sci_rx_buf[sci_rx_buf_ptr] = _io_ports[M6811_SCDR];
42 if (sci_rx_buf[sci_rx_buf_ptr] == '\n' ||
43 sci_rx_buf[sci_rx_buf_ptr] == '\r') {
44 if (sci_rx_buf_ptr == 0) return; /* we've read a blank packet in */
45 sci_rx_buf[sci_rx_buf_ptr] = '\0';
50 if (sci_rx_buf_ptr >= BUFFER_LEN) {
51 sci_rx_buf[BUFFER_LEN] = '\0'; /* this is as much as we could fit */
57 void sci_interrupt_serial() {
58 if (_io_ports[M6811_SCSR] & M6811_RDRF) sci_rx_int();
60 if (_io_ports[M6811_SCSR] & M6811_OR)
61 _io_ports[M6811_SCDR]; /* declare it a lost cause */
70 my_strncpy(sci_tx_buf, "!\n", BUFFER_LEN);
75 my_strncpy(sci_tx_buf, "?\n", BUFFER_LEN);