From ead74fea4d8536c4641ae71d0c4e83770cf811fe Mon Sep 17 00:00:00 2001 From: scipio Date: Tue, 27 Nov 2007 19:26:45 +0000 Subject: [PATCH] Fold in Alec's changes, with bug fix for RX interrupt. --- tos/chips/atm128/Atm128UartP.nc | 50 ++++++++++++++++++++++++++++++--- 1 file changed, 46 insertions(+), 4 deletions(-) diff --git a/tos/chips/atm128/Atm128UartP.nc b/tos/chips/atm128/Atm128UartP.nc index 4891e734..2b904b41 100644 --- a/tos/chips/atm128/Atm128UartP.nc +++ b/tos/chips/atm128/Atm128UartP.nc @@ -32,7 +32,13 @@ /** * @author Alec Woo * @author Jonathan Hui + * @author Philip Levis (maintainer) * @version $Revision$ $Date$ + * + * Modification @ 11/27 (pal): Folded in Alec's reimplementation + * from the -devel branch. Fixed bug in RX interrupts, where + * they were not enabled on start. Possibly due to alternative + * ARC TEP113 implementation that uses UartStream? */ #include @@ -57,6 +63,8 @@ implementation{ norace uint16_t m_tx_len, m_rx_len; norace uint16_t m_tx_pos, m_rx_pos; norace uint16_t m_byte_time; + norace uint8_t m_rx_intr; + norace uint8_t m_tx_intr; command error_t Init.init() { if (PLATFORM_BAUDRATE == 19200UL) @@ -67,8 +75,18 @@ implementation{ } command error_t StdControl.start(){ + /* make sure interupts are off and set flags */ + call HplUart.disableTxIntr(); + call HplUart.disableRxIntr(); + m_rx_intr = 0; + m_tx_intr = 0; + + /* enable tx/rx */ call HplUartTxControl.start(); call HplUartRxControl.start(); + + // Bug fix: pal 11/26/07: RX interrupts should be enabled on start + call HplUart.enableRxIntr(); return SUCCESS; } @@ -79,12 +97,18 @@ implementation{ } async command error_t UartStream.enableReceiveInterrupt(){ - call HplUartRxControl.start(); + atomic{ + m_rx_intr = 3; + call HplUart.enableRxIntr(); + } return SUCCESS; } async command error_t UartStream.disableReceiveInterrupt(){ - call HplUartRxControl.stop(); + atomic{ + call HplUart.disableRxIntr(); + m_rx_intr = 0; + } return SUCCESS; } @@ -98,6 +122,8 @@ implementation{ m_rx_buf = buf; m_rx_len = len; m_rx_pos = 0; + m_rx_intr |= 1; + call HplUart.enableRxIntr(); } return SUCCESS; @@ -110,7 +136,13 @@ implementation{ m_rx_buf[ m_rx_pos++ ] = data; if ( m_rx_pos >= m_rx_len ) { uint8_t* buf = m_rx_buf; - m_rx_buf = NULL; + atomic{ + m_rx_buf = NULL; + if(m_rx_intr != 3){ + call HplUart.disableRxIntr(); + m_rx_intr = 0; + } + } signal UartStream.receiveDone( buf, m_rx_len, SUCCESS ); } } @@ -130,6 +162,8 @@ implementation{ m_tx_buf = buf; m_tx_len = len; m_tx_pos = 0; + m_tx_intr = 1; + call HplUart.enableTxIntr(); call HplUart.tx( buf[ m_tx_pos++ ] ); return SUCCESS; @@ -144,22 +178,30 @@ implementation{ else { uint8_t* buf = m_tx_buf; m_tx_buf = NULL; + m_tx_intr = 0; + call HplUart.disableTxIntr(); signal UartStream.sendDone( buf, m_tx_len, SUCCESS ); } } async command error_t UartByte.send( uint8_t byte ){ + if(m_tx_intr) + return FAIL; + call HplUart.tx( byte ); while ( !call HplUart.isTxEmpty() ); return SUCCESS; } async command error_t UartByte.receive( uint8_t * byte, uint8_t timeout){ - + uint16_t timeout_micro = m_byte_time * timeout + 1; uint16_t start; + if(m_rx_intr) + return FAIL; + start = call Counter.get(); while ( call HplUart.isRxEmpty() ) { if ( ( (uint16_t)call Counter.get() - start ) >= timeout_micro ) -- 2.39.2