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

📄 z8536timer.c

📁 IXP425的BSP代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/* z8536Timer.c - Z8536 timer library *//* Copyright 1984-1996 Wind River Systems, Inc. */#include "copyright_wrs.h"/*modification history--------------------01i,20dec96,dat  fixed SPR 4274, sysTimestampLock, didn't do a lock.01h,23sep96,dat  merged with timestamp driver.01g,11jul96,wlf  doc: cleanup.01f,06jun96,wlf  doc: cleanup.01e,09aug95,kkk  fixed I960 warnings. (spr# 4177)01d,06jan93,dzb  removed sysClk1Int().01c,07dec92,ccc  added sysCioReset() routine to reset specified device.01b,20oct92,ccc  added volatile to register pointer.01a,28aug92,caf  moved clock routines from ver.01p of hkv30/sysLib.c, ansified.*//*DESCRIPTIONThis library contains routines to manipulate the timer functions on theZilog Z8536.  This library handles both the system clock and the auxiliaryclock functions.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.The macros ZCIO_CNTRL_ADRS and ZCIO_HZ must also be defined to indicate thecontrol register address and clock frequency of the Z8536, respectively.The system clock is the ZCIO counter/timer 3.The auxiliary clock is the ZCIO counter/timer 2.The timestamp clock is the ZCIO counter/timer 1.SEE ALSO.I "ZCIO Counter/Timer and Parallel I/O Unit Technical Manual"*//* includes */#include "drv/timer/timestampDev.h"/* locals */LOCAL FUNCPTR sysClkRoutine           = NULL;LOCAL int     sysClkArg               = NULL;LOCAL int     sysClkTicksPerSecond    = 60;LOCAL BOOL    sysClkConnected         = FALSE;LOCAL int     sysClkRunning           = FALSE;LOCAL FUNCPTR sysAuxClkRoutine        = NULL;LOCAL int     sysAuxClkArg            = NULL;LOCAL int     sysAuxClkTicksPerSecond = 60;LOCAL BOOL    sysAuxClkConnected      = FALSE;LOCAL int     sysAuxClkRunning        = FALSE;#ifdef INCLUDE_TIMESTAMP#define ZCIO_MAX_TIME_CNST		0x10000LOCAL	void	sysTimestampInt (void);LOCAL	FUNCPTR	sysTimestampRoutine     = NULL;LOCAL	int	sysTimestampArg         = NULL;LOCAL	BOOL	sysTimestampConnected   = FALSE;LOCAL	int	sysTimestampRunning     = FALSE;#endif /*INCLUDE_TIMESTAMP*/     /******************************************************************************** sysCioReset - z8536 reset** This routine resets the specified z8536.** NOMANUAL*/void sysCioReset    (    volatile UINT8 *pCio		/* cio to reset */    )    {    volatile UINT8 temp;    int delay;    temp  = *pCio;			/* see CIO manual sec 2.3 */    *pCio = ZERO;    temp  = *pCio;    *pCio = ZCIO_MCC;			/* master config control */    *pCio = ZERO;    *pCio = ZCIO_MIC;			/* master interrupt control */    *pCio = ZCIO_MIC_RESET;		/* device RESET */    for (delay = 0; delay < 1000; delay++)	;				/* allow reset to complete */    *pCio = ZCIO_MIC;    *pCio = ZERO;    }/********************************************************************************* 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.  It also connects the clock* error interrupt service routine.** RETURNS: 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 */    sysClkRoutine	= routine;    sysClkArg		= arg;    sysClkConnected	= TRUE;    return (OK);    }/********************************************************************************* sysClkInt - handle a system clock interrupt** This routine handles a system clock interrupt.  It acknowledges the* interrupt and calls the routine installed by sysClkConnect().*/LOCAL void sysClkInt (void)    {    /* acknowledge the interrupt */    *ZCIO_CNTRL_ADRS = ZCIO_CT3CS;		/* C/T 3 Command and Status */    *ZCIO_CNTRL_ADRS = ZCIO_CS_CLIPIUS |	/* Clear IP and IUS */		       ZCIO_CS_GCB;		/* Gate Command Bit */    if (sysClkRoutine != NULL)	(*sysClkRoutine) (sysClkArg);	/* call system clock service routine */    }/********************************************************************************* sysClkDisable - turn off system clock interrupts** This routine disables system clock interrupts.** RETURNS: N/A** SEE ALSO: sysClkEnable()*/void sysClkDisable (void)    {    if (sysClkRunning)        {	/* disable interrupts */	*ZCIO_CNTRL_ADRS = ZCIO_CT3CS;	/* C/T 3 Command and Status */	*ZCIO_CNTRL_ADRS = ZCIO_CS_CLIE;	/* Clear Interrupt Enable */	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)    {    volatile UINT8 *cioCtl;    ULONG  tc;    /* time constant */    if (!sysClkRunning)	{	cioCtl = ZCIO_CNTRL_ADRS;	/* set time constant */	tc = ZCIO_HZ / sysClkTicksPerSecond;	*cioCtl = ZCIO_CT3TCMSB;             /* C/T 3 Time Const (MS Byte) */	*cioCtl = (UINT8) MSB(tc);	*cioCtl = ZCIO_CT3TCLSB;             /* C/T 3 Time Const (LS Byte) */	*cioCtl = (UINT8) LSB(tc);	/* clear and start timer */	*cioCtl = ZCIO_CT3CS;                /* C/T 3 Command and Status */	*cioCtl = ZCIO_CS_CLIPIUS;           /* Clear IP and IUS */	*cioCtl = ZCIO_CT3CS;                /* C/T 3 Command and Status */	*cioCtl = ZCIO_CS_SIE                /* Set Interrupt Enable */		| ZCIO_CS_GCB                /* Gate Command Bit */		| ZCIO_CS_TCB;               /* Trigger Command Bit */	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.** NOTE: The valid range for the system clock is 38 to 10000* ticks per second.** 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);    }/********************************************************************************* 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 with which to call routine        */    )    {    sysAuxClkRoutine	= routine;    sysAuxClkArg	= arg;    sysAuxClkConnected	= TRUE;    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*/LOCAL void sysAuxClkInt (void)    {    /* acknowledge the interrupt */    *ZCIO_CNTRL_ADRS = ZCIO_CT2CS;          /* C/T 2 Command and Status */    *ZCIO_CNTRL_ADRS = ZCIO_CS_CLIPIUS      /* Clear IP and IUS */			  | ZCIO_CS_GCB;         /* Gate Command Bit */    /* call auxiliary clock service routine */    if (sysAuxClkRoutine != NULL)	(*sysAuxClkRoutine) (sysAuxClkArg);    }/********************************************************************************* sysAuxClkDisable - turn off auxiliary clock interrupts** This routine disables auxiliary clock interrupts.** RETURNS: N/A** SEE ALSO: sysAuxClkEnable()*/void sysAuxClkDisable (void)    {    if (sysAuxClkRunning)        {	/* disable interrupts */	*ZCIO_CNTRL_ADRS = ZCIO_CT2CS;	/* C/T 2 Command and Status */	*ZCIO_CNTRL_ADRS = ZCIO_CS_CLIE;   /* Clear Interrupt Enable */	sysAuxClkRunning = FALSE;        }    }/********************************************************************************* sysAuxClkEnable - turn on auxiliary clock interrupts** This routine enables auxiliary clock interrupts.** RETURNS: N/A** SEE ALSO: sysAuxClkDisable()*/void sysAuxClkEnable (void)    {    volatile UINT8 *cioCtl;

⌨️ 快捷键说明

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