Skip to content

Commit

Permalink
Merge pull request adafruit#8700 from dhalbert/8.2.x-pio-dma-based-on…
Browse files Browse the repository at this point in the history
…-fifo-length

Use PIO DMA when transfer size exceeds FIFO length
  • Loading branch information
dhalbert authored Dec 6, 2023
2 parents dd9ecc8 + b3a74de commit c5c7d11
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
7 changes: 5 additions & 2 deletions ports/raspberrypi/common-hal/rp2pio/StateMachine.c
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,8 @@ bool rp2pio_statemachine_construct(rp2pio_statemachine_obj_t *self,
} else if (!tx_fifo) {
join = PIO_FIFO_JOIN_RX;
}
self->fifo_depth = (join == PIO_FIFO_JOIN_NONE) ? 4 : 8;

if (rx_fifo) {
self->rx_dreq = pio_get_dreq(self->pio, self->state_machine, false);
}
Expand Down Expand Up @@ -688,8 +690,9 @@ static bool _transfer(rp2pio_statemachine_obj_t *self,
// This implementation is based on SPI but varies because the tx and rx buffers
// may be different lengths and occur at different times or speeds.

// Use DMA for large transfers if channels are available
const size_t dma_min_size_threshold = 32;
// Use DMA for large transfers if channels are available.
// Don't exceed FIFO size.
const size_t dma_min_size_threshold = self->fifo_depth;
int chan_tx = -1;
int chan_rx = -1;
size_t len = MAX(out_len, in_len);
Expand Down
1 change: 1 addition & 0 deletions ports/raspberrypi/common-hal/rp2pio/StateMachine.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ typedef struct {
bool in_shift_right;
bool user_interruptible;
uint8_t offset;
uint8_t fifo_depth; // Either 4 if FIFOs are not joined, or 8 if they are.

// dma-related items
volatile int pending_buffers;
Expand Down

0 comments on commit c5c7d11

Please sign in to comment.