RTX 51 FULL源码学习(2.2)

1、删除任务

RTXDELET.A51
对_os_delete_task的实现:从任务列表里删除需要删除的任务号并返回操作结果

_os_delete_task:
               DBG_SYS_ENTRY
               RTX_EXCLUDE_INT
               SETB  ?RTX_SUPERVISOR_MODE       ; Supervisor_mode := on
               ; 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_TERM

2、任务调度器

RTXDISP.A51
根据任务就绪表裁决执行任务切换

?RTX_REDISPATCH:
               ; Check if already deallocated
               JB    ?RTX_PROCESSOR_ALLOCATED, ALLOC
               ;       Processor is DEALLOCATED
               ; Clear redispatch request
               CLR   ?RTX_REQ_REDISPATCH
               ; Check if a fast task (=driver task) is ready to execute
               MOV   A, ?RTX_RDY_COUNT3
               JNZ   READY_DRIVER               ; short-cut if yes
               ; Use standard task (=non driver task) stack if processor 
               ; is deallocated
               MOV   SP, #?STACK-1
               ; Use reg.bank 0, SV_mode on
               MOV   PSW, #00H
               SETB  ?RTX_SUPERVISOR_MODE
               RTX_ALLOW_DRV_INT
               JMP   ASSIGN

3、终端的启用与禁止

RTXENABL.A51
主要是对_os_enable_isr、_os_disable_isr的实现,在执行不能强行被系统中断的任务时,需要对该任务进行保护。

测试:
CHECK_INPUT_PARA:
               MOV   A, R7
               SETB  C
               SUBB  A, #?RTX_MAX_INT_NBR
               JC    PARA_OK
               ; Input parameter is not ok
               MOV   A, #1
               RET
系统中断使能
_os_enable_isr:
               DBG_SYS_ENTRY
               RTX_EXCLUDE_INT
               SETB  ?RTX_SUPERVISOR_MODE        ; Supervisor_mode := on
               POP   ?RTX_TMP1                   ; Make free 2 Bytes for
               POP   ?RTX_TMP2                   ; subroutine call
               CALL  CHECK_INPUT_PARA
               PUSH  ?RTX_TMP2
               PUSH  ?RTX_TMP1
               JZ    ALL_OK1
               MOV   R7, #NOT_OK
               JMP   END_ENABLE
禁止系统中断
_os_disable_isr:
               DBG_SYS_ENTRY
               RTX_EXCLUDE_INT
               SETB  ?RTX_SUPERVISOR_MODE        ; Supervisor_mode := on
               POP   ?RTX_TMP1                   ; Make free 2 Bytes for
               POP   ?RTX_TMP2                   ; subroutine call
               CALL  CHECK_INPUT_PARA
               PUSH  ?RTX_TMP2
               PUSH  ?RTX_TMP1
               JZ    ALL_OK2
               MOV   R7, #NOT_OK
               JMP   END_DISABLE

4、中断服务子程

RTXIHAND.A51
在中断服务子程中完成信号、消息发送、检查非完全等待任务的检查

信号量发送
?RTX_HANDLE_ISR_SEND_SIG:
               ; Evaluate the internal Task-Number
               MOV   DPH, #HIGH(?RTX_USER_NUM_TABLE)
               MOV   A, #LOW(?RTX_USER_NUM_TABLE)
               ADD   A, R0
               MOV   DPL, A
               ; DPTR -> user_num_table[user_num]
               MOVX  A, @DPTR
               CJNE  A, #NO_TASK, TASK_FOUND
               RET
消息发送
?RTX_HANDLE_ISR_SEND_MES:
               MOV   A, R0                      ; Get mailbox number param.
               SWAP  A
               RR    A                          ; ACC := 8 * mailbox nr.
               ADD   A, #LOW(?RTX_MBX_CONTROL_BASE)
               MOV   DPL, A
               MOV   DPH, #HIGH(?RTX_MBX_CONTROL_BASE) ; DPTR --> MBX#_COUNT
               GLOBAL_INT_DISABLE
               MOVX  A, @DPTR                   ; Get MBX#_COUNT
               ; Check if any tasks are waiting for messages
               JB    ACC.7, TASKS_WAIT          ; Jump if tasks wait (count<0)
非完全等待任务检查
?RTX_HANDLE_NF_CHECK_REQ:
               MOV   A, R0                      ; Get mailbox number param.
               SWAP  A
               RR    A                          ; ACC := 8 * mailbox nr.
               ADD   A, #LOW(?RTX_MBX_CONTROL_BASE)
               MOV   DPL, A
               MOV   DPH, #HIGH(?RTX_MBX_CONTROL_BASE)
               INC   DPL
                ; Check if any tasks wait for non full message list
	        MOVX  A, @DPTR
	        JNZ   TWAIT   ; Jump if MBX#_TCOUNT > 0
               RET

5、系统初始化

RTXINIT.A51
初始化系统变量及向量表,调用_os_start_system,并移交控制权给第一个任务

_os_start_system:
               DBG_BUSY
               CALL  ?RTX_INIT_INT_REG_FLAGS    ; Initialize the int. enable
                                                ; register bits
               ; Set interrupt masks to disable all interrupts
               MOV   ?RTX_NM_IE, #0
               JNB   ?RTX_ENA_INT_REG1, IBIT_INIT_DONE
               MOV   ?RTX_NM_IE1, #0
               JNB   ?RTX_ENA_INT_REG2, IBIT_INIT_DONE
               MOV   ?RTX_NM_IE2, #0
 IBIT_INIT_DONE:
               RTX_EXCLUDE_INT

6、插入任务到就绪表

RTXINS.A51
将就绪任务id登记到任务就绪表

