38 #include "dev/uart0.h" 39 #include "dev/watchdog.h" 41 #include "isr_compat.h" 43 static int (*uart0_input_handler)(
unsigned char c);
47 #ifdef UART0_CONF_TX_WITH_INTERRUPT 48 #define TX_WITH_INTERRUPT UART0_CONF_TX_WITH_INTERRUPT 50 #define TX_WITH_INTERRUPT 1 53 #ifdef UART0_CONF_RX_WITH_DMA 54 #define RX_WITH_DMA UART0_CONF_RX_WITH_DMA 63 static uint8_t txbuf_data[TXBUFSIZE];
69 static uint8_t rxbuf[RXBUFSIZE];
70 static uint16_t last_size;
71 static struct ctimer rxdma_timer;
74 handle_rxdma_timer(
void *ptr)
78 while(last_size != size) {
79 uart0_input_handler((
unsigned char)rxbuf[RXBUFSIZE - last_size]);
82 last_size = RXBUFSIZE;
98 uart0_set_input(
int (*
input)(
unsigned char c))
103 uart0_input_handler =
input;
107 uart0_writeb(
unsigned char c)
110 #if TX_WITH_INTERRUPT 127 while((UCA0STAT & UCBUSY));
143 UCA0CTL1 |= UCSSEL_2;
145 UCA0BR0 = ((uint8_t *)&ubr)[0];
146 UCA0BR1 = ((uint8_t *)&ubr)[1];
159 UCA0CTL1 &= ~UCSWRST;
162 #if TX_WITH_INTERRUPT 170 DMACTL0 = DMA0TSEL_3;
173 DMA0SA = (
unsigned int)&UCA0RXBUF;
174 DMA0DA = (
unsigned int)&rxbuf;
176 last_size = RXBUFSIZE;
177 DMA0CTL = DMADT_4 + DMASBDB + DMADSTINCR_3 + DMAEN + DMAREQ;
179 msp430_add_lpm_req(MSP430_REQUIRE_LPM1);
184 ISR(USCIAB0RX, uart0_rx_interrupt)
188 if(UCA0STAT & UCRXERR) {
192 if(uart0_input_handler != NULL) {
193 if(uart0_input_handler(c)) {
201 #if TX_WITH_INTERRUPT 202 ISR(USCIAB0TX, uart0_tx_interrupt)
204 if((IFG2 & UCA0TXIFG)) {
static uint8_t transmitting(void)
Check the RF's TX status.
int ringbuf_elements(struct ringbuf *r)
Get the number of elements currently in the ring buffer.
int ringbuf_get(struct ringbuf *r)
Get a byte from the ring buffer.
void ctimer_reset(struct ctimer *c)
Reset a callback timer with the same interval as was previously set.
Header file for the ring buffer library
#define CLOCK_SECOND
A second, measured in system clock time.
void uart0_init(unsigned long ubr)
Initialize the RS232 port.
void ctimer_set(struct ctimer *c, clock_time_t t, void(*f)(void *), void *ptr)
Set a callback timer.
Structure that holds the state of a 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.
static void input(void)
Process a received 6lowpan packet.
void ringbuf_init(struct ringbuf *r, uint8_t *dataptr, uint8_t size)
Initialize a ring buffer.