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

📄 os_task.lis

📁 ucos如何移植到单片机mega128
💻 LIS
📖 第 1 页 / 共 5 页
字号:
 0116           ;         if (((opt & OS_TASK_OPT_STK_CHK) != 0x0000) ||   /* See if stack checking has been enabled     */
 0116           ;             ((opt & OS_TASK_OPT_STK_CLR) != 0x0000)) {   /* See if stack needs to be cleared           */
 0116           ;             #if OS_STK_GROWTH == 1
 0116           ;             (void)memset(pbos, 0, stk_size * sizeof(OS_STK));
 0116           ;             #else
 0116           ;             (void)memset(ptos, 0, stk_size * sizeof(OS_STK));
 0116           ;             #endif
 0116           ;         }
 0116           ; 
 0116           ;         psp = (OS_STK *)OSTaskStkInit(task, pdata, ptos, opt); /* Initialize the task's stack          */
 0116           ;         err = OS_TCBInit(prio, psp, pbos, id, stk_size, pext, opt);
 0116           ;         if (err == OS_NO_ERR) {
 0116           ;             OS_ENTER_CRITICAL();
 0116           ;             OSTaskCtr++;                                       /* Increment the #tasks counter         */
 0116           ;             OS_EXIT_CRITICAL();
 0116           ;             if (OSRunning == TRUE) {                           /* Find HPT if multitasking has started */
 0116           ;                 OS_Sched();
 0116           ;             }
 0116           ;         } else {
 0116           ;             OS_ENTER_CRITICAL();
 0116           ;             OSTCBPrioTbl[prio] = (OS_TCB *)0;                  /* Make this priority avail. to others  */
 0116           ;             OS_EXIT_CRITICAL();
 0116           ;         }
 0116           ;         return (err);
 0116           ;     }
 0116           ;     OS_EXIT_CRITICAL();
 0116           ;     return (OS_PRIO_EXIST);
 0116           ; }
 0116           ; #endif
 0116           ; /*$PAGE*/
 0116           ; /*
 0116           ; *********************************************************************************************************
 0116           ; *                                            DELETE A TASK
 0116           ; *
 0116           ; * Description: This function allows you to delete a task.  The calling task can delete itself by
 0116           ; *              its own priority number.  The deleted task is returned to the dormant state and can be
 0116           ; *              re-activated by creating the deleted task again.
 0116           ; *
 0116           ; * Arguments  : prio    is the priority of the task to delete.  Note that you can explicitely delete
 0116           ; *                      the current task without knowing its priority level by setting 'prio' to
 0116           ; *                      OS_PRIO_SELF.
 0116           ; *
 0116           ; * Returns    : OS_NO_ERR           if the call is successful
 0116           ; *              OS_TASK_DEL_IDLE    if you attempted to delete uC/OS-II's idle task
 0116           ; *              OS_PRIO_INVALID     if the priority you specify is higher that the maximum allowed
 0116           ; *                                  (i.e. >= OS_LOWEST_PRIO) or, you have not specified OS_PRIO_SELF.
 0116           ; *              OS_TASK_DEL_ERR     if the task you want to delete does not exist
 0116           ; *              OS_TASK_DEL_ISR     if you tried to delete a task from an ISR
 0116           ; *
 0116           ; * Notes      : 1) To reduce interrupt latency, OSTaskDel() 'disables' the task:
 0116           ; *                    a) by making it not ready
 0116           ; *                    b) by removing it from any wait lists
 0116           ; *                    c) by preventing OSTimeTick() from making the task ready to run.
 0116           ; *                 The task can then be 'unlinked' from the miscellaneous structures in uC/OS-II.
 0116           ; *              2) The function OS_Dummy() is called after OS_EXIT_CRITICAL() because, on most processors,
 0116           ; *                 the next instruction following the enable interrupt instruction is ignored.  
 0116           ; *              3) An ISR cannot delete a task.
 0116           ; *              4) The lock nesting counter is incremented because, for a brief instant, if the current
 0116           ; *                 task is being deleted, the current task would not be able to be rescheduled because it
 0116           ; *                 is removed from the ready list.  Incrementing the nesting counter prevents another task
 0116           ; *                 from being schedule.  This means that an ISR would return to the current task which is
 0116           ; *                 being deleted.  The rest of the deletion would thus be able to be completed.
 0116           ; *********************************************************************************************************
 0116           ; */
 0116           ; /*$PAGE*/
 0116           ; #if OS_TASK_DEL_EN > 0
 0116           ; INT8U  OSTaskDel (INT8U prio)
 0116           ; {
 0116                   .dbline 374
 0116           ; #if OS_CRITICAL_METHOD == 3                      /* Allocate storage for CPU status register           */
 0116           ;     OS_CPU_SR     cpu_sr;
 0116           ; #endif
 0116           ; 
 0116           ; #if OS_EVENT_EN > 0
 0116           ;     OS_EVENT     *pevent;
 0116           ; #endif    
 0116           ; #if (OS_VERSION >= 251) && (OS_FLAG_EN > 0) && (OS_MAX_FLAGS > 0)
 0116           ;     OS_FLAG_NODE *pnode;
 0116           ; #endif
 0116           ;     OS_TCB       *ptcb;
 0116           ;     BOOLEAN       self;
 0116           ; 
 0116           ; 
 0116           ; 
 0116           ;     if (OSIntNesting > 0) {                                     /* See if trying to delete from ISR    */
 0116 2224              clr R2
 0118 30900000          lds R3,_OSIntNesting
 011C 2314              cp R2,R3
 011E 10F4              brsh L13
 0120                   .dbline 374
 0120                   .dbline 375
 0120           ;         return (OS_TASK_DEL_ISR);
 0120 0FE3              ldi R16,63
 0122 BCC0              xjmp L12
 0124           L13:
 0124                   .dbline 378
 0124           ;     }
 0124           ; #if OS_ARG_CHK_EN > 0
 0124           ;     if (prio == OS_IDLE_PRIO) {                                 /* Not allowed to delete idle task     */
 0124 6431              cpi R22,20
 0126 11F4              brne L15
 0128                   .dbline 378
 0128                   .dbline 379
 0128           ;         return (OS_TASK_DEL_IDLE);
 0128 0DE3              ldi R16,61
 012A B8C0              xjmp L12
 012C           L15:
 012C                   .dbline 381
 012C           ;     }
 012C           ;     if (prio >= OS_LOWEST_PRIO && prio != OS_PRIO_SELF) {       /* Task priority valid ?               */
 012C 6431              cpi R22,20
 012E 20F0              brlo L17
 0130 6F3F              cpi R22,255
 0132 11F0              breq L17
 0134                   .dbline 381
 0134                   .dbline 382
 0134           ;         return (OS_PRIO_INVALID);
 0134 0AE2              ldi R16,42
 0136 B2C0              xjmp L12
 0138           L17:
 0138                   .dbline 385
 0138           ;     }
 0138           ; #endif
 0138           ;     OS_ENTER_CRITICAL();
 0138 0A93              st -y,r16
 013A 0FB7              in r16,0x3F
 013C F894              cli
 013E 0F93              push r16
 0140 0991              ld r16,y+
 0142                   .dbline 385
 0142                   .dbline 386
 0142           ;     if (prio == OS_PRIO_SELF) {                                 /* See if requesting to delete self    */
 0142 6F3F              cpi R22,255
 0144 29F4              brne L19
 0146                   .dbline 386
 0146                   .dbline 387
 0146           ;         prio = OSTCBCur->OSTCBPrio;                             /* Set priority to delete to current   */
 0146 E0910000          lds R30,_OSTCBCur
 014A F0910100          lds R31,_OSTCBCur+1
 014E 6485              ldd R22,z+12
 0150                   .dbline 388
 0150           ;     }
 0150           L19:
 0150                   .dbline 389
 0150           ;     ptcb = OSTCBPrioTbl[prio];
 0150 82E0              ldi R24,2
 0152 869F              mul R24,R22
 0154 F001              movw R30,R0
 0156 80E0              ldi R24,<_OSTCBPrioTbl
 0158 90E0              ldi R25,>_OSTCBPrioTbl
 015A E80F              add R30,R24
 015C F91F              adc R31,R25
 015E 4081              ldd R20,z+0
 0160 5181              ldd R21,z+1
 0162                   .dbline 390
 0162           ;     if (ptcb != (OS_TCB *)0) {                                       /* Task to delete must exist      */
 0162 4030              cpi R20,0
 0164 4507              cpc R20,R21
 0166 09F4              brne X6
 0168 94C0              xjmp L21
 016A           X6:
 016A           X3:
 016A                   .dbline 390
 016A                   .dbline 391
 016A           ;         if ((OSRdyTbl[ptcb->OSTCBY] &= ~ptcb->OSTCBBitX) == 0x00) {  /* Make task not ready            */
 016A 80E0              ldi R24,<_OSRdyTbl
 016C 90E0              ldi R25,>_OSRdyTbl
 016E FA01              movw R30,R20
 0170 2684              ldd R2,z+14
 0172 3324              clr R3
 0174 280E              add R2,R24
 0176 391E              adc R3,R25
 0178 FA01              movw R30,R20
 017A 4784              ldd R4,z+15
 017C 4094              com R4
 017E F101              movw R30,R2
 0180 5080              ldd R5,z+0
 0182 5420              and R5,R4
 0184 452C              mov R4,R5
 0186 4082              std z+0,R4
 0188 5520              tst R5
 018A 41F4              brne L23
 018C                   .dbline 391
 018C                   .dbline 392
 018C           ;             OSRdyGrp &= ~ptcb->OSTCBBitY;
 018C FA01              movw R30,R20
 018E 2088              ldd R2,z+16
 0190 2094              com R2
 0192 30900000          lds R3,_OSRdyGrp
 0196 3220              and R3,R2
 0198 30920000          sts _OSRdyGrp,R3
 019C                   .dbline 393
 019C           ;         }
 019C           L23:
 019C                   .dbline 403
 019C           ; #if OS_EVENT_EN > 0
 019C           ;         pevent = ptcb->OSTCBEventPtr;
 019C           ;         if (pevent != (OS_EVENT *)0) {                          /* If task is waiting on event         */
 019C           ;             if ((pevent->OSEventTbl[ptcb->OSTCBY] &= ~ptcb->OSTCBBitX) == 0) { /* ... remove task from */
 019C           ;                 pevent->OSEventGrp &= ~ptcb->OSTCBBitY;                        /* ... event ctrl block */
 019C           ;             }
 019C           ;         }
 019C           ; #endif
 019C           ; #if (OS_VERSION >= 251) && (OS_FLAG_EN > 0) && (OS_MAX_FLAGS > 0)
 019C           ;         pnode = ptcb->OSTCBFlagNode;
 019C FA01              movw R30,R20
 019E A680              ldd R10,z+6
 01A0 B780              ldd R11,z+7
 01A2                   .dbline 404
 01A2           ;         if (pnode != (OS_FLAG_NODE *)0) {                       /* If task is waiting on event flag    */
 01A2 AA20              tst R10
 01A4 11F4              brne X4
 01A6 BB20              tst R11
 01A8 19F0              breq L25
 01AA           X4:
 01AA                   .dbline 404
 01AA                   .dbline 405
 01AA           ;             OS_FlagUnlink(pnode);                               /* Remove from wait list               */
 01AA 8501              movw R16,R10
 01AC 0E940000          xcall _OS_FlagUnlink
 01B0                   .dbline 406
 01B0           ;         }
 01B0           L25:
 01B0                   .dbline 408
 01B0           ; #endif
 01B0           ;         ptcb->OSTCBDly  = 0;                                    /* Prevent OSTimeTick() from updating  */
 01B0 2224              clr R2
 01B2 3324              clr R3
 01B4 FA01              movw R30,R20
 01B6 3286              std z+10,R3
 01B8 2186              std z+9,R2
 01BA                   .dbline 409
 01BA           ;         ptcb->OSTCBStat = OS_STAT_RDY;                          /* Prevent task from being resumed     */
 01BA FA01              movw R30,R20
 01BC 2386              std z+11,R2
 01BE                   .dbline 410
 01BE           ;               if (OSLockNesting < 255) {
 01BE 80910000          lds R24,_OSLockNesting
 01C2 8F3F              cpi R24,255
 01C4 18F4              brsh L27
 01C6                   .dbline 410
 01C6                   .dbline 411
 01C6           ;             OSLockNesting++;
 01C6 8F5F              subi R24,255    ; addi 1
 01C8 80930000          sts _OSLockNesting,R24
 01CC                   .dbline 412
 01CC           ;               }
 01CC           L27:
 01CC                   .dbline 413
 01CC           ;         OS_EXIT_CRITICAL();                                     /* Enabling INT. ignores next instruc. */
 01CC 0A93              st -y,r16
 01CE 0F91              pop r16
 01D0 0FBF              out 0x3F,r16
 01D2 0991              ld r16,y+
 01D4                   .dbline 413
 01D4                   .dbline 414
 01D4           ;         OS_Dummy();                                             /* ... Dummy ensures that INTs will be */
 01D4 0E940000          xcall _OS_Dummy
 01D8                   .dbline 415

⌨️ 快捷键说明

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