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

📄 os_task.s

📁 使用mega8和iccavr编译器的一段ucos操作系统程序
💻 S
字号:
	.module os_task.c
	.area text(rom, con, rel)
	.dbfile G:\IccPro\ucos_m8_icc\source\os_task.c
	.dbfunc e OSTaskStkInit _OSTaskStkInit fpc
;           stks -> R14,R15
;            tmp -> R12,R13
;            stk -> R10,R11
;            opt -> y+8
;           ptos -> y+6
;          pdata -> R18,R19
;           task -> R16,R17
	.even
_OSTaskStkInit::
	rcall push_gset5x
	.dbline -1
	.dbline 47
; 
; #ifndef  OS_MASTER_FILE
; #include "includes.h"
; #endif
; 
; /*$PAGE*/
; /*
; *********************************************************************************************************
; *                                            CREATE A TASK
; *
; * Description: This function is used to have uC/OS-II manage the execution of a task.  Tasks can either
; *              be created prior to the start of multitasking or by a running task.  A task cannot be
; *              created by an ISR.
; *
; * Arguments  : task     is a pointer to the task's code
; *
; *              pdata    is a pointer to an optional data area which can be used to pass parameters to
; *                       the task when the task first executes.  Where the task is concerned it thinks
; *                       it was invoked and passed the argument 'pdata' as follows:
; *
; *                           void Task (void *pdata)
; *                           {
; *                               for (;;) {
; *                                   Task code;
; *                               }
; *                           }
; *
; *              ptos     is a pointer to the task's top of stack.  If the configuration constant 
; *                       OS_STK_GROWTH is set to 1, the stack is assumed to grow downward (i.e. from high
; *                       memory to low memory).  'pstk' will thus point to the highest (valid) memory 
; *                       location of the stack.  If OS_STK_GROWTH is set to 0, 'pstk' will point to the 
; *                       lowest memory location of the stack and the stack will grow with increasing
; *                       memory locations.
; *
; *              prio     is the task's priority.  A unique priority MUST be assigned to each task and the
; *                       lower the number, the higher the priority.
; *
; * Returns    : OS_NO_ERR        if the function was successful.
; *              OS_PRIO_EXIT     if the task priority already exist 
; *                               (each task MUST have a unique priority).
; *              OS_PRIO_INVALID  if the priority you specify is higher that the maximum allowed 
; *                               (i.e. >= OS_LOWEST_PRIO)
; *********************************************************************************************************
; */
; 
; #if OS_TASK_CREATE_EN
; OS_STK *OSTaskStkInit (void (*task)(void *pd), void *pdata, OS_STK *ptos, INT16U opt){
	.dbline 54
; 
;     INT8U  *stk;
;     INT8U  *stks;		// Temp. variable used for setting up AVR hardware stack
;     INT16U tmp;
; 
; 
;     opt     = opt;			// 'opt' is not used, prevent warning
	.dbline 55
;     stk     = (INT8U *)ptos;		// Wandlung von ptos in Bytezeiger
	ldd R10,y+6
	ldd R11,y+7
	.dbline 57
; 	// AVR return stack ("hardware stack")
;     stks    = (INT8U *)(ptos)-(OS_TASK_DEF_STK_SIZE-32);
	movw R24,R10
	subi R24,68
	sbci R25,0
	.dbline 62
; 
; 	// the function address has an extra level of indirection. Fetch the
;     // actual address.
;     //    
;     tmp = *(INT16U const *)task;
	movw R30,R16
	lpm R12,Z+
	lpm R13,Z
	.dbline 65
;    
; 	// 36 Bytes
;     *stks-- = (INT8U)tmp;	//Put task start address on top of hardware stack
	movw R2,R24
	sbiw R24,1
	movw R30,R2
	std z+0,R12
	.dbline 66
;     *stks-- = (INT8U)(tmp >> 8);
	movw R2,R24
	sbiw R24,1
	movw R14,R24
	movw R4,R12
	mov R4,R5
	clr R5
	movw R30,R2
	std z+0,R4
	.dbline 68
; 
;     *stk-- = (INT8U)0x00;		// R0  = 0x00
	movw R2,R10
	movw R24,R2
	sbiw R24,1
	clr R4
	movw R30,R2
	std z+0,R4
	.dbline 69
;     *stk-- = (INT8U)0x01; 
	movw R2,R24
	sbiw R24,1
	movw R10,R24
	ldi R24,1
	movw R30,R2
	std z+0,R24
	.dbline 70
;     *stk-- = (INT8U)0x02;
	movw R2,R10
	movw R24,R2
	sbiw R24,1
	movw R10,R24
	ldi R24,2
	movw R30,R2
	std z+0,R24
	.dbline 71
;     *stk-- = (INT8U)0x03;
	movw R2,R10
	movw R24,R2
	sbiw R24,1
	movw R10,R24
	ldi R24,3
	movw R30,R2
	std z+0,R24
	.dbline 72
;     *stk-- = (INT8U)0x04;
	movw R2,R10
	movw R24,R2
	sbiw R24,1
	movw R10,R24
	ldi R24,4
	movw R30,R2
	std z+0,R24
	.dbline 73
;     *stk-- = (INT8U)0x05;
	movw R2,R10
	movw R24,R2
	sbiw R24,1
	movw R10,R24
	ldi R24,5
	movw R30,R2
	std z+0,R24
	.dbline 74
;     *stk-- = (INT8U)0x06;
	movw R2,R10
	movw R24,R2
	sbiw R24,1
	movw R10,R24
	ldi R24,6
	movw R30,R2
	std z+0,R24
	.dbline 75
;     *stk-- = (INT8U)0x07;
	movw R2,R10
	movw R24,R2
	sbiw R24,1
	movw R10,R24
	ldi R24,7
	movw R30,R2
	std z+0,R24
	.dbline 76
;     *stk-- = (INT8U)0x08;
	movw R2,R10
	movw R24,R2
	sbiw R24,1
	movw R10,R24
	ldi R24,8
	movw R30,R2
	std z+0,R24
	.dbline 77
;     *stk-- = (INT8U)0x09;
	movw R2,R10
	movw R24,R2
	sbiw R24,1
	movw R10,R24
	ldi R24,9
	movw R30,R2
	std z+0,R24
	.dbline 78
;     *stk-- = (INT8U)0x10;
	movw R2,R10
	movw R24,R2
	sbiw R24,1
	movw R10,R24
	ldi R24,16
	movw R30,R2
	std z+0,R24
	.dbline 79
;     *stk-- = (INT8U)0x11;
	movw R2,R10
	movw R24,R2
	sbiw R24,1
	movw R10,R24
	ldi R24,17
	movw R30,R2
	std z+0,R24
	.dbline 80
;     *stk-- = (INT8U)0x12;
	movw R2,R10
	movw R24,R2
	sbiw R24,1
	movw R10,R24
	ldi R24,18
	movw R30,R2
	std z+0,R24
	.dbline 81
;     *stk-- = (INT8U)0x13;
	movw R2,R10
	movw R24,R2
	sbiw R24,1
	movw R10,R24
	ldi R24,19
	movw R30,R2
	std z+0,R24
	.dbline 82
;     *stk-- = (INT8U)0x14;
	movw R2,R10
	movw R24,R2
	sbiw R24,1
	movw R10,R24
	ldi R24,20
	movw R30,R2
	std z+0,R24
	.dbline 83
;     *stk-- = (INT8U)0x15;
	movw R2,R10
	movw R24,R2
	sbiw R24,1
	movw R10,R24
	ldi R24,21
	movw R30,R2
	std z+0,R24
	.dbline 84
;     tmp    = (INT16U)pdata;
	movw R12,R18
	.dbline 85
;     *stk-- = (INT8U)tmp;	//Simulate call to function with argument
	movw R2,R10
	movw R24,R2
	sbiw R24,1
	movw R30,R2
	std z+0,R12
	.dbline 86
;     *stk-- = (INT8U)(tmp >> 8);
	movw R2,R24
	sbiw R24,1
	movw R4,R12
	mov R4,R5
	clr R5
	movw R30,R2
	std z+0,R4
	.dbline 87
;     *stk-- = (INT8U)0x18;
	movw R2,R24
	sbiw R24,1
	movw R10,R24
	ldi R24,24
	movw R30,R2
	std z+0,R24
	.dbline 88
;     *stk-- = (INT8U)0x19;
	movw R2,R10
	movw R24,R2
	sbiw R24,1
	movw R10,R24
	ldi R24,25
	movw R30,R2
	std z+0,R24
	.dbline 89
;     *stk-- = (INT8U)0x20;
	movw R2,R10
	movw R24,R2
	sbiw R24,1
	movw R10,R24
	ldi R24,32
	movw R30,R2
	std z+0,R24
	.dbline 90
;     *stk-- = (INT8U)0x21;
	movw R2,R10
	movw R24,R2
	sbiw R24,1
	movw R10,R24
	ldi R24,33
	movw R30,R2
	std z+0,R24
	.dbline 91
;     *stk-- = (INT8U)0x22;
	movw R2,R10
	movw R24,R2
	sbiw R24,1
	movw R10,R24
	ldi R24,34
	movw R30,R2
	std z+0,R24
	.dbline 92
;     *stk-- = (INT8U)0x23;
	movw R2,R10
	movw R24,R2
	sbiw R24,1
	movw R10,R24
	ldi R24,35
	movw R30,R2
	std z+0,R24
	.dbline 93
;     *stk-- = (INT8U)0x24;
	movw R2,R10
	movw R24,R2
	sbiw R24,1
	movw R10,R24
	ldi R24,36
	movw R30,R2
	std z+0,R24
	.dbline 94
;     *stk-- = (INT8U)0x25;
	movw R2,R10
	movw R24,R2
	sbiw R24,1
	movw R10,R24
	ldi R24,37
	movw R30,R2
	std z+0,R24
	.dbline 95
;     *stk-- = (INT8U)0x26;
	movw R2,R10
	movw R24,R2
	sbiw R24,1
	movw R10,R24
	ldi R24,38
	movw R30,R2
	std z+0,R24
	.dbline 96
;     *stk-- = (INT8U)0x27;
	movw R2,R10
	movw R24,R2
	sbiw R24,1
	movw R10,R24
	ldi R24,39
	movw R30,R2
	std z+0,R24
	.dbline 98
; 	// the heap pointer Y=R29:R28 will not be stored
;     *stk-- = (INT8U)0x30;
	movw R2,R10
	movw R24,R2
	sbiw R24,1
	movw R10,R24
	ldi R24,48
	movw R30,R2
	std z+0,R24
	.dbline 99
;     *stk-- = (INT8U)0x31;
	movw R2,R10
	movw R24,R2
	sbiw R24,1
	movw R10,R24
	ldi R24,49
	movw R30,R2
	std z+0,R24
	.dbline 101
; //    *stk-- = (INT8U)0x3B;
;     *stk-- = (INT8U)0x80;	//SREG = Interrupts enabled
	movw R2,R10
	movw R24,R2
	sbiw R24,1
	movw R10,R24
	ldi R24,128
	movw R30,R2
	std z+0,R24
	.dbline 103
; 
;     tmp    = (INT16U)(stks);
	movw R12,R14
	.dbline 104
;     *stk-- = (INT8U)(tmp >> 8);
	movw R2,R10
	movw R24,R2
	sbiw R24,1
	movw R10,R24
	movw R4,R12
	mov R4,R5
	clr R5
	movw R30,R2
	std z+0,R4
	.dbline 105
;     *stk   = (INT8U)(tmp);
	movw R30,R24
	std z+0,R12
	.dbline 106
;     return ((void *)stk);
	movw R16,R24
	.dbline -2
L2:
	rcall pop_gset5x
	.dbline 0 ; func end
	ret
	.dbsym r stks 14 pc
	.dbsym r tmp 12 i
	.dbsym r stk 10 pc
	.dbsym l opt 8 i
	.dbsym l ptos 6 pc
	.dbsym r pdata 18 pV
	.dbsym r task 16 pfV
	.dbend
	.dbfunc e OSTaskCreate _OSTaskCreate fc
;            psp -> R10,R11
;            err -> R10
;           prio -> R12
;           ptos -> y+16
;          pdata -> R14,R15
;           task -> R10,R11
	.even
_OSTaskCreate::
	rcall push_gset5x
	movw R14,R18
	movw R10,R16
	sbiw R28,10
	ldd R12,y+18
	.dbline -1
	.dbline 110
; }
; 
; INT8U OSTaskCreate (void (*task)(void *pd), void *pdata, OS_STK *ptos, INT8U prio)
; {
	.dbline 115
;     void   *psp;
;     INT8U   err;
; 
; 
;     if (prio > OS_LOWEST_PRIO) {             /* Make sure priority is within allowable range           */
	ldi R24,15
	cp R24,R12
	brsh L4
	.dbline 115
	.dbline 116
;         return (OS_PRIO_INVALID);
	ldi R16,42
	rjmp L3
L4:
	.dbline 118
;     }
;     OS_ENTER_CRITICAL();
	st -y,r16
	in r16,0x3F
	cli
	push r16
	ld r16,y+
	.dbline 118
	.dbline 119
;     if (OSTCBPrioTbl[prio] == (OS_TCB *)0) { /* Make sure task doesn't already exist at this priority  */
	ldi R24,2
	mul R24,R12
	movw R30,R0
	ldi R24,<_OSTCBPrioTbl
	ldi R25,>_OSTCBPrioTbl
	add R30,R24
	adc R31,R25
	ldd R2,z+0
	ldd R3,z+1
	tst R2
	breq X1
	rjmp L6
X1:
	tst R3
	breq X2
	rjmp L6
X2:
X0:
	.dbline 119
	.dbline 120
;         OSTCBPrioTbl[prio] = (OS_TCB *)1;    /* Reserve the priority to prevent others from doing ...  */
	ldi R24,2
	mul R24,R12
	movw R30,R0
	ldi R24,<_OSTCBPrioTbl
	ldi R25,>_OSTCBPrioTbl
	add R30,R24
	adc R31,R25
	ldi R24,1
	ldi R25,0
	std z+1,R25
	std z+0,R24
	.dbline 122
;                                              /* ... the same thing until task is created.              */
;         OS_EXIT_CRITICAL();
	st -y,r16
	pop r16
	out 0x3F,r16
	ld r16,y+
	.dbline 122
	.dbline 123
;         psp = (void *)OSTaskStkInit(task, pdata, ptos, 0); /* Initialize the task's stack              */
	clr R2
	clr R3
	std y+3,R3
	std y+2,R2
	ldd R0,y+16
	ldd R1,y+17
	std y+1,R1
	std y+0,R0
	movw R18,R14
	movw R16,R10
	rcall _OSTaskStkInit
	movw R10,R16
	.dbline 124
;         err = OSTCBInit(prio, psp, (void *)0, 0, 0, (void *)0, 0);         
	clr R2
	clr R3
	std y+9,R3
	std y+8,R2
	std y+7,R3
	std y+6,R2
	std y+5,R3
	std y+4,R2
	std y+3,R3
	std y+2,R2
	std y+1,R3
	std y+0,R2
	movw R18,R10
	mov R16,R12
	rcall _OSTCBInit
	mov R10,R16
	.dbline 125
;         if (err == OS_NO_ERR) {
	tst R16
	brne L8
	.dbline 125
	.dbline 126
;             OS_ENTER_CRITICAL();
	st -y,r16
	in r16,0x3F
	cli
	push r16
	ld r16,y+
	.dbline 126
	.dbline 127
;             OSTaskCtr++;                                   /* Increment the #tasks counter             */
	lds R24,_OSTaskCtr
	subi R24,255    ; addi 1
	sts _OSTaskCtr,R24
	.dbline 128
;             OS_EXIT_CRITICAL();
	st -y,r16
	pop r16
	out 0x3F,r16
	ld r16,y+
	.dbline 128
	.dbline 129
;             if (OSRunning) {                 /* Find highest priority task if multitasking has started */
	lds R2,_OSRunning
	tst R2
	breq L9
	.dbline 129
	.dbline 130
;                 OSSched();
	rcall _OSSched
	.dbline 131
;             }
	.dbline 132
	rjmp L9
L8:
	.dbline 132
;         } else {
	.dbline 133
;             OS_ENTER_CRITICAL();
	st -y,r16
	in r16,0x3F
	cli
	push r16
	ld r16,y+
	.dbline 133
	.dbline 134
;             OSTCBPrioTbl[prio] = (OS_TCB *)0;/* Make this priority available to others                 */
	ldi R24,2
	mul R24,R12
	movw R30,R0
	ldi R24,<_OSTCBPrioTbl
	ldi R25,>_OSTCBPrioTbl
	add R30,R24
	adc R31,R25
	clr R2
	clr R3
	std z+1,R3
	std z+0,R2
	.dbline 135
;             OS_EXIT_CRITICAL();
	st -y,r16
	pop r16
	out 0x3F,r16
	ld r16,y+
	.dbline 135
	.dbline 136
;         }
L9:
	.dbline 137
;         return (err);
	mov R16,R10
	rjmp L3
L6:
	.dbline 138
;     } else {
	.dbline 139
;         OS_EXIT_CRITICAL();
	st -y,r16
	pop r16
	out 0x3F,r16
	ld r16,y+
	.dbline 139
	.dbline 140
;         return (OS_PRIO_EXIST);
	ldi R16,40
	.dbline -2
L3:
	adiw R28,10
	rcall pop_gset5x
	.dbline 0 ; func end
	ret
	.dbsym r psp 10 pV
	.dbsym r err 10 c
	.dbsym r prio 12 c
	.dbsym l ptos 16 pc
	.dbsym r pdata 14 pV
	.dbsym r task 10 pfV
	.dbend

⌨️ 快捷键说明

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