37#include "dev/watchdog.h"
40#include "isr_compat.h"
42static int (*uart1_input_handler)(
unsigned char c);
43static volatile uint8_t rx_in_progress;
47#ifdef UART1_CONF_TX_WITH_INTERRUPT
48#define TX_WITH_INTERRUPT UART1_CONF_TX_WITH_INTERRUPT
50#define TX_WITH_INTERRUPT 0
53#ifdef UART1_CONF_RX_WITH_DMA
54#define RX_WITH_DMA UART1_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) {
81 uart1_input_handler((
unsigned char)rxbuf[RXBUFSIZE - last_size]);
83 if(last_size == 0) last_size = RXBUFSIZE;
94 return ((~ UTCTL1) & TXEPT) | rx_in_progress |
transmitting;
98uart1_set_input(
int (*
input)(
unsigned char c))
103 uart1_input_handler =
input;
107uart1_writeb(
unsigned char c)
130 while((IFG2 & UTXIFG1) == 0);
149 UCTL1 = SWRST | CHAR;
165#if F_CPU == 3900000ul
167 case UART1_BAUD2UBR(115200ul):
170 case UART1_BAUD2UBR(57600ul):
173 case UART1_BAUD2UBR(38400ul):
176 case UART1_BAUD2UBR(19200ul):
179 case UART1_BAUD2UBR(9600ul):
183#elif F_CPU == 2457600ul
185 case UART1_BAUD2UBR(115200ul):
188 case UART1_BAUD2UBR(57600ul):
197#error Unsupported CPU speed in uart1.c
203 ME2 |= (UTXE1 | URXE1);
224 DMACTL0 = DMA0TSEL_9;
227 DMA0SA = (
unsigned int) &RXBUF1;
228 DMA0DA = (
unsigned int) &rxbuf;
230 last_size = RXBUFSIZE;
231 DMA0CTL = DMADT_4 + DMASBDB + DMADSTINCR_3 + DMAEN + DMAREQ;
233 msp430_add_lpm_req(MSP430_REQUIRE_LPM1);
238ISR(UART1RX, uart1_rx_interrupt)
242 if(!(URXIFG1 & IFG2)) {
255 if(uart1_input_handler != NULL) {
256 if(uart1_input_handler(c)) {
266ISR(UART1TX, uart1_tx_interrupt)
Header file for the callback timer.
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.
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.
A brief description of what this file is.
void uart1_init(unsigned long ubr)
Initalize the RS232 port.