Hello, I have faced a problem with a function pointer variable. I have separated the uart module in two parts: HAL, which abstracts the hardware, and Service, which provides the uart service to the application. The interrupt routine is in HAL module, which has a function pointer variable that is called into the interrupt routine as interrupt handler. The actual interrupt handler function is in Service module. This function is assigned to the function pointer variable through a install function in the init routine. It works in debug simulation, but when I load the hex file to the microcontroller the application does not work. Anyone can help me?
All functions called within an interrupt must be reentrant. (it's a keil keyword).
I have some code that calls queue functions from within a serial interrupt. It will make a disaster of the stack and data if you don't mark such functions reentrant, and of course I forgot this. So each time I attempted communication the system would have a seizure.
The ISR has a seperate variable and data allocation from your main program. This is why you must set such functions you call from an ISR reentrant.
In addition I concur with the prior suggestion. Keep interupts extremely simple with the C51. Remember your uC stack is < 256 bytes at best. Worst case is 128 bytes or less. Stack only uses data/idata space. You may be getting stack corruption by the way.
Stephen
All functions called within an interrupt must be reentrant. (it's a keil keyword). what a waste, there is no need.
Also as a general (not totally unbreakable) rule no functions should be called from ISRs.
Erik
Well it's not always necessary but unfortunately it is necessary for certain things. In my case the serial port queue code was also the same as some other queues code so they shared common functions/routines. That's the way it goes.
The most important thing was that it prevented the reinvention of bugs err new wheels. :D Bugs were (are) more expensive than code space I've decided.
first: All functions called within an interrupt must be reentrant. (it's a keil keyword).
then: Well it's not always necessary
correct: it is NEVER necessary unless you are doing the crazy (for C51) stuff of calling functions from both main and an ISR.
"All functions called within an interrupt must be reentrant."
No, that is not true at all.
The point is that C51 functions are not inherently reentrant; so, if you need them to be so - eg, because you call them from both ISR and "main" code - then you must specifically make them so. eg, by use of the reentrant keyword.