I wish there was a better way to interrupt handlers in classes, for
embedded.  For example I write a UART class as a driver which I
initialize by passing a pointer to hardware address.  However because
different UARTs use different interrupt vectors I end up having to have the
extern C and create each handler which then I have to register a callback
for the handler to call the correct method in class instance.

If you guys have a better way I would love to know.

Thanks
Trampas



On Sat, Apr 10, 2021 at 11:26 AM Jonathan Wakely <jwakely....@gmail.com>
wrote:

>
>
> On Sat, 10 Apr 2021, 15:07 Klaus Rudolph via Gcc-help, <
> gcc-h...@gcc.gnu.org> wrote:
>
>> Hi all,
>>
>> if I write a class with static member function I can use it as an
>> interrupt handler as follows:
>>
>> class Dummy
>> {
>>      static void Handler() __asm__("__vector_10")
>> __attribute__((__signal__, __used__, __externally_visible__));
>> };
>>
>> void Dummy::Handler()
>> {
>>
>> }
>>
>> I can see the vector is entered in the handler table:
>>
>>
>>
>>    1c:  0c 94 34 00     jmp     0x68    ; 0x68 <__bad_interrupt>
>>    20:  0c 94 34 00     jmp     0x68    ; 0x68 <__bad_interrupt>
>>    24:  0c 94 34 00     jmp     0x68    ; 0x68 <__bad_interrupt>
>>    28:  0c 94 36 00     jmp     0x6c    ; 0x6c <__vector_10>
>>    2c:  0c 94 34 00     jmp     0x68    ; 0x68 <__bad_interrupt>
>>    30:  0c 94 34 00     jmp     0x68    ; 0x68 <__bad_interrupt>
>>
>> ###################
>>
>> But if the class becomes a template, the function is not longer entered
>> in the handler. How can I fix it?
>>
>> template < int i >
>> class Dummy
>> {
>>      static void Handler() __asm__("__vector_10")
>> __attribute__((__signal__, __used__, __externally_visible__));
>> };
>>
>> template < int i>
>> void Dummy<i>::Handler()
>> {
>>
>> }
>>
>> Dummy<1> d1;
>>
>
> This doesn't cause the instantiation of the member function.
>
> Have you tried an explicit instantiation?
>
> template class Dummy<1>;
>
>
>
>

Reply via email to