]> oss.titaniummirror.com Git - tinyos-2.x.git/blobdiff - tos/chips/msp430/usart/Msp430SpiNoDmaP.nc
bugfix: previously two bytes were written to the U0TXBUF register before one was...
[tinyos-2.x.git] / tos / chips / msp430 / usart / Msp430SpiNoDmaP.nc
index fcb277700ec6876d098ac050b75b1750e03bcd16..3fc9d9a7067b07b8353fa2959ff38b21679c3e1b 100644 (file)
@@ -31,6 +31,7 @@
 
 /**
  * @author Jonathan Hui <jhui@archedrock.com>
+ * @author Jan Hauer <hauer@tkn.tu-berlin.de> (bugfix in continueOp())
  * @version $Revision$ $Date$
  */
 
@@ -56,9 +57,9 @@ implementation {
     SPI_ATOMIC_SIZE = 2,
   };
 
-  norace uint8_t* m_tx_buf;
-  norace uint8_t* m_rx_buf;
   norace uint16_t m_len;
+  norace uint8_t* COUNT_NOK(m_len) m_tx_buf;
+  norace uint8_t* COUNT_NOK(m_len) m_rx_buf;
   norace uint16_t m_pos;
   norace uint8_t m_client;
 
@@ -86,7 +87,9 @@ implementation {
   }
 
   async command void ResourceConfigure.unconfigure[ uint8_t id ]() {
+    call Usart.resetUsart(TRUE);
     call Usart.disableSpi();
+    call Usart.resetUsart(FALSE);
   }
 
   event void UsartResource.granted[ uint8_t id ]() {
@@ -95,11 +98,13 @@ implementation {
 
   async command uint8_t SpiByte.write( uint8_t tx ) {
     uint8_t byte;
-    call Usart.disableRxIntr();
+    // we are in spi mode which is configured to have turned off interrupts
+    //call Usart.disableRxIntr();
     call Usart.tx( tx );
     while( !call Usart.isRxIntrPending() );
+    call Usart.clrRxIntr();
     byte = call Usart.rx();
-    call Usart.enableRxIntr();
+    //call Usart.enableRxIntr();
     return byte;
   }
 
@@ -107,7 +112,7 @@ implementation {
   default async command error_t UsartResource.request[ uint8_t id ]() { return FAIL; }
   default async command error_t UsartResource.immediateRequest[ uint8_t id ]() { return FAIL; }
   default async command error_t UsartResource.release[ uint8_t id ]() { return FAIL; }
-  default async command msp430_spi_config_t* Msp430SpiConfigure.getConfig[uint8_t id]() {
+  default async command msp430_spi_union_config_t* Msp430SpiConfigure.getConfig[uint8_t id]() {
     return &msp430_spi_default_config;
   }
 
@@ -115,25 +120,24 @@ implementation {
 
   void continueOp() {
 
-    uint8_t end;
-    uint8_t tmp;
+   uint8_t end;
+   uint8_t tmp;
 
-    atomic {
-      call Usart.tx( m_tx_buf ? m_tx_buf[ m_pos ] : 0 );
+   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;
+     end = m_pos + SPI_ATOMIC_SIZE;
+     if ( end > m_len )
+       end = m_len;
 
-      while ( ++m_pos < end ) {
-        while( !call Usart.isTxIntrPending() );
-        call Usart.tx( m_tx_buf ? m_tx_buf[ m_pos ] : 0 );
-        while( !call Usart.isRxIntrPending() );
-        tmp = call Usart.rx();
-        if ( m_rx_buf )
-          m_rx_buf[ m_pos - 1 ] = tmp;
-      }
-    }
+     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 );
+     }
+   }
 
   }