]> 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 ad919b82249137f6cc158bc84a8c63cb61c94f7d..355820460eb6af580b6b211cb13c160596f1cbcd 100644 (file)
@@ -44,7 +44,7 @@ generic module Msp430UartP() {
     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;
   }
@@ -90,19 +90,19 @@ implementation {
   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 */
@@ -112,8 +112,8 @@ implementation {
 
       /* 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();
@@ -126,8 +126,8 @@ implementation {
        */
 
       /* 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();
@@ -210,89 +210,97 @@ 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 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;