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

📄 os_task.lst

📁 IAR project for MSP430 and uC/OS. All configured to start filling with tasks.
💻 LST
📖 第 1 页 / 共 5 页
字号:
    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)
    487          {
    488          #if OS_CRITICAL_METHOD == 3                      /* Allocate storage for CPU status register           */
    489              OS_CPU_SR  cpu_sr;
    490          #endif
    491              BOOLEAN    stat;
    492              INT8U      err;
    493              OS_TCB    *ptcb;
    494          
    495          
    496          #if OS_ARG_CHK_EN > 0
    497              if (prio == OS_IDLE_PRIO) {                                 /* Not allowed to delete idle task     */
   \   0386  7C900C00          CMP.B   #12,R12 
   \   038A  0320              JNE     (?0151) 
    498                  return (OS_TASK_DEL_IDLE);
   \   038C  7C403D00          MOV.B   #61,R12 
    499              }
   \   0390  3041              RET             
   \   0392            ?0151:
    500              if (prio >= OS_LOWEST_PRIO && prio != OS_PRIO_SELF) {       /* Task priority valid ?               */
   \   0392  7C900C00          CMP.B   #12,R12 
   \   0396  0528              JNC     (?0153) 
   \   0398  7C93              CMP.B   #255,R12        
   \   039A  0324              JEQ     (?0153) 
    501                  return (OS_PRIO_INVALID);
   \   039C  7C402A00          MOV.B   #42,R12 
    502              }
   \   03A0  3041              RET             
   \   03A2            ?0153:
    503          #endif
    504              if (prio == OS_PRIO_SELF) {                                 /* See if a task is requesting to ...  */
   \   03A2  7C93              CMP.B   #255,R12        
   \   03A4  32C2              DINT            
   \   03A6  0620              JNE     (?0157) 
    505                  OS_ENTER_CRITICAL();                                    /* ... this task to delete itself      */
    506                  stat = OSTCBCur->OSTCBDelReq;                           /* Return request status to caller     */
   \   03A8  1D420000          MOV     &OSTCBCur,R13   
   \   03AC  5C4D2200          MOV.B   34(R13),R12     
    507                  OS_EXIT_CRITICAL();
   \   03B0  32D2              EINT            
    508                  return (stat);
    509              }
   \   03B2  3041              RET             
   \   03B4            ?0157:
    510              OS_ENTER_CRITICAL();
    511              ptcb = OSTCBPrioTbl[prio];
   \   03B4  7CF3              AND.B   #-1,R12 
   \   03B6  0C5C              ADD     R12,R12 
   \   03B8  1D4C0000          MOV     OSTCBPrioTbl(R12),R13   
    512              if (ptcb != (OS_TCB *)0) {                                  /* Task to delete must exist           */
   \   03BC  0D93              CMP     #0,R13  
   \   03BE  0524              JEQ     (?0159) 
    513                  ptcb->OSTCBDelReq = OS_TASK_DEL_REQ;                    /* Set flag indicating task to be DEL. */
   \   03C0  FD403E00          MOV.B   #62,34(R13)     
   \   03C4  2200
    514                  err               = OS_NO_ERR;
   \   03C6  4C43              MOV.B   #0,R12  
    515              } else {
   \   03C8  023C              JMP     (?0160) 
   \   03CA            ?0159:
    516                  err               = OS_TASK_NOT_EXIST;                  /* Task must be deleted                */
   \   03CA  7C400B00          MOV.B   #11,R12 
   \   03CE            ?0160:
    517              }
    518              OS_EXIT_CRITICAL();
   \   03CE  32D2              EINT            
    519              return (err);
    520          }
   \   03D0  3041              RET             
   \   03D2            OSTaskResume:
    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)
    542          {
    543          #if OS_CRITICAL_METHOD == 3                      /* Allocate storage for CPU status register           */
    544              OS_CPU_SR  cpu_sr;
    545          #endif
    546              OS_TCB    *ptcb;
    547          
    548          
    549          #if OS_ARG_CHK_EN > 0
    550              if (prio >= OS_LOWEST_PRIO) {                               /* Make sure task priority is valid    */
   \   03D2  7C900C00          CMP.B   #12,R12 
   \   03D6  0328              JNC     (?0163) 
    551                  return (OS_PRIO_INVALID);
   \   03D8  7C402A00          MOV.B   #42,R12 
    552              }
   \   03DC  3041              RET             
   \   03DE            ?0163:
    553          #endif
    554              OS_ENTER_CRITICAL();
   \   03DE  32C2              DINT            
    555              ptcb = OSTCBPrioTbl[prio];
   \   03E0  7CF3              AND.B   #-1,R12 
   \   03E2  0C5C              ADD     R12,R12 
   \   03E4  1D4C0000          MOV     OSTCBPrioTbl(R12),R13   
    556              if (ptcb == (OS_TCB *)0) {                                  /* Task to suspend must exist          */
   \   03E8  0D93              CMP     #0,R13  
   \   03EA  0420              JNE     (?0165) 
    557                  OS_EXIT_CRITICAL();
   \   03EC  32D2              EINT            
    558                  return (OS_TASK_RESUME_PRIO);
   \   03EE  7C406400          MOV.B   #100,R12        
    559              }
   \   03F2  3041              RET             
   \   03F4            ?0165:
    560              if ((ptcb->OSTCBStat & OS_STAT_SUSPEND) != OS_STAT_RDY) {              /* Task must be suspended   */
   \   03F4  FDB21C00          BIT.B   #8,28(R13)      
   \   03F8  1724              JEQ     (?0167) 
    561                  if (((ptcb->OSTCBStat &= ~OS_STAT_SUSPEND) == OS_STAT_RDY) &&      /* Remove suspension        */
    562                       (ptcb->OSTCBDly  == 0)) {                                     /* Must not be delayed      */
   \   03FA  FDC21C00          BIC.B   #8,28(R13)      
   \   03FE  CD931C00          CMP.B   #0,28(R13)      
   \   0402  0F20              JNE     (?0169) 
   \   0404  8D931A00          CMP     #0,26(R13)      
   \   0408  0C20              JNE     (?0169) 
    563                      OSRdyGrp               |= ptcb->OSTCBBitY;                     /* Make task ready to run   */
   \   040A  D2DD2100          BIS.B   33(R13),&OSRdyGrp       
   \   040E  0000
    564                      OSRdyTbl[ptcb->OSTCBY] |= ptcb->OSTCBBitX;
   \   0410  5C4D1F00          MOV.B   31(R13),R12     
   \   0414  DCDD2000          BIS.B   32(R13),OSRdyTbl(R12)   
   \   0418  0000
    565                      OS_EXIT_CRITICAL();
   \   041A  32D2              EINT            
    566                      OS_Sched();
   \   041C  B0120000          CALL    #OS_Sched       
    567                  } else {
   \   0420  013C              JMP     (?0172) 
   \   0422            ?0169:
    568                      OS_EXIT_CRITICAL();
   \   0422  32D2              EINT            
   \   0424            ?0172:
    569                  }
    570                  return (OS_NO_ERR);
   \   0424  4C43              MOV.B   #0,R12  
    571              }
   \   0426  3041              RET             
   \   0428            ?0167:
    572              OS_EXIT_CRITICAL();
   \   0428  32D2              EINT            
    573              return (OS_TASK_NOT_SUSPENDED);
   \   042A  7C406500          MOV.B   #101,R12        
    574          }
   \   042E  3041              RET             
   \   0430            OSTaskStkChk:
    575          #endif
    576          /*$PAGE*/
    577          /*
    578          *********************************************************************************************************
    579          *                                             STACK CHECKING
    580          *
    581          * Description: This function is called to check the amount of free memory left on the specified task's
    582          *              stack.
    583          *
    584          * Arguments  : prio     is the task priority
    585          *
    586          *              pdata    is a pointer to a data structure of type OS_STK_DATA.
    587          *
    588          * Returns    : OS_NO_ERR           upon success
    589          *              OS_PRIO_INVALID     if the priority you specify is higher that the maximum allowed
    590          *                      

⌨️ 快捷键说明

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