avr-chat
[Top][All Lists]
Advanced

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

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


From: Joerg Wunsch
Subject: Re: [avr-chat] Any way to friend an interrupt handler?
Date: Wed, 20 Feb 2013 08:43:33 +0100 (MET)

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++;
}

Resulting assembly code:

..global __vector_20
        .type   __vector_20, @function
__vector_20:
        push __zero_reg__
        push r0
        in r0,__SREG__
        push r0
        clr __zero_reg__
..global __vector_20
        .type   __vector_20, @function
__vector_20:
        push __zero_reg__
        push r0
        in r0,__SREG__
        push r0
        clr __zero_reg__
        push r24
        push r25
/* prologue: Signal */
/* frame size = 0 */
/* stack size = 5 */
..L__stack_usage = 5
        lds r24,the_x
        lds r25,the_x+1
        adiw r24,1
        sts the_x+1,r25
        sts the_x,r24
/* epilogue start */
        pop r25
        pop r24
        pop r0
        out __SREG__,r0
        pop r0
        pop __zero_reg__
        reti
        .size   __vector_20, .-__vector_20


-- 
cheers, J"org               .-.-.   --... ...--   -.. .  DL8DTL

http://www.sax.de/~joerg/                        NIC: JW11-RIPE
Never trust an operating system you don't have sources for. ;-)



reply via email to

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