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

📄 kernel.s

📁 AVR单片机C语言程序设计实例精粹
💻 S
字号:
	.module Kernel.c
	.area text(rom, con, rel)
	.dbfile E:\Steaven2000\AVR\AVR_Book\PROGRA~1\SOURCE~1\Code\LCD菜单系统设计\Kernel.c
	.dbfunc e OS_Event_Pend _OS_Event_Pend fi
;     wTaskEvent -> R20,R21
;      bTaskPrio -> R16
	.even
_OS_Event_Pend::
	xcall push_gset1
	.dbline -1
	.dbline 29
; //******************************************************************************
; // File Name : Kernel.c
; // Author    : Steaven
; // Created   : 2008-06-09
; // Modified  : 
; // Revision  : V0.0
; //******************************************************************************
; 
; #include "app.h"
; 
; //Task Control Block structure
; typedef struct
; {
; 	INT16U wTimerPeriod;
; 	INT16U wTimerCount;
; 	INT16U wEvent;
; }OS_TCB;
; 
; //structure array definition
; OS_TCB OSTCB[cMaxTask];
; 
; //******************************************************************************
; // Function    : OS_Event_Pend
; // Input       : wTaskPrio - priority of task
; // Output      : event of task
; // Description : Inquiry event of task indexed by priority and then clear it
; //******************************************************************************
; INT16U OS_Event_Pend(INT8U bTaskPrio)
; {
	.dbline 31
; 	INT16U wTaskEvent;
; 	wTaskEvent = OSTCB[bTaskPrio].wEvent;
	ldi R24,6
	mul R24,R16
	movw R30,R0
	ldi R24,<_OSTCB+4
	ldi R25,>_OSTCB+4
	add R30,R24
	adc R31,R25
	ldd R20,z+0
	ldd R21,z+1
	.dbline 32
; 	OSTCB[bTaskPrio].wEvent &= ~wTaskEvent;
	ldi R24,6
	mul R24,R16
	movw R2,R0
	ldi R24,<_OSTCB+4
	ldi R25,>_OSTCB+4
	add R2,R24
	adc R3,R25
	movw R4,R20
	com R4
	com R5
	movw R30,R2
	ldd R6,z+0
	ldd R7,z+1
	and R6,R4
	and R7,R5
	std z+1,R7
	std z+0,R6
	.dbline 33
; 	return(wTaskEvent);
	movw R16,R20
	.dbline -2
L2:
	xcall pop_gset1
	.dbline 0 ; func end
	ret
	.dbsym r wTaskEvent 20 i
	.dbsym r bTaskPrio 16 c
	.dbend
	.dbfunc e OS_Event_Post _OS_Event_Post fV
;     wTaskEvent -> R20,R21
;      bTaskPrio -> R22
	.even
_OS_Event_Post::
	xcall push_gset2
	movw R20,R18
	mov R22,R16
	.dbline -1
	.dbline 44
; }
; 
; //******************************************************************************
; // Function    : OSEventSend
; // Input       : wTaskPrio - priority of task
; //               wTaskEvent - event to be sent                 
; // Output      : none
; // Description : Send an event to task indexed by priority
; //******************************************************************************
; void OS_Event_Post(INT8U bTaskPrio,INT16U wTaskEvent)
; {
	.dbline 45
; 	OSTCB[bTaskPrio].wEvent |= (1 << wTaskEvent);
	ldi R24,6
	mul R24,R22
	movw R2,R0
	ldi R24,<_OSTCB+4
	ldi R25,>_OSTCB+4
	add R2,R24
	adc R3,R25
	ldi R16,1
	ldi R17,0
	movw R18,R20
	xcall lsl16
	movw R30,R2
	ldd R4,z+0
	ldd R5,z+1
	or R4,R16
	or R5,R17
	std z+1,R5
	std z+0,R4
	.dbline -2
	.dbline 46
; }
L5:
	xcall pop_gset2
	.dbline 0 ; func end
	ret
	.dbsym r wTaskEvent 20 i
	.dbsym r bTaskPrio 22 c
	.dbend
	.dbfunc e OS_Task_Create _OS_Task_Create fV
;   wTimerPeriod -> R18,R19
;      bTaskPrio -> R16
	.even
_OS_Task_Create::
	.dbline -1
	.dbline 56
