This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

CARM-LCP2292: Function calls from within ISRs

Greetings:
I'm desperately chasing obscure bugs in somebody else's code. I say this before I state that some of the ISR's are embarrassingly long, and have multiple calls to utility functions. In a knowledge base article (http://www.keil.com/support/docs/2910.htm), there is a warning that "it would be impossible to call other functions within the interrupt service routines". Since the code under scrutiny routinely does exactly this, how bad is it? It seems to me the compiler only saves registers used within the __isr routine, therefore any functions called from there may overwrite registers which may or may not be pushed and popped by the IRS itself. Is this correct, or do I worry to much (I'm getting desperate for a solution here...).

Thanks,
Doug

  • From the knowledgebase article:

    Yes, it is required to switch the CPU into the User/System Mode. Otherwise it would be impossible to call other functions within the interrupt service routine.

    To be honest, I cannot see why it would be impossible to call other functions. They should work just fine. Maybe someone else in this forum can explain.
    If one of those functions happens to be non-reentrant you can run into obscure bugs. As usual, if there are variables shared between ISRs and normal code, special care must be taken when accessing them in normal code.

    Regards,
    - mike

  • "... some of the ISR's are embarrassingly long, and have multiple calls to utility functions."

    What are these utility functions of which you speak? Are they C library functions or functions that somebody else wrote?

    If they are C library functions, note that not all library functions are reentrant, so if those non-reentrant functions are called from mainline code and ISRs, you could have a problem. The manual lists which library functions are reentrant:

    http://www.keil.com/support/man/docs/ca/ca_library.htm

    On the other hand, if somebody else wrote the utility functions and you have their source code, you should be able to judge for yourself whether or not they are reentrant.