📄 os_cpu_a.s
字号:
;********************************************************************************************************
; uC/OS-II
; The Real-Time Kernel
;
; (c) Copyright 2002, Jean J. Labrosse, Weston, FL
; All Rights Reserved
;
;
; 68HC11 Specific code
; COSMIC C V4.1
;
; File : OS_CPU_A.S
; By : Jean J. Labrosse
; Port Version : V1.02
;********************************************************************************************************
;********************************************************************************************************
; CONFIGURATION CONSTANTS
;********************************************************************************************************
OS_TICK_OC: equ 1 ; We will use Output Compare #1 to generate tick interrupts
OS_TICK_OC_CNTS: equ 2500 ; 100 Hz tick rate (assumes Free Running Timer runs at 250 KHz)
;********************************************************************************************************
; I/O PORT ADDRESSES
;********************************************************************************************************
TFLG1: equ $1023 ; I/O port addresses. Assumes all 68HC11 I/Os start at 0x1000
TOC1: equ $1016
TOC2: equ $1018
TOC3: equ $101A
TOC4: equ $101C
TOC5: equ $101E
;********************************************************************************************************
; PUBLIC DECLARATIONS
;********************************************************************************************************
xdef _OSStartHighRdy
xdef _OSCtxSw
xdef _OSIntCtxSw
xdef _OSTickISR
;********************************************************************************************************
; EXTERNAL DECLARATIONS
;********************************************************************************************************
xref _OSIntExit
xref _OSIntNesting
xref _OSPrioCur
xref _OSPrioHighRdy
xref _OSRunning
xref _OSTaskSwHook
xref _OSTCBCur
xref _OSTCBHighRdy
xref _OSTimeTick
;********************************************************************************************************
; 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 -->
; + 1 CCR
; + 2 B
; + 3 A
; + 4 X (H)
; + 5 X (L)
; + 6 Y (H)
; + 7 Y (L)
; + 8 PC(H)
; + 9 PC(L)
;
; 2) OSStartHighRdy() MUST:
; a) Call OSTaskSwHook() then,
; b) Set OSRunning to TRUE,
; c) Switch to the highest priority task.
;********************************************************************************************************
switch .text
_OSStartHighRdy:
jsr _OSTaskSwHook ; 6~, Invoke user defined context switch hook
ldab #$01 ; 2~, Indicate that we are multitasking
stab _OSRunning ; 4~
ldx _OSTCBHighRdy ; 5~, Point to TCB of highest priority task ready to run
lds 0,x ; 5~, Load SP into 68HC11
rti ; 12~, Run task
;********************************************************************************************************
; TASK LEVEL CONTEXT SWITCH
;
; Description : This function is called when a task makes a higher priority 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:
;
; SP + 0 -->
; + 1 CCR
; + 2 B
; + 3 A
; + 4 X (H)
; + 5 X (L)
; + 6 Y (H)
; + 7 Y (L)
; + 8 PC(H)
; + 9 PC(L)
;
; 3) The stack frame of the task to resume looks as follows:
;
; OSTCBHighRdy->OSTCBStkPtr + 0 -->
; + 1 CCR
; + 2 B
; + 3 A
; + 4 X (H)
; + 5 X (L)
; + 6 Y (H)
; + 7 Y (L)
; + 8 PC(H)
; + 9 PC(L)
;********************************************************************************************************
_OSCtxSw:
ldx _OSTCBCur ; 5~, Point to current task's TCB
sts 0,x ; 5~, Save stack pointer in preempted task's TCB
jsr _OSTaskSwHook ; 6~, Call user task switch hook
ldx _OSTCBHighRdy ; 5~, OSTCBCur = OSTCBHighRdy
stx _OSTCBCur ; 5~,
ldab _OSPrioHighRdy ; 4~, OSPrioCur = OSPrioHighRdy
stab _OSPrioCur ; 4~
lds 0,x ; 5~, Load SP into 68HC11
rti ; 12~, Run task
;********************************************************************************************************
; INTERRUPT LEVEL CONTEXT SWITCH
;
; Description : This function is called by OSIntExit() to perform a context switch to a task that has
; been made ready-to-run by an ISR.
;
; Arguments : none
;********************************************************************************************************
_OSIntCtxSw:
jsr _OSTaskSwHook ; 6~, Call user task switch hook
ldx _OSTCBHighRdy ; 5~, OSTCBCur = OSTCBHighRdy
stx _OSTCBCur ; 5~,
ldab _OSPrioHighRdy ; 4~, OSPrioCur = OSPrioHighRdy
stab _OSPrioCur ; 4~
lds 0,x ; 5~, Load SP into 68HC11
rti ; 12~, Run task
;********************************************************************************************************
; SYSTEM TICK ISR
;
; Description : This function is the ISR used to notify uC/OS-II that a system tick has occurred. You
; must setup the 68HC11's interrupt vector table so that an OUTPUT COMPARE interrupt
; vectors to this function.
;
; Arguments : none
;
; Notes : 1) The 'tick ISR' assumes the we are using the Output Compare specified by OS_TICK_OC
; (see OS_CFG.H and this file) to generate a tick that occurs every OS_TICK_OC_CNTS
; (see OS_CFG.H and this file) which corresponds to the number of FRT (Free Running
; Timer) counts to the next interrupt.
;
; 2) You must specify which output compare will be used by the tick ISR as follows:
; Set OS_TICK_OC in OS_CFG.H (AND in this file) to 1 to use OUTPUT COMPARE #1
; Set OS_TICK_OC in OS_CFG.H (AND in this file) to 2 to use OUTPUT COMPARE #2
; Set OS_TICK_OC in OS_CFG.H (AND in this file) to 3 to use OUTPUT COMPARE #3
; Set OS_TICK_OC in OS_CFG.H (AND in this file) to 4 to use OUTPUT COMPARE #4
; Set OS_TICK_OC in OS_CFG.H (AND in this file) to 5 to use OUTPUT COMPARE #5
;
; 3) TFLG1, TOC1, TOC2, TOC3, TOC4 and TOC5 are defined in this file.
;********************************************************************************************************
_OSTickISR:
inc _OSIntNesting ; 6~, Notify uC/OS-II about ISR
ldab _OSIntNesting ; 4~, if (OSIntNesting == 1) {
cmpb #$01 ; 2~
bne _OSTickISR1 ; 3~
ldy _OSTCBCur ; 3~, OSTCBCur->OSTCBStkPtr = Stack Pointer
sts 0,y ; 3~, }
_OSTickISR1:
if OS_TICK_OC == 1
ldab #$80 ; 2~, Clear OC1F interrupt flag (bit 7)
stab TFLG1 ; 4~
ldd TOC1 ; 5~, Set TOC1 to present time + desired counts to next ISR
addd #OS_TICK_OC_CNTS ; 4~
std TOC1 ; 5~
endif
if OS_TICK_OC == 2
ldab #$40 ; Clear OC2F interrupt flag (bit 6)
stab TFLG1
ldd TOC2 ; Set TOC2 to present time + desired counts to next ISR
addd #OS_TICK_OC_CNTS
std TOC2
endif
if OS_TICK_OC == 3
ldab #$20 ; Clear OC3F interrupt flag (bit 5)
stab TFLG1
ldd TOC3 ; Set TOC3 to present time + desired counts to next ISR
addd #OS_TICK_OC_CNTS
std TOC3
endif
if OS_TICK_OC == 4
ldab #$10 ; Clear OC4F interrupt flag (bit 4)
stab TFLG1
ldd TOC4 ; Set TOC4 to present time + desired counts to next ISR
addd #OS_TICK_OC_CNTS
std TOC4
endif
if OS_TICK_OC == 5
ldab #$08 ; Clear OC5F interrupt flag (bit 3)
stab TFLG1
ldd TOC5 ; Set TOC5 to present time + desired counts to next ISR
addd #OS_TICK_OC_CNTS
std TOC5
endif
cli ; 2~, Enable interrupts to allow interrupt nesting
jsr _OSTimeTick ; 6~+, Call uC/OS-II's tick updating function
jsr _OSIntExit ; 6~+, Notify uC/OS-II about end of ISR
rti ; 12~, Return from interrupt, no higher priority tasks ready.
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -