generic configuration Msp430I2CC() {
provides interface Resource;
+ provides interface ResourceRequested;
provides interface I2CPacket<TI2CBasicAddr> as I2CBasicAddr;
uses interface Msp430I2CConfigure;
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;
generic configuration Msp430Spi0C() {
provides interface Resource;
+ provides interface ResourceRequested;
provides interface SpiByte;
provides interface SpiPacket;
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;
generic configuration Msp430Spi1C() {
provides interface Resource;
+ provides interface ResourceRequested;
provides interface SpiByte;
provides interface SpiPacket;
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;
* 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$
*/
generic configuration Msp430Uart0C() {
provides interface Resource;
+ provides interface ResourceRequested;
provides interface UartStream;
provides interface UartByte;
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;
}
/**
* @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;
* 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$
*/
generic configuration Msp430Uart1C() {
provides interface Resource;
+ provides interface ResourceRequested;
provides interface UartStream;
provides interface UartByte;
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;
}
/**
* @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 ];
}
/**
* @author Jonathan Hui <jhui@archrock.com>
* @author Vlado Handziski <handzisk@tkn.tu-berlin.de>
+ * @author Eric B. Decker <cire831@gmail.com>
* @version $Revision$ $Date$
*/
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;
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 ]();
}
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 ]();
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 {
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 )
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 )
}
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 ) {}
}
generic configuration Msp430Usart0C() {
provides interface Resource;
+ provides interface ResourceRequested;
provides interface ArbiterInfo;
provides interface HplMsp430Usart;
provides interface HplMsp430UsartInterrupts;
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 ];
generic configuration Msp430Usart1C() {
provides interface Resource;
+ provides interface ResourceRequested;
provides interface ArbiterInfo;
provides interface HplMsp430Usart;
provides interface HplMsp430UsartInterrupts;
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 ];
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 ];
components new FcfsArbiterC( MSP430_HPLUSART0_RESOURCE ) as ArbiterC;
Resource = ArbiterC;
+ ResourceRequested = ArbiterC;
ResourceConfigure = ArbiterC;
ArbiterInfo = ArbiterC;
UsartShareP.ArbiterInfo -> ArbiterC;
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 ];
components new FcfsArbiterC( MSP430_HPLUSART1_RESOURCE ) as ArbiterC;
Resource = ArbiterC;
+ ResourceRequested = ArbiterC;
ResourceConfigure = ArbiterC;
ArbiterInfo = ArbiterC;
UsartShareP.ArbiterInfo -> ArbiterC;