avr-libc-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[avr-libc-dev] C++ Interrupts


From: Ron Kreymborg
Subject: [avr-libc-dev] C++ Interrupts
Date: Sun, 20 Jan 2008 00:07:07 +1100

Joerg suggested Dean Camera (and perhaps others) on this list may be able to
help here. 

I would like to find some way to automatically include interrupt handlers as
private methods in C++ classes, a not uncommon wish as can be seen after
browsing various EC++ lists. The concept goes against the basic tenets of
the language which explains the difficulty. However gcc already has the
tools necessary to implement this manually with no additional overhead over
a C interrupt handler. 

The example class header:

class CTimer0
{
public:
    CTimer0();
    ~CTimer0();
private:
    void TIMER0_OVF_vect(void) __attribute__ ((signal, __INTR_ATTRS));
};

produces the message:

Timer0.h:16: warning: '_ZN7CTimer011__vector_16Ev' appears to be a
misspelled signal handler

This is the mangled name of the implementation of the above interrupt method
in the class definition file (cpp) as:

void CTimer0::TIMER0_OVF_vect(void)
{
    Flags |= TIMER0_OVERFLOW;   // indicate the event type
    TCNT0 = TIMER0_TIMEOUT;     // restart the timeout
}

Ie the whole "CTimer0::TIMER0_OVF_vect" name is mangled.

The application compiles successfully but naturally does not link the
handler. Adding the applicable ISR_ALIAS macro anywhere in the class
definition file using the mangled name provided by the above warning message
successfully links the correct handler and all is well, ie:

ISR_ALIAS(TIMER0_OVF_vect, _ZN7CTimer011__vector_16Ev);

This two stage edit process is not that much extra work, but it would be
nice to automate it. It would seem to require access to the compiler
mangling code and implemented in a macro that would look and be used
something like:

CLASS_ISR(CTimer0, TIMER0_OVF_vect)
{
    Flags |= TIMER0_OVERFLOW;   // indicate the event type
    TCNT0 = TIMER0_TIMEOUT;     // restart the timeout
}

It would expand to:

ISR_ALIAS(TIMER0_OVF_vect, _ZN7CTimer011__vector_16Ev);
void CTimer0::TIMER0_OVF_vect(void)
{
    Flags |= TIMER0_OVERFLOW;   // indicate the event type
    TCNT0 = TIMER0_TIMEOUT;     // restart the timeout
}

I have a simple but complete example application including the makefile I
can email to anyone interested. It is easily run in AVRStudio.

Ron Kreymborg







reply via email to

[Prev in Thread] Current Thread [Next in Thread]