?RTX?INSERT_RDY_PRIO?RTXIHAND   SEGMENT CODE
                                RSEG    ?RTX?INSERT_RDY_PRIO?RTXIHAND
?RTX_INSERT_RDY_PRIO:
               MOV   DPH,#HIGH(?RTX_SYS_PAGE)      ; Select RAM page 0
               JB    ACC.7, PRIO23                 ; Insert task_id in
               JB    ACC.6, PRIO1                  ; correct prio. FIFO                                

7、中断处理

RTXINT.A51

?RTX_INT_HANDLER:
               DBG_SYS_ENTRY
               RTX_EXCLUDE_INT
               DBG_BUSY; Reset hardware prio. flip-flop
               CALL  ?RTX_RESET_I_F_F
               MOV   ?RTX_TMP2, R0              ; Save R0,R1,DPH,DPL and PSW
               MOV   ?RTX_TMP3, R1              ; ACC alrady saved by RTXVEC#
               MOV   ?RTX_TMP4, PSW
               MOV   ?RTX_TMP5, DPH
               MOV   ?RTX_TMP6, DPL
               MOV   DPL, A
               ; Get task id from int. table and store in ?RTX_TMP0
               MOV   DPH, #HIGH(?RTX_INT_TID_TABLE_BASE)
               ; DPTR-->int_tid[vector no]
               MOVX  A, @DPTR                   ; Get int. task_id from table
               MOV   ?RTX_TMP0, A
               ; Set up ptr to state_table[task no]
               ANL   A, #01FH
               RL    A
               RL    A
               ADD   A, #LOW(?RTX_STATE_TABLE)
               MOV   DPL, A                     ; DPTR-->state_table[task_no]
                                                ; ?RTX_TMP0 contains task id
               CALL  ?RTX_TMO_DEQUEUE
                                                ; DPTR, ?RTX_TMP0 preserved
               CALL  ?RTX_INTSIG_DEQUEUE
                                                ; DPTR, ?RTX_TMP0 preserved
               CALL  ?RTX_MSG_DEQUEUE
               JZ    MSGDEQDONE                 ; Eval ret code if deq done
                                                ; DPTR preserved if no deq done
               CALL  ?RTX_SEM_DEQUEUE           ; ?RTX_TMP0 preserved
?RTX?RESET_I_F_F?RTXINT  SEGMENT CODE
                         RSEG    ?RTX?RESET_I_F_F?RTXINT
                         ?RTX_RESET_I_F_F:    RETI
                         ;
;   END OF MODULE
;
 END

8、消息接收

RTXIRECV.A51
对_isr_recv_message的实现

_isr_recv_message:
               DBG_SYS_ENTRY
               ; Check the mailbox-parameter
               MOV   A, R7
               SETB  C
               SUBB  A, #7H
               JC    MBX_OK2
               ; Mailbox-Nbr is not ok
               MOV   R7, #NOT_OK
               DBG_SYS_EXIT
               RET

9、信号、消息发送

RTXISEND.A51

_isr_send_signal:
               DBG_SYS_ENTRY
               ; 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
               DBG_SYS_EXIT
               RET
_isr_send_message:
               DBG_SYS_ENTRY
               ; Check the mailbox-parameter
               MOV   A, R7
               SETB  C
               SUBB  A, #7H
               JC    MBX_OK
               ; Mailbox-Nbr is not ok
               MOV   R7, #NOT_OK
               DBG_SYS_EXIT
               RET

10、中断标志设置与复位

RTXISET.A51

_oi_set_int_masks:
               DBG_SYS_ENTRY
               GLOBAL_INT_DISABLE
               MOV   A, R7
               ORL   A, #80H              ; To be sure IE-Bit is set
               ORL   ?RTX_NM_IE, A
               ORL   ?RTX_D_IE, A
               ORL   ?RTX_ND_IE, A
               ANL   A, #7FH              ; To be sure IE-Bit is not set
               ORL   ?RTX_IE, A
               JNB   ?RTX_ENA_INT_REG1, END_SET
               MOV   A, R5
               ORL   ?RTX_NM_IE1, A
               ORL   ?RTX_D_IE1, A
               ORL   ?RTX_ND_IE1, A
               ORL   ?RTX_IEN1, A
               JNB   ?RTX_ENA_INT_REG2, END_SET
               MOV   A, R3
               ORL   ?RTX_NM_IE2, A
               ORL   ?RTX_D_IE2, A
               ORL   ?RTX_ND_IE2, A
               ORL   ?RTX_IEN2, A
_oi_reset_int_masks:
               DBG_SYS_ENTRY
               GLOBAL_INT_DISABLE
               MOV   A, R7
               CPL   A
               ORL   A, #80H              ; To be sure IE-Bit is set
               ANL   ?RTX_NM_IE, A
               ANL   ?RTX_D_IE, A
               ANL   ?RTX_ND_IE, A
               ANL   A, #7FH              ; To be sure IE-Bit is not set
               ANL   ?RTX_IE, A
               JNB   ?RTX_ENA_INT_REG1, END_RESET
               MOV   A, R5
               CPL   A
               ANL   ?RTX_NM_IE1, A
               ANL   ?RTX_D_IE1, A
               ANL   ?RTX_ND_IE1, A
               ANL   ?RTX_IEN1, A
               JNB   ?RTX_ENA_INT_REG2, END_RESET
               MOV   A, R3
               CPL   A
               ANL   ?RTX_NM_IE2, A
               ANL   ?RTX_D_IE2, A
               ANL   ?RTX_ND_IE2, A
               ANL   ?RTX_IEN2, A
展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 数字20 设计师: CSDN官方博客
应支付0元
点击重新获取
扫码支付

支付成功即可阅读