Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
9 years, 6 months ago.
obtaining member function's pointer
I'm trying to set a function, MyFunc() within one class as a interrupt service routine of RTC. The reference says that the following description using & operator should be used, however the compiler reports the error of incompatible type (2nd arg of NVIC_SetVector is uint32_t type).
void MyClass::MyFunc(){...}
void MyClass::OtherFunc(){ NVIC_SetVector(RTC_IRQn, &MyClass::MyFunc);
With casting to uint32_t as follows, the compiler returns the error of invalid type conversion.
NVIC_SetVector(RTC_IRQn, (unint32_t)&MyClass::MyFunc);
How can I set the member function in SetVector?
2 Answers
9 years, 6 months ago.
Additional to Erik's answer, there are articles explaining why regular c++ class method can't be used directly, for example http://www.drdobbs.com/implementing-interrupt-service-routines/184401485
9 years, 6 months ago.
You cannot. You will need to have a static function or regular C function as interrupt vector, then that function can call the real interrupt. You can find an example here: https://developer.mbed.org/users/BaderP/code/SimpleDMA/file/e9ab0bb912c8/SimpleDMA_KL25.cpp. (You also need to get the .h file for it, note that irq_handler1-4 are static functions, so they do not belong to any class object, but are always there).