⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 os_task.lst

📁 时间触发式单片机最小系统
💻 LST
📖 第 1 页 / 共 4 页
字号:
 368          *              4) The lock nesting counter is incremented because, for a brief instant, if the current
 369          *                 task is being deleted, the current task would not be able to be rescheduled because it
 370          *                 is removed from the ready list.  Incrementing the nesting counter prevents another task
 371          *                 from being schedule.  This means that the ISR would return to the current task which is
 372          *                 being deleted.  The rest of the deletion would thus be able to be completed.
 373          *********************************************************************************************************
 374          */
 375          /*$PAGE*/
 376          #if OS_TASK_DEL_EN
              INT8U OSTaskDel (INT8U prio)reentrant
              {
                  OS_TCB   *ptcb;
                  OS_EVENT *pevent;
              
              
                  if (prio == OS_IDLE_PRIO) {                                 /* Not allowed to delete idle task     */
                      return (OS_TASK_DEL_IDLE);
                  }
                  if (prio >= OS_LOWEST_PRIO && prio != OS_PRIO_SELF) {       /* Task priority valid ?               */
                      return (OS_PRIO_INVALID);
                  }
                  OS_ENTER_CRITICAL();
                  if (OSIntNesting > 0) {                                     /* See if trying to delete from ISR    */
                      OS_EXIT_CRITICAL();
                      return (OS_TASK_DEL_ISR);
                  }
                  if (prio == OS_PRIO_SELF) {                                 /* See if requesting to delete self    */
                      prio = OSTCBCur->OSTCBPrio;                             /* Set priority to delete to current   */
                  }
                  if ((ptcb = OSTCBPrioTbl[prio]) != (OS_TCB *)0) {           /* Task to delete must exist           */
                      if ((OSRdyTbl[ptcb->OSTCBY] &= ~ptcb->OSTCBBitX) == 0) {/* Make task not ready                 */
                          OSRdyGrp &= ~ptcb->OSTCBBitY;
                      }
                      if ((pevent = ptcb->OSTCBEventPtr) != (OS_EVENT *)0) {  /* If task is waiting on event         */
                          if ((pevent->OSEventTbl[ptcb->OSTCBY] &= ~ptcb->OSTCBBitX) == 0) { /* ... remove task from */
                              pevent->OSEventGrp &= ~ptcb->OSTCBBitY;                        /* ... event ctrl block */
                          }
                      }
                      ptcb->OSTCBDly  = 0;                                    /* Prevent OSTimeTick() from updating  */
                      ptcb->OSTCBStat = OS_STAT_RDY;                          /* Prevent task from being resumed     */
                      OSLockNesting++;
                      OS_EXIT_CRITICAL();                                     /* Enabling INT. ignores next instruc. */
                      OSDummy();                                              /* ... Dummy ensures that INTs will be */
                      OS_ENTER_CRITICAL();                                    /* ... disabled HERE!                  */
                      OSLockNesting--;
                      OSTaskDelHook(ptcb);                                    /* Call user defined hook              */
                      OSTaskCtr--;                                            /* One less task being managed         */
                      OSTCBPrioTbl[prio] = (OS_TCB *)0;                       /* Clear old priority entry            */
                      if (ptcb->OSTCBPrev == (OS_TCB *)0) {                   /* Remove from TCB chain               */
                          ptcb->OSTCBNext->OSTCBPrev = (OS_TCB *)0;
                          OSTCBList                  = ptcb->OSTCBNext;
                      } else {
                          ptcb->OSTCBPrev->OSTCBNext = ptcb->OSTCBNext;
                          ptcb->OSTCBNext->OSTCBPrev = ptcb->OSTCBPrev;
                      }
                      ptcb->OSTCBNext = OSTCBFreeList;                        /* Return TCB to free TCB list         */
                      OSTCBFreeList   = ptcb;
                      OS_EXIT_CRITICAL();
C51 COMPILER V7.10   OS_TASK                                                               08/23/2004 01:45:18 PAGE 8   

                      OSSched();                                              /* Find new highest priority task      */
                      return (OS_NO_ERR);
                  } else {
                      OS_EXIT_CRITICAL();
                      return (OS_TASK_DEL_ERR);
                  }
              }
              #endif
 434          /*$PAGE*/
 435          /*
 436          *********************************************************************************************************
 437          *                                    REQUEST THAT A TASK DELETE ITSELF
 438          *
 439          * Description: This function is used to:
 440          *                   a) notify a task to delete itself.
 441          *                   b) to see if a task requested that the current task delete itself.
 442          *              This function is a little tricky to understand.  Basically, you have a task that needs
 443          *              to be deleted however, this task has resources that it has allocated (memory buffers,
 444          *              semaphores, mailboxes, queues etc.).  The task cannot be deleted otherwise these
 445          *              resources would not be freed.  The requesting task calls OSTaskDelReq() to indicate that
 446          *              the task needs to be deleted.  Deleting of the task is however, deferred to the task to
 447          *              be deleted.  For example, suppose that task #10 needs to be deleted.  The requesting task
 448          *              example, task #5, would call OSTaskDelReq(10).  When task #10 gets to execute, it calls
 449          *              this function by specifying OS_PRIO_SELF and monitors the returned value.  If the return
 450          *              value is OS_TASK_DEL_REQ, another task requested a task delete.  Task #10 would look like
 451          *              this:
 452          *
 453          *                   void Task(void *dataptr)
 454          *                   {
 455          *                       .
 456          *                       .
 457          *                       while (1) {
 458          *                           OSTimeDly(1);
 459          *                           if (OSTaskDelReq(OS_PRIO_SELF) == OS_TASK_DEL_REQ) {
 460          *                               Release any owned resources;
 461          *                               De-allocate any dynamic memory;
 462          *                               OSTaskDel(OS_PRIO_SELF);
 463          *                           }
 464          *                       }
 465          *                   }
 466          *
 467          * Arguments  : prio    is the priority of the task to request the delete from
 468          *
 469          * Returns    : OS_NO_ERR          if the task exist and the request has been registered
 470          *              OS_TASK_NOT_EXIST  if the task has been deleted.  This allows the caller to know whether
 471          *                                 the request has been executed.
 472          *              OS_TASK_DEL_IDLE   if you requested to delete uC/OS-II's idle task
 473          *              OS_PRIO_INVALID    if the priority you specify is higher that the maximum allowed 
 474          *                                 (i.e. >= OS_LOWEST_PRIO) or, you have not specified OS_PRIO_SELF.
 475          *              OS_TASK_DEL_REQ    if a task (possibly another task) requested that the running task be 
 476          *                                 deleted.
 477          *********************************************************************************************************
 478          */
 479          /*$PAGE*/
 480          #if OS_TASK_DEL_EN
              INT8U OSTaskDelReq (INT8U prio)reentrant
              {
                  BOOLEAN  stat;
                  INT8U    err;
                  OS_TCB  *ptcb;
              
              
C51 COMPILER V7.10   OS_TASK                                                               08/23/2004 01:45:18 PAGE 9   

                  if (prio == OS_IDLE_PRIO) {                                 /* Not allowed to delete idle task     */
                      return (OS_TASK_DEL_IDLE);
                  }
                  if (prio >= OS_LOWEST_PRIO && prio != OS_PRIO_SELF) {       /* Task priority valid ?               */
                      return (OS_PRIO_INVALID);
                  }
                  if (prio == OS_PRIO_SELF) {                                 /* See if a task is requesting to ...  */
                      OS_ENTER_CRITICAL();                                    /* ... this task to delete itself      */
                      stat = OSTCBCur->OSTCBDelReq;                           /* Return request status to caller     */
                      OS_EXIT_CRITICAL();
                      return (stat);
                  } else {
                      OS_ENTER_CRITICAL();
                      if ((ptcb = OSTCBPrioTbl[prio]) != (OS_TCB *)0) {       /* Task to delete must exist           */
                          ptcb->OSTCBDelReq = OS_TASK_DEL_REQ;                /* Set flag indicating task to be DEL. */
                          err               = OS_NO_ERR;
                      } else {
                          err               = OS_TASK_NOT_EXIST;              /* Task must be deleted                */
                      }
                      OS_EXIT_CRITICAL();
                      return (err);
                  }
              }
              #endif
 512          /*$PAGE*/
 513          /*
 514          *********************************************************************************************************
 515          *                                        RESUME A SUSPENDED TASK
 516          *
 517          * Description: This function is called to resume a previously suspended task.  This is the only call that
 518          *              will remove an explicit task suspension.
 519          *
 520          * Arguments  : prio     is the priority of the task to resume.
 521          *
 522          * Returns    : OS_NO_ERR                if the requested task is resumed
 523          *              OS_PRIO_INVALID          if the priority you specify is higher that the maximum allowed 
 524          *                                       (i.e. >= OS_LOWEST_PRIO)
 525          *              OS_TASK_RESUME_PRIO      if the task to resume does not exist
 526          *              OS_TASK_NOT_SUSPENDED    if the task to resume has not been suspended
 527          *********************************************************************************************************
 528          */
 529          
 530          #if OS_TASK_SUSPEND_EN
              INT8U OSTaskResume (INT8U prio)reentrant
              {
                  OS_TCB   *ptcb;
              
              
                  if (prio >= OS_LOWEST_PRIO) {                               /* Make sure task priority is valid    */
                      return (OS_PRIO_INVALID);
                  }
                  OS_ENTER_CRITICAL();
                  if ((ptcb = OSTCBPrioTbl[prio]) == (OS_TCB *)0) {           /* Task to suspend must exist          */
                      OS_EXIT_CRITICAL();
                      return (OS_TASK_RESUME_PRIO);
                  } else {
                      if (ptcb->OSTCBStat & OS_STAT_SUSPEND) {                           /* Task must be suspended   */
                          if (((ptcb->OSTCBStat &= ~OS_STAT_SUSPEND) == OS_STAT_RDY) &&  /* Remove suspension        */
                               (ptcb->OSTCBDly  == 0)) {                                 /* Must not be delayed      */
                              OSRdyGrp               |= ptcb->OSTCBBitY;                 /* Make task ready to run   */
                              OSRdyTbl[ptcb->OSTCBY] |= ptcb->OSTCBBitX;
                              OS_EXIT_CRITICAL();
C51 COMPILER V7.10   OS_TASK                                                               08/23/2004 01:45:18 PAGE 10  

                              OSSched();
                          } else {
                              OS_EXIT_CRITICAL();
                          }
                          return (OS_NO_ERR);
                      } else {
                          OS_EXIT_CRITICAL();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -