I haven't write C++ code in a long while; however now I have to work on a texas instruments F28335 DSP and I am trying to migrate from C to C++. I have the following code that is trying to initialize an interrupt service routine with a static method of a class:
//type definition for the interrupt service routine
typedef interrupt void (*PINT)(void);
//EPWMManager.h
class EPWMManager
{
public:
EPWMManager();
static interrupt void Epwm1InterruptHandler(void);
};
//EPWMManager.cpp
interrupt void EPWMManager::Epwm1InterruptHandler(void)
{
//some code to be called on interruption
}
//main.cpp
int main(void)
{
PINT p;
p = &(EPWMManager::Epwm1InterruptHandler);
return 0;
}
When compiling I get the following:
error: a value of type "void (*)()" cannot be assigned to an entity of type "PINT"
I guess I'm missing some cast.
I think the fundamental problem is that ampersand prefixing the RHS of your assignment to p. Also, "PINT" is "pointer to integer" in other operating systems. So let's avoid any potential name conflicts. But I thinks this will work for you:
// you may have to move "interrupt" keyword to the left of the "void" declaration. Or just remove it.
typedef void (interrupt *FN_INTERRUPT_HANDLER)(void);
interrupt void EPWMManager::Epwm1InterruptHandler(void)
{
//some code to be called on interruption
}
int main(void)
{
FN_INTERRUPT_HANDLER p;
p = EPWMManager::Epwm1InterruptHandler; // no ampersand
// and if for whatever reason you wanted to invoke your function, you could just do this:
p(); // this will invoke your function.
return 0;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With