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

📄 os_task.lst

📁 在C8051F120内移植uCOS-II
💻 LST
📖 第 1 页 / 共 4 页
字号:
 374          *                 replace OSDummy() with a macro that basically executes a NO OP (i.e. OS_NOP()).  The 
 375          *                 NO OP macro would avoid the execution time of the function call and return.
 376          *              3) An ISR cannot delete a task.
 377          *              4) The lock nesting counter is incremented because, for a brief instant, if the current
 378          *                 task is being deleted, the current task would not be able to be rescheduled because it
 379          *                 is removed from the ready list.  Incrementing the nesting counter prevents another task
 380          *                 from being schedule.  This means that the ISR would return to the current task which is
 381          *                 being deleted.  The rest of the deletion would thus be able to be completed.
 382          *********************************************************************************************************
 383          */
 384          /*$PAGE*/
 385          #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               */
C51 COMPILER V8.08   OS_TASK                                                               04/13/2009 13:31:22 PAGE 8   

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

 488          /*$PAGE*/
 489          #if OS_TASK_DEL_EN
              INT8U OSTaskDelReq (INT8U prio)reentrant
              {
                  BOOLEAN  stat;
                  INT8U    err;
                  OS_TCB  *ptcb;
              
              
                  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
 521          /*$PAGE*/
 522          /*
 523          *********************************************************************************************************
 524          *                                        RESUME A SUSPENDED TASK
 525          *
 526          * Description: This function is called to resume a previously suspended task.  This is the only call that
 527          *              will remove an explicit task suspension.
 528          *
 529          * Arguments  : prio     is the priority of the task to resume.
 530          *
 531          * Returns    : OS_NO_ERR                if the requested task is resumed
 532          *              OS_PRIO_INVALID          if the priority you specify is higher that the maximum allowed 
 533          *                                       (i.e. >= OS_LOWEST_PRIO)
 534          *              OS_TASK_RESUME_PRIO      if the task to resume does not exist
 535          *              OS_TASK_NOT_SUSPENDED    if the task to resume has not been suspended
 536          *********************************************************************************************************
 537          */
 538          
 539          #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          */
C51 COMPILER V8.08   OS_TASK                                                               04/13/2009 13:31:22 PAGE 10  

                      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();
                              OSSched();
                          } else {
                              OS_EXIT_CRITICAL();
                          }
                          return (OS_NO_ERR);
                      } else {
                          OS_EXIT_CRITICAL();

⌨️ 快捷键说明

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