2222#include <string.h>
2323
2424static voidFuncPtr ISRcallback [EXTERNAL_NUM_INTERRUPTS ];
25+ static void * ISRcallbackParams [EXTERNAL_NUM_INTERRUPTS ];
2526static uint32_t ISRlist [EXTERNAL_NUM_INTERRUPTS ];
2627static 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