8000 rp2pio: Transfer up to 32 bytes before checking background tasks by jepler · Pull Request #4155 · adafruit/circuitpython · GitHub
[go: up one dir, main page]

Skip to content

rp2pio: Transfer up to 32 bytes before checking background tasks #4155

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 8, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 17 additions & 9 deletions ports/raspberrypi/common-hal/rp2pio/StateMachine.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it'd be clearer if you replaced the original if statements with while loops. That way you'd load up the 4 or 8 entry FIFO and then move on. 32 seems arbitrary and I'm skeptical you'd ever hit that many due to the FIFO size.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I chose 32 because it was the DMA threshold. I didn't check the FIFO size at all! I'll open an issue suggesting the clean-up, but try to get to it next time I'm working in this code.

break;
}
}
RUN_BACKGROUND_TASKS;
if (mp_hal_is_interrupted()) {
Expand Down
0