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

📄 os_time.s43

📁 IAR project for MSP430 and uC/OS. All configured to start filling with tasks.
💻 S43
字号:
	NAME	os_time(16)
	RSEG	CODE(1)
	EXTERN	OSRdyGrp
	EXTERN	OSRdyTbl
	EXTERN	OSTCBCur
	EXTERN	OSTCBPrioTbl
	EXTERN	OSTime
	PUBLIC	OSTimeDly
	PUBLIC	OSTimeDlyHMSM
	PUBLIC	OSTimeDlyResume
	PUBLIC	OSTimeGet
	PUBLIC	OSTimeSet
	EXTERN	OS_Sched
	EXTERN	?CL430_1_26_L08
	EXTERN	?L_MUL_L03
	EXTERN	?UL_DIVMOD_L03
	RSEG	CODE
OSTimeDly:
; 1.	/*
; 2.	*********************************************************************************************************
; 3.	*                                                uC/OS-II
; 4.	*                                          The Real-Time Kernel
; 5.	*                                             TIME MANAGEMENT
; 6.	*
; 7.	*                          (c) Copyright 1992-2002, Jean J. Labrosse, Weston, FL
; 8.	*                                           All Rights Reserved
; 9.	*
; 10.	* File : OS_TIME.C
; 11.	* By   : Jean J. Labrosse
; 12.	*********************************************************************************************************
; 13.	*/
; 14.	
; 15.	#ifndef  OS_MASTER_FILE
; 16.	#include "includes.h"
; 17.	#endif
; 18.	
; 19.	/*
; 20.	*********************************************************************************************************
; 21.	*                                DELAY TASK 'n' TICKS   (n from 0 to 65535)
; 22.	*
; 23.	* Description: This function is called to delay execution of the currently running task until the
; 24.	*              specified number of system ticks expires.  This, of course, directly equates to delaying
; 25.	*              the current task for some time to expire.  No delay will result If the specified delay is
; 26.	*              0.  If the specified delay is greater than 0 then, a context switch will result.
; 27.	*
; 28.	* Arguments  : ticks     is the time delay that the task will be suspended in number of clock 'ticks'.
; 29.	*                        Note that by specifying 0, the task will not be delayed.
; 30.	*
; 31.	* Returns    : none
; 32.	*********************************************************************************************************
; 33.	*/
; 34.	
; 35.	void  OSTimeDly (INT16U ticks)
; 36.	{
; 37.	#if OS_CRITICAL_METHOD == 3                      /* Allocate storage for CPU status register           */
; 38.	    OS_CPU_SR  cpu_sr;
; 39.	#endif    
; 40.	
; 41.	
; 42.	    if (ticks > 0) {                                                      /* 0 means no delay!         */
	CMP	#0,R12	
	JEQ	(?0057)	
; 43.	        OS_ENTER_CRITICAL();
	DINT		
; 44.	        if ((OSRdyTbl[OSTCBCur->OSTCBY] &= ~OSTCBCur->OSTCBBitX) == 0) {  /* Delay current task        */
	MOV	&OSTCBCur,R13	
	MOV.B	31(R13),R13	
	MOV	&OSTCBCur,R14	
	MOV.B	32(R14),R14	
	XOR.B	#-1,R14	
	AND.B	R14,OSRdyTbl(R13)	
	CMP.B	#0,OSRdyTbl(R13)	
	JNE	(?0059)	
; 45.	            OSRdyGrp &= ~OSTCBCur->OSTCBBitY;
	MOV	&OSTCBCur,R13	
	MOV.B	33(R13),R13	
	XOR.B	#-1,R13	
	AND.B	R13,&OSRdyGrp	
?0059:
; 46.	        }
; 47.	        OSTCBCur->OSTCBDly = ticks;                                       /* Load ticks in TCB         */
	MOV	&OSTCBCur,R13	
	MOV	R12,26(R13)	
; 48.	        OS_EXIT_CRITICAL();
	EINT		
; 49.	        OS_Sched();                                                       /* Find next task to run!    */
	CALL	#OS_Sched	
?0057:
; 50.	    }
; 51.	}
	RET		
OSTimeDlyHMSM:
; 52.	/*$PAGE*/
; 53.	/*
; 54.	*********************************************************************************************************
; 55.	*                                     DELAY TASK FOR SPECIFIED TIME
; 56.	*
; 57.	* Description: This function is called to delay execution of the currently running task until some time
; 58.	*              expires.  This call allows you to specify the delay time in HOURS, MINUTES, SECONDS and
; 59.	*              MILLISECONDS instead of ticks.
; 60.	*
; 61.	* Arguments  : hours     specifies the number of hours that the task will be delayed (max. is 255)
; 62.	*              minutes   specifies the number of minutes (max. 59)
; 63.	*              seconds   specifies the number of seconds (max. 59)
; 64.	*              milli     specifies the number of milliseconds (max. 999)
; 65.	*
; 66.	* Returns    : OS_NO_ERR
; 67.	*              OS_TIME_INVALID_MINUTES
; 68.	*              OS_TIME_INVALID_SECONDS
; 69.	*              OS_TIME_INVALID_MS
; 70.	*              OS_TIME_ZERO_DLY
; 71.	*
; 72.	* Note(s)    : The resolution on the milliseconds depends on the tick rate.  For example, you can't do
; 73.	*              a 10 mS delay if the ticker interrupts every 100 mS.  In this case, the delay would be
; 74.	*              set to 0.  The actual delay is rounded to the nearest tick.
; 75.	*********************************************************************************************************
; 76.	*/
; 77.	
; 78.	#if OS_TIME_DLY_HMSM_EN > 0
; 79.	INT8U  OSTimeDlyHMSM (INT8U hours, INT8U minutes, INT8U seconds, INT16U milli)
; 80.	{
	PUSH	R10	
	PUSH	R11	
	PUSH	R8	
	PUSH	R9	
	PUSH	R6	
	PUSH	R7	
	MOV.B	R12,R11	
	MOV.B	R14,R10	
	MOV	16(SP),R12	
	MOV.B	14(SP),R6	
; 81.	    INT32U ticks;
; 82.	    INT16U loops;
; 83.	
; 84.	
; 85.	    if (hours > 0 || minutes > 0 || seconds > 0 || milli > 0) {
	CMP.B	#0,R11	
	JNE	(?0062)	
	CMP.B	#0,R10	
	JNE	(?0062)	
	CMP.B	#0,R6	
	JNE	(?0062)	
	CMP	#0,R12	
	JEQ	(?0061)	
?0062:
; 86.	        if (minutes > 59) {
	CMP.B	#60,R10	
	JNC	(?0065)	
; 87.	            return (OS_TIME_INVALID_MINUTES);    /* Validate arguments to be within range              */
	MOV.B	#81,R12	
; 88.	        }
	JMP	(?0073)	
?0065:
; 89.	        if (seconds > 59) {
	CMP.B	#60,R6	
	JNC	(?0067)	
; 90.	            return (OS_TIME_INVALID_SECONDS);
	MOV.B	#82,R12	
; 91.	        }
	JMP	(?0073)	
?0067:
; 92.	        if (milli > 999) {
	CMP	#1000,R12	
	JNC	(?0069)	
; 93.	            return (OS_TIME_INVALID_MILLI);
	MOV.B	#83,R12	
; 94.	        }
	JMP	(?0073)	
?0069:
; 95.	                                                 /* Compute the total number of clock ticks required.. */
; 96.	                                                 /* .. (rounded to the nearest tick)                   */
; 97.	        ticks = ((INT32U)hours * 3600L + (INT32U)minutes * 60L + (INT32U)seconds) * OS_TICKS_PER_SEC
; 98.	              + OS_TICKS_PER_SEC * ((INT32U)milli + 500L / OS_TICKS_PER_SEC) / 1000L;
	MOV	#0,R13	
	ADD	#2,R12	
	ADDC	#0,R13	
	MOV	#200,R14	
	MOV	#0,R15	
	CALL	#?L_MUL_L03	
	MOV	#1000,R14	
	MOV	#0,R15	
	CALL	#?UL_DIVMOD_L03	
	MOV	R12,R8	
	MOV	R13,R9	
	MOV	#0,R7	
	MOV	R10,R12	
	MOV	#0,R13	
	MOV	#60,R14	
	MOV	#0,R15	
	CALL	#?L_MUL_L03	
	ADD	R12,R6	
	ADDC	R13,R7	
	MOV	R11,R12	
	MOV	#0,R13	
	MOV	#3600,R14	
	MOV	#0,R15	
	CALL	#?L_MUL_L03	
	ADD	R12,R6	
	ADDC	R13,R7	
	MOV	R6,R12	
	MOV	R7,R13	
	MOV	#200,R14	
	MOV	#0,R15	
	CALL	#?L_MUL_L03	
	ADD	R12,R8	
	ADDC	R13,R9	
; 99.	        loops = (INT16U)(ticks / 65536L);        /* Compute the integral number of 65536 tick delays   */
	MOV	R9,R10	
; 100.	        ticks = ticks % 65536L;                  /* Obtain  the fractional number of ticks             */
	AND	#65535,R8	
; 101.	        OSTimeDly((INT16U)ticks);
	MOV	R8,R12	
	CALL	#OSTimeDly	
?0071:
; 102.	        while (loops > 0) {
	CMP	#0,R10	
	JEQ	(?0070)	
; 103.	            OSTimeDly(32768);
	MOV	#32768,R12	
	CALL	#OSTimeDly	
; 104.	            OSTimeDly(32768);
	MOV	#32768,R12	
	CALL	#OSTimeDly	
; 105.	            loops--;
	ADD	#-1,R10	
	JMP	(?0071)	
?0070:
; 106.	        }
; 107.	        return (OS_NO_ERR);
	MOV.B	#0,R12	
; 108.	    }
	JMP	(?0073)	
?0061:
; 109.	    return (OS_TIME_ZERO_DLY);
	MOV.B	#84,R12	
; 110.	}
?0073:
	POP	R7	
	POP	R6	
	POP	R9	
	POP	R8	
	POP	R11	
	POP	R10	
	RET		
