39 #include "dev/uart0.h"
40 #include "dev/watchdog.h"
42 #include "isr_compat.h"
44 static int (*uart0_input_handler)(
unsigned char c);
46 static volatile uint8_t transmitting;
48 #ifdef UART0_CONF_TX_WITH_INTERRUPT
49 #define TX_WITH_INTERRUPT UART0_CONF_TX_WITH_INTERRUPT
51 #define TX_WITH_INTERRUPT 1
59 static uint8_t txbuf_data[TXBUFSIZE];
66 return (UCA0STAT & UCBUSY) | transmitting;
70 uart0_set_input(
int (*input)(
unsigned char c))
72 uart0_input_handler = input;
76 uart0_writeb(
unsigned char c)
87 if(transmitting == 0) {
96 while((UCA0STAT & UCBUSY));
115 UCA0CTL1 |= UCSSEL_2;
131 UCA0CTL1 &= ~UCSWRST;
134 #if TX_WITH_INTERRUPT
140 ISR(USCIAB0RX, uart0_rx_interrupt)
144 ENERGEST_ON(ENERGEST_TYPE_IRQ);
145 if(UCA0STAT & UCRXERR) {
149 if(uart0_input_handler !=
NULL) {
150 if(uart0_input_handler(c)) {
155 ENERGEST_OFF(ENERGEST_TYPE_IRQ);
158 #if TX_WITH_INTERRUPT
159 ISR(USCIAB0TX, uart0_tx_interrupt)
161 ENERGEST_ON(ENERGEST_TYPE_IRQ);
162 if((IFG2 & UCA0TXIFG)){
174 ENERGEST_OFF(ENERGEST_TYPE_IRQ);
Header file for the ring buffer library
void uart0_init(unsigned long ubr)
Initalize the RS232 port.
Structure that holds the state of a ring buffer.
#define NULL
The null pointer.
int ringbuf_get(struct ringbuf *r)
Get a byte from the ring buffer.
void ringbuf_init(struct ringbuf *r, uint8_t *dataptr, uint8_t size)
Initialize a ring buffer.
Header file for the energy estimation mechanism
int ringbuf_elements(struct ringbuf *r)
Get the number of elements currently in the ring buffer.
void watchdog_periodic(void)
Writes the WDT clear sequence.
int ringbuf_put(struct ringbuf *r, uint8_t c)
Insert a byte into the ring buffer.