21
21
22
22
#include <string.h>
23
23
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
27
28
28
29
/* Configure I/O interrupt sources */
29
30
static void __initialize ()
@@ -55,7 +56,7 @@ static void __initialize()
55
56
* \brief Specifies a named Interrupt Service Routine (ISR) to call when an interrupt occurs.
56
57
* Replaces any previous function that was attached to the interrupt.
57
58
*/
58
- void attachInterrupt (pin_size_t pin , voidFuncPtr callback , PinStatus mode )
59
+ void attachInterruptParam (pin_size_t pin , voidFuncPtrParam callback , PinStatus mode , void * params )
59
60
{
60
61
static int enabled = 0 ;
61
62
uint32_t config ;
@@ -100,8 +101,9 @@ void attachInterrupt(pin_size_t pin, voidFuncPtr callback, PinStatus mode)
100
101
// Need to make a new entry
101
102
nints ++ ;
102
103
}
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
105
107
106
108
// Look for right CONFIG register to be addressed
107
109
if (in > EXTERNAL_INT_7 ) {
@@ -141,6 +143,15 @@ void attachInterrupt(pin_size_t pin, voidFuncPtr callback, PinStatus mode)
141
143
EIC -> INTENSET .reg = EIC_INTENSET_EXTINT (inMask );
142
144
}
143
145
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
+
144
155
/*
145
156
* \brief Turns off the given interrupt.
146
157
*/
@@ -171,8 +182,9 @@ void detachInterrupt(pin_size_t pin)
171
182
172
183
// Shift the reminder down
173
184
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 ];
176
188
}
177
189
nints -- ;
178
190
}
@@ -191,7 +203,7 @@ void EIC_Handler(void)
191
203
if ((EIC -> INTFLAG .reg & ISRlist [i ]) != 0 )
192
204
{
193
205
// Call the callback function
194
- ISRcallback [i ]();
206
+ ISRcallback [i ](ISRcallbackParams [ i ] );
195
207
// Clear the interrupt
196
208
EIC -> INTFLAG .reg = ISRlist [i ];
197
209
}
0 commit comments