X-Git-Url: https://oss.titaniummirror.com/gitweb/?a=blobdiff_plain;f=tos%2Fchips%2Fmsp430%2Fusci%2FMsp430UartP.nc;h=6f6384db9618ffef37ebbdfd2a91fa0c6860e702;hb=704e3e7ba90d136a08eb9ed930bf3552b5540517;hp=f998e3cef3a39cc52f137cb631d0e67d400b8b79;hpb=86e1f38f71efaa4ef35d676dde514fb9884f124e;p=tinyos-2.x.git diff --git a/tos/chips/msp430/usci/Msp430UartP.nc b/tos/chips/msp430/usci/Msp430UartP.nc index f998e3ce..6f6384db 100644 --- a/tos/chips/msp430/usci/Msp430UartP.nc +++ b/tos/chips/msp430/usci/Msp430UartP.nc @@ -61,14 +61,14 @@ implementation { uint8_t m_pins; uint8_t* m_sobuf; /* Original buffer ptr from UartStream.send() */ - uint8_t m_solen; /* Original buffer len from UartStream.send() */ + uint16_t m_solen; /* Original buffer len from UartStream.send() */ uint8_t* m_sbuf; /* Position of next char to send */ - uint8_t m_slen; /* Len of chars in m_sbuf to send */ + uint16_t m_slen; /* Len of chars in m_sbuf to send */ bool m_rxie; /* Set if rxie has been enabled to UartStream.receive() */ uint8_t* m_robuf; /* Original receive buffer */ - uint8_t m_rolen; /* Original (maximum) receive len */ + uint16_t m_rolen; /* Original (maximum) receive len */ uint8_t* m_rbuf; /* Position of next byte in which to receive a char */ - uint8_t m_rlen; /* Remaining length in receive buffer */ + uint16_t m_rlen; /* Remaining length in receive buffer */ sfrb(MYBRX, 219U); @@ -117,13 +117,12 @@ implementation { { atomic { /* Disable the device */ - call Registers.setCtl1(UCSYNC); + call Registers.setCtl1(UCSWRST); /* Clear interrupts and interrupt flags */ call Registers.clrIeRx(); call Registers.clrIeTx(); call Registers.clrIfgRx(); - call Registers.clrIfgTx(); /* Restore pins to their pre-configure state */ if (m_pins & PINS_RXD) @@ -152,6 +151,7 @@ implementation { return FAIL; m_sobuf = buf; m_solen = len; + while (!call Registers.getIfgTx()); call Registers.setIeTx(); call Registers.setTxbuf(*m_sobuf); m_slen = m_solen - 1; @@ -163,6 +163,9 @@ implementation { async event void Interrupts.tx() { + /* FIXME: this can cause an arbitrarily long ISR, if m_slen is large. + * But depending on timing, we may always only write 1 byte. + */ while (m_slen && call Registers.getIfgTx()) { call Registers.setTxbuf(*m_sbuf); if (--m_slen) @@ -170,7 +173,6 @@ implementation { } if (m_slen == 0 && m_sobuf) { call Registers.clrIeTx(); - call Registers.clrIfgTx(); m_sobuf = 0; signal UartStream.sendDone(m_sobuf, m_solen, SUCCESS); } @@ -237,25 +239,26 @@ implementation { async event void Interrupts.rx(uint8_t byte) { - atomic { - if (m_robuf) { - /* receive() takes precedence if active */ - while (m_rlen && call Registers.getIfgRx()) { - *m_rbuf = byte; - if (--m_rlen) - m_rbuf++; - } - if (m_rlen == 0 && m_robuf) { - if (m_rxie) { - call Registers.clrIeRx(); - call Registers.clrIfgRx(); - } - m_robuf = 0; - signal UartStream.receiveDone(m_robuf, m_rolen, SUCCESS); + if (m_robuf) { + /* receive() takes precedence if active */ + /* FIXME: an arbitrarily long ISR may occur if m_rlen is large. + * But depending on timing, we may always only read 1 byte. + */ + while (m_rlen && call Registers.getIfgRx()) { + *m_rbuf = byte; + if (--m_rlen) + m_rbuf++; + } + if (m_rlen == 0 && m_robuf) { + if (m_rxie) { + call Registers.clrIeRx(); + call Registers.clrIfgRx(); } - } else - signal UartStream.receivedByte(byte); - } + m_robuf = 0; + signal UartStream.receiveDone(m_robuf, m_rolen, SUCCESS); + } + } else + signal UartStream.receivedByte(byte); } default async command const msp430_usci_uart_t* Configure.get()