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

📄 os_task.s43

📁 ucos2.52在msp430上移植
💻 S43
📖 第 1 页 / 共 4 页
字号:
	JEQ	(?0121)	
; 382.	        return (OS_PRIO_INVALID);
	MOV.B	#42,R12	
; 383.	    }
	JMP	(?0149)	
?0121:
; 384.	#endif
; 385.	    OS_ENTER_CRITICAL();
	DINT		
; 386.	    if (prio == OS_PRIO_SELF) {                                 /* See if requesting to delete self    */
	CMP.B	#255,R10	
	JNE	(?0125)	
; 387.	        prio = OSTCBCur->OSTCBPrio;                             /* Set priority to delete to current   */
	MOV	&OSTCBCur,R12	
	MOV.B	29(R12),R10	
?0125:
; 388.	    }
; 389.	    ptcb = OSTCBPrioTbl[prio];
	MOV.B	R10,R12	
	ADD	R12,R12	
	MOV	OSTCBPrioTbl(R12),R11	
; 390.	    if (ptcb != (OS_TCB *)0) {                                       /* Task to delete must exist      */
	CMP	#0,R11	
	JEQ	(?0127)	
; 391.	        if ((OSRdyTbl[ptcb->OSTCBY] &= ~ptcb->OSTCBBitX) == 0x00) {  /* Make task not ready            */
	MOV.B	31(R11),R12	
	MOV.B	32(R11),R13	
	XOR.B	#-1,R13	
	AND.B	R13,OSRdyTbl(R12)	
	CMP.B	#0,OSRdyTbl(R12)	
	JNE	(?0129)	
; 392.	            OSRdyGrp &= ~ptcb->OSTCBBitY;
	MOV.B	33(R11),R12	
	XOR.B	#-1,R12	
	AND.B	R12,&OSRdyGrp	
?0129:
; 393.	        }
; 394.	#if OS_EVENT_EN > 0
; 395.	        pevent = ptcb->OSTCBEventPtr;
	MOV	18(R11),R12	
; 396.	        if (pevent != (OS_EVENT *)0) {                          /* If task is waiting on event         */
	CMP	#0,R12	
	JEQ	(?0137)	
; 397.	            if ((pevent->OSEventTbl[ptcb->OSTCBY] &= ~ptcb->OSTCBBitX) == 0) { /* ... remove task from */
	MOV.B	31(R11),R13	
	ADD	R12,R13	
	MOV.B	32(R11),R14	
	XOR.B	#-1,R14	
	AND.B	R14,6(R13)	
	CMP.B	#0,6(R13)	
	JNE	(?0137)	
; 398.	                pevent->OSEventGrp &= ~ptcb->OSTCBBitY;                        /* ... event ctrl block */
	MOV.B	33(R11),R13	
	XOR.B	#-1,R13	
	AND.B	R13,1(R12)	
?0137:
; 399.	            }
; 400.	        }
; 401.	#endif
; 402.	#if (OS_VERSION >= 251) && (OS_FLAG_EN > 0) && (OS_MAX_FLAGS > 0)
; 403.	        pnode = ptcb->OSTCBFlagNode;
	MOV	22(R11),R12	
; 404.	        if (pnode != (OS_FLAG_NODE *)0) {                       /* If task is waiting on event flag    */
	CMP	#0,R12	
	JEQ	(?0141)	
; 405.	            OS_FlagUnlink(pnode);                               /* Remove from wait list               */
	CALL	#OS_FlagUnlink	
?0141:
; 406.	        }
; 407.	#endif
; 408.	        ptcb->OSTCBDly  = 0;                                    /* Prevent OSTimeTick() from updating  */
	MOV	#0,26(R11)	
; 409.	        ptcb->OSTCBStat = OS_STAT_RDY;                          /* Prevent task from being resumed     */
	MOV.B	#0,28(R11)	
; 410.	                if (OSLockNesting < 255) {
	CMP.B	#255,&OSLockNesting	
	JC	(?0143)	
; 411.	            OSLockNesting++;
	ADD.B	#1,&OSLockNesting	
?0143:
; 412.	                }
; 413.	        OS_EXIT_CRITICAL();                                     /* Enabling INT. ignores next instruc. */
	EINT		
; 414.	        OS_Dummy();                                             /* ... Dummy ensures that INTs will be */
	CALL	#OS_Dummy	
; 415.	        OS_ENTER_CRITICAL();                                    /* ... disabled HERE!                  */
	DINT		
; 416.	                if (OSLockNesting > 0) {
	CMP.B	#0,&OSLockNesting	
	JEQ	(?0145)	
; 417.	            OSLockNesting--;
	ADD.B	#-1,&OSLockNesting	
?0145:
; 418.	                }
; 419.	        OSTaskDelHook(ptcb);                                    /* Call user defined hook              */
	MOV	R11,R12	
	CALL	#OSTaskDelHook	
; 420.	        OSTaskCtr--;                                            /* One less task being managed         */
	ADD.B	#-1,&OSTaskCtr	
; 421.	        OSTCBPrioTbl[prio] = (OS_TCB *)0;                       /* Clear old priority entry            */
	ADD	R10,R10	
	MOV	#0,OSTCBPrioTbl(R10)	
; 422.	        if (ptcb->OSTCBPrev == (OS_TCB *)0) {                   /* Remove from TCB chain               */
	CMP	#0,16(R11)	
	JNE	(?0147)	
; 423.	            ptcb->OSTCBNext->OSTCBPrev = (OS_TCB *)0;
	MOV	14(R11),R12	
	MOV	#0,16(R12)	
; 424.	            OSTCBList                  = ptcb->OSTCBNext;
	MOV	14(R11),&OSTCBList	
; 425.	        } else {
	JMP	(?0148)	
?0147:
; 426.	            ptcb->OSTCBPrev->OSTCBNext = ptcb->OSTCBNext;
	MOV	16(R11),R12	
	MOV	14(R11),14(R12)	
; 427.	            ptcb->OSTCBNext->OSTCBPrev = ptcb->OSTCBPrev;
	MOV	14(R11),R12	
	MOV	16(R11),16(R12)	
?0148:
; 428.	        }
; 429.	        ptcb->OSTCBNext = OSTCBFreeList;                        /* Return TCB to free TCB list         */
	MOV	&OSTCBFreeList,14(R11)	
; 430.	        OSTCBFreeList   = ptcb;
	MOV	R11,&OSTCBFreeList	
; 431.	        OS_EXIT_CRITICAL();
	EINT		
; 432.	        OS_Sched();                                             /* Find new highest priority task      */
	CALL	#OS_Sched	
; 433.	        return (OS_NO_ERR);
	MOV.B	#0,R12	
; 434.	    }
	JMP	(?0149)	
?0127:
; 435.	    OS_EXIT_CRITICAL();
	EINT		
; 436.	    return (OS_TASK_DEL_ERR);
	MOV.B	#60,R12	
; 437.	}
?0149:
	POP	R11	
	POP	R10	
	RET		
OSTaskDelReq:
; 438.	#endif
; 439.	/*$PAGE*/
; 440.	/*
; 441.	*********************************************************************************************************
; 442.	*                                    REQUEST THAT A TASK DELETE ITSELF
; 443.	*
; 444.	* Description: This function is used to:
; 445.	*                   a) notify a task to delete itself.
; 446.	*                   b) to see if a task requested that the current task delete itself.
; 447.	*              This function is a little tricky to understand.  Basically, you have a task that needs
; 448.	*              to be deleted however, this task has resources that it has allocated (memory buffers,
; 449.	*              semaphores, mailboxes, queues etc.).  The task cannot be deleted otherwise these
; 450.	*              resources would not be freed.  The requesting task calls OSTaskDelReq() to indicate that
; 451.	*              the task needs to be deleted.  Deleting of the task is however, deferred to the task to
; 452.	*              be deleted.  For example, suppose that task #10 needs to be deleted.  The requesting task
; 453.	*              example, task #5, would call OSTaskDelReq(10).  When task #10 gets to execute, it calls
; 454.	*              this function by specifying OS_PRIO_SELF and monitors the returned value.  If the return
; 455.	*              value is OS_TASK_DEL_REQ, another task requested a task delete.  Task #10 would look like
; 456.	*              this:
; 457.	*
; 458.	*                   void Task(void *data)
; 459.	*                   {
; 460.	*                       .
; 461.	*                       .
; 462.	*                       while (1) {
; 463.	*                           OSTimeDly(1);
; 464.	*                           if (OSTaskDelReq(OS_PRIO_SELF) == OS_TASK_DEL_REQ) {
; 465.	*                               Release any owned resources;
; 466.	*                               De-allocate any dynamic memory;
; 467.	*                               OSTaskDel(OS_PRIO_SELF);
; 468.	*                           }
; 469.	*                       }
; 470.	*                   }
; 471.	*
; 472.	* Arguments  : prio    is the priority of the task to request the delete from
; 473.	*
; 474.	* Returns    : OS_NO_ERR          if the task exist and the request has been registered
; 475.	*              OS_TASK_NOT_EXIST  if the task has been deleted.  This allows the caller to know whether
; 476.	*                                 the request has been executed.
; 477.	*              OS_TASK_DEL_IDLE   if you requested to delete uC/OS-II's idle task
; 478.	*              OS_PRIO_INVALID    if the priority you specify is higher that the maximum allowed
; 479.	*                                 (i.e. >= OS_LOWEST_PRIO) or, you have not specified OS_PRIO_SELF.
; 480.	*              OS_TASK_DEL_REQ    if a task (possibly another task) requested that the running task be
; 481.	*                                 deleted.
; 482.	*********************************************************************************************************
; 483.	*/
; 484.	/*$PAGE*/
; 485.	#if OS_TASK_DEL_EN > 0
; 486.	INT8U  OSTaskDelReq (INT8U prio)
; 487.	{
; 488.	#if OS_CRITICAL_METHOD == 3                      /* Allocate storage for CPU status register           */
; 489.	    OS_CPU_SR  cpu_sr;
; 490.	#endif
; 491.	    BOOLEAN    stat;
; 492.	    INT8U      err;
; 493.	    OS_TCB    *ptcb;
; 494.	
; 495.	
; 496.	#if OS_ARG_CHK_EN > 0
; 497.	    if (prio == OS_IDLE_PRIO) {                                 /* Not allowed to delete idle task     */
	CMP.B	#12,R12	
	JNE	(?0151)	
; 498.	        return (OS_TASK_DEL_IDLE);
	MOV.B	#61,R12	
; 499.	    }
	RET		
?0151:
; 500.	    if (prio >= OS_LOWEST_PRIO && prio != OS_PRIO_SELF) {       /* Task priority valid ?               */
	CMP.B	#12,R12	
	JNC	(?0153)	
	CMP.B	#255,R12	
	JEQ	(?0153)	
; 501.	        return (OS_PRIO_INVALID);
	MOV.B	#42,R12	
; 502.	    }
	RET		
?0153:
; 503.	#endif
; 504.	    if (prio == OS_PRIO_SELF) {                                 /* See if a task is requesting to ...  */
	CMP.B	#255,R12	
	DINT		
	JNE	(?0157)	
; 505.	        OS_ENTER_CRITICAL();                                    /* ... this task to delete itself      */
; 506.	        stat = OSTCBCur->OSTCBDelReq;                           /* Return request status to caller     */
	MOV	&OSTCBCur,R13	
	MOV.B	34(R13),R12	
; 507.	        OS_EXIT_CRITICAL();
	EINT		
; 508.	        return (stat);
; 509.	    }
	RET		
?0157:
; 510.	    OS_ENTER_CRITICAL();
; 511.	    ptcb = OSTCBPrioTbl[prio];
	AND.B	#-1,R12	
	ADD	R12,R12	
	MOV	OSTCBPrioTbl(R12),R13	
; 512.	    if (ptcb != (OS_TCB *)0) {                                  /* Task to delete must exist           */
	CMP	#0,R13	
	JEQ	(?0159)	
; 513.	        ptcb->OSTCBDelReq = OS_TASK_DEL_REQ;                    /* Set flag indicating task to be DEL. */
	MOV.B	#62,34(R13)	
; 514.	        err               = OS_NO_ERR;
	MOV.B	#0,R12	
; 515.	    } else {
	JMP	(?0160)	
?0159:
; 516.	        err               = OS_TASK_NOT_EXIST;                  /* Task must be deleted                */
	MOV.B	#11,R12	
?0160:
; 517.	    }
; 518.	    OS_EXIT_CRITICAL();
	EINT		
; 519.	    return (err);
; 520.	}
	RET		
