📄 os_cpu_a.s
字号:
/*
*********************************************************************************************************
* uC/OS-II
* The Real-Time Kernel
*
* (c) Copyright 1992-2002, Jean J. Labrosse, Weston, FL
* All Rights Reserved
*
* File : OS_CPU_A.S
* By : Jean J. Labrosse
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* S1C33 Port
*
* Target : S1C33L05
* Ported by : zyl
* URL : Email : asdw198111@163.com
*
*********************************************************************************************************
*/
;#include "includes.h"
/*
;********************************************************************************************************
; MACRO DEFINITIONS
;********************************************************************************************************
*/
;%r15 不用保存
.macro PUSHALL
pushn %r14
ld.w %r0, %alr
ld.w %r1, %ahr
pushn %r1
.endm
.macro POPALL
popn %r1
ld.w %alr, %r0
ld.w %ahr, %r1
popn %r14
.endm
/*
;********************************************************************************************************
; PUBLIC AND EXTERNAL DECLARATIONS
;********************************************************************************************************
*/
.extern OSIntExit
.extern OSIntNesting
.extern OSISRStkPtr
.extern OSPrioCur
.extern OSPrioHighRdy
.extern OSRunning
.extern OSTCBCur
.extern OSTCBHighRdy
.extern OSTaskSwHook
.extern OSTimeTick
;********************************************************************************************************
; START HIGHEST PRIORITY READY TASK
;
; Description: This function is called by OSStart() to start the highest priority task that is ready to run.
;
; Note : OSStartHighRdy() MUST:
; a) Call OSTaskSwHook() then,
; b) Set OSRunning to TRUE,
; c) Switch to the highest priority task.
;********************************************************************************************************
.text
.global OSStartHighRdy
OSStartHighRdy:
xcall OSTaskSwHook ; Call user defined task switch hook
xld.w %r4,OSRunning ; Indicate that multitasking has started
ld.w %r5,0x1
ld.w [%r4],%r5
;SP = OSTCBHighRdy->OSTCBStkPtr
xld.w %r4, OSTCBHighRdy ; Get highest priority task TCB address
ld.w %r4,[%r4]
ld.w %r4,[%r4]
ld.w %sp,%r4 ; switch to the new stack
POPALL ;Restore all the registers. */
reti ;emulate return from interrupt
;*********************************************************************************************************
; PERFORM A CONTEXT SWITCH (From task level)
; void OSCtxSw(void)
;
; Note(s): Upon entry,
; OSTCBCur points to the OS_TCB of the task to suspend
; OSTCBHighRdy points to the OS_TCB of the task to resume
;
;*********************************************************************************************************
.global OSCtxSw
OSCtxSw:
; ld.w %r0, %psr
; ld.w %r1, %pc
; pushn %r0
PUSHALL
; OSTCBCur->OSTCBStkPtr = SP
xld.w %r4,OSTCBCur
xld.w %r4,[%r4] ; OSTCBCur
ld.w %r5,%sp
xld.w [%r4],%r5 ; store sp in preempted tasks's TCB
xcall OSTaskSwHook ; call Task Switch Hook
; OSPrioCur = OSPrioHighRdy
xld.w %r5,OSPrioHighRdy
xld.ub %r4,[%r5] ; OSPrioHighRdy
xld.w %r5,OSPrioCur
xld.b [%r5],%r4
; OSTCBCur = OSTCBHighRdy
xld.w %r5,OSTCBHighRdy
xld.ub %r4,[%r5] ; OSTCBHighRdy
xld.w %r5,OSTCBCur
xld.b [%r5],%r4 ; set new current task TCB address
; SP = OSTCBHighRdy->OSTCBStkPtr
xld.w %r4,OSTCBHighRdy
xld.w %r4,[%r4]
xld.w %r5,[%r4] ; OSTCBStkPtr
ld.w %sp,%r5 ; get new task's stack pointer
POPALL ;Restore all the registers
reti ;return from interrup
/*
;********************************************************************************************************
; ISR LEVEL CONTEXT SWITCH
;
; Description: This function is called by OSIntExit() to perform an ISR level context switch.
;
; Note : OSIntCtxSw() MUST:
; a) Call OSTaskSwHook()
; b) Copy OSPrioHighRdy to OSPrioCur
; c) Copy OSTCBHighRdy to OSTCBCur
; d) Load the SP with OSTCBHighRdy->OSTCBStkPtr
; e) Restore all the registers from the high priority task stack
; f) Perform a return from interrupt
;********************************************************************************************************
*/
.global OSIntCtxSw
OSIntCtxSw:
xcall OSTaskSwHook ; call Task Switch Hook
; OSPrioCur = OSPrioHighRdy
xld.w %r5,OSPrioHighRdy
xld.ub %r4,[%r5] ; OSPrioHighRdy
xld.w %r5,OSPrioCur
xld.b [%r5],%r4
; OSTCBCur = OSTCBHighRdy
xld.w %r5,OSTCBHighRdy
xld.ub %r4,[%r5] ; OSTCBHighRdy
xld.w %r5,OSTCBCur
xld.b [%r5],%r4 ; set new current task TCB address
; SP = OSTCBHighRdy->OSTCBStkPtr
xld.w %r4,OSTCBHighRdy
xld.w %r4,[%r4]
xld.w %r5,[%r4] ; OSTCBStkPtr
ld.w %sp,%r5 ; get new task's stack pointer
POPALL ;Restore all the registers
reti ;return from interrup
;*********************************************************************************************************
; HANDLE TICK ISR
;
;
; Arguments : none
;
; Returns : none
;
; Note(s) : The following C-like pseudo-code describe the operation being performed in the code below.
;
; Save all registers on the current task's stack;
; OSIntNesting++;
; if (OSIntNesting == 1) {
; OSTCBCur->OSTCBStkPtr = %sp
; }
; OSTimeTick(); Notify uC/OS-II that a tick has occured
; OSIntExit(); Notify uC/OS-II about end of ISR
; Restore all registers that were save on the current task's stack;
; Return from Interrupt;
;*********************************************************************************************************
;
.global OnTickISR
OnTickISR:
PUSHALL
xcall OSIntEnter ; Call OSIntEnter() or OSIntNesting++;
xld.w %r4,OSIntNesting
xld.w %r4,[%r4]
cmp %r4,0x1
jrne next
; OSTCBCur->OSTCBStkPtr = SP
xld.w %r4,OSTCBCur
xld.w %r4,[%r4]
ld.w %r5,%sp
ld.w [%r4],%r5 ; store sp in preempted tasks's TCB
next:
;clear 8bit timer4 factor flag
;*(volatile unsigned char*)0x40288 |=0x01;
xld.w %r5, 0x40288
bset [%r5] , 0x0
;reset timer
;*(volatile unsigned char*)0x40174 |=0x02;
xsub %r5,0x114
bset [%r5],0x1
xcall OSTimeTick ; Call OSTimeTick()
xcall OSIntExit ; Call OSIntExit()
POPALL ;Restore all the registers
reti ;return from interrup
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -