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

📄 os_task.lst

📁 ucos2 程序代码!!!!!可用与51单片机
💻 LST
📖 第 1 页 / 共 4 页
字号:
 362          *                 NO OP macro would avoid the execution time of the function call and return.
 363          *              3) An ISR cannot delete a task.
 364          *              4) The lock nesting counter is incremented because, for a brief instant, if the current
 365          *                 task is being deleted, the current task would not be able to be rescheduled because it
 366          *                 is removed from the ready list.  Incrementing the nesting counter prevents another task
 367          *                 from being schedule.  This means that the ISR would return to the current task which is
 368          *                 being deleted.  The rest of the deletion would thus be able to be completed.
 369          *********************************************************************************************************
 370          */
 371          /*$PAGE*/
 372          #if OS_TASK_DEL_EN
 373          INT8U OSTaskDel (INT8U prio) REENTRANT
 374          {
 375   1          OS_TCB   DT_XDATA *ptcb;
 376   1          OS_EVENT DT_XDATA *pevent;
 377   1      
 378   1      
 379   1          if (prio == OS_IDLE_PRIO) {                                 /* Not allowed to delete idle task     */
 380   2              return (OS_TASK_DEL_IDLE);
 381   2          }
 382   1          if (prio >= OS_LOWEST_PRIO && prio != OS_PRIO_SELF) {       /* Task priority valid ?               */
 383   2              return (OS_PRIO_INVALID);
 384   2          }
 385   1          OS_ENTER_CRITICAL();
 386   1          if (OSIntNesting > 0) {                                     /* See if trying to delete from ISR    */
 387   2              OS_EXIT_CRITICAL();
 388   2              return (OS_TASK_DEL_ISR);
 389   2          }
 390   1          if (prio == OS_PRIO_SELF) {                                 /* See if requesting to delete self    */
 391   2              prio = OSTCBCur->OSTCBPrio;                             /* Set priority to delete to current   */
 392   2          }
 393   1          if ((ptcb = OSTCBPrioTbl[prio]) != (OS_TCB DT_XDATA *)0) {           /* Task to delete must exist     
             -      */
 394   2              if ((OSRdyTbl[ptcb->OSTCBY] &= ~ptcb->OSTCBBitX) == 0) {/* Make task not ready                 */
 395   3                  OSRdyGrp &= ~ptcb->OSTCBBitY;
 396   3              }
 397   2       //       if ((pevent = ptcb->OSTCBEventPtr) != (OS_EVENT DT_XDATA *)0) {  /* If task is waiting on event 
             -        */
 398   2       //           if ((pevent->OSEventTbl[ptcb->OSTCBY] &= ~ptcb->OSTCBBitX) == 0) { /* ... remove task from *
             -/
 399   2       //               pevent->OSEventGrp &= ~ptcb->OSTCBBitY;                        /* ... event ctrl block *
             -/
 400   2       //           }
 401   2       //       }
 402   2              ptcb->OSTCBDly  = 0;                                    /* Prevent OSTimeTick() from updating  */
 403   2              ptcb->OSTCBStat = OS_STAT_RDY;                          /* Prevent task from being resumed     */
 404   2              OSLockNesting++;
 405   2              OS_EXIT_CRITICAL();                                     /* Enabling INT. ignores next instruc. */
 406   2              OSDummy();                                              /* ... Dummy ensures that INTs will be */
 407   2              OS_ENTER_CRITICAL();                                    /* ... disabled HERE!                  */
C51 COMPILER V7.06   OS_TASK                                                               03/22/2009 21:31:01 PAGE 8   

 408   2              OSLockNesting--;
 409   2              OSTaskDelHook(ptcb);                                    /* Call user defined hook              */
 410   2              OSTaskCtr--;                                            /* One less task being managed         */
 411   2              OSTCBPrioTbl[prio] = (OS_TCB DT_XDATA *)0;                       /* Clear old priority entry      
             -      */
 412   2              if (ptcb->OSTCBPrev == (OS_TCB DT_XDATA *)0) {                   /* Remove from TCB chain         
             -      */
 413   3                  ptcb->OSTCBNext->OSTCBPrev = (OS_TCB DT_XDATA *)0;
 414   3                  OSTCBList                  = ptcb->OSTCBNext;
 415   3              } else {
 416   3                  ptcb->OSTCBPrev->OSTCBNext = ptcb->OSTCBNext;
 417   3                  ptcb->OSTCBNext->OSTCBPrev = ptcb->OSTCBPrev;
 418   3              }
 419   2              ptcb->OSTCBNext = OSTCBFreeList;                        /* Return TCB to free TCB list         */
 420   2              OSTCBFreeList   = ptcb;
 421   2              OS_EXIT_CRITICAL();
 422   2              OSSched();                                              /* Find new highest priority task      */
 423   2              return (OS_NO_ERR);
 424   2          } else {
 425   2              OS_EXIT_CRITICAL();
 426   2              return (OS_TASK_DEL_ERR);
 427   2          }
 428   1      }
