Skip to content

Commit c2598b2

Browse files
committed
fixup reset code and remove uneccessary panic
1 parent 7cf9076 commit c2598b2

File tree

2 files changed

+25
-36
lines changed

2 files changed

+25
-36
lines changed

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

Lines changed: 23 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545

4646
#define JD_LOG_SIZE 512
4747
volatile uint32_t jd_log[JD_LOG_SIZE] = {0};
48-
static uint32_t logidx = 0;
48+
uint32_t logidx = 0;
4949

5050
static inline void log_char(char c) {
5151
jd_log[logidx] = c;
@@ -319,6 +319,7 @@ static void uart_configure_tx(busio_jacdac_obj_t* self, int enable) {
319319
NRF_P0->PIN_CNF[self->pin] = 3 << 2; // this overrides DIR setting above
320320
self->uarte->p_reg->PSEL.TXD = self->pin;
321321
self->uarte->p_reg->EVENTS_ENDTX = 0;
322+
self->uarte->p_reg->INTENSET = (UARTE_INTENSET_ENDTX_Msk);
322323
self->uarte->p_reg->ENABLE = 8;
323324
while(!(self->uarte->p_reg->ENABLE));
324325
set_status(self, TX_CONFIGURED);
@@ -327,6 +328,7 @@ static void uart_configure_tx(busio_jacdac_obj_t* self, int enable) {
327328
while(self->uarte->p_reg->TASKS_STOPTX);
328329
self->uarte->p_reg->ENABLE = 0;
329330
while((self->uarte->p_reg->ENABLE));
331+
self->uarte->p_reg->INTENCLR = (UARTE_INTENCLR_ENDTX_Msk);
330332
self->uarte->p_reg->PSEL.TXD = 0xFFFFFFFF;
331333
clr_status(self, TX_CONFIGURED);
332334
}
@@ -340,6 +342,7 @@ static void uart_configure_rx(busio_jacdac_obj_t* self, int enable) {
340342
self->uarte->p_reg->EVENTS_ENDRX = 0;
341343
self->uarte->p_reg->EVENTS_ERROR = 0;
342344
self->uarte->p_reg->ERRORSRC = self->uarte->p_reg->ERRORSRC;
345+
self->uarte->p_reg->INTENSET = (UARTE_INTENSET_ENDRX_Msk | UARTE_INTENSET_ERROR_Msk);
343346
self->uarte->p_reg->ENABLE = 8;
344347
while(!(self->uarte->p_reg->ENABLE));
345348
set_status(self, RX_CONFIGURED);
@@ -348,27 +351,12 @@ static void uart_configure_rx(busio_jacdac_obj_t* self, int enable) {
348351
while(self->uarte->p_reg->TASKS_STOPRX);
349352
self->uarte->p_reg->ENABLE = 0;
350353
while((self->uarte->p_reg->ENABLE));
354+
self->uarte->p_reg->INTENCLR = (UARTE_INTENCLR_ENDRX_Msk | UARTE_INTENCLR_ERROR_Msk);
351355
self->uarte->p_reg->PSEL.RXD = 0xFFFFFFFF;
352356
clr_status(self, RX_CONFIGURED);
353357
}
354358
}
355359

356-
static inline void enable_rx_interrupts(busio_jacdac_obj_t* self) {
357-
self->uarte->p_reg->INTENSET = (UARTE_INTENSET_ENDRX_Msk | UARTE_INTENSET_ERROR_Msk);
358-
}
359-
360-
static inline void disable_rx_interrupts(busio_jacdac_obj_t* self) {
361-
self->uarte->p_reg->INTENCLR = (UARTE_INTENCLR_ENDRX_Msk | UARTE_INTENSET_ERROR_Msk);
362-
}
363-
364-
static inline void enable_tx_interrupts(busio_jacdac_obj_t* self) {
365-
self->uarte->p_reg->INTENSET = (UARTE_INTENSET_ENDTX_Msk);
366-
}
367-
368-
static inline void disable_tx_interrupts(busio_jacdac_obj_t* self) {
369-
self->uarte->p_reg->INTENCLR = (UARTE_INTENCLR_ENDTX_Msk);
370-
}
371-
372360

373361
/*************************************************************************************
374362
* Pin configuration
@@ -382,7 +370,6 @@ static inline void set_pin_tx(busio_jacdac_obj_t* self) {
382370

383371
uart_configure_rx(self, 0);
384372
uart_configure_tx(self, 1);
385-
enable_tx_interrupts(self);
386373
}
387374

388375
// set the JACDAC pin to act as the UART rx pin
@@ -392,7 +379,6 @@ static inline void set_pin_rx(busio_jacdac_obj_t* self) {
392379

393380
uart_configure_tx(self, 0);
394381
uart_configure_rx(self, 1);
395-
enable_rx_interrupts(self);
396382
}
397383

398384
// set the JACDAC pin to act as a gpio pin
@@ -406,20 +392,16 @@ static inline void set_pin_gpio(busio_jacdac_obj_t* self) {
406392
* Receiving
407393
*/
408394
static void stop_uart_dma(busio_jacdac_obj_t* self) {
409-
disable_tx_interrupts(self);
410-
disable_rx_interrupts(self);
411-
412395
nrfx_uarte_tx_abort(self->uarte);
413396
nrfx_uarte_rx_abort(self->uarte);
414397
}
415398

416399
static void rx_timeout(busio_jacdac_obj_t* self) {
417400
log_char('?');
418401
set_P1(0);
419-
disable_rx_interrupts(self);
420402

421-
if (!is_status(self, RX_ACTIVE))
422-
target_panic();
403+
// if (!is_status(self, RX_ACTIVE))
404+
// target_panic();
423405

424406
// disable uart
425407
stop_uart_dma(self);
@@ -462,8 +444,6 @@ static void rx_done(busio_jacdac_obj_t *self) {
462444
set_P1(0);
463445

464446
log_char('R');
465-
466-
disable_rx_interrupts(self);
467447
// clear any upcoming timer interrupts
468448
nrfx_timer_capture(self->timer, NRF_TIMER_CC_CHANNEL0);
469449

@@ -574,7 +554,6 @@ void tx_start(busio_jacdac_obj_t *self) {
574554
static void tx_done(busio_jacdac_obj_t *self) {
575555
set_P0(0);
576556
log_char('t');
577-
disable_tx_interrupts(self);
578557

579558
if (!is_status(self, TX_ACTIVE))
580559
target_panic();
@@ -629,7 +608,7 @@ static void uart_irq(const nrfx_uarte_event_t* event, void* context) {
629608

630609
switch ( event->type ) {
631610
case NRFX_UARTE_EVT_RX_DONE:
632-
// rx_done(self);
611+
rx_done(self);
633612
break;
634613

635614
case NRFX_UARTE_EVT_TX_DONE:
@@ -640,8 +619,16 @@ static void uart_irq(const nrfx_uarte_event_t* event, void* context) {
640619
log_char('E');
641620
log_char((char)event->data.error.error_mask);
642621
// Possible Error source is Overrun, Parity, Framing, Break
643-
if ((event->data.error.error_mask & NRF_UARTE_ERROR_BREAK_MASK) && is_status(self, RX_ACTIVE))
644-
rx_done(self);
622+
if (is_status(self, RX_ACTIVE))
623+
{
624+
log_char('&');
625+
if ((event->data.error.error_mask & NRF_UARTE_ERROR_BREAK_MASK))
626+
rx_done(self);
627+
}
628+
else if (is_status(self, TX_ACTIVE))
629+
{
630+
log_char('*');
631+
}
645632

646633
break;
647634
}
@@ -835,9 +822,6 @@ void common_hal_busio_jacdac_deinit(busio_jacdac_obj_t* self) {
835822
// uart
836823
if (self->uarte)
837824
{
838-
disable_tx_interrupts(self);
839-
disable_rx_interrupts(self);
840-
841825
nrfx_uarte_tx_abort(self->uarte);
842826
nrfx_uarte_rx_abort(self->uarte);
843827
nrfx_uarte_uninit(self->uarte);
@@ -946,7 +930,10 @@ void jacdac_reset(void) {
946930

947931
for (int i = 0; i < JD_INST_ARRAY_SIZE; i++)
948932
{
949-
common_hal_busio_jacdac_deinit(jd_instances[i]);
950-
jd_instances[i] = NULL;
933+
if (jd_instances[i])
934+
{
935+
common_hal_busio_jacdac_deinit(jd_instances[i]);
936+
jd_instances[i] = NULL;
937+
}
951938
}
952939
}

ports/nrf/supervisor/port.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
#include "common-hal/busio/I2C.h"
4646
#include "common-hal/busio/SPI.h"
4747
#include "common-hal/busio/UART.h"
48+
#include "common-hal/busio/JACDAC.h"
4849
#include "common-hal/pulseio/PulseOut.h"
4950
#include "common-hal/pulseio/PulseIn.h"
5051
#include "common-hal/pwmio/PWMOut.h"
@@ -179,6 +180,7 @@ void reset_port(void) {
179180
#if CIRCUITPY_BUSIO
180181
i2c_reset();
181182
spi_reset();
183+
jacdac_reset();
182184
uart_reset();
183185
#endif
184186

0 commit comments

Comments
 (0)