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

📄 os_task.lst

📁 keil下单片机C8051F020的源程序
💻 LST
📖 第 1 页 / 共 4 页
字号:
C51 COMPILER V7.50   OS_TASK                                                               12/12/2007 16:55:25 PAGE 4   

 179   1          if (prio > OS_LOWEST_PRIO) {             /* Make sure priority is within allowable range           */
 180   2              return (OS_PRIO_INVALID);
 181   2          }
 182   1          OS_ENTER_CRITICAL();
 183   1          if (OSTCBPrioTbl[prio] == (OS_TCB *)0) { /* Make sure task doesn't already exist at this priority  */
 184   2              OSTCBPrioTbl[prio] = (OS_TCB *)1;    /* Reserve the priority to prevent others from doing ...  */
 185   2                                                   /* ... the same thing until task is created.              */
 186   2              OS_EXIT_CRITICAL();
 187   2              psp = (void *)OSTaskStkInit(task, ppdata, ptos, 0); /* Initialize the task's stack              */
 188   2              err = OSTCBInit(prio, psp, (void *)0, 0, 0, (void *)0, 0);         
 189   2              if (err == OS_NO_ERR) {
 190   3                  OS_ENTER_CRITICAL();
 191   3                  OSTaskCtr++;                                   /* Increment the #tasks counter             */
 192   3                  OSTaskCreateHook(OSTCBPrioTbl[prio]);          /* Call user defined hook                   */
 193   3                  OS_EXIT_CRITICAL();
 194   3                  if (OSRunning) {                 /* Find highest priority task if multitasking has started */
 195   4                      OSSched();
 196   4                  }
 197   3              } else {
 198   3                  OS_ENTER_CRITICAL();
 199   3                  OSTCBPrioTbl[prio] = (OS_TCB *)0;/* Make this priority available to others                 */
 200   3                  OS_EXIT_CRITICAL();
 201   3              }
 202   2              return (err);
 203   2          } else {
 204   2              OS_EXIT_CRITICAL();
 205   2              return (OS_PRIO_EXIST);
 206   2          }
 207   1      }
 208          #endif
 209          /*$PAGE*/
 210          /*
 211          *********************************************************************************************************
 212          *                                     CREATE A TASK (Extended Version)
 213          *
 214          * Description: This function is used to have uC/OS-II manage the execution of a task.  Tasks can either
 215          *              be created prior to the start of multitasking or by a running task.  A task cannot be
 216          *              created by an ISR.  This function is similar to OSTaskCreate() except that it allows
 217          *              additional information about a task to be specified.
 218          *
 219          * Arguments  : task     is a pointer to the task's code
 220          *
 221          *              pdata    is a pointer to an optional data area which can be used to pass parameters to
 222          *                       the task when the task first executes.  Where the task is concerned it thinks
 223          *                       it was invoked and passed the argument 'pdata' as follows:
 224          *
 225          *                           void Task (void *pdata)
 226          *                           {
 227          *                               for (;;) {
 228          *                                   Task code;
 229          *                               }
 230          *                           }
 231          *
 232          *              ptos     is a pointer to the task's top of stack.  If the configuration constant 
 233          *                       OS_STK_GROWTH is set to 1, the stack is assumed to grow downward (i.e. from high
 234          *                       memory to low memory).  'pstk' will thus point to the highest (valid) memory 
 235          *                       location of the stack.  If OS_STK_GROWTH is set to 0, 'pstk' will point to the 
 236          *                       lowest memory location of the stack and the stack will grow with increasing
 237          *                       memory locations.  'pstk' MUST point to a valid 'free' data item.
 238          *
 239          *              prio     is the task's priority.  A unique priority MUST be assigned to each task and the
 240          *                       lower the number, the higher the priority.
C51 COMPILER V7.50   OS_TASK                                                               12/12/2007 16:55:25 PAGE 5   

 241          *
 242          *              id       is the task's ID (0..65535)
 243          *
 244          *              pbos     is a pointer to the task's bottom of stack.  If the configuration constant 
 245          *                       OS_STK_GROWTH is set to 1, the stack is assumed to grow downward (i.e. from high
 246          *                       memory to low memory).  'pbos' will thus point to the LOWEST (valid) memory 
 247          *                       location of the stack.  If OS_STK_GROWTH is set to 0, 'pbos' will point to the 
 248          *                       HIGHEST memory location of the stack and the stack will grow with increasing
 249          *                       memory locations.  'pbos' MUST point to a valid 'free' data item.
 250          *
 251          *              stk_size is the size of the stack in number of elements.  If OS_STK is set to INT8U,
 252          *                       'stk_size' corresponds to the number of bytes available.  If OS_STK is set to
 253          *                       INT16U, 'stk_size' contains the number of 16-bit entries available.  Finally, if
 254          *                       OS_STK is set to INT32U, 'stk_size' contains the number of 32-bit entries
 255          *                       available on the stack.
 256          *
 257          *              pext     is a pointer to a user supplied memory location which is used as a TCB extension.
 258          *                       For example, this user memory can hold the contents of floating-point registers
 259          *                       during a context switch, the time each task takes to execute, the number of times
 260          *                       the task has been switched-in, etc. 
 261          *
 262          *              opt      contains additional information (or options) about the behavior of the task.  The 
 263          *                       LOWER 8-bits are reserved by uC/OS-II while the upper 8 bits can be application 
 264          *                       specific.  See OS_TASK_OPT_??? in uCOS-II.H.
 265          *
 266          * Returns    : OS_NO_ERR        if the function was successful.
 267          *              OS_PRIO_EXIT     if the task priority already exist 
 268          *                               (each task MUST have a unique priority).
 269          *              OS_PRIO_INVALID  if the priority you specify is higher that the maximum allowed 
 270          *                               (i.e. > OS_LOWEST_PRIO)
 271          *********************************************************************************************************
 272          */
 273          /*$PAGE*/
 274          #if   OS_TASK_CREATE_EXT_EN    
              INT8U OSTaskCreateExt (void   (*task)(void *pd), 
                                     void    *ppdata, 
                                     OS_STK  *ptos, 
                                     INT8U    prio,
                                     INT16U   id,
                                     OS_STK  *pbos,
                                     INT32U   stk_size,
                                     void    *pext,
                                     INT16U   opt) reentrant
              {
                  void    *psp;
                  INT8U    err;
                  INT16U   i;
                  OS_STK  *pfill;
              
              
                  if (prio > OS_LOWEST_PRIO) {             /* Make sure priority is within allowable range           */
                      return (OS_PRIO_INVALID);
                  }
                  OS_ENTER_CRITICAL();
                  if (OSTCBPrioTbl[prio] == (OS_TCB *)0) { /* Make sure task doesn't already exist at this priority  */
                      OSTCBPrioTbl[prio] = (OS_TCB *)1;    /* Reserve the priority to prevent others from doing ...  */
                                                           /* ... the same thing until task is created.              */
                      OS_EXIT_CRITICAL();
                      
                      if (opt & OS_TASK_OPT_STK_CHK) {     /* See if stack checking has been enabled                 */
                          if (opt & OS_TASK_OPT_STK_CLR) { /* See if stack needs to be cleared                       */
                              pfill = pbos;                /* Yes, fill the stack with zeros                         */
C51 COMPILER V7.50   OS_TASK                                                               12/12/2007 16:55:25 PAGE 6   

                              for (i = 0; i < stk_size; i++) {
                                  #if OS_STK_GROWTH == 1
                                  *pfill++ = (OS_STK)0;
                                  #else
                                  *pfill-- = (OS_STK)0;
                                  #endif
                              }
                          }
                      }
                      
                      psp = (void *)OSTaskStkInit(task, ppdata, ptos, opt); /* Initialize the task's stack            */
                      err = OSTCBInit(prio, psp, pbos, id, stk_size, pext, opt);         
                      if (err == OS_NO_ERR) {
                          OS_ENTER_CRITICAL();
                          OSTaskCtr++;                                     /* Increment the #tasks counter           */
                          OSTaskCreateHook(OSTCBPrioTbl[prio]);            /* Call user defined hook                 */
                          OS_EXIT_CRITICAL();
                          if (OSRunning) {                 /* Find highest priority task if multitasking has started */
                              OSSched();
                          }
                      } else {
                          OS_ENTER_CRITICAL();
                          OSTCBPrioTbl[prio] = (OS_TCB *)0;/* Make this priority available to others                 */
                          OS_EXIT_CRITICAL();
                      }
                      return (err);
                  } else {
                      OS_EXIT_CRITICAL();
                      return (OS_PRIO_EXIST);
                  }
              }
              #endif
 335          /*$PAGE*/
 336          /*
 337          *********************************************************************************************************
 338          *                                            DELETE A TASK
 339          *
 340          * Description: This function allows you to delete a task.  The calling task can delete itself by 
 341          *              its own priority number.  The deleted task is returned to the dormant state and can be
 342          *              re-activated by creating the deleted task again.
 343          *
 344          * Arguments  : prio    is the priority of the task to delete.  Note that you can explicitely delete
 345          *                      the current task without knowing its priority level by setting 'prio' to
 346          *                      OS_PRIO_SELF.
 347          *
 348          * Returns    : OS_NO_ERR           if the call is successful
 349          *              OS_TASK_DEL_IDLE    if you attempted to delete uC/OS-II's idle task
 350          *              OS_PRIO_INVALID     if the priority you specify is higher that the maximum allowed 
 351          *                                  (i.e. >= OS_LOWEST_PRIO) or, you have not specified OS_PRIO_SELF.
 352          *              OS_TASK_DEL_ERR     if the task you want to delete does not exist
 353          *              OS_TASK_DEL_ISR     if you tried to delete a task from an ISR
 354          *
 355          * Notes      : 1) To reduce interrupt latency, OSTaskDel() 'disables' the task:
 356          *                    a) by making it not ready
 357          *                    b) by removing it from any wait lists
 358          *                    c) by preventing OSTimeTick() from making the task ready to run.
 359          *                 The task can then be 'unlinked' from the miscellaneous structures in uC/OS-II.
 360          *              2) The function OSDummy() is called after OS_EXIT_CRITICAL() because, on most processors, 
 361          *                 the next instruction following the enable interrupt instruction is ignored.  You can 
 362          *                 replace OSDummy() with a macro that basically executes a NO OP (i.e. OS_NOP()).  The 
 363          *                 NO OP macro would avoid the execution time of the function call and return.
 364          *              3) An ISR cannot delete a task.

⌨️ 快捷键说明

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