Skip to content

Commit 09d9136

Browse files
authored
Merge pull request #9980 from dhalbert/pio-background-dma0-only
Use only DMA0 for PIO background read/write
2 parents 78a747e + a9d41bb commit 09d9136

File tree

2 files changed

+15
-28
lines changed

2 files changed

+15
-28
lines changed

ports/raspberrypi/audio_dma.c

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -486,28 +486,14 @@ void __not_in_flash_func(isr_dma_0)(void) {
486486
dma->channels_to_load_mask |= mask;
487487
background_callback_add(&dma->callback, dma_callback_fun, (void *)dma);
488488
}
489-
if (MP_STATE_PORT(background_pio)[i] != NULL) {
490-
rp2pio_statemachine_obj_t *pio = MP_STATE_PORT(background_pio)[i];
491-
rp2pio_statemachine_dma_complete_write(pio, i);
492-
}
493-
}
494-
}
495-
496-
void __not_in_flash_func(isr_dma_1)(void) {
497-
for (size_t i = 0; i < NUM_DMA_CHANNELS; i++) {
498-
uint32_t mask = 1 << i;
499-
if ((dma_hw->intr & mask) == 0) {
500-
continue;
501-
}
502-
// acknowledge interrupt early. Doing so late means that you could lose an
503-
// interrupt if the buffer is very small and the DMA operation
504-
// completed by the time callback_add() / dma_complete() returned. This
505-
// affected PIO continuous write more than audio.
506-
dma_hw->ints1 = mask;
507-
if (MP_STATE_PORT(background_pio)[i] != NULL) {
508-
rp2pio_statemachine_obj_t *pio = MP_STATE_PORT(background_pio)[i];
489+
if (MP_STATE_PORT(background_pio_read)[i] != NULL) {
490+
rp2pio_statemachine_obj_t *pio = MP_STATE_PORT(background_pio_read)[i];
509491
rp2pio_statemachine_dma_complete_read(pio, i);
510492
}
493+
if (MP_STATE_PORT(background_pio_write)[i] != NULL) {
494+
rp2pio_statemachine_obj_t *pio = MP_STATE_PORT(background_pio_write)[i];
495+
rp2pio_statemachine_dma_complete_write(pio, i);
496+
}
511497
}
512498
}
513499

ports/raspberrypi/common-hal/rp2pio/StateMachine.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ static void rp2pio_statemachine_clear_dma_write(int pio_index, int sm) {
9696
if (!dma_hw->inte0) {
9797
irq_set_mask_enabled(1 << DMA_IRQ_0, false);
9898
}
99-
MP_STATE_PORT(background_pio)[channel_write] = NULL;
99+
MP_STATE_PORT(background_pio_write)[channel_write] = NULL;
100100
dma_channel_abort(channel_write);
101101
dma_channel_unclaim(channel_write);
102102
}
@@ -111,7 +111,7 @@ static void rp2pio_statemachine_clear_dma_read(int pio_index, int sm) {
111111
if (!dma_hw->inte0) {
112112
irq_set_mask_enabled(1 << DMA_IRQ_0, false);
113113
}
114-
MP_STATE_PORT(background_pio)[channel_read] = NULL;
114+
MP_STATE_PORT(background_pio_read)[channel_read] = NULL;
115115
dma_channel_abort(channel_read);
116116
dma_channel_unclaim(channel_read);
117117
}
@@ -1229,7 +1229,7 @@ bool common_hal_rp2pio_statemachine_background_write(rp2pio_statemachine_obj_t *
12291229

12301230
// Acknowledge any previous pending interrupt
12311231
dma_hw->ints0 |= 1u << channel_write;
1232-
MP_STATE_PORT(background_pio)[channel_write] = self;
1232+
MP_STATE_PORT(background_pio_write)[channel_write] = self;
12331233
dma_hw->inte0 |= 1u << channel_write;
12341234

12351235
irq_set_mask_enabled(1 << DMA_IRQ_0, true);
@@ -1392,10 +1392,10 @@ bool common_hal_rp2pio_statemachine_background_read(rp2pio_statemachine_obj_t *s
13921392

13931393
common_hal_mcu_disable_interrupts();
13941394
// Acknowledge any previous pending interrupt
1395-
dma_hw->ints1 |= 1u << channel_read;
1396-
MP_STATE_PORT(background_pio)[channel_read] = self;
1397-
dma_hw->inte1 |= 1u << channel_read;
1398-
irq_set_mask_enabled(1 << DMA_IRQ_1, true);
1395+
dma_hw->ints0 |= 1u << channel_read;
1396+
MP_STATE_PORT(background_pio_read)[channel_read] = self;
1397+
dma_hw->inte0 |= 1u << channel_read;
1398+
irq_set_mask_enabled(1 << DMA_IRQ_0, true);
13991399
dma_start_channel_mask((1u << channel_read));
14001400
common_hal_mcu_enable_interrupts();
14011401

@@ -1485,4 +1485,5 @@ mp_obj_t common_hal_rp2pio_statemachine_get_last_write(rp2pio_statemachine_obj_t
14851485

14861486
// Use a compile-time constant for MP_REGISTER_POINTER so the preprocessor will
14871487
// not split the expansion across multiple lines.
1488-
MP_REGISTER_ROOT_POINTER(mp_obj_t background_pio[enum_NUM_DMA_CHANNELS]);
1488+
MP_REGISTER_ROOT_POINTER(mp_obj_t background_pio_read[enum_NUM_DMA_CHANNELS]);
1489+
MP_REGISTER_ROOT_POINTER(mp_obj_t background_pio_write[enum_NUM_DMA_CHANNELS]);

0 commit comments

Comments
 (0)