当前位置:网站首页>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 .
边栏推荐
- 关于ALV格式控制部分的写法
- Cannot paste multiple pictures at once
- Flask framework operation database_ Add, delete, modify and query statements
- Sleuth+zipkin to track distributed service links
- Raft protocol - process demonstration
- Excel splicing database statement
- Anaconda offline installation environment
- Typescript from getting started to mastering (XVI) configuration file - first knowledge of compileroptions configuration item
- 大厂们终于无法忍受“加一秒”了,微软谷歌Meta等公司提议废除闰秒
- OA项目之会议通知(查询&是否参会&反馈详情)
猜你喜欢

新零售O2O 电商模式解析

Vs code must know and know 20 shortcut keys!

Rdkit II: use rdkit screening to screen 2D pharmacophores of chemical small molecules

Shutter start white screen

SQL窗口函数

Rdkit I: using rdkit to screen the structural characteristics of chemical small molecules

Rdkit: introduce smiles code, smart code and Morgan fingerprint (ECFP)

Overestimated test driven development?

Typescript from getting started to mastering (XXII) namespace namespace (I)

Beijing post network research 2015 problem2
随机推荐
Typescript from getting started to mastering (XXIII) namespace namespace (Part 2)
Functions and comparison of repeaters, hubs, bridges, switches and routers
深入C语言(3)—— C的输入输出流
Exness: dove resolution helped gold rebound, and the focus turned to U.S. GDP
Beijing post network research 2015 problem2
从2019 年开始,你一定停止使用了这个营销策略…
《陌路曾相逢》夏陌沈疏晏_夏陌沈疏晏最新章节
In depth C language (2) -- definition and use of structure
three. JS Part 54 how to pass structure array to shader
Environment configuration stepping pit during colab use
Install the packet capturing certificate
Use of leak scanning (vulnerability scanning) tool burpsuite or burp Suite (with installation and installation package download of burpsuite+1.7.26)
1. Header file - Comment - namespace - standard input / output stream
EMD 经验模态分解
代码 ~ 隐藏或禁用状态栏和虚拟按键
Cloudera manager platform fault repair record
Practical application cases of digital Twins - smart energy
Since 2019, you must have stopped using this marketing strategy
Simple use of eventbus
(newcoder 15079) irrelevant (inclusion exclusion principle)