This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Compiler/TMS320F28062: Using Interrupt routines as class methods

Part Number: TMS320F28062


Tool/software: TI C/C++ Compiler

Hello, 

ate the moment I am working on a really big project and to keep the programming as clean as possible I am using C++.

But now I am stuck at a point which is quite complicated (at least for me). I want the interrupt routines to be part of the class itself. I know that this won`t work with a simple function pointer to the method since the Object always passes the "this"pointer and the isr routines have no params. I could get it to work by declaring the functions as static but this would not hide the isr routine inside the class and I couldn`t use any kind of polymorphism.

I will try to explain what I would like to achieve.

Lets say I have a Base class called "Vehicle" and 2 subclasses "Car" and "Bike". Both of the subclasses need a isr routine called "break()" (I know "break" is a keyword, this is just an example) that is triggered when you hit the break (Like an external Pin interrupt) . Both subclasses must implement this function because breaking is mandotory. So I made the Base class abstract to force the subclasses to implement their own version of break.

The vehicle that is used is decided during runtime. So my code will instantiate the vehicle like this: "Vehicle myVehicle = new Car();    OR    Vehicle myVehicle = new Bike()"

With this the rest of my Code will be exactly the same since I could do something like: myVehicle.go() or myVehicle.turnOnTheLight(); and every object has its own implemented version of the functions.

Now the problem:

How can I made a class method interruptable? 

So I can write: PieVectTable.XINT1 = &myVehicle.break();

I already found this link 

http://processors.wiki.ti.com/index.php/Invoke_a_C%2B%2B_Class_Member_Function_from_an_Interrupt

but it just tells me how to call a member of a function inside a isr routine. I also found some design patterns for what I am trying to achieve but those are all for other MCU Families like Atmel etc. and I could not adapt them.

I hope someone have ever done this and could help me :)

Thanks

  • Olovskos said:

    How can I made a class method interruptable? 

    So I can write: PieVectTable.XINT1 = &myVehicle.break();

    That is not supported.  The problem you cannot avoid is that the function break expects an argument, the address of the member object it is invoked on.  This address is assigned to the "this" pointer.  But interrupt functions can take no arguments, and return no results.  

    Thanks and regards,

    -George