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

📄 ixdp2400timer.c

📁 ixp2400 bsp for vxworks
💻 C
📖 第 1 页 / 共 2 页
字号:
/* ixdp2400Timer.c - ixdp2400 timer library *//* Copyright 2001 Wind River Systems, Inc. *//*modification history--------------------01b,14oct02,scm  correct timestamp value for downward counting counter...01a,12apr02,vgd   written from templateTimer.c*//*DESCRIPTIONThere are 4 timers in IXP2400 which can be clocked by SYSTEM_CLK, SYSTEM_CLK/16, SYSTEM_CLK/256 or by external clock through GPIO pins. The timer counters can be loaded with some initial value and will count down to zero and will raise an interrupt if interrupts are not masked. In addition the 4th timer can be used as watchdog timer , when watchdog enable bits are set to 1. when used as watchdog timer and when count of zero is encountered, it will initiate  the rest sequence. However this driver does notimplement the watchdog timer.Each timer consists of a 32 bit counter. By default the timer counter load register is set to 0xFFFFFFFF. The timer will count down to zeroand wrap back to 0xFFFFFFFF and continue to decrement the counter if the load register is not programmed to any value. If different value is programmed to the load register, then the counter will load this value everytime it counts down to zero.An interrupt is issued to XSCALE whenever the counter reaches zero. The interrupt signals can be enabled or disabled by the IRQ enable registers in the Interrupt Controller. The interrupt remains asserted until it is cleared by writing a 1 to the corresponding Timer clear register.At any time, the current timer value may be read from the status register.  Registers:Timer Control Registers:  [0:1] - rsvd  [2-3] - pre-scale setting  [4-6] - rsvd  [7]- timer activate  [8-31] - rsvdTimer counter loader register  [0-31] - counter load valueTimer counter status register  [0-31] - current counter valueTimer Interrupt clear register  [1-31] - rsvd  [0] - clear interrupt being assertedTimer watchdog enable  [1-31]- rsvd  [0]-watchdog enable bitThis driver provides 3 main functions, system clock support, auxilliaryclock support, and timestamp timer support.  If necessary, each functionmay be conditioned by a separate INCLUDE_ macro.  The timestamp functionis always conditional upon the INCLUDE_TIMESTAMP macro. Timer 2 and 3 are used for System clock and aux clock respectively.Note that the system clock timer provides for the timestamp facility aswell, therefore changing the system clock rate will affect thetimestamp timer period, which can be read by callingsysTimestampPeriod().The macros SYS_CLK_RATE_MIN, SYS_CLK_RATE_MAX, AUX_CLK_RATE_MIN, andAUX_CLK_RATE_MAX must be defined to provide parameter checking for thesys[Aux]ClkRateSet() routines.INCLUDES:timestampDev.h*//* includes */#include "vxWorks.h"#include "config.h"#include "drv/timer/timerDev.h"#ifdef INCLUDE_TIMESTAMP#include "drv/timer/timestampDev.h"#endif/* locals */LOCAL FUNCPTR sysClkRoutine	= NULL; /* routine to call on clock tick */LOCAL int sysClkArg		= 0; /* its argument */LOCAL int sysClkRunning		= FALSE;LOCAL int sysClkTicksPerSecond	= 60;LOCAL BOOL    sysClkConnected       = FALSE;LOCAL FUNCPTR sysAuxClkRoutine	= NULL;LOCAL int sysAuxClkArg		= 0;LOCAL int sysAuxClkRunning	= FALSE;LOCAL int sysAuxClkTicksPerSecond = 60;LOCAL BOOL    sysAuxClkConnected       = FALSE;#ifdef INCLUDE_TIMESTAMPLOCAL BOOL	sysTimestampRunning	= FALSE; 		/* running flag */LOCAL FUNCPTR	sysTimestampRoutine	= NULL;  	/* routine to call on intr */LOCAL int	sysTimestampArg		= 0;     		/* arg for routine */void	sysTimestampInt (void);		 		/* forward declaration */LOCAL unsigned int sysTimestampOFCnt = 0;LOCAL unsigned int sysClkPeriod = 0; 			/* SYS_TIMER_CLK / 60; */#endif  /* INCLUDE_TIMESTAMP *//********************************************************************************* sysClkInt - interrupt level processing for system clock** This routine handles an auxiliary clock interrupt.  It acknowledges the* interrupt and calls the routine installed by sysClkConnect().*/void sysClkInt (void)  {	volatile unsigned dummy;   /*acknowledge the interrupt if needed */   IXP2400_REG_WRITE(IXP2400_TIMER2_COUNTER_CLR,0x01);   /* read back to make sure that write is completed */   IXP2400_REG_READ(IXP2400_TIMER2_COUNTER_CLR, dummy);#ifdef INCLUDE_TIMESTAMP 	sysTimestampOFCnt += sysClkPeriod;#endif   /* call system clock service routine */   if ((sysClkRoutine != NULL) && sysClkRunning)     (*(FUNCPTR) sysClkRoutine) (sysClkArg);    }/********************************************************************************* sysClkConnect - connect a routine to the system clock interrupt** This routine specifies the interrupt service routine to be called at each* clock interrupt.  Normally, it is called from usrRoot() in usrConfig.c to * connect usrClock() to the system clock interrupt.** RETURN: OK, or ERROR if the routine cannot be connected to the interrupt.** SEE ALSO: intConnect(), usrClock(), sysClkEnable()*/STATUS sysClkConnect    (    FUNCPTR routine,	/* routine to be called at each clock interrupt */    int arg		/* argument with which to call routine */    )    {        sysClkRoutine   = routine;        sysClkArg       = arg;		   	if (!sysClkConnected )	{	sysHwInit2 ();	/* XXX for now -- needs to be in usrConfig.c */	intConnect (INUM_TO_IVEC (SYS_TIMER_INT_LVL), sysClkInt, 0);	sysClkConnected  = TRUE;	}       	return (OK);    }/********************************************************************************* sysClkDisable - turn off system clock interrupts** This routine disables system clock interrupts.** RETURNS: N/A** SEE ALSO: sysClkEnable()*/void sysClkDisable (void)    {	FAST int locKey;	volatile unsigned dummy;   	if (sysClkRunning)	{	/* Lock Interrupts */        locKey = intLock();				/*  disable system timer interrupts at the interrupt controller */	IXP2400_REG_WRITE(IXP2400_IRQ_ENABLE_CLR_REG, IXP2400_INT_VEC_T2 );				/* de-activate the timer here */ 	IXP2400_REG_WRITE(IXP2400_TIMER2_CONTROL, 0x0 );	/* read back to make sure that write is completed */	IXP2400_REG_READ(IXP2400_TIMER2_CONTROL, dummy);	/* UnLock Interrupts */ 	intUnlock (locKey);	sysClkRunning = FALSE;	}    }/********************************************************************************* sysClkEnable - turn on system clock interrupts** This routine enables system clock interrupts.** RETURNS: N/A** SEE ALSO: sysClkConnect(), sysClkDisable(), sysClkRateSet()*/void sysClkEnable (void)    {	 UINT32 tc;	 FAST int locKey;	 volatile unsigned dummy;    	if (!sysClkRunning)	{	 /* Lock Interrupts */   	locKey = intLock();    /* Set up timer - divide clock input by 1, enable timer */	IXP2400_REG_WRITE(IXP2400_TIMER2_CONTROL, IXP2400_TIMER_ACTIVATE);			/*	 * Calculate the timer value	 * Note that it may take some ticks to reload the counter	 * so counter value = (clock rate / sysClkTicksPerSecond) - num_ticks	 */	#ifdef RELOAD_TICKS     tc = (SYS_TIMER_CLK/sysClkTicksPerSecond) - IXP2400_RELOAD_TICKS;#else     tc = (SYS_TIMER_CLK/sysClkTicksPerSecond);#endif#ifdef INCLUDE_TIMESTAMP	sysClkPeriod = (SYS_TIMER_CLK / sysClkTicksPerSecond);#endif	/* Load Timer Reload value into Timer registers */ 	IXP2400_REG_WRITE (IXP2400_TIMER2_LOAD, tc);	/* read back to make sure that write is completed */	IXP2400_REG_READ(IXP2400_TIMER2_LOAD, dummy);	 /* UnLock Interrupts */	intUnlock (locKey);				/* enable clock interrupt in interrupt controller */	intEnable(SYS_TIMER_INT_LVL);		sysClkRunning = TRUE;	}    }/********************************************************************************* sysClkRateGet - get the system clock rate** This routine returns the system clock rate.** RETURNS: The number of ticks per second of the system clock.** SEE ALSO: sysClkEnable(), sysClkRateSet()*/int sysClkRateGet (void)    {    	return (sysClkTicksPerSecond);    }/********************************************************************************* sysClkRateSet - set the system clock rate** This routine sets the interrupt rate of the system clock.* It is called by usrRoot() in usrConfig.c.** RETURNS: OK, or ERROR if the tick rate is invalid or the timer cannot be set.** SEE ALSO: sysClkEnable(), sysClkRateGet()*/STATUS sysClkRateSet    (    int ticksPerSecond	    /* number of clock interrupts per second */    )    {   	if (ticksPerSecond < SYS_CLK_RATE_MIN || ticksPerSecond > SYS_CLK_RATE_MAX)		return (ERROR);   	sysClkTicksPerSecond = ticksPerSecond;   	if (sysClkRunning)	{		sysClkDisable ();		sysClkEnable ();	}    	return (OK);    }/********************************************************************************* sysAuxClkInt - handle an auxiliary clock interrupt** This routine handles an auxiliary clock interrupt.  It acknowledges the* interrupt and calls the routine installed by sysAuxClkConnect().** RETURNS: N/A*/void sysAuxClkInt (void)    {	volatile unsigned dummy;     /* acknowledge the interrupt if needed */	IXP2400_REG_WRITE(IXP2400_TIMER3_COUNTER_CLR,0x01);	/* read back to make sure that write is completed */	IXP2400_REG_READ(IXP2400_TIMER3_COUNTER_CLR, dummy);    /* call auxiliary clock service routine */    if ((sysAuxClkRoutine != NULL) && sysAuxClkRunning)		(*sysAuxClkRoutine) (sysAuxClkArg);    }/********************************************************************************* sysAuxClkConnect - connect a routine to the auxiliary clock interrupt** This routine specifies the interrupt service routine to be called at each* auxiliary clock interrupt.  It does not enable auxiliary clock interrupts.** RETURNS: OK, or ERROR if the routine cannot be connected to the interrupt.** SEE ALSO: intConnect(), sysAuxClkEnable()*/

⌨️ 快捷键说明

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