21
21
22
22
#include <string.h>
23
23
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
27
27
28
28
29
29
/* Configure I/O interrupt sources */
@@ -76,7 +76,8 @@ void attachInterrupt(uint32_t pin, voidFuncPtr callback, uint32_t mode)
76
76
}
77
77
78
78
// 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 ;
80
81
81
82
// Assign pin to EIC
82
83
pinPeripheral (pin , PIO_EXTINT );
@@ -92,15 +93,15 @@ void attachInterrupt(uint32_t pin, voidFuncPtr callback, uint32_t mode)
92
93
93
94
// Check if we already have this interrupt
94
95
for (current = 0 ; current < nints ; current ++ ) {
95
- if (ISRlist [current ] == in ) {
96
+ if (ISRlist [current ] == inMask ) {
96
97
break ;
97
98
}
98
99
}
99
100
if (current == nints ) {
100
101
// Need to make a new entry
101
102
nints ++ ;
102
103
}
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
104
105
ISRcallback [current ] = callback ; // List of callback adresses
105
106
106
107
// Look for right CONFIG register to be addressed
@@ -138,7 +139,7 @@ void attachInterrupt(uint32_t pin, voidFuncPtr callback, uint32_t mode)
138
139
}
139
140
}
140
141
// Enable the interrupt
141
- EIC -> INTENSET .reg = EIC_INTENSET_EXTINT (1 << in );
142
+ EIC -> INTENSET .reg = EIC_INTENSET_EXTINT (inMask );
142
143
}
143
144
144
145
/*
@@ -154,15 +155,16 @@ void detachInterrupt(uint32_t pin)
154
155
if (in == NOT_AN_INTERRUPT || in == EXTERNAL_INT_NMI )
155
156
return ;
156
157
157
- EIC -> INTENCLR .reg = EIC_INTENCLR_EXTINT (1 << in );
158
+ uint32_t inMask = 1 << in ;
159
+ EIC -> INTENCLR .reg = EIC_INTENCLR_EXTINT (inMask );
158
160
159
161
// Disable wakeup capability on pin during sleep
160
- EIC -> WAKEUP .reg &= ~( 1 << in ) ;
162
+ EIC -> WAKEUP .reg &= ~inMask ;
161
163
162
164
// Remove callback from the ISR list
163
165
uint32_t current ;
164
166
for (current = 0 ; current < nints ; current ++ ) {
165
- if (ISRlist [current ] == in ) {
167
+ if (ISRlist [current ] == inMask ) {
166
168
break ;
167
169
}
168
170
}
@@ -187,12 +189,12 @@ void EIC_Handler(void)
187
189
// Loop over all enabled interrupts in the list
188
190
for (uint32_t i = 0 ; i < nints ; i ++ )
189
191
{
190
- if ((EIC -> INTFLAG .reg & 1 << ISRlist [i ]) != 0 )
192
+ if ((EIC -> INTFLAG .reg & ISRlist [i ]) != 0 )
191
193
{
192
194
// Call the callback function
193
195
ISRcallback [i ]();
194
196
// Clear the interrupt
195
- EIC -> INTFLAG .reg = 1 << ISRlist [i ];
197
+ EIC -> INTFLAG .reg = ISRlist [i ];
196
198
}
197
199
}
198
200
}
0 commit comments