summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Epler <jepler@gmail.com>2021-02-08 08:35:07 -0600
committerJeff Epler <jepler@gmail.com>2021-02-08 08:35:07 -0600
commit5423e4966c857c7d02c08f87fd872ddfbe8afc20 (patch)
tree95f955e3ef50ed09e0cf85683c85cf0d4bdaf24e
parenta10ce39ae6dd21a9226c24a8782c8e94ee8343ff (diff)
rp2pio: Transfer up to 32 bytes before checking background tasks
@Jerryneedell noticed that this problem affected strips short enough to not use the DMA peripheral, thanks for the hot tip! Instead of checking for background tasks after every byte transfer, try up to 32 transfers before attending to background tasks. This fixes the problem I was seeing on my 5-pixel circuit. Closes #4135.
-rw-r--r--ports/raspberrypi/common-hal/rp2pio/StateMachine.c26
1 files changed, 17 insertions, 9 deletions
diff --git a/ports/raspberrypi/common-hal/rp2pio/StateMachine.c b/ports/raspberrypi/common-hal/rp2pio/StateMachine.c
index 6510410b0..90c48130e 100644
--- a/ports/raspberrypi/common-hal/rp2pio/StateMachine.c
+++ b/ports/raspberrypi/common-hal/rp2pio/StateMachine.c
@@ -546,15 +546,23 @@ static bool _transfer(rp2pio_statemachine_obj_t *self,
size_t tx_remaining = out_len;
while (rx_remaining || tx_remaining) {
- if (tx_remaining && !pio_sm_is_tx_fifo_full(self->pio, self->state_machine)) {
- *tx_destination = *data_out;
- data_out++;
- --tx_remaining;
- }
- if (rx_remaining && !pio_sm_is_rx_fifo_empty(self->pio, self->state_machine)) {
- *data_in = (uint8_t) *rx_source;
- data_in++;
- --rx_remaining;
+ for (int i=0; i<32; i++) {
+ bool did_transfer = false;
+ if (tx_remaining && !pio_sm_is_tx_fifo_full(self->pio, self->state_machine)) {
+ *tx_destination = *data_out;
+ data_out++;
+ --tx_remaining;
+ did_transfer = true;
+ }
+ if (rx_remaining && !pio_sm_is_rx_fifo_empty(self->pio, self->state_machine)) {
+ *data_in = (uint8_t) *rx_source;
+ data_in++;
+ --rx_remaining;
+ did_transfer = true;
+ }
+ if (!did_transfer) {
+ break;
+ }
}
RUN_BACKGROUND_TASKS;
if (mp_hal_is_interrupted()) {