interface HplMsp430UsciInt as Interrupts;
interface HplMsp430GeneralIO as RXD;
interface HplMsp430GeneralIO as TXD;
- interface Msp430UsciUartConfigure; /* maybe just Msp430UsciConfigure */
- interface Counter<T32khz,uint16_6>
+ interface Msp430UsciConfigure;
+ interface Counter<T32khz,uint16_t>;
interface ArbiterInfo;
}
}
uint8_t* rbuf; /* Position of next byte in which to receive a char */
uint8_t rlen; /* Remaining length in receive buffer */
- async command void ResourceConfigure.configure();
+ async command void ResourceConfigure.configure()
{
+ 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);
- /* FIXME: use Msp430UsciConfig to configure ports */
+
+ /* 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 pins for module function */
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);
}
- async command void ResourceConfigure.unconfigure();
+ async command void ResourceConfigure.unconfigure()
{
/* Disable the device */
call Registers.setCtl0(UCSYNC);
+
/* Clear interrupts and interrupt flags */
call Registers.clrIeRx();
call Registers.clrIeTx();
call Registers.clrIfgRx();
call Registers.clrIfgTx();
- /* Restore pins to state just before configure() */
+
+ /* Restore pins to their preconfigured state */
restoreBits(RXD, 0, dir, out, ren);
restoreBits(TXD, 0, dir, out, ren);
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;
+ }
- async command error_t UartStream.send( uint8_t* buf, uint16_t len )
+ async command error_t UartStream.send(uint8_t* buf, uint16_t len)
{
if (sobuf || !buf || !len)
return FAIL;
}
}
- async command error_t enableReceiveInterrupt()
+ async command error_t UartStream.enableReceiveInterrupt()
{
if (!robuf)
call Registers.clrIfgRx();
return SUCCESS;
}
- async command error_t disableReceiveInterrupt()
+ async command error_t UartStream.disableReceiveInterrupt()
{
if (!robuf) {
call Registers.clrIeRx();
return SUCCESS;
}
- async command error_t receive(uint8_t* buf, uint16_t len)
+ async command error_t UartByte.receive(uint8_t* byte, uint8_t timeout)
+ {
+ 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;
+ }
+ }
+ 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) {
+ if (!call Registers.getIeRx()) {
call Registers.clrIfgRx();
call Registers.setIeRx();
rxie = TRUE;
} else
signal UartStream.receivedByte(byte);
}
+
+ default async command msp430_usci_config_t* Msp430UsciConfigure.get()
+ {
+ 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,
+ irtctl: 0,
+ irrctl: 0,
+ abctl: 0
+ /* FIXME: pullup/pulldown configuration... */
+ }
+ };
+
+ return &def;
+ }
+
+ async event void Interrupts.i2cStart() {}
+ async event void Interrupts.i2cStop() {}
+ async event void Interrupts.i2cCal() {}
+ async event void Interrupts.brk() {}
+ async event void Interrupts.i2cNak() {}
+ async event void Counter.overflow() {}
}