From a6cf74302a602a5606483ffac7cf3f9376fdd604 Mon Sep 17 00:00:00 2001 From: janhauer Date: Mon, 16 Jun 2008 07:31:21 +0000 Subject: [PATCH] bugfix: previously two bytes were written to the U0TXBUF register before one was read from the U0RXBUF, which at bus speed >500KHz could lead to a race condition. This has been fixed. --- tos/chips/msp430/usart/Msp430SpiNoDmaP.nc | 40 +++++++++++------------ 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/tos/chips/msp430/usart/Msp430SpiNoDmaP.nc b/tos/chips/msp430/usart/Msp430SpiNoDmaP.nc index 9409ecba..3fc9d9a7 100644 --- a/tos/chips/msp430/usart/Msp430SpiNoDmaP.nc +++ b/tos/chips/msp430/usart/Msp430SpiNoDmaP.nc @@ -31,6 +31,7 @@ /** * @author Jonathan Hui + * @author Jan Hauer (bugfix in continueOp()) * @version $Revision$ $Date$ */ @@ -119,27 +120,24 @@ implementation { void continueOp() { - uint8_t end; - uint8_t tmp; - - atomic { - call Usart.tx( m_tx_buf ? m_tx_buf[ m_pos ] : 0 ); - - end = m_pos + SPI_ATOMIC_SIZE; - if ( end > m_len ) - end = m_len; - - while ( ++m_pos < end ) { - while( !call Usart.isTxIntrPending() ); - call Usart.clrTxIntr(); - call Usart.tx( m_tx_buf ? m_tx_buf[ m_pos ] : 0 ); - while( !call Usart.isRxIntrPending() ); - call Usart.clrRxIntr(); - tmp = call Usart.rx(); - if ( m_rx_buf ) - m_rx_buf[ m_pos - 1 ] = tmp; - } - } + uint8_t end; + uint8_t tmp; + + atomic { + call Usart.tx( m_tx_buf ? m_tx_buf[ m_pos ] : 0 ); + + end = m_pos + SPI_ATOMIC_SIZE; + if ( end > m_len ) + end = m_len; + + while ( ++m_pos < end ) { + while( !call Usart.isRxIntrPending() ); + tmp = call Usart.rx(); + if ( m_rx_buf ) + m_rx_buf[ m_pos - 1 ] = tmp; + call Usart.tx( m_tx_buf ? m_tx_buf[ m_pos ] : 0 ); + } + } } -- 2.39.2