📄 os_task.lst
字号:
C51 COMPILER V6.23a OS_TASK 12/09/2004 16:50:26 PAGE 1
C51 COMPILER V6.23a, COMPILATION OF MODULE OS_TASK
OBJECT MODULE PLACED IN OS_TASK.OBJ
COMPILER INVOKED BY: C:\Program Files\Keil\C51\BIN\C51.EXE OS_TASK.C LARGE BROWSE DEBUG OBJECTEXTEND
stmt level source
1 /*
2 *********************************************************************************************************
3 * uC/OS-II
4 * The Real-Time Kernel
5 * TASK MANAGEMENT
6 *
7 * (c) Copyright 1992-2002, Jean J. Labrosse, Weston, FL
8 * All Rights Reserved
9 *
10 * File : OS_TASK.C
11 * By : Jean J. Labrosse
12 *********************************************************************************************************
13 */
14
15 #ifndef OS_MASTER_FILE
16 #include "includes.h"
17 #endif
18
19 /*
20 *********************************************************************************************************
21 * CHANGE PRIORITY OF A TASK
22 *
23 * Description: This function allows you to change the priority of a task dynamically. Note that the new
24 * priority MUST be available.
25 *
26 * Arguments : oldp is the old priority
27 *
28 * newp is the new priority
29 *
30 * Returns : OS_NO_ERR is the call was successful
31 * OS_PRIO_INVALID if the priority you specify is higher that the maximum allowed
32 * (i.e. >= OS_LOWEST_PRIO)
33 * OS_PRIO_EXIST if the new priority already exist.
34 * OS_PRIO_ERR there is no task with the specified OLD priority (i.e. the OLD task does
35 * not exist.
36 *********************************************************************************************************
37 */
38
39 #if OS_TASK_CHANGE_PRIO_EN > 0
40 INT8U OSTaskChangePrio (INT8U oldprio, INT8U newprio) KCREENTRANT
41 {
42 1 #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
OS_CPU_SR cpu_sr;
#endif
45 1
46 1 #if OS_EVENT_EN > 0
47 1 OS_EVENT *pevent;
48 1 #endif
49 1
50 1 OS_TCB *ptcb;
51 1 INT8U x;
52 1 INT8U y;
53 1 INT8U bitx;
54 1 INT8U bity;
55 1
C51 COMPILER V6.23a OS_TASK 12/09/2004 16:50:26 PAGE 2
56 1
57 1
58 1 #if OS_ARG_CHK_EN > 0
59 1 if ((oldprio >= OS_LOWEST_PRIO && oldprio != OS_PRIO_SELF) ||
60 1 newprio >= OS_LOWEST_PRIO) {
61 2 return (OS_PRIO_INVALID);
62 2 }
63 1 #endif
64 1 OS_ENTER_CRITICAL();
65 1 if (OSTCBPrioTbl[newprio] != (OS_TCB *)0) { /* New priority must not already exist */
66 2 OS_EXIT_CRITICAL();
67 2 return (OS_PRIO_EXIST);
68 2 } else {
69 2 OSTCBPrioTbl[newprio] = (OS_TCB *)1; /* Reserve the entry to prevent others */
70 2 OS_EXIT_CRITICAL();
71 2 y = newprio >> 3; /* Precompute to reduce INT. latency */
72 2 bity = OSMapTbl[y];
73 2 x = newprio & 0x07;
74 2 bitx = OSMapTbl[x];
75 2 OS_ENTER_CRITICAL();
76 2 if (oldprio == OS_PRIO_SELF) { /* See if changing self */
77 3 oldprio = OSTCBCur->OSTCBPrio; /* Yes, get priority */
78 3 }
79 2 ptcb = OSTCBPrioTbl[oldprio];
80 2 if (ptcb != (OS_TCB *)0) { /* Task to change must exist */
81 3 OSTCBPrioTbl[oldprio] = (OS_TCB *)0; /* Remove TCB from old priority */
82 3 if ((OSRdyTbl[ptcb->OSTCBY] & ptcb->OSTCBBitX) != 0x00) { /* If task is ready make it not */
83 4 if ((OSRdyTbl[ptcb->OSTCBY] &= ~ptcb->OSTCBBitX) == 0x00) {
84 5 OSRdyGrp &= ~ptcb->OSTCBBitY;
85 5 }
86 4 OSRdyGrp |= bity; /* Make new priority ready to run */
87 4 OSRdyTbl[y] |= bitx;
88 4 #if OS_EVENT_EN > 0
89 4 } else {
90 4 pevent = ptcb->OSTCBEventPtr;
91 4 if (pevent != (OS_EVENT *)0) { /* Remove from event wait list */
92 5 if ((pevent->OSEventTbl[ptcb->OSTCBY] &= ~ptcb->OSTCBBitX) == 0) {
93 6 pevent->OSEventGrp &= ~ptcb->OSTCBBitY;
94 6 }
95 5 pevent->OSEventGrp |= bity; /* Add new priority to wait list */
96 5 pevent->OSEventTbl[y] |= bitx;
97 5 }
98 4 #endif
99 4 }
100 3 OSTCBPrioTbl[newprio] = ptcb; /* Place pointer to TCB @ new priority */
101 3 ptcb->OSTCBPrio = newprio; /* Set new task priority */
102 3 ptcb->OSTCBY = y;
103 3 ptcb->OSTCBX = x;
104 3 ptcb->OSTCBBitY = bity;
105 3 ptcb->OSTCBBitX = bitx;
106 3 OS_EXIT_CRITICAL();
107 3 OS_Sched(); /* Run highest priority task ready */
108 3 return (OS_NO_ERR);
109 3 } else {
110 3 OSTCBPrioTbl[newprio] = (OS_TCB *)0; /* Release the reserved prio. */
111 3 OS_EXIT_CRITICAL();
112 3 return (OS_PRIO_ERR); /* Task to change didn't exist */
113 3 }
114 2 }
115 1 }
116 #endif
117 /*$PAGE*/
C51 COMPILER V6.23a OS_TASK 12/09/2004 16:50:26 PAGE 3
118 /*
119 *********************************************************************************************************
120 * CREATE A TASK
121 *
122 * Description: This function is used to have uC/OS-II manage the execution of a task. Tasks can either
123 * be created prior to the start of multitasking or by a running task. A task cannot be
124 * created by an ISR.
125 *
126 * Arguments : task is a pointer to the task's code
127 *
128 * pdata is a pointer to an optional data area which can be used to pass parameters to
129 * the task when the task first executes. Where the task is concerned it thinks
130 * it was invoked and passed the argument 'pdata' as follows:
131 *
132 * void Task (void *pdata)
133 * {
134 * for (;;) {
135 * Task code;
136 * }
137 * }
138 *
139 * ptos is a pointer to the task's top of stack. If the configuration constant
140 * OS_STK_GROWTH is set to 1, the stack is assumed to grow downward (i.e. from high
141 * memory to low memory). 'pstk' will thus point to the highest (valid) memory
142 * location of the stack. If OS_STK_GROWTH is set to 0, 'pstk' will point to the
143 * lowest memory location of the stack and the stack will grow with increasing
144 * memory locations.
145 *
146 * prio is the task's priority. A unique priority MUST be assigned to each task and the
147 * lower the number, the higher the priority.
148 *
149 * Returns : OS_NO_ERR if the function was successful.
150 * OS_PRIO_EXIT if the task priority already exist
151 * (each task MUST have a unique priority).
152 * OS_PRIO_INVALID if the priority you specify is higher that the maximum allowed
153 * (i.e. >= OS_LOWEST_PRIO)
154 *********************************************************************************************************
155 */
156
157 #if OS_TASK_CREATE_EN > 0
158 INT8U OSTaskCreate (void (*task)(void *pd) KCREENTRANT, void *pdata, OS_STK *ptos, INT8U prio) KCREENTRAN
-T
159 {
160 1 #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
OS_CPU_SR cpu_sr;
#endif
163 1 OS_STK *psp;
164 1 INT8U err;
165 1
166 1
167 1 #if OS_ARG_CHK_EN > 0
168 1 if (prio > OS_LOWEST_PRIO) { /* Make sure priority is within allowable range */
169 2 return (OS_PRIO_INVALID);
170 2 }
171 1 #endif
172 1 OS_ENTER_CRITICAL();
173 1 if (OSTCBPrioTbl[prio] == (OS_TCB *)0) { /* Make sure task doesn't already exist at this priority */
174 2 OSTCBPrioTbl[prio] = (OS_TCB *)1; /* Reserve the priority to prevent others from doing ... */
175 2 /* ... the same thing until task is created. */
176 2 OS_EXIT_CRITICAL();
177 2 psp = (OS_STK *)OSTaskStkInit(task, pdata, ptos, 0); /* Initialize the task's stack */
178 2 err = OS_TCBInit(prio, psp, (OS_STK *)0, 0, 0, (void *)0, 0);
C51 COMPILER V6.23a OS_TASK 12/09/2004 16:50:26 PAGE 4
179 2 if (err == OS_NO_ERR) {
180 3 OS_ENTER_CRITICAL();
181 3 OSTaskCtr++; /* Increment the #tasks counter */
182 3 OS_EXIT_CRITICAL();
183 3 if (OSRunning == TRUE) { /* Find highest priority task if multitasking has started */
184 4 OS_Sched();
185 4 }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -