X-Git-Url: http://pileus.org/git/?a=blobdiff_plain;f=hw2%2Fserial_irq.c;h=68945cfcbb759e8e46361046f7c40c7ce7734e0f;hb=70a817bdd055b39c1990778594ed97a532748d31;hp=67beeab353ff9ac707eb13696a678925f41443e9;hpb=fcf3a5999ccfbb4a88f747ee3d9ed1c9c81891de;p=~andy%2Fcsm213a-hw diff --git a/hw2/serial_irq.c b/hw2/serial_irq.c index 67beeab..68945cf 100644 --- a/hw2/serial_irq.c +++ b/hw2/serial_irq.c @@ -4,6 +4,7 @@ #include #include "serial_api.h" #include "serial_irq.h" +#include "timer_dma.h" /* Defines */ #define SIRQ_LEN 1024 @@ -21,6 +22,14 @@ struct sirq_t { queue_t rcv; }; +/* Test data */ +extern uint32_t test_xmt_enab; +extern uint64_t test_xmt_time0; +extern uint64_t test_xmt_time1; + +extern uint32_t test_rcv_enab; +extern uint64_t test_rcv_time; + /* Port data */ static sirq_t sirq_ports[SIRQ_NUM_UART]; @@ -32,7 +41,17 @@ void sirq_handler(uint32_t _port, SerialIrq event) // Handle transmit if (event == TxIrq && port->xmt.rix != port->xmt.wix) { int byte = port->xmt.buf[port->xmt.rix]; + + uint64_t time0 = tdma_time(); serial_putc(&port->uart, byte); + uint64_t time1 = tdma_time(); + + if (test_xmt_enab) { + test_xmt_time0 = time0; + test_xmt_time1 = time1; + test_xmt_enab = 0; + } + port->xmt.rix = (port->xmt.rix+1) % SIRQ_LEN; } else { serial_irq_set(&port->uart, TxIrq, 0); @@ -75,7 +94,7 @@ void sirq_putc(sirq_t *port, int byte) int sirq_getc(sirq_t *port) { int byte = 0; - if (port->rcv.rix < port->rcv.wix) { + if (port->rcv.rix != port->rcv.wix) { byte = port->rcv.buf[port->rcv.rix]; port->rcv.rix = (port->rcv.rix+1) % SIRQ_LEN; } @@ -93,7 +112,29 @@ void sirq_write(sirq_t *port, void *data, int len) /* Check if port is writable */ int sirq_ready(sirq_t *port) { - return port->rcv.rix < port->rcv.wix; + return port->rcv.rix != port->rcv.wix; +} + +/* Debug print */ +void sirq_debug(sirq_t *port) +{ + sirq_printf("xmt - wix:%03x rix:%03x\r\n", port->xmt.wix, port->xmt.rix); + sirq_printf("rcv - wix:%03x rix:%03x\r\n", port->rcv.wix, port->rcv.rix); + sirq_printf("irq - ??\r\n"); + sirq_printf("uart - ??\r\n"); + + // __IO uint8_t BDH; + // __IO uint8_t BDL; + // __IO uint8_t C1; + // __IO uint8_t C2; + // __IO uint8_t S1; + // __IO uint8_t S2; + // __IO uint8_t C3; + // __IO uint8_t D; + // __IO uint8_t MA1; + // __IO uint8_t MA2; + // __IO uint8_t C4; + // __IO uint8_t C5; } /* Write ASCII data to the output queue */