-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Add is_isr parameter to dcd_edpt_xfer, dcd_edpt_xfer_fifo, usbd_edpt_xfer, and usbd_edpt_xfer_fifo functions #3313
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
Conversation
Co-authored-by: HiFiPhile <4375114+HiFiPhile@users.noreply.github.com>
Co-authored-by: HiFiPhile <4375114+HiFiPhile@users.noreply.github.com>
Co-authored-by: HiFiPhile <4375114+HiFiPhile@users.noreply.github.com>
Co-authored-by: HiFiPhile <4375114+HiFiPhile@users.noreply.github.com>
- revert all submodule changes
- Add is_isr argument to usbd_edpt_xfer and usbd_edpt_xfer_fifo, set it to true if called in ISR, for example audiod_rx_xfer_isr
- Added bool is_isr parameter to usbd_edpt_xfer() and usbd_edpt_xfer_fifo() wrapper functions - These are called by class drivers to queue USB transfers - Updated all callers to pass false by default (non-ISR context) - Updated audiod_rx_xfer_isr() and audiod_tx_xfer_isr() to pass true (ISR context) - All 21 unit tests pass Co-authored-by: HiFiPhile <4375114+HiFiPhile@users.noreply.github.com>
- revert all submodule changes
- Add is_isr argument to usbd_edpt_xfer and usbd_edpt_xfer_fifo, set it to true if called in ISR, for example audiod_rx_xfer_isr
Added is_isr parameter to usbd_edpt_xfer() and usbd_edpt_xfer_fifo() wrapper functions. ISR functions like audiod_rx_xfer_isr() and audiod_tx_xfer_isr() now pass true, while all other callers pass false. Submodule changes will be reverted in next commit. Commit: 27415e6
f06b05d to
4143243
Compare
Signed-off-by: Mengsk <admin@hifiphile.com>
4143243 to
30132e8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds a bool is_isr parameter to the DCD and USBD transfer functions (dcd_edpt_xfer, dcd_edpt_xfer_fifo, usbd_edpt_xfer, and usbd_edpt_xfer_fifo) to indicate whether the functions are being called from ISR or task context. This enables proper synchronization handling by allowing the locking mechanism to differentiate between interrupt and non-interrupt contexts.
Key changes:
- Updated function signatures across DCD layer, USBD layer, and class drivers
- Modified locking calls in DWC2 driver to use the new
is_isrparameter - Most callers pass
false(task context); ISR functions like audio callbacks passtrue
Reviewed Changes
Copilot reviewed 49 out of 49 changed files in this pull request and generated 30 comments.
Show a summary per file
| File | Description |
|---|---|
| src/device/dcd.h | Added is_isr parameter to DCD function declarations |
| src/device/usbd_pvt.h | Added is_isr parameter to USBD wrapper declarations |
| src/device/usbd.c | Updated implementations to accept and propagate is_isr parameter |
| src/device/usbd_control.c | Updated control transfer calls to pass false for task context |
| src/portable/synopsys/dwc2/dcd_dwc2.c | Modified to use is_isr parameter in spin lock/unlock calls |
| src/portable//dcd_.c (30+ files) | Added is_isr parameter with (void) is_isr; suppression |
| src/class/audio/audio_device.c | Updated ISR callbacks to pass true; non-ISR calls pass false |
| src/class/*/[device].c (10+ files) | Updated all transfer calls to pass false for task context |
| test/unit-test/test/device/usbd/test_usbd.c | Updated mock expectations to include new parameter |
| test/unit-test/test/device/msc/test_msc_device.c | Updated mock expectations to include new parameter |
| test/fuzz/dcd_fuzz.cc | Added parameter with unused suppression |
| src/tusb.c | Updated stream transfer call to pass false |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Uh oh!
There was an error while loading. Please reload this page.
Overview
This PR fixes issue #3311 by adding a
bool is_isrparameter to both the low-level DCD functions (dcd_edpt_xfer()anddcd_edpt_xfer_fifo()) and the high-level wrapper functions (usbd_edpt_xfer()andusbd_edpt_xfer_fifo()). This allows both DCD drivers and class drivers to properly handle synchronization based on whether they are being called from ISR context or task context.Problem
Previously, these functions hardcoded
usbd_spin_lock(false)andusbd_spin_unlock(false), assuming they were always called from non-ISR (task) context. However, in some scenarios, these functions may need to be called from ISR context, which requires different locking behavior to avoid deadlocks or race conditions.Solution
Added a
bool is_isrparameter to both the DCD-level and USBD-level functions that indicates the calling context:is_isr = false: Called from task context (normal application code, deferred processing)is_isr = true: Called from ISR context (interrupt handlers)This parameter is then passed through the call chain to
usbd_spin_lock()andusbd_spin_unlock()to ensure proper synchronization.Changes
API Updates
src/device/dcd.h: Updated DCD function declarations to includebool is_isrparametersrc/device/usbd_pvt.h: Updated USBD wrapper function declarations to includebool is_isrparametersrc/device/usbd.c: Updated implementations to accept and pass through theis_isrparameterDCD Driver Updates
Updated all ~30 DCD driver implementations across multiple MCU families:
usbd_spin_lock()/usbd_spin_unlock()calls to use theis_isrparameter(void) is_isr;to suppress unused parameter warnings where appropriateClass Driver Updates
Updated all class drivers to pass the appropriate
is_isrvalue:false(task context)audiod_rx_xfer_isr()andaudiod_tx_xfer_isr()passtrue(ISR context)Test Updates
Validation
Example Usage
Fixes #3311
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.