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

📄 os_task.s79

📁 ARM仿真案例
💻 S79
📖 第 1 页 / 共 5 页
字号:
//  143 *                       location of the stack.  If OS_STK_GROWTH is set to 0, 'pstk' will point to the
//  144 *                       lowest memory location of the stack and the stack will grow with increasing
//  145 *                       memory locations.
//  146 *
//  147 *              prio     is the task's priority.  A unique priority MUST be assigned to each task and the
//  148 *                       lower the number, the higher the priority.
//  149 *
//  150 * Returns    : OS_NO_ERR        if the function was successful.
//  151 *              OS_PRIO_EXIT     if the task priority already exist
//  152 *                               (each task MUST have a unique priority).
//  153 *              OS_PRIO_INVALID  if the priority you specify is higher that the maximum allowed
//  154 *                               (i.e. >= OS_LOWEST_PRIO)
//  155 *********************************************************************************************************
//  156 */
//  157 
//  158 #if OS_TASK_CREATE_EN > 0

        RSEG CODE:CODE:NOROOT(2)
        CFI Block cfiBlock3 Using cfiCommon1
        CFI Function OSTaskCreate
        THUMB
//  159 INT8U  OSTaskCreate (void (*task)(void *pd), void *p_arg, OS_STK *ptos, INT8U prio)
//  160 {
OSTaskCreate:
        PUSH     {R4-R7,LR}
        CFI ?RET Frame(CFA, -4)
        CFI R7 Frame(CFA, -8)
        CFI R6 Frame(CFA, -12)
        CFI R5 Frame(CFA, -16)
        CFI R4 Frame(CFA, -20)
        CFI CFA R13+20
        MOVS     R4,R0
        MOVS     R5,R1
        MOVS     R6,R2
        MOVS     R7,R3
//  161 #if OS_CRITICAL_METHOD == 3                  /* Allocate storage for CPU status register               */
//  162     OS_CPU_SR  cpu_sr;
//  163 #endif
//  164     OS_STK    *psp;
//  165     INT8U      err;
//  166 
//  167 
//  168 #if OS_ARG_CHK_EN > 0
//  169     if (prio > OS_LOWEST_PRIO) {             /* Make sure priority is within allowable range           */
        CMP      R7,#+64
        BCC      ??OSTaskCreate_0
//  170         return (OS_PRIO_INVALID);
        MOVS     R0,#+42
        B        ??OSTaskCreate_1
//  171     }
//  172 #endif
//  173     OS_ENTER_CRITICAL();
??OSTaskCreate_0:
        _BLF     OS_CPU_SR_Save,??OS_CPU_SR_Save??rT
//  174     if (OSTCBPrioTbl[prio] == (OS_TCB *)0) { /* Make sure task doesn't already exist at this priority  */
        LSLS     R1,R7,#+2
        LDR      R2,??DataTable23  ;; OSTCBPrioTbl
        LDR      R1,[R2, R1]
        CMP      R1,#+0
        BNE      ??OSTaskCreate_2
//  175         OSTCBPrioTbl[prio] = (OS_TCB *)1;    /* Reserve the priority to prevent others from doing ...  */
        LSLS     R3,R7,#+2
        LDR      R1,??DataTable23  ;; OSTCBPrioTbl
        MOVS     R2,#+1
        STR      R2,[R1, R3]
//  176                                              /* ... the same thing until task is created.              */
//  177         OS_EXIT_CRITICAL();
        _BLF     OS_CPU_SR_Restore,??OS_CPU_SR_Restore??rT
//  178         psp = (OS_STK *)OSTaskStkInit(task, p_arg, ptos, 0);    /* Initialize the task's stack         */
        MOVS     R3,#+0
        MOVS     R2,R6
        MOVS     R1,R5
        MOVS     R0,R4
        _BLF     OSTaskStkInit,??OSTaskStkInit??rT
        MOVS     R4,R0
