📄 context.asm
字号:
;*
;==============================================================================
; COPYRIGHT (C) 2004-2006 Haishen Ruan, All rights reserved.
; SUMMARY:
; Timer service.
;
;
; LICENSE INFORMATION
; RS-RTOS is free software; you can redistribute it and/or modify it under
; terms of the GNU General Public License as published by the
; Free Software Foundation; either version 2, or (at your option) any
; later version.
;
; RS-RTOS is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
; General Public License for more details.
;
; You should have received a copy of the GNU General Public License
; along with RS-RTOS; see file COPYING. If not, write to the Free Software
; Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
;
; As a special exception, including RS-RTOS header files in a file,
; instantiating RS-RTOS generics or templates, or linking other files
; with RS-RTOS objects to produce an executable application, does not
; by itself cause the resulting executable application to be covered
; by the GNU General Public License. This exception does not
; however invalidate any other reasons why the executable file might be
; covered by the GNU Public License.
;
;
; DESCRIPTION:
; See http://www.RS-RTOS.org for documentation, latest information, license
; and contact details.
; email:ruanhaishen@gmail.com
;============================================================================*/
;*===========================================================================*/
#include "example/KeilC51/config.h"
#include "arch/C51/inc/mem_model.h"
;Priority of idle task
#define RSI_IDLE_PRIO (CFG_MAX_TASKS - 1)
public __task_fore
extrn code(__do_tick)
extrn code(__schedule)
#if RSI_MEM_MODEL == SMALL
extrn data(_sched_lock)
#elif RSI_MEM_MODEL == COMPACT
extrn xdata(_sched_lock)
#else
extrn xdata(_sched_lock)
#endif
COUNTER EQU 20000
T0H_COUNTER EQU (65536 - COUNTER) / 256
T0L_COUNTER EQU (65536 - COUNTER) - T0H_COUNTER * 256
CSEG AT 000BH
CLR EA
MOV TH0, #T0H_COUNTER
MOV TL0, #T0L_COUNTER
JMP __timer_handle
CSEG AT 0100H
;*===========================================================================*/
;void __task_fore(void)
;{
__task_fore:
; Get argument from stack
MOV A, SP
MOV R0, A
INC R0
INC R0
INC R0
; Save argument to R6 & R7
MOV A, @R0
MOV R6, A
INC R0
MOV A, @R0
MOV R7, A
; Enable interrupt
SETB EA
RET
;}
;*===========================================================================*/
;void __timer_handle(void)
;{
__timer_handle:
PUSH ACC
PUSH B
PUSH PSW
PUSH DPH
PUSH DPL
PUSH 00H
PUSH 01H
PUSH 02H
PUSH 03H
PUSH 04H
PUSH 05H
PUSH 06H
PUSH 07H
; _sched_lock++
#if RSI_MEM_MODEL == SMALL
INC _sched_lock
#elif RSI_MEM_MODEL == COMPACT
MOV R0, #LOW _sched_lock
MOVX A, @R0
INC A
MOVX @R0, A
#else
MOV DPTR, #_sched_lock
MOVX A, @DPTR
INC A
MOVX @DPTR, A
#endif
SETB EA
;================================================
LCALL __do_tick
MOV A, #LOW timer_exit
PUSH ACC
MOV A, #HIGH timer_exit
PUSH ACC
RETI
;================================================
timer_exit:
#if RSI_MEM_MODEL == SMALL
DEC _sched_lock
MOV A, _sched_lock
#elif RSI_MEM_MODEL == COMPACT
MOV R0, #LOW _sched_lock
MOVX A, @R0
DEC A
MOVX @R0, A
#else
MOV DPTR, #_sched_lock
MOVX A, @DPTR
DEC A
MOVX @DPTR, A
#endif
JNZ timer_return
LCALL __schedule
timer_return:
POP 07H
POP 06H
POP 05H
POP 04H
POP 03H
POP 02H
POP 01H
POP 00H
POP DPL
POP DPH
POP PSW
POP B
POP ACC
RET
;}
;*===========================================================================*/
END
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -