📄 s3c44b0xtimer.c
字号:
/* s3c44b0xTimer.c - Samsung KS32C timer library *//* Copyright 1984-2001 Wind River Systems, Inc. */#include "copyright_wrs.h"/*modification history--------------------01a,12apr01,m_h created from snds100 template.*//*DESCRIPTION*//* includes */#include "vxWorks.h"#include "config.h"#include "drv/timer/timerDev.h"#include "drv/timer/timestampDev.h"#include "s3c44b0xTimer.h"/* defines *//* The default is to assume memory mapped I/O *//* 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 *//********************************************************************************* 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) { int buf; S3C44B0X_REG_READ32(S3C44B0X_TCON,buf); buf &= ~(0x07 << 24); S3C44B0X_REG_WRITE32(S3C44B0X_TCON,buf); S3C44B0X_REG_READ32(S3C44B0X_TCFG0,buf); buf = (buf & ~(0x0ff << 16)) | (PRESCALER2 << 16); S3C44B0X_REG_WRITE32(S3C44B0X_TCFG0,buf); S3C44B0X_REG_READ32(S3C44B0X_TCFG1,buf); buf = (buf & ~(0x0f << 20)) | (MUX5 << 20); S3C44B0X_REG_WRITE32(S3C44B0X_TCFG1,buf); 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) { if (sysClkRunning) { int buf; S3C44B0X_REG_READ32(S3C44B0X_TCON,buf); buf &= ~(0x07 << 24); S3C44B0X_REG_WRITE32(S3C44B0X_TCON,buf); /* disable timer interrupt in the interrupt controller */ intDisable (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) { 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. */ int buf; S3C44B0X_REG_WRITE32 (S3C44B0X_TCNTB5, COUNT / sysClkTicksPerSecond); S3C44B0X_REG_READ32 (S3C44B0X_TCON, buf); buf |= (0x06 << 24); S3C44B0X_REG_WRITE32 (S3C44B0X_TCON, buf); S3C44B0X_REG_READ32 (S3C44B0X_TCON, buf); buf |= (buf & ~(1 << 25)) | (1 << 24); S3C44B0X_REG_WRITE32 (S3C44B0X_TCON, buf); /* enable clock interrupt in interrupt controller */ intEnable (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 */ sysAuxClkRoutine = (FUNCPTR)((UINT32)routine | 1);#else sysAuxClkRoutine = routine;#endif /* CPU_FAMILY == ARM */ return (OK); }/********************************************************************************* sysAuxClkDisable - turn off auxiliary clock interrupts** This routine disables auxiliary clock interrupts.** RETURNS: N/A*
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -