📄 os_task.s
字号:
.module os_task.c
.area text(rom, con, rel)
.dbfile C:\icc\examples.avr\AVR_PQ1A_DEMO\21_uCOSII\os_task.c
.dbfunc e OSTaskStkInit _OSTaskStkInit fpc
; stks -> R10,R11
; tmp -> R22,R23
; stk -> R20,R21
; opt -> y+8
; ptos -> y+6
; pdata -> R18,R19
; task -> R16,R17
.even
_OSTaskStkInit::
xcall push_gset3
.dbline -1
.dbline 48
;
; #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 55
;
; OS_STK *stk;
; INT8U *stks; // Temp. variable used for setting up AVR hardware stack
; INT16U tmp;
;
;
; opt = opt; // 'opt' is not used, prevent warning
.dbline 56
; stk = (OS_STK *)ptos; // Wandlung von ptos in Bytezeiger
ldd R20,y+6
ldd R21,y+7
.dbline 58
; // AVR return stack ("hardware stack")
; stks = (OS_STK *)(ptos)-(OS_TASK_DEF_STK_SIZE-32);
ldd R24,y+6
ldd R25,y+7
subi R24,68
sbci R25,0
.dbline 63
;
; // the function address has an extra level of indirection. Fetch the
; // actual address.
; //
; tmp = *(INT16U const *)task;
movw R30,R16
lpm R22,Z+
lpm R23,Z
.dbline 66
;
; // 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,R22
.dbline 67
; *stks-- = (INT8U)(tmp >> 8);
movw R2,R24
sbiw R24,1
movw R10,R24
movw R4,R22
mov R4,R5
clr R5
movw R30,R2
std z+0,R4
.dbline 69
;
; *stk-- = (INT8U)0x00; // R0 = 0x00
movw R2,R20
subi R20,1
sbci R21,0
clr R4
movw R30,R2
std z+0,R4
.dbline 70
; *stk-- = (INT8U)0x01;
movw R2,R20
subi R20,1
sbci R21,0
ldi R24,1
movw R30,R2
std z+0,R24
.dbline 71
; *stk-- = (INT8U)0x02;
movw R2,R20
subi R20,1
sbci R21,0
ldi R24,2
movw R30,R2
std z+0,R24
.dbline 72
; *stk-- = (INT8U)0x03;
movw R2,R20
subi R20,1
sbci R21,0
ldi R24,3
movw R30,R2
std z+0,R24
.dbline 73
; *stk-- = (INT8U)0x04;
movw R2,R20
subi R20,1
sbci R21,0
ldi R24,4
movw R30,R2
std z+0,R24
.dbline 74
; *stk-- = (INT8U)0x05;
movw R2,R20
subi R20,1
sbci R21,0
ldi R24,5
movw R30,R2
std z+0,R24
.dbline 75
; *stk-- = (INT8U)0x06;
movw R2,R20
subi R20,1
sbci R21,0
ldi R24,6
movw R30,R2
std z+0,R24
.dbline 76
; *stk-- = (INT8U)0x07;
movw R2,R20
subi R20,1
sbci R21,0
ldi R24,7
movw R30,R2
std z+0,R24
.dbline 77
; *stk-- = (INT8U)0x08;
movw R2,R20
subi R20,1
sbci R21,0
ldi R24,8
movw R30,R2
std z+0,R24
.dbline 78
; *stk-- = (INT8U)0x09;
movw R2,R20
subi R20,1
sbci R21,0
ldi R24,9
movw R30,R2
std z+0,R24
.dbline 79
; *stk-- = (INT8U)0x10;
movw R2,R20
subi R20,1
sbci R21,0
ldi R24,16
movw R30,R2
std z+0,R24
.dbline 80
; *stk-- = (INT8U)0x11;
movw R2,R20
subi R20,1
sbci R21,0
ldi R24,17
movw R30,R2
std z+0,R24
.dbline 81
; *stk-- = (INT8U)0x12;
movw R2,R20
subi R20,1
sbci R21,0
ldi R24,18
movw R30,R2
std z+0,R24
.dbline 82
; *stk-- = (INT8U)0x13;
movw R2,R20
subi R20,1
sbci R21,0
ldi R24,19
movw R30,R2
std z+0,R24
.dbline 83
; *stk-- = (INT8U)0x14;
movw R2,R20
subi R20,1
sbci R21,0
ldi R24,20
movw R30,R2
std z+0,R24
.dbline 84
; *stk-- = (INT8U)0x15;
movw R2,R20
subi R20,1
sbci R21,0
ldi R24,21
movw R30,R2
std z+0,R24
.dbline 85
; tmp = (INT16U)pdata;
movw R22,R18
.dbline 86
; *stk-- = (INT8U)tmp; //Simulate call to function with argument
movw R2,R20
subi R20,1
sbci R21,0
movw R30,R2
std z+0,R22
.dbline 87
; *stk-- = (INT8U)(tmp >> 8);
movw R2,R20
subi R20,1
sbci R21,0
movw R4,R22
mov R4,R5
clr R5
movw R30,R2
std z+0,R4
.dbline 88
; *stk-- = (INT8U)0x18;
movw R2,R20
subi R20,1
sbci R21,0
ldi R24,24
movw R30,R2
std z+0,R24
.dbline 89
; *stk-- = (INT8U)0x19;
movw R2,R20
subi R20,1
sbci R21,0
ldi R24,25
movw R30,R2
std z+0,R24
.dbline 90
; *stk-- = (INT8U)0x20;
movw R2,R20
subi R20,1
sbci R21,0
ldi R24,32
movw R30,R2
std z+0,R24
.dbline 91
; *stk-- = (INT8U)0x21;
movw R2,R20
subi R20,1
sbci R21,0
ldi R24,33
movw R30,R2
std z+0,R24
.dbline 92
; *stk-- = (INT8U)0x22;
movw R2,R20
subi R20,1
sbci R21,0
ldi R24,34
movw R30,R2
std z+0,R24
.dbline 93
; *stk-- = (INT8U)0x23;
movw R2,R20
subi R20,1
sbci R21,0
ldi R24,35
movw R30,R2
std z+0,R24
.dbline 94
; *stk-- = (INT8U)0x24;
movw R2,R20
subi R20,1
sbci R21,0
ldi R24,36
movw R30,R2
std z+0,R24
.dbline 95
; *stk-- = (INT8U)0x25;
movw R2,R20
subi R20,1
sbci R21,0
ldi R24,37
movw R30,R2
std z+0,R24
.dbline 96
; *stk-- = (INT8U)0x26;
movw R2,R20
subi R20,1
sbci R21,0
ldi R24,38
movw R30,R2
std z+0,R24
.dbline 97
; *stk-- = (INT8U)0x27;
movw R2,R20
subi R20,1
sbci R21,0
ldi R24,39
movw R30,R2
std z+0,R24
.dbline 99
; // the heap pointer Y=R29:R28 will not be stored
; *stk-- = (INT8U)0x30;
movw R2,R20
subi R20,1
sbci R21,0
ldi R24,48
movw R30,R2
std z+0,R24
.dbline 100
; *stk-- = (INT8U)0x31;
movw R2,R20
subi R20,1
sbci R21,0
ldi R24,49
movw R30,R2
std z+0,R24
.dbline 102
; // *stk-- = (INT8U)0x3B;
; *stk-- = (INT8U)0x80; //SREG = Interrupts enabled
movw R2,R20
subi R20,1
sbci R21,0
ldi R24,128
movw R30,R2
std z+0,R24
.dbline 104
;
; tmp = (INT16U)(stks);
movw R22,R10
.dbline 105
; *stk-- = (OS_STK)(tmp >> 8);
movw R2,R20
subi R20,1
sbci R21,0
movw R4,R22
mov R4,R5
clr R5
movw R30,R2
std z+0,R4
.dbline 106
; *stk = (OS_STK)(tmp);
movw R30,R20
std z+0,R22
.dbline 107
; return ((void *)stk);
mov R16,R20
mov R17,R21
.dbline -2
L2:
xcall pop_gset3
.dbline 0 ; func end
ret
.dbsym r stks 10 pc
.dbsym r tmp 22 i
.dbsym r stk 20 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 -> R20,R21
; err -> R20
; prio -> R22
; ptos -> y+16
; pdata -> R10,R11
; task -> R20,R21
.even
_OSTaskCreate::
xcall push_gset3
movw R10,R18
movw R20,R16
sbiw R28,10
ldd R22,y+18
.dbline -1
.dbline 111
; }
;
; INT8U OSTaskCreate (void (*task)(void *pd), void *pdata, OS_STK *ptos, INT8U prio)
; {
.dbline 116
; void *psp;
; INT8U err;
;
;
; if (prio > OS_LOWEST_PRIO) { /* Make sure priority is within allowable range */
ldi R24,15
cp R24,R22
brsh L4
.dbline 116
.dbline 117
; return (OS_PRIO_INVALID);
ldi R16,42
xjmp L3
L4:
.dbline 119
; }
; OS_ENTER_CRITICAL();
st -y,r16
in r16,0x3f
cli
push r16
ld r16,y+
.dbline 119
.dbline 120
; if (OSTCBPrioTbl[prio] == (OS_TCB *)0) { /* Make sure task doesn't already exist at this priority */
ldi R24,2
mul R24,R22
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
xjmp L6
X1:
tst R3
breq X2
xjmp L6
X2:
X0:
.dbline 120
.dbline 121
; OSTCBPrioTbl[prio] = (OS_TCB *)1; /* Reserve the priority to prevent others from doing ... */
ldi R24,2
mul R24,R22
movw R30,R0
ldi R24,<_OSTCBPrioTbl
ldi R25,>_OSTCBPrioTbl
add R30,R24
adc R31,R25
ldi R24,1
ldi R25,0
std z+0,R24
std z+1,R25
.dbline 123
; /* ... the same thing until task is created. */
; OS_EXIT_CRITICAL();
st -y,r16
pop r16
out 0x3F,r16
ld r16,y+
.dbline 123
.dbline 124
; psp = (void *)OSTaskStkInit(task, pdata, ptos, 0); /* Initialize the task's stack */
clr R2
clr R3
std y+2,R2
std y+3,R3
ldd R0,y+16
ldd R1,y+17
std y+0,R0
std y+1,R1
movw R18,R10
movw R16,R20
xcall _OSTaskStkInit
movw R20,R16
.dbline 125
; err = OSTCBInit(prio, psp, (void *)0, 0, 0, (void *)0, 0);
clr R2
clr R3
std y+8,R2
std y+9,R3
std y+6,R2
std y+7,R3
std y+4,R2
std y+5,R3
std y+2,R2
std y+3,R3
std y+0,R2
std y+1,R3
movw R18,R20
mov R16,R22
xcall _OSTCBInit
mov R20,R16
.dbline 126
; if (err == OS_NO_ERR) {
tst R16
brne L8
.dbline 126
.dbline 127
; OS_ENTER_CRITICAL();
st -y,r16
in r16,0x3f
cli
push r16
ld r16,y+
.dbline 127
.dbline 128
; OSTaskCtr++; /* Increment the #tasks counter */
lds R24,_OSTaskCtr
subi R24,255 ; addi 1
sts _OSTaskCtr,R24
.dbline 129
; OS_EXIT_CRITICAL();
st -y,r16
pop r16
out 0x3F,r16
ld r16,y+
.dbline 129
.dbline 130
; if (OSRunning) { /* Find highest priority task if multitasking has started */
lds R2,_OSRunning
tst R2
breq L9
.dbline 130
.dbline 131
; OSSched();
xcall _OSSched
.dbline 132
; }
.dbline 133
xjmp L9
L8:
.dbline 133
; } else {
.dbline 134
; OS_ENTER_CRITICAL();
st -y,r16
in r16,0x3f
cli
push r16
ld r16,y+
.dbline 134
.dbline 135
; OSTCBPrioTbl[prio] = (OS_TCB *)0;/* Make this priority available to others */
ldi R24,2
mul R24,R22
movw R30,R0
ldi R24,<_OSTCBPrioTbl
ldi R25,>_OSTCBPrioTbl
add R30,R24
adc R31,R25
clr R2
clr R3
std z+0,R2
std z+1,R3
.dbline 136
; OS_EXIT_CRITICAL();
st -y,r16
pop r16
out 0x3F,r16
ld r16,y+
.dbline 136
.dbline 137
; }
L9:
.dbline 138
; return (err);
mov R16,R20
xjmp L3
L6:
.dbline 139
; } else {
.dbline 140
; OS_EXIT_CRITICAL();
st -y,r16
pop r16
out 0x3F,r16
ld r16,y+
.dbline 140
.dbline 141
; return (OS_PRIO_EXIST);
ldi R16,40
.dbline -2
L3:
adiw R28,10
xcall pop_gset3
.dbline 0 ; func end
ret
.dbsym r psp 20 pV
.dbsym r err 20 c
.dbsym r prio 22 c
.dbsym l ptos 16 pc
.dbsym r pdata 10 pV
.dbsym r task 20 pfV
.dbend
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -