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

📄 os_task.lst

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

 241          *
 242          *              prio     is the task's priority.  A unique priority MUST be assigned to each task and the
 243          *                       lower the number, the higher the priority.
 244          *
 245          *              id       is the task's ID (0..65535)
 246          *
 247          *              pbos     is a pointer to the task's bottom of stack.  If the configuration constant 
 248          *                       OS_STK_GROWTH is set to 1, the stack is assumed to grow downward (i.e. from high
 249          *                       memory to low memory).  'pbos' will thus point to the LOWEST (valid) memory 
 250          *                       location of the stack.  If OS_STK_GROWTH is set to 0, 'pbos' will point to the 
 251          *                       HIGHEST memory location of the stack and the stack will grow with increasing
 252          *                       memory locations.  'pbos' MUST point to a valid 'free' data item.
 253          *
 254          *              stk_size is the size of the stack in number of elements.  If OS_STK is set to INT8U,
 255          *                       'stk_size' corresponds to the number of bytes available.  If OS_STK is set to
 256          *                       INT16U, 'stk_size' contains the number of 16-bit entries available.  Finally, if
 257          *                       OS_STK is set to INT32U, 'stk_size' contains the number of 32-bit entries
 258          *                       available on the stack.
 259          *
 260          *              pext     is a pointer to a user supplied memory location which is used as a TCB extension.
 261          *                       For example, this user memory can hold the contents of floating-point registers
 262          *                       during a context switch, the time each task takes to execute, the number of times
 263          *                       the task has been switched-in, etc. 
 264          *
 265          *              opt      contains additional information (or options) about the behavior of the task.  The 
 266          *                       LOWER 8-bits are reserved by uC/OS-II while the upper 8 bits can be application 
 267          *                       specific.  See OS_TASK_OPT_??? in uCOS-II.H.
 268          *
 269          * Returns    : OS_NO_ERR        if the function was successful.
 270          *              OS_PRIO_EXIT     if the task priority already exist 
 271          *                               (each task MUST have a unique priority).
 272          *              OS_PRIO_INVALID  if the priority you specify is higher that the maximum allowed 
 273          *                               (i.e. > OS_LOWEST_PRIO)
 274          *********************************************************************************************************
 275          */
 276          /*$PAGE*/
 277          #if   OS_TASK_CREATE_EXT_EN    
              INT8U OSTaskCreateExt (void   (*task)(void *pd), 
                                     void    *dataptr, 
                                     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();
                      
C51 COMPILER V7.10   OS_TASK                                                               08/23/2004 01:45:18 PAGE 6   

                      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                         */
                              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, dataptr, 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
 338          /*$PAGE*/
 339          /*
 340          *********************************************************************************************************
 341          *                                            DELETE A TASK
 342          *
 343          * Description: This function allows you to delete a task.  The calling task can delete itself by 
 344          *              its own priority number.  The deleted task is returned to the dormant state and can be
 345          *              re-activated by creating the deleted task again.
 346          *
 347          * Arguments  : prio    is the priority of the task to delete.  Note that you can explicitely delete
 348          *                      the current task without knowing its priority level by setting 'prio' to
 349          *                      OS_PRIO_SELF.
 350          *
 351          * Returns    : OS_NO_ERR           if the call is successful
 352          *              OS_TASK_DEL_IDLE    if you attempted to delete uC/OS-II's idle task
 353          *              OS_PRIO_INVALID     if the priority you specify is higher that the maximum allowed 
 354          *                                  (i.e. >= OS_LOWEST_PRIO) or, you have not specified OS_PRIO_SELF.
 355          *              OS_TASK_DEL_ERR     if the task you want to delete does not exist
 356          *              OS_TASK_DEL_ISR     if you tried to delete a task from an ISR
 357          *
 358          * Notes      : 1) To reduce interrupt latency, OSTaskDel() 'disables' the task:
 359          *                    a) by making it not ready
 360          *                    b) by removing it from any wait lists
 361          *                    c) by preventing OSTimeTick() from making the task ready to run.
 362          *                 The task can then be 'unlinked' from the miscellaneous structures in uC/OS-II.
 363          *              2) The function OSDummy() is called after OS_EXIT_CRITICAL() because, on most processors, 
C51 COMPILER V7.10   OS_TASK                                                               08/23/2004 01:45:18 PAGE 7   

 364          *                 the next instruction following the enable interrupt instruction is ignored.  You can 
 365          *                 replace OSDummy() with a macro that basically executes a NO OP (i.e. OS_NOP()).  The 
 366          *                 NO OP macro would avoid the execution time of the function call and return.
 367          *              3) An ISR cannot delete a task.

⌨️ 快捷键说明

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