📄 os_task.lst
字号:
176 1 INT8U err;
177 1
178 1 if (prio > OS_LOWEST_PRIO) { /* Make sure priority is within allowable range */
179 2 return (OS_PRIO_INVALID);
180 2 }
181 1 OS_ENTER_CRITICAL();
182 1 if (OSTCBPrioTbl[prio] == (OS_TCB DT_XDATA *)0) { /* Make sure task doesn't already exist at this prio
-rity */
183 2 OSTCBPrioTbl[prio] = (OS_TCB DT_XDATA *)1; /* Reserve the priority to prevent others from doing
- ... */
184 2 /* ... the same thing until task is created. */
185 2 OS_EXIT_CRITICAL();
186 2 psp = (void DT_XDATA *)OSTaskStkInit(task, ppdata, ptos, 0); /* Initialize the task's stack
- */
187 2 err = OSTCBInit(prio, psp, (void DT_XDATA *)0, 0, 0, (void DT_XDATA *)0, 0);
188 2 if (err == OS_NO_ERR) {
189 3 OS_ENTER_CRITICAL();
190 3 OSTaskCtr++; /* Increment the #tasks counter */
191 3 OSTaskCreateHook(OSTCBPrioTbl[prio]); /* Call user defined hook */
192 3 OS_EXIT_CRITICAL();
193 3 if (OSRunning) { /* Find highest priority task if multitasking has started */
194 4 OSSched();
195 4 }
196 3 } else {
197 3 OS_ENTER_CRITICAL();
198 3 OSTCBPrioTbl[prio] = (OS_TCB DT_XDATA *)0;/* Make this priority available to others
- */
199 3 OS_EXIT_CRITICAL();
200 3 }
201 2 return (err);
202 2 } else {
203 2 OS_EXIT_CRITICAL();
204 2 return (OS_PRIO_EXIST);
205 2 }
206 1 }
207 #endif
208 /*$PAGE*/
209 /*
210 *********************************************************************************************************
211 * CREATE A TASK (Extended Version)
212 *
213 * Description: This function is used to have uC/OS-II manage the execution of a task. Tasks can either
214 * be created prior to the start of multitasking or by a running task. A task cannot be
215 * created by an ISR. This function is similar to OSTaskCreate() except that it allows
216 * additional information about a task to be specified.
217 *
218 * Arguments : task is a pointer to the task's code
219 *
220 * ppdata is a pointer to an optional data area which can be used to pass parameters to
221 * the task when the task first executes. Where the task is concerned it thinks
222 * it was invoked and passed the argument 'ppdata' as follows:
223 *
224 * void Task (void *ppdata)
225 * {
226 * for (;;) {
227 * Task code;
228 * }
229 * }
C51 COMPILER V8.08 OS_TASK 11/08/2008 14:01:54 PAGE 5
230 *
231 * ptos is a pointer to the task's top of stack. If the configuration constant
232 * OS_STK_GROWTH is set to 1, the stack is assumed to grow downward (i.e. from high
233 * memory to low memory). 'pstk' will thus point to the highest (valid) memory
234 * location of the stack. If OS_STK_GROWTH is set to 0, 'pstk' will point to the
235 * lowest memory location of the stack and the stack will grow with increasing
236 * memory locations. 'pstk' MUST point to a valid 'free' data item.
237 *
238 * prio is the task's priority. A unique priority MUST be assigned to each task and the
239 * lower the number, the higher the priority.
240 *
241 * id is the task's ID (0..65535)
242 *
243 * pbos is a pointer to the task's bottom of stack. If the configuration constant
244 * OS_STK_GROWTH is set to 1, the stack is assumed to grow downward (i.e. from high
245 * memory to low memory). 'pbos' will thus point to the LOWEST (valid) memory
246 * location of the stack. If OS_STK_GROWTH is set to 0, 'pbos' will point to the
247 * HIGHEST memory location of the stack and the stack will grow with increasing
248 * memory locations. 'pbos' MUST point to a valid 'free' data item.
249 *
250 * stk_size is the size of the stack in number of elements. If OS_STK is set to INT8U,
251 * 'stk_size' corresponds to the number of bytes available. If OS_STK is set to
252 * INT16U, 'stk_size' contains the number of 16-bit entries available. Finally, if
253 * OS_STK is set to INT32U, 'stk_size' contains the number of 32-bit entries
254 * available on the stack.
255 *
256 * pext is a pointer to a user supplied memory location which is used as a TCB extension.
257 * For example, this user memory can hold the contents of floating-point registers
258 * during a context switch, the time each task takes to execute, the number of times
259 * the task has been switched-in, etc.
260 *
261 * opt contains additional information (or options) about the behavior of the task. The
262 * LOWER 8-bits are reserved by uC/OS-II while the upper 8 bits can be application
263 * specific. See OS_TASK_OPT_??? in uCOS-II.H.
264 *
265 * Returns : OS_NO_ERR if the function was successful.
266 * OS_PRIO_EXIT if the task priority already exist
267 * (each task MUST have a unique priority).
268 * OS_PRIO_INVALID if the priority you specify is higher that the maximum allowed
269 * (i.e. > OS_LOWEST_PRIO)
270 *********************************************************************************************************
271 */
272 /*$PAGE*/
273 #if OS_TASK_CREATE_EXT_EN
INT8U OSTaskCreateExt (void (DT_CODE *task)(void DT_XDATA *pd),
void DT_XDATA *ppdata,
OS_STK DT_XDATA *ptos,
INT8U prio,
INT16U id,
OS_STK DT_XDATA *pbos,
INT32U stk_size,
void DT_XDATA *pext,
INT16U opt) REENTRANT
{
void DT_XDATA *psp;
INT8U err;
INT16U i;
OS_STK DT_XDATA *pfill;
if (prio > OS_LOWEST_PRIO) { /* Make sure priority is within allowable range */
return (OS_PRIO_INVALID);
C51 COMPILER V8.08 OS_TASK 11/08/2008 14:01:54 PAGE 6
}
OS_ENTER_CRITICAL();
if (OSTCBPrioTbl[prio] == (OS_TCB DT_XDATA *)0) { /* Make sure task doesn't already exist at this prio
-rity */
OSTCBPrioTbl[prio] = (OS_TCB DT_XDATA *)1; /* Reserve the priority to prevent others from doing
- ... */
/* ... the same thing until task is created. */
OS_EXIT_CRITICAL();
if (opt & OS_TASK_OPT_STK_CHK) { /* See if stack checking has been enabled */
if (opt & OS_TASK_OPT_STK_CLR) { /* See if stack needs to be cleared */
pfill = pbos; /* Yes, fill the stack with zeros */
for (i = 0; i < stk_size; i++) {
#if OS_STK_GROWTH == 1
*pfill++ = (OS_STK)0;
#else
*pfill-- = (OS_STK)0;
#endif
}
}
}
psp = (void DT_XDATA *)OSTaskStkInit(task, ppdata, ptos, opt); /* Initialize the task's stack
- */
err = OSTCBInit(prio, psp, pbos, id, stk_size, pext, opt);
if (err == OS_NO_ERR) {
OS_ENTER_CRITICAL();
OSTaskCtr++; /* Increment the #tasks counter */
OSTaskCreateHook(OSTCBPrioTbl[prio]); /* Call user defined hook */
OS_EXIT_CRITICAL();
if (OSRunning) { /* Find highest priority task if multitasking has started */
OSSched();
}
} else {
OS_ENTER_CRITICAL();
OSTCBPrioTbl[prio] = (OS_TCB DT_XDATA *)0;/* Make this priority available to others
- */
OS_EXIT_CRITICAL();
}
return (err);
} else {
OS_EXIT_CRITICAL();
return (OS_PRIO_EXIST);
}
}
#endif
334 /*$PAGE*/
335 /*
336 *********************************************************************************************************
337 * DELETE A TASK
338 *
339 * Description: This function allows you to delete a task. The calling task can delete itself by
340 * its own priority number. The deleted task is returned to the dormant state and can be
341 * re-activated by creating the deleted task again.
342 *
343 * Arguments : prio is the priority of the task to delete. Note that you can explicitely delete
344 * the current task without knowing its priority level by setting 'prio' to
345 * OS_PRIO_SELF.
346 *
347 * Returns : OS_NO_ERR if the call is successful
348 * OS_TASK_DEL_IDLE if you attempted to delete uC/OS-II's idle task
349 * OS_PRIO_INVALID if the priority you specify is higher that the maximum allowed
C51 COMPILER V8.08 OS_TASK 11/08/2008 14:01:54 PAGE 7
350 * (i.e. >= OS_LOWEST_PRIO) or, you have not specified OS_PRIO_SELF.
351 * OS_TASK_DEL_ERR if the task you want to delete does not exist
352 * OS_TASK_DEL_ISR if you tried to delete a task from an ISR
353 *
354 * Notes : 1) To reduce interrupt latency, OSTaskDel() 'disables' the task:
355 * a) by making it not ready
356 * b) by removing it from any wait lists
357 * c) by preventing OSTimeTick() from making the task ready to run.
358 * The task can then be 'unlinked' from the miscellaneous structures in uC/OS-II.
359 * 2) The function OSDummy() is called after OS_EXIT_CRITICAL() because, on most processors,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -