Skip to content

Commit 8c440df

Browse files
xxxajkcmaglie
authored andcommitted
AVR: Faster Interrupts, no size change.
Fixes #2408
1 parent d6ea1c0 commit 8c440df

File tree

1 file changed

+37
-23
lines changed

1 file changed

+37
-23
lines changed

Diff for: hardware/arduino/avr/cores/arduino/WInterrupts.c

+37-23
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,37 @@
3232

3333
#include "wiring_private.h"
3434

35-
static volatile voidFuncPtr intFunc[EXTERNAL_NUM_INTERRUPTS];
35+
static void nothing(void) {
36+
}
37+
38+
static volatile voidFuncPtr intFunc[EXTERNAL_NUM_INTERRUPTS] = {
39+
#if EXTERNAL_NUM_INTERRUPTS > 8
40+
#warning There are more than 8 external interrupts. Some callbacks may not be initialized.
41+
nothing,
42+
#endif
43+
#if EXTERNAL_NUM_INTERRUPTS > 7
44+
nothing,
45+
#endif
46+
#if EXTERNAL_NUM_INTERRUPTS > 6
47+
nothing,
48+
#endif
49+
#if EXTERNAL_NUM_INTERRUPTS > 5
50+
nothing,
51+
#endif
52+
#if EXTERNAL_NUM_INTERRUPTS > 4
53+
nothing,
54+
#endif
55+
#if EXTERNAL_NUM_INTERRUPTS > 3
56+
nothing,
57+
#endif
58+
#if EXTERNAL_NUM_INTERRUPTS > 2
59+
nothing,
60+
#endif
61+
#if EXTERNAL_NUM_INTERRUPTS > 1
62+
nothing,
63+
#endif
64+
nothing
65+
};
3666
// volatile static voidFuncPtr twiIntFunc;
3767

3868
void attachInterrupt(uint8_t interruptNum, void (*userFunc)(void), int mode) {
@@ -238,7 +268,7 @@ void detachInterrupt(uint8_t interruptNum) {
238268
#endif
239269
}
240270

241-
intFunc[interruptNum] = 0;
271+
intFunc[interruptNum] = nothing;
242272
}
243273
}
244274

@@ -250,87 +280,71 @@ void attachInterruptTwi(void (*userFunc)(void) ) {
250280

251281
#if defined(__AVR_ATmega32U4__)
252282
ISR(INT0_vect) {
253-
if(intFunc[EXTERNAL_INT_0])
254-
intFunc[EXTERNAL_INT_0]();
283+
intFunc[EXTERNAL_INT_0]();
255284
}
256285

257286
ISR(INT1_vect) {
258-
if(intFunc[EXTERNAL_INT_1])
259-
intFunc[EXTERNAL_INT_1]();
287+
intFunc[EXTERNAL_INT_1]();
260288
}
261289

262290
ISR(INT2_vect) {
263-
if(intFunc[EXTERNAL_INT_2])
264-
intFunc[EXTERNAL_INT_2]();
291+
intFunc[EXTERNAL_INT_2]();
265292
}
266293

267294
ISR(INT3_vect) {
268-
if(intFunc[EXTERNAL_INT_3])
269-
intFunc[EXTERNAL_INT_3]();
295+
intFunc[EXTERNAL_INT_3]();
270296
}
271297

272298
ISR(INT6_vect) {
273-
if(intFunc[EXTERNAL_INT_4])
274-
intFunc[EXTERNAL_INT_4]();
299+
intFunc[EXTERNAL_INT_4]();
275300
}
276301

277302
#elif defined(EICRA) && defined(EICRB)
278303

279304
ISR(INT0_vect) {
280-
if(intFunc[EXTERNAL_INT_2])
281305
intFunc[EXTERNAL_INT_2]();
282306
}
283307

284308
ISR(INT1_vect) {
285-
if(intFunc[EXTERNAL_INT_3])
286309
intFunc[EXTERNAL_INT_3]();
287310
}
288311

289312
ISR(INT2_vect) {
290-
if(intFunc[EXTERNAL_INT_4])
291313
intFunc[EXTERNAL_INT_4]();
292314
}
293315

294316
ISR(INT3_vect) {
295-
if(intFunc[EXTERNAL_INT_5])
296317
intFunc[EXTERNAL_INT_5]();
297318
}
298319

299320
ISR(INT4_vect) {
300-
if(intFunc[EXTERNAL_INT_0])
301321
intFunc[EXTERNAL_INT_0]();
302322
}
303323

304324
ISR(INT5_vect) {
305-
if(intFunc[EXTERNAL_INT_1])
306325
intFunc[EXTERNAL_INT_1]();
307326
}
308327

309328
ISR(INT6_vect) {
310-
if(intFunc[EXTERNAL_INT_6])
311329
intFunc[EXTERNAL_INT_6]();
312330
}
313331

314332
ISR(INT7_vect) {
315-
if(intFunc[EXTERNAL_INT_7])
316333
intFunc[EXTERNAL_INT_7]();
317334
}
318335

319336
#else
320337

321338
ISR(INT0_vect) {
322-
if(intFunc[EXTERNAL_INT_0])
323339
intFunc[EXTERNAL_INT_0]();
324340
}
325341

326342
ISR(INT1_vect) {
327-
if(intFunc[EXTERNAL_INT_1])
328343
intFunc[EXTERNAL_INT_1]();
329344
}
330345

331346
#if defined(EICRA) && defined(ISC20)
332347
ISR(INT2_vect) {
333-
if(intFunc[EXTERNAL_INT_2])
334348
intFunc[EXTERNAL_INT_2]();
335349
}
336350
#endif

0 commit comments

Comments
 (0)