?? os_task.lst
字號:
C51 COMPILER V7.06 OS_TASK 07/18/2003 11:06:04 PAGE 1
C51 COMPILER V7.06, COMPILATION OF MODULE OS_TASK
OBJECT MODULE PLACED IN .\os_task.obj
COMPILER INVOKED BY: C:\KEIL\C51\BIN\C51.EXE ..\keilc51\os_task.c LARGE BROWSE DEBUG OBJECTEXTEND PRINT(.\os_task.lst) O
-BJECT(.\os_task.obj)
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) reentrant //using 0
41 {
42 1 #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
43 1 OS_CPU_SR cpu_sr;
44 1 #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;
C51 COMPILER V7.06 OS_TASK 07/18/2003 11:06:04 PAGE 2
55 1 INT8U y_old;
56 1
57 1
58 1 #if OS_ARG_CHK_EN > 0
59 1 if (oldprio >= OS_LOWEST_PRIO) {
60 2 if (oldprio != OS_PRIO_SELF) {
61 3 return (OS_PRIO_INVALID);
62 3 }
63 2 }
64 1 if (newprio >= OS_LOWEST_PRIO) {
65 2 return (OS_PRIO_INVALID);
66 2 }
67 1 #endif
68 1 OS_ENTER_CRITICAL();
69 1 if (OSTCBPrioTbl[newprio] != (OS_TCB *)0) { /* New priority must not already exist */
70 2 OS_EXIT_CRITICAL();
71 2 return (OS_PRIO_EXIST);
72 2 }
73 1 if (oldprio == OS_PRIO_SELF) { /* See if changing self */
74 2 oldprio = OSTCBCur->OSTCBPrio; /* Yes, get priority */
75 2 }
76 1 ptcb = OSTCBPrioTbl[oldprio];
77 1 if (ptcb == (OS_TCB *)0) { /* Does task to change exist? */
78 2 OS_EXIT_CRITICAL(); /* No, can't change its priority! */
79 2 return (OS_PRIO_ERR);
80 2 }
81 1 y = newprio >> 3; /* Yes, compute new TCB fields */
82 1 bity = OSMapTbl[y];
83 1 x = newprio & 0x07;
84 1 bitx = OSMapTbl[x];
85 1 OSTCBPrioTbl[oldprio] = (OS_TCB *)0; /* Remove TCB from old priority */
86 1 OSTCBPrioTbl[newprio] = ptcb; /* Place pointer to TCB @ new priority */
87 1 y_old = ptcb->OSTCBY;
88 1 if ((OSRdyTbl[y_old] & ptcb->OSTCBBitX) != 0x00) { /* If task is ready make it not */
89 2 OSRdyTbl[y_old] &= ~ptcb->OSTCBBitX;
90 2 if (OSRdyTbl[y_old] == 0x00) {
91 3 OSRdyGrp &= ~ptcb->OSTCBBitY;
92 3 }
93 2 OSRdyGrp |= bity; /* Make new priority ready to run */
94 2 OSRdyTbl[y] |= bitx;
95 2 #if OS_EVENT_EN > 0
96 2 } else { /* Task was not ready ... */
97 2 pevent = ptcb->OSTCBEventPtr;
98 2 if (pevent != (OS_EVENT *)0) { /* ... remove from event wait list */
99 3 pevent->OSEventTbl[y_old] &= ~ptcb->OSTCBBitX;
100 3 if (pevent->OSEventTbl[y_old] == 0) {
101 4 pevent->OSEventGrp &= ~ptcb->OSTCBBitY;
102 4 }
103 3 pevent->OSEventGrp |= bity; /* Add new priority to wait list */
104 3 pevent->OSEventTbl[y] |= bitx;
105 3 }
106 2 #endif
107 2 }
108 1 ptcb->OSTCBPrio = newprio; /* Set new task priority */
109 1 ptcb->OSTCBY = y;
110 1 ptcb->OSTCBX = x;
111 1 ptcb->OSTCBBitY = bity;
112 1 ptcb->OSTCBBitX = bitx;
113 1 OS_EXIT_CRITICAL();
114 1 OS_Sched(); /* Run highest priority task ready */
115 1 return (OS_NO_ERR);
116 1 }
C51 COMPILER V7.06 OS_TASK 07/18/2003 11:06:04 PAGE 3
117 #endif
118 /*$PAGE*/
119 /*
120 *********************************************************************************************************
121 * CREATE A TASK
122 *
123 * Description: This function is used to have uC/OS-II manage the execution of a task. Tasks can either
124 * be created prior to the start of multitasking or by a running task. A task cannot be
125 * created by an ISR.
126 *
127 * Arguments : task is a pointer to the task's code
128 *
129 * pdata is a pointer to an optional data area which can be used to pass parameters to
130 * the task when the task first executes. Where the task is concerned it thinks
131 * it was invoked and passed the argument 'pdata' as follows:
132 *
133 * void Task (void *pdata)
134 * {
135 * for (;;) {
136 * Task code;
137 * }
138 * }
139 *
140 * ptos is a pointer to the task's top of stack. If the configuration constant
141 * OS_STK_GROWTH is set to 1, the stack is assumed to grow downward (i.e. from high
142 * memory to low memory). 'pstk' will thus point to the highest (valid) memory
143 * location of the stack. If OS_STK_GROWTH is set to 0, 'pstk' will point to the
144 * lowest memory location of the stack and the stack will grow with increasing
145 * memory locations.
146 *
147 * prio is the task's priority. A unique priority MUST be assigned to each task and the
148 * lower the number, the higher the priority.
149 *
150 * Returns : OS_NO_ERR if the function was successful.
151 * OS_PRIO_EXIT if the task priority already exist
152 * (each task MUST have a unique priority).
153 * OS_PRIO_INVALID if the priority you specify is higher that the maximum allowed
154 * (i.e. >= OS_LOWEST_PRIO)
155 *********************************************************************************************************
156 */
157
158 #if OS_TASK_CREATE_EN > 0
159 INT8U OSTaskCreate (void (*task)(void *pd), void *pndata, OS_STK *ptos, INT8U prio) reentrant //using 0
160 {
161 1 #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
162 1 OS_CPU_SR cpu_sr;
163 1 #endif
164 1 OS_STK *psp;
165 1 INT8U err;
166 1
167 1
168 1 #if OS_ARG_CHK_EN > 0
169 1 if (prio > OS_LOWEST_PRIO) { /* Make sure priority is within allowable range */
170 2 return (OS_PRIO_INVALID);
171 2 }
172 1 #endif
173 1 OS_ENTER_CRITICAL();
174 1 if (OSTCBPrioTbl[prio] == (OS_TCB *)0) { /* Make sure task doesn't already exist at this priority */
175 2 OSTCBPrioTbl[prio] = (OS_TCB *)1; /* Reserve the priority to prevent others from doing ... */
176 2 /* ... the same thing until task is created. */
177 2 OS_EXIT_CRITICAL();
178 2 psp = (OS_STK *)OSTaskStkInit(task, pndata, ptos, 0); /* Initialize the task's stack */
C51 COMPILER V7.06 OS_TASK 07/18/2003 11:06:04 PAGE 4
179 2 err = OS_TCBInit(prio, psp, (OS_STK *)0, 0, 0, (void *)0, 0);
180 2 if (err == OS_NO_ERR) {
181 3 OS_ENTER_CRITICAL();
182 3 OSTaskCtr++; /* Increment the #tasks counter */
183 3 OS_EXIT_CRITICAL();
184 3 if (OSRunning == TRUE) { /* Find highest priority task if multitasking has started */
185 4 OS_Sched();
186 4 }
187 3 } else {
188 3 OS_ENTER_CRITICAL();
189 3 OSTCBPrioTbl[prio] = (OS_TCB *)0;/* Make this priority available to others */
190 3 OS_EXIT_CRITICAL();
191 3 }
192 2 return (err);
193 2 }
194 1 OS_EXIT_CRITICAL();
195 1 return (OS_PRIO_EXIST);
196 1 }
197 #endif
198 /*$PAGE*/
199 /*
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -