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 if (p_event->type == NRF_DRV_UART_EVT_RX_DONE) {
67 if (uart0_input_handler != NULL) {
68 uart0_input_handler(p_event->data.rxtx.p_data[0]);
70 (void)nrf_drv_uart_rx(rx_buffer, 1);
71 }
else if (p_event->type == NRF_DRV_UART_EVT_TX_DONE) {
74 nrf_drv_uart_tx(&c, 1);
80 uart0_set_input(
int (*
input)(
unsigned char c))
82 uart0_input_handler =
input;
86 uart0_writeb(
unsigned char c)
88 if (nrf_drv_uart_tx(&c, 1) == NRF_ERROR_BUSY) {
102 nrf_drv_uart_config_t
config = NRF_DRV_UART_DEFAULT_CONFIG;
103 ret_code_t retcode = nrf_drv_uart_init(&config, uart_event_handler);
104 APP_ERROR_CHECK(retcode);
108 nrf_drv_uart_rx_enable();
109 nrf_drv_uart_rx(rx_buffer, 1);
int ringbuf_elements(struct ringbuf *r)
Get the number of elements currently in the ring buffer.
__STATIC_INLINE void __WFE(void)
Wait For Event.
int ringbuf_get(struct ringbuf *r)
Get a byte from the ring buffer.
Header file for the ring buffer library
void uart0_init(unsigned long ubr)
Initialize the RS232 port.
Structure that holds the state of a ring buffer.
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.