avr-libc-dev
[Top][All Lists]
Advanced

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

[avr-libc-dev] Re: C++ Interrupts


From: Dean Camera
Subject: [avr-libc-dev] Re: C++ Interrupts
Date: Sun, 20 Jan 2008 18:00:45 +1100

Followup:

No, doesn't work - you can't extern "C" a member function. You also can't alias 
a regular function to a non-mangled class function name, which was another line 
of thought for me. My solution:

        #define CLASS_ISR(vector, ...) { vector(); } ISR(vector, __VA_ARGS__)

That can be applied to any member function in the C file, of any name. Example:

Test.h:

        #include <avr/interrupt.h>

        class Test
        {
         public:
          Test();
          ~Test();
         private:
          void ADC_vect(void);
        };

Test.cpp:

        #include "Test.h"

        Test::Test(void)
        {
                 Test::ADC_vect();
        }

        Test::~Test(void)
        {

        }

        #define CLASS_ISR(vector, ...) { vector(); } ISR(vector, __VA_ARGS__)

        void Test::ADC_vect(void) CLASS_ISR(ADC_vect, ISR_BLOCK)
        {
                 PORTC = 0xFF;
        }


Which means you can name the function anything, and it should be accessible as 
a normal function, but also link in as an ISR. As I can't seem to get the 
intermixed assembly listing, I can't see how effective it is, but it should 
allow you to call the ISR by the member function name you give it, with either 
no penalty at all (if the optimizer inlines it) or a small penalty of a JUMP 
instruction.

Not elegant, but that's the best you can get I think without resorting to 
custom tools or compile scripts.

- Dean


reply via email to

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