📄 pcctimer.c
字号:
/* pccTimer.c - PCC Timer library *//* Copyright 1984-1996 Wind River Systems, Inc. */#include "copyright_wrs.h"/*modification history--------------------01i,22jul96,dat merged with timestamp driver.01h,06jun96,wlf doc: cleanup.01g,16apr94,dzb changed the file name from pccTimer.c to pccTimerTS.c01f,07apr94,dzb optimized timestamp routines.01e,10jan94,dzb added conditional compilation for INCLUDE_TIMESTAMP macro.01d,17sep93,dzb added timestamp support.01c,07jul92,ccc changed genericTimer.h to timerDev.h.01b,26jun92,ccc changed include to genericTimer.h.01a,10jun92,ccc created by moving routines from sysLib.c of mv147, ansified.*//*DESCRIPTIONThis library contains routines to manipulate the timer functions on thePCC chip with a board-independent interface. This library handles boththe system clock and the auxiliary clock functions.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. When the timestamp timer is running, tick timer #2 is reset everysystem clock interrupt in an effort to control time skew. Note that changingthe system clock rate will affect the timestamp timer period, which can beread by calling sysTimestampPeriod().NOTE: the auxiliary clock and timestamp timer share the same physical timer(tick timer #2). Only one of these facilities may used at a time. Theapplicable disable routine (sysAuxClkDisable() or sysTimestampDisable())can be used to relinquish control of tick timer #2, and the other facilitymay then be enabled. If either clock is active, attempting to activatethe other clock will fail.*/#include "drv/timer/timerDev.h"#include "drv/timer/timestampDev.h"/* Locals */#define TICK_FREQ 160000LOCAL int sysClkTicksPerSecond = 60;LOCAL BOOL sysClkRunning = FALSE;LOCAL FUNCPTR sysClkRoutine = NULL;LOCAL int sysClkArg = NULL;LOCAL BOOL sysClkConnected = FALSE;LOCAL int auxClkTicksPerSecond = 60;LOCAL BOOL sysAuxClkRunning = FALSE;LOCAL FUNCPTR sysAuxClkRoutine = NULL;LOCAL int sysAuxClkArg = NULL;LOCAL BOOL auxClkConnected = FALSE;LOCAL BOOL sysTimestampRunning = FALSE; /* running flag *//********************************************************************************* sysClkInt - handle system clock interrupts** This routine handles system clock interrupts.*/LOCAL void sysClkInt (void) { /* reset clock interrupt */ /* clear overflow counter, enable & start counter */ *TIC_1_CSR = TIC_1_CSR_CLR_OVF | TIC_1_CSR_ENABLE; *TIC_1_INT_CTL = INT_LVL_TIC_1 | TIC_1_INT_CTL_CLEAR | TIC_1_INT_CTL_ENABLE; /* reset & enable int, set level */#ifdef INCLUDE_TIMESTAMP if (sysTimestampRunning) /* sync up timestamp timer */ sysTimestampEnable ();#endif /* INCLUDE_TIMESTAMP */ 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 called at each system clock interrupt */ int arg /* argument with which to call routine */ ) { sysHwInit2 (); /* XXX for now -- needs to be in usrConfig.c */ sysClkConnected = TRUE; 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 interrupts */ *TIC_1_INT_CTL = TIC_1_INT_CTL_DISABLE; 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) { /* preload the preload register */ *TIC_1_PRELOAD = (short) (65536 - (TICK_FREQ / sysClkTicksPerSecond)); /* enable the clock interrupt. */ *TIC_1_CSR = TIC_1_CSR_STOP; /* load counter from preload register */ /* clear overflow counter, enable & start counter */ *TIC_1_CSR = TIC_1_CSR_CLR_OVF | TIC_1_CSR_ENABLE; *TIC_1_INT_CTL = TIC_1_INT_CTL_CLEAR | TIC_1_INT_CTL_ENABLE | INT_LVL_TIC_1; /* reset&enable int, set level */ 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 auxiliary clock interrupts*/LOCAL void sysAuxClkInt (void) { /* reset clock interrupt */ /* clear overflow counter, enable & start counter */ *TIC_2_CSR = TIC_2_CSR_CLR_OVF | TIC_2_CSR_ENABLE; *TIC_2_INT_CTL = TIC_2_INT_CTL_CLEAR | TIC_2_INT_CTL_ENABLE | INT_LVL_TIC_2; /* reset & enable int, set level */ 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 */ ) { auxClkConnected = TRUE; sysAuxClkRoutine = routine; sysAuxClkArg = arg; return (OK); }/********************************************************************************* sysAuxClkDisable - turn off auxiliary clock interrupts** This routine disables auxiliary clock interrupts.** RETURNS: N/A** SEE ALSO: sysAuxClkEnable()*/void sysAuxClkDisable (void) { if ((sysAuxClkRunning) && (!sysTimestampRunning)) { /* clear overflow counter & stop counter */ *TIC_2_CSR = TIC_2_CSR_CLR_OVF | TIC_2_CSR_STOP; /* reset & disable int, set level */ *TIC_2_INT_CTL = TIC_2_INT_CTL_CLEAR | TIC_2_INT_CTL_DISABLE; sysAuxClkRunning = FALSE;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -