interface HplMsp430UsciInt as Interrupts;
interface HplMsp430GeneralIO as RXD;
interface HplMsp430GeneralIO as TXD;
- interface Msp430UsciConfigure;
+ interface AsyncConfigure<const msp430_usci_uart_t*> as Configure;
interface Counter<T32khz,uint16_t>;
interface ArbiterInfo;
}
async command void ResourceConfigure.configure()
{
atomic {
- msp430_usci_config_t* config = call Msp430UsciConfigure.get();
+ const msp430_usci_uart_t* config = call Configure.get();
call Registers.setCtl1(UCSWRST);
/* Configure USCI registers */
- call Registers.assignCtl0(config->uart.ctl0);
- call Registers.assignCtl1(config->uart.ctl1|UCSWRST);
- call Registers.assignBr0(config->uart.brx & 0xff);
- call Registers.assignBr1(config->uart.brx >> 8);
- call Registers.assignMctl(config->uart.mctl);
- call Registers.assignIrtctl(config->uart.irtctl);
- call Registers.assignIrrctl(config->uart.irrctl);
- call Registers.assignAbctl(config->uart.abctl);
+ call Registers.assignCtl0(config->ctl0 & ~UCSYNC);
+ call Registers.assignCtl1(config->ctl1 | UCSWRST);
+ call Registers.assignBr0(config->brx & 0xff);
+ call Registers.assignBr1(config->brx >> 8);
+ call Registers.assignMctl(config->mctl);
+ call Registers.assignIrtctl(config->irtctl);
+ call Registers.assignIrrctl(config->irrctl);
+ call Registers.assignAbctl(config->abctl);
call Registers.clrStat(UCLISTEN);
/* Save pin IO states */
/* Configure RX pin for UART use */
call RXD.makeInput();
- if (config->uart.ren & USCI_REN_RX) {
- if (config->uart.ren & USCI_REN_RX_PULLUP)
+ if (config->ren & USCI_REN_RX) {
+ if (config->ren & USCI_REN_RX_PULLUP)
call RXD.set();
else
call RXD.clr();
*/
/* Configure TX pin for UART use */
- if (config->uart.ren & USCI_REN_TX) {
- if (config->uart.ren & USCI_REN_TX_PULLUP)
+ if (config->ren & USCI_REN_TX) {
+ if (config->ren & USCI_REN_TX_PULLUP)
call TXD.set();
else
call TXD.clr();
async command error_t UartStream.enableReceiveInterrupt()
{
- if (!robuf)
- call Registers.clrIfgRx();
- call Registers.setIeRx();
- rxie = FALSE;
- return SUCCESS;
+ atomic {
+ if (!robuf)
+ call Registers.clrIfgRx();
+ call Registers.setIeRx();
+ rxie = FALSE;
+ return SUCCESS;
+ }
}
async command error_t UartStream.disableReceiveInterrupt()
{
- if (!robuf) {
- call Registers.clrIeRx();
- call Registers.clrIfgRx();
- } else
- rxie = TRUE;
- return SUCCESS;
+ atomic {
+ if (!robuf) {
+ call Registers.clrIeRx();
+ call Registers.clrIfgRx();
+ } else
+ rxie = TRUE;
+ return SUCCESS;
+ }
}
async command error_t UartByte.receive(uint8_t* byte, uint8_t timeout)
{
- uint16_t t;
+ atomic {
+ uint16_t t;
- /* FIXME: race with UartStream.receive() */
- if (robuf || !byte)
- return FAIL;
- /* TODO: implement timeout, byte-time units. For now, 1-2 sec */
- t = TBR;
- while (t < TBR) {
- if (call Registers.getIfgRx()) {
- *byte = call Registers.getRxbuf();
- return SUCCESS;
+ /* FIXME: race with UartStream.receive() */
+ if (robuf || !byte)
+ return FAIL;
+ /* TODO: implement timeout, byte-time units. For now, 1-2 sec */
+ t = TBR;
+ while (t < TBR) {
+ if (call Registers.getIfgRx()) {
+ *byte = call Registers.getRxbuf();
+ return SUCCESS;
+ }
}
+ return FAIL;
}
- return FAIL;
}
async command error_t UartStream.receive(uint8_t* buf, uint16_t len)
{
- if (robuf || !buf || !len)
- return FAIL;
- robuf = rbuf = buf;
- rolen = rlen = len;
- if (!call Registers.getIeRx()) {
- call Registers.clrIfgRx();
- call Registers.setIeRx();
- rxie = TRUE;
- } else
- rxie = FALSE;
+ atomic {
+ if (robuf || !buf || !len)
+ return FAIL;
+ robuf = rbuf = buf;
+ rolen = rlen = len;
+ if (!call Registers.getIeRx()) {
+ call Registers.clrIfgRx();
+ call Registers.setIeRx();
+ rxie = TRUE;
+ } else
+ rxie = FALSE;
+ }
}
async event void Interrupts.rx(uint8_t byte)
{
- if (robuf) {
- /* receive() takes precedence if active */
- while (rlen && call Registers.getIfgRx()) {
- *rbuf = byte;
- if (--rlen)
- rbuf++;
- }
- if (rlen == 0 && robuf) {
- if (rxie) {
- call Registers.clrIeRx();
- call Registers.clrIfgRx();
+ atomic {
+ if (robuf) {
+ /* receive() takes precedence if active */
+ while (rlen && call Registers.getIfgRx()) {
+ *rbuf = byte;
+ if (--rlen)
+ rbuf++;
}
- robuf = 0;
- signal UartStream.receiveDone(robuf, rolen, SUCCESS);
- }
- } else
- signal UartStream.receivedByte(byte);
+ if (rlen == 0 && robuf) {
+ if (rxie) {
+ call Registers.clrIeRx();
+ call Registers.clrIfgRx();
+ }
+ robuf = 0;
+ signal UartStream.receiveDone(robuf, rolen, SUCCESS);
+ }
+ } else
+ signal UartStream.receivedByte(byte);
+ }
}
- default async command msp430_usci_config_t* Msp430UsciConfigure.get()
+ default async command const msp430_usci_uart_t* Configure.get()
{
- static msp430_usci_config_t def = {
- uart: {
- ctl0: UCMODE_0, /* async, lsb first, 8N1 */
- ctl1: UCSWRST|UCSSEL_1, /* clock uart from SMCLK */
- brx: UBRX_32768HZ_9600,
- mctl: UMCTL_32768HZ_9600,
- irtctl: 0,
- irrctl: 0,
- abctl: 0,
- ren: USCI_REN_NONE
- }
+ const static msp430_usci_uart_t def = {
+ ctl0: UCMODE_0, /* async, lsb first, 8N1 */
+ ctl1: UCSWRST|UCSSEL_3, /* clock uart from SMCLK */
+ brx: UBRX_1MHZ_115200,
+ mctl: UMCTL_1MHZ_115200,
+ irtctl: 0,
+ irrctl: 0,
+ abctl: 0,
+ ren: USCI_REN_NONE
};
return &def;