- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Dear all,
I develop my project with C++ language. But I encounter a problem: how to register a ISR? For example: I define a UART class class UART { //Internal Data protected: const alt_u32 UART_BASE_ADDRESS; const alt_u32 UART_IRQ_NUMBER; alt_u8 bUARTReceiveData; bool bReceiveNewData; public: UART(alt_u32 BaseAddress, alt_u32 IRQNumber):UART_BASE_ADDRESS(BaseAddress),UART_IRQ_NUMBER(IRQNumber) { alt_irq_register(UART_IRQ_NUMBER, this, UartIsr); } ~UART() {;} void UartIsr(void* pClass, alt_u32 id) { } bool IsReceiveNewData(void) { return bReceiveNewData; } alt_u8 GetData(void) { return bUARTReceiveData; } }; But the compiler report that: error: argument of type `void (UART:: )(void*, alt_u32)' does not match `void (*)(void*, alt_u32)' I also try: alt_irq_register(UART_IRQ_NUMBER, this, (void(*)(void*, alt_u32))UartIsr); But the error still occurred. Anybody help? DavidLink Copied
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I usually use a private static member function in this case, static is necessary, the visibility does not matter. Inside the function you can reinterpret_cast the void pointer to a pointer to your object (assuming you passed 'this' when the ISR was registered).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for your reply. http://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/tongue.gif
I'll complete the answer(I got it from Scott McNutt), hope it will be useful for someone who encounter the same problem. Make the UartIsr() operation class static. E.g.: static void UartIsr(void* pClass, alt_u32 id); Remember, the 'this' pointer is implicitly passed to non-static member functions -- so non-static member functions can never match a 'C' language prototype. As long as UartIsr is a class member, it can always invoke other member functions regardless of their visibility: class UART { private: void doISR (alt_u32 id); protected: static void UartIsr (void *pClass, alt_u32 id) { UART *uart = (UART *)pClass; uart->doISR (id); // ... and other calls as needed ... } // ... and so on. }; Thanks Scott McNutt again, David
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page