Skip to content

Commit 3ee766b

Browse files
committed
put received bytes to fifo when error
1 parent d092722 commit 3ee766b

1 file changed

Lines changed: 15 additions & 7 deletions

File tree

  • ports/nrf/common-hal/busio

ports/nrf/common-hal/busio/UART.c

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,18 +67,24 @@ static void ringbuf_clear(ringbuf_t *r)
6767
r->iput = r->iget = 0;
6868
}
6969

70+
// will overwrite old data
71+
static void ringbuf_put_n(ringbuf_t* r, uint8_t* buf, uint8_t bufsize)
72+
{
73+
for(uint8_t i=0; i < bufsize; i++) {
74+
if ( ringbuf_put(r, buf[i]) < 0 ) {
75+
// if full overwrite old data
76+
(void) ringbuf_get(r);
77+
ringbuf_put(r, buf[i]);
78+
}
79+
}
80+
}
81+
7082
static void uart_callback_irq (const nrfx_uarte_event_t * event, void * context) {
7183
busio_uart_obj_t* self = (busio_uart_obj_t*) context;
7284

7385
switch ( event->type ) {
7486
case NRFX_UARTE_EVT_RX_DONE:
75-
for(uint8_t i=0; i < event->data.rxtx.bytes; i++) {
76-
if ( ringbuf_put(&self->rbuf, event->data.rxtx.p_data[i]) < 0 ) {
77-
// if full overwrite old data
78-
(void) ringbuf_get(&self->rbuf);
79-
ringbuf_put(&self->rbuf, event->data.rxtx.p_data[i]);
80-
}
81-
}
87+
ringbuf_put_n(&self->rbuf, event->data.rxtx.p_data, event->data.rxtx.bytes);
8288

8389
// keep receiving
8490
(void) nrfx_uarte_rx(&self->uarte, &self->rx_char, 1);
@@ -92,6 +98,8 @@ static void uart_callback_irq (const nrfx_uarte_event_t * event, void * context)
9298
// Possible Error source is Overrun, Parity, Framing, Break
9399
// uint32_t errsrc = event->data.error.error_mask;
94100

101+
ringbuf_put_n(&self->rbuf, event->data.error.rxtx.p_data, event->data.error.rxtx.bytes);
102+
95103
// Keep receiving
96104
(void) nrfx_uarte_rx(&self->uarte, &self->rx_char, 1);
97105
break;

0 commit comments

Comments
 (0)