]> Pileus Git - ~andy/csm213a-hw/blobdiff - hw2/serial_irq.c
Fix bug in irq code
[~andy/csm213a-hw] / hw2 / serial_irq.c
index 68945cfcbb759e8e46361046f7c40c7ce7734e0f..e002ce94f49a07c96d7436612ab4cbaa014bc214 100644 (file)
@@ -20,16 +20,9 @@ struct sirq_t {
        serial_t uart;\r
        queue_t  xmt;\r
        queue_t  rcv;\r
+       int      irq;\r
 };\r
 \r
-/* Test data */\r
-extern uint32_t test_xmt_enab;\r
-extern uint64_t test_xmt_time0;\r
-extern uint64_t test_xmt_time1;\r
-\r
-extern uint32_t test_rcv_enab;\r
-extern uint64_t test_rcv_time;\r
-\r
 /* Port data */\r
 static sirq_t sirq_ports[SIRQ_NUM_UART];\r
 \r
@@ -41,20 +34,11 @@ void sirq_handler(uint32_t _port, SerialIrq event)
        // Handle transmit\r
        if (event == TxIrq && port->xmt.rix != port->xmt.wix) {\r
                int byte = port->xmt.buf[port->xmt.rix];\r
-\r
-               uint64_t time0 = tdma_time();\r
                serial_putc(&port->uart, byte);\r
-               uint64_t time1 = tdma_time();\r
-\r
-               if (test_xmt_enab) {\r
-                       test_xmt_time0 = time0;\r
-                       test_xmt_time1 = time1;\r
-                       test_xmt_enab  = 0;\r
-               }\r
-\r
                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
@@ -87,7 +71,10 @@ 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