From b4c4cd44a334949519c179e8e52ad91c6d12f67c Mon Sep 17 00:00:00 2001 From: hg Date: Thu, 5 Jun 2014 20:45:12 +0200 Subject: [PATCH] works --- src/main.cpp | 2 +- src/uart.cpp | 35 ++++++++++++++++++++++++----------- 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 4608656..e64b37b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -46,7 +46,7 @@ int main() { uartWrite('W'); while (1) { - __bis_status_register(LPM0_bits); +// __bis_status_register(LPM0_bits); } } diff --git a/src/uart.cpp b/src/uart.cpp index ca8ac34..af22e11 100644 --- a/src/uart.cpp +++ b/src/uart.cpp @@ -27,6 +27,9 @@ static inline void disableDataRegisterEmptyInterrupt() { void uartInit() { UCA0CTL1 |= UCSWRST; + P1SEL = BIT1 + BIT2; + P1SEL2 = BIT1 + BIT2; + UCA0CTL1 |= UCSSEL0; // ACLK UCA0BR0 = 13; @@ -43,7 +46,24 @@ void uartInit() { // stdout = mystdout; } +inline void _realUartTx() { + if ((IFG2 | UCA0TXIE) != 0) { + if (txBufferReadIdx != txBufferWriteIdx) { + UCA0TXBUF = txBuffer[txBufferReadIdx]; + txBufferReadIdx++; + if (txBufferReadIdx > UART_TX_BUFFER_SIZE) { + txBufferReadIdx = 0; + } + } else { + disableDataRegisterEmptyInterrupt(); + } + } +} + void uartWrite(uint8_t o) { +#if 0 + UCA0TXBUF = o; +#else if (txBufferWriteIdx == (UART_TX_BUFFER_SIZE - 1)) { while (txBufferReadIdx == UART_TX_BUFFER_SIZE); } else { @@ -58,6 +78,8 @@ void uartWrite(uint8_t o) { } enableDataRegisterEmptyInterrupt(); + _realUartTx(); +#endif } @@ -69,18 +91,9 @@ void uartWrite(uint8_t o) { //} + ISR(USCIAB0TX, UART_TX_ISR) { - if ((IFG2 | UCA0TXIE) != 0) { - if (txBufferReadIdx != txBufferWriteIdx) { - UCA0TXBUF = txBuffer[txBufferReadIdx]; - txBufferReadIdx++; - if (txBufferReadIdx > UART_TX_BUFFER_SIZE) { - txBufferReadIdx = 0; - } - } else { - disableDataRegisterEmptyInterrupt(); - } - } + _realUartTx(); } ISR(USCIAB0RX, UART_RX_ISR) {