📄 os_task.s
字号:
.module os_task.c
.area text(rom, con, rel)
.dbfile E:\ypt050912\XIAZAI\xinzai\UCOSAVR128\Source\os_task.c
.dbfunc e OSTaskCreate _OSTaskCreate fc
; psp -> R12,R13
; err -> R12
; cpu_sr -> R10
; prio -> R14
; ptos -> y+24
; p_arg -> y+22
; task -> R12,R13
.even
_OSTaskCreate::
st -y,r19
st -y,r18
xcall push_gset5
movw R12,R16
sbiw R28,12
ldd R14,y+26
.dbline -1
.dbline 177
; /*
; *********************************************************************************************************
; * uC/OS-II
; * The Real-Time Kernel
; * TASK MANAGEMENT
; *
; * (c) Copyright 1992-2005, Jean J. Labrosse, Weston, FL
; * All Rights Reserved
; *
; * File : OS_TASK.C
; * By : Jean J. Labrosse
; * Version : V2.80
; *********************************************************************************************************
; */
;
; #ifndef OS_MASTER_FILE
; #include <ucos_ii.h>
; #endif
;
; /*
; *********************************************************************************************************
; * CHANGE PRIORITY OF A TASK
; *
; * Description: This function allows you to change the priority of a task dynamically. Note that the new
; * priority MUST be available.
; *
; * Arguments : oldp is the old priority
; *
; * newp is the new priority
; *
; * Returns : OS_NO_ERR is the call was successful
; * OS_PRIO_INVALID if the priority you specify is higher that the maximum allowed
; * (i.e. >= OS_LOWEST_PRIO)
; * OS_PRIO_EXIST if the new priority already exist.
; * OS_PRIO_ERR there is no task with the specified OLD priority (i.e. the OLD task does
; * not exist.
; * OS_TASK_NOT_EXIST if the task is assigned to a Mutex PIP.
; *********************************************************************************************************
; */
;
; #if OS_TASK_CHANGE_PRIO_EN > 0
; INT8U OSTaskChangePrio (INT8U oldprio, INT8U newprio)
; {
; #if OS_EVENT_EN
; OS_EVENT *pevent;
; #endif
; OS_TCB *ptcb;
; INT8U x;
; INT8U y;
; #if OS_LOWEST_PRIO <= 63
; INT8U bitx;
; INT8U bity;
; #else
; INT16U bitx;
; INT16U bity;
; #endif
; INT8U y_old;
; #if OS_CRITICAL_METHOD == 3
; OS_CPU_SR cpu_sr = 0; /* Storage for CPU status register */
; #endif
;
;
;
; #if OS_ARG_CHK_EN > 0
; if (oldprio >= OS_LOWEST_PRIO) {
; if (oldprio != OS_PRIO_SELF) {
; return (OS_PRIO_INVALID);
; }
; }
; if (newprio >= OS_LOWEST_PRIO) {
; return (OS_PRIO_INVALID);
; }
; #endif
; OS_ENTER_CRITICAL();
; if (OSTCBPrioTbl[newprio] != (OS_TCB *)0) { /* New priority must not already exist */
; OS_EXIT_CRITICAL();
; return (OS_PRIO_EXIST);
; }
; if (oldprio == OS_PRIO_SELF) { /* See if changing self */
; oldprio = OSTCBCur->OSTCBPrio; /* Yes, get priority */
; }
; ptcb = OSTCBPrioTbl[oldprio];
; if (ptcb == (OS_TCB *)0) { /* Does task to change exist? */
; OS_EXIT_CRITICAL(); /* No, can't change its priority! */
; return (OS_PRIO_ERR);
; }
; if (ptcb == (OS_TCB *)1) { /* Is task assigned to Mutex */
; OS_EXIT_CRITICAL(); /* No, can't change its priority! */
; return (OS_TASK_NOT_EXIST);
; }
; #if OS_LOWEST_PRIO <= 63
; y = newprio >> 3; /* Yes, compute new TCB fields */
; x = newprio & 0x07;
; #else
; y = (newprio >> 4) & 0xFF;
; x = newprio & 0x0F;
; #endif
;
; bity = 1 << y;
; bitx = 1 << x;
; OSTCBPrioTbl[oldprio] = (OS_TCB *)0; /* Remove TCB from old priority */
; OSTCBPrioTbl[newprio] = ptcb; /* Place pointer to TCB @ new priority */
; y_old = ptcb->OSTCBY;
; if ((OSRdyTbl[y_old] & ptcb->OSTCBBitX) != 0) { /* If task is ready make it not */
; OSRdyTbl[y_old] &= ~ptcb->OSTCBBitX;
; if (OSRdyTbl[y_old] == 0) {
; OSRdyGrp &= ~ptcb->OSTCBBitY;
; }
; OSRdyGrp |= bity; /* Make new priority ready to run */
; OSRdyTbl[y] |= bitx;
; #if OS_EVENT_EN
; } else { /* Task was not ready ... */
; pevent = ptcb->OSTCBEventPtr;
; if (pevent != (OS_EVENT *)0) { /* ... remove from event wait list */
; pevent->OSEventTbl[y_old] &= ~ptcb->OSTCBBitX;
; if (pevent->OSEventTbl[y_old] == 0) {
; pevent->OSEventGrp &= ~ptcb->OSTCBBitY;
; }
; pevent->OSEventGrp |= bity; /* Add new priority to wait list */
; pevent->OSEventTbl[y] |= bitx;
; }
; #endif
; }
; ptcb->OSTCBPrio = newprio; /* Set new task priority */
; ptcb->OSTCBY = y;
; ptcb->OSTCBX = x;
; ptcb->OSTCBBitY = bity;
; ptcb->OSTCBBitX = bitx;
; OS_EXIT_CRITICAL();
; OS_Sched(); /* Run highest priority task ready */
; return (OS_NO_ERR);
; }
; #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
; *
; * p_arg 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 'p_arg' as follows:
; *
; * void Task (void *p_arg)
; * {
; * 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)
; * OS_ERR_TASK_CREATE_ISR if you tried to create a task from an ISR.
; *********************************************************************************************************
; */
;
; #if OS_TASK_CREATE_EN > 0
; INT8U OSTaskCreate (void (*task)(void *p_arg), void *p_arg, OS_STK *ptos, INT8U prio)
; {
.dbline 181
; OS_STK *psp;
; INT8U err;
; #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
; OS_CPU_SR cpu_sr = 0;
clr R10
.dbline 191
; #endif
;
;
;
; #if OS_ARG_CHK_EN > 0
; if (prio > OS_LOWEST_PRIO) { /* Make sure priority is within allowable range */
; return (OS_PRIO_INVALID);
; }
; #endif
; OS_ENTER_CRITICAL();
xcall _OS_CPU_SR_Save
mov R10,R16
.dbline 192
; if (OSIntNesting > 0) { /* Make sure we don't create the task from within an ISR */
clr R2
lds R3,_OSIntNesting
cp R2,R3
brsh L2
.dbline 192
.dbline 193
; OS_EXIT_CRITICAL();
xcall _OS_CPU_SR_Restore
.dbline 194
; return (OS_ERR_TASK_CREATE_ISR);
ldi R16,16
xjmp L1
L2:
.dbline 196
; }
; if (OSTCBPrioTbl[prio] == (OS_TCB *)0) { /* Make sure task doesn't already exist at this priority */
ldi R24,2
mul R24,R14
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 L4
X1:
tst R3
breq X2
xjmp L4
X2:
X0:
.dbline 196
.dbline 197
; OSTCBPrioTbl[prio] = (OS_TCB *)1; /* Reserve the priority to prevent others from doing ... */
ldi R24,2
mul R24,R14
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 199
; /* ... the same thing until task is created. */
; OS_EXIT_CRITICAL();
mov R16,R10
xcall _OS_CPU_SR_Restore
.dbline 200
; psp = OSTaskStkInit(task, p_arg, ptos, 0); /* Initialize the task's stack */
clr R2
clr R3
std y+3,R3
std y+2,R2
ldd R0,y+24
ldd R1,y+25
std y+1,R1
std y+0,R0
ldd R18,y+22
ldd R19,y+23
movw R16,R12
xcall _OSTaskStkInit
movw R12,R16
.dbline 201
; err = OS_TCBInit(prio, psp, (OS_STK *)0, 0, 0, (void *)0, 0);
clr R2
clr R3
std y+11,R3
std y+10,R2
std y+9,R3
std y+8,R2
ldi R20,0
ldi R21,0
ldi R22,0
ldi R23,0
std y+4,R20
std y+5,R21
std y+6,R22
std y+7,R23
std y+3,R3
std y+2,R2
std y+1,R3
std y+0,R2
movw R18,R12
mov R16,R14
xcall _OS_TCBInit
mov R12,R16
.dbline 202
; if (err == OS_NO_ERR) {
tst R16
brne L6
.dbline 202
.dbline 203
; if (OSRunning == TRUE) { /* Find highest priority task if multitasking has started */
lds R24,_OSRunning
cpi R24,1
brne L7
.dbline 203
.dbline 204
; OS_Sched();
xcall _OS_Sched
.dbline 205
; }
.dbline 206
xjmp L7
L6:
.dbline 206
; } else {
.dbline 207
; OS_ENTER_CRITICAL();
xcall _OS_CPU_SR_Save
mov R10,R16
.dbline 208
; OSTCBPrioTbl[prio] = (OS_TCB *)0;/* Make this priority available to others */
ldi R24,2
mul R24,R14
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 209
; OS_EXIT_CRITICAL();
xcall _OS_CPU_SR_Restore
.dbline 210
; }
L7:
.dbline 211
; return (err);
mov R16,R12
xjmp L1
L4:
.dbline 213
; }
; OS_EXIT_CRITICAL();
mov R16,R10
xcall _OS_CPU_SR_Restore
.dbline 214
; return (OS_PRIO_EXIST);
ldi R16,40
.dbline -2
L1:
adiw R28,12
xcall pop_gset5
adiw R28,2
.dbline 0 ; func end
ret
.dbsym r psp 12 pc
.dbsym r err 12 c
.dbsym r cpu_sr 10 c
.dbsym r prio 14 c
.dbsym l ptos 24 pc
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -