📄 os_task.lst
字号:
227:../OSsrc/os_task.c **** }
228:../OSsrc/os_task.c **** #endif
229:../OSsrc/os_task.c **** /*$PAGE*/
230:../OSsrc/os_task.c **** /*
231:../OSsrc/os_task.c **** ***************************************************************************************************
232:../OSsrc/os_task.c **** * CREATE A TASK (Extended Version)
233:../OSsrc/os_task.c **** *
234:../OSsrc/os_task.c **** * Description: This function is used to have uC/OS-II manage the execution of a task. Tasks can ei
235:../OSsrc/os_task.c **** * be created prior to the start of multitasking or by a running task. A task cannot b
236:../OSsrc/os_task.c **** * created by an ISR. This function is similar to OSTaskCreate() except that it allows
237:../OSsrc/os_task.c **** * additional information about a task to be specified.
238:../OSsrc/os_task.c **** *
239:../OSsrc/os_task.c **** * Arguments : task is a pointer to the task's code
240:../OSsrc/os_task.c **** *
241:../OSsrc/os_task.c **** * p_arg is a pointer to an optional data area which can be used to pass parameters
242:../OSsrc/os_task.c **** * the task when the task first executes. Where the task is concerned it thi
243:../OSsrc/os_task.c **** * it was invoked and passed the argument 'p_arg' as follows:
244:../OSsrc/os_task.c **** *
245:../OSsrc/os_task.c **** * void Task (void *p_arg)
246:../OSsrc/os_task.c **** * {
247:../OSsrc/os_task.c **** * for (;;) {
248:../OSsrc/os_task.c **** * Task code;
249:../OSsrc/os_task.c **** * }
250:../OSsrc/os_task.c **** * }
251:../OSsrc/os_task.c **** *
252:../OSsrc/os_task.c **** * ptos is a pointer to the task's top of stack. If the configuration constant
253:../OSsrc/os_task.c **** * OS_STK_GROWTH is set to 1, the stack is assumed to grow downward (i.e. fro
254:../OSsrc/os_task.c **** * memory to low memory). 'ptos' will thus point to the highest (valid) memo
255:../OSsrc/os_task.c **** * location of the stack. If OS_STK_GROWTH is set to 0, 'ptos' will point to
256:../OSsrc/os_task.c **** * lowest memory location of the stack and the stack will grow with increasin
257:../OSsrc/os_task.c **** * memory locations. 'ptos' MUST point to a valid 'free' data item.
258:../OSsrc/os_task.c **** *
259:../OSsrc/os_task.c **** * prio is the task's priority. A unique priority MUST be assigned to each task a
260:../OSsrc/os_task.c **** * lower the number, the higher the priority.
261:../OSsrc/os_task.c **** *
262:../OSsrc/os_task.c **** * id is the task's ID (0..65535)
263:../OSsrc/os_task.c **** *
264:../OSsrc/os_task.c **** * pbos is a pointer to the task's bottom of stack. If the configuration constant
265:../OSsrc/os_task.c **** * OS_STK_GROWTH is set to 1, the stack is assumed to grow downward (i.e. fro
266:../OSsrc/os_task.c **** * memory to low memory). 'pbos' will thus point to the LOWEST (valid) memor
267:../OSsrc/os_task.c **** * location of the stack. If OS_STK_GROWTH is set to 0, 'pbos' will point to
268:../OSsrc/os_task.c **** * HIGHEST memory location of the stack and the stack will grow with increasi
269:../OSsrc/os_task.c **** * memory locations. 'pbos' MUST point to a valid 'free' data item.
270:../OSsrc/os_task.c **** *
271:../OSsrc/os_task.c **** * stk_size is the size of the stack in number of elements. If OS_STK is set to INT8U
272:../OSsrc/os_task.c **** * 'stk_size' corresponds to the number of bytes available. If OS_STK is set
273:../OSsrc/os_task.c **** * INT16U, 'stk_size' contains the number of 16-bit entries available. Final
274:../OSsrc/os_task.c **** * OS_STK is set to INT32U, 'stk_size' contains the number of 32-bit entries
275:../OSsrc/os_task.c **** * available on the stack.
276:../OSsrc/os_task.c **** *
277:../OSsrc/os_task.c **** * pext is a pointer to a user supplied memory location which is used as a TCB ext
278:../OSsrc/os_task.c **** * For example, this user memory can hold the contents of floating-point regi
279:../OSsrc/os_task.c **** * during a context switch, the time each task takes to execute, the number o
280:../OSsrc/os_task.c **** * the task has been switched-in, etc.
281:../OSsrc/os_task.c **** *
282:../OSsrc/os_task.c **** * opt contains additional information (or options) about the behavior of the tas
283:../OSsrc/os_task.c **** * LOWER 8-bits are reserved by uC/OS-II while the upper 8 bits can be applic
284:../OSsrc/os_task.c **** * specific. See OS_TASK_OPT_??? in uCOS-II.H. Current choices are:
285:../OSsrc/os_task.c **** *
286:../OSsrc/os_task.c **** * OS_TASK_OPT_STK_CHK Stack checking to be allowed for the task
287:../OSsrc/os_task.c **** * OS_TASK_OPT_STK_CLR Clear the stack when the task is created
288:../OSsrc/os_task.c **** * OS_TASK_OPT_SAVE_FP If the CPU has floating-point registers, save the
289:../OSsrc/os_task.c **** * during a context switch.
290:../OSsrc/os_task.c **** *
291:../OSsrc/os_task.c **** * Returns : OS_ERR_NONE if the function was successful.
292:../OSsrc/os_task.c **** * OS_PRIO_EXIT if the task priority already exist
293:../OSsrc/os_task.c **** * (each task MUST have a unique priority).
294:../OSsrc/os_task.c **** * OS_ERR_PRIO_INVALID if the priority you specify is higher that the maximum allow
295:../OSsrc/os_task.c **** * (i.e. > OS_LOWEST_PRIO)
296:../OSsrc/os_task.c **** * OS_ERR_TASK_CREATE_ISR if you tried to create a task from an ISR.
297:../OSsrc/os_task.c **** ***************************************************************************************************
298:../OSsrc/os_task.c **** */
299:../OSsrc/os_task.c **** /*$PAGE*/
300:../OSsrc/os_task.c **** #if OS_TASK_CREATE_EXT_EN > 0
301:../OSsrc/os_task.c **** INT8U OSTaskCreateExt (void (*task)(void *p_arg),
302:../OSsrc/os_task.c **** void *p_arg,
303:../OSsrc/os_task.c **** OS_STK *ptos,
304:../OSsrc/os_task.c **** INT8U prio,
305:../OSsrc/os_task.c **** INT16U id,
306:../OSsrc/os_task.c **** OS_STK *pbos,
307:../OSsrc/os_task.c **** INT32U stk_size,
308:../OSsrc/os_task.c **** void *pext,
309:../OSsrc/os_task.c **** INT16U opt)
310:../OSsrc/os_task.c **** {
311:../OSsrc/os_task.c **** OS_STK *psp;
312:../OSsrc/os_task.c **** INT8U err;
313:../OSsrc/os_task.c **** #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register
314:../OSsrc/os_task.c **** OS_CPU_SR cpu_sr = 0;
315:../OSsrc/os_task.c **** #endif
316:../OSsrc/os_task.c ****
317:../OSsrc/os_task.c ****
318:../OSsrc/os_task.c ****
319:../OSsrc/os_task.c **** #if OS_ARG_CHK_EN > 0
320:../OSsrc/os_task.c **** if (prio > OS_LOWEST_PRIO) { /* Make sure priority is within allowable range
321:../OSsrc/os_task.c **** return (OS_ERR_PRIO_INVALID);
322:../OSsrc/os_task.c **** }
323:../OSsrc/os_task.c **** #endif
324:../OSsrc/os_task.c **** OS_ENTER_CRITICAL();
325:../OSsrc/os_task.c **** if (OSIntNesting > 0) { /* Make sure we don't create the task from within an I
326:../OSsrc/os_task.c **** OS_EXIT_CRITICAL();
327:../OSsrc/os_task.c **** return (OS_ERR_TASK_CREATE_ISR);
328:../OSsrc/os_task.c **** }
329:../OSsrc/os_task.c **** if (OSTCBPrioTbl[prio] == (OS_TCB *)0) { /* Make sure task doesn't already exist at this priori
330:../OSsrc/os_task.c **** OSTCBPrioTbl[prio] = OS_TCB_RESERVED;/* Reserve the priority to prevent others from doing .
331:../OSsrc/os_task.c **** /* ... the same thing until task is created.
332:../OSsrc/os_task.c **** OS_EXIT_CRITICAL();
333:../OSsrc/os_task.c ****
334:../OSsrc/os_task.c **** #if OS_TASK_STAT_STK_CHK_EN > 0
335:../OSsrc/os_task.c **** OS_TaskStkClr(pbos, stk_size, opt); /* Clear the task stack (if needed)
336:../OSsrc/os_task.c **** #endif
337:../OSsrc/os_task.c ****
338:../OSsrc/os_task.c **** psp = OSTaskStkInit(task, p_arg, ptos, opt); /* Initialize the task's stack
339:../OSsrc/os_task.c **** err = OS_TCBInit(prio, psp, pbos, id, stk_size, pext, opt);
340:../OSsrc/os_task.c **** if (err == OS_ERR_NONE) {
341:../OSsrc/os_task.c **** if (OSRunning == OS_TRUE) { /* Find HPT if multitasking has star
342:../OSsrc/os_task.c **** OS_Sched();
343:../OSsrc/os_task.c **** }
344:../OSsrc/os_task.c **** } else {
345:../OSsrc/os_task.c **** OS_ENTER_CRITICAL();
346:../OSsrc/os_task.c **** OSTCBPrioTbl[prio] = (OS_TCB *)0; /* Make this priority avail. to othe
347:../OSsrc/os_task.c **** OS_EXIT_CRITICAL();
348:../OSsrc/os_task.c **** }
349:../OSsrc/os_task.c **** return (err);
350:../OSsrc/os_task.c **** }
351:../OSsrc/os_task.c **** OS_EXIT_CRITICAL();
352:../OSsrc/os_task.c **** return (OS_ERR_PRIO_EXIST);
353:../OSsrc/os_task.c **** }
354:../OSsrc/os_task.c **** #endif
355:../OSsrc/os_task.c **** /*$PAGE*/
356:../OSsrc/os_task.c **** /*
357:../OSsrc/os_task.c **** ***************************************************************************************************
358:../OSsrc/os_task.c **** * DELETE A TASK
359:../OSsrc/os_task.c **** *
360:../OSsrc/os_task.c **** * Description: This function allows you to delete a task. The calling task can delete itself by
361:../OSsrc/os_task.c **** * its own priority number. The deleted task is returned to the dormant state and can
362:../OSsrc/os_task.c **** * re-activated by creating the deleted task again.
363:../OSsrc/os_task.c **** *
364:../OSsrc/os_task.c **** * Arguments : prio is the priority of the task to delete. Note that you can explicitely delete
365:../OSsrc/os_task.c **** * the current task without knowing its priority level by setting 'prio' to
366:../OSsrc/os_task.c **** * OS_PRIO_SELF.
367:../OSsrc/os_task.c **** *
368:../OSsrc/os_task.c **** * Returns : OS_ERR_NONE if the call is successful
369:../OSsrc/os_task.c **** * OS_ERR_TASK_DEL_IDLE if you attempted to delete uC/OS-II's idle task
370:../OSsrc/os_task.c **** * OS_ERR_PRIO_INVALID if the priority you specify is higher that the maximum allow
371:../OSsrc/os_task.c **** * (i.e. >= OS_LOWEST_PRIO) or, you have not specified OS_PRIO_
372:../OSsrc/os_task.c **** * OS_ERR_TASK_DEL if the task is assigned to a Mutex PIP.
373:../OSsrc/os_task.c **** * OS_ERR_TASK_NOT_EXIST if the task you want to delete does not exist.
374:../OSsrc/os_task.c **** * OS_ERR_TASK_DEL_ISR if you tried to delete a task from an ISR
375:../OSsrc/os_task.c **** *
376:../OSsrc/os_task.c **** * Notes : 1) To reduce interrupt latency, OSTaskDel() 'disables' the task:
377:../OSsrc/os_task.c **** * a) by making it not ready
378:../OSsrc/os_task.c **** * b) by removing it from any wait lists
379:../OSsrc/os_task.c **** * c) by preventing OSTimeTick() from making the task ready to run.
380:../OSsrc/os_task.c **** * The task can then be 'unlinked' from the miscellaneous structures in uC/OS-II.
381:../OSsrc/os_task.c **** * 2) The function OS_Dummy() is called after OS_EXIT_CRITICAL() because, on most proce
382:../OSsrc/os_task.c **** * the next instruction following the enable interrupt instruction is ignored.
383:../OSsrc/os_task.c **** * 3) An ISR cannot delete a task.
384:../OSsrc/os_task.c **** * 4) The lock nesting counter is incremented because, for a brief instant, if the curr
385:../OSsrc/os_task.c **** * task is being deleted, the current task would not be able to be rescheduled becau
386:../OSsrc/os_task.c **** * is removed from the ready list. Incrementing the nesting counter prevents anothe
387:../OSsrc/os_task.c **** * from being schedule. This means that an ISR would return to the current task whi
388:../OSsrc/os_task.c **** * being deleted. The rest of the deletion would thus be able to be completed.
389:../OSsrc/os_task.c **** ***************************************************************************************************
390:../OSsrc/os_task.c **** */
391:../OSsrc/os_task.c **** /*$PAGE*/
392:../OSsrc/os_task.c **** #if OS_TASK_DEL_EN > 0
393:../OSsrc/os_task.c **** INT8U OSTaskDel (INT8U prio)
394:../OSsrc/os_task.c **** {
395:../OSsrc/os_task.c **** #if OS_EVENT_EN
396:../OSsrc/os_task.c **** OS_EVENT *pevent;
397:../OSsrc/os_task.c **** #endif
398:../OSsrc/os_task.c **** #if (OS_FLAG_EN > 0) && (OS_MAX_FLAGS > 0)
399:../OSsrc/os_task.c **** OS_FLAG_NODE *pnode;
400:../OSsrc/os_task.c **** #endif
401:../OSsrc/os_task.c **** OS_TCB *ptcb;
402:../OSsrc/os_task.c **** INT8U y;
403:../OSsrc/os_task.c **** #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register
404:../OSsrc/os_task.c **** OS_CPU_SR cpu_sr = 0;
405:../OSsrc/os_task.c **** #endif
406:../OSsrc/os_task.c ****
407:../OSsrc/os_task.c ****
408:../OSsrc/os_task.c ****
409:../OSsrc/os_task.c **** if (OSIntNesting > 0) { /* See if trying to delete from ISR
410:../OSsrc/os_task.c **** return (OS_ERR_TASK_DEL_ISR);
411:../OSsrc/os_task.c **** }
412:../OSsrc/os_task.c **** if (prio == OS_TASK_IDLE_PRIO) { /* Not allowed to delete idle task
413:../OSsrc/os_task.c **** return (OS_ERR_TASK_DEL_IDLE);
414:../OSsrc/os_task.c **** }
415:../OSsrc/os_task.c **** #if OS_ARG_CHK_EN > 0
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -