Skip to content

Commit 9a67d2d

Browse files
committed
implement attachInterruptParam
1 parent 5ae2f68 commit 9a67d2d

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

Diff for: cores/arduino/WInterrupts.c

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

2222
#include <string.h>
2323

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
24+
static voidFuncPtrParam ISRcallback[EXTERNAL_NUM_INTERRUPTS];
25+
static void* ISRcallbackParams[EXTERNAL_NUM_INTERRUPTS];
26+
static uint32_t ISRlist[EXTERNAL_NUM_INTERRUPTS];
27+
static uint32_t nints; // Stores total number of attached interrupts
2728

2829
/* Configure I/O interrupt sources */
2930
static void __initialize()
@@ -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, voidFuncPtrParam callback, PinStatus mode, void* params)
5960
{
6061
static int enabled = 0;
6162
uint32_t config;
@@ -100,8 +101,9 @@ void attachInterrupt(pin_size_t pin, voidFuncPtr callback, PinStatus mode)
100101
// Need to make a new entry
101102
nints++;
102103
}
103-
ISRlist[current] = inMask; // List of interrupt in order of when they were attached
104-
ISRcallback[current] = callback; // List of callback adresses
104+
ISRlist[current] = inMask; // List of interrupt in order of when they were attached
105+
ISRcallback[current] = callback; // List of callback adresses
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
*/
@@ -171,8 +182,9 @@ void detachInterrupt(pin_size_t pin)
171182

172183
// Shift the reminder down
173184
for (; current<nints-1; current++) {
174-
ISRlist[current] = ISRlist[current+1];
175-
ISRcallback[current] = ISRcallback[current+1];
185+
ISRlist[current] = ISRlist[current+1];
186+
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)