8000 Merge pull request #4155 from jepler/rpi-pio-background · adafruit/circuitpython@b0ed258 · GitHub
[go: up one dir, main page]

Skip to content

Commit b0ed258

Browse files
authored
Merge pull request #4155 from jepler/rpi-pio-background
rp2pio: Transfer up to 32 bytes before checking background tasks
2 parents f171660 + 5423e49 commit b0ed258

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

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

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -546,15 +546,23 @@ static bool _transfer(rp2pio_statemachine_obj_t *self,
546546
size_t tx_remaining = out_len;
547547

548548
while (rx_remaining || tx_remaining) {
549-
if (tx_remaining && !pio_sm_is_tx_fifo_full(self->pio, self->state_machine)) {
550-
*tx_destination = *data_out;
551-
data_out++;
552-
--tx_remaining;
553-
}
554-
if (rx_remaining && !pio_sm_is_rx_fifo_empty(self->pio, self->state_machine)) {
555-
*data_in = (uint8_t) *rx_source;
556-
data_in++;
557-
--rx_remaining;
549+
for (int i=0; i<32; i++) {
550+
bool did_transfer = false;
551+
if (tx_remaining && !pio_sm_is_tx_fifo_full(self->pio, self->state_machine)) {
552+
*tx_destination = *data_out;
553+
data_out++;
554+
--tx_remaining;
555+
did_transfer = true;
556+
}
557+
if (rx_remaining && !pio_sm_is_rx_fifo_empty(self->pio, self->state_machine)) {
558+
*data_in = (uint8_t) *rx_source;
559+
data_in++;
560+
--rx_remaining;
561+
did_transfer = true;
562+
}
563+
if (!did_transfer) {
564+
break;
565+
}
558566
}
559567
RUN_BACKGROUND_TASKS;
560568
if (mp_hal_is_interrupted()) {

0 commit comments

Comments
 (0)
0