[Top][All Lists]

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

Re: [avr-chat] Any way to friend an interrupt handler?

From: David Brown
Subject: Re: [avr-chat] Any way to friend an interrupt handler?
Date: Wed, 20 Feb 2013 11:08:15 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130110 Thunderbird/17.0.2

On 20/02/13 08:43, Joerg Wunsch wrote:
> Rick Mann <address@hidden> wrote:
>> I'm trying to allow my timer overflow interrupt handler access to
>> private static members of a C++ class, with this:
>>     friend    ::TIMER1_OVF_vect();
> You have to explicitly declare the vector since you need a (forward)
> declaration before you can define it.  There's no avr-libc macro to
> declare an ISR only without defining it.  Manual declaration works:
> #include <avr/io.h>
> #include <avr/interrupt.h>
> extern "C" void TIMER1_OVF_vect(void) __attribute__((signal));
> class x {
>         friend void ::TIMER1_OVF_vect(void);
> private:
>         int i;
> };
> class x the_x;
> ISR(TIMER1_OVF_vect)
> {
>   the_x.i++;
> }

Another option that might be usable (depending on how things are split
within different modules) is to make the ISR just a wrapper for the
"real" code:

class x {
        friend void ::timerInterrupt(void);
private :
        int i;

class x the_x;

static void timerInterrupt(void) {

ISR(TIMER1_OVF_vect) {

With non-negligible optimisations enabled, the static timerInterrupt
function will be inlined within the ISR function, so there is no extra
overhead.  (Normally there can be significant overhead if an interrupt
function calls an external function.)

Just a thought for another style.

reply via email to

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