For sufficiently large cyw43 PIO SPI transfers, sleep via async_context before entering busy wait. #2344

Open
esky-software wants to merge 3 commits from esky-software/cyw43-pio-sleep-min into develop
esky-software commented 2025-03-10 12:52:49 -05:00 (Migrated from github.com)

Fixes #2343

The function cyw43_spi_transfer() busy waits on the transfer DMA channel(s), even for large transfers.
This is far from optimal in an RTOS or other asynchronous environment.

We might use DMA interrupts to handle the completion of the transfer, but this would require some restructuring of the driver code.

More simply, we can estimate the duration of the transfer, and if it's larger than a threshold call cyw43_delay_us() to sleep via the async context before starting the busy wait for the end of the transfer.

Define CYW43_PIO_SLEEP_MIN_US as the threshold duration (microseconds) to enable the feature.

Fixes #2343 The function cyw43_spi_transfer() busy waits on the transfer DMA channel(s), even for large transfers. This is far from optimal in an RTOS or other asynchronous environment. We might use DMA interrupts to handle the completion of the transfer, but this would require some restructuring of the driver code. More simply, we can estimate the duration of the transfer, and if it's larger than a threshold call cyw43_delay_us() to sleep via the async context before starting the busy wait for the end of the transfer. Define CYW43_PIO_SLEEP_MIN_US as the threshold duration (microseconds) to enable the feature.
lurch (Migrated from github.com) reviewed 2025-03-13 05:36:27 -05:00
@ -55,2 +55,4 @@
#endif
// PICO_CONFIG: CYW43_PIO_SLEEP_MIN_US, For PIO SPI transfers longer than this (in microseconds), sleep via async_context before entering busy wait, type=int, default=disabled, group=pico_cyw43_driver
#if CYW43_PIO_SLEEP_MIN_US
lurch (Migrated from github.com) commented 2025-03-13 05:36:26 -05:00

Perhaps this should have a // PICO_CONFIG: metadata-comment? See https://github.com/search?q=repo%3Araspberrypi%2Fpico-sdk%20PICO_CONFIG&type=code for other examples. (although I guess that means you probably want to decide on a sensible "default" value for this too? 😉 )

Perhaps this should have a `// PICO_CONFIG: ` metadata-comment? See https://github.com/search?q=repo%3Araspberrypi%2Fpico-sdk%20PICO_CONFIG&type=code for other examples. (although I guess that means you probably want to decide on a sensible "default" value for this too? :wink: )
esky-software (Migrated from github.com) reviewed 2025-03-13 11:58:15 -05:00
@ -55,2 +55,4 @@
#endif
// PICO_CONFIG: CYW43_PIO_SLEEP_MIN_US, For PIO SPI transfers longer than this (in microseconds), sleep via async_context before entering busy wait, type=int, default=disabled, group=pico_cyw43_driver
#if CYW43_PIO_SLEEP_MIN_US
esky-software (Migrated from github.com) commented 2025-03-13 11:58:15 -05:00

The default value is 0/undefined, which preserves the present functionality.

The default value is 0/undefined, which preserves the present functionality.
kilograham (Migrated from github.com) reviewed 2025-04-04 13:29:45 -05:00
@ -55,2 +55,4 @@
#endif
// PICO_CONFIG: CYW43_PIO_SLEEP_MIN_US, For PIO SPI transfers longer than this (in microseconds), sleep via async_context before entering busy wait, type=int, default=disabled, group=pico_cyw43_driver
#if CYW43_PIO_SLEEP_MIN_US
kilograham (Migrated from github.com) commented 2025-04-04 13:29:45 -05:00

it should still have a PICO_CONFIG so people know it exists (it will show up in the docs)

it should still have a PICO_CONFIG so people know it exists (it will show up in the docs)
esky-software (Migrated from github.com) reviewed 2025-04-10 07:12:09 -05:00
@ -55,2 +55,4 @@
#endif
// PICO_CONFIG: CYW43_PIO_SLEEP_MIN_US, For PIO SPI transfers longer than this (in microseconds), sleep via async_context before entering busy wait, type=int, default=disabled, group=pico_cyw43_driver
#if CYW43_PIO_SLEEP_MIN_US
esky-software (Migrated from github.com) commented 2025-04-10 07:12:09 -05:00

Added.

Added.
peterharperuk (Migrated from github.com) reviewed 2025-05-08 11:20:25 -05:00
peterharperuk (Migrated from github.com) left a comment
No description provided.
Seem like a good change and a good idea.
lurch (Migrated from github.com) reviewed 2025-05-08 11:40:09 -05:00
@ -54,6 +54,18 @@ void cyw43_set_pio_clkdiv_int_frac8(uint32_t clock_div_int, uint8_t clock_div_fr
}
lurch (Migrated from github.com) commented 2025-05-08 11:40:09 -05:00

Could you add type=int, in here (just before the default) please? (apologies for the late feedback)

Could you add `type=int, ` in here (just before the `default`) please? (apologies for the late feedback)
esky-software (Migrated from github.com) reviewed 2025-05-08 12:01:17 -05:00
@ -54,6 +54,18 @@ void cyw43_set_pio_clkdiv_int_frac8(uint32_t clock_div_int, uint8_t clock_div_fr
}
esky-software (Migrated from github.com) commented 2025-05-08 12:01:16 -05:00

Done.

Done.
esky-software commented 2025-05-30 05:13:57 -05:00 (Migrated from github.com)

Not sure why this shows as 'esky software dismissed peterharperuk's stale review...' with my update.
Did I do something wrongly?

Not sure why this shows as 'esky software dismissed peterharperuk's stale review...' with my update. Did I do something wrongly?
peterharperuk commented 2025-05-30 05:39:33 -05:00 (Migrated from github.com)

It's a mystery - don't worry about it.

It's a mystery - don't worry about it.
peterharperuk (Migrated from github.com) approved these changes 2025-05-30 10:41:13 -05:00
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'esky-software/cyw43-pio-sleep-min:esky-software/cyw43-pio-sleep-min'
git switch 'esky-software/cyw43-pio-sleep-min'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'develop'
git merge --no-ff 'esky-software/cyw43-pio-sleep-min'
git switch 'esky-software/cyw43-pio-sleep-min'
git rebase 'develop'
git switch 'develop'
git merge --ff-only 'esky-software/cyw43-pio-sleep-min'
git switch 'esky-software/cyw43-pio-sleep-min'
git rebase 'develop'
git switch 'develop'
git merge --no-ff 'esky-software/cyw43-pio-sleep-min'
git switch 'develop'
git merge --squash 'esky-software/cyw43-pio-sleep-min'
git switch 'develop'
git merge --ff-only 'esky-software/cyw43-pio-sleep-min'
git switch 'develop'
git merge 'esky-software/cyw43-pio-sleep-min'
git push origin 'develop'
Sign in to join this conversation.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gh-raspberrypi/pico-sdk!2344
No description provided.