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

📄 sndstimer.c

📁 三星官方基于VXWORKS的S3C2510的BSP
💻 C
📖 第 1 页 / 共 2 页
字号:
/* sndsTimer.c - Samsung SNDS100 timer library */

/*
modification history
--------------------
01b,27sep99.nb  added timestamp support and documentation	
01a,21aug99.knp  snds specific timer, adapted from WRS template
*/

/*

DESCRIPTION
Samsung's SNDS100 Ver 1.0 board is an evaluation board for their KS32C50100
microprocessor.  This is an ARM based processor with several integrated peripherals.
It has an interrupt controller, two 32-bit timers, one Ethernet controller,
two HDLC controllers, one IIC controller, general purpose I/O ports, and a 
2-channel DMA controller.

The 32-bit timers can be programmed in interval mode or toggle mode.  In
interval mode, an output pulse is generated when the countdown value in
the count register reaches  zero.  This will generate a pule frequency of
(SYSCLK/count).  On the other hand, in the toggle mode, the output toggles
its state for each time the countdown value reaches zero.  In this case, the
output frequency will be (SYSCLK/(2*count)).

The Timer Data register is used to load the countdown value.  When the timer
is enabled using the Timer Mode register, the Timer Count register is loaded
with the count in Timer Data register.  The count value is decremented for every
internal clock edge.  Once the count becomes zero, an interrupt is generated
(if enabled in the interrupt controller) and the Timer Count register is
reloaded automatically.

The internal timer registers are accessed in a straight-forward fashion.
They are accessible as 32-bit integers from the internal system register
offsets, as given in sndstimer.h file.  The macros SNDS_TIMER_REG_WRITE
and SNDS_TIMER_REG_READ does nothing but reading and writing 32-bit
integers from and to the given addresses.

This driver provides 3 main functions, system clock support, auxilliary
clock support, and timestamp timer support.  If necessary, each function
may be conditioned by a separate INCLUDE_ macro.  The timestamp function
is always conditional upon the INCLUDE_TIMESTAMP macro.

The SNDS100 timer register definitions are given in sndstimer.h file.

The macros SYS_CLK_RATE_MIN, SYS_CLK_RATE_MAX, AUX_CLK_RATE_MIN, and
AUX_CLK_RATE_MAX must be defined in snds100.h to provide parameter checking 
for the sys[Aux]ClkRateSet() routines.

INCLUDES:
sndstimer.h
timestampDev.h
*/

/* includes */

#include "vxWorks.h"
#include "config.h"
#include "drv/timer/timerDev.h"
#include "drv/timer/timestampDev.h"
#include "sndsTimer.h"

/* defines */

/* The default is to assume memory mapped I/O */

#ifndef SNDS_TIMER_REG_READ
#define SNDS_TIMER_REG_READ(reg, result) \
	((result) = *(volatile UINT32 *)(reg))
#endif /*SNDS_TIMER_READ*/

#ifndef SNDS_TIMER_REG_WRITE
#define SNDS_TIMER_REG_WRITE(reg, data) \
	(*((volatile UINT32 *)(reg)) = (data))
#endif /*SNDS_TIMER_WRITE*/

#ifndef SNDS_TIMER_INT_ENABLE
#define SNDS_TIMER_INT_ENABLE(level) intEnable(level)
#endif

#ifndef SNDS_TIMER_INT_DISABLE
#define SNDS_TIMER_INT_DISABLE(level) intDisable(level)
#endif


/* locals */

LOCAL FUNCPTR sysClkRoutine	= NULL; /* routine to call on clock tick */
LOCAL int sysClkArg		= NULL; /* its argument */
LOCAL int sysClkRunning		= FALSE;
LOCAL int sysClkTicksPerSecond	= 60;

LOCAL FUNCPTR sysAuxClkRoutine	= NULL;
LOCAL int sysAuxClkArg		= NULL;
LOCAL int sysAuxClkRunning	= FALSE;
LOCAL int sysAuxClkTicksPerSecond = 100;
LOCAL int sysAuxClkTicks;

#ifdef INCLUDE_TIMESTAMP

LOCAL BOOL	sysTimestampRunning	= FALSE; /* running flag */
LOCAL int	sysTimestampPeriodValue	= NULL;  /* Max counter value */
LOCAL FUNCPTR	sysTimestampRoutine	= NULL;  /* routine to call on intr */
LOCAL int	sysTimestampArg		= 0;     /* arg for routine */
      void	sysTimestampInt (void);		 /* forward declaration */

#endif  /* INCLUDE_TIMESTAMP */


/*******************************************************************************
*
* sysClkInt - interrupt level processing for system clock
*
* This routine handles an system clock interrupt.  It acknowledges the
* interrupt and calls the routine installed by sysClkConnect().
*/

void sysClkInt (void)
    {

	/* call system clock service routine */

	if (sysClkRoutine != NULL)
		(* 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 */
    )
    {
    static BOOL beenHere = FALSE;

    if (!beenHere)
	{
	beenHere = TRUE;
	sysHwInit2 ();
	}

    sysClkRoutine   = NULL;
    sysClkArg	    = arg;
    sysClkRoutine   = routine;

    return (OK);
    }


/*******************************************************************************
*
* sysClkDisable - turn off system clock interrupts
*
* This routine disables system clock interrupts.
*
* RETURNS: N/A
*
* SEE ALSO: sysClkEnable()
*/

void sysClkDisable (void)
    {

    int oier;
    
    if (sysClkRunning)
	{
		
	SNDS_TIMER_REG_READ (SNDS_TIMER_TMOD, oier);
        SNDS_TIMER_REG_WRITE (SNDS_TIMER_TMOD, oier & ~(1));
	
	/* disable timer interrupt in the interrupt controller */
	
	SNDS_TIMER_INT_DISABLE (SYS_TIMER_INT_LVL);

	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 oier;
    int sysClkTicks;

    if (!sysClkRunning)
	{
	/*

	 * Calculate the number of ticks of the timer clock that this
	 * period requires.  Do this once, here, so that the timer interrupt
	 * routine does not need to perform a division.
	 */
	sysClkTicks = (SYS_TIMER_CLK / sysClkTicksPerSecond);

	/*
	 * Load the match register with a new value calculated by
	 * adding the ticks per interrupt to the current value of the
	 * counter register.  Note that this may wraparound to a value
	 * less than the current counter value but that's OK.
	 */

	SNDS_TIMER_REG_WRITE (SNDS_TIMER_TDATA_0, sysClkTicks);

	SNDS_TIMER_REG_READ (SNDS_TIMER_TMOD,oier);
	SNDS_TIMER_REG_WRITE (SNDS_TIMER_TMOD, oier|1);

	/* enable clock interrupt in interrupt controller */

	SNDS_TIMER_INT_ENABLE (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)
    {
    /* 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

⌨️ 快捷键说明

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