os_task.ls1

来自「在51单片机上移植成功的UCOS-II操作系统源代码,包括源代码及相关注释」· LS1 代码 · 共 1,019 行 · 第 1/5 页

LS1
1,019
字号

                     178     ;         return (OS_PRIO_INVALID);
                     179     ;     }
                     180     ;     OS_ENTER_CRITICAL();
                     181     ;     if (OSTCBPrioTbl[newprio] != (OS_TCB *)0) {                 /* New priority must not 
                             already exist */
                     182     ;         OS_EXIT_CRITICAL();
                     183     ;         return (OS_PRIO_EXIST);
                     184     ;     } else {
                     185     ;         OSTCBPrioTbl[newprio] = (OS_TCB *)1;                    /* Reserve the entry to p
                             revent others */
                     186     ;         OS_EXIT_CRITICAL();
                     187     ;         y    = newprio >> 3;                                    /* Precompute to reduce I
                             NT. latency   */
                     188     ;         bity = OSMapTbl[y];
                     189     ;         x    = newprio & 0x07;
                     190     ;         bitx = OSMapTbl[x];
                     191     ;         OS_ENTER_CRITICAL();
                     192     ;         if (oldprio == OS_PRIO_SELF) {                          /* See if changing self  
                                           */
                     193     ;             oldprio = OSTCBCur->OSTCBPrio;                      /* Yes, get priority     
                                           */
                     194     ;         }
                     195     ;         if ((ptcb = OSTCBPrioTbl[oldprio]) != (OS_TCB *)0) {    /* Task to change must ex
                             ist           */
                     196     ;             OSTCBPrioTbl[oldprio] = (OS_TCB *)0;                /* Remove TCB from old pr
                             iority        */
                     197     ;             if (OSRdyTbl[ptcb->OSTCBY] & ptcb->OSTCBBitX) {     /* If task is ready make 
                             it not ready  */
                     198     ;                 if ((OSRdyTbl[ptcb->OSTCBY] &= ~ptcb->OSTCBBitX) == 0) {
                     199     ;                     OSRdyGrp &= ~ptcb->OSTCBBitY;
                     200     ;                 }
                     201     ;                 OSRdyGrp    |= bity;                            /* Make new priority read
                             y to run      */
                     202     ;                 OSRdyTbl[y] |= bitx;
                     203     ;             } else {
                     204     ;                 if ((pevent = ptcb->OSTCBEventPtr) != (OS_EVENT *)0) { /* Remove from eve
                             nt wait list  */
                     205     ;                     if ((pevent->OSEventTbl[ptcb->OSTCBY] &= ~ptcb->OSTCBBitX) == 0) {
                     206     ;                         pevent->OSEventGrp &= ~ptcb->OSTCBBitY;
                     207     ;                     }
                     208     ;                     pevent->OSEventGrp    |= bity;              /* Add new priority to wa
                             it list       */
                     209     ;                     pevent->OSEventTbl[y] |= bitx;
                     210     ;                 }
                     211     ;             }
                     212     ;             OSTCBPrioTbl[newprio] = ptcb;                       /* Place pointer to TCB @
                              new priority */
                     213     ;             ptcb->OSTCBPrio       = newprio;                    /* Set new task priority 
                                           */
                     214     ;             ptcb->OSTCBY          = y;
                     215     ;             ptcb->OSTCBX          = x;
                     216     ;             ptcb->OSTCBBitY       = bity;
                     217     ;             ptcb->OSTCBBitX       = bitx;
                     218     ;             OS_EXIT_CRITICAL();
                     219     ;             OSSched();                                          /* Run highest priority t
                             ask ready     */
                     220     ;             return (OS_NO_ERR);
                     221     ;         } else {
                     222     ;             OSTCBPrioTbl[newprio] = (OS_TCB *)0;                /* Release the reserved p
                             rio.          */
                     223     ;             OS_EXIT_CRITICAL();
                     224     ;             return (OS_PRIO_ERR);                               /* Task to change didn't 
                             exist         */
                     225     ;         }
                     226     ;     }
                     227     ; }
