当前位置:网站首页>UCOS task switching process
UCOS task switching process
2022-07-29 03:47:00 【Drill up and strengthen】
One 、UCOS The task obtains the environment recovery process before the processor runs
The task enters the ready state when it is established , Their stacks are initialized by software , Make it similar to the stack after interruption . Each task in memory will create a virtual processor ( Used to back up physical processors ). The main information stored in the virtual processor is : The breakpoint address of the program (PC)、 Task stack pointer (SP)、 Program status word register (PSR)、 General purpose register contents , And function call information ( Already exists on stack ). These contents are usually saved in the task stack . When you need to run a task , Assign the private stack pointer of the task to the stack pointer of the processor SP, Copy the virtual processor of the task to the actual processor .

The processor passes through two pointer registers PC and SP To connect with task code and task stack ,PC It refers to the task code executed ,SP Is the stack that points to the task .
Task stack pointer (SP) Point to the top of the task private stack of the currently running task , Use task control block (TCB) Save task stack pointer (SP).
Two 、UCOS The environment backup process before the processor stops running when the task is deprived
answer : When the task is deprived , The transition from running state to thread state , There will be task switching .

When you need to abort the current task , Copy the virtual processor corresponding to the task to memory , At the same time, the task control block (TCB) Save the private stack pointer of the task at this time SP. Then assign the private stack pointer of another task to be run to the stack pointer of the processor SP, Its virtual processor is also copied into the actual processor , The scheduler of the operating system performs these two replication tasks according to certain rules .
When the task level scheduler (OSSched()) When it is determined that a new high priority task needs to be executed , Will call OSCtxSw().
OSCtxSw Do the task switching execution steps :

1)OSCtxSw() First, save the status register and program counter of the current task to the stack of the current task . The order in which registers are stacked and when interrupts occur CPU The order of pressing registers onto the stack is the same . Assume here that the status register SR Stack first , The remaining registers are then stacked in turn .
2)OSCtxSw() take CPU The current value of the stack pointer is saved to the control block of the task that will stop running OS_TCB in , That is to say OSTCBCurPtr->StkPtr = R14.
3)OSCtxSw() The of the new task OS_TCB The value of the stack pointer of the task saved in the manned CPU Stack pointer register , The value of this pointer was saved the last time the task was switched , It points to the top of the task stack at that time . This step is R14 = OSTCBHighRdyPtr->StkPtrc.
4) Last ,OSCtxSw() Recover from the new stack CPU Register value . Program counters and status registers usually pop up the stack when executing interrupt return instructions .
边栏推荐
- EMD empirical mode decomposition
- 深入C语言(1)——操作符与表达式
- Environment configuration stepping pit during colab use
- Uni app internationalization
- Alibaba Font Icon Library Usage and update methods
- (nowcoder22529c) diner (inclusion exclusion principle + permutation and combination)
- OPENSQL快速学习
- (newcoder 15079)无关(容斥原理)
- Spark dataframe replaces empty characters (or other values) in each column with null
- 1985-2020 (8 Editions) global surface coverage download and introduction
猜你喜欢

OA项目之会议通知(查询&是否参会&反馈详情)

消费行业数字化升级成 “刚需”,weiit 新零售 SaaS 为企业赋能!

EMD empirical mode decomposition

Realize multi-level linkage through recursion

向日葵远程控制为何采用BGP服务器?自动最优路线、跨运营商高速传输
![MOS管 —— 快速复苏应用笔记(贰)[参数与应用]](/img/54/eb040a51304192def8cfb360c7c213.png)
MOS管 —— 快速复苏应用笔记(贰)[参数与应用]

tron OUT_ OF_ ENERGY

Getting started with caspin

1. Mx6u driver development-2-led driver

Microcomputer principle and interface technology
随机推荐
Arrow function of new features of ES6
How to understand clock cycle and formula CPU execution time = number of CPU clock cycles / dominant frequency
Introduction to static routing and dynamic routing protocols OSPF and rip and static routing configuration commands
LVS+KeepAlived高可用部署实战应用
Solve the delay in opening the console of Google browser
数字孪生实际应用案例-智慧能源篇
"Strangers once met" Summer Street Shen Shuyan_ Xia Mo Shen Shuyan's latest chapter
I.MX6U-驱动开发-2-LED驱动
lodash库常用方法
1. 头文件-注释-命名空间-标准输入输出流
Use of leak scanning (vulnerability scanning) tool burpsuite or burp Suite (with installation and installation package download of burpsuite+1.7.26)
深入C语言(3)—— C的输入输出流
Android view system and custom view Series 1: (kotlin version)
(nowcoder22529c) diner (inclusion exclusion principle + permutation and combination)
(codeforce547) c-mike and foam
Since 2019, you must have stopped using this marketing strategy
Why is continuous integration and deployment important in development?
Typescript from getting started to mastering (XXIII) namespace namespace (Part 2)
OPENSQL快速学习
JS cookie usage