Skip to content

Commit d714479

Browse files
committed
clean up
1 parent 01c1296 commit d714479

File tree

1 file changed

+16
-21
lines changed
  • ports/nrf/common-hal/busio

1 file changed

+16
-21
lines changed

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

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -48,20 +48,8 @@
4848
}\
4949
}while(0)
5050

51-
#define UARTE_DEBUG 0
52-
53-
#if UARTE_DEBUG
54-
#define PRINT_INT(x) printf("%s: %d: " #x " = %ld\n" , __FUNCTION__, __LINE__, (uint32_t) (x) )
55-
#else
56-
#define PRINT_INT(x)
57-
#endif
58-
5951
static uint32_t get_nrf_baud (uint32_t baudrate);
6052

61-
static uint32_t _err = 0;
62-
static uint32_t _err_count = 0;
63-
64-
6553
static void uart_callback_irq (const nrfx_uarte_event_t * event, void * context) {
6654
busio_uart_obj_t* self = (busio_uart_obj_t*) context;
6755

@@ -74,12 +62,9 @@ static void uart_callback_irq (const nrfx_uarte_event_t * event, void * context)
7462
break;
7563

7664
case NRFX_UART_EVT_ERROR:
77-
// Abort too fast will cause error occasionally
7865
if ( self->rx_count == -1 ) {
79-
self->rx_count = 0; // event->data.error.rxtx.bytes;
66+
self->rx_count = 0;
8067
}
81-
_err_count = event->data.error.rxtx.bytes;
82-
_err = event->data.error.error_mask;
8368
break;
8469

8570
default:
@@ -184,7 +169,7 @@ size_t common_hal_busio_uart_read(busio_uart_obj_t *self, uint8_t *data, size_t
184169
uint64_t start_ticks = ticks_ms;
185170

186171
while ( 1 ) {
187-
// Wait for on-going reception to complete
172+
// Wait for on-going transfer to complete
188173
while ( (self->rx_count == -1) && (ticks_ms - start_ticks < self->timeout_ms) ) {
189174
#ifdef MICROPY_VM_HOOK_LOOP
190175
MICROPY_VM_HOOK_LOOP
@@ -233,8 +218,19 @@ size_t common_hal_busio_uart_write(busio_uart_obj_t *self, const uint8_t *data,
233218

234219
if ( len == 0 ) return 0;
235220

236-
if ( !nrfx_uarte_tx_in_progress(&self->uarte) ) {
237-
nrfx_uarte_tx_abort(&self->uarte);
221+
uint64_t start_ticks = ticks_ms;
222+
223+
// Wait for on-going transfer to complete
224+
while ( nrfx_uarte_tx_in_progress(&self->uarte) && (ticks_ms - start_ticks < self->timeout_ms) ) {
225+
#ifdef MICROPY_VM_HOOK_LOOP
226+
MICROPY_VM_HOOK_LOOP
227+
#endif
228+
}
229+
230+
// Time up
231+
if ( !(ticks_ms - start_ticks < self->timeout_ms) ) {
232+
*errcode = MP_EAGAIN;
233+
return MP_STREAM_ERROR;
238234
}
239235

240236
// EasyDMA can only access SRAM
@@ -248,7 +244,6 @@ size_t common_hal_busio_uart_write(busio_uart_obj_t *self, const uint8_t *data,
248244
_VERIFY_ERR(*errcode);
249245
(*errcode) = 0;
250246

251-
uint64_t start_ticks = ticks_ms;
252247
while ( nrfx_uarte_tx_in_progress(&self->uarte) && (ticks_ms - start_ticks < self->timeout_ms) ) {
253248
#ifdef MICROPY_VM_HOOK_LOOP
254249
MICROPY_VM_HOOK_LOOP
@@ -283,7 +278,7 @@ uint32_t common_hal_busio_uart_rx_characters_available(busio_uart_obj_t *self) {
283278
#ifndef NRF52840_XXAA
284279
mp_raise_NotImplementedError(translate("busio.UART not yet implemented"));
285280
#else
286-
return (self->rx_count > 0) ? 1 : 0;
281+
return (self->rx_count > 0) ? self->rx_count : 0;
287282
#endif
288283
}
289284

0 commit comments

Comments
 (0)