📄 ixp425timer.c
字号:
/* ixp425Timer.c - ixp425 processor timer library *//* Copyright 2002 Wind River Systems, Inc. */#include "copyright_wrs.h"/*modification history--------------------01d,28jul03,m_h initialize sysAuxClk to standard values01c,09jul03,m_h multiple callouts from auxClk01b,05dec02,jb Fixed timestamp and aux clock01a,05jun02,jb initial version...*//*DESCRIPTIONThis library contains routines to manipulate the timer functions. _________ _________ __________hardware GP TIMER0 GP TIMER1 Time-Stampclock _________ _________ __________ | | |interface - ------------- - | | | | | | | |software _______ _________ ________ ____________clock(s) sysClk sysAuxClk ixpAuxClk timeStampClk ------- --------- --------- ------------interface functions:clkInt() - clock interrupt handlerclkConnect() - connect a routine to the clock interruptclkDisable() - turn off system clock interruptsclkEnable() - turn on system clock interruptsclkRateGet() - get the system clock rate oscillations per secondclkPeriod() - get the period of the timer (tick counter rollover)clkFreq() - get a timer clock frequencyclkTimestamp() - get a tick counter countNote: There are two different types of ticks referred to. The frequencytick and the counter tick. A frequency tick refers to the timer clockoscillations per second and the counter ticks refer to the number of times(ticks) a register decreases until roll over.The macros SYS_CLK_RATE_MIN, SYS_CLK_RATE_MAX must be defined toprovide parameter checking for the sysClkRateSet() routine.Note: The auxClk code is somewhat non-standard because the second timeris shared between two auxClk sub-systems. sysAuxClk functionality is availableto the user as specified my the vxWorks guidelines. Mimicking the sysAuxClk,there is an ixp BSP specific auxClk set of functions with the prefix ixpAuxClk.Because these two subsystems share a clock a restriction has been made suchthat one clock frequency must be a multiple of the other frequency. If thisrestriction is violated, the functions sysAuxClkRateSet() andixpAuxClkRateSet() will return ERROR.ixpAuxClk routines are used for ethernet polling in ixEthAccSysEnd.c. Temporary ethernet problems may occur as sysAuxClk frequencies are changedso care should be used if sysAuxClk functions are called at times otherthan during initial startup initialization.The auxClk layer that actually accesses hardware (e.g. enables interrupts andsets the reload register) has the prefix "ixeSysAuxClk". These functionsshould not be called by application code.*/#include "ixp425.h"#include "ixp425Timer.h"#include "drv/timer/timerDev.h"#ifdef INCLUDE_TIMESTAMP#include "drv/timer/timestampDev.h"#endif#ifdef INCLUDE_WINDVIEW/* Wind view event logging */#include "wvLib.h"/* Event definitions for Windview */#define IXP425TIMER_EVT_AUXINTERRUPT 2000#define IXP425TIMER_EVT_SYSAUXCLKROUTINE 2001#define IXP425TIMER_EVT_IXPAUXCLKROUTINE 2002static UINT32 cts = 0; /* Current Timestamp */static UINT32 lcts = 0; /* Last Timestamp */static UINT32 dcts = 0; /* Difference */#define WV_EVENT(evt) { \ cts = *((volatile int *)IXP425_OSTS); \ dcts = cts - lcts; \ lcts = cts; \ wvEvent(evt,(char *)&cts,4); \ }#else#define WV_EVENT(evt)#endif /* INCLUDE_WINDVIEW *//* * The APB timer block is not based on the CPU speed, but on * the APB core clock of 66Mhz. */#define TIMER_APB_CLOCK_MHZ ( IXP425_PERIPHERAL_BUS_CLOCK )/* hardware access methods */#ifndef IXP425_REG_TIMER_READ#define IXP425_REG_TIMER_READ(reg,result) \ ((result) = *(volatile UINT32 *)(reg))#endif /*IXP425_REG_TIMER_READ*/#ifndef IXP425_REG_TIMER_WRITE#define IXP425_REG_TIMER_WRITE(reg,data) \ (*((volatile UINT32 *)(reg)) = (data))#endif /*IXP425_REG_TIMER_WRITE*//* Locals */LOCAL int clockTicksPerSecond = IXP425_OSST_TICKS_PER_SECOND;LOCAL UINT32 clockTimerRollOver = IXP425_OSST_ROLLOVER;LOCAL BOOL clockConnected = FALSE;LOCAL BOOL sysClkRunning = FALSE;LOCAL void sysClkDummyRoutine(int arg) {}LOCAL FUNCPTR sysClkRoutine = (FUNCPTR) sysClkDummyRoutine;LOCAL int sysClkArg = (int) NULL;LOCAL BOOL sysClkConnected = FALSE;LOCAL void sysAuxClkDummyRoutine(int arg) {}/* These variables implement the sysAuxClk interface * but are implemented as a layer on top of the ixpSysAuxClk functions */LOCAL BOOL sysAuxClkRunning = FALSE;LOCAL FUNCPTR sysAuxClkRoutine = (FUNCPTR)sysAuxClkDummyRoutine;LOCAL int sysAuxClkArg = (int) NULL;LOCAL BOOL sysAuxClkConnected = FALSE;LOCAL int sysAuxClkTicksPerSecond = 100;LOCAL int sysAuxClkTicksPerFuncCall = 1; /* interrupt count max */LOCAL int sysAuxClkTicksCount = 0; /* interrupt count *//* These variables are for BSP pseudo AuxClk functions */LOCAL BOOL ixpAuxClkRunning = FALSE;LOCAL FUNCPTR ixpAuxClkRoutine = (FUNCPTR)sysAuxClkDummyRoutine;LOCAL int ixpAuxClkArg = (int) NULL;LOCAL BOOL ixpAuxClkConnected = FALSE;LOCAL int ixpAuxClkTicksPerSecond = 0;LOCAL int ixpAuxClkTicksPerFuncCall = 0; /* interrupt count max */LOCAL int ixpAuxClkTicksCount = 0; /* interrupt count *//* These variables are for mess with the clock interrupts and dispatch callouts */LOCAL BOOL ixpSysAuxClkRunning = FALSE;LOCAL FUNCPTR ixpSysAuxClkRoutine = (FUNCPTR)sysAuxClkDummyRoutine;LOCAL int ixpSysAuxClkArg = (int) NULL;LOCAL BOOL ixpSysAuxClkConnected = FALSE;LOCAL int ixpSysAuxClkTicksPerSecond = 100;LOCAL int ixpSysAuxClkRollOver = ((TIMER_APB_CLOCK_MHZ * 0x100000) / 100);#ifdef INCLUDE_TIMESTAMPLOCAL BOOL sysTimestampRunning = FALSE;LOCAL FUNCPTR sysTimestampRoutine = (FUNCPTR) NULL;LOCAL int sysTimestampArg = (int) NULL;#endifLOCAL STATUS ixpSysAuxClkConnect(FUNCPTR routine, int arg);LOCAL void ixpSysAuxClkDisconnect (void);LOCAL void ixpSysAuxClkDisable (void);LOCAL void ixpSysAuxClkEnable (void);LOCAL int ixpSysAuxClkRateGet (void);LOCAL STATUS ixpSysAuxClkRateSet (void);LOCAL void clkInt (void){ /* Clear Pending Interrupt by writing '1' to it */ IXP425_REG_TIMER_WRITE(IXP425_OSST, IXP425_OSST_TIMER_1_PEND); if (sysClkRunning) (*(FUNCPTR) sysClkRoutine) (sysClkArg); /* The timer is free running and as such it has already reloaded * and is counting down */}/***************************************************************************** clkConnect - connect a routine to the clock interrupt** This routine specifies the interrupt service routine to be called at each* clock interrupt.** RETURN: OK** SEE ALSO: intConnect(), usrClock(), clkEnable()*/LOCAL STATUS clkConnect (void) { if(!clockConnected) { sysHwInit2 (); (void)intConnect ((void *)INT_VEC_TIMER1, clkInt, 0); clockConnected = TRUE; } return (OK); }/***************************************************************************** clkDisable - turn off system clock interrupts** This routine disables clock interrupts. In order for the hardware clock* to be disables all the software clocks must be disabled.** RETURNS: N/A** SEE ALSO: clkEnable()*/LOCAL void clkDisable (void) { intDisable(INT_VEC_TIMER1); /* Clear the OST register for this timer, This disabled the timer */ IXP425_REG_TIMER_WRITE( IXP425_OSRT1 , IXP425_OST_DISABLED ); }/***************************************************************************** clkEnable - turn on system clock interrupts** This routine enables system clock interrupts. Any software clock can* enable the hardware clock** RETURNS: N/A** SEE ALSO: sysClkDisable(), sysClkRateSet()*/LOCAL void clkEnable (void) { IXP425_REG_TIMER_WRITE( IXP425_OSRT1 , ((clockTimerRollOver & ~IXP425_OST_RELOAD_MASK) | IXP425_OST_ENABLE ) ); intEnable(INT_VEC_TIMER1); }/***************************************************************************** clkRateGet - get the system clock rate** This routine returns the oscillations clock rate.** RETURNS: The number of oscillations per second of the clock.** SEE ALSO: sysClkEnable(), sysClkRateSet()*/LOCAL int clkRateGet (void) { return (clockTicksPerSecond); }/**************************************************************************** clkPeriod - get the period of the tick counter** This routine gets the period of the timer, in ticks. The* period, or terminal count, is the number of ticks to which the tick* counter counts before rolling over and restarting the counting process.** RETURNS: The period of the timer in counter ticks.*/LOCAL UINT32 clkPeriod (void) { return (clockTimerRollOver); }/**************************************************************************** clkFreq - get a timer clock frequency** This routine gets the frequency of the timer clock, in ticks per* second. The rate of the timer is set explicitly by the* hardware and typically cannot be altered.** RETURNS: The timer clock frequency, in counter ticks per second.*/LOCAL UINT32 clkFreq (void) { return ( TIMER_APB_CLOCK_MHZ * 0x100000); }/**************************************************************************** clkTimestamp - get a time stamp count** This routine returns the current value of the timer tick counter.* The tick count can be converted to seconds by dividing it by the return of* clkFreq().*** RETURNS: The current time stamp count.** SEE ALSO: clkFreq()*/LOCAL UINT32 clkTimestamp (void) { UINT32 count; /* Read the free running up-timer from peripherial block */ IXP425_REG_TIMER_READ(IXP425_OSTS,count); return(count); } /***************************************************************************** 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** SEE ALSO: intConnect(), usrClock(), sysClkEnable()*/STATUS sysClkConnect ( FUNCPTR routine, /* routine called at each system clock interrupt */ int arg /* argument with which to call routine */ ) { sysClkConnected = TRUE; sysClkRoutine = routine; sysClkArg = arg; clkConnect(); 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) { clkDisable(); sysClkRunning = FALSE; } }/***************************************************************************** sysClkEnable - turn on system clock interrupts** This routine enables system clock interrupts.** RETURNS: N/A** SEE ALSO: sysClkDisable(), sysClkRateSet()*/void sysClkEnable (void) { if (!sysClkRunning) { clkEnable(); 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()
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -