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."
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.
View all questions in Keil forum