Search code examples
operating-systemembeddedinterruptrtosautosar

DisableAllInterrupts VS SuspendAllInterrupts (OSEK\VDX)


I would like to know the difference between DisableAllInterrupts and SuspendAllInterrupts in OSEK?

DisableAllInterrupts description in OSEK doc

SuspendAllInterrupts description in OSEK doc


Solution

  • The disable/enable interface is unsuitable for nesting. The suspend/resume can be nested so that if a function suspends and resumes when the caller has already suspended, the interrupts will only be enabled on the outermost resume call.

    The documentation also states that suspend saves the "recognition status". It is not clear to me what that means; I have looked throughout the entire document and nowhere does it define that term clearly. I assume that all interrupts that are recognised before are restored after the call. That would (I guess) mean that if you enabled a new interrupt while suspended, the the resume might disable it. Enabling a new interrupt in a disabled section on the other hand would persist after enable. It is less than clear however IMO.

    Nested suspend/resume will work as follows:

    1. There will be a counter, that when suspend is called, if the counter is zero, then the interrupts are suspended, the recognition state is saved. In any event the counter is incremented.

    2. When resume is called, the counter is decremented, and if it becomes zero, then the recognition state is restored and interrupts enabled.

    The effect of that is if you for example:

                         Nest-count    Interrupts
    -----------------------------------------------
                             0         Enabled
    suspend() ;              1         Disabled
        suspend() ;          2         Disabled
        resume() ;           1         Disabled
        suspend() ;          2         Disabled
            suspend() ;      3         Disabled
            resume() ;       2         Disabled
        resume() ;           1         Disabled
    resume() ;               0         Enabled
    

    If you are writing a critical section in a function that may be called from some other function you should use suspend/resume. If you use disable/enable in the above scenario it would enable interrupts prematurely:

                         Interrupts
    --------------------------------                     
                         Enabled
    disable() ;          Disabled
        enable() ;       Enabled
        enable() ;       Enabled
        disable() ;      Disabled
            disable() ;  Disabled
            enable() ;   Enabled
        enable() ;       Enabled
    enable() ;           Enabled
    

    See in the enable/disable the nesting has no effect. You should use nesting if you call functions from a critical section when such functions might also have critical sections within them - to ensure the outer critical section is not terminated prematurely.