OSTimeDlyResume:
; 111.	#endif
; 112.	/*$PAGE*/
; 113.	/*
; 114.	*********************************************************************************************************
; 115.	*                                         RESUME A DELAYED TASK
; 116.	*
; 117.	* Description: This function is used resume a task that has been delayed through a call to either
; 118.	*              OSTimeDly() or OSTimeDlyHMSM().  Note that you MUST NOT call this function to resume a
; 119.	*              task that is waiting for an event with timeout.  This situation would make the task look
; 120.	*              like a timeout occurred (unless you desire this effect).  Also, you cannot resume a task
; 121.	*              that has called OSTimeDlyHMSM() with a combined time that exceeds 65535 clock ticks.  In
; 122.	*              other words, if the clock tick runs at 100 Hz then, you will not be able to resume a
; 123.	*              delayed task that called OSTimeDlyHMSM(0, 10, 55, 350) or higher.
; 124.	*
; 125.	*                  (10 Minutes * 60 + 55 Seconds + 0.35) * 100 ticks/second.
; 126.	*
; 127.	* Arguments  : prio      specifies the priority of the task to resume
; 128.	*
; 129.	* Returns    : OS_NO_ERR                 Task has been resumed
; 130.	*              OS_PRIO_INVALID           if the priority you specify is higher that the maximum allowed
; 131.	*                                        (i.e. >= OS_LOWEST_PRIO)
; 132.	*              OS_TIME_NOT_DLY           Task is not waiting for time to expire
; 133.	*              OS_TASK_NOT_EXIST         The desired task has not been created
; 134.	*********************************************************************************************************
; 135.	*/
; 136.	
; 137.	#if OS_TIME_DLY_RESUME_EN > 0
; 138.	INT8U  OSTimeDlyResume (INT8U prio)
; 139.	{
; 140.	#if OS_CRITICAL_METHOD == 3                      /* Allocate storage for CPU status register           */
; 141.	    OS_CPU_SR  cpu_sr;
; 142.	#endif    
; 143.	    OS_TCB    *ptcb;
; 144.	
; 145.	
; 146.	    if (prio >= OS_LOWEST_PRIO) {
	CMP.B	#12,R12	
	JNC	(?0075)	
; 147.	        return (OS_PRIO_INVALID);
	MOV.B	#42,R12	
; 148.	    }
	RET		
?0075:
; 149.	    OS_ENTER_CRITICAL();
	DINT		
; 150.	    ptcb = (OS_TCB *)OSTCBPrioTbl[prio];                   /* Make sure that task exist                */
	AND.B	#-1,R12	
	ADD	R12,R12	
	MOV	OSTCBPrioTbl(R12),R13	
; 151.	    if (ptcb != (OS_TCB *)0) {
	CMP	#0,R13	
	JEQ	(?0077)	
; 152.	        if (ptcb->OSTCBDly != 0) {                         /* See if task is delayed                   */
	CMP	#0,26(R13)	
	JEQ	(?0079)	
; 153.	            ptcb->OSTCBDly  = 0;                           /* Clear the time delay                     */
	MOV	#0,26(R13)	
; 154.	            if ((ptcb->OSTCBStat & OS_STAT_SUSPEND) == OS_STAT_RDY) {  /* See if task is ready to run  */
	BIT.B	#8,28(R13)	
	JNE	(?0081)	
; 155.	                OSRdyGrp               |= ptcb->OSTCBBitY;             /* Make task ready to run       */
	BIS.B	33(R13),&OSRdyGrp	
; 156.	                OSRdyTbl[ptcb->OSTCBY] |= ptcb->OSTCBBitX;
	MOV.B	31(R13),R12	
	BIS.B	32(R13),OSRdyTbl(R12)	
; 157.	                OS_EXIT_CRITICAL();
	EINT		
; 158.	                OS_Sched();                                /* See if this is new highest priority      */
	CALL	#OS_Sched	
; 159.	            } else {
	JMP	(?0082)	
?0081:
; 160.	                OS_EXIT_CRITICAL();                        /* Task may be suspended                    */
	EINT		
?0082:
; 161.	            }
; 162.	            return (OS_NO_ERR);
	MOV.B	#0,R12	
; 163.	        } else {
	RET		
?0079:
; 164.	            OS_EXIT_CRITICAL();
	EINT		
; 165.	            return (OS_TIME_NOT_DLY);                      /* Indicate that task was not delayed       */
	MOV.B	#80,R12	
; 166.	        }
	RET		
?0077:
; 167.	    }
; 168.	    OS_EXIT_CRITICAL();
	EINT		
; 169.	    return (OS_TASK_NOT_EXIST);                            /* The task does not exist                  */
	MOV.B	#11,R12	
; 170.	}
	RET		