*** WARNING C280 IN LINE 376 OF UC_OS_II\OS_TASK.C: 'pevent': unreferenced local variable
 429          #endif
 430          /*$PAGE*/
 431          /*
 432          *********************************************************************************************************
 433          *                                    REQUEST THAT A TASK DELETE ITSELF
 434          *
 435          * Description: This function is used to:
 436          *                   a) notify a task to delete itself.
 437          *                   b) to see if a task requested that the current task delete itself.
 438          *              This function is a little tricky to understand.  Basically, you have a task that needs
 439          *              to be deleted however, this task has resources that it has allocated (memory buffers,
 440          *              semaphores, mailboxes, queues etc.).  The task cannot be deleted otherwise these
 441          *              resources would not be freed.  The requesting task calls OSTaskDelReq() to indicate that
 442          *              the task needs to be deleted.  Deleting of the task is however, deferred to the task to
 443          *              be deleted.  For example, suppose that task #10 needs to be deleted.  The requesting task
 444          *              example, task #5, would call OSTaskDelReq(10).  When task #10 gets to execute, it calls
 445          *              this function by specifying OS_PRIO_SELF and monitors the returned value.  If the return
 446          *              value is OS_TASK_DEL_REQ, another task requested a task delete.  Task #10 would look like
 447          *              this:
 448          *
 449          *                   void Task(void *data)
 450          *                   {
 451          *                       .
 452          *                       .
 453          *                       while (1) {
 454          *                           OSTimeDly(1);
 455          *                           if (OSTaskDelReq(OS_PRIO_SELF) == OS_TASK_DEL_REQ) {
 456          *                               Release any owned resources;
 457          *                               De-allocate any dynamic memory;
 458          *                               OSTaskDel(OS_PRIO_SELF);
 459          *                           }
 460          *                       }
 461          *                   }
 462          *
 463          * Arguments  : prio    is the priority of the task to request the delete from
 464          *
 465          * Returns    : OS_NO_ERR          if the task exist and the request has been registered
 466          *              OS_TASK_NOT_EXIST  if the task has been deleted.  This allows the caller to know whether
C51 COMPILER V7.06   OS_TASK                                                               03/22/2009 21:31:01 PAGE 9   

 467          *                                 the request has been executed.
 468          *              OS_TASK_DEL_IDLE   if you requested to delete uC/OS-II's idle task
 469          *              OS_PRIO_INVALID    if the priority you specify is higher that the maximum allowed 
 470          *                                 (i.e. >= OS_LOWEST_PRIO) or, you have not specified OS_PRIO_SELF.
 471          *              OS_TASK_DEL_REQ    if a task (possibly another task) requested that the running task be 
 472          *                                 deleted.
 473          *********************************************************************************************************
 474          */
 475          /*$PAGE*/
 476          #if OS_TASK_DEL_EN
 477          INT8U OSTaskDelReq (INT8U prio) REENTRANT
 478          {
 479   1          BOOLEAN  stat;
 480   1          INT8U    err;
 481   1          OS_TCB  DT_XDATA *ptcb;
 482   1      
 483   1      
 484   1          if (prio == OS_IDLE_PRIO) {                                 /* Not allowed to delete idle task     */
 485   2              return (OS_TASK_DEL_IDLE);
 486   2          }
 487   1          if (prio >= OS_LOWEST_PRIO && prio != OS_PRIO_SELF) {       /* Task priority valid ?               */
 488   2              return (OS_PRIO_INVALID);
 489   2          }
 490   1          if (prio == OS_PRIO_SELF) {                                 /* See if a task is requesting to ...  */
 491   2              OS_ENTER_CRITICAL();                                    /* ... this task to delete itself      */
 492   2              stat = OSTCBCur->OSTCBDelReq;                           /* Return request status to caller     */
 493   2              OS_EXIT_CRITICAL();
 494   2              return (stat);
 495   2          } else {
 496   2              OS_ENTER_CRITICAL();
 497   2              if ((ptcb = OSTCBPrioTbl[prio]) != (OS_TCB DT_XDATA *)0) {       /* Task to delete must exist     
             -      */
 498   3                  ptcb->OSTCBDelReq = OS_TASK_DEL_REQ;                /* Set flag indicating task to be DEL. */
 499   3                  err               = OS_NO_ERR;
 500   3              } else {
 501   3                  err               = OS_TASK_NOT_EXIST;              /* Task must be deleted                */
 502   3              }
 503   2              OS_EXIT_CRITICAL();
 504   2              return (err);
 505   2          }
 506   1      }
 507          #endif
 508          /*$PAGE*/
 509          /*
 510          *********************************************************************************************************
 511          *                                        RESUME A SUSPENDED TASK
 512          *
 513          * Description: This function is called to resume a previously suspended task.  This is the only call that
 514          *              will remove an explicit task suspension.
 515          *
 516          * Arguments  : prio     is the priority of the task to resume.
 517          *
 518          * Returns    : OS_NO_ERR                if the requested task is resumed
 519          *              OS_PRIO_INVALID          if the priority you specify is higher that the maximum allowed 
 520          *                                       (i.e. >= OS_LOWEST_PRIO)
 521          *              OS_TASK_RESUME_PRIO      if the task to resume does not exist
 522          *              OS_TASK_NOT_SUSPENDED    if the task to resume has not been suspended
 523          *********************************************************************************************************
 524          */
 525          
 526          #if OS_TASK_SUSPEND_EN
              INT8U OSTaskResume (INT8U prio) REENTRANT
C51 COMPILER V7.06   OS_TASK                                                               03/22/2009 21:31:01 PAGE 10  

              {
                  OS_TCB   DT_XDATA *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 DT_XDATA *)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();

⌨️ 快捷键说明

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