]> oss.titaniummirror.com Git - tinyos-2.x.git/blobdiff - tos/chips/msp430/usci/Msp430UartP.nc
Fix up atomic warnings for robug in MSp430UartP.nc.
[tinyos-2.x.git] / tos / chips / msp430 / usci / Msp430UartP.nc
index ce31d9ce9e4c83b1aedf7c6471851e83a7232a65..355820460eb6af580b6b211cb13c160596f1cbcd 100644 (file)
@@ -210,83 +210,93 @@ 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()
   {
     const static msp430_usci_uart_t def = { 
       ctl0: UCMODE_0,          /* async, lsb first, 8N1 */
-      ctl1: UCSWRST|UCSSEL_1,  /* clock uart from SMCLK */
-      brx: UBRX_32768HZ_9600,
-      mctl: UMCTL_32768HZ_9600,
+      ctl1: UCSWRST|UCSSEL_3,  /* clock uart from SMCLK */
+      brx: UBRX_1MHZ_115200,
+      mctl: UMCTL_1MHZ_115200,
       irtctl: 0,
       irrctl: 0,
       abctl: 0,