41 #include "dev/watchdog.h"
45 static int (*uart0_input_handler)(
unsigned char c);
47 static volatile uint8_t transmitting;
49 #ifdef UART0_CONF_TX_WITH_INTERRUPT
50 #define TX_WITH_INTERRUPT UART0_CONF_TX_WITH_INTERRUPT
52 #define TX_WITH_INTERRUPT 1
60 static uint8_t txbuf_data[TXBUFSIZE];
67 return (UCA0STAT & UCBUSY) | transmitting;
71 uart0_set_input(
int (*input)(
unsigned char c))
73 uart0_input_handler = input;
77 uart0_writeb(
unsigned char c)
88 if(transmitting == 0) {
97 while((UCA0STAT & UCBUSY));
116 UCA0CTL1 |= UCSSEL_2;
132 UCA0CTL1 &= ~UCSWRST;
135 #if TX_WITH_INTERRUPT
142 #ifdef __IAR_SYSTEMS_ICC__
143 #pragma vector=USCIAB0RX_VECTOR
146 interrupt(USCIAB0RX_VECTOR)
148 uart0_rx_interrupt(
void)
152 ENERGEST_ON(ENERGEST_TYPE_IRQ);
153 leds_toggle(LEDS_RED);
154 if(UCA0STAT & UCRXERR) {
158 if(uart0_input_handler !=
NULL) {
159 if(uart0_input_handler(c)) {
164 ENERGEST_OFF(ENERGEST_TYPE_IRQ);
167 #if TX_WITH_INTERRUPT
168 #ifdef __IAR_SYSTEMS_ICC__
169 #pragma vector=USCIAB0TX_VECTOR
172 interrupt(USCIAB0TX_VECTOR)
174 uart0_tx_interrupt(
void)
176 ENERGEST_ON(ENERGEST_TYPE_IRQ);
177 if((IFG2 & UCA0TXIFG)){
189 ENERGEST_OFF(ENERGEST_TYPE_IRQ);