Skip to content

Commit 06ce4a4

Browse files
Bitmask for IRQ stack, save ~112B RAM (#3148)
The ARM PRIMASK register only has 1 bit defined, so just save that bit and not the whole 32b returned by save_and_disable_irq(). Reduces memory usage by 120 bytes for all apps.
1 parent a96cd4a commit 06ce4a4

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

cores/rp2040/wiring_private.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,12 @@
3030
#define maxIRQs 15
3131
#endif
3232
static uint32_t _irqStackTop[2] = { 0, 0 };
33+
#ifdef __riscv
3334
static uint32_t _irqStack[2][maxIRQs];
35+
#else
36+
// ARM there's only 1 bit valid, so we'll just shift it in and out...
37+
static uint32_t _irqStack[2];
38+
#endif
3439

3540
#ifdef __FREERTOS
3641
static UBaseType_t __savedIrqs[configNUMBER_OF_CORES];
@@ -52,7 +57,13 @@ extern "C" void interrupts() {
5257
// ERROR
5358
return;
5459
}
60+
#ifdef __riscv
5561
restore_interrupts(_irqStack[core][--_irqStackTop[core]]);
62+
#else
63+
uint32_t mask = _irqStack[core] & 1;
64+
_irqStack[core] >>= 1;
65+
restore_interrupts(mask);
66+
#endif
5667
}
5768

5869
extern "C" void noInterrupts() {
@@ -71,7 +82,13 @@ extern "C" void noInterrupts() {
7182
// ERROR
7283
panic("IRQ stack overflow");
7384
}
85+
#ifdef __riscv
7486
_irqStack[core][_irqStackTop[core]++] = save_and_disable_interrupts();
87+
#else
88+
_irqStack[core] <<= 1;
89+
_irqStack[core] |= save_and_disable_interrupts() ? 1 : 0;
90+
_irqStackTop[core]++;
91+
#endif
7592
}
7693

7794
auto_init_mutex(_irqMutex);

0 commit comments

Comments
 (0)