X-Git-Url: https://oss.titaniummirror.com/gitweb/?a=blobdiff_plain;f=tos%2Fchips%2Fmsp430%2Fusart%2FHplMsp430Usart0P.nc;h=cf618bfbbdba8cc75855497c1102b256380c6293;hb=337d0b13acf569c2640b3ed7b7f5c7cec35d7ddd;hp=5fdeb41b010b797f0bdabb4780086ea4e19a8f82;hpb=1a329382c4f4556fd52d85f4e3f4a67e54911682;p=tinyos-2.x.git diff --git a/tos/chips/msp430/usart/HplMsp430Usart0P.nc b/tos/chips/msp430/usart/HplMsp430Usart0P.nc index 5fdeb41b..cf618bfb 100644 --- a/tos/chips/msp430/usart/HplMsp430Usart0P.nc +++ b/tos/chips/msp430/usart/HplMsp430Usart0P.nc @@ -67,6 +67,7 @@ * @author: Jonathan Hui * @author: Vlado Handziski * @author: Joe Polastre + * @author: Philipp Huppertz * @version $Revision$ $Date$ */ @@ -206,7 +207,6 @@ implementation async command void Usart.disableUart() { atomic { ME1 &= ~(UTXE0 | URXE0); // USART0 UART module enable - call Usart.resetUsart(TRUE); call UTXD.selectIOFunc(); call URXD.selectIOFunc(); } @@ -247,113 +247,64 @@ implementation async command void Usart.disableSpi() { atomic { ME1 &= ~USPIE0; // USART0 SPI module disable - call Usart.resetUsart(TRUE); call SIMO.selectIOFunc(); call SOMI.selectIOFunc(); call UCLK.selectIOFunc(); } } + + void configSpi(msp430_spi_union_config_t* config) { + // U0CTL = (config->spiRegisters.uctl & ~I2C) | SYNC | SWRST; + U0CTL = (config->spiRegisters.uctl) | SYNC | SWRST; + U0TCTL = config->spiRegisters.utctl; - void configSpi(msp430_spi_config_t* config) { - msp430_uctl_t uctl = call Usart.getUctl(); - msp430_utctl_t utctl = call Usart.getUtctl(); - - uctl.clen = config->clen; - uctl.listen = config->listen; - uctl.mm = config->mm; - uctl.sync = 1; - - utctl.ckph = config->ckph; - utctl.ckpl = config->ckpl; - utctl.ssel = config->ssel; - utctl.stc = config->stc; - - call Usart.setUctl(uctl); - call Usart.setUtctl(utctl); - call Usart.setUbr(config->ubr); + call Usart.setUbr(config->spiRegisters.ubr); call Usart.setUmctl(0x00); } - - async command void Usart.setModeSpi(msp430_spi_config_t* config) { + async command void Usart.setModeSpi(msp430_spi_union_config_t* config) { + atomic { + call Usart.resetUsart(TRUE); + call HplI2C.clearModeI2C(); + call Usart.disableUart(); configSpi(config); call Usart.enableSpi(); call Usart.resetUsart(FALSE); call Usart.clrIntr(); call Usart.disableIntr(); - } - return; - } - - - void configUart(msp430_uart_config_t* config) { - msp430_uctl_t uctl = call Usart.getUctl(); - msp430_utctl_t utctl = call Usart.getUtctl(); - msp430_urctl_t urctl = call Usart.getUrctl(); - - uctl.pena = config->pena; - uctl.pev = config->pev; - uctl.spb = config->spb; - uctl.clen = config->clen; - uctl.listen = config->listen; - uctl.sync = 0; - uctl.mm = config->mm; - - utctl.ckpl = config->ckpl; - utctl.ssel = config->ssel; - utctl.urxse = config->urxse; - - urctl.urxeie = config->urxeie; - urctl.urxwie = config->urxwie; - - call Usart.setUctl(uctl); - call Usart.setUtctl(utctl); - call Usart.setUrctl(urctl); - call Usart.setUbr(config->ubr); - call Usart.setUmctl(config->umctl); - } - - async command void Usart.setModeUartTx(msp430_uart_config_t* config) { - - atomic { - call UTXD.selectModuleFunc(); - call URXD.selectIOFunc(); - call Usart.resetUsart(TRUE); - configUart(config); - call Usart.enableUartTx(); - call Usart.resetUsart(FALSE); - call Usart.clrIntr(); - call Usart.disableIntr(); - } - + } return; } - async command void Usart.setModeUartRx(msp430_uart_config_t* config) { + void configUart(msp430_uart_union_config_t* config) { - atomic { - call UTXD.selectIOFunc(); - call URXD.selectModuleFunc(); - call Usart.resetUsart(TRUE); - configUart(config); - call Usart.enableUartRx(); - call Usart.resetUsart(FALSE); - call Usart.clrIntr(); - call Usart.disableIntr(); - } + U0CTL = (config->uartRegisters.uctl & ~SYNC) | SWRST; + U0TCTL = config->uartRegisters.utctl; + U0RCTL = config->uartRegisters.urctl; - return; + call Usart.setUbr(config->uartRegisters.ubr); + call Usart.setUmctl(config->uartRegisters.umctl); } - async command void Usart.setModeUart(msp430_uart_config_t* config) { + async command void Usart.setModeUart(msp430_uart_union_config_t* config) { - atomic { - call UTXD.selectModuleFunc(); - call URXD.selectModuleFunc(); + atomic { call Usart.resetUsart(TRUE); + call HplI2C.clearModeI2C(); + call Usart.disableSpi(); configUart(config); - call Usart.enableUart(); + if ((config->uartConfig.utxe == 1) && (config->uartConfig.urxe == 1)) { + call Usart.enableUart(); + } else if ((config->uartConfig.utxe == 0) && (config->uartConfig.urxe == 1)) { + call Usart.disableUartTx(); + call Usart.enableUartRx(); + } else if ((config->uartConfig.utxe == 1) && (config->uartConfig.urxe == 0)){ + call Usart.disableUartRx(); + call Usart.enableUartTx(); + } else { + call Usart.disableUart(); + } call Usart.resetUsart(FALSE); call Usart.clrIntr(); call Usart.disableIntr(); @@ -364,7 +315,6 @@ implementation async command bool Usart.isTxIntrPending(){ if (IFG1 & UTXIFG0){ - IFG1 &= ~UTXIFG0; return TRUE; } return FALSE; @@ -441,5 +391,6 @@ implementation default async event void I2CInterrupts.fired() {} default async command bool HplI2C.isI2C() { return FALSE; } + default async command void HplI2C.clearModeI2C() {}; }