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

📄 os_task.lst

📁 IAR project for MSP430 and uC/OS. All configured to start filling with tasks.
💻 LST
📖 第 1 页 / 共 5 页
字号:
    198          /*
    199          *********************************************************************************************************
    200          *                                     CREATE A TASK (Extended Version)
    201          *
    202          * Description: This function is used to have uC/OS-II manage the execution of a task.  Tasks can either
    203          *              be created prior to the start of multitasking or by a running task.  A task cannot be
    204          *              created by an ISR.  This function is similar to OSTaskCreate() except that it allows
    205          *              additional information about a task to be specified.
    206          *
    207          * Arguments  : task     is a pointer to the task's code
    208          *
    209          *              pdata    is a pointer to an optional data area which can be used to pass parameters to
    210          *                       the task when the task first executes.  Where the task is concerned it thinks
    211          *                       it was invoked and passed the argument 'pdata' as follows:
    212          *
    213          *                           void Task (void *pdata)
    214          *                           {
    215          *                               for (;;) {
    216          *                                   Task code;
    217          *                               }
    218          *                           }
    219          *
    220          *              ptos     is a pointer to the task's top of stack.  If the configuration constant
    221          *                       OS_STK_GROWTH is set to 1, the stack is assumed to grow downward (i.e. from high
    222          *                       memory to low memory).  'pstk' will thus point to the highest (valid) memory
    223          *                       location of the stack.  If OS_STK_GROWTH is set to 0, 'pstk' will point to the
    224          *                       lowest memory location of the stack and the stack will grow with increasing
    225          *                       memory locations.  'pstk' MUST point to a valid 'free' data item.
    226          *
    227          *              prio     is the task's priority.  A unique priority MUST be assigned to each task and the
    228          *                       lower the number, the higher the priority.
    229          *
    230          *              id       is the task's ID (0..65535)
    231          *
    232          *              pbos     is a pointer to the task's bottom 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).  'pbos' will thus point to the LOWEST (valid) memory
    235          *                       location of the stack.  If OS_STK_GROWTH is set to 0, 'pbos' will point to the
    236          *                       HIGHEST memory location of the stack and the stack will grow with increasing
    237          *                       memory locations.  'pbos' MUST point to a valid 'free' data item.
    238          *
    239          *              stk_size is the size of the stack in number of elements.  If OS_STK is set to INT8U,
    240          *                       'stk_size' corresponds to the number of bytes available.  If OS_STK is set to
    241          *                       INT16U, 'stk_size' contains the number of 16-bit entries available.  Finally, if
    242          *                       OS_STK is set to INT32U, 'stk_size' contains the number of 32-bit entries
    243          *                       available on the stack.
    244          *
    245          *              pext     is a pointer to a user supplied memory location which is used as a TCB extension.
    246          *                       For example, this user memory can hold the contents of floating-point registers
    247          *                       during a context switch, the time each task takes to execute, the number of times
    248          *                       the task has been switched-in, etc.
    249          *
    250          *              opt      contains additional information (or options) about the behavior of the task.  The
    251          *                       LOWER 8-bits are reserved by uC/OS-II while the upper 8 bits can be application
    252          *                       specific.  See OS_TASK_OPT_??? in uCOS-II.H.
    253          *
    254          * Returns    : OS_NO_ERR        if the function was successful.
    255          *              OS_PRIO_EXIT     if the task priority already exist
    256          *                               (each task MUST have a unique priority).
    257          *              OS_PRIO_INVALID  if the priority you specify is higher that the maximum allowed
    258          *                               (i.e. > OS_LOWEST_PRIO)
    259          *********************************************************************************************************
    260          */
    261          /*$PAGE*/
    262          #if OS_TASK_CREATE_EXT_EN > 0
    263          INT8U  OSTaskCreateExt (void   (*task)(void *pd),
    264                                  void    *pdata,
    265                                  OS_STK  *ptos,
    266                                  INT8U    prio,
    267                                  INT16U   id,
    268                                  OS_STK  *pbos,
    269                                  INT32U   stk_size,
    270                                  void    *pext,
    271                                  INT16U   opt)
    272          {
   \   01A6  0A12              PUSH    R10     
   \   01A8  0B12              PUSH    R11     
   \   01AA  0812              PUSH    R8      
   \   01AC  0912              PUSH    R9      
   \   01AE  0612              PUSH    R6      
   \   01B0  0712              PUSH    R7      
   \   01B2  0412              PUSH    R4      
   \   01B4  084C              MOV     R12,R8  
   \   01B6  094E              MOV     R14,R9  
   \   01B8  14411600          MOV     22(SP),R4       
   \   01BC  1A411800          MOV     24(SP),R10      
   \   01C0  1B411A00          MOV     26(SP),R11      
   \   01C4  16411E00          MOV     30(SP),R6       
   \   01C8  57411200          MOV.B   18(SP),R7       
    273          #if OS_CRITICAL_METHOD == 3                  /* Allocate storage for CPU status register               */
    274              OS_CPU_SR  cpu_sr;
    275          #endif
    276              OS_STK    *psp;
    277              INT8U      err;
    278          
    279          
    280          #if OS_ARG_CHK_EN > 0
    281              if (prio > OS_LOWEST_PRIO) {             /* Make sure priority is within allowable range           */
   \   01CC  77900D00          CMP.B   #13,R7  
   \   01D0  0328              JNC     (?0097) 
    282                  return (OS_PRIO_INVALID);
   \   01D2  7C402A00          MOV.B   #42,R12 
    283              }
   \   01D6  433C              JMP     (?0109) 
   \   01D8            ?0097:
    284          #endif
    285              OS_ENTER_CRITICAL();
   \   01D8  32C2              DINT            
    286              if (OSTCBPrioTbl[prio] == (OS_TCB *)0) { /* Make sure task doesn't already exist at this priority  */
   \   01DA  4C47              MOV.B   R7,R12  
   \   01DC  0C5C              ADD     R12,R12 
   \   01DE  8C930000          CMP     #0,OSTCBPrioTbl(R12)    
   \   01E2  3A20              JNE     (?0099) 
    287                  OSTCBPrioTbl[prio] = (OS_TCB *)1;    /* Reserve the priority to prevent others from doing ...  */
   \   01E4  4C47              MOV.B   R7,R12  
   \   01E6  0C5C              ADD     R12,R12 
   \   01E8  9C430000          MOV     #1,OSTCBPrioTbl(R12)    
    288                                                       /* ... the same thing until task is created.              */
    289                  OS_EXIT_CRITICAL();
   \   01EC  32D2              EINT            
    290          
    291                  if (((opt & OS_TASK_OPT_STK_CHK) != 0x0000) ||   /* See if stack checking has been enabled     */
    292                      ((opt & OS_TASK_OPT_STK_CLR) != 0x0000)) {   /* See if stack needs to be cleared           */
   \   01EE  16B3              BIT     #1,R6   
   \   01F0  0220              JNE     (?0102) 
   \   01F2  26B3              BIT     #2,R6   
   \   01F4  0824              JEQ     (?0101) 
   \   01F6            ?0102:
    293                      #if OS_STK_GROWTH == 1
    294                      (void)memset(pbos, 0, stk_size * sizeof(OS_STK));
   \   01F6  0C4A              MOV     R10,R12 
   \   01F8  0C5C              ADD     R12,R12 
   \   01FA  0C12              PUSH    R12     
   \   01FC  0E43              MOV     #0,R14  
   \   01FE  0C44              MOV     R4,R12  
   \   0200  B0120000          CALL    #memset 
   \   0204  2153              ADD     #2,SP   
   \   0206            ?0101:
    295                      #else
    296                      (void)memset(ptos, 0, stk_size * sizeof(OS_STK));
    297                      #endif
    298                  }
    299          
    300                  psp = (OS_STK *)OSTaskStkInit(task, pdata, ptos, opt); /* Initialize the task's stack          */
   \   0206  0612              PUSH    R6      
   \   0208  11121400          PUSH    20(SP)  
   \   020C  0E49              MOV     R9,R14  
   \   020E  0C48              MOV     R8,R12  
   \   0210  B0120000          CALL    #OSTaskStkInit  
   \   0214  0E4C              MOV     R12,R14 
   \   0216  2152              ADD     #4,SP   
    301                  err = OS_TCBInit(prio, psp, pbos, id, stk_size, pext, opt);
   \   0218  0612              PUSH    R6      
   \   021A  11122000          PUSH    32(SP)  
   \   021E  0B12              PUSH    R11     
   \   0220  0A12              PUSH    R10     
   \   0222  11121E00          PUSH    30(SP)  
   \   0226  0412              PUSH    R4      
   \   0228  4C47              MOV.B   R7,R12  
   \   022A  B0120000          CALL    #OS_TCBInit     
   \   022E  31500C00          ADD     #12,SP  
   \   0232  4A4C              MOV.B   R12,R10 
    302                  if (err == OS_NO_ERR) {
   \   0234  4A93              CMP.B   #0,R10  
   \   0236  32C2              DINT            
   \   0238  0920              JNE     (?0105) 
    303                      OS_ENTER_CRITICAL();
    304                      OSTaskCtr++;                                       /* Increment the #tasks counter         */
   \   023A  D2530000          ADD.B   #1,&OSTaskCtr   
    305                      OS_EXIT_CRITICAL();
   \   023E  32D2              EINT            
    306                      if (OSRunning == TRUE) {                           /* Find HPT if multitasking has started */
   \   0240  D2930000          CMP.B   #1,&OSRunning   
   \   0244  0720              JNE     (?0108) 
    307                          OS_Sched();
   \   0246  B0120000          CALL    #OS_Sched       
    308                      }
    309                  } else {
   \   024A  043C              JMP     (?0108) 
   \   024C            ?0105:
    310                      OS_ENTER_CRITICAL();
    311                      OSTCBPrioTbl[prio] = (OS_TCB *)0;                  /* Make this priority avail. to others  */
   \   024C  0757              ADD     R7,R7   
   \   024E  87430000          MOV     #0,OSTCBPrioTbl(R7)     
    312                      OS_EXIT_CRITICAL();
   \   0252  32D2              EINT            
   \   0254            ?0108:
    313                  }
    314                  return (err);
   \   0254  4C4A              MOV.B   R10,R12 
    315              }
   \   0256  033C              JMP     (?0109) 
   \   0258            ?0099:
    316              OS_EXIT_CRITICAL();
   \   0258  32D2              EINT            
    317              return (OS_PRIO_EXIST);
   \   025A  7C402800          MOV.B   #40,R12 
    318          }
   \   025E            ?0109:
   \   025E  3441              POP     R4      
   \   0260  3741              POP     R7      
   \   0262  3641              POP     R6      
   \   0264  3941              POP     R9      
   \   0266  3841              POP     R8      
   \   0268  3B41              POP     R11     
   \   026A  3A41              POP     R10     
   \   026C  3041              RET             
   \   026E            OSTaskDel:
    319          #endif
    320          /*$PAGE*/
    321          /*
    322          *********************************************************************************************************
    323          *                                            DELETE A TASK
    324          *
    325          * Description: This function allows you to delete a task.  The calling task can delete itself by
    326          *              its own priority number.  The deleted task is returned to the dormant state and can be
    327          *              re-activated by creating the deleted task again.
    328          *
    329          * Arguments  : prio    is the priority of the task to delete.  Note that you can explicitely delete
    330          *                      the current task without knowing its priority level by setting 'prio' to
    331          *                      OS_PRIO_SELF.

⌨️ 快捷键说明

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