45
45
46
46
#define JD_LOG_SIZE 512
47
47
volatile uint32_t jd_log [JD_LOG_SIZE ] = {0 };
48
- static uint32_t logidx = 0 ;
48
+ uint32_t logidx = 0 ;
49
49
50
50
static inline void log_char (char c ) {
51
51
jd_log [logidx ] = c ;
@@ -319,6 +319,7 @@ static void uart_configure_tx(busio_jacdac_obj_t* self, int enable) {
319
319
NRF_P0 -> PIN_CNF [self -> pin ] = 3 << 2 ; // this overrides DIR setting above
320
320
self -> uarte -> p_reg -> PSEL .TXD = self -> pin ;
321
321
self -> uarte -> p_reg -> EVENTS_ENDTX = 0 ;
322
+ self -> uarte -> p_reg -> INTENSET = (UARTE_INTENSET_ENDTX_Msk );
322
323
self -> uarte -> p_reg -> ENABLE = 8 ;
323
324
while (!(self -> uarte -> p_reg -> ENABLE ));
324
325
set_status (self , TX_CONFIGURED );
@@ -327,6 +328,7 @@ static void uart_configure_tx(busio_jacdac_obj_t* self, int enable) {
327
328
while (self -> uarte -> p_reg -> TASKS_STOPTX );
328
329
self -> uarte -> p_reg -> ENABLE = 0 ;
329
330
while ((self -> uarte -> p_reg -> ENABLE ));
331
+ self -> uarte -> p_reg -> INTENCLR = (UARTE_INTENCLR_ENDTX_Msk );
330
332
self -> uarte -> p_reg -> PSEL .TXD = 0xFFFFFFFF ;
331
333
clr_status (self , TX_CONFIGURED );
332
334
}
@@ -340,6 +342,7 @@ static void uart_configure_rx(busio_jacdac_obj_t* self, int enable) {
340
342
self -> uarte -> p_reg -> EVENTS_ENDRX = 0 ;
341
343
self -> uarte -> p_reg -> EVENTS_ERROR = 0 ;
342
344
self -> uarte -> p_reg -> ERRORSRC = self -> uarte -> p_reg -> ERRORSRC ;
345
+ self -> uarte -> p_reg -> INTENSET = (UARTE_INTENSET_ENDRX_Msk | UARTE_INTENSET_ERROR_Msk );
343
346
self -> uarte -> p_reg -> ENABLE = 8 ;
344
347
while (!(self -> uarte -> p_reg -> ENABLE ));
345
348
set_status (self , RX_CONFIGURED );
@@ -348,27 +351,12 @@ static void uart_configure_rx(busio_jacdac_obj_t* self, int enable) {
348
351
while (self -> uarte -> p_reg -> TASKS_STOPRX );
349
352
self -> uarte -> p_reg -> ENABLE = 0 ;
350
353
while ((self -> uarte -> p_reg -> ENABLE ));
354
+ self -> uarte -> p_reg -> INTENCLR = (UARTE_INTENCLR_ENDRX_Msk | UARTE_INTENCLR_ERROR_Msk );
351
355
self -> uarte -> p_reg -> PSEL .RXD = 0xFFFFFFFF ;
352
356
clr_status (self , RX_CONFIGURED );
353
357
}
354
358
}
355
359
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
-
372
360
373
361
/*************************************************************************************
374
362
* Pin configuration
@@ -382,7 +370,6 @@ static inline void set_pin_tx(busio_jacdac_obj_t* self) {
382
370
383
371
uart_configure_rx (self , 0 );
384
372
uart_configure_tx (self , 1 );
385
- enable_tx_interrupts (self );
386
373
}
387
374
388
375
// 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) {
392
379
393
380
uart_configure_tx (self , 0 );
394
381
uart_configure_rx (self , 1 );
395
- enable_rx_interrupts (self );
396
382
}
397
383
398
384
// 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) {
406
392
* Receiving
407
393
*/
408
394
static void stop_uart_dma (busio_jacdac_obj_t * self ) {
409
- disable_tx_interrupts (self );
410
- disable_rx_interrupts (self );
411
-
412
395
nrfx_uarte_tx_abort (self -> uarte );
413
396
nrfx_uarte_rx_abort (self -> uarte );
414
397
}
415
398
416
399
static void rx_timeout (busio_jacdac_obj_t * self ) {
417
400
log_char ('?' );
418
401
set_P1 (0 );
419
- disable_rx_interrupts (self );
420
402
421
- if (!is_status (self , RX_ACTIVE ))
422
- target_panic ();
403
+ // if (!is_status(self, RX_ACTIVE))
404
+ // target_panic();
423
405
424
406
// disable uart
425
407
stop_uart_dma (self );
@@ -462,8 +444,6 @@ static void rx_done(busio_jacdac_obj_t *self) {
462
444
set_P1 (0 );
463
445
464
446
log_char ('R' );
465
-
466
- disable_rx_interrupts (self );
467
447
// clear any upcoming timer interrupts
468
448
nrfx_timer_capture (self -> timer , NRF_TIMER_CC_CHANNEL0 );
469
449
@@ -574,7 +554,6 @@ void tx_start(busio_jacdac_obj_t *self) {
574
554
static void tx_done (busio_jacdac_obj_t * self ) {
575
555
set_P0 (0 );
576
556
log_char ('t' );
577
- disable_tx_interrupts (self );
578
557
579
558
if (!is_status (self , TX_ACTIVE ))
580
559
target_panic ();
@@ -629,7 +608,7 @@ static void uart_irq(const nrfx_uarte_event_t* event, void* context) {
629
608
630
609
switch ( event -> type ) {
631
610
case NRFX_UARTE_EVT_RX_DONE :
632
- // rx_done(self);
611
+ rx_done (self );
633
612
break ;
634
613
635
614
case NRFX_UARTE_EVT_TX_DONE :
@@ -640,8 +619,16 @@ static void uart_irq(const nrfx_uarte_event_t* event, void* context) {
640
619
log_char ('E' );
641
620
log_char ((char )event -> data .error .error_mask );
642
621
// 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
+ }
645
632
646
633
break ;
647
634
}
@@ -835,9 +822,6 @@ void common_hal_busio_jacdac_deinit(busio_jacdac_obj_t* self) {
835
822
// uart
836
823
if (self -> uarte )
837
824
{
838
- disable_tx_interrupts (self );
839
- disable_rx_interrupts (self );
840
-
841
825
nrfx_uarte_tx_abort (self -> uarte );
842
826
nrfx_uarte_rx_abort (self -> uarte );
843
827
nrfx_uarte_uninit (self -> uarte );
@@ -946,7 +930,10 @@ void jacdac_reset(void) {
946
930
947
931
for (int i = 0 ; i < JD_INST_ARRAY_SIZE ; i ++ )
948
932
{
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
+ }
951
938
}
952
939
}
0 commit comments