Skip to content

Commit c5c7d11

Browse files
authored
Merge pull request #8700 from dhalbert/8.2.x-pio-dma-based-on-fifo-length
Use PIO DMA when transfer size exceeds FIFO length
2 parents dd9ecc8 + b3a74de commit c5c7d11

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,8 @@ bool rp2pio_statemachine_construct(rp2pio_statemachine_obj_t *self,
348348
} else if (!tx_fifo) {
349349
join = PIO_FIFO_JOIN_RX;
350350
}
351+
self->fifo_depth = (join == PIO_FIFO_JOIN_NONE) ? 4 : 8;
352+
351353
if (rx_fifo) {
352354
self->rx_dreq = pio_get_dreq(self->pio, self->state_machine, false);
353355
}
@@ -688,8 +690,9 @@ static bool _transfer(rp2pio_statemachine_obj_t *self,
688690
// This implementation is based on SPI but varies because the tx and rx buffers
689691
// may be different lengths and occur at different times or speeds.
690692

691-
// Use DMA for large transfers if channels are available
692-
const size_t dma_min_size_threshold = 32;
693+
// Use DMA for large transfers if channels are available.
694+
// Don't exceed FIFO size.
695+
const size_t dma_min_size_threshold = self->fifo_depth;
693696
int chan_tx = -1;
694697
int chan_rx = -1;
695698
size_t len = MAX(out_len, in_len);

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ typedef struct {
5959
bool in_shift_right;
6060
bool user_interruptible;
6161
uint8_t offset;
62+
uint8_t fifo_depth; // Either 4 if FIFOs are not joined, or 8 if they are.
6263

6364
// dma-related items
6465
volatile int pending_buffers;

0 commit comments

Comments
 (0)