]> Pileus Git - ~andy/csm213a-hw/blobdiff - hw2/serial_irq.c
Import testing code and update makefiles
[~andy/csm213a-hw] / hw2 / serial_irq.c
index 67beeab353ff9ac707eb13696a678925f41443e9..e002ce94f49a07c96d7436612ab4cbaa014bc214 100644 (file)
@@ -4,6 +4,7 @@
 #include <stdio.h>\r
 #include "serial_api.h"\r
 #include "serial_irq.h"\r
+#include "timer_dma.h"\r
 \r
 /* Defines */\r
 #define SIRQ_LEN  1024\r
@@ -19,6 +20,7 @@ struct sirq_t {
        serial_t uart;\r
        queue_t  xmt;\r
        queue_t  rcv;\r
+       int      irq;\r
 };\r
 \r
 /* Port data */\r
@@ -36,6 +38,7 @@ void sirq_handler(uint32_t _port, SerialIrq event)
                port->xmt.rix = (port->xmt.rix+1) % SIRQ_LEN;\r
        } else {\r
                serial_irq_set(&port->uart, TxIrq, 0);\r
+               port->irq = 0;\r
        }\r
 \r
        // Handle receive\r
@@ -68,14 +71,17 @@ void sirq_putc(sirq_t *port, int byte)
 {\r
        port->xmt.buf[port->xmt.wix] = byte;\r
        port->xmt.wix = (port->xmt.wix+1) % SIRQ_LEN;\r
-       serial_irq_set(&port->uart, TxIrq, 1);\r
+       if (!port->irq) {\r
+               port->irq = 1;\r
+               serial_irq_set(&port->uart, TxIrq, 1);\r
+       }\r
 }\r
 \r
 /* Read byte from the port */\r
 int sirq_getc(sirq_t *port)\r
 {\r
        int byte = 0;\r
-       if (port->rcv.rix < port->rcv.wix) {\r
+       if (port->rcv.rix != port->rcv.wix) {\r
                byte = port->rcv.buf[port->rcv.rix];\r
                port->rcv.rix = (port->rcv.rix+1) % SIRQ_LEN;\r
        }\r
@@ -93,7 +99,29 @@ void sirq_write(sirq_t *port, void *data, int len)
 /* Check if port is writable */\r
 int sirq_ready(sirq_t *port)\r
 {\r
-       return port->rcv.rix < port->rcv.wix;\r
+       return port->rcv.rix != port->rcv.wix;\r
+}\r
+\r
+/* Debug print */\r
+void sirq_debug(sirq_t *port)\r
+{\r
+       sirq_printf("xmt  - wix:%03x rix:%03x\r\n", port->xmt.wix, port->xmt.rix);\r
+       sirq_printf("rcv  - wix:%03x rix:%03x\r\n", port->rcv.wix, port->rcv.rix);\r
+       sirq_printf("irq  - ??\r\n");\r
+       sirq_printf("uart - ??\r\n");\r
+\r
+       // __IO uint8_t BDH;     \r
+       // __IO uint8_t BDL;     \r
+       // __IO uint8_t C1;      \r
+       // __IO uint8_t C2;      \r
+       // __IO uint8_t S1;      \r
+       // __IO uint8_t S2;      \r
+       // __IO uint8_t C3;      \r
+       // __IO uint8_t D;       \r
+       // __IO uint8_t MA1;     \r
+       // __IO uint8_t MA2;     \r
+       // __IO uint8_t C4;      \r
+       // __IO uint8_t C5;      \r
 }\r
 \r
 /* Write ASCII data to the output queue */\r