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 const msp430_usci_uart_t* Configure.get()