os_task.lst
来自「atmega单片机用的ucos系统 占用内存适中 是atmega单片机合适的操作」· LST 代码 · 共 1,070 行 · 第 1/5 页
LST
1,070 行
269:OSsrc/os_task.c **** *
270:OSsrc/os_task.c **** * Returns : OS_NO_ERR if the function was successful.
271:OSsrc/os_task.c **** * OS_PRIO_EXIT if the task priority already exist
272:OSsrc/os_task.c **** * (each task MUST have a unique priority).
273:OSsrc/os_task.c **** * OS_PRIO_INVALID if the priority you specify is higher that the maximum allow
274:OSsrc/os_task.c **** * (i.e. > OS_LOWEST_PRIO)
275:OSsrc/os_task.c **** * OS_ERR_TASK_CREATE_ISR if you tried to create a task from an ISR.
276:OSsrc/os_task.c **** ***************************************************************************************************
277:OSsrc/os_task.c **** */
278:OSsrc/os_task.c **** /*$PAGE*/
279:OSsrc/os_task.c **** #if OS_TASK_CREATE_EXT_EN > 0
280:OSsrc/os_task.c **** INT8U OSTaskCreateExt (void (*task)(void *pd),
281:OSsrc/os_task.c **** void *p_arg,
282:OSsrc/os_task.c **** OS_STK *ptos,
283:OSsrc/os_task.c **** INT8U prio,
284:OSsrc/os_task.c **** INT16U id,
285:OSsrc/os_task.c **** OS_STK *pbos,
286:OSsrc/os_task.c **** INT32U stk_size,
287:OSsrc/os_task.c **** void *pext,
288:OSsrc/os_task.c **** INT16U opt)
289:OSsrc/os_task.c **** {
290:OSsrc/os_task.c **** OS_STK *psp;
291:OSsrc/os_task.c **** INT8U err;
292:OSsrc/os_task.c **** #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register
293:OSsrc/os_task.c **** OS_CPU_SR cpu_sr;
294:OSsrc/os_task.c ****
295:OSsrc/os_task.c ****
296:OSsrc/os_task.c ****
297:OSsrc/os_task.c **** cpu_sr = 0; /* Prevent compiler warning
298:OSsrc/os_task.c **** #endif
299:OSsrc/os_task.c **** #if OS_ARG_CHK_EN > 0
300:OSsrc/os_task.c **** if (prio > OS_LOWEST_PRIO) { /* Make sure priority is within allowable range
301:OSsrc/os_task.c **** return (OS_PRIO_INVALID);
302:OSsrc/os_task.c **** }
303:OSsrc/os_task.c **** #endif
304:OSsrc/os_task.c **** OS_ENTER_CRITICAL();
305:OSsrc/os_task.c **** if (OSIntNesting > 0) { /* Make sure we don't create the task from within an I
306:OSsrc/os_task.c **** OS_EXIT_CRITICAL();
307:OSsrc/os_task.c **** return (OS_ERR_TASK_CREATE_ISR);
308:OSsrc/os_task.c **** }
309:OSsrc/os_task.c **** if (OSTCBPrioTbl[prio] == (OS_TCB *)0) { /* Make sure task doesn't already exist at this priori
310:OSsrc/os_task.c **** OSTCBPrioTbl[prio] = (OS_TCB *)1; /* Reserve the priority to prevent others from doing .
311:OSsrc/os_task.c **** /* ... the same thing until task is created.
312:OSsrc/os_task.c **** OS_EXIT_CRITICAL();
313:OSsrc/os_task.c ****
314:OSsrc/os_task.c **** OS_TaskStkClr(pbos, stk_size, opt); /* Clear the task stack (if needed)
315:OSsrc/os_task.c ****
316:OSsrc/os_task.c **** psp = (OS_STK *)OSTaskStkInit(task, p_arg, ptos, opt); /* Initialize the task's stack
317:OSsrc/os_task.c **** err = OS_TCBInit(prio, psp, pbos, id, stk_size, pext, opt);
318:OSsrc/os_task.c **** if (err == OS_NO_ERR) {
319:OSsrc/os_task.c **** if (OSRunning == TRUE) { /* Find HPT if multitasking has star
320:OSsrc/os_task.c **** OS_Sched();
321:OSsrc/os_task.c **** }
322:OSsrc/os_task.c **** } else {
323:OSsrc/os_task.c **** OS_ENTER_CRITICAL();
324:OSsrc/os_task.c **** OSTCBPrioTbl[prio] = (OS_TCB *)0; /* Make this priority avail. to othe
325:OSsrc/os_task.c **** OS_EXIT_CRITICAL();
326:OSsrc/os_task.c **** }
327:OSsrc/os_task.c **** return (err);
328:OSsrc/os_task.c **** }
329:OSsrc/os_task.c **** OS_EXIT_CRITICAL();
330:OSsrc/os_task.c **** return (OS_PRIO_EXIST);
331:OSsrc/os_task.c **** }
332:OSsrc/os_task.c **** #endif
333:OSsrc/os_task.c **** /*$PAGE*/
334:OSsrc/os_task.c **** /*
335:OSsrc/os_task.c **** ***************************************************************************************************
336:OSsrc/os_task.c **** * DELETE A TASK
337:OSsrc/os_task.c **** *
338:OSsrc/os_task.c **** * Description: This function allows you to delete a task. The calling task can delete itself by
339:OSsrc/os_task.c **** * its own priority number. The deleted task is returned to the dormant state and can
340:OSsrc/os_task.c **** * re-activated by creating the deleted task again.
341:OSsrc/os_task.c **** *
342:OSsrc/os_task.c **** * Arguments : prio is the priority of the task to delete. Note that you can explicitely delete
343:OSsrc/os_task.c **** * the current task without knowing its priority level by setting 'prio' to
344:OSsrc/os_task.c **** * OS_PRIO_SELF.
345:OSsrc/os_task.c **** *
346:OSsrc/os_task.c **** * Returns : OS_NO_ERR if the call is successful
347:OSsrc/os_task.c **** * OS_TASK_DEL_IDLE if you attempted to delete uC/OS-II's idle task
348:OSsrc/os_task.c **** * OS_PRIO_INVALID if the priority you specify is higher that the maximum allowed
349:OSsrc/os_task.c **** * (i.e. >= OS_LOWEST_PRIO) or, you have not specified OS_PRIO_SELF
350:OSsrc/os_task.c **** * OS_TASK_DEL_ERR if the task you want to delete does not exist.
351:OSsrc/os_task.c **** * OS_TASK_NOT_EXIST if the task is assigned to a Mutex PIP.
352:OSsrc/os_task.c **** * OS_TASK_DEL_ISR if you tried to delete a task from an ISR
353:OSsrc/os_task.c **** *
354:OSsrc/os_task.c **** * Notes : 1) To reduce interrupt latency, OSTaskDel() 'disables' the task:
355:OSsrc/os_task.c **** * a) by making it not ready
356:OSsrc/os_task.c **** * b) by removing it from any wait lists
357:OSsrc/os_task.c **** * c) by preventing OSTimeTick() from making the task ready to run.
358:OSsrc/os_task.c **** * The task can then be 'unlinked' from the miscellaneous structures in uC/OS-II.
359:OSsrc/os_task.c **** * 2) The function OS_Dummy() is called after OS_EXIT_CRITICAL() because, on most proce
360:OSsrc/os_task.c **** * the next instruction following the enable interrupt instruction is ignored.
361:OSsrc/os_task.c **** * 3) An ISR cannot delete a task.
362:OSsrc/os_task.c **** * 4) The lock nesting counter is incremented because, for a brief instant, if the curr
363:OSsrc/os_task.c **** * task is being deleted, the current task would not be able to be rescheduled becau
364:OSsrc/os_task.c **** * is removed from the ready list. Incrementing the nesting counter prevents anothe
365:OSsrc/os_task.c **** * from being schedule. This means that an ISR would return to the current task whi
366:OSsrc/os_task.c **** * being deleted. The rest of the deletion would thus be able to be completed.
367:OSsrc/os_task.c **** ***************************************************************************************************
368:OSsrc/os_task.c **** */
369:OSsrc/os_task.c **** /*$PAGE*/
370:OSsrc/os_task.c **** #if OS_TASK_DEL_EN > 0
371:OSsrc/os_task.c **** INT8U OSTaskDel (INT8U prio)
372:OSsrc/os_task.c **** {
373:OSsrc/os_task.c **** #if OS_EVENT_EN
374:OSsrc/os_task.c **** OS_EVENT *pevent;
375:OSsrc/os_task.c **** #endif
376:OSsrc/os_task.c **** #if (OS_VERSION >= 251) && (OS_FLAG_EN > 0) && (OS_MAX_FLAGS > 0)
377:OSsrc/os_task.c **** OS_FLAG_NODE *pnode;
378:OSsrc/os_task.c **** #endif
379:OSsrc/os_task.c **** OS_TCB *ptcb;
380:OSsrc/os_task.c **** INT8U y;
381:OSsrc/os_task.c **** #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register
382:OSsrc/os_task.c **** OS_CPU_SR cpu_sr;
383:OSsrc/os_task.c ****
384:OSsrc/os_task.c ****
385:OSsrc/os_task.c ****
386:OSsrc/os_task.c **** cpu_sr = 0; /* Prevent compiler warning
387:OSsrc/os_task.c **** #endif
388:OSsrc/os_task.c **** if (OSIntNesting > 0) { /* See if trying to delete from ISR
389:OSsrc/os_task.c **** return (OS_TASK_DEL_ISR);
390:OSsrc/os_task.c **** }
391:OSsrc/os_task.c **** #if OS_ARG_CHK_EN > 0
392:OSsrc/os_task.c **** if (prio == OS_IDLE_PRIO) { /* Not allowed to delete idle task
393:OSsrc/os_task.c **** return (OS_TASK_DEL_IDLE);
394:OSsrc/os_task.c **** }
395:OSsrc/os_task.c **** if (prio >= OS_LOWEST_PRIO) { /* Task priority valid ?
396:OSsrc/os_task.c **** if (prio != OS_PRIO_SELF) {
397:OSsrc/os_task.c **** return (OS_PRIO_INVALID);
398:OSsrc/os_task.c **** }
399:OSsrc/os_task.c **** }
400:OSsrc/os_task.c **** #endif
401:OSsrc/os_task.c **** OS_ENTER_CRITICAL();
402:OSsrc/os_task.c **** if (prio == OS_PRIO_SELF) { /* See if requesting to delete self
403:OSsrc/os_task.c **** prio = OSTCBCur->OSTCBPrio; /* Set priority to delete to curren
404:OSsrc/os_task.c **** }
405:OSsrc/os_task.c **** ptcb = OSTCBPrioTbl[prio];
406:OSsrc/os_task.c **** if (ptcb == (OS_TCB *)0) { /* Task to delete must exist
407:OSsrc/os_task.c **** OS_EXIT_CRITICAL();
408:OSsrc/os_task.c **** return (OS_TASK_DEL_ERR);
409:OSsrc/os_task.c **** }
410:OSsrc/os_task.c **** if (ptcb == (OS_TCB *)1) { /* Must not be assigned to Mutex
411:OSsrc/os_task.c **** OS_EXIT_CRITICAL();
412:OSsrc/os_task.c **** return (OS_TASK_NOT_EXIST);
413:OSsrc/os_task.c **** }
414:OSsrc/os_task.c **** y = ptcb->OSTCBY;
415:OSsrc/os_task.c **** OSRdyTbl[y] &= ~ptcb->OSTCBBitX;
416:OSsrc/os_task.c **** if (OSRdyTbl[y] == 0x00) { /* Make task not ready
417:OSsrc/os_task.c **** OSRdyGrp &= ~ptcb->OSTCBBitY;
418:OSsrc/os_task.c **** }
419:OSsrc/os_task.c **** #if OS_EVENT_EN
420:OSsrc/os_task.c **** pevent = ptcb->OSTCBEventPtr;
421:OSsrc/os_task.c **** if (pevent != (OS_EVENT *)0) { /* If task is waiting on event
422:OSsrc/os_task.c **** pevent->OSEventTbl[y] &= ~ptcb->OSTCBBitX;
423:OSsrc/os_task.c **** if (pevent->OSEventTbl[y] == 0) { /* ... remove task from ...
424:OSsrc/os_task.c **** pevent->OSEventGrp &= ~ptcb->OSTCBBitY; /* ... event ctrl block
425:OSsrc/os_task.c **** }
426:OSsrc/os_task.c **** }
427:OSsrc/os_task.c **** #endif
428:OSsrc/os_task.c **** #if (OS_VERSION >= 251) && (OS_FLAG_EN > 0) && (OS_MAX_FLAGS > 0)
429:OSsrc/os_task.c **** pnode = ptcb->OSTCBFlagNode;
430:OSsrc/os_task.c **** if (pnode != (OS_FLAG_NODE *)0) { /* If task is waiting on event flag
431:OSsrc/os_task.c **** OS_FlagUnlink(pnode); /* Remove from wait list
432:OSsrc/os_task.c **** }
433:OSsrc/os_task.c **** #endif
434:OSsrc/os_task.c **** ptcb->OSTCBDly = 0; /* Prevent OSTimeTick() from updati
435:OSsrc/os_task.c **** ptcb->OSTCBStat = OS_STAT_RDY; /* Prevent task from being resumed
436:OSsrc/os_task.c **** ptcb->OSTCBPendTO = FALSE;
437:OSsrc/os_task.c **** if (OSLockNesting < 255u) { /* Make sure we don't context switch
438:OSsrc/os_task.c **** OSLockNesting++;
439:OSsrc/os_task.c **** }
440:OSsrc/os_task.c **** OS_EXIT_CRITICAL(); /* Enabling INT. ignores next instr
441:OSsrc/os_task.c **** OS_Dummy(); /* ... Dummy ensures that INTs will
442:OSsrc/os_task.c **** OS_ENTER_CRITICAL(); /* ... disabled HERE!
443:OSsrc/os_task.c **** if (OSLockNesting > 0) { /* Remove context switch lock
444:OSsrc/os_task.c **** OSLockNesting--;
445:OSsrc/os_task.c **** }
446:OSsrc/os_task.c **** OSTaskDelHook(ptcb); /* Call user defined hook
447:OSsrc/os_task.c **** OSTaskCtr--; /* One less task being managed
448:OSsrc/os_task.c **** OSTCBPrioTbl[prio] = (OS_TCB *)0; /* Clear old priority entry
449:OSsrc/os_task.c **** if (ptcb->OSTCBPrev == (OS_TCB *)0) { /* Remove from TCB chain
450:OSsrc/os_task.c **** ptcb->OSTCBNext->OSTCBPrev = (OS_TCB *)0;
451:OSsrc/os_task.c **** OSTCBList = ptcb->OSTCBNext;
452:OSsrc/os_task.c **** } else {
453:OSsrc/os_task.c **** ptcb->OSTCBPrev->OSTCBNext = ptcb->OSTCBNext;
454:OSsrc/os_task.c **** ptcb->OSTCBNext->OSTCBPrev = ptcb->OSTCBPrev;
455:OSsrc/os_task.c **** }
456:OSsrc/os_task.c **** ptcb->OSTCBNext = OSTCBFreeList; /* Return TCB to free TCB list
457:OSsrc/os_task.c **** OSTCBFreeList = ptcb;
458:OSsrc/os_task.c **** #if OS_TASK_NAME_SIZE > 1
459:OSsrc/os_task.c **** ptcb->OSTCBTaskName[0] = '?'; /* Unknown name
460:OSsrc/os_task.c **** ptcb->OSTCBTaskName[1] = OS_ASCII_NUL;
461:OSsrc/os_task.c **** #endif
462:OSsrc/os_task.c **** OS_EXIT_CRITICAL();
463:OSsrc/os_task.c **** OS_Sched(); /* Find new highest priority task
464:OSsrc/os_task.c **** return (OS_NO_ERR);
465:OSsrc/os_task.c **** }
466:OSsrc/os_task.c **** #endif
467:OSsrc/os_task.c **** /*$PAGE*/
468:OSsrc/os_task.c **** /*
469:OSsrc/os_task.c **** ***************************************************************************************************
470:OSsrc/os_task.c **** * REQUEST THAT A TASK DELETE ITSELF
471:OSsrc/os_task.c **** *
472:OSsrc/os_task.c **** * Description: This function is used to:
473:OSsrc/os_task.c **** * a) notify a task to delete itself.
474:OSsrc/os_task.c **** * b) to see if a task requested that the current task delete itself.
475:OSsrc/os_task.c **** * This function is a little tricky to understand. Basically, you have a task that nee
476:OSsrc/os_task.c **** * to be deleted however, this task has resources that it has allocated (memory buffers
477:OSsrc/os_task.c **** * semaphores, mailboxes, queues etc.). The task cannot be deleted otherwise these
478:OSsrc/os_task.c **** * resources would not be freed. The requesting task calls OSTaskDelReq() to indicate
479:OSsrc/os_task.c **** * the task needs to be deleted. Deleting of the task is however, deferred to the task
480:OSsrc/os_task.c **** * be deleted. For example, suppose that task #10 needs to be deleted. The requesting
481:OSsrc/os_task.c **** * example, task #5, would call OSTaskDelReq(10). When task #10 gets to execute, it ca
482:OSsrc/os_task.c **** * this function by specifying OS_PRIO_SELF and monitors the returned value. If the re
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?