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

📄 os_task.s43

📁 IAR project for MSP430 and uC/OS. All configured to start filling with tasks.
💻 S43
📖 第 1 页 / 共 4 页
字号:
?0167:
; 572.	    OS_EXIT_CRITICAL();
	EINT		
; 573.	    return (OS_TASK_NOT_SUSPENDED);
	MOV.B	#101,R12	
; 574.	}
	RET		
OSTaskStkChk:
; 575.	#endif
; 576.	/*$PAGE*/
; 577.	/*
; 578.	*********************************************************************************************************
; 579.	*                                             STACK CHECKING
; 580.	*
; 581.	* Description: This function is called to check the amount of free memory left on the specified task's
; 582.	*              stack.
; 583.	*
; 584.	* Arguments  : prio     is the task priority
; 585.	*
; 586.	*              pdata    is a pointer to a data structure of type OS_STK_DATA.
; 587.	*
; 588.	* Returns    : OS_NO_ERR           upon success
; 589.	*              OS_PRIO_INVALID     if the priority you specify is higher that the maximum allowed
; 590.	*                                  (i.e. > OS_LOWEST_PRIO) or, you have not specified OS_PRIO_SELF.
; 591.	*              OS_TASK_NOT_EXIST   if the desired task has not been created
; 592.	*              OS_TASK_OPT_ERR     if you did NOT specified OS_TASK_OPT_STK_CHK when the task was created
; 593.	*********************************************************************************************************
; 594.	*/
; 595.	#if OS_TASK_CREATE_EXT_EN > 0
; 596.	INT8U  OSTaskStkChk (INT8U prio, OS_STK_DATA *pdata)
; 597.	{
	PUSH	R10	
	PUSH	R11	
	PUSH	R8	
	PUSH	R9	
; 598.	#if OS_CRITICAL_METHOD == 3                      /* Allocate storage for CPU status register           */
; 599.	    OS_CPU_SR  cpu_sr;
; 600.	#endif
; 601.	    OS_TCB    *ptcb;
; 602.	    OS_STK    *pchk;
; 603.	    INT32U     free;
; 604.	    INT32U     size;
; 605.	
; 606.	
; 607.	#if OS_ARG_CHK_EN > 0
; 608.	    if (prio > OS_LOWEST_PRIO && prio != OS_PRIO_SELF) {        /* Make sure task priority is valid    */
	CMP.B	#13,R12	
	JNC	(?0175)	
	CMP.B	#255,R12	
	JEQ	(?0175)	
; 609.	        return (OS_PRIO_INVALID);
	MOV.B	#42,R12	
; 610.	    }
	JMP	(?0187)	
?0175:
; 611.	#endif
; 612.	    pdata->OSFree = 0;                                          /* Assume failure, set to 0 size       */
	MOV	#0,0(R14)	
	MOV	#0,2(R14)	
; 613.	    pdata->OSUsed = 0;
	MOV	#0,4(R14)	
	MOV	#0,6(R14)	
; 614.	    OS_ENTER_CRITICAL();
	DINT		
; 615.	    if (prio == OS_PRIO_SELF) {                        /* See if check for SELF                        */
	CMP.B	#255,R12	
	JNE	(?0179)	
; 616.	        prio = OSTCBCur->OSTCBPrio;
	MOV	&OSTCBCur,R13	
	MOV.B	29(R13),R12	
?0179:
; 617.	    }
; 618.	    ptcb = OSTCBPrioTbl[prio];
	AND.B	#-1,R12	
	ADD	R12,R12	
	MOV	OSTCBPrioTbl(R12),R8	
; 619.	    if (ptcb == (OS_TCB *)0) {                         /* Make sure task exist                         */
	CMP	#0,R8	
	JNE	(?0181)	
; 620.	        OS_EXIT_CRITICAL();
	EINT		
; 621.	        return (OS_TASK_NOT_EXIST);
	MOV.B	#11,R12	
; 622.	    }
	JMP	(?0187)	
?0181:
; 623.	    if ((ptcb->OSTCBOpt & OS_TASK_OPT_STK_CHK) == 0) { /* Make sure stack checking option is set       */
	BIT	#1,10(R8)	
	JNE	(?0183)	
; 624.	        OS_EXIT_CRITICAL();
	EINT		
; 625.	        return (OS_TASK_OPT_ERR);
	MOV.B	#130,R12	
; 626.	    }
	JMP	(?0187)	
?0183:
; 627.	    free = 0;
	MOV	#0,R10	
	MOV	#0,R11	
; 628.	    size = ptcb->OSTCBStkSize;
	MOV	6(R8),R12	
	MOV	8(R8),R13	
; 629.	    pchk = ptcb->OSTCBStkBottom;
	MOV	4(R8),R15	
; 630.	    OS_EXIT_CRITICAL();
	EINT		
?0185:
; 631.	#if OS_STK_GROWTH == 1
; 632.	    while (*pchk++ == (OS_STK)0) {                    /* Compute the number of zero entries on the stk */
	MOV	@R15+,R8	
	CMP	#0,R8	
	JNE	(?0184)	
; 633.	        free++;
	ADD	#1,R10	
	ADDC	#0,R11	
	JMP	(?0185)	
?0184:
; 634.	    }
; 635.	#else
; 636.	    while (*pchk-- == (OS_STK)0) {
; 637.	        free++;
; 638.	    }
; 639.	#endif
; 640.	    pdata->OSFree = free * sizeof(OS_STK);            /* Compute number of free bytes on the stack     */
	MOV	R10,R8	
	MOV	R11,R9	
	ADD	R8,R8	
	ADDC	R9,R9	
	MOV	R8,0(R14)	
	MOV	R9,2(R14)	
; 641.	    pdata->OSUsed = (size - free) * sizeof(OS_STK);   /* Compute number of bytes used on the stack     */
	SUB	R10,R12	
	SUBC	R11,R13	
	ADD	R12,R12	
	ADDC	R13,R13	
	MOV	R12,4(R14)	
	MOV	R13,6(R14)	
; 642.	    return (OS_NO_ERR);
	MOV.B	#0,R12	
; 643.	}
?0187:
	POP	R9	
	POP	R8	
	POP	R11	
	POP	R10	
	RET		
OSTaskSuspend:
; 644.	#endif
; 645.	/*$PAGE*/
; 646.	/*
; 647.	*********************************************************************************************************
; 648.	*                                            SUSPEND A TASK
; 649.	*
; 650.	* Description: This function is called to suspend a task.  The task can be the calling task if the
; 651.	*              priority passed to OSTaskSuspend() is the priority of the calling task or OS_PRIO_SELF.
; 652.	*
; 653.	* Arguments  : prio     is the priority of the task to suspend.  If you specify OS_PRIO_SELF, the
; 654.	*                       calling task will suspend itself and rescheduling will occur.
; 655.	*
; 656.	* Returns    : OS_NO_ERR                if the requested task is suspended
; 657.	*              OS_TASK_SUSPEND_IDLE     if you attempted to suspend the idle task which is not allowed.
; 658.	*              OS_PRIO_INVALID          if the priority you specify is higher that the maximum allowed
; 659.	*                                       (i.e. >= OS_LOWEST_PRIO) or, you have not specified OS_PRIO_SELF.
; 660.	*              OS_TASK_SUSPEND_PRIO     if the task to suspend does not exist
; 661.	*
; 662.	* Note       : You should use this function with great care.  If you suspend a task that is waiting for
; 663.	*              an event (i.e. a message, a semaphore, a queue ...) you will prevent this task from
; 664.	*              running when the event arrives.
; 665.	*********************************************************************************************************
; 666.	*/
; 667.	
; 668.	#if OS_TASK_SUSPEND_EN > 0
; 669.	INT8U  OSTaskSuspend (INT8U prio)
; 670.	{
; 671.	#if OS_CRITICAL_METHOD == 3                      /* Allocate storage for CPU status register           */
; 672.	    OS_CPU_SR  cpu_sr;
; 673.	#endif
; 674.	    BOOLEAN    self;
; 675.	    OS_TCB    *ptcb;
; 676.	
; 677.	
; 678.	#if OS_ARG_CHK_EN > 0
; 679.	    if (prio == OS_IDLE_PRIO) {                                 /* Not allowed to suspend idle task    */
	CMP.B	#12,R12	
	JNE	(?0189)	
; 680.	        return (OS_TASK_SUSPEND_IDLE);
	MOV.B	#91,R12	
; 681.	    }
	RET		
?0189:
; 682.	    if (prio >= OS_LOWEST_PRIO && prio != OS_PRIO_SELF) {       /* Task priority valid ?               */
	CMP.B	#12,R12	
	JNC	(?0191)	
	CMP.B	#255,R12	
	JEQ	(?0191)	
; 683.	        return (OS_PRIO_INVALID);
	MOV.B	#42,R12	
; 684.	    }
	RET		
?0191:
; 685.	#endif
; 686.	    OS_ENTER_CRITICAL();
	DINT		
; 687.	    if (prio == OS_PRIO_SELF) {                                 /* See if suspend SELF                 */
	CMP.B	#255,R12	
	MOV	&OSTCBCur,R13	
	JNE	(?0195)	
; 688.	        prio = OSTCBCur->OSTCBPrio;
	MOV.B	29(R13),R12	
; 689.	        self = TRUE;
	MOV.B	#1,R14	
	JMP	(?0199)	
?0195:
; 690.	    } else if (prio == OSTCBCur->OSTCBPrio) {                   /* See if suspending self              */
	CMP.B	29(R13),R12	
	JNE	(?0198)	
; 691.	        self = TRUE;
	MOV.B	#1,R14	
; 692.	    } else {
	JMP	(?0199)	
?0198:
; 693.	        self = FALSE;                                           /* No suspending another task          */
	MOV.B	#0,R14	
?0199:
; 694.	    }
; 695.	    ptcb = OSTCBPrioTbl[prio];
	AND.B	#-1,R12	
	ADD	R12,R12	
	MOV	OSTCBPrioTbl(R12),R13	
; 696.	    if (ptcb == (OS_TCB *)0) {                                  /* Task to suspend must exist          */
	CMP	#0,R13	
	JNE	(?0201)	
; 697.	        OS_EXIT_CRITICAL();
	EINT		
; 698.	        return (OS_TASK_SUSPEND_PRIO);
	MOV.B	#90,R12	
; 699.	    }
	RET		
?0201:
; 700.	    if ((OSRdyTbl[ptcb->OSTCBY] &= ~ptcb->OSTCBBitX) == 0x00) { /* Make task not ready                 */
	MOV.B	31(R13),R12	
	MOV.B	32(R13),R15	
	XOR.B	#-1,R15	
	AND.B	R15,OSRdyTbl(R12)	
	CMP.B	#0,OSRdyTbl(R12)	
	JNE	(?0203)	
; 701.	        OSRdyGrp &= ~ptcb->OSTCBBitY;
	MOV.B	33(R13),R12	
	XOR.B	#-1,R12	
	AND.B	R12,&OSRdyGrp	
?0203:
; 702.	    }
; 703.	    ptcb->OSTCBStat |= OS_STAT_SUSPEND;                         /* Status of task is 'SUSPENDED'       */
	BIS.B	#8,28(R13)	
; 704.	    OS_EXIT_CRITICAL();
	EINT		
; 705.	    if (self == TRUE) {                                         /* Context switch only if SELF         */
	CMP.B	#1,R14	
	JNE	(?0205)	
; 706.	        OS_Sched();
	CALL	#OS_Sched	
?0205:
; 707.	    }
; 708.	    return (OS_NO_ERR);
	MOV.B	#0,R12	
; 709.	}
	RET		
OSTaskQuery:
; 710.	#endif
; 711.	/*$PAGE*/
; 712.	/*
; 713.	*********************************************************************************************************
; 714.	*                                            QUERY A TASK
; 715.	*
; 716.	* Description: This function is called to obtain a copy of the desired task's TCB.
; 717.	*
; 718.	* Arguments  : prio     is the priority of the task to obtain information from.
; 719.	*
; 720.	* Returns    : OS_NO_ERR       if the requested task is suspended
; 721.	*              OS_PRIO_INVALID if the priority you specify is higher that the maximum allowed
; 722.	*                              (i.e. > OS_LOWEST_PRIO) or, you have not specified OS_PRIO_SELF.
; 723.	*              OS_PRIO_ERR     if the desired task has not been created
; 724.	*********************************************************************************************************
; 725.	*/
; 726.	
; 727.	#if OS_TASK_QUERY_EN > 0
; 728.	INT8U  OSTaskQuery (INT8U prio, OS_TCB *pdata)
; 729.	{
	MOV	R14,R13	
; 730.	#if OS_CRITICAL_METHOD == 3                      /* Allocate storage for CPU status register           */
; 731.	    OS_CPU_SR  cpu_sr;
; 732.	#endif
; 733.	    OS_TCB    *ptcb;
; 734.	
; 735.	
; 736.	#if OS_ARG_CHK_EN > 0
; 737.	    if (prio > OS_LOWEST_PRIO && prio != OS_PRIO_SELF) {   /* Task priority valid ?                    */
	CMP.B	#13,R12	
	JNC	(?0208)	
	CMP.B	#255,R12	
	JEQ	(?0208)	
; 738.	        return (OS_PRIO_INVALID);
	MOV.B	#42,R12	
; 739.	    }
	RET		
?0208:
; 740.	#endif
; 741.	    OS_ENTER_CRITICAL();
	DINT		
; 742.	    if (prio == OS_PRIO_SELF) {                            /* See if suspend SELF                      */
	CMP.B	#255,R12	
	JNE	(?0212)	
; 743.	        prio = OSTCBCur->OSTCBPrio;
	MOV	&OSTCBCur,R14	
	MOV.B	29(R14),R12	
?0212:
; 744.	    }
; 745.	    ptcb = OSTCBPrioTbl[prio];
	AND.B	#-1,R12	
	ADD	R12,R12	
	MOV	OSTCBPrioTbl(R12),R14	
; 746.	    if (ptcb == (OS_TCB *)0) {                             /* Task to query must exist                 */
	CMP	#0,R14	
	JNE	(?0214)	
; 747.	        OS_EXIT_CRITICAL();
	EINT		
; 748.	        return (OS_PRIO_ERR);
	MOV.B	#41,R12	
; 749.	    }
	RET		
?0214:
; 750.	    memcpy(pdata, ptcb, sizeof(OS_TCB));                   /* Copy TCB into user storage area          */
	PUSH	#36	
	MOV	R13,R12	
	CALL	#memcpy	
	ADD	#2,SP	
; 751.	    OS_EXIT_CRITICAL();
	EINT		
; 752.	    return (OS_NO_ERR);
	MOV.B	#0,R12	
; 753.	}
	RET		
; 754.	#endif
	END

⌨️ 快捷键说明

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