- call Registers.setCtl0(UCSYNC);
- /* Save pin states */
- dir = out = ren = 0;
- saveBits(STE, 0, dir, out, ren);
- saveBits(SIMO, 1, dir, out, ren);
- saveBits(SOMI, 2, dir, out, ren);
- saveBits(SCL, 3, dir, out, ren);
- /* FIXME: use Msp430UsciConfig to configure ports */
- /* FIXME: we may need to have REN/DIR stuff in the configuration... */
- if (call Registers.getCtl1(UCMODE_3) != UCMODE_0) {
- call STE.selectModuleFunc();
- call SIMO.selectModuleFunc();
- call SOMI.selectModuleFunc();
- call SCL.selectModuleFunc();
- /* Clear interrupts; we'll add them as needed */
- call Registers.clrCtl1(UCRXEIE|UCBRKIE);
- call Registers.clrIeRx();
- call Registers.clrIeTx();
- /* Enable the device */
- call Registers.clrCtl0(UCSYNC);
+ atomic {
+ const msp430_usci_config_t* config = call Msp430UsciConfigure.get();
+
+ call Registers.setCtl1(UCSWRST);
+
+ /* Configure USCI registers */
+ call Registers.assignCtl0(config->spi.ctl0);
+ call Registers.assignCtl1(config->spi.ctl1|UCSWRST);
+ call Registers.assignBr0(config->spi.brx & 0xff);
+ call Registers.assignBr1(config->spi.brx >> 8);
+ call Registers.assignMctl(config->spi.mctl);
+ call Registers.assignIrtctl(config->spi.irtctl);
+ call Registers.assignIrrctl(config->spi.irrctl);
+ call Registers.assignAbctl(config->spi.abctl);
+ call Registers.clrStat(UCLISTEN);
+
+ /* Save pin IO states */
+ dir = out = ren = 0;
+ saveBits(RXD, 0, dir, out, ren);
+ saveBits(TXD, 1, dir, out, ren);
+
+ /* Configure RX pin for UART use */
+ call RXD.makeInput();
+ if (config->spi.ren & USCI_REN_RX) {
+ if (config->spi.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.
+ */
+
+ /* Configure TX pin for UART use */
+ if (config->spi.ren & USCI_REN_TX) {
+ if (config->spi.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);
+ }