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

📄 os_flag.s43

📁 IAR project for MSP430 and uC/OS. All configured to start filling with tasks.
💻 S43
📖 第 1 页 / 共 4 页
字号:
; 635.	    }
; 636.	    OS_EXIT_CRITICAL();
	EINT		
; 637.	    if (sched == TRUE) {
	CMP.B	#1,R9	
	JNE	(?0192)	
; 638.	        OS_Sched();
	CALL	#OS_Sched	
?0192:
; 639.	    }
; 640.	    OS_ENTER_CRITICAL();
	DINT		
; 641.	    flags_cur = pgrp->OSFlagFlags;
	MOV	4(R10),R12	
; 642.	    OS_EXIT_CRITICAL();
	EINT		
; 643.	    *err      = OS_NO_ERR;
	MOV.B	#0,0(R11)	
; 644.	    return (flags_cur);
; 645.	}
?0193:
	POP	R9	
	POP	R8	
	POP	R11	
	POP	R10	
	RET		
OSFlagQuery:
; 646.	/*$PAGE*/
; 647.	/*
; 648.	*********************************************************************************************************
; 649.	*                                           QUERY EVENT FLAG
; 650.	*
; 651.	* Description: This function is used to check the value of the event flag group.
; 652.	*
; 653.	* Arguments  : pgrp         is a pointer to the desired event flag group.
; 654.	*
; 655.	*              err           is a pointer to an error code returned to the called:
; 656.	*                            OS_NO_ERR              The call was successfull
; 657.	*                            OS_FLAG_INVALID_PGRP   You passed a NULL pointer
; 658.	*                            OS_ERR_EVENT_TYPE      You are not pointing to an event flag group
; 659.	*
; 660.	* Returns    : The current value of the event flag group.
; 661.	*
; 662.	* Called From: Task or ISR
; 663.	*********************************************************************************************************
; 664.	*/
; 665.	
; 666.	#if OS_FLAG_QUERY_EN > 0
; 667.	OS_FLAGS  OSFlagQuery (OS_FLAG_GRP *pgrp, INT8U *err)
; 668.	{
; 669.	#if OS_CRITICAL_METHOD == 3                       /* Allocate storage for CPU status register          */
; 670.	    OS_CPU_SR  cpu_sr;
; 671.	#endif
; 672.	    OS_FLAGS   flags;
; 673.	
; 674.	
; 675.	#if OS_ARG_CHK_EN > 0
; 676.	    if (pgrp == (OS_FLAG_GRP *)0) {               /* Validate 'pgrp'                                   */
	CMP	#0,R12	
	JNE	(?0195)	
; 677.	        *err = OS_FLAG_INVALID_PGRP;
	MOV.B	#150,0(R14)	
; 678.	        return ((OS_FLAGS)0);
; 679.	    }
	RET		
?0195:
; 680.	    if (pgrp->OSFlagType != OS_EVENT_TYPE_FLAG) { /* Validate event block type                         */
	MOV.B	#5,R13	
	CMP.B	@R12,R13	
	JEQ	(?0197)	
; 681.	        *err = OS_ERR_EVENT_TYPE;
	MOV.B	#1,0(R14)	
; 682.	        return ((OS_FLAGS)0);
	MOV	#0,R12	
; 683.	    }
	RET		
?0197:
; 684.	#endif
; 685.	    OS_ENTER_CRITICAL();
	DINT		
; 686.	    flags = pgrp->OSFlagFlags;
	MOV	4(R12),R13	
; 687.	    OS_EXIT_CRITICAL();
	EINT		
; 688.	    *err = OS_NO_ERR;
	MOV.B	#0,0(R14)	
; 689.	    return (flags);                               /* Return the current value of the event flags       */
	MOV	R13,R12	
; 690.	}
	RET		
