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

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

RE: [avr-libc-dev] C++ Interrupts


From: Ron Kreymborg
Subject: RE: [avr-libc-dev] C++ Interrupts
Date: Sun, 20 Jan 2008 15:50:04 +1100

> I don't think this will work because the this pointer isn't setup. If
> you try
> to access any member variables of your interrupt class you'll end up in
> neverwhere.

Thanks Marcus, but the trick is in the attributes. The definition of the
interrupt method:

void TIMER0_OVF_vect(void) __attribute__ ((signal, __INTR_ATTRS));

becomes:

void __vector_16(void) __attribute__ ((signal, used, externally_visible));

and the macros change the implementation to look like:

extern "C" void __vector_16(void)
__attribute__((alias("_ZN7CTimer011__vector_16Ev")));
void CTimer0::__vector_16(void)
{
   ...

So you see the rules of C++ play no part at all in linking the 16th
interrupt vector to the address of the class interrupt method, but they do
ensure it is private from other C++ code.

Interestingly, I have developed the following macros and they come pretty
close to what I am after. It looks like avr-gcc (or this version) always
mangles the same way, so DO_MANGLE builds the mangled name and CLASS_ISR
puts the method together.

#define DO_MANGLE(theclass, thename, L1, L2) \
   _ZN ## L1 ## theclass ## L2 ## thename ## Ev

#define CLASS_ISR(theclass, L1, intname, L2) \
    ISR_ALIAS(intname, DO_MANGLE(theclass, intname, L1, L2)); \
    void theclass::intname(void)

where L1 is the length of the class name and L2 the length of the vector
name (__vector_2, __vector_16, etc). For the example CTimer0 class and a
Timer0 overflow interrupt, the use below correctly produces the definition
shown above.

CLASS_ISR(CTimer0, 7, TIMER0_OVF_vect, 11)
{

Having to define the lengths means I am still far from automatic however.

Ron Kreymborg








reply via email to

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