- call Registers.setCtl0(UCSYNC);
- /* Save pin states */
- dir = out = ren = 0;
- saveBits(RXD, 0, dir, out, ren);
- saveBits(TXD, 1, dir, out, ren);
- /* FIXME: use Msp430UsciConfig to configure ports */
- /* FIXME: we may need to have REN/DIR stuff in the configuration... */
- call RXD.selectModuleFunc();
- call TXD.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_uart_t* config = call Configure.get();
+
+ call Registers.setCtl1(UCSWRST);
+
+ /* Configure USCI registers */
+ 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);
+ if (config->uclisten)
+ call Registers.setStat(UCLISTEN);
+ else
+ call Registers.clrStat(UCLISTEN);
+
+ /* Configure pins for UART, saving prior pin states */
+ m_pins = 0;
+ if (call RXD.isIOFunc()) {
+ m_pins |= (1 << PINS_RXD);
+ call RXD.selectModuleFunc();
+ }
+ if (call TXD.isIOFunc()) {
+ m_pins |= (1 << PINS_TXD);
+ call TXD.selectModuleFunc();
+ }
+
+ /* Clear interrupts; we'll add them as needed */
+ call Registers.clrIeRx();
+ call Registers.clrIeTx();
+
+ /* Enable the device */
+ call Registers.clrCtl1(UCSWRST);
+ }