OS_FlagBlock:
; 691.	#endif
; 692.	
; 693.	/*$PAGE*/
; 694.	/*
; 695.	*********************************************************************************************************
; 696.	*                         SUSPEND TASK UNTIL EVENT FLAG(s) RECEIVED OR TIMEOUT OCCURS
; 697.	*
; 698.	* Description: This function is internal to uC/OS-II and is used to put a task to sleep until the desired
; 699.	*              event flag bit(s) are set.
; 700.	*
; 701.	* Arguments  : pgrp          is a pointer to the desired event flag group.
; 702.	*
; 703.	*              pnode         is a pointer to a structure which contains data about the task waiting for
; 704.	*                            event flag bit(s) to be set.
; 705.	*
; 706.	*              flags         Is a bit pattern indicating which bit(s) (i.e. flags) you wish to check.
; 707.	*                            The bits you want are specified by setting the corresponding bits in
; 708.	*                            'flags'.  e.g. if your application wants to wait for bits 0 and 1 then
; 709.	*                            'flags' would contain 0x03.
; 710.	*
; 711.	*              wait_type     specifies whether you want ALL bits to be set/cleared or ANY of the bits
; 712.	*                            to be set/cleared.
; 713.	*                            You can specify the following argument:
; 714.	*
; 715.	*                            OS_FLAG_WAIT_CLR_ALL   You will check ALL bits in 'mask' to be clear (0)
; 716.	*                            OS_FLAG_WAIT_CLR_ANY   You will check ANY bit  in 'mask' to be clear (0)
; 717.	*                            OS_FLAG_WAIT_SET_ALL   You will check ALL bits in 'mask' to be set   (1)
; 718.	*                            OS_FLAG_WAIT_SET_ANY   You will check ANY bit  in 'mask' to be set   (1)
; 719.	*
; 720.	*              timeout       is the desired amount of time that the task will wait for the event flag
; 721.	*                            bit(s) to be set.
; 722.	*
; 723.	* Returns    : none
; 724.	*
; 725.	* Called by  : OSFlagPend()  OS_FLAG.C
; 726.	*
; 727.	* Note(s)    : This function is INTERNAL to uC/OS-II and your application should not call it.
; 728.	*********************************************************************************************************
; 729.	*/
; 730.	
; 731.	static  void  OS_FlagBlock (OS_FLAG_GRP *pgrp, OS_FLAG_NODE *pnode, OS_FLAGS flags, INT8U wait_type, INT16U timeout)
; 732.	{
; 733.	    OS_FLAG_NODE  *pnode_next;
; 734.	
; 735.	
; 736.	    OSTCBCur->OSTCBStat      |= OS_STAT_FLAG;
	MOV	&OSTCBCur,R13	
	BIS.B	#32,28(R13)	
; 737.	    OSTCBCur->OSTCBDly        = timeout;              /* Store timeout in task's TCB                   */
	MOV	&OSTCBCur,R13	
	MOV	6(SP),26(R13)	
; 738.	#if OS_TASK_DEL_EN > 0
; 739.	    OSTCBCur->OSTCBFlagNode   = pnode;                /* TCB to link to node                           */
	MOV	&OSTCBCur,R13	
	MOV	R14,22(R13)	
; 740.	#endif
; 741.	    pnode->OSFlagNodeFlags    = flags;                /* Save the flags that we need to wait for       */
	MOV	2(SP),8(R14)	
; 742.	    pnode->OSFlagNodeWaitType = wait_type;            /* Save the type of wait we are doing            */
	MOV.B	4(SP),10(R14)	
; 743.	    pnode->OSFlagNodeTCB      = (void *)OSTCBCur;     /* Link to task's TCB                            */
	MOV	&OSTCBCur,4(R14)	
; 744.	    pnode->OSFlagNodeNext     = pgrp->OSFlagWaitList; /* Add node at beginning of event flag wait list */
	MOV	2(R12),0(R14)	
; 745.	    pnode->OSFlagNodePrev     = (void *)0;
	MOV	#0,2(R14)	
; 746.	    pnode->OSFlagNodeFlagGrp  = (void *)pgrp;         /* Link to Event Flag Group                      */
	MOV	R12,6(R14)	
; 747.	    pnode_next                = (OS_FLAG_NODE *)pgrp->OSFlagWaitList;
	MOV	2(R12),R13	
; 748.	    if (pnode_next != (void *)0) {                    /* Is this the first NODE to insert?             */
	CMP	#0,R13	
	JEQ	(?0200)	
; 749.	        pnode_next->OSFlagNodePrev = pnode;           /* No, link in doubly linked list                */
	MOV	R14,2(R13)	
?0200:
; 750.	    }
; 751.	    pgrp->OSFlagWaitList = (void *)pnode;
	MOV	R14,2(R12)	
; 752.	                                                      /* Suspend current task until flag(s) received   */
; 753.	    if ((OSRdyTbl[OSTCBCur->OSTCBY] &= ~OSTCBCur->OSTCBBitX) == 0) {
	MOV	&OSTCBCur,R12	
	MOV.B	31(R12),R12	
	MOV	&OSTCBCur,R13	
	MOV.B	32(R13),R13	
	XOR.B	#-1,R13	
	AND.B	R13,OSRdyTbl(R12)	
	CMP.B	#0,OSRdyTbl(R12)	
	JNE	(?0202)	
; 754.	        OSRdyGrp &= ~OSTCBCur->OSTCBBitY;
	MOV	&OSTCBCur,R12	
	MOV.B	33(R12),R12	
	XOR.B	#-1,R12	
	AND.B	R12,&OSRdyGrp	
?0202:
; 755.	    }
; 756.	}
	RET		
OS_FlagInit:
; 757.	
; 758.	/*$PAGE*/
; 759.	/*
; 760.	*********************************************************************************************************
; 761.	*                                    INITIALIZE THE EVENT FLAG MODULE
; 762.	*
; 763.	* Description: This function is called by uC/OS-II to initialize the event flag module.  Your application
; 764.	*              MUST NOT call this function.  In other words, this function is internal to uC/OS-II.
; 765.	*
; 766.	* Arguments  : none
; 767.	*
; 768.	* Returns    : none
; 769.	*
; 770.	* WARNING    : You MUST NOT call this function from your code.  This is an INTERNAL function to uC/OS-II.
; 771.	*********************************************************************************************************
; 772.	*/
; 773.	
; 774.	void  OS_FlagInit (void)
; 775.	{
; 776.	#if OS_MAX_FLAGS == 1
; 777.	    OSFlagFreeList                 = (OS_FLAG_GRP *)&OSFlagTbl[0];  /* Only ONE event flag group!      */
; 778.	    OSFlagFreeList->OSFlagType     = OS_EVENT_TYPE_UNUSED;
; 779.	    OSFlagFreeList->OSFlagWaitList = (void *)0;
; 780.	#endif
; 781.	
; 782.	#if OS_MAX_FLAGS >= 2
; 783.	    INT8U        i;
; 784.	    OS_FLAG_GRP *pgrp1;
; 785.	    OS_FLAG_GRP *pgrp2;
; 786.	
; 787.	
; 788.	    pgrp1 = &OSFlagTbl[0];
	MOV	#OSFlagTbl,R14	
; 789.	    pgrp2 = &OSFlagTbl[1];
	MOV	#(OSFlagTbl+6),R13	
; 790.	    for (i = 0; i < (OS_MAX_FLAGS - 1); i++) {                      /* Init. list of free EVENT FLAGS  */
	MOV.B	#0,R12	
?0204:
	CMP.B	#4,R12	
	JC	(?0203)	
; 791.	        pgrp1->OSFlagType     = OS_EVENT_TYPE_UNUSED;
	MOV.B	#0,0(R14)	
; 792.	        pgrp1->OSFlagWaitList = (void *)pgrp2;
	MOV	R13,2(R14)	
; 793.	        pgrp1++;
	ADD	#6,R14	
; 794.	        pgrp2++;
	ADD	#6,R13	
	ADD.B	#1,R12	
	JMP	(?0204)	
?0203:
; 795.	    }
; 796.	    pgrp1->OSFlagWaitList = (void *)0;
	MOV	#0,2(R14)	
; 797.	    OSFlagFreeList        = (OS_FLAG_GRP *)&OSFlagTbl[0];
	MOV	#OSFlagTbl,&OSFlagFreeList	
; 798.	#endif
; 799.	}
	RET		
OS_FlagTaskRdy:
; 800.	
; 801.	/*$PAGE*/
; 802.	/*
; 803.	*********************************************************************************************************
; 804.	*                              MAKE TASK READY-TO-RUN, EVENT(s) OCCURRED
; 805.	*
; 806.	* Description: This function is internal to uC/OS-II and is used to make a task ready-to-run because the
; 807.	*              desired event flag bits have been set.
; 808.	*
; 809.	* Arguments  : pnode         is a pointer to a structure which contains data about the task waiting for
; 810.	*                            event flag bit(s) to be set.
; 811.	*
; 812.	*              flags_rdy     contains the bit pattern of the event flags that cause the task to become
; 813.	*                            ready-to-run.
; 814.	*
; 815.	* Returns    : none
; 816.	*
; 817.	* Called by  : OSFlagsPost() OS_FLAG.C
; 818.	*
; 819.	* Note(s)    : 1) This function assumes that interrupts are disabled.
; 820.	*              2) This function is INTERNAL to uC/OS-II and your application should not call it.
; 821.	*********************************************************************************************************
; 822.	*/
; 823.	
; 824.	static  BOOLEAN  OS_FlagTaskRdy (OS_FLAG_NODE *pnode, OS_FLAGS flags_rdy)
; 825.	{
	PUSH	R10	
; 826.	    OS_TCB   *ptcb;
; 827.	    BOOLEAN   sched;
; 828.	
; 829.	
; 830.	    ptcb                = (OS_TCB *)pnode->OSFlagNodeTCB;  /* Point to TCB of waiting task             */
	MOV	4(R12),R13	
; 831.	    ptcb->OSTCBDly      = 0;
	MOV	#0,26(R13)	
; 832.	    ptcb->OSTCBFlagsRdy = flags_rdy;
	MOV	R14,24(R13)	
; 833.	    ptcb->OSTCBStat    &= ~OS_STAT_FLAG;
	AND.B	#223,28(R13)	
; 834.	    if (ptcb->OSTCBStat == OS_STAT_RDY) {                  /* Put task into ready list                 */
	CMP.B	#0,28(R13)	
	JNE	(?0208)	
; 835.	        OSRdyGrp               |= ptcb->OSTCBBitY;
	BIS.B	33(R13),&OSRdyGrp	
; 836.	        OSRdyTbl[ptcb->OSTCBY] |= ptcb->OSTCBBitX;
	MOV.B	31(R13),R14	
	BIS.B	32(R13),OSRdyTbl(R14)	
; 837.	        sched                   = TRUE;
	MOV.B	#1,R10	
; 838.	    } else {
	JMP	(?0209)	
?0208:
; 839.	        sched                   = FALSE;
	MOV.B	#0,R10	
?0209:
; 840.	    }
; 841.	    OS_FlagUnlink(pnode);
	CALL	#OS_FlagUnlink	
; 842.	    return (sched);
	MOV.B	R10,R12	
; 843.	}
	POP	R10	
	RET		
OS_FlagUnlink:
; 844.	
; 845.	/*$PAGE*/
; 846.	/*
; 847.	*********************************************************************************************************
; 848.	*                                  UNLINK EVENT FLAG NODE FROM WAITING LIST
; 849.	*
; 850.	* Description: This function is internal to uC/OS-II and is used to unlink an event flag node from a
; 851.	*              list of tasks waiting for the event flag.
; 852.	*
; 853.	* Arguments  : pnode         is a pointer to a structure which contains data about the task waiting for
; 854.	*                            event flag bit(s) to be set.
; 855.	*
; 856.	* Returns    : none
; 857.	*
; 858.	* Called by  : OS_FlagTaskRdy() OS_FLAG.C
; 859.	*              OSFlagPend()     OS_FLAG.C
; 860.	*              OSTaskDel()      OS_TASK.C
; 861.	*
; 862.	* Note(s)    : 1) This function assumes that interrupts are disabled.
; 863.	*              2) This function is INTERNAL to uC/OS-II and your application should not call it.
; 864.	*********************************************************************************************************
; 865.	*/
; 866.	
; 867.	void  OS_FlagUnlink (OS_FLAG_NODE *pnode)
; 868.	{
; 869.	#if OS_TASK_DEL_EN > 0
; 870.	    OS_TCB       *ptcb;
; 871.	#endif
; 872.	    OS_FLAG_GRP  *pgrp;
; 873.	    OS_FLAG_NODE *pnode_prev;
; 874.	    OS_FLAG_NODE *pnode_next;
; 875.	
; 876.	
; 877.	    pnode_prev = (OS_FLAG_NODE *)pnode->OSFlagNodePrev;
	MOV	2(R12),R13	
; 878.	    pnode_next = (OS_FLAG_NODE *)pnode->OSFlagNodeNext;
	MOV	@R12,R14	
; 879.	    if (pnode_prev == (OS_FLAG_NODE *)0) {                      /* Is it first node in wait list?      */
	CMP	#0,R13	
	JNE	(?0211)	
; 880.	        pgrp                 = (OS_FLAG_GRP *)pnode->OSFlagNodeFlagGrp;
	MOV	6(R12),R13	
; 881.	        pgrp->OSFlagWaitList = (void *)pnode_next;              /*      Update list for new 1st node   */
	MOV	R14,2(R13)	
; 882.	        if (pnode_next != (OS_FLAG_NODE *)0) {
	CMP	#0,R14	
	JEQ	(?0216)	
; 883.	            pnode_next->OSFlagNodePrev = (OS_FLAG_NODE *)0;     /*      Link new 1st node PREV to NULL */
	MOV	#0,2(R14)	
; 884.	        }
; 885.	    } else {                                                    /* No,  A node somewhere in the list   */
	JMP	(?0216)	
?0211:
; 886.	        pnode_prev->OSFlagNodeNext = pnode_next;                /*      Link around the node to unlink */
	MOV	R14,0(R13)	
; 887.	        if (pnode_next != (OS_FLAG_NODE *)0) {                  /*      Was this the LAST node?        */
	CMP	#0,R14	
	JEQ	(?0216)	
; 888.	            pnode_next->OSFlagNodePrev = pnode_prev;            /*      No, Link around current node   */
	MOV	R13,2(R14)	
?0216:
; 889.	        }
; 890.	    }
; 891.	#if OS_TASK_DEL_EN > 0
; 892.	    ptcb                = (OS_TCB *)pnode->OSFlagNodeTCB;
	MOV	4(R12),R13	
; 893.	    ptcb->OSTCBFlagNode = (OS_FLAG_NODE *)0;
	MOV	#0,22(R13)	
; 894.	#endif
; 895.	}
	RET		
; 896.	#endif
	END

⌨️ 快捷键说明

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