?? os_cpu_a_backup.s
字號:
;********************************************************************************************************
; uC/OS-II
; The Real-Time Kernel
;
; (c) Copyright 1992-2004, Micrium, Weston, FL
; All Rights Reserved
;
; ARM Generic Port
; IAR C Compiler
;
; File : OS_CPU_A.ASM
; Version : V1.50
; By : Jean J. Labrosse
;********************************************************************************************************
GLOBAL OS_CPU_SR_Save ; Functions declared in this file
GLOBAL OS_CPU_SR_Restore
GLOBAL OSStartHighRdy
GLOBAL OSCtxSw
GLOBAL OSIntCtxSw
GLOBAL OS_CPU_IRQ_ISR
; GLOBAL OS_CPU_FIQ_ISR
NO_INT EQU 0xC0 ; Mask used to disable interrupts (Both FIR and IRQ)
SYS32_MODE EQU 0x1F
FIQ32_MODE EQU 0x11
IRQ32_MODE EQU 0x12
;*********************************************************************************************************
; CRITICAL SECTION METHOD 3 FUNCTIONS
;
; Description: Disable/Enable interrupts by preserving the state of interrupts. Generally speaking you
; would store the state of the interrupt disable flag in the local variable 'cpu_sr' and then
; disable interrupts. 'cpu_sr' is allocated in all of uC/OS-II's functions that need to
; disable interrupts. You would restore the interrupt disable state by copying back 'cpu_sr'
; into the CPU's status register.
;
; Prototypes : OS_CPU_SR OS_CPU_SR_Save(void);
; void OS_CPU_SR_Restore(OS_CPU_SR cpu_sr);
;
;
; Note(s) : 1) These functions are used in general like this:
;
; void Task (void *p_arg)
; {
; #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
; OS_CPU_SR cpu_sr;
; #endif
;
; :
; :
; OS_ENTER_CRITICAL(); /* cpu_sr = OS_CPU_SaveSR(); */
; :
; :
; OS_EXIT_CRITICAL(); /* OS_CPU_RestoreSR(cpu_sr); */
; :
; :
; }
;
; 2) OS_CPU_SaveSR() is implemented as recommended by Atmel's application note:
;
; "Disabling Interrupts at Processor Level"
;*********************************************************************************************************
AREA OS_ASM_CODE, CODE, READONLY
; ENTRY
CODE32
IMPORT OSRunning ; External references
IMPORT OSPrioCur
IMPORT OSPrioHighRdy
IMPORT OSTCBCur
IMPORT OSTCBHighRdy
IMPORT OSIntNesting
IMPORT OSIntEnter
IMPORT OSIntExit
IMPORT OSTaskSwHook
IMPORT OS_CPU_IRQ_ISR_Handler
; IMPORT OS_CPU_FIQ_ISR_Handler
; RSEG CODE:CODE:NOROOT(2)
OS_CPU_SR_Save
mrs r0,CPSR
orr r1,r0,#NO_INT
msr CPSR_c,r1
mov pc,lr
OS_CPU_SR_Restore
msr CPSR_c,r0
mov pc,lr
;OS_CPU_SR_Save
; MRS R0,CPSR ; Set IRQ and FIQ bits in CPSR to disable all interrupts
; ORR R1,R0,#NO_INT
; MSR CPSR_c,R1
; MRS R1,CPSR ; Confirm that CPSR contains the proper interrupt disable flags
; AND R1,R1,#NO_INT
; CMP R1,#NO_INT
; BNE OS_CPU_SR_Save ; Not properly disabled (try again)
; MOV PC,LR ; Disabled, return the original CPSR contents in R0
;
;
;OS_CPU_SR_Restore
; MSR CPSR_c,R0
; MOV PC,LR
;
;
;;*********************************************************************************************************
;; START MULTITASKING
; void OSStartHighRdy(void)
;
; Note(s) : 1) OSStartHighRdy() MUST:
; a) Call OSTaskSwHook() then,
; b) Set OSRunning to TRUE,
; c) Switch to the highest priority task.
;*********************************************************************************************************
; RSEG CODE:CODE:NOROOT(2)
; CODE32
OSStartHighRdy
MSR CPSR_cxsf, #0xDF ; Switch to SYS mode with IRQ and FIQ disabled
BL OSTaskSwHook ; OSTaskSwHook();
LDR R4, =OSRunning ; OSRunning = TRUE
MOV R5, #1
STRB R5, [R4]
; SWITCH TO HIGHEST PRIORITY TASK
LDR R4, =OSTCBHighRdy ; Get highest priority task TCB address
LDR R4, [R4] ; get stack pointer
LDR SP, [R4] ; switch to the new stack
LDR R4, [SP], #4 ; pop new task's CPSR
MSR CPSR_cxsf,R4
LDR R0, [SP], #4 ; pop new task's context
LDR R1, [SP], #4
LDR R2, [SP], #4
LDR R3, [SP], #4
LDR R4, [SP], #4
LDR R5, [SP], #4
LDR R6, [SP], #4
LDR R7, [SP], #4
LDR R8, [SP], #4
LDR R9, [SP], #4
LDR R10, [SP], #4
LDR R11, [SP], #4
LDR R12, [SP], #4
LDR LR, [SP], #4
LDR PC, [SP], #4
;*********************************************************************************************************
; PERFORM A CONTEXT SWITCH (From task level) - OSCtxSw()
;
; Note(s) : 1) OSCtxSw() is called in SYS mode with BOTH FIQ and IRQ interrupts DISABLED
;
; 2) The pseudo-code for OSCtxSw() is:
; a) Save the current task's context onto the current task's stack
; b) OSTCBCur->OSTCBStkPtr = SP;
; c) OSTaskSwHook();
; d) OSPrioCur = OSPrioHighRdy;
; e) OSTCBCur = OSTCBHighRdy;
; f) SP = OSTCBHighRdy->OSTCBStkPtr;
; g) Restore the new task's context from the new task's stack
; h) Return to new task's code
;
; 3) Upon entry:
; OSTCBCur points to the OS_TCB of the task to suspend
; OSTCBHighRdy points to the OS_TCB of the task to resume
;*********************************************************************************************************
; RSEG CODE:CODE:NOROOT(2)
CODE32
OSCtxSw
; SAVE CURRENT TASK'S CONTEXT
STR LR, [SP, #-4]! ; Return address
STR LR, [SP, #-4]!
STR R12, [SP, #-4]!
STR R11, [SP, #-4]!
STR R10, [SP, #-4]!
STR R9, [SP, #-4]!
STR R8, [SP, #-4]!
STR R7, [SP, #-4]!
STR R6, [SP, #-4]!
STR R5, [SP, #-4]!
STR R4, [SP, #-4]!
STR R3, [SP, #-4]!
STR R2, [SP, #-4]!
STR R1, [SP, #-4]!
STR R0, [SP, #-4]!
MRS R4, CPSR ; push current CPSR
STR R4, [SP, #-4]!
LDR R4, =OSTCBCur ; OSTCBCur->OSTCBStkPtr = SP;
LDR R5, [R4]
STR SP, [R5]
BL OSTaskSwHook ; OSTaskSwHook();
LDR R4, =OSPrioCur ; OSPrioCur = OSPrioHighRdy
LDR R5, =OSPrioHighRdy
LDRB R6, [R5]
STRB R6, [R4]
LDR R4, =OSTCBCur ; OSTCBCur = OSTCBHighRdy;
LDR R6, =OSTCBHighRdy
LDR R6, [R6]
STR R6, [R4]
LDR SP, [R6] ; SP = OSTCBHighRdy->OSTCBStkPtr;
; RESTORE NEW TASK'S CONTEXT
LDR R4, [SP], #4 ; pop new task's CPSR
MSR CPSR_cxsf, R4
LDR R0, [SP], #4 ; pop new task's context
LDR R1, [SP], #4
LDR R2, [SP], #4
LDR R3, [SP], #4
LDR R4, [SP], #4
LDR R5, [SP], #4
LDR R6, [SP], #4
LDR R7, [SP], #4
LDR R8, [SP], #4
LDR R9, [SP], #4
LDR R10, [SP], #4
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -