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: Markus Lampert
Subject: Re: [avr-libc-dev] C++ Interrupts
Date: Sat, 19 Jan 2008 13:49:14 -0800 (PST)

Hey Ron,

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. 

The only way to do it properly would have a class member function as an
interrupt handler and from there call into the approriate instance (which
you'll have to to store in a singleton pattern or similar).

But once you do that you can use a "regular" interrupt handler and access the
singlton from there.

Anyway, encapsulating this into a macro or avr-libc library function would
probably prove difficult because access to singletons isn't standardized. The
macro would need the class name, the member function and a functor (of sorts)
to get the (singleton) object.

Have fun,
Markus


--- Ron Kreymborg <address@hidden> wrote:

> 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
> 
> 
> 
> 
> 
> _______________________________________________
> AVR-libc-dev mailing list
> address@hidden
> http://lists.nongnu.org/mailman/listinfo/avr-libc-dev
> 



      
____________________________________________________________________________________
Looking for last minute shopping deals?  
Find them fast with Yahoo! Search.  
http://tools.search.yahoo.com/newsearch/category.php?category=shopping




reply via email to

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