; 
; //******************************************************************************
; // Function    : OS_Task_Create
; // Input       : wTaskPrio - priority of task
; //               wTimerPeriod - period of task
; // Output      : none
; // Description : Set time period of a task to create it
; //******************************************************************************
; void OS_Task_Create(INT8U bTaskPrio,INT16U wTimerPeriod)
; {
	.dbline 57
; 	OSTCB[bTaskPrio].wTimerPeriod = wTimerPeriod;
	ldi R24,6
	mul R24,R16
	movw R30,R0
	ldi R24,<_OSTCB
	ldi R25,>_OSTCB
	add R30,R24
	adc R31,R25
	std z+1,R19
	std z+0,R18
	.dbline -2
	.dbline 58
; }
L7:
	.dbline 0 ; func end
	ret
	.dbsym r wTimerPeriod 18 i
	.dbsym r bTaskPrio 16 c
	.dbend
	.dbfunc e OS_Task_Init _OS_Task_Init fV
;    wTimerCount -> R18,R19
;      bTaskPrio -> R16
	.even
_OS_Task_Init::
	.dbline -1
	.dbline 68
; 
; //******************************************************************************
; // Function    : OS_Task_Start
; // Input       : wTaskPrio - priority of task
; //               wTimerCount - Initial time count of a task
; // Output      : none
; // Description : Set initial time count of a task
; //******************************************************************************
; void OS_Task_Init(INT8U bTaskPrio,INT16U wTimerCount)
; {
	.dbline 69
; 	OSTCB[bTaskPrio].wTimerCount = wTimerCount;
	ldi R24,6
	mul R24,R16
	movw R30,R0
	ldi R24,<_OSTCB+2
	ldi R25,>_OSTCB+2
	add R30,R24
	adc R31,R25
	std z+1,R19
	std z+0,R18
	.dbline -2
	.dbline 70
; }
L8:
	.dbline 0 ; func end
	ret
	.dbsym r wTimerCount 18 i
	.dbsym r bTaskPrio 16 c
	.dbend
	.dbfunc e OS_Task_Switch _OS_Task_Switch fi
;          bTemp -> R20
;      bTaskPrio -> R16
	.even
_OS_Task_Switch::
	xcall push_gset1
	.dbline -1
	.dbline 80
; 
; //******************************************************************************
; // Function    : OS_Task_Switch
; // Input       : wTaskPrio - priority of task
; // Output      : none
; // Description : inquiry the task in ready status.if there's no ready task with
; //               priority higher than current one,the task would run
; //******************************************************************************
; INT16U OS_Task_Switch(INT8U bTaskPrio)
; {
	.dbline 82
; 	INT8U bTemp;
; 	for(bTemp = 0;bTemp < bTaskPrio;bTemp++)
	clr R20
	xjmp L14
L11:
	.dbline 83
; 	{
	.dbline 84
; 		if(OSTCB[bTemp].wEvent != 0)
	ldi R24,6
	mul R24,R20
	movw R30,R0
	ldi R24,<_OSTCB+4
	ldi R25,>_OSTCB+4
	add R30,R24
	adc R31,R25
	ldd R2,z+0
	ldd R3,z+1
	tst R2
	brne X0
	tst R3
	breq L15
X0:
	.dbline 85
; 		{
	.dbline 86
; 			return(true);
	ldi R16,1
	ldi R17,0
	xjmp L10
L15:
	.dbline 88
L12:
	.dbline 82
	inc R20
L14:
	.dbline 82
	cp R20,R16
	brlo L11
	.dbline 89
; 		}
; 	}
; 	return(false);
	clr R16
	clr R17
	.dbline -2
L10:
	xcall pop_gset1
	.dbline 0 ; func end
	ret
	.dbsym r bTemp 20 c
	.dbsym r bTaskPrio 16 c
	.dbend
	.dbfunc e OS_Task_Update _OS_Task_Update fV
;          bTemp -> R20
	.even
_OS_Task_Update::
	xcall push_gset1
	.dbline -1
	.dbline 100
; }
; 
; //******************************************************************************
; // Function    : OS_Task_Update
; // Input       : none
; // Output      : none
; // Description : increase timercount of all tasks in each SYS clock ISR.if task
; //               is timeout,Kernel send a timer event to the task
; //******************************************************************************
; void OS_Task_Update(void)
; {
	.dbline 102
; 	INT8U bTemp;
; 	for(bTemp = 0;bTemp < cMaxTask;bTemp++)
	clr R20
	xjmp L22
L19:
	.dbline 103
; 	{
	.dbline 104
; 		OSTCB[bTemp].wTimerCount++;
	ldi R24,6
	mul R24,R20
	movw R2,R0
	ldi R24,<_OSTCB+2
	ldi R25,>_OSTCB+2
	add R2,R24
	adc R3,R25
	movw R30,R2
	ldd R24,z+0
	ldd R25,z+1
	adiw R24,1
	std z+1,R25
	std z+0,R24
	.dbline 105
; 		if(OSTCB[bTemp].wTimerCount == OSTCB[bTemp].wTimerPeriod)
	ldi R24,6
	mul R24,R20
	ldi R24,<_OSTCB
	ldi R25,>_OSTCB
	movw R30,R0
	add R30,R24
	adc R31,R25
	ldd R2,z+0
	ldd R3,z+1
	ldi R24,<_OSTCB+2
	ldi R25,>_OSTCB+2
	movw R30,R0
	add R30,R24
	adc R31,R25
	ldd R4,z+0
	ldd R5,z+1
	cp R4,R2
	cpc R5,R3
	brne L24
	.dbline 106
; 		{
	.dbline 107
; 			OSTCB[bTemp].wTimerCount = 0;
	ldi R24,6
	mul R24,R20
	movw R30,R0
	ldi R24,<_OSTCB+2
	ldi R25,>_OSTCB+2
	add R30,R24
	adc R31,R25
	clr R2
	clr R3
	std z+1,R3
	std z+0,R2
	.dbline 108
; 			OS_Event_Post(bTemp,0);
	clr R18
	clr R19
	mov R16,R20
	xcall _OS_Event_Post
	.dbline 109
; 		}
L24:
	.dbline 110
L20:
	.dbline 102
	inc R20
L22:
	.dbline 102
	cpi R20,2
	brsh X1
	xjmp L19
X1:
	.dbline -2
	.dbline 111
; 	}
; }
L18:
	xcall pop_gset1
	.dbline 0 ; func end
	ret
	.dbsym r bTemp 20 c
	.dbend
	.dbfunc e OS_Init _OS_Init fV