OSTimeGet:
; 171.	#endif    
; 172.	/*$PAGE*/
; 173.	/*
; 174.	*********************************************************************************************************
; 175.	*                                         GET CURRENT SYSTEM TIME
; 176.	*
; 177.	* Description: This function is used by your application to obtain the current value of the 32-bit
; 178.	*              counter which keeps track of the number of clock ticks.
; 179.	*
; 180.	* Arguments  : none
; 181.	*
; 182.	* Returns    : The current value of OSTime
; 183.	*********************************************************************************************************
; 184.	*/
; 185.	
; 186.	#if OS_TIME_GET_SET_EN > 0
; 187.	INT32U  OSTimeGet (void)
; 188.	{
; 189.	#if OS_CRITICAL_METHOD == 3                      /* Allocate storage for CPU status register           */
; 190.	    OS_CPU_SR  cpu_sr;
; 191.	#endif    
; 192.	    INT32U     ticks;
; 193.	
; 194.	
; 195.	    OS_ENTER_CRITICAL();
	DINT		
; 196.	    ticks = OSTime;
	MOV	&OSTime,R12	
	MOV	&(OSTime+2),R13	
; 197.	    OS_EXIT_CRITICAL();
	EINT		
; 198.	    return (ticks);
; 199.	}
	RET		
OSTimeSet:
; 200.	#endif    
; 201.	
; 202.	/*
; 203.	*********************************************************************************************************
; 204.	*                                            SET SYSTEM CLOCK
; 205.	*
; 206.	* Description: This function sets the 32-bit counter which keeps track of the number of clock ticks.
; 207.	*
; 208.	* Arguments  : ticks      specifies the new value that OSTime needs to take.
; 209.	*
; 210.	* Returns    : none
; 211.	*********************************************************************************************************
; 212.	*/
; 213.	
; 214.	#if OS_TIME_GET_SET_EN > 0
; 215.	void  OSTimeSet (INT32U ticks)
; 216.	{
; 217.	#if OS_CRITICAL_METHOD == 3                      /* Allocate storage for CPU status register           */
; 218.	    OS_CPU_SR  cpu_sr;
; 219.	#endif    
; 220.	
; 221.	
; 222.	    OS_ENTER_CRITICAL();
	DINT		
; 223.	    OSTime = ticks;
	MOV	R12,&OSTime	
	MOV	R13,&(OSTime+2)	
; 224.	    OS_EXIT_CRITICAL();
	EINT		
; 225.	}
	RET		
; 226.	#endif    
	END

⌨️ 快捷键说明

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