?? s3c2510timer.c
字號:
/* s3c2510Timer.c - SAMSUNG S3C2500 timer driver */
/* Copyright 2002 SAMSUNG ELECTRONICS */
/*
modification history
--------------------
01a,08feb02,jmLee created.
*/
#include "vxWorks.h"
#include "intLib.h"
#include "errno.h"
#include "drv/timer/timerDev.h"
#include "drv/timer/timestampDev.h"
#include "drv/multi/s3c2510.h"
#include "config.h"
#include "drv/intrCtl/s3c2510Intr.h"
#include "drv/timer/s3c2510Timer.h"
/* Local forward declarations */
LOCAL BOOL sysClkConnectFirstTime = TRUE;
LOCAL FUNCPTR sysClkRoutine = NULL;
LOCAL int sysClkArg = 0;
LOCAL int sysClkRunning = FALSE;
LOCAL int sysClkTicksPerSecond = DEF_SYS_CLK_TICKS;
LOCAL BOOL sysAuxClkConnectFirstTime = TRUE;
LOCAL FUNCPTR sysAuxClkRoutine = NULL;
LOCAL int sysAuxClkArg = 0;
LOCAL int sysAuxClkRunning = FALSE;
LOCAL int sysAuxClkTicksPerSecond = DEF_SYS_AUX_CLK_TICKS;
#ifdef INCLUDE_TIMESTAMP
LOCAL BOOL sysTimestampConnectFirstTime = TRUE;
LOCAL FUNCPTR sysTimestampRoutine = NULL;
LOCAL int sysTimestampArg = 0;
LOCAL BOOL sysTimestampRunning = FALSE;
#endif /* INCLUDE_TIMESTAMP */
/*******************************************************************************
*
* sysClkInt - clock interrupt handler
*
* This routine handles the clock interrupt on the S3C9500 architecture. It is
* attached to the TIMER5 vector by the routine sysClkConnect().
*
* RETURNS : N/A
*/
LOCAL void sysClkInt(void)
{
/* Clear interrupt. */
*S3C2510_TIC |= S3C2510_TIC_T5;
#ifdef INCLUDE_LED
{
static int count = 0;
if (!(count % (sysClkRateGet() / 2)))
{
if (!(count % sysClkRateGet()))
{
LED_ON(LED1_MASK);
}
else
{
LED_OFF(LED1_MASK);
}
}
if (!(count % (sysClkRateGet() / 10)))
{
LED_OFF(LED6_MASK | LED7_MASK | LED8_MASK);
}
count++;
}
#endif /* INCLUDE_LED */
/* Call system clock service routine. */
if (sysClkRoutine && sysClkRunning)
{
(*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 called at each clock interrupt */
int arg /* argument to clock interrupt routine */
)
{
if (sysClkConnectFirstTime)
{
sysHwInit2();
/* Enable peripheral clock. */
*S3C2510_PCLKDIS &= ~S3C2510_PCLKDIS_TIMER5;
/* Interval mode. */
*S3C2510_TMOD &= ~S3C2510_TMOD_TMD5;
/* Connect and enable interrupt. */
intConnect(INT_VEC_TIMER5, (VOIDFUNCPTR)sysClkInt, 0);
intEnable(INT_LVL_TIMER5);
sysClkConnectFirstTime = FALSE;
}
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)
{
/* Disable timer. */
*S3C2510_TMOD &= ~S3C2510_TMOD_TE5;
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)
{
/* Calculate the timer interval. */
*S3C2510_TDATA5 = SPLL_FREQ * 1000 * 1000 / sysClkTicksPerSecond - 1;
/* Enable timer. */
*S3C2510_TMOD |= S3C2510_TMOD_TE5;
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();
}
LED_ON(LED8_MASK);
return OK;
}
/*******************************************************************************
*
* sysAuxClkInt - auxiliary clock interrupt handler
*
* This routine handles the auxiliary clock interrupton the S3C9500 architecture.
* It is attached to the TIMER5 vector by the routine sysAuxClkConnect().
*
* RETURNS : N/A
*/
LOCAL void sysAuxClkInt(void)
{
/* Clear interrupt. */
*S3C2510_TIC |= S3C2510_TIC_T4;
/* Call auxiliary clock service routine. */
if (sysAuxClkRoutine && 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()
*/
STATUS sysAuxClkConnect(
FUNCPTR routine, /* routine called at each auxiliary clock interrupt */
int arg /* argument to auxiliary clock interrupt routine */
)
{
if (sysAuxClkConnectFirstTime)
{
/* Enable peripheral clock. */
*S3C2510_PCLKDIS &= ~S3C2510_PCLKDIS_TIMER4;
/* Interval mode. */
*S3C2510_TMOD &= ~S3C2510_TMOD_TMD4;
/* Connect and enable interrupt. */
intConnect(INT_VEC_TIMER4, (VOIDFUNCPTR)sysAuxClkInt, 0);
intEnable(INT_LVL_TIMER4);
sysAuxClkConnectFirstTime = FALSE;
}
sysAuxClkRoutine = routine;
sysAuxClkArg = arg;
return OK;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -