39 #include "dev/uart0.h"
40 #include "dev/watchdog.h"
42 #include "isr_compat.h"
44 static int (*uart0_input_handler)(
unsigned char c);
48 #ifdef UART0_CONF_TX_WITH_INTERRUPT
49 #define TX_WITH_INTERRUPT UART0_CONF_TX_WITH_INTERRUPT
51 #define TX_WITH_INTERRUPT 1
54 #ifdef UART0_CONF_RX_WITH_DMA
55 #define RX_WITH_DMA UART0_CONF_RX_WITH_DMA
64 static uint8_t txbuf_data[TXBUFSIZE];
70 static uint8_t
rxbuf[RXBUFSIZE];
71 static uint16_t last_size;
72 static struct ctimer rxdma_timer;
75 handle_rxdma_timer(
void *ptr)
79 while(last_size != size) {
80 uart0_input_handler((
unsigned char)
rxbuf[RXBUFSIZE - last_size]);
83 last_size = RXBUFSIZE;
104 uart0_input_handler =
input;
108 uart0_writeb(
unsigned char c)
111 #if TX_WITH_INTERRUPT
128 while((UCA0STAT & UCBUSY));
135 #if !NETSTACK_CONF_WITH_IPV4
147 UCA0CTL1 |= UCSSEL_2;
163 UCA0CTL1 &= ~UCSWRST;
166 #if TX_WITH_INTERRUPT
174 DMACTL0 = DMA0TSEL_3;
177 DMA0SA = (
unsigned int)&UCA0RXBUF;
178 DMA0DA = (
unsigned int)&
rxbuf;
180 last_size = RXBUFSIZE;
181 DMA0CTL = DMADT_4 + DMASBDB + DMADSTINCR_3 + DMAEN + DMAREQ;
183 msp430_add_lpm_req(MSP430_REQUIRE_LPM1);
188 ISR(USCIAB0RX, uart0_rx_interrupt)
192 ENERGEST_ON(ENERGEST_TYPE_IRQ);
193 if(UCA0STAT & UCRXERR) {
197 if(uart0_input_handler !=
NULL) {
198 if(uart0_input_handler(c)) {
203 ENERGEST_OFF(ENERGEST_TYPE_IRQ);
207 #if TX_WITH_INTERRUPT
208 ISR(USCIAB0TX, uart0_tx_interrupt)
210 ENERGEST_ON(ENERGEST_TYPE_IRQ);
211 if((IFG2 & UCA0TXIFG)) {
223 ENERGEST_OFF(ENERGEST_TYPE_IRQ);
int ringbuf_get(struct ringbuf *r)
Get a byte from the ring buffer.
void uart0_init(unsigned long ubr)
Initialize the RS232 port.
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.
Header file for the energy estimation mechanism
int ringbuf_elements(struct ringbuf *r)
Get the number of elements currently in the ring buffer.
#define NULL
The null pointer.
static uint8_t transmitting(void)
Check the RF's TX status.
void ringbuf_init(struct ringbuf *r, uint8_t *dataptr, uint8_t size)
Initialize a ring buffer.
Structure that holds the state of a ring buffer.
void watchdog_periodic(void)
Writes the WDT clear sequence.
#define CLOCK_SECOND
A second, measured in system clock time.
void uart0_set_input(int(*input)(unsigned char c))
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.
tcirc_buf rxbuf
The RX circular buffer, for storing characters from serial port.
Header file for the ring buffer library