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

📄 os_cpu_a.asm

📁 ZLG的EASYARM8962开发板Keil实验例程
💻 ASM
📖 第 1 页 / 共 2 页
字号:
        LDR     R4, =OSRunning                                          ;  OSRunning = TRUE
        MOV     R5, #1
        STRB    R5, [R4]

        LDR     R4, =NVIC_INT_CTRL                                      ;  trigger the PendSV exception
                                                                        ;  触发软件中断
        LDR     R5, =NVIC_PENDSVSET
        STR     R5, [R4]

        CPSIE   I                                                       ;  enable interrupts at processor 
                                                                        ;  level使能所有优先级的中断
OSStartHang
        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.01.18
;**-------------------------------------------------------------------------------------------------------
;** Modified by:            Ni Likao 倪力考
;** Modified date:          2007.11.02
;**-------------------------------------------------------------------------------------------------------
;*********************************************************************************************************
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.01.18
;**-------------------------------------------------------------------------------------------------------
;** Modified by:            Ni Likao 倪力考
;** Modified date:          2007.11.02
;**-------------------------------------------------------------------------------------------------------
;*********************************************************************************************************
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.01.18
;**-------------------------------------------------------------------------------------------------------
;** Modified by:            Ni Likao 倪力考
;** Modified date:          2007.11.02
;**-------------------------------------------------------------------------------------------------------
;*********************************************************************************************************
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, =OSTCBCur                                           ;  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     R0, =OSTaskSwHook                                       ;  OSTaskSwHook();
        BLX     R0
        POP     {R14}
 	  
        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     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


    ALIGN


    END
;*********************************************************************************************************
;  END FILE                                               
;*********************************************************************************************************

⌨️ 快捷键说明

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