os_cpu_a.lst
来自「SDIO文件系统forHMI-STM32」· LST 代码 · 共 366 行 · 第 1/2 页
LST
366 行
(essentially, causes a context switch) to cause
112 0000000E ; the first task to start.
113 0000000E ;
114 0000000E ; 2) OSStartHighRdy() MUST:
115 0000000E ; a) Setup PendSV exception priority to low
est;
116 0000000E ; b) Set initial PSP to 0, to tell context
switcher this is first run;
117 0000000E ; c) Set OSRunning to TRUE;
118 0000000E ; d) Trigger PendSV exception;
119 0000000E ; e) Enable interrupts (tasks will run with
interrupts enabled).
ARM Macro Assembler Page 4
120 0000000E ;*******************************************************
**************************************************
121 0000000E
122 0000000E OSStartHighRdy
123 0000000E 4824 LDR R0, =NVIC_SYSPRI2 ; Set the Pen
dSV exception prior
ity
124 00000010 F04F 0100 LDR R1, =NVIC_PENDSV_PRI
125 00000014 7001 STRB R1, [R0]
126 00000016
127 00000016
128 00000016 2000 MOVS R0, #0 ; Set the PSP to 0
for initial context
switch call
129 00000018 F380 8809 MSR PSP, R0
130 0000001C
131 0000001C 481D LDR R0, __OS_Running
; OSRunning = TRUE
132 0000001E 2101 MOVS R1, #1
133 00000020 7001 STRB R1, [R0]
134 00000022
135 00000022 4820 LDR R0, =NVIC_INT_CTRL ; Trigger th
e PendSV exception
(causes context swi
tch)
136 00000024 F04F 5180 LDR R1, =NVIC_PENDSVSET
137 00000028 6001 STR R1, [R0]
138 0000002A
139 0000002A B662 CPSIE I ;开总中断
; Enable
interrupts at proce
ssor level
140 0000002C
141 0000002C OSStartHang
142 0000002C E7FE B OSStartHang ; Should never get
here
143 0000002E
144 0000002E
145 0000002E ;*******************************************************
**************************************************
146 0000002E ; PERFORM A CONTEXT SWITCH
(From task level)
147 0000002E ; void OSCtxSw
(void)
148 0000002E ;
149 0000002E ; Note(s) : 1) OSCtxSw() is called when OS wants to perf
orm a task context switch. This function
150 0000002E ; triggers the PendSV exception which is wh
ere the real work is done.
151 0000002E ;*******************************************************
**************************************************
152 0000002E
153 0000002E OSCtxSw ;悬起PSV异常
154 0000002E ;PUSH {R0, R1} ;自己添加的代码
155 0000002E 481D LDR R0, =NVIC_INT_CTRL ; Trigger th
e PendSV exception
(causes context swi
tch)
ARM Macro Assembler Page 5
156 00000030 F04F 5180 LDR R1, =NVIC_PENDSVSET
157 00000034 6001 STR R1, [R0]
158 00000036 ;POP {R0, R1} ;自己添加的代码
159 00000036 4770 BX LR
160 00000038
161 00000038 ;*******************************************************
**************************************************
162 00000038 ; PERFORM A CONTEXT SWITCH (
From interrupt level)
163 00000038 ; void OSIntCtxS
w(void)
164 00000038 ;
165 00000038 ; Notes: 1) OSIntCtxSw() is called by OSIntExit() whe
n it determines a context switch is needed as
166 00000038 ; the result of an interrupt. This functio
n simply triggers a PendSV exception which will
167 00000038 ; be handled when there are no more interru
pts active and interrupts are enabled.
168 00000038 ;*******************************************************
**************************************************
169 00000038
170 00000038 OSIntCtxSw ;悬起PSV异常
171 00000038 ;PUSH {R0, R1} ;自己添加的代码
172 00000038 481A LDR R0, =NVIC_INT_CTRL ; Trigger th
e PendSV exception
(causes context swi
tch)
173 0000003A F04F 5180 LDR R1, =NVIC_PENDSVSET
174 0000003E 6001 STR R1, [R0]
175 00000040 ;POP {R0, R1} ;自己添加的代码
176 00000040 4770 BX LR
177 00000042
178 00000042 ;*******************************************************
**************************************************
179 00000042 ; HANDLE PendSV
EXCEPTION
180 00000042 ; void OSPend
SV(void)
181 00000042 ;
182 00000042 ; Note(s) : 1) OSPendSV is used to cause a context switc
h. This is a recommended method for performing
183 00000042 ; context switches with Cortex-M3. This is
because the Cortex-M3 auto-saves half of the
184 00000042 ; processor context on any exception, and r
estores same on return from exception. So only
185 00000042 ; saving of R4-R11 is required and fixing u
p the stack pointers. Using the PendSV exception
186 00000042 ; this way means that context saving and re
storing is identical whether it is initiated from
187 00000042 ; a thread or occurs due to an interrupt or
exception.
188 00000042 ;
189 00000042 ; 2) Pseudo-code is:
190 00000042 ; a) Get the process SP, if 0 then skip (go
to d) the saving part (first context switch);
191 00000042 ; b) Save remaining regs r4-r11 on process
stack;
192 00000042 ; c) Save the process SP in its TCB, OSTCBC
ur->OSTCBStkPtr = SP;
ARM Macro Assembler Page 6
193 00000042 ; d) Call OSTaskSwHook();
194 00000042 ; e) Get current high priority, OSPrioCur =
OSPrioHighRdy;
195 00000042 ; f) Get current ready thread TCB, OSTCBCur
= OSTCBHighRdy;
196 00000042 ; g) Get new process SP from TCB, SP = OSTC
BHighRdy->OSTCBStkPtr;
197 00000042 ; h) Restore R4-R11 from new process stack;
198 00000042 ; i) Perform exception return which will re
store remaining context.
199 00000042 ;
200 00000042 ; 3) On entry into OSPendSV handler:
201 00000042 ; a) The following have been saved on the p
rocess stack (by processor):
202 00000042 ; xPSR, PC, LR, R12, R0-R3
203 00000042 ; b) Processor mode is switched to Handler
mode (from Thread mode)
204 00000042 ; c) Stack is Main stack (switched from Pro
cess stack)
205 00000042 ; d) OSTCBCur points to the OS_TCB of
the task to suspend
206 00000042 ; OSTCBHighRdy points to the OS_TCB of
the task to resume
207 00000042 ;
208 00000042 ; 4) Since OSPendSV is set to lowest priority
in the system (by OSStartHighRdy() above), we
209 00000042 ; know that it will only be run when no oth
er exception or interrupt is active, and
210 00000042 ; therefore safe to assume that context bei
ng switched out was using the process stack (PSP).
211 00000042 ;*******************************************************
**************************************************
212 00000042 ;Cortex-M3进入异常服务例程时,自动压栈了R0-R3,R12,LR(R14,
连接寄存器),PSR(程序状态寄存器)和PC(R15).并且在返回时自
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?