I'd like to be able to write my ISR in one place:
some_collection TimerHandlers;
// added to ISR table in linker script
void rawTimerIRQHandler() {
call_each_handler_in(handlers);
}
Such that I can then register handlers in other files
// file1.cpp
void ledTimerHandler1() {
}
register(ledTimerHandler1); //or in an init function if not possible here
// file2.cpp
void ledTimerHandler2() {
}
register(ledTimerHandler2); //or in an init function if not possible here
And when the hardware jumps to rawTimerIRQHandler
, it executes ledTimerHandler1
and ledTimerHandler2
in some arbitrary order.
Obviously, I can implement this using something similar to a vector<void(*)()>
, but since the number of these handlers is known at compile-time, is there any way I can generate an array (or template linked list) at compile-time? I'd like to avoid the dynamic memory allocation that comes with vector
.
I'm open to using template<>
, #define
, or even GCC-specific attributes to acheive this goal.