]> oss.titaniummirror.com Git - tinyos-2.x.git/commitdiff
Update to include paramaterization of the UartStream interface as well as push Resour...
authorklueska <klueska>
Wed, 21 May 2008 22:11:57 +0000 (22:11 +0000)
committerklueska <klueska>
Wed, 21 May 2008 22:11:57 +0000 (22:11 +0000)
12 files changed:
tos/chips/msp430/usart/Msp430I2CC.nc
tos/chips/msp430/usart/Msp430Spi0C.nc
tos/chips/msp430/usart/Msp430Spi1C.nc
tos/chips/msp430/usart/Msp430Uart0C.nc
tos/chips/msp430/usart/Msp430Uart0P.nc
tos/chips/msp430/usart/Msp430Uart1C.nc
tos/chips/msp430/usart/Msp430Uart1P.nc
tos/chips/msp430/usart/Msp430UartP.nc
tos/chips/msp430/usart/Msp430Usart0C.nc
tos/chips/msp430/usart/Msp430Usart1C.nc
tos/chips/msp430/usart/Msp430UsartShare0P.nc
tos/chips/msp430/usart/Msp430UsartShare1P.nc

index 7c5727bc754ed98a2309be7a9a94f7ef1af258ea..d36e2fa5a0961bca68fc2b8f10e4b12fd106e40d 100644 (file)
@@ -40,6 +40,7 @@
 generic configuration Msp430I2CC() {
   
   provides interface Resource;
+  provides interface ResourceRequested;
   provides interface I2CPacket<TI2CBasicAddr> as I2CBasicAddr;
   
   uses interface Msp430I2CConfigure;
@@ -58,6 +59,7 @@ implementation {
   Msp430I2CConfigure = I2CP.Msp430I2CConfigure[ CLIENT_ID ];
   
   components new Msp430Usart0C() as UsartC;
+  ResourceRequested = UsartC;
   I2CP.ResourceConfigure[ CLIENT_ID ] <- UsartC.ResourceConfigure;
   I2CP.UsartResource[ CLIENT_ID ] -> UsartC.Resource;
   I2CP.I2CInterrupts -> UsartC.HplMsp430I2CInterrupts;
index cf22622359f00aefc48e20c8e68e2c78a356ac2a..fe87e86243aa9d809749af7b1ade80f502589921 100644 (file)
@@ -45,6 +45,7 @@
 generic configuration Msp430Spi0C() {
 
   provides interface Resource;
+  provides interface ResourceRequested;
   provides interface SpiByte;
   provides interface SpiPacket;
 
@@ -70,6 +71,7 @@ implementation {
   Msp430SpiConfigure = SpiP.Msp430SpiConfigure[ CLIENT_ID ];
 
   components new Msp430Usart0C() as UsartC;
+  ResourceRequested = UsartC;
   SpiP.ResourceConfigure[ CLIENT_ID ] <- UsartC.ResourceConfigure;
   SpiP.UsartResource[ CLIENT_ID ] -> UsartC.Resource;
   SpiP.UsartInterrupts -> UsartC.HplMsp430UsartInterrupts;
index 61363f331b0e69ebd083a618c1f54636f20c4c94..110d747028feb8a0c0cd63bebb7dd59f5e8a5181 100644 (file)
@@ -45,6 +45,7 @@
 generic configuration Msp430Spi1C() {
 
   provides interface Resource;
+  provides interface ResourceRequested;
   provides interface SpiByte;
   provides interface SpiPacket;
 
@@ -70,6 +71,7 @@ implementation {
   Msp430SpiConfigure = SpiP.Msp430SpiConfigure[ CLIENT_ID ];
 
   components new Msp430Usart1C() as UsartC;
+  ResourceReqeusted = UsartC;
   SpiP.ResourceConfigure[ CLIENT_ID ] <- UsartC.ResourceConfigure;
   SpiP.UsartResource[ CLIENT_ID ] -> UsartC.Resource;
   SpiP.UsartInterrupts -> UsartC.HplMsp430UsartInterrupts;
index 6079a94d6d134237e50ba839dea8f8370adc3420..0aa8033618d52f0b97602dce3b7354caf2301c93 100644 (file)
@@ -33,6 +33,7 @@
  * An implementation of the UART on USART0 for the MSP430.
  * @author Vlado Handziski <handzisk@tkn.tu-berlin.de>
  * @author Jonathan Hui <jhui@archedrock.com>
+ * @author Eric B. Decker <cire831@gmail.com>
  * @version $Revision$ $Date$
  */
 
@@ -41,6 +42,7 @@
 generic configuration Msp430Uart0C() {
 
   provides interface Resource;
+  provides interface ResourceRequested;
   provides interface UartStream;
   provides interface UartByte;
 
@@ -55,13 +57,13 @@ implementation {
 
   components Msp430Uart0P as UartP;
   Resource = UartP.Resource[ CLIENT_ID ];
-  UartStream = UartP.UartStream;
-  UartByte = UartP.UartByte;
+  UartStream = UartP.UartStream[ CLIENT_ID ];
+  UartByte = UartP.UartByte[ CLIENT_ID ];
   Msp430UartConfigure = UartP.Msp430UartConfigure[ CLIENT_ID ];
 
   components new Msp430Usart0C() as UsartC;
+  ResourceRequested = UsartC;
   UartP.ResourceConfigure[ CLIENT_ID ] <- UsartC.ResourceConfigure;
   UartP.UsartResource[ CLIENT_ID ] -> UsartC.Resource;
-  UartP.UsartInterrupts -> UsartC.HplMsp430UsartInterrupts;
-
+  UartP.UsartInterrupts[ CLIENT_ID ] -> UsartC.HplMsp430UsartInterrupts;
 }
index b61f800426253763e9dd09ede913193f241540a6..bce4f7fbfe531d254010de9cc9728694b39e015d 100644 (file)
 /**
  * @author Jonathan Hui <jhui@archedrock.com>
  * @author Vlado Handziski <handzisk@tkn.tu-berlin.de>
+ * @author Eric B. Decker <cire831@gmail.com>
  * @version $Revision$ $Date$
  */
 
 configuration Msp430Uart0P {
 
   provides interface Resource[ uint8_t id ];
-  provides interface ResourceConfigure[uint8_t id ];
-  provides interface UartStream;
-  provides interface UartByte;
+  provides interface ResourceConfigure[ uint8_t id ];
+  provides interface UartStream[ uint8_t id ];
+  provides interface UartByte[ uint8_t id ];
 
   uses interface Resource as UsartResource[ uint8_t id ];
   uses interface Msp430UartConfigure[ uint8_t id ];
-  uses interface HplMsp430UsartInterrupts as UsartInterrupts;
-
+  uses interface HplMsp430UsartInterrupts as UsartInterrupts[ uint8_t id ];
 }
 
 implementation {
-
   components new Msp430UartP() as UartP;
   Resource = UartP.Resource;
   ResourceConfigure = UartP.ResourceConfigure;
index 4829a4c58a0e6376a49a6278f14e1495397a5063..a824fd3570fe12e2bf122492e22c5c8645f07bd6 100644 (file)
@@ -33,6 +33,7 @@
  * An implementation of the UART on USART1 for the MSP430.
  * @author Vlado Handziski <handzisk@tkn.tu-berlin.de>
  * @author Jonathan Hui <jhui@archedrock.com>
+ * @author Eric B. Decker <cire81@gmail.com>
  * @version $Revision$ $Date$
  */
 
@@ -41,6 +42,7 @@
 generic configuration Msp430Uart1C() {
 
   provides interface Resource;
+  provides interface ResourceRequested;
   provides interface UartStream;
   provides interface UartByte;
 
@@ -55,13 +57,13 @@ implementation {
 
   components Msp430Uart1P as UartP;
   Resource = UartP.Resource[ CLIENT_ID ];
-  UartStream = UartP.UartStream;
-  UartByte = UartP.UartByte;
+  UartStream = UartP.UartStream[ CLIENT_ID ];
+  UartByte = UartP.UartByte[ CLIENT_ID ];;
   Msp430UartConfigure = UartP.Msp430UartConfigure[ CLIENT_ID ];
 
   components new Msp430Usart1C() as UsartC;
+  ResourceRequested = UsartC;
   UartP.ResourceConfigure[ CLIENT_ID ] <- UsartC.ResourceConfigure;
   UartP.UsartResource[ CLIENT_ID ] -> UsartC.Resource;
-  UartP.UsartInterrupts -> UsartC.HplMsp430UsartInterrupts;
-
+  UartP.UsartInterrupts[ CLIENT_ID ] -> UsartC.HplMsp430UsartInterrupts;
 }
index 834feea7a1b225483e4ff11aa667c0113f638e87..0f367db04f3afc3fb4cb0a42042ddb1f00f24e8f 100644 (file)
 /**
  * @author Jonathan Hui <jhui@archedrock.com>
  * @author Vlado Handziski <handzisk@tkn.tu-berlin.de>
+ * @author Eric B. Decker <cire831@gmail.com>
  * @version $Revision$ $Date$
  */
 
 configuration Msp430Uart1P {
 
   provides interface Resource[ uint8_t id ];
-  provides interface ResourceConfigure[uint8_t id ];
-  provides interface UartStream;
-  provides interface UartByte;
+  provides interface ResourceConfigure[ uint8_t id ];
+  provides interface UartStream[ uint8_t id ];
+  provides interface UartByte[ uint8_t id ];
   
   uses interface Resource as UsartResource[ uint8_t id ];
   uses interface Msp430UartConfigure[ uint8_t id ];
-  uses interface HplMsp430UsartInterrupts as UsartInterrupts;
+  uses interface HplMsp430UsartInterrupts as UsartInterrupts[ uint8_t id ];
 
 }
 
index 9393595c0a90c3533027187d1cd4a75b93a12d9b..ca408466913a96e4d9335bd4c487bed0e060a5e2 100644 (file)
@@ -32,6 +32,7 @@
 /**
  * @author Jonathan Hui <jhui@archrock.com>
  * @author Vlado Handziski <handzisk@tkn.tu-berlin.de>
+ * @author Eric B. Decker <cire831@gmail.com>
  * @version $Revision$ $Date$
  */
 
@@ -41,14 +42,13 @@ generic module Msp430UartP() {
 
   provides interface Resource[ uint8_t id ];
   provides interface ResourceConfigure[ uint8_t id ];
-  //provides interface Msp430UartControl as UartControl[ uint8_t id ];
-  provides interface UartStream;
-  provides interface UartByte;
+  provides interface UartStream[ uint8_t id ];
+  provides interface UartByte[ uint8_t id ];
   
   uses interface Resource as UsartResource[ uint8_t id ];
   uses interface Msp430UartConfigure[ uint8_t id ];
   uses interface HplMsp430Usart as Usart;
-  uses interface HplMsp430UsartInterrupts as UsartInterrupts;
+  uses interface HplMsp430UsartInterrupts as UsartInterrupts[ uint8_t id ];
   uses interface Counter<T32khz,uint16_t>;
   uses interface Leds;
 
@@ -60,6 +60,7 @@ implementation {
   norace uint16_t m_tx_len, m_rx_len;
   norace uint16_t m_tx_pos, m_rx_pos;
   norace uint8_t m_byte_time;
+  norace uint8_t current_owner;
   
   async command error_t Resource.immediateRequest[ uint8_t id ]() {
     return call UsartResource.immediateRequest[ id ]();
@@ -74,6 +75,8 @@ implementation {
   }
 
   async command error_t Resource.release[ uint8_t id ]() {
+    if (call UsartResource.isOwner[id]() == FALSE)
+      return FAIL;
     if ( m_rx_buf || m_tx_buf )
       return EBUSY;
     return call UsartResource.release[ id ]();
@@ -90,24 +93,32 @@ implementation {
     call Usart.resetUsart(TRUE);
     call Usart.disableIntr();
     call Usart.disableUart();
-    call Usart.resetUsart(FALSE);
+
+    /* leave the usart in reset */
+    //call Usart.resetUsart(FALSE); // this shouldn't be called.
   }
 
   event void UsartResource.granted[ uint8_t id ]() {
     signal Resource.granted[ id ]();
   }
   
-  async command error_t UartStream.enableReceiveInterrupt() {
+  async command error_t UartStream.enableReceiveInterrupt[ uint8_t id ]() {
+    if (call UsartResource.isOwner[id]() == FALSE)
+      return FAIL;
     call Usart.enableRxIntr();
     return SUCCESS;
   }
   
-  async command error_t UartStream.disableReceiveInterrupt() {
+  async command error_t UartStream.disableReceiveInterrupt[ uint8_t id ]() {
+    if (call UsartResource.isOwner[id]() == FALSE)
+      return FAIL;
     call Usart.disableRxIntr();
     return SUCCESS;
   }
 
-  async command error_t UartStream.receive( uint8_t* buf, uint16_t len ) {
+  async command error_t UartStream.receive[ uint8_t id ]( uint8_t* buf, uint16_t len ) {
+    if (call UsartResource.isOwner[id]() == FALSE)
+      return FAIL;
     if ( len == 0 )
       return FAIL;
     atomic {
@@ -120,21 +131,22 @@ implementation {
     return SUCCESS;
   }
   
-  async event void UsartInterrupts.rxDone( uint8_t data ) {
+  async event void UsartInterrupts.rxDone[uint8_t id]( uint8_t data ) {
     if ( m_rx_buf ) {
       m_rx_buf[ m_rx_pos++ ] = data;
       if ( m_rx_pos >= m_rx_len ) {
        uint8_t* buf = m_rx_buf;
        m_rx_buf = NULL;
-       signal UartStream.receiveDone( buf, m_rx_len, SUCCESS );
+       signal UartStream.receiveDone[id]( buf, m_rx_len, SUCCESS );
       }
-    }
-    else {
-      signal UartStream.receivedByte( data );
+    } else {
+      signal UartStream.receivedByte[id]( data );
     }
   }
   
-  async command error_t UartStream.send( uint8_t* buf, uint16_t len ) {
+  async command error_t UartStream.send[ uint8_t id ]( uint8_t* buf, uint16_t len ) {
+    if (call UsartResource.isOwner[id]() == FALSE)
+      return FAIL;
     if ( len == 0 )
       return FAIL;
     else if ( m_tx_buf )
@@ -142,36 +154,46 @@ implementation {
     m_tx_buf = buf;
     m_tx_len = len;
     m_tx_pos = 0;
+    current_owner = id;
     call Usart.tx( buf[ m_tx_pos++ ] );
     return SUCCESS;
   }
   
-  async event void UsartInterrupts.txDone() {
-    if ( m_tx_pos < m_tx_len ) {
+  async event void UsartInterrupts.txDone[uint8_t id]() {
+    if(current_owner != id) {
+      uint8_t* buf = m_tx_buf;
+      m_tx_buf = NULL;
+      signal UartStream.sendDone[id]( buf, m_tx_len, FAIL );
+    }
+    else if ( m_tx_pos < m_tx_len ) {
       call Usart.tx( m_tx_buf[ m_tx_pos++ ] );
     }
     else {
       uint8_t* buf = m_tx_buf;
       m_tx_buf = NULL;
-      signal UartStream.sendDone( buf, m_tx_len, SUCCESS );
+      signal UartStream.sendDone[id]( buf, m_tx_len, SUCCESS );
     }
   }
   
-    async command error_t UartByte.send( uint8_t data ) {
-      call Usart.clrTxIntr();
-      call Usart.disableTxIntr ();
-      call Usart.tx( data );
-      while( !call Usart.isTxIntrPending() );
-      call Usart.clrTxIntr();
-      call Usart.enableTxIntr();
+  async command error_t UartByte.send[ uint8_t id ]( uint8_t data ) {
+    if (call UsartResource.isOwner[id]() == FALSE)
+      return FAIL;
+    call Usart.clrTxIntr();
+    call Usart.disableTxIntr ();
+    call Usart.tx( data );
+    while( !call Usart.isTxIntrPending() );
+    call Usart.clrTxIntr();
+    call Usart.enableTxIntr();
     return SUCCESS;
   }
   
-  async command error_t UartByte.receive( uint8_t* byte, uint8_t timeout ) {
+  async command error_t UartByte.receive[ uint8_t id ]( uint8_t* byte, uint8_t timeout ) {
     
     uint16_t timeout_micro = m_byte_time * timeout + 1;
     uint16_t start;
     
+    if (call UsartResource.isOwner[id]() == FALSE)
+      return FAIL;
     start = call Counter.get();
     while( !call Usart.isRxIntrPending() ) {
       if ( ( call Counter.get() - start ) >= timeout_micro )
@@ -194,4 +216,8 @@ implementation {
   }
 
   default event void Resource.granted[ uint8_t id ]() {}
+
+  default async event void UartStream.sendDone[ uint8_t id ](uint8_t* buf, uint16_t len, error_t error) {}
+  default async event void UartStream.receivedByte[ uint8_t id ](uint8_t byte) {}
+  default async event void UartStream.receiveDone[ uint8_t id ]( uint8_t* buf, uint16_t len, error_t error ) {}
 }
index 0b8bdb91b115e737f1aa6f74ce01845d95fc75a3..49bd5bec3469ca2a5ba5f03dc742ae1ae119e830 100644 (file)
@@ -39,6 +39,7 @@
 generic configuration Msp430Usart0C() {
 
   provides interface Resource;
+  provides interface ResourceRequested;
   provides interface ArbiterInfo;
   provides interface HplMsp430Usart;
   provides interface HplMsp430UsartInterrupts;
@@ -60,6 +61,7 @@ implementation {
   components Msp430UsartShare0P as UsartShareP;
 
   Resource = UsartShareP.Resource[ CLIENT_ID ];
+  ResourceRequested = UsartShareP.ResourceRequested[ CLIENT_ID ];
   ResourceConfigure = UsartShareP.ResourceConfigure[ CLIENT_ID ];
   ArbiterInfo = UsartShareP.ArbiterInfo;
   HplMsp430UsartInterrupts = UsartShareP.Interrupts[ CLIENT_ID ];
index 29f5d0214b5076035e51f3a932e017fced7b4e8e..866e18e1b3827ae44bd56e778ed6a62b9e2ce97a 100644 (file)
@@ -40,6 +40,7 @@
 generic configuration Msp430Usart1C() {
 
   provides interface Resource;
+  provides interface ResourceRequested;
   provides interface ArbiterInfo;
   provides interface HplMsp430Usart;
   provides interface HplMsp430UsartInterrupts;
@@ -56,6 +57,7 @@ implementation {
   components Msp430UsartShare1P as UsartShareP;
 
   Resource = UsartShareP.Resource[ CLIENT_ID ];
+  ResourceRequested = UsartShareP.ResourceRequested[ CLIENT_ID ];
   ResourceConfigure = UsartShareP.ResourceConfigure[ CLIENT_ID ];
   ArbiterInfo = UsartShareP.ArbiterInfo;
   HplMsp430UsartInterrupts = UsartShareP.Interrupts[ CLIENT_ID ];
index af092585ca59e3c8229f770d5436a85bfa306ab1..d8643407466e6fc856d508098328ea2be8658071 100644 (file)
@@ -39,6 +39,7 @@ configuration Msp430UsartShare0P {
   provides interface HplMsp430UsartInterrupts as Interrupts[ uint8_t id ];
   provides interface HplMsp430I2CInterrupts as I2CInterrupts[ uint8_t id ];
   provides interface Resource[ uint8_t id ];
+  provides interface ResourceRequested[ uint8_t id ];
   provides interface ArbiterInfo;
 
   uses interface ResourceConfigure[ uint8_t id ];
@@ -52,6 +53,7 @@ implementation {
   
   components new FcfsArbiterC( MSP430_HPLUSART0_RESOURCE ) as ArbiterC;
   Resource = ArbiterC;
+  ResourceRequested = ArbiterC;
   ResourceConfigure = ArbiterC;
   ArbiterInfo = ArbiterC;
   UsartShareP.ArbiterInfo -> ArbiterC;
index 1b6edcf5b78d620c9db706c18c2bfc7200e03368..3b977b3449a2604fc7ea7d5ba67eca4aaa1a9351 100644 (file)
@@ -39,6 +39,7 @@ configuration Msp430UsartShare1P {
 
   provides interface HplMsp430UsartInterrupts as Interrupts[ uint8_t id ];
   provides interface Resource[ uint8_t id ];
+  provides interface ResourceRequested[ uint8_t id ];
   provides interface ArbiterInfo;
 
   uses interface ResourceConfigure[ uint8_t id ];
@@ -52,6 +53,7 @@ implementation {
 
   components new FcfsArbiterC( MSP430_HPLUSART1_RESOURCE ) as ArbiterC;
   Resource = ArbiterC;
+  ResourceRequested = ArbiterC;
   ResourceConfigure = ArbiterC;
   ArbiterInfo = ArbiterC;
   UsartShareP.ArbiterInfo -> ArbiterC;