📄 os_task.lst
字号:
332 *
333 * Returns : OS_NO_ERR if the call is successful
334 * OS_TASK_DEL_IDLE if you attempted to delete uC/OS-II's idle task
335 * OS_PRIO_INVALID if the priority you specify is higher that the maximum allowed
336 * (i.e. >= OS_LOWEST_PRIO) or, you have not specified OS_PRIO_SELF.
337 * OS_TASK_DEL_ERR if the task you want to delete does not exist
338 * OS_TASK_DEL_ISR if you tried to delete a task from an ISR
339 *
340 * Notes : 1) To reduce interrupt latency, OSTaskDel() 'disables' the task:
341 * a) by making it not ready
342 * b) by removing it from any wait lists
343 * c) by preventing OSTimeTick() from making the task ready to run.
344 * The task can then be 'unlinked' from the miscellaneous structures in uC/OS-II.
345 * 2) The function OS_Dummy() is called after OS_EXIT_CRITICAL() because, on most processors,
346 * the next instruction following the enable interrupt instruction is ignored.
347 * 3) An ISR cannot delete a task.
348 * 4) The lock nesting counter is incremented because, for a brief instant, if the current
349 * task is being deleted, the current task would not be able to be rescheduled because it
350 * is removed from the ready list. Incrementing the nesting counter prevents another task
351 * from being schedule. This means that an ISR would return to the current task which is
352 * being deleted. The rest of the deletion would thus be able to be completed.
353 *********************************************************************************************************
354 */
355 /*$PAGE*/
356 #if OS_TASK_DEL_EN > 0
357 INT8U OSTaskDel (INT8U prio)
358 {
\ 026E 0A12 PUSH R10
\ 0270 0B12 PUSH R11
\ 0272 4A4C MOV.B R12,R10
359 #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
360 OS_CPU_SR cpu_sr;
361 #endif
362
363 #if OS_EVENT_EN > 0
364 OS_EVENT *pevent;
365 #endif
366 #if (OS_VERSION >= 251) && (OS_FLAG_EN > 0) && (OS_MAX_FLAGS > 0)
367 OS_FLAG_NODE *pnode;
368 #endif
369 OS_TCB *ptcb;
370 BOOLEAN self;
371
372
373
374 if (OSIntNesting > 0) { /* See if trying to delete from ISR */
\ 0274 C2930000 CMP.B #0,&OSIntNesting
\ 0278 0324 JEQ (?0117)
375 return (OS_TASK_DEL_ISR);
\ 027A 7C403F00 MOV.B #63,R12
376 }
\ 027E 803C JMP (?0149)
\ 0280 ?0117:
377 #if OS_ARG_CHK_EN > 0
378 if (prio == OS_IDLE_PRIO) { /* Not allowed to delete idle task */
\ 0280 7A900C00 CMP.B #12,R10
\ 0284 0320 JNE (?0119)
379 return (OS_TASK_DEL_IDLE);
\ 0286 7C403D00 MOV.B #61,R12
380 }
\ 028A 7A3C JMP (?0149)
\ 028C ?0119:
381 if (prio >= OS_LOWEST_PRIO && prio != OS_PRIO_SELF) { /* Task priority valid ? */
\ 028C 7A900C00 CMP.B #12,R10
\ 0290 0528 JNC (?0121)
\ 0292 7A93 CMP.B #255,R10
\ 0294 0324 JEQ (?0121)
382 return (OS_PRIO_INVALID);
\ 0296 7C402A00 MOV.B #42,R12
383 }
\ 029A 723C JMP (?0149)
\ 029C ?0121:
384 #endif
385 OS_ENTER_CRITICAL();
\ 029C 32C2 DINT
386 if (prio == OS_PRIO_SELF) { /* See if requesting to delete self */
\ 029E 7A93 CMP.B #255,R10
\ 02A0 0420 JNE (?0125)
387 prio = OSTCBCur->OSTCBPrio; /* Set priority to delete to current */
\ 02A2 1C420000 MOV &OSTCBCur,R12
\ 02A6 5A4C1D00 MOV.B 29(R12),R10
\ 02AA ?0125:
388 }
389 ptcb = OSTCBPrioTbl[prio];
\ 02AA 4C4A MOV.B R10,R12
\ 02AC 0C5C ADD R12,R12
\ 02AE 1B4C0000 MOV OSTCBPrioTbl(R12),R11
390 if (ptcb != (OS_TCB *)0) { /* Task to delete must exist */
\ 02B2 0B93 CMP #0,R11
\ 02B4 6224 JEQ (?0127)
391 if ((OSRdyTbl[ptcb->OSTCBY] &= ~ptcb->OSTCBBitX) == 0x00) { /* Make task not ready */
\ 02B6 5C4B1F00 MOV.B 31(R11),R12
\ 02BA 5D4B2000 MOV.B 32(R11),R13
\ 02BE 7DE3 XOR.B #-1,R13
\ 02C0 CCFD0000 AND.B R13,OSRdyTbl(R12)
\ 02C4 CC930000 CMP.B #0,OSRdyTbl(R12)
\ 02C8 0520 JNE (?0129)
392 OSRdyGrp &= ~ptcb->OSTCBBitY;
\ 02CA 5C4B2100 MOV.B 33(R11),R12
\ 02CE 7CE3 XOR.B #-1,R12
\ 02D0 C2FC0000 AND.B R12,&OSRdyGrp
\ 02D4 ?0129:
393 }
394 #if OS_EVENT_EN > 0
395 pevent = ptcb->OSTCBEventPtr;
\ 02D4 1C4B1200 MOV 18(R11),R12
396 if (pevent != (OS_EVENT *)0) { /* If task is waiting on event */
\ 02D8 0C93 CMP #0,R12
\ 02DA 1024 JEQ (?0137)
397 if ((pevent->OSEventTbl[ptcb->OSTCBY] &= ~ptcb->OSTCBBitX) == 0) { /* ... remove task from */
\ 02DC 5D4B1F00 MOV.B 31(R11),R13
\ 02E0 0D5C ADD R12,R13
\ 02E2 5E4B2000 MOV.B 32(R11),R14
\ 02E6 7EE3 XOR.B #-1,R14
\ 02E8 CDFE0600 AND.B R14,6(R13)
\ 02EC CD930600 CMP.B #0,6(R13)
\ 02F0 0520 JNE (?0137)
398 pevent->OSEventGrp &= ~ptcb->OSTCBBitY; /* ... event ctrl block */
\ 02F2 5D4B2100 MOV.B 33(R11),R13
\ 02F6 7DE3 XOR.B #-1,R13
\ 02F8 CCFD0100 AND.B R13,1(R12)
\ 02FC ?0137:
399 }
400 }
401 #endif
402 #if (OS_VERSION >= 251) && (OS_FLAG_EN > 0) && (OS_MAX_FLAGS > 0)
403 pnode = ptcb->OSTCBFlagNode;
\ 02FC 1C4B1600 MOV 22(R11),R12
404 if (pnode != (OS_FLAG_NODE *)0) { /* If task is waiting on event flag */
\ 0300 0C93 CMP #0,R12
\ 0302 0224 JEQ (?0141)
405 OS_FlagUnlink(pnode); /* Remove from wait list */
\ 0304 B0120000 CALL #OS_FlagUnlink
\ 0308 ?0141:
406 }
407 #endif
408 ptcb->OSTCBDly = 0; /* Prevent OSTimeTick() from updating */
\ 0308 8B431A00 MOV #0,26(R11)
409 ptcb->OSTCBStat = OS_STAT_RDY; /* Prevent task from being resumed */
\ 030C CB431C00 MOV.B #0,28(R11)
410 if (OSLockNesting < 255) {
\ 0310 F2930000 CMP.B #255,&OSLockNesting
\ 0314 022C JC (?0143)
411 OSLockNesting++;
\ 0316 D2530000 ADD.B #1,&OSLockNesting
\ 031A ?0143:
412 }
413 OS_EXIT_CRITICAL(); /* Enabling INT. ignores next instruc. */
\ 031A 32D2 EINT
414 OS_Dummy(); /* ... Dummy ensures that INTs will be */
\ 031C B0120000 CALL #OS_Dummy
415 OS_ENTER_CRITICAL(); /* ... disabled HERE! */
\ 0320 32C2 DINT
416 if (OSLockNesting > 0) {
\ 0322 C2930000 CMP.B #0,&OSLockNesting
\ 0326 0224 JEQ (?0145)
417 OSLockNesting--;
\ 0328 F2530000 ADD.B #-1,&OSLockNesting
\ 032C ?0145:
418 }
419 OSTaskDelHook(ptcb); /* Call user defined hook */
\ 032C 0C4B MOV R11,R12
\ 032E B0120000 CALL #OSTaskDelHook
420 OSTaskCtr--; /* One less task being managed */
\ 0332 F2530000 ADD.B #-1,&OSTaskCtr
421 OSTCBPrioTbl[prio] = (OS_TCB *)0; /* Clear old priority entry */
\ 0336 0A5A ADD R10,R10
\ 0338 8A430000 MOV #0,OSTCBPrioTbl(R10)
422 if (ptcb->OSTCBPrev == (OS_TCB *)0) { /* Remove from TCB chain */
\ 033C 8B931000 CMP #0,16(R11)
\ 0340 0820 JNE (?0147)
423 ptcb->OSTCBNext->OSTCBPrev = (OS_TCB *)0;
\ 0342 1C4B0E00 MOV 14(R11),R12
\ 0346 8C431000 MOV #0,16(R12)
424 OSTCBList = ptcb->OSTCBNext;
\ 034A 924B0E00 MOV 14(R11),&OSTCBList
\ 034E 0000
425 } else {
\ 0350 0A3C JMP (?0148)
\ 0352 ?0147:
426 ptcb->OSTCBPrev->OSTCBNext = ptcb->OSTCBNext;
\ 0352 1C4B1000 MOV 16(R11),R12
\ 0356 9C4B0E00 MOV 14(R11),14(R12)
\ 035A 0E00
427 ptcb->OSTCBNext->OSTCBPrev = ptcb->OSTCBPrev;
\ 035C 1C4B0E00 MOV 14(R11),R12
\ 0360 9C4B1000 MOV 16(R11),16(R12)
\ 0364 1000
\ 0366 ?0148:
428 }
429 ptcb->OSTCBNext = OSTCBFreeList; /* Return TCB to free TCB list */
\ 0366 9B420000 MOV &OSTCBFreeList,14(R11)
\ 036A 0E00
430 OSTCBFreeList = ptcb;
\ 036C 824B0000 MOV R11,&OSTCBFreeList
431 OS_EXIT_CRITICAL();
\ 0370 32D2 EINT
432 OS_Sched(); /* Find new highest priority task */
\ 0372 B0120000 CALL #OS_Sched
433 return (OS_NO_ERR);
\ 0376 4C43 MOV.B #0,R12
434 }
\ 0378 033C JMP (?0149)
\ 037A ?0127:
435 OS_EXIT_CRITICAL();
\ 037A 32D2 EINT
436 return (OS_TASK_DEL_ERR);
\ 037C 7C403C00 MOV.B #60,R12
437 }
\ 0380 ?0149:
\ 0380 3B41 POP R11
\ 0382 3A41 POP R10
\ 0384 3041 RET
\ 0386 OSTaskDelReq:
438 #endif
439 /*$PAGE*/
440 /*
441 *********************************************************************************************************
442 * REQUEST THAT A TASK DELETE ITSELF
443 *
444 * Description: This function is used to:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -