Early out of (un)maskInterrupts() if no GPIO interrupts need to be masked (#2831)

My application is designed to generate HSTX data on core0 in interrupts,
but also uses hardware SPI for SD card access.

It turns out that the amount of time spent in maskInterrupts/
unmaskInterrupts, even with an empty _usingIRQs, is too long.

Add a quick check and avoid touching the interrupt disable flag if
there's not actually any GPIO interrupt to (un)mask.
This commit is contained in:
Jeff Epler 2025-02-28 14:44:47 -06:00 committed by GitHub
parent 8deb6b9724
commit 46a58fb4b5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -108,6 +108,9 @@ public:
@brief Disables any GPIO interrupts registered before an SPI transaction begins @brief Disables any GPIO interrupts registered before an SPI transaction begins
*/ */
void maskInterrupts() { void maskInterrupts() {
if (_usingIRQs.empty()) {
return;
}
noInterrupts(); // Avoid possible race conditions if IRQ comes in while main app is in middle of this noInterrupts(); // Avoid possible race conditions if IRQ comes in while main app is in middle of this
// Disable any IRQs that are being used for SPI // Disable any IRQs that are being used for SPI
io_bank0_irq_ctrl_hw_t *irq_ctrl_base = get_core_num() ? &iobank0_hw->proc1_irq_ctrl : &iobank0_hw->proc0_irq_ctrl; io_bank0_irq_ctrl_hw_t *irq_ctrl_base = get_core_num() ? &iobank0_hw->proc1_irq_ctrl : &iobank0_hw->proc0_irq_ctrl;
@ -134,6 +137,9 @@ public:
@brief Restores GPIO interrupts masks after an SPI transaction completes @brief Restores GPIO interrupts masks after an SPI transaction completes
*/ */
void unmaskInterrupts() { void unmaskInterrupts() {
if (_usingIRQs.empty()) {
return;
}
noInterrupts(); // Avoid race condition so the GPIO IRQs won't come back until all state is restored noInterrupts(); // Avoid race condition so the GPIO IRQs won't come back until all state is restored
DEBUGSPI("SPI::endTransaction()\n"); DEBUGSPI("SPI::endTransaction()\n");
// Re-enable IRQs // Re-enable IRQs