os_cpu_a.s
资源名称:ucos.rar [点击查看]
上传用户:dongxin
上传日期:2022-06-22
资源大小:370k
文件大小:15k
源码类别:
uCOS
开发平台:
Others
- /*
- ;************************************************************************************************
- ; uC/OS-II
- ; The Real-Time Kernel
- ;
- ; (c) Copyright 2006, Micrium, Inc., Weston, FL
- ; All Rights Reserved
- ;
- ; File : OS_CPU_A.ASM
- ; By : Jean J. Labrosse
- ;
- ; Note(s) : 1) This port uses the MOVEM.L (A7),D0-D7/A0-A6, LEA 60(A7)A7 construct instead of
- ; the traditional 68xxx MOVEM.L (A7)+,D0-D7/A0-A6.
- ;
- ; 2) The LEA instruction is required because the ColdFire cannot push multiple
- ; registers directly to the stack.
- ;*************************************************************************************************
- */
- /*
- ;*************************************************************************************************
- ; PUBLIC DECLARATIONS
- ;*************************************************************************************************
- */
- .global _OS_CPU_SR_Save
- .global _OS_CPU_SR_Restore
- .global _OSCtxSw
- .global _OSIntCtxSw
- .global _OSStartHighRdy
- .global _OSInitVBR
- //定义自己的中断函数
- .global _pit0_handler
- .global _uart0_handler
- .global _irq1_handler
- .global _irq7_handler
- .global _OS_My_ISR
- /*
- ;**************************************************************************************************
- ; EXTERNAL DECLARATIONS
- ;**************************************************************************************************
- */
- .extern _OSRunning
- .extern _OSIntExit
- .extern _OSIntNesting
- .extern _OSLockNesting
- .extern _OSPrioCur
- .extern _OSPrioHighRdy
- .extern _OSRdyGrp
- .extern _OSRdyTbl
- .extern _OSTaskSwHook
- .extern _OSTCBCur
- .extern _OSTCBHighRdy
- .extern _OSIntEnter
- //声明自己的中断服务函数
- .extern _OS_IRQ1_ISR_Handler
- .extern _OS_IRQ7_ISR_Handler
- .extern _OS_PIT0_ISR_Handler
- .extern _OS_UART0_ISR_Handler
- .text
- .align 4
- /*
- ;********************************************************************************************************
- ; OSCPUSaveSR() for OS_CRITICAL_METHOD #3
- ;
- ; Description : This functions implements the OS_CRITICAL_METHOD #3 function to preserve the state of the
- ; interrupt disable flag in order to be able to restore it later.
- ;
- ; Arguments : none
- ;
- ; Returns : It is assumed that the return value is placed in the D0 register as expected by the
- ; compiler.
- ;
- ; Note(s) : 1) It is assumed that the compiler uses the STANDARD calling convention
- ;********************************************************************************************************
- */
- _OS_CPU_SR_Save:
- MOVE.W SR,D0 ; Copy SR into D0
- MOVE.L D0,-(A7) ; Save D0
- ORI.L #0x0700,D0 ; Disable interrupts
- MOVE D0,SR
- MOVE.L (A7)+,D0 ; Restore D0
- RTS
- /*
- ;********************************************************************************************************
- ; OSCPURestoreSR() for OS_CRITICAL_METHOD #3
- ;
- ; Description : This functions implements the OS_CRITICAL_METHOD #function to restore the state of the
- ; interrupt flag.
- ;
- ; Arguments : os_cpu_sr is the contents of the SR to restore. It is assumed that this 'argument' is
- ; passed on the stack
- ;
- ; Returns : None
- ;
- ; Note(s) : 1) It is assumed that the compiler uses the STANDARD calling convention
- ;********************************************************************************************************
- */
- _OS_CPU_SR_Restore:
- MOVE.L D0,-(A7) ; Save D0
- MOVE.W 10(A7),D0
- MOVE.W D0,SR
- MOVE.L (A7)+,D0 ; Restore D0
- RTS
- /*
- ;*************************************************************************************************
- ; VECTOR BASE REGISTER INITIALIZATION
- ;
- ; This is to set the Vector Base Register to 0x00000000, in case the startup bootloader moved it
- ; somewhere else.
- ;*******************************************************************************************
- */
- _OSInitVBR:
- MOVE.L D0,-(A7) ; Save D0
- MOVEQ #0,D0
- MOVEC D0,VBR
- MOVE.L (A7)+,D0 ; Restore D0
- RTS
- /*
- ;*******************************************************************************************
- ; START HIGHEST PRIORITY TASK READY-TO-RUN
- ;
- ; Description: This function is called by OSStart() to start the highest priority task that
- ; was created by your application before calling OSStart().
- ;
- ; Arguments : none
- ;
- ; Note(s) : 1) The stack frame is assumed to look as follows:
- ;
- ; OSTCBHighRdy->OSTCBStkPtr + 0 ----> D0 Low Memory
- ; + 4 D1
- ; + 8 D2
- ; + 12 D3
- ; + 16 D4
- ; + 20 D5
- ; + 24 D6
- ; + 28 D7
- ; + 32 A0
- ; + 36 A1
- ; + 40 A2
- ; + 44 A3
- ; + 48 A4
- ; + 52 A5
- ; + 56 A6
- ; + 60 Format, Vector, OS_INITIAL_SR
- ; + 64 task
- ; + 68 task
- ; + 72 p_arg High Memory
- ;
- ; 2) OSStartHighRdy() MUST:
- ; a) Call OSTaskSwHook() then,
- ; b) Set OSRunning to TRUE,
- ; c) Switch to the highest priority task.
- ;*******************************************************************************************
- */
- _OSStartHighRdy:
- JSR _OSTaskSwHook
- MOVEQ.L #1, D4 //OSRunning = TRUE;说明多任务运行
- MOVE.B D4,_OSRunning
- MOVE.L (_OSTCBHighRdy),A1 //取得最高优先级任务的TCB地址
- MOVE.L (A1),A7 //取得其堆栈地址
- MOVEM.L (A7),D0-D7/A0-A6 //恢复寄存器
- LEA 60(A7),A7 //修改堆栈指针
- RTE
- /*
- ;*******************************************************************************************
- ; TASK LEVEL CONTEXT SWITCH
- ;
- ; Description : This function is called when a task makes a higher prio task ready-to-run.
- ;
- ; Arguments : none
- ;
- ; Note(s) : 1) Upon entry,
- ; OSTCBCur points to the OS_TCB of the task to suspend
- ; OSTCBHighRdy points to the OS_TCB of the task to resume
- ;
- ; 2) The stack frame of the task to suspend looks as follows (the registers
- ; for task to suspend need to be saved):
- ;
- ; SP + 0 ----> Format, Vector, SR Low Memory
- ; + 4 PC of task High Memory
- ;
- ; 3) The stack frame of the task to resume looks as follows:
- ;
- ; OSTCBHighRdy->OSTCBStkPtr + 0 ----> D0 Low Memory
- ; + 4 D1
- ; + 8 D2
- ; + 12 D3
- ; + 16 D4
- ; + 20 D5
- ; + 24 D6
- ; + 28 D7
- ; + 32 A0
- ; + 36 A1
- ; + 40 A2
- ; + 44 A3
- ; + 48 A4
- ; + 52 A5
- ; + 56 A6
- ; + 60 SR of task
- ; + 64 PC of task High Memory
- ;
- ;*******************************************************************************************
- */
- _OSCtxSw:
- LEA -60(A7),A7
- MOVEM.L D0-D7/A0-A6,(A7) //保存寄存器到当前任务的堆栈
- JSR _OSTaskSwHook
- MOVE.L (_OSTCBCur),A1 //在当前任务TCB中保存栈顶指针
- MOVE.L A7,(A1)
- MOVE.L (_OSTCBHighRdy),A1 // OSTCBCur = OSTCBHighRdy
- MOVE.L A1,(_OSTCBCur)
- MOVE.L (A1),A7 //取得将要运行任务的堆栈
- MOVE.B (_OSPrioHighRdy),D0 // OSPrioCur = OSPrioHighRdy
- MOVE.B D0,(_OSPrioCur)
- MOVEM.L (A7),D0-D7/A0-A6 //恢复CPU寄存器
- LEA 60(A7),A7
- RTE
- /*
- ;*******************************************************************************************
- ; INTERRUPT LEVEL CONTEXT SWITCH
- ;
- ;
- ; Description : This function is provided for backward compatibility and to
- ; satisfy OSIntExit()
- ; in OS_CORE.C.
- ;
- ; Arguments : none
- ;*******************************************************************************************
- */
- _OSIntCtxSw:
- JSR _OSTaskSwHook
- MOVE.B (_OSPrioHighRdy),D0 //OSPrioCur = OSPrioHighRdy
- MOVE.B D0,(_OSPrioCur)
- MOVE.L (_OSTCBHighRdy),A1 //OSTCBCur = OSTCBHighRdy
- MOVE.L A1,(_OSTCBCur)
- MOVE.L (A1),A7 //SP = OSTCBHighRdy->OSTCBStkPtr
- MOVEM.L (A7),D0-D7/A0-A6 //恢复CPU寄存器
- LEA 60(A7),A7
- RTE //运行任务
- /*
- ;*******************************************************************************************
- ; GENERIC ISR
- ;
- ; Description : This function shows how to write ISRs
- ;
- ; Arguments : none
- ;
- ; Notes : 1) You MUST save ALL the CPU registers as shown below
- ; 2) You MUST increment 'OSIntNesting' and NOT call OSIntEnter()
- ; 3) You MUST use OSIntExit() to exit an ISR with the MCF5275.
- ;*******************************************************************************************
- */
- _OS_My_ISR:
- LEA -60(A7),A7 /* Save processor registers onto stack */
- MOVEM.L D0-D7/A0-A6,(A7)
- MOVEQ.L #0,D0 /* OSIntNesting++ */
- MOVE.B (_OSIntNesting),D0
- ADDQ.L #1,D0
- MOVE.B D0,(_OSIntNesting)
- CMPI.L #1, D0 /* if (OSIntNesting == 1) */
- BNE _OS_My_ISR_1
- MOVE.L (_OSTCBCur), A1 /* OSTCBCur-<OSTCBStkPtr = SP */
- MOVE.L A7,(A1)
- _OS_My_ISR_1:
- JSR _OS_My_ISR_Handler /* OS_My_ISR_Handler() */
- JSR _OSIntExit /* Exit the ISR */
- MOVEM.L (A7),D0-D7/A0-A6 /* Restore processor registers from stack */
- LEA 60(A7),A7
- RTE /* Return to task or nested ISR */
- _OS_My_ISR_Handler:
- RTS
- /* create my ISR function */
- /* SW2 按键中断*/
- _irq1_handler:
- //SAVE ALL REGISTERS
- LEA -60(A7),A7
- MOVEM.L D0-D7/A0-A6,(A7)
- //OSIntNesting++,中断嵌套次数加1
- MOVEQ.L #0,D0
- MOVE.B (_OSIntNesting),D0
- ADDQ.L #1,D0
- MOVE.B D0,(_OSIntNesting)
- //如果OSIntNesting == 1,保存SP到当前任务的堆栈中
- CMPI.L #1,D0
- BNE _OS_IRQ1_ISR_1
- MOVE.L (_OSTCBCur),A1
- MOVE.L A7,(A1)
- _OS_IRQ1_ISR_1:
- JSR _OS_IRQ1_ISR_Handler
- JSR _OSIntExit
- //RESTORE ALL REGISTERS
- MOVEM.L (A7),D0-D7/A0-A6
- LEA 60(A7),A7
- RTE
- // sw2 按键中断
- _irq7_handler:
- //SAVE ALL REGISTERS
- LEA -60(A7),A7
- MOVEM.L D0-D7/A0-A6,(A7)
- //OSIntNesting++,中断嵌套次数加1
- MOVEQ.L #0,D0
- MOVE.B (_OSIntNesting),D0
- ADDQ.L #1,D0
- MOVE.B D0,(_OSIntNesting)
- //如果OSIntNesting == 1,保存SP到当前任务的堆栈中
- CMPI.L #1,D0
- BNE _OS_IRQ7_ISR_1
- MOVE.L (_OSTCBCur),A1
- MOVE.L A7,(A1)
- _OS_IRQ7_ISR_1:
- JSR _OS_IRQ7_ISR_Handler
- JSR _OSIntExit
- //RESTORE ALL REGISTERS
- MOVEM.L (A7),D0-D7/A0-A6
- LEA 60(A7),A7
- RTE
- // 时钟中断
- _pit0_handler:
- //SAVE ALL REGISTERS
- LEA -60(A7),A7
- MOVEM.L D0-D7/A0-A6,(A7)
- //OSIntNesting++,中断嵌套次数加1
- MOVEQ.L #0,D0
- MOVE.B (_OSIntNesting),D0
- ADDQ.L #1,D0
- MOVE.B D0,(_OSIntNesting)
- //如果OSIntNesting == 1,保存SP到当前任务的堆栈中
- CMPI.L #1,D0
- BNE _OS_PIT0_ISR_1
- MOVE.L (_OSTCBCur),A1
- MOVE.L A7,(A1)
- _OS_PIT0_ISR_1:
- JSR _OS_PIT0_ISR_Handler
- JSR _OSIntExit
- //RESTORE ALL REGISTERS
- MOVEM.L (A7),D0-D7/A0-A6
- LEA 60(A7),A7
- RTE
- // 串口中断
- _uart0_handler:
- //SAVE ALL REGISTERS
- LEA -60(A7),A7
- MOVEM.L D0-D7/A0-A6,(A7)
- //OSIntNesting++,中断嵌套次数加1
- MOVEQ.L #0,D0
- MOVE.B (_OSIntNesting),D0
- ADDQ.L #1,D0
- MOVE.B D0,(_OSIntNesting)
- //如果OSIntNesting == 1,保存SP到当前任务的堆栈中
- CMPI.L #1,D0
- BNE _OS_UART0_ISR_1
- MOVE.L (_OSTCBCur),A1
- MOVE.L A7,(A1)
- _OS_UART0_ISR_1:
- JSR _OS_UART0_ISR_Handler
- JSR _OSIntExit
- //RESTORE ALL REGISTERS
- MOVEM.L (A7),D0-D7/A0-A6
- LEA 60(A7),A7
- RTE
- .end