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

📄 os_task.lst

📁 ucos v2.62 安装程序 附带已移植到C8051F020的UCOS源码
💻 LST
📖 第 1 页 / 共 5 页
字号:
 383   1          ptcb = OSTCBPrioTbl[prio];
 384   1          if (ptcb != (OS_TCB *)0) {                                  /* Task to delete must exist           */
 385   2                  y            =  ptcb->OSTCBY;
 386   2                      OSRdyTbl[y] &= ~ptcb->OSTCBBitX;
 387   2              if (OSRdyTbl[y] == 0x00) {                              /* Make task not ready                 */
 388   3                  OSRdyGrp &= ~ptcb->OSTCBBitY;
 389   3              }
 390   2      #if OS_EVENT_EN > 0
                      pevent = ptcb->OSTCBEventPtr;
                      if (pevent != (OS_EVENT *)0) {                          /* If task is waiting on event         */
                                  pevent->OSEventTbl[y] &= ~ptcb->OSTCBBitX;
                          if (pevent->OSEventTbl[y] == 0) {                   /* ... remove task from ...            */
                              pevent->OSEventGrp &= ~ptcb->OSTCBBitY;         /* ... event ctrl block                */
                          }
                      }
              #endif
 399   2      #if (OS_VERSION >= 251) && (OS_FLAG_EN > 0) && (OS_MAX_FLAGS > 0)
                      pnode = ptcb->OSTCBFlagNode;
                      if (pnode != (OS_FLAG_NODE *)0) {                       /* If task is waiting on event flag    */
                          OS_FlagUnlink(pnode);                               /* Remove from wait list               */
                      }
              #endif
 405   2              ptcb->OSTCBDly  = 0;                                    /* Prevent OSTimeTick() from updating  */
 406   2              ptcb->OSTCBStat = OS_STAT_RDY;                          /* Prevent task from being resumed     */
 407   2                      if (OSLockNesting < 255u) {
 408   3                  OSLockNesting++;
 409   3                      }
 410   2              OS_EXIT_CRITICAL();                                     /* Enabling INT. ignores next instruc. */
 411   2              OS_Dummy();                                             /* ... Dummy ensures that INTs will be */
 412   2              OS_ENTER_CRITICAL();                                    /* ... disabled HERE!                  */
 413   2                      if (OSLockNesting > 0) {
 414   3                  OSLockNesting--;
 415   3                      }
 416   2              OSTaskDelHook(ptcb);                                    /* Call user defined hook              */
 417   2              OSTaskCtr--;                                            /* One less task being managed         */
 418   2              OSTCBPrioTbl[prio] = (OS_TCB *)0;                       /* Clear old priority entry            */
 419   2              if (ptcb->OSTCBPrev == (OS_TCB *)0) {                   /* Remove from TCB chain               */
 420   3                  ptcb->OSTCBNext->OSTCBPrev = (OS_TCB *)0;
 421   3                  OSTCBList                  = ptcb->OSTCBNext;
 422   3              } else {
 423   3                  ptcb->OSTCBPrev->OSTCBNext = ptcb->OSTCBNext;
 424   3                  ptcb->OSTCBNext->OSTCBPrev = ptcb->OSTCBPrev;
 425   3              }
 426   2              ptcb->OSTCBNext   = OSTCBFreeList;                      /* Return TCB to free TCB list         */
C51 COMPILER V8.05a   OS_TASK                                                              04/11/2007 16:19:49 PAGE 8   

 427   2              OSTCBFreeList     = ptcb;
 428   2              ptcb->OSTCBStkPtr = (OS_STK *)0;                        /* Show that TCB is 'unused'           */
 429   2      #if OS_TASK_NAME_SIZE > 0
                              (void)strcpy(ptcb->OSTCBTaskName, "?");                       /* Unknown name                        */
              #endif
 432   2              OS_EXIT_CRITICAL();
 433   2              OS_Sched();                                             /* Find new highest priority task      */
 434   2              return (OS_NO_ERR);
 435   2          }
 436   1          OS_EXIT_CRITICAL();
 437   1          return (OS_TASK_DEL_ERR);
 438   1      }
 439          #endif
 440          /*$PAGE*/
 441          /*
 442          *********************************************************************************************************
 443          *                                    REQUEST THAT A TASK DELETE ITSELF
 444          *
 445          * Description: This function is used to:
 446          *                   a) notify a task to delete itself.
 447          *                   b) to see if a task requested that the current task delete itself.
 448          *              This function is a little tricky to understand.  Basically, you have a task that needs
 449          *              to be deleted however, this task has resources that it has allocated (memory buffers,
 450          *              semaphores, mailboxes, queues etc.).  The task cannot be deleted otherwise these
 451          *              resources would not be freed.  The requesting task calls OSTaskDelReq() to indicate that
 452          *              the task needs to be deleted.  Deleting of the task is however, deferred to the task to
 453          *              be deleted.  For example, suppose that task #10 needs to be deleted.  The requesting task
 454          *              example, task #5, would call OSTaskDelReq(10).  When task #10 gets to execute, it calls
 455          *              this function by specifying OS_PRIO_SELF and monitors the returned value.  If the return
 456          *              value is OS_TASK_DEL_REQ, another task requested a task delete.  Task #10 would look like
 457          *              this:
 458          *
 459          *                   void Task(void *data)
 460          *                   {
 461          *                       .
 462          *                       .
 463          *                       while (1) {
 464          *                           OSTimeDly(1);
 465          *                           if (OSTaskDelReq(OS_PRIO_SELF) == OS_TASK_DEL_REQ) {
 466          *                               Release any owned resources;
 467          *                               De-allocate any dynamic memory;
 468          *                               OSTaskDel(OS_PRIO_SELF);
 469          *                           }
 470          *                       }
 471          *                   }
 472          *
 473          * Arguments  : prio    is the priority of the task to request the delete from
 474          *
 475          * Returns    : OS_NO_ERR          if the task exist and the request has been registered
 476          *              OS_TASK_NOT_EXIST  if the task has been deleted.  This allows the caller to know whether
 477          *                                 the request has been executed.
 478          *              OS_TASK_DEL_IDLE   if you requested to delete uC/OS-II's idle task
 479          *              OS_PRIO_INVALID    if the priority you specify is higher that the maximum allowed
 480          *                                 (i.e. >= OS_LOWEST_PRIO) or, you have not specified OS_PRIO_SELF.
 481          *              OS_TASK_DEL_REQ    if a task (possibly another task) requested that the running task be
 482          *                                 deleted.
 483          *********************************************************************************************************
 484          */
 485          /*$PAGE*/
 486          #if OS_TASK_DEL_EN > 0
 487          INT8U  OSTaskDelReq (INT8U prio) KCREENTRANT    
 488          {
C51 COMPILER V8.05a   OS_TASK                                                              04/11/2007 16:19:49 PAGE 9   

 489   1      #if OS_CRITICAL_METHOD == 3                      /* Allocate storage for CPU status register           */
                  OS_CPU_SR  cpu_sr;
              #endif
 492   1          BOOLEAN    stat;
 493   1          INT8U      err;
 494   1          OS_TCB    *ptcb;
 495   1      
 496   1      
 497   1      #if OS_ARG_CHK_EN > 0
 498   1          if (prio == OS_IDLE_PRIO) {                                 /* Not allowed to delete idle task     */
 499   2              return (OS_TASK_DEL_IDLE);
 500   2          }
 501   1          if (prio >= OS_LOWEST_PRIO) {                                                       /* Task priority valid ?               */
 502   2              if (prio != OS_PRIO_SELF) {                       
 503   3                  return (OS_PRIO_INVALID);
 504   3                      }
 505   2          }
 506   1      #endif
 507   1          if (prio == OS_PRIO_SELF) {                                 /* See if a task is requesting to ...  */
 508   2              OS_ENTER_CRITICAL();                                    /* ... this task to delete itself      */
 509   2              stat = OSTCBCur->OSTCBDelReq;                           /* Return request status to caller     */
 510   2              OS_EXIT_CRITICAL();
 511   2              return (stat);
 512   2          }
 513   1          OS_ENTER_CRITICAL();
 514   1          ptcb = OSTCBPrioTbl[prio];
 515   1          if (ptcb != (OS_TCB *)0) {                                  /* Task to delete must exist           */
 516   2              ptcb->OSTCBDelReq = OS_TASK_DEL_REQ;                    /* Set flag indicating task to be DEL. */
 517   2              err               = OS_NO_ERR;
 518   2          } else {
 519   2              err               = OS_TASK_NOT_EXIST;                  /* Task must be deleted                */
 520   2          }
 521   1          OS_EXIT_CRITICAL();
 522   1          return (err);
 523   1      }
 524          #endif
 525          /*$PAGE*/
 526          /*
 527          *********************************************************************************************************
 528          *                                        GET THE NAME OF A TASK
 529          *
 530          * Description: This function is called to obtain the name of a task.
 531          *
 532          * Arguments  : prio      is the priority of the task that you want to obtain the name from.
 533          *
 534          *              pname     is a pointer to an ASCII string that will receive the name of the task.  The 
 535          *                        string must be able to hold at least OS_TASK_NAME_SIZE characters.
 536          *
 537          *              err       is a pointer to an error code that can contain one of the following values:
 538          *
 539          *                        OS_NO_ERR                  if the requested task is resumed
 540          *                        OS_TASK_NOT_EXIST          if the task has not been created
 541          *                        OS_PRIO_INVALID            if you specified an invalid priority:
 542          *                                                   A higher value than the idle task or not OS_PRIO_SELF.
 543          *                        OS_ERR_PNAME_NULL          You passed a NULL pointer for 'pname'
 544          *
 545          * Returns    : The length of the string or 0 if the task does not exist.
 546          *********************************************************************************************************
 547          */
 548          
 549          #if OS_TASK_NAME_SIZE > 0
              INT8U  OSTaskNameGet (INT8U prio, char *pname, INT8U *err)      KCREENTRANT     
C51 COMPILER V8.05a   OS_TASK                                                              04/11/2007 16:19:49 PAGE 10  

              {
              #if OS_CRITICAL_METHOD == 3                      /* Allocate storage for CPU status register           */
                  OS_CPU_SR  cpu_sr;
              #endif
                  OS_TCB    *ptcb;
                  INT8U      len;
              
              
                  OS_ENTER_CRITICAL();
              #if OS_ARG_CHK_EN > 0
                  if (prio > OS_LOWEST_PRIO && prio != OS_PRIO_SELF) {        /* Task priority valid ?               */
                      *err = OS_PRIO_INVALID;                                 /* No                                  */
                      return (0);
                  }
                  if (pname == (char *)0) {                    /* Is 'pname' a NULL pointer?                         */
                      OS_EXIT_CRITICAL();                      /* Yes                                                */
                      *err = OS_ERR_PNAME_NULL;
                      return (0);
                  }
              #endif
                  if (prio == OS_PRIO_SELF) {                  /* See if caller desires it's own name                */
                      prio = OSTCBCur->OSTCBPrio;
                  }
                  ptcb = OSTCBPrioTbl[prio];
                  if (ptcb == (OS_TCB *)0) {                   /* Does task exist?                                   */
                      OS_EXIT_CRITICAL();                      /* No                                                 */
                      *err = OS_TASK_NOT_EXIST;
                      return (0);

⌨️ 快捷键说明

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