//  179         err = OS_TCBInit(prio, psp, (OS_STK *)0, 0, 0, (void *)0, 0);
        MOVS     R2,#+0
        MOVS     R1,#+0
        MOVS     R0,R1
        PUSH     {R0-R2}
        CFI CFA R13+32
        MOVS     R3,R0
        MOVS     R1,R4
        MOVS     R0,R7
        _BLF     OS_TCBInit,??OS_TCBInit??rT
        MOVS     R4,R0
//  180         if (err == OS_NO_ERR) {
        ADD      SP,SP,#+12
        CFI CFA R13+20
        BNE      ??OSTaskCreate_3
//  181             OS_ENTER_CRITICAL();
        _BLF     OS_CPU_SR_Save,??OS_CPU_SR_Save??rT
//  182             OSTaskCtr++;                                        /* Increment the #tasks counter        */
        LDR      R1,??DataTable32  ;; OSTaskCtr
        LDR      R2,??DataTable32  ;; OSTaskCtr
        LDRB     R2,[R2, #+0]
        ADDS     R2,R2,#+1
        STRB     R2,[R1, #+0]
//  183             OS_EXIT_CRITICAL();
        _BLF     OS_CPU_SR_Restore,??OS_CPU_SR_Restore??rT
//  184             if (OSRunning == TRUE) {         /* Find highest priority task if multitasking has started */
        LDR      R0,??DataTable22  ;; OSRunning
        LDRB     R0,[R0, #+0]
        CMP      R0,#+1
        BNE      ??OSTaskCreate_4
//  185                 OS_Sched();
        _BLF     OS_Sched,??OS_Sched??rT
        B        ??OSTaskCreate_4
//  186             }
//  187         } else {
//  188             OS_ENTER_CRITICAL();
??OSTaskCreate_3:
        _BLF     OS_CPU_SR_Save,??OS_CPU_SR_Save??rT
//  189             OSTCBPrioTbl[prio] = (OS_TCB *)0;/* Make this priority available to others                 */
        LSLS     R1,R7,#+2
        LDR      R2,??DataTable23  ;; OSTCBPrioTbl
        MOVS     R3,#+0
        STR      R3,[R2, R1]
//  190             OS_EXIT_CRITICAL();
        _BLF     OS_CPU_SR_Restore,??OS_CPU_SR_Restore??rT
//  191         }
//  192         return (err);
??OSTaskCreate_4:
        MOVS     R0,R4
        B        ??OSTaskCreate_1
//  193     }
//  194     OS_EXIT_CRITICAL();
??OSTaskCreate_2:
        _BLF     OS_CPU_SR_Restore,??OS_CPU_SR_Restore??rT
//  195     return (OS_PRIO_EXIST);
        MOVS     R0,#+40
??OSTaskCreate_1:
        POP      {R4-R7}
        POP      {R1}
        BX       R1               ;; return
        CFI EndBlock cfiBlock3
//  196 }

        RSEG CODE:CODE:NOROOT(2)
        CFI Block cfiBlock4 Using cfiCommon0
        CFI NoFunction
        ARM
??OSTaskCreateExt??rA:
        ADD      R12,PC,#+1
        BX       R12
        CFI EndBlock cfiBlock4
        REQUIRE OSTaskCreateExt
//  197 #endif
//  198 
//  199 /*
//  200 *********************************************************************************************************
//  201 *                                     CREATE A TASK (Extended Version)
//  202 *
//  203 * Description: This function is used to have uC/OS-II manage the execution of a task.  Tasks can either
//  204 *              be created prior to the start of multitasking or by a running task.  A task cannot be
//  205 *              created by an ISR.  This function is similar to OSTaskCreate() except that it allows
//  206 *              additional information about a task to be specified.
//  207 *
//  208 * Arguments  : task     is a pointer to the task's code
//  209 *
//  210 *              p_arg    is a pointer to an optional data area which can be used to pass parameters to
//  211 *                       the task when the task first executes.  Where the task is concerned it thinks
//  212 *                       it was invoked and passed the argument 'p_arg' as follows:
//  213 *
//  214 *                           void Task (void *p_arg)
//  215 *                           {
//  216 *                               for (;;) {
//  217 *                                   Task code;
//  218 *                               }
//  219 *                           }
//  220 *
//  221 *              ptos     is a pointer to the task's top of stack.  If the configuration constant
//  222 *                       OS_STK_GROWTH is set to 1, the stack is assumed to grow downward (i.e. from high
//  223 *                       memory to low memory).  'ptos' will thus point to the highest (valid) memory
//  224 *                       location of the stack.  If OS_STK_GROWTH is set to 0, 'ptos' will point to the
//  225 *                       lowest memory location of the stack and the stack will grow with increasing
//  226 *                       memory locations.  'ptos' MUST point to a valid 'free' data item.
//  227 *
//  228 *              prio     is the task's priority.  A unique priority MUST be assigned to each task and the
//  229 *                       lower the number, the higher the priority.
//  230 *
//  231 *              id       is the task's ID (0..65535)
//  232 *
//  233 *              pbos     is a pointer to the task's bottom of stack.  If the configuration constant
//  234 *                       OS_STK_GROWTH is set to 1, the stack is assumed to grow downward (i.e. from high
//  235 *                       memory to low memory).  'pbos' will thus point to the LOWEST (valid) memory
//  236 *                       location of the stack.  If OS_STK_GROWTH is set to 0, 'pbos' will point to the
//  237 *                       HIGHEST memory location of the stack and the stack will grow with increasing
//  238 *                       memory locations.  'pbos' MUST point to a valid 'free' data item.
//  239 *
//  240 *              stk_size is the size of the stack in number of elements.  If OS_STK is set to INT8U,
//  241 *                       'stk_size' corresponds to the number of bytes available.  If OS_STK is set to
//  242 *                       INT16U, 'stk_size' contains the number of 16-bit entries available.  Finally, if
//  243 *                       OS_STK is set to INT32U, 'stk_size' contains the number of 32-bit entries
//  244 *                       available on the stack.
//  245 *
//  246 *              pext     is a pointer to a user supplied memory location which is used as a TCB extension.
//  247 *                       For example, this user memory can hold the contents of floating-point registers
//  248 *                       during a context switch, the time each task takes to execute, the number of times
//  249 *                       the task has been switched-in, etc.
//  250 *
//  251 *              opt      contains additional information (or options) about the behavior of the task.  The
//  252 *                       LOWER 8-bits are reserved by uC/OS-II while the upper 8 bits can be application
//  253 *                       specific.  See OS_TASK_OPT_??? in uCOS-II.H.
//  254 *
//  255 * Returns    : OS_NO_ERR        if the function was successful.
//  256 *              OS_PRIO_EXIT     if the task priority already exist
//  257 *                               (each task MUST have a unique priority).
//  258 *              OS_PRIO_INVALID  if the priority you specify is higher that the maximum allowed
//  259 *                               (i.e. > OS_LOWEST_PRIO)
//  260 *********************************************************************************************************
//  261 */
//  262 
//  263 #if OS_TASK_CREATE_EXT_EN > 0

        RSEG CODE:CODE:NOROOT(2)
        CFI Block cfiBlock5 Using cfiCommon1
        CFI Function OSTaskCreateExt
        THUMB
//  264 INT8U  OSTaskCreateExt (void   (*task)(void *pd),
//  265                         void    *p_arg,
//  266                         OS_STK  *ptos,
//  267                         INT8U    prio,
//  268                         INT16U   id,
//  269                         OS_STK  *pbos,
//  270                         INT32U   stk_size,
//  271                         void    *pext,
//  272                         INT16U   opt)
//  273 {
OSTaskCreateExt:
        PUSH     {R0,R1,R4-R7,LR}
        CFI ?RET Frame(CFA, -4)
        CFI R7 Frame(CFA, -8)
        CFI R6 Frame(CFA, -12)
        CFI R5 Frame(CFA, -16)
        CFI R4 Frame(CFA, -20)
        CFI CFA R13+28
        MOVS     R4,R2
        MOVS     R5,R3
        LDR      R6,[SP, #+36]
        MOV      R0,SP
        LDRH     R7,[R0, #+44]
//  274 #if OS_CRITICAL_METHOD == 3                  /* Allocate storage for CPU status register               */
//  275     OS_CPU_SR  cpu_sr;
//  276 #endif
//  277     OS_STK    *psp;
//  278     INT8U      err;
//  279 
//  280 
//  281 #if OS_ARG_CHK_EN > 0
//  282     if (prio > OS_LOWEST_PRIO) {             /* Make sure priority is within allowable range           */
        CMP      R5,#+64
        BCC      ??OSTaskCreateExt_0
//  283         return (OS_PRIO_INVALID);
        MOVS     R0,#+42
        B        ??OSTaskCreateExt_1
//  284     }
//  285 #endif
//  286     OS_ENTER_CRITICAL();
??OSTaskCreateExt_0:
        _BLF     OS_CPU_SR_Save,??OS_CPU_SR_Save??rT
//  287     if (OSTCBPrioTbl[prio] == (OS_TCB *)0) { /* Make sure task doesn't already exist at this priority  */
        LSLS     R1,R5,#+2
        LDR      R2,??DataTable23  ;; OSTCBPrioTbl
        LDR      R1,[R2, R1]
        CMP      R1,#+0
        BNE      ??OSTaskCreateExt_2
//  288         OSTCBPrioTbl[prio] = (OS_TCB *)1;    /* Reserve the priority to prevent others from doing ...  */
        LSLS     R3,R5,#+2
        LDR      R1,??DataTable23  ;; OSTCBPrioTbl
        MOVS     R2,#+1
        STR      R2,[R1, R3]
//  289                                              /* ... the same thing until task is created.              */
//  290         OS_EXIT_CRITICAL();
        _BLF     OS_CPU_SR_Restore,??OS_CPU_SR_Restore??rT
//  291 
//  292         OS_TaskStkClr(pbos, stk_size, opt);                    /* Clear the task stack (if needed)     */
        MOVS     R2,R7
        MOVS     R1,R6
        LDR      R0,[SP, #+32]
        BL       OS_TaskStkClr
//  293 
//  294         psp = (OS_STK *)OSTaskStkInit(task, p_arg, ptos, opt); /* Initialize the task's stack          */
        MOVS     R3,R7
        MOVS     R2,R4
        LDR      R1,[SP, #+4]
        LDR      R0,[SP, #+0]
        _BLF     OSTaskStkInit,??OSTaskStkInit??rT
        MOVS     R4,R0
//  295         err = OS_TCBInit(prio, psp, pbos, id, stk_size, pext, opt);
        MOVS     R2,R7
        LDR      R1,[SP, #+40]
        MOVS     R0,R6
        PUSH     {R0-R2}
        CFI CFA R13+40
        ADD      R0,SP,#+12
        LDRH     R3,[R0, #+28]
        LDR      R2,[SP, #+44]
        MOVS     R1,R4
        MOVS     R0,R5
        _BLF     OS_TCBInit,??OS_TCBInit??rT
        MOVS     R4,R0
//  296         if (err == OS_NO_ERR) {
        ADD      SP,SP,#+12
        CFI CFA R13+28
        BNE      ??OSTaskCreateExt_3
//  297             OS_ENTER_CRITICAL();
        _BLF     OS_CPU_SR_Save,??OS_CPU_SR_Save??rT
//  298             OSTaskCtr++;                                       /* Increment the #tasks counter         */
        LDR      R1,??DataTable32  ;; OSTaskCtr
        LDR      R2,??DataTable32  ;; OSTaskCtr
        LDRB     R2,[R2, #+0]
        ADDS     R2,R2,#+1
        STRB     R2,[R1, #+0]

⌨️ 快捷键说明

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