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

📄 os_task.lst

📁 在51上运行的小的OS系统
💻 LST
📖 第 1 页 / 共 5 页
字号:
 137          *                                            CREATE A TASK
 138          *
 139          * Description: This function is used to have uC/OS-II manage the execution of a task.  Tasks can either
 140          *              be created prior to the start of multitasking or by a running task.  A task cannot be
 141          *              created by an ISR.
 142          *
 143          * Arguments  : task     is a pointer to the task's code
 144          *
 145          *              p_arg    is a pointer to an optional data area which can be used to pass parameters to
 146          *                       the task when the task first executes.  Where the task is concerned it thinks
 147          *                       it was invoked and passed the argument 'p_arg' as follows:
 148          *
 149          *                           void Task (void *p_arg)
 150          *                           {
 151          *                               for (;;) {
 152          *                                   Task code;
 153          *                               }
 154          *                           }
 155          *
 156          *              ptos     is a pointer to the task's top of stack.  If the configuration constant
 157          *                       OS_STK_GROWTH is set to 1, the stack is assumed to grow downward (i.e. from high
 158          *                       memory to low memory).  'pstk' will thus point to the highest (valid) memory
 159          *                       location of the stack.  If OS_STK_GROWTH is set to 0, 'pstk' will point to the
 160          *                       lowest memory location of the stack and the stack will grow with increasing
 161          *                       memory locations.
 162          *
 163          *              prio     is the task's priority.  A unique priority MUST be assigned to each task and the
 164          *                       lower the number, the higher the priority.
 165          *
 166          * Returns    : OS_NO_ERR               if the function was successful.
 167          *              OS_PRIO_EXIT            if the task priority already exist
 168          *                                      (each task MUST have a unique priority).
 169          *              OS_PRIO_INVALID         if the priority you specify is higher that the maximum allowed
 170          *                                      (i.e. >= OS_LOWEST_PRIO)
 171          *              OS_ERR_TASK_CREATE_ISR  if you tried to create a task from an ISR.
 172          *********************************************************************************************************
 173          */
 174          
 175          #if OS_TASK_CREATE_EN > 0
 176          INT8U  OSTaskCreate (void (*task)(void *p_arg), void *p_arg, OS_STK *ptos, INT8U prio)
 177          {
 178              OS_STK    *psp;
 179              INT8U      err;
 180          #if OS_CRITICAL_METHOD == 3                  /* Allocate storage for CPU status register               */
                  OS_CPU_SR  cpu_sr = 0;
              #endif
 183          
C51 COMPILER V8.08   OS_TASK                                                               08/04/2008 21:49:52 PAGE 5   

 184          
 185          
 186          #if OS_ARG_CHK_EN > 0
 187              if (prio > OS_LOWEST_PRIO) {             /* Make sure priority is within allowable range           */
 188                  return (OS_PRIO_INVALID);
 189              }
 190          #endif
 191              OS_ENTER_CRITICAL();
 192              if (OSIntNesting > 0) {                  /* Make sure we don't create the task from within an ISR  */
 193                  OS_EXIT_CRITICAL();
 194                  return (OS_ERR_TASK_CREATE_ISR);
 195              }
 196              if (OSTCBPrioTbl[prio] == (OS_TCB *)0) { /* Make sure task doesn't already exist at this priority  */
 197                  OSTCBPrioTbl[prio] = (OS_TCB *)1;    /* Reserve the priority to prevent others from doing ...  */
 198                                                       /* ... the same thing until task is created.              */
 199                  OS_EXIT_CRITICAL();
 200                  psp = OSTaskStkInit(task, p_arg, ptos, 0);              /* Initialize the task's stack         */
 201                  err = OS_TCBInit(prio, psp, (OS_STK *)0, 0, 0, (void *)0, 0);
 202                  if (err == OS_NO_ERR) {
 203                      if (OSRunning == TRUE) {         /* Find highest priority task if multitasking has started */
 204                          OS_Sched();
 205                      }
 206                  } else {
 207                      OS_ENTER_CRITICAL();
 208                      OSTCBPrioTbl[prio] = (OS_TCB *)0;/* Make this priority available to others                 */
 209                      OS_EXIT_CRITICAL();
 210                  }
 211                  return (err);
 212              }
 213              OS_EXIT_CRITICAL();
 214              return (OS_PRIO_EXIST);
 215          }
 216          #endif
 217          /*$PAGE*/
 218          /*
 219          *********************************************************************************************************
 220          *                                     CREATE A TASK (Extended Version)
 221          *
 222          * Description: This function is used to have uC/OS-II manage the execution of a task.  Tasks can either
 223          *              be created prior to the start of multitasking or by a running task.  A task cannot be
 224          *              created by an ISR.  This function is similar to OSTaskCreate() except that it allows
 225          *              additional information about a task to be specified.
 226          *
 227          * Arguments  : task      is a pointer to the task's code
 228          *
 229          *              p_arg     is a pointer to an optional data area which can be used to pass parameters to
 230          *                        the task when the task first executes.  Where the task is concerned it thinks
 231          *                        it was invoked and passed the argument 'p_arg' as follows:
 232          *
 233          *                            void Task (void *p_arg)
 234          *                            {
 235          *                                for (;;) {
 236          *                                    Task code;
 237          *                                }
 238          *                            }
 239          *
 240          *              ptos      is a pointer to the task's top of stack.  If the configuration constant
 241          *                        OS_STK_GROWTH is set to 1, the stack is assumed to grow downward (i.e. from high
 242          *                        memory to low memory).  'ptos' will thus point to the highest (valid) memory
 243          *                        location of the stack.  If OS_STK_GROWTH is set to 0, 'ptos' will point to the
 244          *                        lowest memory location of the stack and the stack will grow with increasing
 245          *                        memory locations.  'ptos' MUST point to a valid 'free' data item.
C51 COMPILER V8.08   OS_TASK                                                               08/04/2008 21:49:52 PAGE 6   

 246          *
 247          *              prio      is the task's priority.  A unique priority MUST be assigned to each task and the
 248          *                        lower the number, the higher the priority.
 249          *
 250          *              id        is the task's ID (0..65535)
 251          *
 252          *              pbos      is a pointer to the task's bottom of stack.  If the configuration constant
 253          *                        OS_STK_GROWTH is set to 1, the stack is assumed to grow downward (i.e. from high
 254          *                        memory to low memory).  'pbos' will thus point to the LOWEST (valid) memory
 255          *                        location of the stack.  If OS_STK_GROWTH is set to 0, 'pbos' will point to the
 256          *                        HIGHEST memory location of the stack and the stack will grow with increasing
 257          *                        memory locations.  'pbos' MUST point to a valid 'free' data item.
 258          *
 259          *              stk_size  is the size of the stack in number of elements.  If OS_STK is set to INT8U,
 260          *                        'stk_size' corresponds to the number of bytes available.  If OS_STK is set to
 261          *                        INT16U, 'stk_size' contains the number of 16-bit entries available.  Finally, if
 262          *                        OS_STK is set to INT32U, 'stk_size' contains the number of 32-bit entries
 263          *                        available on the stack.
 264          *
 265          *              pext      is a pointer to a user supplied memory location which is used as a TCB extension.
 266          *                        For example, this user memory can hold the contents of floating-point registers
 267          *                        during a context switch, the time each task takes to execute, the number of times
 268          *                        the task has been switched-in, etc.
 269          *
 270          *              opt       contains additional information (or options) about the behavior of the task.  The
 271          *                        LOWER 8-bits are reserved by uC/OS-II while the upper 8 bits can be application
 272          *                        specific.  See OS_TASK_OPT_??? in uCOS-II.H.  Current choices are:
 273          *
 274          *                        OS_TASK_OPT_STK_CHK      Stack checking to be allowed for the task
 275          *                        OS_TASK_OPT_STK_CLR      Clear the stack when the task is created
 276          *                        OS_TASK_OPT_SAVE_FP      If the CPU has floating-point registers, save them
 277          *                                                 during a context switch.
 278          *
 279          * Returns    : OS_NO_ERR               if the function was successful.
 280          *              OS_PRIO_EXIT            if the task priority already exist
 281          *                                      (each task MUST have a unique priority).
 282          *              OS_PRIO_INVALID         if the priority you specify is higher that the maximum allowed
 283          *                                      (i.e. > OS_LOWEST_PRIO)
 284          *              OS_ERR_TASK_CREATE_ISR  if you tried to create a task from an ISR.
 285          *********************************************************************************************************
 286          */
 287          /*$PAGE*/
 288          #if OS_TASK_CREATE_EXT_EN > 0
 289          INT8U  OSTaskCreateExt (void   (*task)(void *p_arg),
 290                                  void    *p_arg,
 291                                  OS_STK  *ptos,
 292                                  INT8U    prio,
 293                                  INT16U   id,
 294                                  OS_STK  *pbos,
 295                                  INT32U   stk_size,
 296                                  void    *pext,
 297                                  INT16U   opt)
 298          {
 299              OS_STK    *psp;
 300              INT8U      err;
 301          #if OS_CRITICAL_METHOD == 3                  /* Allocate storage for CPU status register               */
                  OS_CPU_SR  cpu_sr = 0;
              #endif
 304          
 305          
 306          
 307          #if OS_ARG_CHK_EN > 0
C51 COMPILER V8.08   OS_TASK                                                               08/04/2008 21:49:52 PAGE 7   

 308              if (prio > OS_LOWEST_PRIO) {             /* Make sure priority is within allowable range           */
 309                  return (OS_PRIO_INVALID);
 310              }
 311          #endif
 312              OS_ENTER_CRITICAL();
 313              if (OSIntNesting > 0) {                  /* Make sure we don't create the task from within an ISR  */
 314                  OS_EXIT_CRITICAL();
 315                  return (OS_ERR_TASK_CREATE_ISR);
 316              }
 317              if (OSTCBPrioTbl[prio] == (OS_TCB *)0) { /* Make sure task doesn't already exist at this priority  */
 318                  OSTCBPrioTbl[prio] = (OS_TCB *)1;    /* Reserve the priority to prevent others from doing ...  */
 319                                                       /* ... the same thing until task is created.              */
 320                  OS_EXIT_CRITICAL();
 321          
 322                  OS_TaskStkClr(pbos, stk_size, opt);                    /* Clear the task stack (if needed)     */
 323          
 324                  psp = OSTaskStkInit(task, p_arg, ptos, opt);           /* Initialize the task's stack          */
 325                  err = OS_TCBInit(prio, psp, pbos, id, stk_size, pext, opt);
 326                  if (err == OS_NO_ERR) {
 327                      if (OSRunning == TRUE) {                           /* Find HPT if multitasking has started */
 328                          OS_Sched();
 329                      }
 330                  } else {
 331                      OS_ENTER_CRITICAL();
 332                      OSTCBPrioTbl[prio] = (OS_TCB *)0;                  /* Make this priority avail. to others  */
 333                      OS_EXIT_CRITICAL();
 334                  }
 335                  return (err);
 336              }
 337              OS_EXIT_CRITICAL();
 338              return (OS_PRIO_EXIST);
 339          }

⌨️ 快捷键说明

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