📄 os_task.lis
字号:
.module os_task.c
.area text(rom, con, rel)
0000 .dbfile E:\ypt050912\XIAZAI\xinzai\UCOSAVR128\Source\os_task.c
0000 .dbfunc e OSTaskCreate _OSTaskCreate fc
0000 ; psp -> R12,R13
0000 ; err -> R12
0000 ; cpu_sr -> R10
0000 ; prio -> R14
0000 ; ptos -> y+24
0000 ; p_arg -> y+22
0000 ; task -> R12,R13
.even
0000 _OSTaskCreate::
0000 3A93 st -y,r19
0002 2A93 st -y,r18
0004 0E940000 xcall push_gset5
0008 6801 movw R12,R16
000A 2C97 sbiw R28,12
000C EA8C ldd R14,y+26
000E .dbline -1
000E .dbline 177
000E ; /*
000E ; *********************************************************************************************************
000E ; * uC/OS-II
000E ; * The Real-Time Kernel
000E ; * TASK MANAGEMENT
000E ; *
000E ; * (c) Copyright 1992-2005, Jean J. Labrosse, Weston, FL
000E ; * All Rights Reserved
000E ; *
000E ; * File : OS_TASK.C
000E ; * By : Jean J. Labrosse
000E ; * Version : V2.80
000E ; *********************************************************************************************************
000E ; */
000E ;
000E ; #ifndef OS_MASTER_FILE
000E ; #include <ucos_ii.h>
000E ; #endif
000E ;
000E ; /*
000E ; *********************************************************************************************************
000E ; * CHANGE PRIORITY OF A TASK
000E ; *
000E ; * Description: This function allows you to change the priority of a task dynamically. Note that the new
000E ; * priority MUST be available.
000E ; *
000E ; * Arguments : oldp is the old priority
000E ; *
000E ; * newp is the new priority
000E ; *
000E ; * Returns : OS_NO_ERR is the call was successful
000E ; * OS_PRIO_INVALID if the priority you specify is higher that the maximum allowed
000E ; * (i.e. >= OS_LOWEST_PRIO)
000E ; * OS_PRIO_EXIST if the new priority already exist.
000E ; * OS_PRIO_ERR there is no task with the specified OLD priority (i.e. the OLD task does
000E ; * not exist.
000E ; * OS_TASK_NOT_EXIST if the task is assigned to a Mutex PIP.
000E ; *********************************************************************************************************
000E ; */
000E ;
000E ; #if OS_TASK_CHANGE_PRIO_EN > 0
000E ; INT8U OSTaskChangePrio (INT8U oldprio, INT8U newprio)
000E ; {
000E ; #if OS_EVENT_EN
000E ; OS_EVENT *pevent;
000E ; #endif
000E ; OS_TCB *ptcb;
000E ; INT8U x;
000E ; INT8U y;
000E ; #if OS_LOWEST_PRIO <= 63
000E ; INT8U bitx;
000E ; INT8U bity;
000E ; #else
000E ; INT16U bitx;
000E ; INT16U bity;
000E ; #endif
000E ; INT8U y_old;
000E ; #if OS_CRITICAL_METHOD == 3
000E ; OS_CPU_SR cpu_sr = 0; /* Storage for CPU status register */
000E ; #endif
000E ;
000E ;
000E ;
000E ; #if OS_ARG_CHK_EN > 0
000E ; if (oldprio >= OS_LOWEST_PRIO) {
000E ; if (oldprio != OS_PRIO_SELF) {
000E ; return (OS_PRIO_INVALID);
000E ; }
000E ; }
000E ; if (newprio >= OS_LOWEST_PRIO) {
000E ; return (OS_PRIO_INVALID);
000E ; }
000E ; #endif
000E ; OS_ENTER_CRITICAL();
000E ; if (OSTCBPrioTbl[newprio] != (OS_TCB *)0) { /* New priority must not already exist */
000E ; OS_EXIT_CRITICAL();
000E ; return (OS_PRIO_EXIST);
000E ; }
000E ; if (oldprio == OS_PRIO_SELF) { /* See if changing self */
000E ; oldprio = OSTCBCur->OSTCBPrio; /* Yes, get priority */
000E ; }
000E ; ptcb = OSTCBPrioTbl[oldprio];
000E ; if (ptcb == (OS_TCB *)0) { /* Does task to change exist? */
000E ; OS_EXIT_CRITICAL(); /* No, can't change its priority! */
000E ; return (OS_PRIO_ERR);
000E ; }
000E ; if (ptcb == (OS_TCB *)1) { /* Is task assigned to Mutex */
000E ; OS_EXIT_CRITICAL(); /* No, can't change its priority! */
000E ; return (OS_TASK_NOT_EXIST);
000E ; }
000E ; #if OS_LOWEST_PRIO <= 63
000E ; y = newprio >> 3; /* Yes, compute new TCB fields */
000E ; x = newprio & 0x07;
000E ; #else
000E ; y = (newprio >> 4) & 0xFF;
000E ; x = newprio & 0x0F;
000E ; #endif
000E ;
000E ; bity = 1 << y;
000E ; bitx = 1 << x;
000E ; OSTCBPrioTbl[oldprio] = (OS_TCB *)0; /* Remove TCB from old priority */
000E ; OSTCBPrioTbl[newprio] = ptcb; /* Place pointer to TCB @ new priority */
000E ; y_old = ptcb->OSTCBY;
000E ; if ((OSRdyTbl[y_old] & ptcb->OSTCBBitX) != 0) { /* If task is ready make it not */
000E ; OSRdyTbl[y_old] &= ~ptcb->OSTCBBitX;
000E ; if (OSRdyTbl[y_old] == 0) {
000E ; OSRdyGrp &= ~ptcb->OSTCBBitY;
000E ; }
000E ; OSRdyGrp |= bity; /* Make new priority ready to run */
000E ; OSRdyTbl[y] |= bitx;
000E ; #if OS_EVENT_EN
000E ; } else { /* Task was not ready ... */
000E ; pevent = ptcb->OSTCBEventPtr;
000E ; if (pevent != (OS_EVENT *)0) { /* ... remove from event wait list */
000E ; pevent->OSEventTbl[y_old] &= ~ptcb->OSTCBBitX;
000E ; if (pevent->OSEventTbl[y_old] == 0) {
000E ; pevent->OSEventGrp &= ~ptcb->OSTCBBitY;
000E ; }
000E ; pevent->OSEventGrp |= bity; /* Add new priority to wait list */
000E ; pevent->OSEventTbl[y] |= bitx;
000E ; }
000E ; #endif
000E ; }
000E ; ptcb->OSTCBPrio = newprio; /* Set new task priority */
000E ; ptcb->OSTCBY = y;
000E ; ptcb->OSTCBX = x;
000E ; ptcb->OSTCBBitY = bity;
000E ; ptcb->OSTCBBitX = bitx;
000E ; OS_EXIT_CRITICAL();
000E ; OS_Sched(); /* Run highest priority task ready */
000E ; return (OS_NO_ERR);
000E ; }
000E ; #endif
000E ; /*$PAGE*/
000E ; /*
000E ; *********************************************************************************************************
000E ; * CREATE A TASK
000E ; *
000E ; * Description: This function is used to have uC/OS-II manage the execution of a task. Tasks can either
000E ; * be created prior to the start of multitasking or by a running task. A task cannot be
000E ; * created by an ISR.
000E ; *
000E ; * Arguments : task is a pointer to the task's code
000E ; *
000E ; * p_arg is a pointer to an optional data area which can be used to pass parameters to
000E ; * the task when the task first executes. Where the task is concerned it thinks
000E ; * it was invoked and passed the argument 'p_arg' as follows:
000E ; *
000E ; * void Task (void *p_arg)
000E ; * {
000E ; * for (;;) {
000E ; * Task code;
000E ; * }
000E ; * }
000E ; *
000E ; * ptos is a pointer to the task's top of stack. If the configuration constant
000E ; * OS_STK_GROWTH is set to 1, the stack is assumed to grow downward (i.e. from high
000E ; * memory to low memory). 'pstk' will thus point to the highest (valid) memory
000E ; * location of the stack. If OS_STK_GROWTH is set to 0, 'pstk' will point to the
000E ; * lowest memory location of the stack and the stack will grow with increasing
000E ; * memory locations.
000E ; *
000E ; * prio is the task's priority. A unique priority MUST be assigned to each task and the
000E ; * lower the number, the higher the priority.
000E ; *
000E ; * Returns : OS_NO_ERR if the function was successful.
000E ; * OS_PRIO_EXIT if the task priority already exist
000E ; * (each task MUST have a unique priority).
000E ; * OS_PRIO_INVALID if the priority you specify is higher that the maximum allowed
000E ; * (i.e. >= OS_LOWEST_PRIO)
000E ; * OS_ERR_TASK_CREATE_ISR if you tried to create a task from an ISR.
000E ; *********************************************************************************************************
000E ; */
000E ;
000E ; #if OS_TASK_CREATE_EN > 0
000E ; INT8U OSTaskCreate (void (*task)(void *p_arg), void *p_arg, OS_STK *ptos, INT8U prio)
000E ; {
000E .dbline 181
000E ; OS_STK *psp;
000E ; INT8U err;
000E ; #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
000E ; OS_CPU_SR cpu_sr = 0;
000E AA24 clr R10
0010 .dbline 191
0010 ; #endif
0010 ;
0010 ;
0010 ;
0010 ; #if OS_ARG_CHK_EN > 0
0010 ; if (prio > OS_LOWEST_PRIO) { /* Make sure priority is within allowable range */
0010 ; return (OS_PRIO_INVALID);
0010 ; }
0010 ; #endif
0010 ; OS_ENTER_CRITICAL();
0010 0E940000 xcall _OS_CPU_SR_Save
0014 A02E mov R10,R16
0016 .dbline 192
0016 ; if (OSIntNesting > 0) { /* Make sure we don't create the task from within an ISR */
0016 2224 clr R2
0018 30900000 lds R3,_OSIntNesting
001C 2314 cp R2,R3
001E 20F4 brsh L2
0020 .dbline 192
0020 .dbline 193
0020 ; OS_EXIT_CRITICAL();
0020 0E940000 xcall _OS_CPU_SR_Restore
0024 .dbline 194
0024 ; return (OS_ERR_TASK_CREATE_ISR);
0024 00E1 ldi R16,16
0026 61C0 xjmp L1
0028 L2:
0028 .dbline 196
0028 ; }
0028 ; if (OSTCBPrioTbl[prio] == (OS_TCB *)0) { /* Make sure task doesn't already exist at this priority */
0028 82E0 ldi R24,2
002A 8E9D mul R24,R14
002C F001 movw R30,R0
002E 80E0 ldi R24,<_OSTCBPrioTbl
0030 90E0 ldi R25,>_OSTCBPrioTbl
0032 E80F add R30,R24
0034 F91F adc R31,R25
0036 2080 ldd R2,z+0
0038 3180 ldd R3,z+1
003A 2220 tst R2
003C 09F0 breq X1
003E 51C0 xjmp L4
0040 X1:
0040 3320 tst R3
0042 09F0 breq X2
0044 4EC0 xjmp L4
0046 X2:
0046 X0:
0046 .dbline 196
0046 .dbline 197
0046 ; OSTCBPrioTbl[prio] = (OS_TCB *)1; /* Reserve the priority to prevent others from doing ... */
0046 82E0 ldi R24,2
0048 8E9D mul R24,R14
004A F001 movw R30,R0
004C 80E0 ldi R24,<_OSTCBPrioTbl
004E 90E0 ldi R25,>_OSTCBPrioTbl
0050 E80F add R30,R24
0052 F91F adc R31,R25
0054 81E0 ldi R24,1
0056 90E0 ldi R25,0
0058 9183 std z+1,R25
005A 8083 std z+0,R24
005C .dbline 199
005C ; /* ... the same thing until task is created. */
005C ; OS_EXIT_CRITICAL();
005C 0A2D mov R16,R10
005E 0E940000 xcall _OS_CPU_SR_Restore
0062 .dbline 200
0062 ; psp = OSTaskStkInit(task, p_arg, ptos, 0); /* Initialize the task's stack */
0062 2224 clr R2
0064 3324 clr R3
0066 3B82 std y+3,R3
0068 2A82 std y+2,R2
006A 088C ldd R0,y+24
006C 198C ldd R1,y+25
006E 1982 std y+1,R1
0070 0882 std y+0,R0
0072 2E89 ldd R18,y+22
0074 3F89 ldd R19,y+23
0076 8601 movw R16,R12
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -