39#include "dev/watchdog.h"
41#include "isr_compat.h"
43static 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
63static uint8_t txbuf_data[TXBUFSIZE];
69static uint8_t rxbuf[RXBUFSIZE];
70static uint16_t last_size;
71static struct ctimer rxdma_timer;
74handle_rxdma_timer(
void *ptr)
78 while(last_size != size) {
79 uart0_input_handler((
unsigned char)rxbuf[RXBUFSIZE - last_size]);
82 last_size = RXBUFSIZE;
98uart0_set_input(
int (*
input)(
unsigned char c))
103 uart0_input_handler =
input;
107uart0_writeb(
unsigned char c)
127 while((UCA0STAT & UCBUSY));
143 UCA0CTL1 |= UCSSEL_2;
145 UCA0BR0 = ((uint8_t *)&ubr)[0];
146 UCA0BR1 = ((uint8_t *)&ubr)[1];
159 UCA0CTL1 &= ~UCSWRST;
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);
184ISR(USCIAB0RX, uart0_rx_interrupt)
188 if(UCA0STAT & UCRXERR) {
192 if(uart0_input_handler != NULL) {
193 if(uart0_input_handler(c)) {
202ISR(USCIAB0TX, uart0_tx_interrupt)
204 if((IFG2 & UCA0TXIFG)) {
void watchdog_periodic(void)
Writes the WDT clear sequence.
#define CLOCK_SECOND
A second, measured in system clock time.
void ctimer_set(struct ctimer *c, clock_time_t t, void(*f)(void *), void *ptr)
Set a callback timer.
void ctimer_reset(struct ctimer *c)
Reset a callback timer with the same interval as was previously set.
void uart0_init(unsigned long ubr)
Initalize the RS232 port.
static uint8_t transmitting(void)
Check the RF's TX status.
int ringbuf_get(struct ringbuf *r)
Get a byte from the ring buffer.
int ringbuf_put(struct ringbuf *r, uint8_t c)
Insert a byte into the ring buffer.
void ringbuf_init(struct ringbuf *r, uint8_t *dataptr, uint8_t size)
Initialize a ring buffer.
int ringbuf_elements(struct ringbuf *r)
Get the number of elements currently in the ring buffer.
static void input(void)
Process a received 6lowpan packet.
Header file for the ring buffer library.
Structure that holds the state of a ring buffer.