📄 os_task.lst
字号:
if (prio > OS_LOWEST_PRIO) { /* Make sure priority is within allowable range */
return (OS_PRIO_INVALID);
}
OS_ENTER_CRITICAL();
if (OSTCBPrioTbl[prio] == (OS_TCB *)0) { /* Make sure task doesn't already exist at this priority */
OSTCBPrioTbl[prio] = (OS_TCB *)1; /* Reserve the priority to prevent others from doing ... */
/* ... the same thing until task is created. */
OS_EXIT_CRITICAL();
psp = (void *)OSTaskStkInit(task, dataptr, ptos, 0); /* Initialize the task's stack *
-/
err = OSTCBInit(prio, psp, (void *)0, 0, 0, (void *)0, 0);
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 *)0;/* Make this priority available to others */
OS_EXIT_CRITICAL();
}
return (err);
} else {
OS_EXIT_CRITICAL();
return (OS_PRIO_EXIST);
}
}
#endif
216 /*$PAGE*/
217 /*
218 *********************************************************************************************************
219 * CREATE A TASK (Extended Version)
220 *
221 * Description: This function is used to have uC/OS-II manage the execution of a task. Tasks can either
222 * be created prior to the start of multitasking or by a running task. A task cannot be
223 * created by an ISR. This function is similar to OSTaskCreate() except that it allows
224 * additional information about a task to be specified.
225 *
226 * Arguments : task is a pointer to the task's code
227 *
228 * dataptr is a pointer to an optional data area which can be used to pass parameters to
229 * the task when the task first executes. Where the task is concerned it thinks
230 * it was invoked and passed the argument 'dataptr' as follows:
231 *
232 * void Task (void *dataptr)
233 * {
234 * for (;;) {
235 * Task code;
236 * }
237 * }
238 *
239 * ptos is a pointer to the task's top of stack. If the configuration constant
240 * OS_STK_GROWTH is set to 1, the stack is assumed to grow downward (i.e. from high
C51 COMPILER V8.08 OS_TASK 04/13/2009 13:31:22 PAGE 5
241 * memory to low memory). 'pstk' will thus point to the highest (valid) memory
242 * location of the stack. If OS_STK_GROWTH is set to 0, 'pstk' will point to the
243 * lowest memory location of the stack and the stack will grow with increasing
244 * memory locations. 'pstk' MUST point to a valid 'free' data item.
245 *
246 * prio is the task's priority. A unique priority MUST be assigned to each task and the
247 * lower the number, the higher the priority.
248 *
249 * id is the task's ID (0..65535)
250 *
251 * pbos is a pointer to the task's bottom of stack. If the configuration constant
252 * OS_STK_GROWTH is set to 1, the stack is assumed to grow downward (i.e. from high
253 * memory to low memory). 'pbos' will thus point to the LOWEST (valid) memory
254 * location of the stack. If OS_STK_GROWTH is set to 0, 'pbos' will point to the
255 * HIGHEST memory location of the stack and the stack will grow with increasing
256 * memory locations. 'pbos' MUST point to a valid 'free' data item.
257 *
258 * stk_size is the size of the stack in number of elements. If OS_STK is set to INT8U,
259 * 'stk_size' corresponds to the number of bytes available. If OS_STK is set to
260 * INT16U, 'stk_size' contains the number of 16-bit entries available. Finally, if
261 * OS_STK is set to INT32U, 'stk_size' contains the number of 32-bit entries
262 * available on the stack.
263 *
264 * pext is a pointer to a user supplied memory location which is used as a TCB extension.
265 * For example, this user memory can hold the contents of floating-point registers
266 * during a context switch, the time each task takes to execute, the number of times
267 * the task has been switched-in, etc.
268 *
269 * opt contains additional information (or options) about the behavior of the task. The
270 * LOWER 8-bits are reserved by uC/OS-II while the upper 8 bits can be application
271 * specific. See OS_TASK_OPT_??? in uCOS-II.H.
272 *
273 * Returns : OS_NO_ERR if the function was successful.
274 * OS_PRIO_EXIT if the task priority already exist
275 * (each task MUST have a unique priority).
276 * OS_PRIO_INVALID if the priority you specify is higher that the maximum allowed
277 * (i.e. > OS_LOWEST_PRIO)
278 *********************************************************************************************************
279 */
280 /*$PAGE*/
281 #if OS_TASK_CREATE_EXT_EN
282 INT8U OSTaskCreateExt (void (*task)(void *pd),
283 void *dataptr,
284 OS_STK *ptos,
285 INT8U prio,
286 INT16U id,
287 OS_STK *pbos,
288 INT32U stk_size,
289 void *pext,
290 INT16U opt) reentrant
291 {
292 1 #if OS_CRITICAL_METHOD == 2
293 1 unsigned DTYPE int_ss;
294 1 #endif
295 1
296 1 //void *psp;
297 1 INT8U err;
298 1 INT16U i;
299 1 OS_STK *pfill;
300 1
301 1
302 1 if (prio > OS_LOWEST_PRIO) { /* Make sure priority is within allowable range */
C51 COMPILER V8.08 OS_TASK 04/13/2009 13:31:22 PAGE 6
303 2 return (OS_PRIO_INVALID);
304 2 }
305 1 OS_ENTER_CRITICAL();
306 1 if (OSTCBPrioTbl[prio] == (OS_TCB *)0) { /* Make sure task doesn't already exist at this priority */
307 2 OSTCBPrioTbl[prio] = (OS_TCB *)1; /* Reserve the priority to prevent others from doing ... */
308 2 /* ... the same thing until task is created. */
309 2 OS_EXIT_CRITICAL();
310 2
311 2 if (opt & OS_TASK_OPT_STK_CHK) { /* See if stack checking has been enabled */
312 3 if (opt & OS_TASK_OPT_STK_CLR) { /* See if stack needs to be cleared */
313 4 pfill = pbos; /* Yes, fill the stack with zeros */
314 4 for (i = 0; i < stk_size; i++) {
315 5 #if OS_STK_GROWTH == 1
316 5 *pfill++ = (OS_STK)0;
317 5 #else
*pfill-- = (OS_STK)0;
#endif
320 5 }
321 4 }
322 3 }
323 2
324 2 OSSimSTKBP=(OS_STK*)ptos; //appended by ring wang
325 2 OSTaskStkInit(task, dataptr, pbos, (INT16U)OSSimSTKBP); /* Initialize the task's stack
-*/
326 2 err = OSTCBInit(prio, pbos, ptos, id, stk_size, pext, opt);
327 2 if (err == OS_NO_ERR) {
328 3 OS_ENTER_CRITICAL();
329 3 OSTaskCtr++; /* Increment the #tasks counter */
330 3 OSTaskCreateHook(OSTCBPrioTbl[prio]); /* Call user defined hook */
331 3 OS_EXIT_CRITICAL();
332 3 if (OSRunning) { /* Find highest priority task if multitasking has started */
333 4 OSSched();
334 4 }
335 3 } else {
336 3 OS_ENTER_CRITICAL();
337 3 OSTCBPrioTbl[prio] = (OS_TCB *)0;/* Make this priority available to others */
338 3 OS_EXIT_CRITICAL();
339 3 }
340 2 return (err);
341 2 } else {
342 2 OS_EXIT_CRITICAL();
343 2 return (OS_PRIO_EXIST);
344 2 }
345 1 }
346 #endif
347 /*$PAGE*/
348 /*
349 *********************************************************************************************************
350 * DELETE A TASK
351 *
352 * Description: This function allows you to delete a task. The calling task can delete itself by
353 * its own priority number. The deleted task is returned to the dormant state and can be
354 * re-activated by creating the deleted task again.
355 *
356 * Arguments : prio is the priority of the task to delete. Note that you can explicitely delete
357 * the current task without knowing its priority level by setting 'prio' to
358 * OS_PRIO_SELF.
359 *
360 * Returns : OS_NO_ERR if the call is successful
361 * OS_TASK_DEL_IDLE if you attempted to delete uC/OS-II's idle task
362 * OS_PRIO_INVALID if the priority you specify is higher that the maximum allowed
363 * (i.e. >= OS_LOWEST_PRIO) or, you have not specified OS_PRIO_SELF.
C51 COMPILER V8.08 OS_TASK 04/13/2009 13:31:22 PAGE 7
364 * OS_TASK_DEL_ERR if the task you want to delete does not exist
365 * OS_TASK_DEL_ISR if you tried to delete a task from an ISR
366 *
367 * Notes : 1) To reduce interrupt latency, OSTaskDel() 'disables' the task:
368 * a) by making it not ready
369 * b) by removing it from any wait lists
370 * c) by preventing OSTimeTick() from making the task ready to run.
371 * The task can then be 'unlinked' from the miscellaneous structures in uC/OS-II.
372 * 2) The function OSDummy() is called after OS_EXIT_CRITICAL() because, on most processors,
373 * the next instruction following the enable interrupt instruction is ignored. You can
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -