static int uarte_nrfx_err_check(struct device *dev) { u32_t error = 0; NRF_UARTE_Type *uarte = get_uarte_instance(dev); if (nrf_uarte_event_check(uarte, NRF_UARTE_EVENT_ERROR)) { /* register bitfields maps to the defines in uart.h */ error = nrf_uarte_errorsrc_get_and_clear(uarte); } return error; }
static void uarte_irq_handler(NRF_UARTE_Type * p_uarte, uarte_control_block_t * p_cb) { if (nrf_uarte_event_check(p_uarte, NRF_UARTE_EVENT_ERROR)) { nrfx_uarte_event_t event; nrf_uarte_event_clear(p_uarte, NRF_UARTE_EVENT_ERROR); event.type = NRFX_UARTE_EVT_ERROR; event.data.error.error_mask = nrf_uarte_errorsrc_get_and_clear(p_uarte); event.data.error.rxtx.bytes = nrf_uarte_rx_amount_get(p_uarte); event.data.error.rxtx.p_data = p_cb->p_rx_buffer; // Abort transfer. p_cb->rx_buffer_length = 0; p_cb->rx_secondary_buffer_length = 0; p_cb->handler(&event, p_cb->p_context); } else if (nrf_uarte_event_check(p_uarte, NRF_UARTE_EVENT_ENDRX)) { nrf_uarte_event_clear(p_uarte, NRF_UARTE_EVENT_ENDRX); size_t amount = nrf_uarte_rx_amount_get(p_uarte); // If the transfer was stopped before completion, amount of transfered bytes // will not be equal to the buffer length. Interrupted transfer is ignored. if (amount == p_cb->rx_buffer_length) { if (p_cb->rx_secondary_buffer_length) { uint8_t * p_data = p_cb->p_rx_buffer; nrf_uarte_shorts_disable(p_uarte, NRF_UARTE_SHORT_ENDRX_STARTRX); p_cb->rx_buffer_length = p_cb->rx_secondary_buffer_length; p_cb->p_rx_buffer = p_cb->p_rx_secondary_buffer; p_cb->rx_secondary_buffer_length = 0; rx_done_event(p_cb, amount, p_data); } else { p_cb->rx_buffer_length = 0; rx_done_event(p_cb, amount, p_cb->p_rx_buffer); } } } if (nrf_uarte_event_check(p_uarte, NRF_UARTE_EVENT_RXTO)) { nrf_uarte_event_clear(p_uarte, NRF_UARTE_EVENT_RXTO); if (p_cb->rx_buffer_length) { p_cb->rx_buffer_length = 0; rx_done_event(p_cb, nrf_uarte_rx_amount_get(p_uarte), p_cb->p_rx_buffer); } } if (nrf_uarte_event_check(p_uarte, NRF_UARTE_EVENT_ENDTX)) { nrf_uarte_event_clear(p_uarte, NRF_UARTE_EVENT_ENDTX); if (p_cb->tx_buffer_length) { tx_done_event(p_cb, nrf_uarte_tx_amount_get(p_uarte)); } } }
uint32_t nrfx_uarte_errorsrc_get(nrfx_uarte_t const * p_instance) { nrf_uarte_event_clear(p_instance->p_reg, NRF_UARTE_EVENT_ERROR); return nrf_uarte_errorsrc_get_and_clear(p_instance->p_reg); }