⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 os_cpu_a.asm

📁 本文件为新一代基于ARM7构造的微处理器资料
💻 ASM
📖 第 1 页 / 共 2 页
字号:
    B       OSStartHang             


;*********************************************************************************************************
;** Function name:      OSCtxSw
;** Descriptions:	Perform a contex switch from task level  任务级上下文切换                          
;** Input parameters:	None 无
;** Output parameters:  None 无
;** Returned value:	None 无        
;** Created by:		Steven Zhou 周绍刚
;** Created Date:       2007.12.12
;**-------------------------------------------------------------------------------------------------------
;** Modified by:           
;** Modified date:         
;**-------------------------------------------------------------------------------------------------------
;*********************************************************************************************************
OSCtxSw
    PUSH    {R4, R5}
    LDR     R4, =NVIC_INT_CTRL                                          ;  trigger the PendSV exception
                                                                        ;  触发软件中断
    LDR     R5, =NVIC_PENDSVSET
    STR     R5, [R4]
    POP     {R4, R5}
    BX      LR


;*********************************************************************************************************
;** Function name:      OSIntCtxSw
;** Descriptions:	Called by OSIntExit() when it determines a context switch is needed as the
;**                     result of an interrupt.
;**                     中断级任务切换                 
;** Input parameters:   None 无
;** Output parameters:	None 无
;** Returned value:	None 无
;** Created by:		Steven Zhou 周绍刚
;** Created Date:       2007.12.12
;**-------------------------------------------------------------------------------------------------------
;** Modified by:   
;** Modified date: 
;**-------------------------------------------------------------------------------------------------------
;*********************************************************************************************************
OSIntCtxSw
    PUSH    {R4, R5}
    LDR     R4, =NVIC_INT_CTRL                                          ;  trigger the PendSV exception
                                                                        ;  触发软件中断
    LDR     R5, =NVIC_PENDSVSET
    STR     R5, [R4]
    POP     {R4, R5}
    BX      LR
    NOP


;*********************************************************************************************************
;** Function name:      OSPendSV
;** Descriptions:	Used to cause a context switch 用于上下文切换
;** Input parameters:	None 无
;** Output parameters:	None 无
;** Returned value:	None 无
;** Created by:		Steven Zhou 周绍刚
;** Created Date:	2007.12.12
;**-------------------------------------------------------------------------------------------------------
;** Modified by:         
;** Modified date:       
;**-------------------------------------------------------------------------------------------------------
;*********************************************************************************************************
OSPendSV
    IF OS_CRITICAL_INT_PRIO > 0	                                        ;  disable interupt 禁能中断
        MRS R3, BASEPRI
        LDR R1, =OS_CRITICAL_INT_PRIO
	MSR BASEPRI, R1
    ELSE
       	MRS     R3, PRIMASK                
       	CPSID   I
    ENDIF

    MRS     R0, PSP                                                     ;  PSP is process stack pointer  
                                                                        ;  PSP是任务的堆栈指针
    CBZ     R0, OSPendSV_nosave                                         ;  skip register save the first 
                                                                        ;  time第一次跳过保存

    SUB     R0, R0, #0x20                                               ;  save remaining regs r4-11 on 
                                                                        ;  process stack 保存r4-r11
    STM     R0, {R4-R11}

    LDR     R4, __OS_TCBCur                                             ;  OSTCBCur->OSTCBStkPtr = SP;
    LDR     R4, [R4]
    STR     R0, [R4]                                                    ;  R0 is SP of process being 
                                                                        ;  switched outR0是被切换开的任务
                                                                        ;  的堆栈指针
OSPendSV_nosave
    PUSH    {R14}                                                       ;  need to save LR exc_return 
                                                                        ;  value保存LR返回值

    LDR.W   R0, __OS_TaskSwHook                                         ;  OSTaskSwHook();
    BLX     R0
    POP     {R14}
 	  
    LDR     R4, __OS_PrioCur                                            ;  OSPrioCur = OSPrioHighRdy
    LDR     R5, __OS_PrioHighRdy     
    LDRB    R6, [R5]
    STRB    R6, [R4]

    LDR     R4, __OS_TCBCur                                             ;  OSTCBCur  = OSTCBHighRdy;
    LDR     R6, __OS_TCBHighRdy      
    LDR     R6, [R6]
    STR     R6, [R4]

    LDR     R0, [R6]                                                    ;  SP = OSTCBHighRdy->OSTCBStkPtr;
    LDM     R0, {R4-R11}                                                ;  restore r4-11 from new process
                                                                        ;  stack 从新任务的堆栈恢复r4-r11
    ADD     R0, R0, #0x20
    MSR     PSP, R0                                                     ;  load PSP with new process SP
                                                                        ;  从新任务的堆栈恢复PSP
 	   	
    ORR     LR, LR, #0x04                                               ;  ensure exception return uses 
                                                                        ;  PSP确保返回后使用PSP
        
    IF OS_CRITICAL_INT_PRIO > 0                                         ;  restore interrupts 恢复中断  
        MSR 	BASEPRI,  R3
    ELSE
	MSR     PRIMASK, R3
    ENDIF
		   
    BX      LR                                                          ; exception return will restore 
                                                                        ;  remaining context 
                                                                        ;  返回时会恢复剩下的上下文
    NOP


;*********************************************************************************************************
;** Function name:      IntDisAll
;** Descriptions:	Disable all interrupts from the interrupt controller  关闭中断控制器的所有中断
;** Input parameters:	None 无
;** Output parameters:	None 无
;** Returned value:	None 无
;** Created by:		Steven Zhou 周绍刚
;** Created Date:	2007.12.12
;**-------------------------------------------------------------------------------------------------------
;** Modified by:         
;** Modified date:       
;**-------------------------------------------------------------------------------------------------------
;*********************************************************************************************************
intDisAll
    CPSID   I
    BX      LR
    
    
;*********************************************************************************************************
;  POINTERS TO VARIABLES
;  变量指针  
;*********************************************************************************************************
    DATA

__OS_TaskSwHook:
    DC32    OSTaskSwHook

__OS_IntExit:
    DC32    OSIntExit

__OS_IntNesting:
    DC32    OSIntNesting

__OS_PrioCur:
    DC32    OSPrioCur

__OS_PrioHighRdy:
    DC32    OSPrioHighRdy

__OS_Running:
    DC32    OSRunning

__OS_TCBCur:
    DC32    OSTCBCur

__OS_TCBHighRdy:
    DC32    OSTCBHighRdy

__OS_EnterSum:
    DC32    OsEnterSum


    END

;*********************************************************************************************************
;  __END FILE 
;*********************************************************************************************************

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -