How RTOS does task switching from interrupt

后端 未结 2 756
栀梦
栀梦 2021-01-12 05:38

Suppose there is two task running TASK_A and TASK_B. While TASK_A is running an interrupt occurred and a context switch to TASK_B is needed.

While inside ISR, TASK_B

2条回答
  •  北海茫月
    2021-01-12 06:27

    The ISR has to be implemented in a way that allows for a context switch. Typically, at the end of the ISR there will be a call to an RTOS function that checks for and performs the context switch.

    When the interrupt occurs, the CPU saves its context and jumps to the ISR. The way the context is saved varies among CPU families. When the ISR is complete, it should call a special RTOS routine that allows for a context switch after an ISR. If there is a higher priority task ready to run then this routine will perform a context switch. It will take the pre-interrupt context saved by the CPU and save it with TASK_A. Then it will get the saved context of TASK_B and restore it into the CPU such that when the end-of-interrupt instruction is called, execution returns to the context of TASK_B.

    The details of all of this is very CPU and RTOS dependent.

提交回复
热议问题