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

Can a function know whether it executes on interrupt context or not?

Hello,
I am busy writing an RTOS with a preemptive scheduler. I have written a mutex which works fine, but, of course, I cannot use that mutex (a one that loops until the lock is released by another task) in interrupt context (doing so locks the interrupt controller, hence the scheduler, ergo the entire system). So I made a special version of the mutex that does not poll - but I was wondering whether there is a way to tell on which context a function is called? That way I can simplify the interface. I know it is possible on a x86.
Kind regards,
Tamir Michael

  • Perhaps you should familiarize yourself with the C166 architecture before embarking on writing an RTOS for it.
    When an interrupt occurs, the CPU saves the PSW on the stack, raises ILVL in the PSW to the interrupt's priority and jumps to the interrupt vector location. So normally 'execution in interrupt context' would mean that current ILVL is greater than zero.

    Regards,
    - mike