I'm writing a template class that uses interrupts. For every specialization, I have to make sure that the ISR name matches the template arguments. That's tedious and error-prone.
I'm not trying to change the way teensyduino works, but would it be theoretically possible to create an interrupt handler table with specialized template functions? The "classic" C table looks like this:
Instead, we could move the whole table out of the "extern C" declaration and use a template function:
And specialize ISRs in headers:
That would facilitate e.g. passing a DMA channel as a template parameter to a driver class, which then specializes the handler for this DMA channel interrupt. I'm just not sure if it *can* work, that's why I didn't try yet. Any thoughts on this?
Regards
Christoph
I'm not trying to change the way teensyduino works, but would it be theoretically possible to create an interrupt handler table with specialized template functions? The "classic" C table looks like this:
Code:
__attribute__ ((section(".vectors"), used))
void (* const gVectors[])(void) =
{
(void (*)(void))((unsigned long)&_estack), // 0 ARM: Initial Stack Pointer
ResetHandler, // 1 ARM: Initial Program Counter
nmi_isr,
...
Instead, we could move the whole table out of the "extern C" declaration and use a template function:
Code:
template<typename T>
void handler(void)
{
... // what the "unused_isr" handler does
}
void (* const gVectors[])(void) =
{
(void (*)(void))((unsigned long)&_estack), // 0 ARM: Initial Stack Pointer
Handler<Reset>, // 1 ARM: Initial Program Counter
Handler<Nmi>,
...
And specialize ISRs in headers:
Code:
template<>
void Handler<Dma::Channel<3> > (void)
{
...
}
That would facilitate e.g. passing a DMA channel as a template parameter to a driver class, which then specializes the handler for this DMA channel interrupt. I'm just not sure if it *can* work, that's why I didn't try yet. Any thoughts on this?
Regards
Christoph