📄 sh7615timer.c
字号:
/* sh7615Timer.c - template timer library *//* Copyright 1984-2001 Wind River Systems, Inc. *//*modification history--------------------01g,21feb02,h_k fixed timestamp interrupt enable (SPR #73506). removed sysTimestampPeriodValue to avoid compile warning.01f,02nov01,zl corrected NULL usage.01e,06oct00,zl corrected vectors for AUX and timestamp drivers.01d,16sep00,zl timestamp to use maximum period.01c,30aug00,zl fixed INTC_IPRD modification.01b,20aug00,csi added AUX clock and timestamp.01a,11aug00,zl written.*//*DESCRIPTIONThis library contains routines to manipulate the timer functions on theSH7615 on-chip timer unit (TPU) with a board-independant interface.This library handles the system clock, auxiliary clock, and timestamptimer facilities.The macros SYS_CLK_RATE_MIN, SYS_CLK_RATE_MAX, AUX_CLK_RATE_MIN, andAUX_CLK_RATE_MAX must be defined to provide parameter checking for thesys[Aux]ClkRateSet() routines.To include the timestamp timer facility, the macro INCLUDE_TIMESTAMP must bedefined. The macro TIMESTAMP_LEVEL must be defined to provide the timestamptimer's interrupt level.INCLUDES:timestampDev.h*//* includes */#include "vxWorks.h"#include "config.h"#include "drv/timer/timerDev.h"#include "drv/timer/timestampDev.h"/* select tick frequency */#define TICK_FREQ (SYS_PCLK_FREQ / 64)#define TCR_DIVIDE TCR_DIV64/* The default is to assume memory mapped I/O */#ifndef SH7615TPU_READ#define SH7615TPU_READ(reg, result) \ ((result) = *(reg))#endif /* SH7615TPU_READ */#ifndef SH7615TPU_WRITE#define SH7615TPU_WRITE(reg, data) \ (*(reg) = (data))#endif /* SH7615TPU_WRITE */#ifndef SH7615TPU_SET#define SH7615TPU_SET(reg, data) \ (*(reg) |= (data))#endif /* SH7615TPU_SET */#ifndef SH7615TPU_CLEAR#define SH7615TPU_CLEAR(reg, data) \ (*(reg) &= ~(data))#endif /* SH7615TPU_CLEAR *//* locals */LOCAL FUNCPTR sysClkRoutine = NULL; /* routine to call on clock tick */LOCAL int sysClkArg = 0; /* its argument */LOCAL int sysClkRunning = FALSE;LOCAL int sysClkTicksPerSecond = 60;LOCAL FUNCPTR sysAuxClkRoutine = NULL;LOCAL int sysAuxClkArg = 0;LOCAL int sysAuxClkRunning = FALSE;LOCAL int sysAuxClkTicksPerSecond = 100;#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 an auxiliary clock interrupt. It acknowledges the* interrupt and calls the routine installed by sysClkConnect().*/void sysClkInt (void) { UINT8 value; if (SH7615TPU_READ (TPU_TSR0, value), (value & TSR_TGFA) == TSR_TGFA) { /* clear the interrupt */ SH7615TPU_WRITE (TPU_TSR0, (value & ~TSR_TGFA)); /* 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 (); /* XXX for now -- needs to be in usrConfig.c */ } 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) { if (sysClkRunning) { /* disable system timer interrupts */ SH7615TPU_WRITE (TPU_TIER0, 0); 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) { static BOOL connected = FALSE; if (!connected) { UINT16 tmp; /* Disable interrupt and clear the status register */ SH7615TPU_WRITE (TPU_TIER0, 0); SH7615TPU_READ (TPU_TSR0, tmp); SH7615TPU_WRITE (TPU_TSR0, 0); /* connect handler */ intConnect(IV_TPU_TGI0A, sysClkInt, 0); /* Set system clock interrupt priority */ SH7615TPU_READ (INTC_IPRD, tmp); SH7615TPU_WRITE (INTC_IPRD, (tmp & 0x0fff) | (INT_LVL_SYSCLK << 12)); sysClkRunning = FALSE; connected = TRUE; } if (!sysClkRunning) { /* select counter at F/64 , clear with TGRA */ SH7615TPU_WRITE (TPU_TCR0, TCR_DIVIDE | TCR_TGRA); /* set period */ SH7615TPU_WRITE (TPU_TGR0A, (TICK_FREQ / sysClkTicksPerSecond)); /* Reset counter */ SH7615TPU_WRITE (TPU_TCNT0, 0); /* enable interrupt */ SH7615TPU_WRITE (TPU_TIER0, TIER_TGIEA); /* start counter */ SH7615TPU_SET (TPU_TSTR, TSTR_CST0); 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) { UINT8 value; /* acknowledge the interrupt if needed */ if (SH7615TPU_READ (TPU_TSR1, value), (value & TSR_TGFA) == TSR_TGFA) { /* clear the interrupt */ SH7615TPU_WRITE (TPU_TSR1, (value & ~TSR_TGFA)); /* 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()*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -