📄 cxskv5t.asm
字号:
;******************************************************
;
; Copyright (C) 1999
; CMX Co.
; 680 Worcester Road
; Framingham, Mass 01702
;
; All Rights Reserved
;
; This material is CONFIDENTIAL
;*******************************************************
; VERSION 5.30
; for Tasking -Mt model
$CASE
$DEBUG
$SYMB
$LOCALS
$MODEL(TINY)
NAME CXSKV5T
fwlink equ 00h ;forward wait link
bwlink equ 02h ;backward wait link
ftlink equ 04h ;forward time link
btlink equ 06h ;backward time link
tcbstate equ 08h ;task state
trig equ 0ah ;the number of triggers (starts) for task
tsk_priority equ 0bh ;task priority, 0 is highest
tcbtimer equ 0ch ;task countdown delay timer
nxttcb equ 0eh ;ptr to next TCB (task control block)
task_addr_sof equ 10h ;address of where task's code begins
stk_start equ 12h ;the task's stack start address
stk_save equ 14h ;the task's stack address after context save
;***************************************************
;
; TASK control flags
;
;***************************************************
; tcbstate high byte, 1'st byte of tcbstate
CMX_IDLE equ 0100h ;task not able to run, no triggers
READY equ 0200h ;the task ready to run
RESUME equ 0400h ;the task ready to run, resume where it left off
RUNNING equ 0800h ;the task is the running task
TIME equ 1000h ;waiting on time
; tcbstate low byte, 2'nd byte of tcbstate
RESOURCE equ 01h ;waiting on resouce
WAIT equ 02h ;waiting
SEND_MESG equ 08h ;waiting for task that recieved message,to wake me
WAIT_MESG equ 10h ;waiting for message
FLAGS equ 20h ;waiting on event
TIME_EXPIRED equ 40h ;the time period specified has ellapsed
SEMAPHORE equ 80h ;waiting for semaphore
extern _timertask:WORD
extern _cmx_tcb:WORD
extern _interrupt_stack:WORD
extern _locked_out:BYTE
extern _activetcb:WORD
extern _active_priority:BYTE
extern _TSLICE_SCALE:BYTE
extern _SLICE_ON:BYTE
extern _tslice_count:BYTE
extern _ie_holder:WORD
extern _K_I_Intrp_Pipe_Out:NEAR
extern _K_I_Timer_Task:NEAR
extern _K_OS_Low_Power_Func:NEAR
BITW SECTION DATA BITADDRESSABLE PUBLIC 'CBITWORDS'
_cmx_flag1 LABEL WORD
DS 1
PUBLIC _cmx_flag1
BITW ENDS
preempted equ 01h ;preempted flag
do_timer_tsk equ 02h ;do timer task flag
do_time_slice equ 04h ;do time slice, next task to slice
slice_enable equ 08h ;time slicing enabled
do_coop_sched equ 10h ;do a cooperative schedule, to NEXT task that can run
do_int_pipe equ 20h ;process interrupt pipe
idle_flag equ 40h ;helps determines power down mode
cmx_active equ 80h ;identifies that CMX RTOS entered
_preempted BIT _cmx_flag1.0
_do_timer_tsk BIT _cmx_flag1.1
_do_time_slice BIT _cmx_flag1.2
_slice_enable BIT _cmx_flag1.3
_do_coop_sched BIT _cmx_flag1.4
_do_int_pipe BIT _cmx_flag1.5
_idle_flag BIT _cmx_flag1.6
_cmx_active BIT _cmx_flag1.7
@SET (ADD_NOP,1) ;set to 1, to add 2 NOP's after BCLR IEN
;(fixes some 166 silicon)
@SET (FIX166,1) ;set to 1, to add BFLDH PSW,#0F0H,0F0H; NOP; NOP
;preceeding RETI instructions (fixes some 166 silicon)
@SET( LOW_POWER_ACTIVE, 0 ) ;set to non zero, if power down mode wanted
;see code that test this variable
@SET (SLICE_ENABLE,1) ;set to 1, to include time slicing code
@SET (INT_ENABLE,0) ;set to 1, to select the ability to have the
;K_I_Scheduler disable interrupts up to a certain
;priority level. Note that interrupts above this
;level will NOT be mask out, so those interrupts
;can NOT use CMX in any fashion in most cases.
INT_LEVEL equ 8 ;ILVL level (0 - 15 decimal) or (0h - 0Fh hex)
@SET (CMXTRACKER_ENABLE,0) ;SET TO 1 IF USING CMXTRACKER, otherwise 0
@IF( @CMXTRACKER_ENABLE )
EXTERN _previoustcb:WORD
EXTERN _cmxtracker_in_task:NEAR
@ENDI
; NOTE: The BSO/Tasking software (version 3 and 4.0) have INCORRECT
; CODE as far as the FPPUSHUS and FPPOPUS functions. This means that
; even though CMX will attempt to properly save and restore the floating
; point stack, it will NOT be properly restored, for the BSO code
; MUST BE FIXED. We have placed this switch here, so when BSO fixes
; their functions, then the user CAN use floating point arithmetic.
@SET (FLOAT_ENABLE,0) ;set to 1, to have floating point stack saved and
;restored. PLEASE see above note.
@SET (Ff_ENABLE,0) ;set to 1, if interrupt uses the floating point stack
;fppushus and fppopus. Implies the -Ff option is being used.
;Note that each interrupt must have this option enabled, unless
;the "Pragma noframe" is being used.
@IF( @FLOAT_ENABLE )
EXTERN __fppushus:NEAR
EXTERN __fppopus:NEAR
@ELSE
@SET (Ff_ENABLE,0) ;DO NOT TOUCH! Force Ff_enable back to zero
@ENDI
;For some reason, Tasking is in release 6.0, r1 potentially PUSHING the
;the PSW. We are not sure why. Please see the next switch setting if
;you are using 6.0, r1.
@SET (PSW_INT_PUSH,0) ;set to 1, to have you have Version 6.0 r1 and are
;using compiler switches that generate a "PUSH PSW"
;within the interrupt prologue code. You will need
;to check the listing of the compiler generated output.
; In version 6.0 r5 Tasking switched the order MDH and MDL were pushed in
; the ISR entry code. MDH is pushed first then MDL in v6.0r5.
@SET (MDH_PUSHED_FIRST,1) ;set to 1, if you have Version 6.0 r5 and above.
FAKE_RETI LIT "DB 0FBh,088h" ;This will suppress the warnings that the TASKING assembler
;would flag, if a RETI instruction was within a PROCEDURE
CXSKV5T_PR SECTION CODE WORD PUBLIC 'CPROGRAM'
GLOBAL _K_OS_Intrp_Exit_No_Frame
GLOBAL _K_OS_Intrp_Exit
GLOBAL _K_OS_Enable_Interrupts
GLOBAL _K_OS_Disable_Interrupts
GLOBAL _K_OS_Save_Interrupts
GLOBAL _K_OS_Restore_Interrupts
PUBLIC _K_I_Sched
PUBLIC _K_I_Scheduler
PUBLIC _preempted
PUBLIC _do_timer_tsk
PUBLIC _do_time_slice
PUBLIC _slice_enable
PUBLIC _do_coop_sched
PUBLIC _do_int_pipe
PUBLIC _idle_flag
PUBLIC _cmx_active
; NOTE: USER STACK POINTER IS R0
; FOR LARGE AND MEDIUM MODEL DPP1 IS USED WITH R0 FOR USER STACK POINTER
; NOTE: for TINY MODEL only
;
; NOTE INTERRUPT
; PUSH PSW NOTE: SGTDIS = 1
; IP
;
; NOTE: ASSUMED CODE < 64K, DATA < 64K
;
; NEAR CALLS ARE
;
; IP
;
copyright db 'Copyright (c) 1999 CMX-RTX RTOS, CMX Company.'
db 'All rights reserved'
EVEN
_K_I_Sched PROC NEAR
push PSW ;save psw
MOV [-R0],R1 ;save reg 1 & 2
MOV [-R0],R2
push ZEROS ;identify that sched was called, non interrupt
sched_int:
MOV [-R0],R3
MOV [-R0],R4 ;save ALL REGISTERS
MOV [-R0],R5
MOV [-R0],R6
MOV [-R0],R7
MOV [-R0],R8
MOV [-R0],R9
MOV [-R0],R10
MOV [-R0],R11
MOV [-R0],R12
MOV [-R0],R13
MOV [-R0],R14
MOV [-R0],R15
@IF( @FLOAT_ENABLE )
CALLA cc_UC,__fppushus
@ENDI
; now save system stack contents
mov r2,#?SYSSTACK_TOP
sub r2,sp ;r2 contains count
MOV R4,R2 ;SAVE COUNT
save_loop:
pop r1 ;save SYSTEM stack contents
MOV [-R0],R1
sub r2,#2
JMPR cc_NZ,save_loop
MOV [-R0],R4 ;STORE COUNT
MOV R10,_activetcb ;get active task TCB
MOV R5,[R10+ #tcbstate] ;get current active task's state
jb r5.11,set_resume ;see if task was running
MOVB _active_priority,ONES ;set priority to lowest.
JMPR cc_UC,sched_cont
set_resume:
BFLDH R5,#1EH,#04H ;yes, so set flag indicating the task should
;finish its code, because the interrupt
;preempted it
mov [R10+ #tcbstate],R5 ;save task's new state
sched_cont:
mov [R10 + #stk_save],r0 ;save task's current stack address
_K_I_Scheduler:
@IF( @INT_ENABLE )
BFLDH PSW,#0F0H,#(INT_LEVEL << 4)
@ELSE
BCLR IEN ;turn interrupts off
@ENDI
@IF( @ADD_NOP )
NOP ;These 2 NOP's fix the 80C16x silicon
NOP
@ENDI
MOV SP,#?SYSSTACK_TOP ; Set stack pointer.
MOV R0,_interrupt_stack ;really only used for timer task and
;pipe action task
sched_again:
;
@IF( @INT_ENABLE )
BFLDH PSW,#0F0H,#00h
@ELSE
BSET IEN ;turn interrupts ON
@ENDI
rescan1:
jnb _cmx_flag1.1,rescan2 ;see if timer task needs servicing
bclr _cmx_flag1.1 ;yes, clear bit
PUSH R10 ;save our pointer
CALLA cc_UC,_K_I_Timer_Task ;go service timers
POP R10 ;restore active TCB
rescan2:
jnb _cmx_flag1.5,rescan4 ;see if interrupt pipe needs servicing
PUSH R10 ;yes, save active tcb reg
CALLA cc_UC,_K_I_Intrp_Pipe_Out ;go process interrupt pipe contents
POP R10 ;restore reg
rescan4:
jnb _cmx_flag1.0,rescan5 ;is PREEMPTED flag set, new task?
BFLDL _cmx_flag1,#(preempted OR do_coop_sched OR do_time_slice OR slice_enable or idle_flag),#idle_flag
MOV R10,#_cmx_tcb ;set r10 to CMX timer task
MOV R10,[R10 + #nxttcb] ;set r10 to highest priority user task
JMPR cc_UC,midpaus2 ;now go test task's state
rescan5:
jnb _cmx_flag1.4,rescan6 ;is COOPERATIVE sched flag set
BFLDL _cmx_flag1,#(do_coop_sched OR do_time_slice OR slice_enable),#00h
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -