]> oss.titaniummirror.com Git - tinyos-2.x.git/blobdiff - tos/chips/msp430/usci/Msp430UartP.nc
USCI UART output on USCI_A1 is working, using ACLK as BRCLK. Baud rate
[tinyos-2.x.git] / tos / chips / msp430 / usci / Msp430UartP.nc
index 550b1623f0fe19e12da7431ef47c66e2d66dc2d6..ad919b82249137f6cc158bc84a8c63cb61c94f7d 100644 (file)
@@ -89,63 +89,94 @@ implementation {
 
   async command void ResourceConfigure.configure()
   {
-    msp430_usci_config_t* config = call Msp430UsciConfigure.get();
+    atomic {
+      msp430_usci_config_t* config = call Msp430UsciConfigure.get();
 
-    call Registers.setCtl0(UCSYNC);
-    /* Save pin states */
-    dir = out = ren = 0;
-    saveBits(RXD, 0, dir, out, ren);
-    saveBits(TXD, 1, dir, out, ren);
+      call Registers.setCtl1(UCSWRST);
 
-    /* Configure USCI registers */
-    call Registers.assignCtl0(0xff, config->uart.ctl0);
-    call Registers.assignCtl1(0xff, config->uart.ctl1|UCSWRST);
-    call Registers.assignBr0(0xff, config->uart.brx & 0xff);
-    call Registers.assignBr1(0xff, config->uart.brx >> 8);
-    call Registers.assignMctl(0xff, config->uart.mctl);
-    call Registers.assignIrtctl(0xff, config->uart.irtctl);
-    call Registers.assignIrrctl(0xff, config->uart.irrctl);
-    call Registers.assignAbctl(0xff, config->uart.abctl);
-    /* FIXME: we may need to have REN/DIR stuff in the configuration... */
+      /* 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.clrStat(UCLISTEN);
 
-    /* Configure pins for module function */
-    call RXD.selectModuleFunc();
-    call TXD.selectModuleFunc();
+      /* Save pin IO states */
+      dir = out = ren = 0;
+      saveBits(RXD, 0, dir, out, ren);
+      saveBits(TXD, 1, dir, out, ren);
 
-    /* Clear interrupts; we'll add them as needed */
-    call Registers.clrCtl1(UCRXEIE|UCBRKIE);
-    call Registers.clrIeRx();
-    call Registers.clrIeTx();
+      /* Configure RX pin for UART use */
+      call RXD.makeInput();
+      if (config->uart.ren & USCI_REN_RX) {
+       if (config->uart.ren & USCI_REN_RX_PULLUP)
+         call RXD.set();
+       else
+         call RXD.clr();
+       call RXD.enableRen();
+      }
+      call RXD.selectModuleFunc();
+
+#if 0 /* pull-ups don't make sense on TXD, since it doesn't appear that
+       * enabling an open-drain emulation mode via USCI is possible.
+       */
 
-    /* Enable the device */
-    call Registers.clrCtl0(UCSYNC);
+      /* Configure TX pin for UART use */
+      if (config->uart.ren & USCI_REN_TX) {
+       if (config->uart.ren & USCI_REN_TX_PULLUP)
+         call TXD.set();
+       else
+         call TXD.clr();
+       call TXD.enableRen();
+      }
+      call TXD.selectModuleFunc();
+#endif
+
+      /* Clear interrupts; we'll add them as needed */
+      call Registers.clrIeRx();
+      call Registers.clrIeTx();
+
+      /* Enable the device */
+      call Registers.clrCtl1(UCSWRST);
+    }
   }
 
   async command void ResourceConfigure.unconfigure()
   {
-    /* Disable the device */
-    call Registers.setCtl0(UCSYNC);
+    atomic {
+      /* Disable the device */
+      call Registers.setCtl1(UCSYNC);
 
-    /* Clear interrupts and interrupt flags */
-    call Registers.clrIeRx();
-    call Registers.clrIeTx();
-    call Registers.clrIfgRx();
-    call Registers.clrIfgTx();
+      /* Clear interrupts and interrupt flags */
+      call Registers.clrIeRx();
+      call Registers.clrIeTx();
+      call Registers.clrIfgRx();
+      call Registers.clrIfgTx();
 
-    /* Restore pins to their preconfigured state */
-    restoreBits(RXD, 0, dir, out, ren);
-    restoreBits(TXD, 0, dir, out, ren);
-    call RXD.selectIOFunc();
-    call TXD.selectIOFunc();
+      /* Restore pins to their preconfigured state */
+#if 0
+      restoreBits(RXD, 0, dir, out, ren);
+      restoreBits(TXD, 0, dir, out, ren);
+#endif
+      call RXD.selectIOFunc();
+      call TXD.selectIOFunc();
+    }
   }
 
   async command error_t UartByte.send(uint8_t byte)
   {
     /* FIXME: race with UartStream.send() */
-    if (sobuf)
-      return FAIL;
-    call Registers.setTxbuf(byte);
-    return SUCCESS;
+    atomic {
+      if (sobuf)
+       return FAIL;
+      while (call Registers.getStat(UCBUSY));
+      call Registers.setTxbuf(byte);
+      return SUCCESS;
+    }
   }
 
   async command error_t UartStream.send(uint8_t* buf, uint16_t len)
@@ -254,13 +285,13 @@ implementation {
     static msp430_usci_config_t def = { 
       uart: {
        ctl0: UCMODE_0,         /* async, lsb first, 8N1 */
-       ctl1: UCSWRST|UCSSEL_3, /* clock uart from SMCLK */
-       brx: UBRX_1MHZ_9600,
-       mctl: UMCTL_1MHZ_9600,
+       ctl1: UCSWRST|UCSSEL_1, /* clock uart from SMCLK */
+       brx: UBRX_32768HZ_9600,
+       mctl: UMCTL_32768HZ_9600,
        irtctl: 0,
        irrctl: 0,
-       abctl: 0
-       /* FIXME: pullup/pulldown configuration... */
+       abctl: 0,
+       ren: USCI_REN_NONE
       }
     };
 
@@ -273,4 +304,10 @@ implementation {
   async event void Interrupts.brk() {}
   async event void Interrupts.i2cNak() {}
   async event void Counter.overflow() {}
+
+  default async event void UartStream.sendDone( uint8_t* buf, uint16_t len,
+      error_t error ) {}
+  default async event void UartStream.receivedByte( uint8_t byte ) {}
+  default async event void UartStream.receiveDone( uint8_t* buf, uint16_t len,
+      error_t error ) {}
 }