From 88bc2aa5e7e7c3870700a40d78829b51d3ae3754 Mon Sep 17 00:00:00 2001 From: "R. Steve McKown" Date: Wed, 7 Apr 2010 19:16:46 -0600 Subject: [PATCH] USCI fixes. * Watch out for sendData() clobbering TXBUF. * May solve a loss of UART TX chars. * USCI UartStream.send() gains nothing by immediately sending the 1st byte. * m_sobuf cannot be null in Interrupts.tx, so remove the check. --- tos/chips/msp430/usci/Msp430SpiP.nc | 1 + tos/chips/msp430/usci/Msp430UartP.nc | 12 ++++-------- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/tos/chips/msp430/usci/Msp430SpiP.nc b/tos/chips/msp430/usci/Msp430SpiP.nc index 22bfbbd3..142edb7b 100644 --- a/tos/chips/msp430/usci/Msp430SpiP.nc +++ b/tos/chips/msp430/usci/Msp430SpiP.nc @@ -250,6 +250,7 @@ implementation { if (end > m_len) end = m_len; + waitOnTx(); /* Don't assume that the last tx is done already */ call Registers.setTxbuf(m_txBuf ? m_txBuf[m_pos] : 0); while (++m_pos < end) { waitOnRx(); diff --git a/tos/chips/msp430/usci/Msp430UartP.nc b/tos/chips/msp430/usci/Msp430UartP.nc index dcdc5b38..a4bec076 100644 --- a/tos/chips/msp430/usci/Msp430UartP.nc +++ b/tos/chips/msp430/usci/Msp430UartP.nc @@ -146,14 +146,9 @@ implementation { atomic { if (m_sobuf || !buf || !len) return FAIL; - m_sobuf = buf; - m_solen = len; - while (!call Registers.getIfgTx()); + m_sbuf = m_sobuf = buf; + m_slen = m_solen = len; call Registers.setIeTx(); - call Registers.setTxbuf(*m_sobuf); - m_slen = m_solen - 1; - if (m_slen) - m_sbuf = m_sobuf + 1; return SUCCESS; } } @@ -163,12 +158,13 @@ implementation { /* 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 (!call Registers.getIfgTx()); /* in case interleaved UB.send */ while (m_slen && call Registers.getIfgTx()) { call Registers.setTxbuf(*m_sbuf); if (--m_slen) m_sbuf++; } - if (m_slen == 0 && m_sobuf) { + if (m_slen == 0) { call Registers.clrIeTx(); m_sobuf = 0; signal UartStream.sendDone(m_sobuf, m_solen, SUCCESS); -- 2.39.2