]> oss.titaniummirror.com Git - tinyos-2.x.git/commitdiff
Fold in Alec's changes, with bug fix for RX interrupt.
authorscipio <scipio>
Tue, 27 Nov 2007 19:26:45 +0000 (19:26 +0000)
committerscipio <scipio>
Tue, 27 Nov 2007 19:26:45 +0000 (19:26 +0000)
tos/chips/atm128/Atm128UartP.nc

index 4891e734a3d791a3ba492af13396f3ea4f3500ab..2b904b41422bd371b1efd2dce1788b0343888387 100644 (file)
 /**
  * @author Alec Woo <awoo@archrock.com>
  * @author Jonathan Hui <jhui@archrock.com>
+ * @author Philip Levis <pal@cs.stanford.edu> (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 <Timer.h>
@@ -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 )