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

📄 cxskv5m.asm

📁 上传一个带源代码的嵌入式实时多任务操作系统CMX
💻 ASM
📖 第 1 页 / 共 2 页
字号:
;******************************************************
;
;	Copyright (C) 1999
;	CMX Co.
;	680 Worcester Road
;	Framingham, Mass 01702
;
;	All Rights Reserved
;
;	This material is CONFIDENTIAL
;*******************************************************
; VERSION 5.30
; for Tasking -Mm model
$CASE
$DEBUG
$SYMB
$SEGMENTED
$LOCALS
$MODEL(MEDIUM)
	NAME	CXSKV5M
	ASSUME	DPP3:SYSTEM
	
fwlink_pof	equ	00h	;forward wait link
fwlink_pag	equ	02h	
bwlink_pof	equ	04h	;backward wait link
bwlink_pag	equ	06h
ftlink_pof	equ	08h	;forward time link
ftlink_pag	equ	0ah
btlink_pof	equ	0ch	;backward time link
btlink_pag	equ	0eh
tcbstate	equ	10h	;task state    
trig		equ 	12h	;the number of triggers (starts) for task
tsk_priority	equ	13h	;task priority, 0 is highest
tcbtimer	equ	14h	;task countdown delay timer
nxttcb_pof  	equ	16h	;ptr to next TCB (task control block)
nxttcb_pag  	equ	18h	;ptr to next TCB (task control block)
task_addr_sof	equ	1ah	;address of where task's code begins
stk_start_pof  	equ	1ch	;the task's external ram address 
stk_start_pag  	equ	1eh	;of beginning of stack
stk_save_pof  	equ	20h	;the task's external ram address to hold 
stk_save_pag  	equ	22h	;stack address, when context saved


;***************************************************
;
;	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	DPP2:_interrupt_stack:WORD
	EXTERN	DPP2:_locked_out:BYTE
	EXTERN	DPP2:_activetcb:WORD
	EXTERN	DPP2:_active_priority:BYTE
	EXTERN  DPP2:_TSLICE_SCALE:BYTE
	EXTERN  DPP2:_SLICE_ON:BYTE
	EXTERN  DPP2:_tslice_count:BYTE
	EXTERN	DPP2:_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	DPP2:_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

CXSKV5M_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: DPP0 AND DPP2 MAY BE CORRUPTED, MAKE SURE THEY ARE PROPER WHEN USING THEM

; NOTE: for MEDIUM MODEL only
;
; NOTE INTERRUPT 
;	PUSH PSW
;	CSP (SGTDIS = 0)
;	IP 
;
; NOTE: ASSUMED CODE < 64K, DATA > 64K
;
; FAR CALLS ARE 
;
;	CSP 
;	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
	MOV	[-R0],R2
	push	ZEROS	;identify that sched was called, non interrupt
sched_int:
	MOV	[-R0],R3	;save rest of registers
	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	R10,_activetcb
	MOV	DPP0,_activetcb+2
	MOV	[-R0],R4	;STORE COUNT	
	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_pof],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
	MOV	DPP1, #PAG C166_DGROUP	;user stack uses default DATA GROUP
	BFLDH	R0,#0C0H,#40H	;HAVE R0 POINT TO DPP1 (stack page)
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
;	save reg 10 AND DPP0
	PUSH 	DPP0
	PUSH	R10		;save our pointer
	CALLA	cc_UC,_K_I_Timer_Task	;do timer task routine
	POP	R10		;restore active TCB
	POP	DPP0
rescan2:
	jnb 	_cmx_flag1.5,rescan4	;see if interrupt pipe needs servicing
;	save reg 10 AND DPP0
	PUSH 	DPP0
	PUSH	R10		;yes, save active tcb reg
	CALLA	cc_UC,_K_I_Intrp_Pipe_Out	;process interrupt pipe contents
	POP	R10		;restore reg
	POP	DPP0
rescan4:
	jnb 	_cmx_flag1.0,rescan5	;is PREEMPTED flag set, new task?
	MOV	DPP0,#PAG (_cmx_tcb)
	MOV	R10,#POF (_cmx_tcb)	;start at top of list
	BFLDL	_cmx_flag1,#(preempted OR do_coop_sched OR do_time_slice OR slice_enable or idle_flag),#idle_flag
	MOV	R10,[R10+#nxttcb_pof]	;get user's highest priority 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
	JMPR	cc_UC,findready		;get next task in line, able to run
rescan6:
@IF( @SLICE_ENABLE )
	jbc 	_cmx_flag1.2,findready	;should we do a time slice switch
@ENDI
midpaus2:

⌨️ 快捷键说明

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