[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[avr-chat] C++ Interrupts
From: |
Ron Kreymborg |
Subject: |
[avr-chat] C++ Interrupts |
Date: |
Thu, 17 Jan 2008 12:42:00 +1100 |
Hi Folks
In the past I have handled peripheral interrupts by a simple vector into a
class public method:
ISR(TIMER0_OVF_vect)
{
Timer0.OverflowInterrupt();
}
However, IMHO a more elegant C++ solution would be to define the interrupt
handler as a private function within the class. The listing below shows an
example. My problem is finding a way to have the compiler provide the link
from the interrupt table. The example works and can be tested by loading the
elf into AVRStudio, switch to the disassemble view to locate the
OverflowInterrupt entry point, and edit the program memory address for the
TIMER0 overflow interrupt.
Hardly practical, so can anyone suggest a declaration that would make this
link automatic within avr-gcc?
Regards, Ron
-----------------------
#include "Types.h"
#define TIMER0_OVERFLOW 0x01
#define TIMER0_TIMEOUT 100
volatile int Flags;
class cTimer0
{
public:
//---------------------------------------------------------------
cTimer0()
{
TCNT0 = TIMER0_TIMEOUT;
TCCR0 = 0x06;
TIMSK |= (1<<TOIE0); // enable Timer0 timeout interrupt
Flags &= ~TIMER0_OVERFLOW;
}
//---------------------------------------------------------------
~cTimer0()
{
TIMSK &= ~(1<<TOIE0); // disable Timer0 timeout interrupt
}
private:
//---------------------------------------------------------------
void OverflowInterrupt(void) __attribute__ ((signal, __INTR_ATTRS))
{
Flags |= TIMER0_OVERFLOW; // indicate the event type
TCNT0 = TIMER0_TIMEOUT; // restart the timeout
}
};
//--------------------------------------------------------------------------
---
//
int main(void)
{
cTimer0 Timer0;
sei(); // hello world
while (TRUE)
{
if (Flags & TIMER0_OVERFLOW)
{
Flags &= ~TIMER0_OVERFLOW;
// Action the event here...
}
.
.
.
}
return 0;
}
- [avr-chat] C++ Interrupts,
Ron Kreymborg <=