From 706ae98642ef403b5cc9af03486def14cba25799 Mon Sep 17 00:00:00 2001 From: smckown Date: Tue, 9 Sep 2008 18:10:36 +0000 Subject: [PATCH] Fix up atomic warnings for robug in MSp430UartP.nc. --- tos/chips/msp430/usci/Msp430UartP.nc | 106 +++++++++++++++------------ 1 file changed, 58 insertions(+), 48 deletions(-) diff --git a/tos/chips/msp430/usci/Msp430UartP.nc b/tos/chips/msp430/usci/Msp430UartP.nc index 7b39bbcd..35582046 100644 --- a/tos/chips/msp430/usci/Msp430UartP.nc +++ b/tos/chips/msp430/usci/Msp430UartP.nc @@ -210,74 +210,84 @@ implementation { 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() -- 2.39.2