5 char sci_tx_buf[BUFFER_LEN];
6 volatile char sci_rx_buf[BUFFER_LEN];
7 volatile bool sci_have_packet;
8 volatile u8 sci_rx_buf_ptr;
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;
26 for (c = sci_tx_buf; *c; c++) {
27 /* wait for TX ready */
28 while (!(_io_ports[M6811_SCSR] & M6811_TDRE));
31 _io_ports[M6811_SCDR] = *c;
36 /* XXX FIXME we should do something about errors. nack? */
37 if (sci_have_packet) {
39 _io_ports[M6811_SCDR]; /* read it anyway */
42 sci_rx_buf[sci_rx_buf_ptr] = _io_ports[M6811_SCDR];
43 if (sci_rx_buf[sci_rx_buf_ptr] == '\n' ||
44 sci_rx_buf[sci_rx_buf_ptr] == '\r') {
45 if (sci_rx_buf_ptr == 0) return; /* we've read a blank packet in */
46 sci_rx_buf[sci_rx_buf_ptr] = '\0';
51 if (sci_rx_buf_ptr >= BUFFER_LEN) {
52 sci_rx_buf[BUFFER_LEN] = '\0'; /* this is as much as we could fit */
58 void sci_interrupt_serial() {
61 if (_io_ports[M6811_SCSR] & M6811_RDRF) sci_rx_int();
63 if (_io_ports[M6811_SCSR] & M6811_OR)
64 _io_ports[M6811_SCDR]; /* declare it a lost cause */
73 my_strncpy(sci_tx_buf, "!\n", BUFFER_LEN);
78 my_strncpy(sci_tx_buf, "?\n", BUFFER_LEN);