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 */
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) {
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 */
void send_nack() {
send_string("?" CRLF);
}
+
+u16 sci_timer;
+void serial_rti() { /* called every 6.6 ms */
+ if (sci_timer) sci_timer--;
+}
+
+/* for gdb compatibility */
+int serial_readchar(u8 timeout) {
+ sci_timer = timeout * 152;
+ while (sci_timer && sci_rx_buf_ptr_start == sci_rx_buf_ptr); /* spin */
+ if (sci_timer == 0) return SERIAL_TIMEOUT;
+ return sci_rx_buf[sci_rx_buf_ptr_start++];
+}
+
+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 */
+ }
+}