avr-gcc-list
[Top][All Lists]
Advanced

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

Re: [avr-gcc-list] Sharing interrupts


From: Erik Christiansen
Subject: Re: [avr-gcc-list] Sharing interrupts
Date: Tue, 9 Dec 2003 10:59:31 +1100
User-agent: Mutt/1.3.28i

On Mon, Dec 08, 2003 at 04:17:50PM -0500, Dave Hansen wrote:
> From: Pablo Bleyer Kocik <address@hidden>
> > I was wondering, is there an easy way to register two interrupt vectors 
> >with the same interrupt handler? The SIGNAL/INTERRUPT macros expand to a 
> >function declaration and function definition header, so it is not possible 
> >to assign function pointers with them.

...

> Another solution might be to write an assembly ISR to jump to the other 
> ISR. I'm less sure of how this would work, but something like
> 
>   // In a C file
>   SIGNAL(SIG_FOR_VECTOR_X)
>   {
>      // Do what you gotta do
>   }
> 
> 
>   ; in an assembly file
>   __vector_y:   rjmp __vector_x
> 

In the absence of a direct 'C' language method for pointing two vectors
to the same ISR, it can easily be done in assembler.

------------------------------------------------------------------------
   .global log_isr               ; Just like "external"

   .section .vectors,"ax",@progbits
   
; Interrupt Vector Table
   jmp  _start                   ; N.B. ATmega64 has 2 words/vector.
;   SIG_INTERRUPT0
   ldi   r16,0                   
   rjmp  v_error                 ; Look, they
;   SIG_INTERRUPT1
   ldi   r16,1
   rjmp  v_error                 ; all go to
;   SIG_INTERRUPT2
   ldi   r16,2
   rjmp  v_error                 ; the same ISR.
;   SIG_INTERRUPT3
                                 ; ldi optionally used to indicate
                                 ; which vector was followed.
   ...

;   SIG_UART0_TRANS
   jmp   log_isr                 ; This ISR is in another file.

   ...

_start:
------------------------------------------------------------------------

(In this example, v_error causes LEDs on a port to flash a number
indicating which unanticipated interrupt occurred. During debugging it
is sometimes the first indication of a wayward pointer, as it tramples
through the SFRs, enabling interrupts, amongst other forms of mayhem.)

Whether you use gcc, or avr-as directly, the resulting object file is
then linked like any other, and the job is done.

Erik


reply via email to

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