[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [avr-gcc-list] Two interrupts one function?
From: |
Ned Konz |
Subject: |
Re: [avr-gcc-list] Two interrupts one function? |
Date: |
Sun, 14 May 2006 07:13:23 -0700 |
User-agent: |
Thunderbird 1.5.0.2 (Macintosh/20060308) |
Ned Konz wrote:
Trampas wrote:
I have two external interrupts connected to a quadature encoder, I do
the same operations when either interrupt pin is changed. I was
wondering if it was possible to have one ISR that is called from both
interrupts. If so how do I do it?
Seems like this would work (jump from the second handler to the first).
Look at the definition of ISR(), EMPTY_INTERRUPT(), and _VECTOR()
Here's a version with a macro called ALIAS_VECTOR() to hide much of the
ugliness:
/*
* Shows how to share a single ISR between two or more interrupts,
* using a "jmp" instruction to get from the secondary interrupt(s) to
the primary code.
avr-gcc -Os -mmcu=atmega128 -Wa,-ahlsd=twoisrs.lst -o twoisrs.elf
twoisrs.c
*/
#include <avr/io.h>
#include <avr/interrupt.h>
// Syntactic sugar:
#define ALIAS_VECTOR(fromName,toNum) \
void fromName(void) __attribute__ ((signal, naked)); \
void fromName(void) \
{ \
__asm__ __volatile__ ("jmp __vector_" #toNum ::); \
}
// defines __vector_1
ISR(INT0_vect)
{
// your code here
}
// defines __vector_2 (INT1_vect) to jump to __vector_1 (INT0_vect)
ALIAS_VECTOR(INT1_vect,1)
int main(void)
{
}
Thanks,
--
Ned Konz
address@hidden
http://bike-nomad.com