m5200slicetimer.c

来自「MPC5200 BSP 支持ATA,USB, I2C,扩展网口」· C语言 代码 · 共 412 行

C
412
字号
/* m5200SliceTimer.c - MPC5200 Slice Timer library *//* Copyright 1984-2003 Wind River Systems, Inc. *//*modification history--------------------01b,24sep03,pdr  fixed bugs, merge changes for SLT0.01a,15sep03,pdr  written.*//*DESCRIPTIONThis driver provides the auxilliary clock support.The auxiliary clock will use the Slice Timer of the MPC5200.By the default the slice timer 1 is used for the auxiliary clock.If the slice timer 0 has to be used for the auxiliary clock(not recommended), then the macro AUX_CLOCK_SLT0 need to be definedand the macro USE_CRITICAL_INTERRUPTS need to be set to 1.The macros AUX_CLK_RATE_MIN, and AUX_CLK_RATE_MAX must be definedto provide parameter checking for the sysAuxClkRateSet() routines.INCLUDES:timestampDev.h, m5200SliceTimer.h*//* includes */#include "vxWorks.h"#include "config.h"#include "drv/timer/timerDev.h"#include "drv/timer/timestampDev.h"#include "drv/timer/m5200SliceTimer.h"/* defines *//* locals */LOCAL FUNCPTR sysAuxClkRoutine	  = NULL;LOCAL int sysAuxClkArg		      = 0;LOCAL BOOL sysAuxClkRunning	      = FALSE;LOCAL int sysAuxClkTicksPerSecond = 100;#if 0LOCAL FUNCPTR sysClkRoutine	  = NULL;LOCAL int sysClkArg		      = 0;LOCAL BOOL sysClkRunning	      = FALSE;LOCAL int sysClkTicksPerSecond = 60;LOCAL BOOL	sysClkConnectFirstTime	= TRUE;#endif/********************************************************************************* 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)    {#if defined(AUX_CLOCK_SLT0) && USE_CRITICAL_INTERRUPT	/* Reset Slice Timer 0 Status Bit */	*SLT0_STATUS = SLT_STATUS_RESET;	m5200IntAck(INUM_SLT0);#else	/* Reset Slice Timer 1 Status Bit */	*SLT1_STATUS = SLT_STATUS_RESET;	/* acknowledge the interrupt */#endif /* AUX_CLOCK_SLT0 */    /* call auxiliary clock service routine */	if (sysAuxClkRoutine != NULL)		{		(*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()*/STATUS sysAuxClkConnect    (    FUNCPTR routine,    /* routine called at each aux clock interrupt */    int arg             /* argument to auxiliary clock interrupt routine */    )    {    sysAuxClkRoutine = NULL;    sysAuxClkArg	 = arg;    sysAuxClkRoutine = routine;    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)        {#if defined(AUX_CLOCK_SLT0) && USE_CRITICAL_INTERRUPT		/* Reset Slice Timer 0 */		*SLT0_CTRL = 0;#else		/* Reset Slice Timer 1 */		*SLT1_CTRL = 0;				intDisable(INUM_SLT1);#endif /* AUX_CLOCK_SLT0 */		sysAuxClkRunning = FALSE;        }    }/********************************************************************************* sysAuxClkEnable - turn on auxiliary clock interrupts** This routine enables auxiliary clock interrupts.** RETURNS: N/A** SEE ALSO: sysAuxClkConnect(), sysAuxClkDisable(), sysAuxClkRateSet()*/void sysAuxClkEnable (void)    {    static BOOL connected = FALSE;	UINT32		countValue;    if (!connected)		{#if defined(AUX_CLOCK_SLT0) && USE_CRITICAL_INTERRUPT		intConnect(IV_SLT0, (VOIDFUNCPTR) sysAuxClkInt, 0);#else		intConnect(IV_SLT1, (VOIDFUNCPTR) sysAuxClkInt, 0);#endif /* AUX_CLOCK_SLT0 */		connected = TRUE;		}    if (!sysAuxClkRunning)        {		countValue = IPB_CLOCK / sysAuxClkTicksPerSecond;#if defined(AUX_CLOCK_SLT0) && USE_CRITICAL_INTERRUPT		/* Reset Slice Timer 0 */		*SLT0_CTRL = 0;		/* Reset Slice Timer 0 Status Bit */		*SLT0_STATUS = SLT_STATUS_RESET;	   		/* Load Counter Value */		*SLT0_TCNT = (countValue & 0x00FFFFFF);    			/* Start Slice Timer 0 (Set Timer Enable Bit) */		*SLT0_CTRL = (SLT_CTRL_ENABLE|SLT_CTRL_INT_ENABLE);		intEnable(INUM_SLT0);#else		/* Reset Slice Timer 1 */		*SLT1_CTRL = 0;		/* Reset Slice Timer 1 Status Bit */		*SLT1_STATUS = SLT_STATUS_RESET;	   		/* Load Counter Value */		*SLT1_TCNT = (countValue & 0x00FFFFFF);    			/* Start Slice Timer 1 (Set Timer Enable Bit) */		*SLT1_CTRL = (SLT_CTRL_ENABLE|SLT_CTRL_INT_ENABLE|SLT_CTRL_RUN_WAIT);		intEnable(INUM_SLT1);#endif /* AUX_CLOCK_SLT0 */		sysAuxClkRunning = TRUE;				}    }/********************************************************************************* sysAuxClkRateGet - get the auxiliary clock rate** This routine returns the interrupt rate of the auxiliary clock.** RETURNS: The number of ticks per second of the auxiliary clock.** SEE ALSO: sysAuxClkEnable(), sysAuxClkRateSet()*/int sysAuxClkRateGet (void)    {    return (sysAuxClkTicksPerSecond);    }/********************************************************************************* sysAuxClkRateSet - set the auxiliary clock rate** This routine sets the interrupt rate of the auxiliary clock.  It does not* enable auxiliary clock interrupts.** RETURNS: OK, or ERROR if the tick rate is invalid or the timer cannot be set.** SEE ALSO: sysAuxClkEnable(), sysAuxClkRateGet()*/STATUS sysAuxClkRateSet    (    int ticksPerSecond  /* number of clock interrupts per second */    )    {    if (ticksPerSecond < AUX_CLK_RATE_MIN || ticksPerSecond > AUX_CLK_RATE_MAX)		{        return (ERROR);		}	sysAuxClkTicksPerSecond = ticksPerSecond;	if (sysAuxClkRunning)		{		sysAuxClkDisable ();		sysAuxClkEnable ();		}    return (OK);    }  #if 0/********************************************************************************* sysClkInt - clock interrupt handler** This routine handles the clock interrupt on the PowerPC architecture. It is* attached to the decrementer vector by the routine sysClkConnect().** RETURNS : N/A*/LOCAL void sysClkInt (void)    {	/* Reset Slice Timer 0 Status Bit */	*SLT0_STATUS = SLT_STATUS_RESET;	m5200IntAck(INUM_SLT0);  /* call system clock service routine */		if (sysClkRunning && (sysClkRoutine != NULL))	(*(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.** RETURNS: OK, or ERROR if the routine cannot be connected to the interrupt.** SEE ALSO: intConnect(), usrClock(), sysClkEnable()*/    STATUS sysClkConnect    (    FUNCPTR 	routine,	/* routine to connect */    int 	arg		/* argument for the routine */    )    {    if (sysClkConnectFirstTime)		{		sysHwInit2();		sysClkConnectFirstTime = FALSE;		}		sysClkRoutine = NULL;    sysClkRoutine	= routine;    sysClkArg		= arg;    return (OK);    }/******************************************************************************** sysClkEnable - turn on system clock interrupts** This routine enables system clock interrupts.** RETURNS: N/A** SEE ALSO: sysClkConnect(), sysClkDisable(), sysClkRateSet()*/void sysClkEnable (void)    {    static BOOL connected = FALSE;		UINT32		countValue;    if (!connected)		{		intConnect(IV_SLT0, (VOIDFUNCPTR) sysClkInt, 0);		connected = TRUE;		}    if (!sysClkRunning)    {		countValue = IPB_CLOCK / sysClkTicksPerSecond;		/* Reset Slice Timer 0 */		*SLT0_CTRL = 0;		/* Reset Slice Timer 0 Status Bit */		*SLT0_STATUS = SLT_STATUS_RESET;	   		/* Load Counter Value */		*SLT0_TCNT = (countValue & 0x00FFFFFF);    			/* Start Slice Timer 0 (Set Timer Enable Bit) */		*SLT0_CTRL = (SLT_CTRL_ENABLE|SLT_CTRL_INT_ENABLE);		intEnable(INUM_SLT0);		sysClkRunning = TRUE;				}    }/******************************************************************************** sysClkDisable - turn off system clock interrupts** This routine disables system clock interrupts.** RETURNS: N/A** SEE ALSO: sysClkEnable()*/void sysClkDisable (void)    {    if (sysClkRunning)    {		/* Reset Slice Timer 0 */		*SLT0_CTRL = 0;   	intDisable(INUM_SLT0);		sysAuxClkRunning = FALSE;    }    }/******************************************************************************** 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);    /* save the clock speed */    sysClkTicksPerSecond = ticksPerSecond;		if (sysClkRunning)		{		sysClkDisable ();		sysClkEnable ();		}    return (OK);    }#endif

⌨️ 快捷键说明

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