Skip to content

Commit 46a58fb

Browse files
authored
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.
1 parent 8deb6b9 commit 46a58fb

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

libraries/SPI/src/SPIHelper.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ class SPIHelper {
108108
@brief Disables any GPIO interrupts registered before an SPI transaction begins
109109
*/
110110
void maskInterrupts() {
111+
if (_usingIRQs.empty()) {
112+
return;
113+
}
111114
noInterrupts(); // Avoid possible race conditions if IRQ comes in while main app is in middle of this
112115
// Disable any IRQs that are being used for SPI
113116
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 @@ class SPIHelper {
134137
@brief Restores GPIO interrupts masks after an SPI transaction completes
135138
*/
136139
void unmaskInterrupts() {
140+
if (_usingIRQs.empty()) {
141+
return;
142+
}
137143
noInterrupts(); // Avoid race condition so the GPIO IRQs won't come back until all state is restored
138144
DEBUGSPI("SPI::endTransaction()\n");
139145
// Re-enable IRQs

0 commit comments

Comments
 (0)