📄 s3c2410timer.c
字号:
/* s3c2410Timer.c - Samsung S3C2410 timer library *//* Copyright 1984-2001 Wind River Systems, Inc. */#include "copyright_wrs.h"/*modification history--------------------*//* includes */#include "vxWorks.h"#include "config.h"#include "drv/timer/timerDev.h"#include "drv/timer/timestampDev.h"#include "s3c2410Timer.h"/* defines *//* The default is to assume memory mapped I/O */#ifndef SNGKS32C_TIMER_REG_READ#define SNGKS32C_TIMER_REG_READ(reg, result) \ ((result) = *(volatile UINT32 *)(reg))#endif /*SNGKS32C_TIMER_READ*/#ifndef SNGKS32C_TIMER_REG_WRITE#define SNGKS32C_TIMER_REG_WRITE(reg, data) \ (*((volatile UINT32 *)(reg)) = (data))#endif /*SNGKS32C_TIMER_WRITE*/#ifndef SNGKS32C_TIMER_INT_ENABLE#define SNGKS32C_TIMER_INT_ENABLE(level) intEnable(level)#endif#ifndef SNGKS32C_TIMER_INT_DISABLE#define SNGKS32C_TIMER_INT_DISABLE(level) intDisable(level)#endif/* locals */LOCAL FUNCPTR sysClkRoutine = NULL; /* routine to call on clock tick */LOCAL int sysClkArg = (int)NULL; /* its argument */LOCAL int sysClkRunning = FALSE;LOCAL int sysClkConnected = FALSE;LOCAL int sysClkTicksPerSecond = 60;LOCAL FUNCPTR sysAuxClkRoutine = NULL;LOCAL int sysAuxClkArg = (int)NULL;LOCAL int sysAuxClkRunning = FALSE;LOCAL int sysAuxClkTicksPerSecond = 100;LOCAL int sysAuxClkTicks;#ifdef INCLUDE_TIMESTAMPLOCAL BOOL sysTimestampRunning = FALSE; /* running flag */LOCAL FUNCPTR sysTimestampRoutine = NULL; /* routine to call on intr */LOCAL int sysTimestampArg = 0; /* arg for routine */ void sysTimestampInt (void); /* forward declaration */#endif /* INCLUDE_TIMESTAMP *//* Lizm FIXED for s3c2410 */#define rTCFG0 (0x51000000)#define rTCFG1 (0x51000004)#define rTCON (0x51000008) #define rTCNTB0 (0x5100000C)#define rTCMPB0 (0x51000010)#define rTCNTO0 (0x51000014) #define rTCNTB1 (0x51000018)#define rTCMPB1 (0x5100001C)#define rTCNTO1 (0x51000020) #define rTCNTB2 (0x51000024)#define rTCMPB2 (0x51000028)#define rTCNTO2 (0x5100002C) #define rTCNTB3 (0x51000030)#define rTCMPB3 (0x51000034)#define rTCNTO3 (0x51000038) #define rTCNTB4 (0x5100003C)#define rTCNTO4 (0x51000040)/********************************************************************************* sysClkInt - interrupt level processing for system clock** This routine handles a 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 */ ) { if (sysClkConnected == FALSE) { /* set up timers for intrerval mode, don't enable yet */ SNGKS32C_TIMER_REG_WRITE (rTCON, 0x0); sysHwInit2 (); sysClkConnected = TRUE; } sysClkRoutine = NULL; sysClkArg = arg;#if ((CPU_FAMILY == ARM) && ARM_THUMB) /* set b0 so that sysClkConnect() can be used from shell */ sysClkRoutine = (FUNCPTR)((UINT32)routine | 1);#else sysClkRoutine = routine;#endif /* CPU_FAMILY == ARM */ 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) { SNGKS32C_TIMER_REG_READ (rTCON, oier); SNGKS32C_TIMER_REG_WRITE (rTCON, oier & ~(0x00000001)); /* disable timer interrupt in the interrupt controller, Timer 0 */ SNGKS32C_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; if (!sysClkRunning) { /* * 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 thats OK. */ /* FCLK=200.8M, PCLK = 50.2M */ /*prescaler value for Timer 0 and 1 = 100*/ SNGKS32C_TIMER_REG_READ (rTCFG0, oier); SNGKS32C_TIMER_REG_WRITE(rTCFG0, (oier & 0xFFFFFF00) | 0x0063); /*Select MUX input for PWM Timer0 and Timer 1 = 1/4 */ SNGKS32C_TIMER_REG_READ (rTCFG1, oier); SNGKS32C_TIMER_REG_WRITE (rTCFG1, (oier & 0xFFFFFF00) | 0x0011); SNGKS32C_TIMER_REG_WRITE (rTCNTB0,((125*1000)/sysClkTicksPerSecond)); /* set T0 count, xxx*/ SNGKS32C_TIMER_REG_READ (rTCON, oier); SNGKS32C_TIMER_REG_WRITE (rTCON, ((oier&0xFFFFFFF0)|0x0002)); /*update T0*/ SNGKS32C_TIMER_REG_WRITE (rTCON, ((oier&0xFFFFFFF0)|0x0009)); /*T0,auto reload and start*/ /* enable clock interrupt in interrupt controller */ SNGKS32C_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 ( FUNCPTR routine, /* routine called at each aux clock interrupt */ int arg /* argument to auxiliary clock interrupt routine */ ) { sysAuxClkRoutine = NULL; sysAuxClkArg = arg;#if ((CPU_FAMILY == ARM) && ARM_THUMB) /* set b0 so that sysClkConnect() can be used from shell */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -