Skip to content

Commit 812d3e9

Browse files
committed
Put interrupt mask instead of interrupt num in ISR callbacks list
This should save some cycles inside ISR Handler.
1 parent 9d9fe5c commit 812d3e9

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

cores/arduino/WInterrupts.c

+14-12
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121

2222
#include <string.h>
2323

24-
static voidFuncPtr ISRcallback[EXTERNAL_NUM_INTERRUPTS];
25-
static EExt_Interrupts ISRlist[EXTERNAL_NUM_INTERRUPTS];
26-
static uint32_t nints; // Stores total number of attached interrupts
24+
static voidFuncPtr ISRcallback[EXTERNAL_NUM_INTERRUPTS];
25+
static uint32_t ISRlist[EXTERNAL_NUM_INTERRUPTS];
26+
static uint32_t nints; // Stores total number of attached interrupts
2727

2828

2929
/* Configure I/O interrupt sources */
@@ -76,7 +76,8 @@ void attachInterrupt(uint32_t pin, voidFuncPtr callback, uint32_t mode)
7676
}
7777

7878
// Enable wakeup capability on pin in case being used during sleep
79-
EIC->WAKEUP.reg |= (1 << in);
79+
uint32_t inMask = 1 << in;
80+
EIC->WAKEUP.reg |= inMask;
8081

8182
// Assign pin to EIC
8283
pinPeripheral(pin, PIO_EXTINT);
@@ -92,15 +93,15 @@ void attachInterrupt(uint32_t pin, voidFuncPtr callback, uint32_t mode)
9293

9394
// Check if we already have this interrupt
9495
for (current=0; current<nints; current++) {
95-
if (ISRlist[current] == in) {
96+
if (ISRlist[current] == inMask) {
9697
break;
9798
}
9899
}
99100
if (current == nints) {
100101
// Need to make a new entry
101102
nints++;
102103
}
103-
ISRlist[current] = in; // List of interrupt in order of when they were attached
104+
ISRlist[current] = inMask; // List of interrupt in order of when they were attached
104105
ISRcallback[current] = callback; // List of callback adresses
105106

106107
// Look for right CONFIG register to be addressed
@@ -138,7 +139,7 @@ void attachInterrupt(uint32_t pin, voidFuncPtr callback, uint32_t mode)
138139
}
139140
}
140141
// Enable the interrupt
141-
EIC->INTENSET.reg = EIC_INTENSET_EXTINT(1 << in);
142+
EIC->INTENSET.reg = EIC_INTENSET_EXTINT(inMask);
142143
}
143144

144145
/*
@@ -154,15 +155,16 @@ void detachInterrupt(uint32_t pin)
154155
if (in == NOT_AN_INTERRUPT || in == EXTERNAL_INT_NMI)
155156
return;
156157

157-
EIC->INTENCLR.reg = EIC_INTENCLR_EXTINT(1 << in);
158+
uint32_t inMask = 1 << in;
159+
EIC->INTENCLR.reg = EIC_INTENCLR_EXTINT(inMask);
158160

159161
// Disable wakeup capability on pin during sleep
160-
EIC->WAKEUP.reg &= ~(1 << in);
162+
EIC->WAKEUP.reg &= ~inMask;
161163

162164
// Remove callback from the ISR list
163165
uint32_t current;
164166
for (current=0; current<nints; current++) {
165-
if (ISRlist[current] == in) {
167+
if (ISRlist[current] == inMask) {
166168
break;
167169
}
168170
}
@@ -187,12 +189,12 @@ void EIC_Handler(void)
187189
// Loop over all enabled interrupts in the list
188190
for (uint32_t i=0; i<nints; i++)
189191
{
190-
if ((EIC->INTFLAG.reg & 1<<ISRlist[i]) != 0)
192+
if ((EIC->INTFLAG.reg & ISRlist[i]) != 0)
191193
{
192194
// Call the callback function
193195
ISRcallback[i]();
194196
// Clear the interrupt
195-
EIC->INTFLAG.reg = 1<<ISRlist[i];
197+
EIC->INTFLAG.reg = ISRlist[i];
196198
}
197199
}
198200
}

0 commit comments

Comments
 (0)