37 #include "dev/uart1.h"
38 #include "dev/watchdog.h"
40 #include "isr_compat.h"
42 static int (*uart1_input_handler)(
unsigned char c);
44 static volatile uint8_t transmitting;
46 #ifdef UART1_CONF_TX_WITH_INTERRUPT
47 #define TX_WITH_INTERRUPT UART1_CONF_TX_WITH_INTERRUPT
49 #define TX_WITH_INTERRUPT 1
56 static uint8_t txbuf_data[TXBUFSIZE];
63 return (UCA0STAT & UCBUSY) | transmitting;
67 uart1_set_input(
int (*input)(
unsigned char c))
69 uart1_input_handler = input;
73 uart1_writeb(
unsigned char c)
85 if(transmitting == 0) {
93 while(!(IFG2 & UCA0TXIFG));
112 UCA0CTL1 |= UCSSEL_2;
116 UCA0CTL1 &= ~UCSWRST;
122 ISR(USCIAB1RX, uart1_rx_interrupt)
125 ENERGEST_ON(ENERGEST_TYPE_IRQ);
128 if(UCA0STAT & UCRXERR) {
132 if(uart1_input_handler !=
NULL) {
133 if(uart1_input_handler(c)) {
138 ENERGEST_OFF(ENERGEST_TYPE_IRQ);
141 #if TX_WITH_INTERRUPT
142 ISR(USCIAB1TX, uart1_tx_interrupt)
144 ENERGEST_ON(ENERGEST_TYPE_IRQ);
145 if(IFG2 & UCA0TXIFG) {
153 ENERGEST_OFF(ENERGEST_TYPE_IRQ);
void uart1_init(unsigned long ubr)
Initalize the RS232 port.
Header file for the ring buffer library
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.
Header file for the energy estimation mechanism
int ringbuf_elements(struct ringbuf *r)
Get the number of elements currently in the ring buffer.
int ringbuf_put(struct ringbuf *r, uint8_t c)
Insert a byte into the ring buffer.