How RTOS does task switching from interrupt

后端 未结 2 781
栀梦
栀梦 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

    An RTOS will require specific ISR entry/exit code to be included in each ISR that may cause a context switch (typically any that call the RTOS API). These functions maintain a counter that allows nested interrupts; when the counter is decremented to zero, the outermost ISR is about to return, and the exit code invokes the kernel scheduler.

    The scheduler will restore the context to the highest priority ready task; this includes modifying the return address so that the RETI instruction causes the program counter to be set to TASK_B's restart point rather the TASK_A. The scheduler will store the TASK_A restart point in the task control block(TCB) so that its context can be similarly restored.

提交回复
热议问题