Address of member function for Interrupt handler

19 Jan 2010

For an ADC driver, I would like to define a member function as an interrupt handler. This is what I have tried so far...

 

        typedef void (ADC::*IntHandlerType)(void);
        IntHandlerType pointer = &ADC::_ADC_IRQHandler;


        NVIC_SetVector(ADC_IRQn, (uint32_t)pointer);

However I'm getting an "Invalid Type Conversion (E171)" trying to typecast it to a uint32_t.

 

19 Jan 2010

You can's use a non-static class method as a raw interrupt handler. Use either a static function or a plain function, and then call the member from it (e.g. using class instance from a global variable).

19 Jan 2010

OK thanks, I'll try that.

19 Jan 2010

I was looking at UsbMouse in the cookbook, and found example code there. Take a look at the files:

http://mbed.org/projects/cookbook/svn/USBMouse/trunk/usbdc.cpp
http://mbed.org/projects/cookbook/svn/USBMouse/trunk/usbdc.h

specifically, variable "instance" and _usbisr() function.

Note that NVIC_SetVector() replaces NVIC_Vector() function that does not exist anymore, as well as #include "nvic_api.h".

21 Jan 2010

Thanks Ilya! I have it working now.