;          bTemp -> R16
	.even
_OS_Init::
	.dbline -1
	.dbline 120
; 
; //******************************************************************************
; // Function    : OS_Init
; // Input       : none
; // Output      : none
; // Description : Initlization of TCBs
; //******************************************************************************
; void OS_Init(void)
; {
	.dbline 122
; 	INT8U bTemp;
; 	for(bTemp = 0;bTemp < cMaxTask;bTemp++)
	clr R16
	xjmp L32
L29:
	.dbline 123
	.dbline 124
	ldi R24,6
	mul R24,R16
	movw R30,R0
	ldi R24,<_OSTCB
	ldi R25,>_OSTCB
	add R30,R24
	adc R31,R25
	clr R2
	clr R3
	std z+1,R3
	std z+0,R2
	.dbline 125
	ldi R24,6
	mul R24,R16
	movw R30,R0
	ldi R24,<_OSTCB+2
	ldi R25,>_OSTCB+2
	add R30,R24
	adc R31,R25
	std z+1,R3
	std z+0,R2
	.dbline 126
	ldi R24,6
	mul R24,R16
	movw R30,R0
	ldi R24,<_OSTCB+4
	ldi R25,>_OSTCB+4
	add R30,R24
	adc R31,R25
	std z+1,R3
	std z+0,R2
	.dbline 127
L30:
	.dbline 122
	inc R16
L32:
	.dbline 122
	cpi R16,2
	brlo L29
	.dbline -2
	.dbline 128
; 	{
; 		OSTCB[bTemp].wTimerPeriod = 0;
; 		OSTCB[bTemp].wTimerCount = 0;
; 		OSTCB[bTemp].wEvent = 0;
; 	}
; }
L28:
	.dbline 0 ; func end
	ret
	.dbsym r bTemp 16 c
	.dbend
	.dbfunc e OS_Start _OS_Start fV
	.even
_OS_Start::
	.dbline -1
	.dbline 137
; 
; //******************************************************************************
; // Function    : OS_Start
; // Input       : none
; // Output      : none
; // Description : Initlization of tasks and Start Kernel
; //******************************************************************************
; void OS_Start(void)
; {
	.dbline 138
; 	Task_Init();
	xcall _Task_Init
	.dbline 139
; 	Task_Start();
	.dbline -2
	.dbline 140
; }
L35:
	.dbline 0 ; func end
	xjmp _Task_Start
	.dbend
	.area bss(ram, con, rel)
	.dbfile E:\Steaven2000\AVR\AVR_Book\PROGRA~1\SOURCE~1\Code\LCD菜单系统设计\Kernel.c
_OSTCB::
	.blkb 12
	.dbsym e OSTCB _OSTCB A[12:2]X

⌨️ 快捷键说明

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