Hi All, Could anybody help me out with the following problem? I have a module with the following declarations.
int (*on_CAN_msg)(void); ... void CAN_int_handler(void) interrupt 7 using 1 { ... if (on_CAN_msg) on_CAN_msg(); ... }
int CAN_msg_handler(void){ ... } extern int (*on_CAN_msg)(void) = CAN_msg_handler;
CAN_int_handler ! (CAN_msg_handler), main ! (on_CAN_msg)
int main(){ ... on_CAN_msg = CAN_msg_handler; ... }
Don't worry too much about why your essentially incorrect method miraculously works --- just use the correct one, i.e. the one in which the variable is defined and initialization in the module that has the initializer available to it, rather than the one that wants to call through hat pointer. And while you're at it, you should consider getting rid of all 'extern' declarations in .c files. #include header files instead --- that's what they're there for. I.e. there should be a "main.h" contain that extern declaration, and both can.c and main.c should #include that.
If you're going to use function pointers, you should read the following application note: http://www.keil.com/appnotes/docs/apnt_129.asp Jon