1、版本信息
VERSION.A51
NAME RTX51_LIB____VERSION_0V700
2、RTX 51与Keil C51 编程接口
RTX2C51.A51
例如寄存器组、系统上下文、标志位、任务描述表等入口地址:
System-Constants
PUBLIC ?RTX_EXTREGSIZE
; Flags
PUBLIC ?RTX_TS_DELAY, ?RTX_TS_REQ
; Initial-Task-Descriptor Table
PUBLIC ?RTX_TASKCONST
; Table for external to internal task-number conversion
PUBLIC ?RTX_USER_NUM_TABLE
; Shows the interrupts used by ISR-Routines
PUBLIC ?RTX_ISRDESCR
; Taskswitching for Floating-Point Operations
PUBLIC ?RTX_TASKSWITCHING
3、中断
RTXATTA.A51
对函数os_attach_interrupt和os_detach_interrupt的实现
- os_attach_interrupt:
_os_attach_interrupt:
DBG_SYS_ENTRY
RTX_EXCLUDE_INT
SETB ?RTX_SUPERVISOR_MODE ; Supervisor_mode := on
RTX_ALLOW_DRV_INT
RTX_ALLOW_DRV_INT
; Check the input parameter
MOV A, R7
SETB C
SUBB A, #?RTX_MAX_INT_NBR
JC PARA_OK1
; Input parameter is not ok
MOV R7, #NOT_OK
JMP END_ATTACH
- os_detach_interrupt:
_os_detach_interrupt:
DBG_SYS_ENTRY
RTX_EXCLUDE_INT
SETB ?RTX_SUPERVISOR_MODE ; Supervisor_mode := on
; Check the input parameter
MOV A, R7
SETB C
SUBB A, #?RTX_MAX_INT_NBR
JC PARA_OK2
; Input parameter is not ok
MOV R7, #NOT_OK
JMP END_DETACH
4、任务快
RTXBLOCK.A51
这个部分分为:快速任务块、标准任务快。
- 快速任务块:
?RTX?DBLOCK?RTXBLOCK SEGMENT CODE
RSEG ?RTX?DBLOCK?RTXBLOCK
?RTX_DBLOCK:
MOV A, R0 ; save R0
JB ?RTX_RUNNING_TID.1, DBLOCK3
JB ?RTX_RUNNING_TID.0, DBLOCK2
- 标准任务快:
?RTX?NDBLOCK?RTXBLOCK SEGMENT CODE
RSEG ?RTX?NDBLOCK?RTXBLOCK
?RTX_NDBLOCK: MOV A, ?RTX_RUNNING_TID ; Extract standard task
ANL A, #00FH ; (non driver task) no
MOV B, A ; save task-no
MOV A, #LOW(?RTX_KNTXT_PTR_TABLE)
ADD A, B
ADD A, B
MOV DPL, A
MOV DPH, #HIGH(?RTX_KNTXT_PTR_TABLE)
MOVX A, @DPTR
MOV B, A
INC DPL
MOVX A, @DPTR
MOV DPL, A
MOV DPH, B ; DPTR -> kntxt ACC
; Saved context(R7)=NIL_EVENT
MOV A, #NIL_EVENT
INC DPL
MOVX @DPTR, A
; Prepare DPTR-offset for SP
MOV B, #0CH
; Check if save of R6..R4 requested
CJNE R3, #1, STACK_SAV
; Store R6
INC DPL
MOV A, R6
MOVX @DPTR, A
; Store R5
INC DPL
MOV A, R5
MOVX @DPTR, A
; Store R4
INC DPL
MOV A, R4
MOVX @DPTR, A
; Correct DPTR-offset for SP
MOV B, #09H
5、信号的清除
RTXCLEAR.A51
对_os_clear_signal的实现
_os_clear_signal:
DBG_SYS_ENTRY
RTX_EXCLUDE_INT
SETB ?RTX_SUPERVISOR_MODE ; Supervisor_mode := on
RTX_ALLOW_DRV_INT
RTX_EXCLUDE_INT
; Check task-number
MOV A, R7
SETB C
SUBB A, #?RTX_MAXTASKN
JC EVAL_INTERNAL_NUM
; Number is greater than the maximum used task-number
MOV R7, #NOT_OK
JMP END_CLEAR
6、系统时钟
RTXCLK.A51
对系统时钟的初始化以及中断服务
- 设置系统时钟重装载值
SYSCLK_RELOAD MACRO
LOCAL ENDL
GLOBAL_INT_DISABLE
CLR ?RTX_TCONTROL
MOV DPL, #LOW(?RTX_SYS_TICK)
MOV DPH, #HIGH(?RTX_SYS_TICK)
INC DPL ; Get low byte first
MOVX A, @DPTR
ADD A, ?RTX_TLOW
MOV ?RTX_TLOW, A
DEC DPL
MOVX A, @DPTR ; Get high byte
ADDC A, ?RTX_THIGH
MOV ?RTX_THIGH, A
JNC ENDL ; Check if compensate-overflow
; Compensate overflow. Set the timer to -50 for immediate
; Clock-INT
MOV ?RTX_THIGH, #0FFH
MOV ?RTX_TLOW, #0CDH
- 系统时钟初始化
SYSCLK_INIT MACRO
CLR ?RTX_TCONTROL ; Stop timer 0
CLR ?RTX_TFLAG ; Clear int. request
MOV DPH, #HIGH(?RTX_SYS_TICK) ; Get count values
MOV DPL, #LOW(?RTX_SYS_TICK)
MOVX A, @DPTR
MOV ?RTX_THIGH, A ; Load counters
INC DPL
MOVX A, @DPTR
MOV ?RTX_TLOW, A
;
MOV A, ?RTX_TCON ; Set initial values
ANL A, #?RTX_TCON_AND_MASK ; for TCON register
ORL A, #?RTX_TCON_OR_MASK ; (if required)
MOV ?RTX_TCON, A
;
MOV A, ?RTX_TMOD
ANL A, #?RTX_TMOD_AND_MASK ; Use timer 0 as 16
ORL A, #?RTX_TMOD_OR_MASK ; bit timer
MOV ?RTX_TMOD, A
;
SETB ?RTX_TCONTROL ; Enable counting
ENDM
3.系统时钟中断服务
?RTX_SYSCLK_INTHNDLR:
; Check if already in the system-clock handler
JNB ?RTX_SYSCLK_ISR, ENTRY_OK
SETB ?RTX_TFLAG ; re-activate overflow-INT
RETI
- 系统时间片的设置
_os_set_slice:
DBG_SYS_ENTRY
RTX_EXCLUDE_INT
; Check the time slice
CLR C
MOV A,R7
SUBB A,#LOW(CLK_SLICE_MIN)
MOV A,R6
SUBB A,#HIGH(CLK_SLICE_MIN)
JC OSS_1
SETB C
MOV A,R7
SUBB A,#LOW(CLK_SLICE_MAX)
MOV A,R6
SUBB A,#HIGH(CLK_SLICE_MAX)
JC OSS_2
7、任务创建与调度
RTXCREA.A51
对_os_create_task的实现
os_create_task:
DBG_SYS_ENTRY
RTX_EXCLUDE_INT
SETB ?RTX_SUPERVISOR_MODE ; Supervisor_mode := on
RTX_ALLOW_DRV_INT
; Test if the task is not already started
MOV DPH, #HIGH(?RTX_USER_NUM_TABLE)
MOV A, #LOW(?RTX_USER_NUM_TABLE)
ADD A, R7
MOV DPL, A
; DPTR -> user_num_table[user_task_num]
MOVX A, @DPTR
CLR C
SUBB A, #NO_TASK
JZ TASK_OK ; Task does not exist
JMP ERR_EXIT
8、系统数据变量的声明
RTXDATA.A51
包含各种字段的定义、中断向量表、任务就绪表、邮箱和信号量控制块等等
?RTX_DISP_TMP1: DS 1 ; Temp. var. for RTXDISP (do NOT use elsewhere)
?RTX_DISP_TMP2: DS 1 ; Temp. var. for RTXDISP (do NOT use elsewhere)
?RTX_DISP_TMP3: DS 1 ; Temp. var. for RTXDISP (do NOT use elsewhere)
?RTX_DISP_TMP4: DS 1 ; Temp. var. for RTXDISP (do NOT use elsewhere)
?RTX_DISP_TMP5: DS 1 ; Temp. var. for RTXDISP (do NOT use elsewhere)
?RTX_RDY_PRIO0: DS 16 ; Ready list FIFO for prio. = 0
?RTX_RDY_PRIO0_END:
?RTX_RDY_PRIO1: DS 16 ; Ready list FIFO for prio. = 1
?RTX_RDY_PRIO1_END:
?RTX_RDY_PRIO2: DS 16 ; Ready list FIFO for prio. = 2
?RTX_RDY_PRIO2_END:
?RTX_RDY_PRIO3: DS 16 ; Ready list FIFO for prio. = 3
?RTX_RDY_PRIO3_END:
?RTX_INT0_TID: DS 1 ; Interrupt owner list (#=0..15)
?RTX_INT1_TID: DS 1 ;
?RTX_INT2_TID: DS 1 ;
?RTX_INT3_TID: DS 1 ;
?RTX_INT4_TID: DS 1 ;
?RTX_INT5_TID: DS 1 ;
?RTX_INT6_TID: DS 1 ;
?RTX_INT7_TID: DS 1 ;
?RTX_INT8_TID: DS 1 ;
?RTX_INT9_TID: DS 1 ;
?RTX_INT10_TID: DS 1 ;
?RTX_INT11_TID: DS 1 ;
?RTX_INT12_TID: DS 1 ;
?RTX_INT13_TID: DS 1 ;
?RTX_INT14_TID: DS 1 ;
?RTX_INT15_TID: DS 1 ;
9、系统调试
RTXDBG.A51
- 获取所有邮箱状态:
_os_check_mailboxes:
DBG_SYS_ENTRY
RTX_EXCLUDE_INT
SETB ?RTX_SUPERVISOR_MODE ; Supervisor_mode := on
MOV R0, #0 ; R0 -> counter
- 获取已定义邮箱状态:
_os_check_mailbox:
DBG_SYS_ENTRY
RTX_EXCLUDE_INT
SETB ?RTX_SUPERVISOR_MODE ; Supervisor_mode := on
; Check the mailbox-parameter
MOV A, R7
SETB C
SUBB A, #7H
JC MBX_OK
; input parameter not ok
MOV R7, #NOT_OK
JMP CX_END
- 获取所有信息量状态
_os_check_semaphores:
DBG_SYS_ENTRY
RTX_EXCLUDE_INT
SETB ?RTX_SUPERVISOR_MODE ; Supervisor_mode := on
MOV R0, #0 ; R0 = counter
- 获取已定义信息量状态
_os_check_semaphore:
DBG_SYS_ENTRY
RTX_EXCLUDE_INT
SETB ?RTX_SUPERVISOR_MODE ; Supervisor_mode := on
; Check the semaphore parameter
MOV A, R7
JNB ACC.3, SEM_NOTOK
ANL A, #0F0H
JZ SEM_OK
- 获取所有任务状态
_os_check_tasks:
DBG_SYS_ENTRY
RTX_EXCLUDE_INT
SETB ?RTX_SUPERVISOR_MODE ; Supervisor_mode := on
MOV R0, #0 ; R0 -> task-counter
- 获取系统中当前有效任务的状态
_os_check_task:
DBG_SYS_ENTRY
RTX_EXCLUDE_INT
SETB ?RTX_SUPERVISOR_MODE ; Supervisor_mode := on
; Check if valid tasknumber
MOV A, R7
SETB C
SUBB A, #?RTX_MAXTASKN
JC EVAL_INTERNAL_NUM
; Number is greater than the maximum used task-number
MOV R7, #NOT_OK
JMP CHK_TSK_END
- 获取内存池信息
_os_check_pool:
DBG_SYS_ENTRY
RTX_EXCLUDE_INT
SETB ?RTX_SUPERVISOR_MODE ; Supervisor_mode := on
MOV A, R7
ORL A, R6
JNZ CP_INP_OK
MOV R7, #NOT_OK
JMP CP_END
10、总结:
主要简要概述了各个文件的功能以及罗列了功能实现的主要代码,阅读时,打开源码,可参照上面的主要代码进行定位,阅读每个功能的具体实现!