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

📄 dga001timer.c

📁 IXP425的BSP代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/* dga001Timer.c - DGA-001 Timer library *//* Copyright 1994-1998 Wind River Systems, Inc. */#include "copyright_wrs.h"/*modification history--------------------01o,23apr98,hk   added tkt's counter glitch filter to sysTimestamp{Lock}.01n,09dec97,hk   changed TICK_FREQ to DGA_TICK_FREQ. added sys{Aux}ClkDisable()                 in sys{Aux}ClkConnect(). reviewed timestamp driver code.01m,12jul97,hk   changed inclusion of multi/dga001.h to timer/dga001Timer.h.01l,06may97,hk   added TSTAMP_USE_DGA001_TT1. added default TIMESTAMP_LEVEL.01k,04may97,hk   merged in timestamp driver.01f,18apr97,st   moved initialization of Timerstamp-Timer in                 sysTimestampConnect() to sysTimestampEnable().01i,06mar97,st   added support for timestamp function for windview01h,10nov95,hk   followed dga001.h-01j macro name changes.01g,09nov95,hk   added more type casting. followed dga001.h 01i.01f,08nov95,hk   changed dga001.h directory to drv/multi/.01e,08jun95,hk   changed sysClkInt/sysAuxClkInt for CSR20 header mod.01d,06jun95,hk   renamed timer select macros.01c,28feb95,hk   changed sysClkConnect() and sysAuxClkConnect() to conform the		 corrected IV_ defines in ivSh.h-01e. copyright 1995.01b,09nov94,sa   fixed.01a,08nov94,sa   derived from 01f of sh7604Timer.c.*//*DESCRIPTIONThis library contains routines to manipulate the timer functions on theDGA-001 chip with a board-independant interface.  This library handles boththe system clock, auxiliary clock, and timestamp timer facilities.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.To include the timestamp timer facility, the macro INCLUDE_TIMESTAMP must bedefined.  The macro TIMESTAMP_LEVEL must be defined to provide the timestamptimer's interrupt level.*/#include "drv/timer/timerDev.h"#include "drv/timer/timestampDev.h"#include "drv/timer/dga001Timer.h"#include "config.h"/* Locals */ #define DGA_TICK_FREQ	1000000			/* 1MHz */#ifdef	SYSCLK_USE_DGA001_TT0LOCAL int     sysClkTicksPerSecond = 60; LOCAL BOOL    sysClkRunning        = FALSE; LOCAL FUNCPTR sysClkRoutine        = NULL; LOCAL int     sysClkArg            = NULL; LOCAL BOOL    sysClkConnected      = FALSE; #endif#ifdef	AUXCLK_USE_DGA001_TT1LOCAL int     auxClkTicksPerSecond = 60; LOCAL BOOL    sysAuxClkRunning     = FALSE; LOCAL FUNCPTR sysAuxClkRoutine     = NULL; LOCAL int     sysAuxClkArg         = NULL;LOCAL BOOL    auxClkConnected      = FALSE; #endif#if defined(INCLUDE_TIMESTAMP) && defined(TSTAMP_USE_DGA001_TT1)LOCAL BOOL    sysTimestampRunning  = FALSE;	/* running flag */LOCAL FUNCPTR sysTimestampRoutine  = NULL;	/* user rollover routine */LOCAL int     sysTimestampArg      = NULL;	/* arg to user routine */#ifndef	TIMESTAMP_LEVEL#error TIMESTAMP_LEVEL is not defined#endif /* ! TIMESTAMP_LEVEL */#endif /* INCLUDE_TIMESTAMP && TSTAMP_USE_DGA001_TT1 */#ifdef	SYSCLK_USE_DGA001_TT0/********************************************************************************* sysClkInt - handle system clock interrupts** This routine handles system clock interrupts.*/LOCAL void sysClkInt (void)    {    if ( !(*DGA_CSR20 & CSR20_TT0IRQ))	return;    if (sysClkRoutine != NULL)	(*sysClkRoutine) (sysClkArg);    *DGA_CSR23 = (UINT32)CSR23_TT0ICL;		/* clear interrupt */    }/********************************************************************************* 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 called at each system clock interrupt */    int arg             /* argument with which to call routine           */    )    {    sysHwInit2 ();      /* XXX for now -- needs to be in usrConfig.c */    sysClkDisable ();    if (intConnect (INT_VEC_TT0, sysClkInt, NULL) != OK)	return (ERROR);    sysClkConnected = TRUE;    sysClkRoutine   = routine;    sysClkArg       = arg;    return (OK);    }/********************************************************************************* sysClkDisable - turn off system clock interrupts** This routine disables system clock interrupts.** RETURNS: N/A** SEE ALSO: sysClkEnable()*/ void sysClkDisable (void)    {    if (sysClkRunning)	{	*DGA_CSR21 &= (UINT32) ~CSR21_TT0IEN;	/* disable interrupt */	*DGA_CSR12 &= (UINT32) ~CSR12_TT0CEN;	/* stop timer */	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)    {    if (!sysClkRunning)	{	*DGA_CSR12  = (UINT32) NULL;		/* stop timer */	*DGA_CSR13  = (UINT32) NULL;		/* clear count */	*DGA_CSR23  = (UINT32) CSR23_TT0ICL;	/* clear interrupt */	*DGA_CSR21 |= (UINT32) CSR21_TT0IEN;	/* enable interrupt */	/* load compare register with the number of micro seconds and          * start the counter.	 */	*DGA_CSR12 = (UINT32)((DGA_TICK_FREQ / sysClkTicksPerSecond - 1) | 				CSR12_TT0CEN);	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);    }#endif	/* SYSCLK_USE_DGA001_TT0 */#ifdef	AUXCLK_USE_DGA001_TT1/********************************************************************************* sysAuxClkInt - handle auxiliary clock interrupts*/ LOCAL void sysAuxClkInt (void)    {    if ( !(*DGA_CSR20 & CSR20_TT1IRQ))	return;    if (sysAuxClkRoutine != NULL)	(*sysAuxClkRoutine) (sysAuxClkArg);    *DGA_CSR23 = (UINT32)CSR23_TT1ICL;		/* reset clock interrupt */    }/********************************************************************************* 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()*/ STATUS sysAuxClkConnect    (    FUNCPTR routine,    /* routine called at each aux clock interrupt    */    int arg             /* argument to auxiliary clock interrupt routine */    )    {    sysAuxClkDisable ();    if (intConnect (INT_VEC_TT1, sysAuxClkInt, NULL) != OK)	return (ERROR);    auxClkConnected  = TRUE;    sysAuxClkRoutine = routine;    sysAuxClkArg     = arg;     return (OK);    }/********************************************************************************* sysAuxClkDisable - turn off auxiliary clock interrupts** This routine disables auxiliary clock interrupts.** RETURNS: N/A** SEE ALSO: sysAuxClkEnable()*/ void sysAuxClkDisable (void)    {    if (sysAuxClkRunning)	{	*DGA_CSR21 &= (UINT32) ~CSR21_TT1IEN;	/* disable interrupt */	*DGA_CSR14 &= (UINT32) ~CSR14_TT1CEN;	/* stop timer */	sysAuxClkRunning = FALSE;	}    }/********************************************************************************

⌨️ 快捷键说明

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