36 #include "dev/uart1.h" 37 #include "dev/watchdog.h" 40 #include "isr_compat.h" 42 static int (*uart1_input_handler)(
unsigned char c);
43 static 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 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) {
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;
98 uart1_set_input(
int (*
input)(
unsigned char c))
103 uart1_input_handler =
input;
107 uart1_writeb(
unsigned char c)
110 #if TX_WITH_INTERRUPT 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);
216 #if TX_WITH_INTERRUPT 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);
238 ISR(UART1RX, uart1_rx_interrupt)
242 if(!(URXIFG1 & IFG2)) {
255 if(uart1_input_handler != NULL) {
256 if(uart1_input_handler(c)) {
265 #if TX_WITH_INTERRUPT 266 ISR(UART1TX, uart1_tx_interrupt)
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 uart1_init(unsigned long ubr)
Initalize the RS232 port.
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.
Header file for the callback timer
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.