OSTaskResume:
; 521.	#endif
; 522.	/*$PAGE*/
; 523.	/*
; 524.	*********************************************************************************************************
; 525.	*                                        RESUME A SUSPENDED TASK
; 526.	*
; 527.	* Description: This function is called to resume a previously suspended task.  This is the only call that
; 528.	*              will remove an explicit task suspension.
; 529.	*
; 530.	* Arguments  : prio     is the priority of the task to resume.
; 531.	*
; 532.	* Returns    : OS_NO_ERR                if the requested task is resumed
; 533.	*              OS_PRIO_INVALID          if the priority you specify is higher that the maximum allowed
; 534.	*                                       (i.e. >= OS_LOWEST_PRIO)
; 535.	*              OS_TASK_RESUME_PRIO      if the task to resume does not exist
; 536.	*              OS_TASK_NOT_SUSPENDED    if the task to resume has not been suspended
; 537.	*********************************************************************************************************
; 538.	*/
; 539.	
; 540.	#if OS_TASK_SUSPEND_EN > 0
; 541.	INT8U  OSTaskResume (INT8U prio)
; 542.	{
; 543.	#if OS_CRITICAL_METHOD == 3                      /* Allocate storage for CPU status register           */
; 544.	    OS_CPU_SR  cpu_sr;
; 545.	#endif
; 546.	    OS_TCB    *ptcb;
; 547.	
; 548.	
; 549.	#if OS_ARG_CHK_EN > 0
; 550.	    if (prio >= OS_LOWEST_PRIO) {                               /* Make sure task priority is valid    */
	CMP.B	#12,R12	
	JNC	(?0163)	
; 551.	        return (OS_PRIO_INVALID);
	MOV.B	#42,R12	
; 552.	    }
	RET		
?0163:
; 553.	#endif
; 554.	    OS_ENTER_CRITICAL();
	DINT		
; 555.	    ptcb = OSTCBPrioTbl[prio];
	AND.B	#-1,R12	
	ADD	R12,R12	
	MOV	OSTCBPrioTbl(R12),R13	
; 556.	    if (ptcb == (OS_TCB *)0) {                                  /* Task to suspend must exist          */
	CMP	#0,R13	
	JNE	(?0165)	
; 557.	        OS_EXIT_CRITICAL();
	EINT		
; 558.	        return (OS_TASK_RESUME_PRIO);
	MOV.B	#100,R12	
; 559.	    }
	RET		
?0165:
; 560.	    if ((ptcb->OSTCBStat & OS_STAT_SUSPEND) != OS_STAT_RDY) {              /* Task must be suspended   */
	BIT.B	#8,28(R13)	
	JEQ	(?0167)	
; 561.	        if (((ptcb->OSTCBStat &= ~OS_STAT_SUSPEND) == OS_STAT_RDY) &&      /* Remove suspension        */
; 562.	             (ptcb->OSTCBDly  == 0)) {                                     /* Must not be delayed      */
	BIC.B	#8,28(R13)	
	CMP.B	#0,28(R13)	
	JNE	(?0169)	
	CMP	#0,26(R13)	
	JNE	(?0169)	
; 563.	            OSRdyGrp               |= ptcb->OSTCBBitY;                     /* Make task ready to run   */
	BIS.B	33(R13),&OSRdyGrp	
; 564.	            OSRdyTbl[ptcb->OSTCBY] |= ptcb->OSTCBBitX;
	MOV.B	31(R13),R12	
	BIS.B	32(R13),OSRdyTbl(R12)	
; 565.	            OS_EXIT_CRITICAL();
	EINT		
; 566.	            OS_Sched();
	CALL	#OS_Sched	
; 567.	        } else {
	JMP	(?0172)	
?0169:
; 568.	            OS_EXIT_CRITICAL();
	EINT		
?0172:
; 569.	        }
; 570.	        return (OS_NO_ERR);
	MOV.B	#0,R12	
; 571.	    }
	RET		

⌨️ 快捷键说明

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