📄 os_task.lst
字号:
381 1 if (prio >= OS_LOWEST_PRIO && prio != OS_PRIO_SELF) { /* Task priority valid ? */
382 2 return (OS_PRIO_INVALID);
383 2 }
384 1 #endif
385 1 OS_ENTER_CRITICAL();
386 1 if (prio == OS_PRIO_SELF) { /* See if requesting to delete self */
387 2 prio = OSTCBCur->OSTCBPrio; /* Set priority to delete to current */
388 2 }
389 1 ptcb = OSTCBPrioTbl[prio];
390 1 if (ptcb != (OS_TCB *)0) { /* Task to delete must exist */
391 2 if ((OSRdyTbl[ptcb->OSTCBY] &= ~ptcb->OSTCBBitX) == 0x00) { /* Make task not ready */
392 3 OSRdyGrp &= ~ptcb->OSTCBBitY;
393 3 }
394 2 #if OS_EVENT_EN > 0
395 2 pevent = ptcb->OSTCBEventPtr;
396 2 if (pevent != (OS_EVENT *)0) { /* If task is waiting on event */
397 3 if ((pevent->OSEventTbl[ptcb->OSTCBY] &= ~ptcb->OSTCBBitX) == 0) { /* ... remove task from */
398 4 pevent->OSEventGrp &= ~ptcb->OSTCBBitY; /* ... event ctrl block */
399 4 }
400 3 }
401 2 #endif
402 2 #if (OS_VERSION >= 251) && (OS_FLAG_EN > 0) && (OS_MAX_FLAGS > 0)
403 2 pnode = ptcb->OSTCBFlagNode;
404 2 if (pnode != (OS_FLAG_NODE *)0) { /* If task is waiting on event flag */
405 3 OS_FlagUnlink(pnode); /* Remove from wait list */
406 3 }
407 2 #endif
408 2 ptcb->OSTCBDly = 0; /* Prevent OSTimeTick() from updating */
409 2 ptcb->OSTCBStat = OS_STAT_RDY; /* Prevent task from being resumed */
410 2 if (OSLockNesting < 255) {
411 3 OSLockNesting++;
412 3 }
413 2 OS_EXIT_CRITICAL(); /* Enabling INT. ignores next instruc. */
414 2 OS_Dummy(); /* ... Dummy ensures that INTs will be */
415 2 OS_ENTER_CRITICAL(); /* ... disabled HERE! */
416 2 if (OSLockNesting > 0) {
417 3 OSLockNesting--;
418 3 }
419 2 OSTaskDelHook(ptcb); /* Call user defined hook */
420 2 OSTaskCtr--; /* One less task being managed */
421 2 OSTCBPrioTbl[prio] = (OS_TCB *)0; /* Clear old priority entry */
422 2 if (ptcb->OSTCBPrev == (OS_TCB *)0) { /* Remove from TCB chain */
423 3 ptcb->OSTCBNext->OSTCBPrev = (OS_TCB *)0;
424 3 OSTCBList = ptcb->OSTCBNext;
425 3 } else {
426 3 ptcb->OSTCBPrev->OSTCBNext = ptcb->OSTCBNext;
C51 COMPILER V6.23a OS_TASK 12/09/2004 16:50:26 PAGE 8
427 3 ptcb->OSTCBNext->OSTCBPrev = ptcb->OSTCBPrev;
428 3 }
429 2 ptcb->OSTCBNext = OSTCBFreeList; /* Return TCB to free TCB list */
430 2 OSTCBFreeList = ptcb;
431 2 OS_EXIT_CRITICAL();
432 2 OS_Sched(); /* Find new highest priority task */
433 2 return (OS_NO_ERR);
434 2 }
435 1 OS_EXIT_CRITICAL();
436 1 return (OS_TASK_DEL_ERR);
437 1 }
*** WARNING C280 IN LINE 370 OF OS_TASK.C: 'self': unreferenced local variable
438 #endif
439 /*$PAGE*/
440 /*
441 *********************************************************************************************************
442 * REQUEST THAT A TASK DELETE ITSELF
443 *
444 * Description: This function is used to:
445 * a) notify a task to delete itself.
446 * b) to see if a task requested that the current task delete itself.
447 * This function is a little tricky to understand. Basically, you have a task that needs
448 * to be deleted however, this task has resources that it has allocated (memory buffers,
449 * semaphores, mailboxes, queues etc.). The task cannot be deleted otherwise these
450 * resources would not be freed. The requesting task calls OSTaskDelReq() to indicate that
451 * the task needs to be deleted. Deleting of the task is however, deferred to the task to
452 * be deleted. For example, suppose that task #10 needs to be deleted. The requesting task
453 * example, task #5, would call OSTaskDelReq(10). When task #10 gets to execute, it calls
454 * this function by specifying OS_PRIO_SELF and monitors the returned value. If the return
455 * value is OS_TASK_DEL_REQ, another task requested a task delete. Task #10 would look like
456 * this:
457 *
458 * void Task(void *data)
459 * {
460 * .
461 * .
462 * while (1) {
463 * OSTimeDly(1);
464 * if (OSTaskDelReq(OS_PRIO_SELF) == OS_TASK_DEL_REQ) {
465 * Release any owned resources;
466 * De-allocate any dynamic memory;
467 * OSTaskDel(OS_PRIO_SELF);
468 * }
469 * }
470 * }
471 *
472 * Arguments : prio is the priority of the task to request the delete from
473 *
474 * Returns : OS_NO_ERR if the task exist and the request has been registered
475 * OS_TASK_NOT_EXIST if the task has been deleted. This allows the caller to know whether
476 * the request has been executed.
477 * OS_TASK_DEL_IDLE if you requested to delete uC/OS-II's idle task
478 * OS_PRIO_INVALID if the priority you specify is higher that the maximum allowed
479 * (i.e. >= OS_LOWEST_PRIO) or, you have not specified OS_PRIO_SELF.
480 * OS_TASK_DEL_REQ if a task (possibly another task) requested that the running task be
481 * deleted.
482 *********************************************************************************************************
483 */
484 /*$PAGE*/
485 #if OS_TASK_DEL_EN > 0
486 INT8U OSTaskDelReq (INT8U prio) KCREENTRANT
487 {
C51 COMPILER V6.23a OS_TASK 12/09/2004 16:50:26 PAGE 9
488 1 #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
OS_CPU_SR cpu_sr;
#endif
491 1 BOOLEAN stat;
492 1 INT8U err;
493 1 OS_TCB *ptcb;
494 1
495 1
496 1 #if OS_ARG_CHK_EN > 0
497 1 if (prio == OS_IDLE_PRIO) { /* Not allowed to delete idle task */
498 2 return (OS_TASK_DEL_IDLE);
499 2 }
500 1 if (prio >= OS_LOWEST_PRIO && prio != OS_PRIO_SELF) { /* Task priority valid ? */
501 2 return (OS_PRIO_INVALID);
502 2 }
503 1 #endif
504 1 if (prio == OS_PRIO_SELF) { /* See if a task is requesting to ... */
505 2 OS_ENTER_CRITICAL(); /* ... this task to delete itself */
506 2 stat = OSTCBCur->OSTCBDelReq; /* Return request status to caller */
507 2 OS_EXIT_CRITICAL();
508 2 return (stat);
509 2 }
510 1 OS_ENTER_CRITICAL();
511 1 ptcb = OSTCBPrioTbl[prio];
512 1 if (ptcb != (OS_TCB *)0) { /* Task to delete must exist */
513 2 ptcb->OSTCBDelReq = OS_TASK_DEL_REQ; /* Set flag indicating task to be DEL. */
514 2 err = OS_NO_ERR;
515 2 } else {
516 2 err = OS_TASK_NOT_EXIST; /* Task must be deleted */
517 2 }
518 1 OS_EXIT_CRITICAL();
519 1 return (err);
520 1 }
521 #endif
522 /*$PAGE*/
523 /*
524 *********************************************************************************************************
525 * RESUME A SUSPENDED TASK
526 *
527 * Description: This function is called to resume a previously suspended task. This is the only call that
528 * will remove an explicit task suspension.
529 *
530 * Arguments : prio is the priority of the task to resume.
531 *
532 * Returns : OS_NO_ERR if the requested task is resumed
533 * OS_PRIO_INVALID if the priority you specify is higher that the maximum allowed
534 * (i.e. >= OS_LOWEST_PRIO)
535 * OS_TASK_RESUME_PRIO if the task to resume does not exist
536 * OS_TASK_NOT_SUSPENDED if the task to resume has not been suspended
537 *********************************************************************************************************
538 */
539
540 #if OS_TASK_SUSPEND_EN > 0
541 INT8U OSTaskResume (INT8U prio) KCREENTRANT
542 {
543 1 #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
OS_CPU_SR cpu_sr;
#endif
546 1 OS_TCB *ptcb;
547 1
548 1
549 1 #if OS_ARG_CHK_EN > 0
C51 COMPILER V6.23a OS_TASK 12/09/2004 16:50:26 PAGE 10
550 1 if (prio >= OS_LOWEST_PRIO) { /* Make sure task priority is valid */
551 2 return (OS_PRIO_INVALID);
552 2 }
553 1 #endif
554 1 OS_ENTER_CRITICAL();
555 1 ptcb = OSTCBPrioTbl[prio];
556 1 if (ptcb == (OS_TCB *)0) { /* Task to suspend must exist */
557 2 OS_EXIT_CRITICAL();
558 2 return (OS_TASK_RESUME_PRIO);
559 2 }
560 1 if ((ptcb->OSTCBStat & OS_STAT_SUSPEND) != OS_STAT_RDY) { /* Task must be suspended */
561 2 if (((ptcb->OSTCBStat &= ~OS_STAT_SUSPEND) == OS_STAT_RDY) && /* Remove suspension */
562 2 (ptcb->OSTCBDly == 0)) { /* Must not be delayed */
563 3 OSRdyGrp |= ptcb->OSTCBBitY; /* Make task ready to run */
564 3 OSRdyTbl[ptcb->OSTCBY] |= ptcb->OSTCBBitX;
565 3 OS_EXIT_CRITICAL();
566 3 OS_Sched();
567 3 } else {
568 3 OS_EXIT_CRITICAL();
569 3 }
570 2 return (OS_NO_ERR);
571 2 }
572 1 OS_EXIT_CRITICAL();
573 1 return (OS_TASK_NOT_SUSPENDED);
574 1 }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -