44 #include "nrf_drv_config.h"
45 #include "nrf_drv_uart.h"
46 #include "app_util_platform.h"
47 #include "app_error.h"
50 #include "dev/uart0.h"
51 #include "dev/watchdog.h"
55 static uint8_t rx_buffer[1];
57 static int (*uart0_input_handler)(
unsigned char c);
60 static uint8_t txbuf_data[TXBUFSIZE];
64 uart_event_handler(nrf_drv_uart_event_t * p_event,
void * p_context)
66 ENERGEST_ON(ENERGEST_TYPE_IRQ);
68 if (p_event->type == NRF_DRV_UART_EVT_RX_DONE) {
69 if (uart0_input_handler !=
NULL) {
70 uart0_input_handler(p_event->data.rxtx.p_data[0]);
72 (void)nrf_drv_uart_rx(rx_buffer, 1);
73 }
else if (p_event->type == NRF_DRV_UART_EVT_TX_DONE) {
76 nrf_drv_uart_tx(&c, 1);
80 ENERGEST_OFF(ENERGEST_TYPE_IRQ);
86 uart0_input_handler =
input;
90 uart0_writeb(
unsigned char c)
92 if (nrf_drv_uart_tx(&c, 1) == NRF_ERROR_BUSY) {
106 nrf_drv_uart_config_t config = NRF_DRV_UART_DEFAULT_CONFIG;
107 ret_code_t retcode = nrf_drv_uart_init(&config, uart_event_handler);
108 APP_ERROR_CHECK(retcode);
112 nrf_drv_uart_rx_enable();
113 nrf_drv_uart_rx(rx_buffer, 1);
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.
int ringbuf_elements(struct ringbuf *r)
Get the number of elements currently in the ring buffer.
#define NULL
The null pointer.
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 uart0_set_input(int(*input)(unsigned char c))
Header file for the ring buffer library