62 lines
1.3 KiB
Plaintext
62 lines
1.3 KiB
Plaintext
#include <stdint.h>
|
|
#include <stdio.h>
|
|
#include <msp430g2553.h>
|
|
|
|
#include "uart.h"
|
|
#include "PontCoopScheduler.h"
|
|
|
|
uint8_t txBuffer[UART_TX_BUFFER_SIZE+5];
|
|
uint8_t txBufferReadIdx = 0;
|
|
uint8_t txBufferWriteIdx = 0;
|
|
|
|
|
|
void uartInit(void *handleArg) {
|
|
UCA0CTL1 |= UCSWRST;
|
|
|
|
P1SEL |= BIT1 | BIT2;
|
|
P1SEL2 |= BIT1 | BIT2;
|
|
UCA0CTL1 |= UCSSEL0; // ACLK
|
|
UCA0BR0 = 13;
|
|
UCA0BR1 = 0;
|
|
UCA0MCTL = UCBSR1 | UCBSR2;
|
|
|
|
UCA0CTL1 &= ~UCSWRST;
|
|
}
|
|
|
|
void uartExec(void *handleArg) {
|
|
if (txBufferReadIdx != txBufferWriteIdx) {
|
|
if ((IFG2 & UCA0TXIE) != 0) {
|
|
UCA0TXBUF = txBuffer[txBufferReadIdx];
|
|
txBufferReadIdx++;
|
|
if (txBufferReadIdx > UART_TX_BUFFER_SIZE) {
|
|
txBufferReadIdx = 0;
|
|
}
|
|
}
|
|
} else {
|
|
// stop transmitting
|
|
schDel(uartExec, NULL);
|
|
}
|
|
}
|
|
|
|
int putchar(int character) {
|
|
if (((txBufferWriteIdx == (UART_TX_BUFFER_SIZE - 1)) && (txBufferReadIdx == UART_TX_BUFFER_SIZE)) ||
|
|
((txBufferWriteIdx != (UART_TX_BUFFER_SIZE - 1)) && (txBufferReadIdx == (txBufferWriteIdx + 1)))) {
|
|
return EOF;
|
|
}
|
|
txBuffer[txBufferWriteIdx] = (unsigned char)character;
|
|
txBufferWriteIdx++;
|
|
|
|
if (txBufferWriteIdx > UART_TX_BUFFER_SIZE) {
|
|
txBufferWriteIdx = 0;
|
|
}
|
|
|
|
// start transmitting
|
|
schAdd(uartExec, NULL, 0, 5);
|
|
|
|
return character;
|
|
}
|
|
|
|
|
|
|
|
|