static void rx_byte(NRF_UART_Type * p_uart, uart_control_block_t * p_cb) { if (!p_cb->rx_buffer_length) { nrf_uart_event_clear(p_uart, NRF_UART_EVENT_RXDRDY); // Byte received when buffer is not set - data lost. (void) nrf_uart_rxd_get(p_uart); return; } nrf_uart_event_clear(p_uart, NRF_UART_EVENT_RXDRDY); p_cb->p_rx_buffer[p_cb->rx_counter] = nrf_uart_rxd_get(p_uart); p_cb->rx_counter++; }
static int uart_nrfx_poll_in(struct device *dev, unsigned char *c) { if (!nrf_uart_event_check(NRF_UART0, NRF_UART_EVENT_RXDRDY)) { return -1; } /* Clear the interrupt */ nrf_uart_event_clear(NRF_UART0, NRF_UART_EVENT_RXDRDY); /* got a character */ *c = nrf_uart_rxd_get(NRF_UART0); return 0; }
/** Interrupt driven FIFO read function */ static int uart_nrfx_fifo_read(struct device *dev, u8_t *rx_data, const int size) { u8_t num_rx = 0; while ((size - num_rx > 0) && nrf_uart_event_check(NRF_UART0, NRF_UART_EVENT_RXDRDY)) { /* Clear the interrupt */ nrf_uart_event_clear(NRF_UART0, NRF_UART_EVENT_RXDRDY); /* Receive a character */ rx_data[num_rx++] = (u8_t)nrf_uart_rxd_get(NRF_UART0); } return num_rx; }
/** * Interrupt handler of UART0 peripherial. */ void UARTE0_UART0_IRQHandler(void) { // Check if any error has been detected. if (nrf_uart_event_check(UART_INSTANCE, NRF_UART_EVENT_ERROR)) { // Clear error event and ignore erronous byte in RXD register. nrf_uart_event_clear(UART_INSTANCE, NRF_UART_EVENT_ERROR); nrf_uart_event_clear(UART_INSTANCE, NRF_UART_EVENT_RXDRDY); } else if (nrf_uart_event_check(UART_INSTANCE, NRF_UART_EVENT_RXDRDY)) { // Clear RXDRDY event. nrf_uart_event_clear(UART_INSTANCE, NRF_UART_EVENT_RXDRDY); // Read byte from the UART buffer. uint8_t byte = nrf_uart_rxd_get(UART_INSTANCE); if (!isRxBufferFull()) { sReceiveBuffer[sReceiveHead] = byte; sReceiveHead = (sReceiveHead + 1) % UART_RX_BUFFER_SIZE; otSysEventSignalPending(); } } if (nrf_uart_event_check(UART_INSTANCE, NRF_UART_EVENT_TXDRDY)) { // Clear TXDRDY event. nrf_uart_event_clear(UART_INSTANCE, NRF_UART_EVENT_TXDRDY); // Send any more bytes if available or call application about TX done. if (sTransmitLength) { nrf_uart_txd_set(UART_INSTANCE, *sTransmitBuffer++); sTransmitLength--; } else { sTransmitDone = true; nrf_uart_task_trigger(UART_INSTANCE, NRF_UART_TASK_STOPTX); otSysEventSignalPending(); } } }
static int _uart_getc(struct rt_serial_device *serial) { int ch = -1; UART_CFG_T *instance = working_cfg; RT_ASSERT(serial != RT_NULL); if (serial->parent.user_data != RT_NULL) { instance = (UART_CFG_T*)serial->parent.user_data; } if (nrf_uart_event_check(instance->uart.reg.p_uart, NRF_UART_EVENT_RXDRDY)) { nrf_uart_event_clear(instance->uart.reg.p_uart, NRF_UART_EVENT_RXDRDY); ch = (int)(nrf_uart_rxd_get(instance->uart.reg.p_uart)); } return ch; }