A51 MACRO ASSEMBLER  OS_TASK                                                              09/09/2007 21:13:11 PAGE     5

                     228     ; #endif
                     229     ; /*$PAGE*/
                     230     ; /*
                     231     ; *****************************************************************************************
                             ****************
                     232     ; *                                            CREATE A TASK
                     233     ; *
                     234     ; * Description: This function is used to have uC/OS-II manage the execution of a task.  Ta
                             sks can either
                     235     ; *              be created prior to the start of multitasking or by a running task.  A tas
                             k cannot be
                     236     ; *              created by an ISR.
                     237     ; *
                     238     ; * Arguments  : task     is a pointer to the task's code
                     239     ; *
                     240     ; *              pdata    is a pointer to an optional data area which can be used to pass p
                             arameters to
                     241     ; *                       the task when the task first executes.  Where the task is concern
                             ed it thinks
                     242     ; *                       it was invoked and passed the argument 'pdata' as follows:
                     243     ; *
                     244     ; *                           void Task (void *pdata)
                     245     ; *                           {
                     246     ; *                               for (;;) {
                     247     ; *                                   Task code;
                     248     ; *                               }
                     249     ; *                           }
                     250     ; *
                     251     ; *              ptos     is a pointer to the task's top of stack.  If the configuration co
                             nstant 
                     252     ; *                       OS_STK_GROWTH is set to 1, the stack is assumed to grow downward 
                             (i.e. from high
                     253     ; *                       memory to low memory).  'pstk' will thus point to the highest (va
                             lid) memory 
                     254     ; *                       location of the stack.  If OS_STK_GROWTH is set to 0, 'pstk' will
                              point to the 
                     255     ; *                       lowest memory location of the stack and the stack will grow with 
                             increasing
                     256     ; *                       memory locations.
                     257     ; *
                     258     ; *              prio     is the task's priority.  A unique priority MUST be assigned to ea
                             ch task and the
                     259     ; *                       lower the number, the higher the priority.
                     260     ; *
                     261     ; * Returns    : OS_NO_ERR        if the function was successful.
                     262     ; *              OS_PRIO_EXIT     if the task priority already exist 
                     263     ; *                               (each task MUST have a unique priority).
                     264     ; *              OS_PRIO_INVALID  if the priority you specify is higher that the maximum al
                             lowed 
                     265     ; *                               (i.e. >= OS_LOWEST_PRIO)
                     266     ; *****************************************************************************************
                             ****************
                     267     ; */
                     268     ; 
                     269     ; #if OS_TASK_CREATE_EN
                     270     ; INT8U OSTaskCreate (void (*task)(void *pd), void *ppdata, OS_STK *ptos, INT8U prio) reent
                             rant
                     271     
----                 272             RSEG  ?PR?_?OSTaskCreate?OS_TASK
0000                 273     _?OSTaskCreate:
                     274             USING   0
                     275                             ; SOURCE LINE # 173
0000 90FFFD          276             MOV     DPTR,#0FFFDH
0003 120000   F      277             LCALL   ?C?ADDXBP
0006 EB              278             MOV     A,R3
0007 F0              279             MOVX    @DPTR,A
A51 MACRO ASSEMBLER  OS_TASK                                                              09/09/2007 21:13:11 PAGE     6

0008 A3              280             INC     DPTR
0009 EA              281             MOV     A,R2
000A F0              282             MOVX    @DPTR,A
000B A3              283             INC     DPTR
000C E9              284             MOV     A,R1
000D F0              285             MOVX    @DPTR,A
000E 90FFFC          286             MOV     DPTR,#0FFFCH
0011 120000   F      287             LCALL   ?C?ADDXBP
                     288     ; {
                     289     ;     void   *psp;
                     290     ;     INT8U   err;
                     291     ; 
                     292     ; 
                     293     ;     if (prio > OS_LOWEST_PRIO) {             /* Make sure priority is within allowable ra
                             nge           */
                     294                             ; SOURCE LINE # 179
0014 90000D          295             MOV     DPTR,#0DH
0017 120000   F      296             LCALL   ?C?XBPOFF
001A E0              297             MOVX    A,@DPTR
001B FE              298             MOV     R6,A
001C D3              299             SETB    C
001D 941C            300             SUBB    A,#01CH
001F 4005            301             JC      ?C0002
                     302     ;         return (OS_PRIO_INVALID);
                     303                             ; SOURCE LINE # 180
0021 7F2A            304             MOV     R7,#02AH
0023 020000   F      305             LJMP    ?C0003
                     306     ;     }
                     307                             ; SOURCE LINE # 181
0026                 308     ?C0002:
                     309     ;     OS_ENTER_CRITICAL();
                     310                             ; SOURCE LINE # 182
0026 C2AF            311             CLR     EA
                     312     ;     if (OSTCBPrioTbl[prio] == (OS_TCB *)0) { /* Make sure task doesn't already exist at t
                             his priority  */
                     313                             ; SOURCE LINE # 183
0028 EE              314             MOV     A,R6
0029 75F003          315             MOV     B,#03H
002C A4              316             MUL     AB
002D 2400     F      317             ADD     A,#LOW (OSTCBPrioTbl)
002F F582            318             MOV     DPL,A
0031 E4              319             CLR     A
0032 3400     F      320             ADDC    A,#HIGH (OSTCBPrioTbl)
0034 F583            321             MOV     DPH,A
0036 E0              322             MOVX    A,@DPTR
0037 FB              323             MOV     R3,A
0038 A3              324             INC     DPTR
0039 E0              325             MOVX    A,@DPTR
003A FA              326             MOV     R2,A
003B A3              327             INC     DPTR
003C E0              328             MOVX    A,@DPTR
003D 4A              329             ORL     A,R2
003E 4B              330             ORL     A,R3
003F 6003            331             JZ      $ + 5H
0041 020000   F      332             LJMP    ?C0004
                     333     ;         OSTCBPrioTbl[prio] = (OS_TCB *)1;    /* Reserve the priority to prevent others fr
                             om doing ...  */
                     334                             ; SOURCE LINE # 184
0044 FB              335             MOV     R3,A
0045 FA              336             MOV     R2,A
0046 7901            337             MOV     R1,#01H
0048 90000D          338             MOV     DPTR,#0DH
004B 120000   F      339             LCALL   ?C?XBPOFF
004E E0              340             MOVX    A,@DPTR
004F 75F003          341             MOV     B,#03H
0052 A4              342             MUL     AB
A51 MACRO ASSEMBLER  OS_TASK                                                              09/09/2007 21:13:11 PAGE     7

⌨️ 快捷键说明

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