Skip to content

Commit 40f9573

Browse files
committed
feat(ISR): implement attachInterruptParam
1 parent 993398c commit 40f9573

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

.github/workflows/compile-examples.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ jobs:
264264
github-token: ${{ secrets.GITHUB_TOKEN }}
265265

266266
- name: Save memory usage change report as artifact
267-
uses: actions/upload-artifact@v1
267+
uses: actions/upload-artifact@v5
268268
with:
269269
name: sketches-reports
270270
path: sketches-reports

cores/arduino/WInterrupts.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <string.h>
2323

2424
static voidFuncPtr ISRcallback[EXTERNAL_NUM_INTERRUPTS];
25+
static void* ISRcallbackParams[EXTERNAL_NUM_INTERRUPTS];
2526
static uint32_t ISRlist[EXTERNAL_NUM_INTERRUPTS];
2627
static uint32_t nints; // Stores total number of attached interrupts
2728

@@ -55,7 +56,7 @@ static void __initialize()
5556
* \brief Specifies a named Interrupt Service Routine (ISR) to call when an interrupt occurs.
5657
* Replaces any previous function that was attached to the interrupt.
5758
*/
58-
void attachInterrupt(pin_size_t pin, voidFuncPtr callback, PinStatus mode)
59+
void attachInterruptParam(pin_size_t pin, voidFuncPtr callback, PinStatus mode, void* params)
5960
{
6061
static int enabled = 0;
6162
uint32_t config;
@@ -101,7 +102,8 @@ void attachInterrupt(pin_size_t pin, voidFuncPtr callback, PinStatus mode)
101102
nints++;
102103
}
103104
ISRlist[current] = inMask; // List of interrupt in order of when they were attached
104-
ISRcallback[current] = callback; // List of callback adresses
105+
ISRcallback[current] = callback; // List of callback
106+
ISRcallbackParams[current] = params; // List of arguments to send to the callbacks
105107

106108
// Look for right CONFIG register to be addressed
107109
if (in > EXTERNAL_INT_7) {
@@ -141,6 +143,15 @@ void attachInterrupt(pin_size_t pin, voidFuncPtr callback, PinStatus mode)
141143
EIC->INTENSET.reg = EIC_INTENSET_EXTINT(inMask);
142144
}
143145

146+
/*
147+
* \brief Specifies a named Interrupt Service Routine (ISR) to call when an interrupt occurs.
148+
* Replaces any previous function that was attached to the interrupt.
149+
*/
150+
void attachInterrupt(uint8_t pin, voidFuncPtr callback, PinStatus mode)
151+
{
152+
attachInterruptParam(pin, (voidFuncPtrParam)callback, mode, NULL);
153+
}
154+
144155
/*
145156
* \brief Turns off the given interrupt.
146157
*/
@@ -173,6 +184,7 @@ void detachInterrupt(pin_size_t pin)
173184
for (; current<nints-1; current++) {
174185
ISRlist[current] = ISRlist[current+1];
175186
ISRcallback[current] = ISRcallback[current+1];
187+
ISRcallbackParams[current] = ISRcallbackParams[current+1];
176188
}
177189
nints--;
178190
}
@@ -191,7 +203,7 @@ void EIC_Handler(void)
191203
if ((EIC->INTFLAG.reg & ISRlist[i]) != 0)
192204
{
193205
// Call the callback function
194-
ISRcallback[i]();
206+
ISRcallback[i](ISRcallbackParams[i]);
195207
// Clear the interrupt
196208
EIC->INTFLAG.reg = ISRlist[i];
197209
}

0 commit comments

Comments
 (0)