uart disabled so far
This commit is contained in:
61
disabled/uart.c-disabled
Normal file
61
disabled/uart.c-disabled
Normal file
@ -0,0 +1,61 @@
|
||||
#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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
14
disabled/uart.h-disabled
Normal file
14
disabled/uart.h-disabled
Normal file
@ -0,0 +1,14 @@
|
||||
#ifndef UART_H_
|
||||
#define UART_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
#define UART_TX_BUFFER_SIZE 20
|
||||
|
||||
|
||||
void uartInit(void *handleArg);
|
||||
void uartExec(void *handleArg);
|
||||
int putchar(int character);
|
||||
|
||||
#endif // UART_H_
|
Reference in New Issue
Block a user