📄 ppc405timer.c
字号:
/* ppc405Timer.c - PowerPC 405 timer library *//******************************************************************************* This source and object code has been made available to you by IBM on an AS-IS basis. IT IS PROVIDED WITHOUT WARRANTY OF ANY KIND, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE OR OF NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO EVENT SHALL IBM OR ITS LICENSORS BE LIABLE FOR INCIDENTAL, CONSEQUENTIAL OR PUNITIVE DAMAGES. IBMS OR ITS LICENSORS DAMAGES FOR ANY CAUSE OF ACTION, WHETHER IN CONTRACT OR IN TORT, AT LAW OR AT EQUITY, SHALL BE LIMITED TO A MAXIMUM OF $1,000 PER LICENSE. No license under IBM patents or patent applications is to be implied by the copyright license. Any user of this software should understand that neither IBM nor its licensors will be responsible for any consequences resulting from the use of this software. Any person who transfers this source code or any derivative work must include the IBM copyright notice, this paragraph, and the preceding two paragraphs in the transferred software. Any person who transfers this object code or any derivative work must include the IBM copyright notice in the transferred software. COPYRIGHT I B M CORPORATION 2000 LICENSED MATERIAL - PROGRAM PROPERTY OF I B M"*******************************************************************************//* Copyright 1984-2002 Wind River Systems, Inc. *//*modification history--------------------01h,12jul02,pch SPR 77082: fix compiler warning re unused fitTable[] and fitPeriodMask[]01g,19apr02,gjc Fixing sysAuxClkSetRate algorithm.01f,19nov01,g_h Add #ifdef INCLUDE_AUX_CLK to isolate the AUX clock01e,06dec01,kab Update for T2.2; fix compiler warnings01d,19sep01,pch SPR 20698, 69142, 69143: TSR is write-to-clear, not read/modify/writeback01c,29nov00,s_m changes from ibm01b,23mar00,mcg removed manual PIT reload in sysClkInt01a,20sep99,mcg created from ppc403Timer.c version 01n*//*DESCRIPTIONThis library provides PowerPC 405 Timer routines. This library handlesthe system clock, the auxiliary clock and timestamp functions. Toinclude the timestamp timer facility, the macro INCLUDE_TIMESTAMP mustbe defined.The macro SYS_CLK_FREQ should be defined before usingthis module. This macro is the rate at which clock ticks occur. Fordouble clocked busses, this value should be half the actual clock speed.The macros SYS_CLK_RATE_MIN, SYS_CLK_RATE_MAX, AUX_CLK_RATE_MIN,and AUX_CLK_RATE_MAX must be defined to provideparameter checking for sysClkRateSet().The BSP is responsible for connecting the interrupt handlers, sysClkInt(),and sysAuxClkInt(), to the appropriate vectors.INCLUDE FILES: ppc403Timer.hSEE ALSO:.pG "Configuration"*//* includes */#include "vxWorks.h"#include "vxLib.h"#include "intLib.h"#include "drv/timer/ppc403Timer.h"#include "drv/timer/timestampDev.h"/* local defines *//* Auxiliary clock default rate */#ifndef AUX_CLK_RATE_DEFAULT# define AUX_CLK_RATE_DEFAULT 10#endif/* extern declarations *//* Locals */#ifdef INCLUDE_AUX_CLKLOCAL FIT_PERIOD fitTable[] = /* available FIT periods */ { { (1 << 9), 0x00000000}, { (1 << 13), 0x01000000}, { (1 << 17), 0x02000000}, { (1 << 21), 0x03000000}, };#endif /* INCLUDE_AUX_CLK */LOCAL WDT_PERIOD wdtTable[] = /* available WDT periods */ { { (1 << 17), 0x00000000}, { (1 << 21), 0x40000000}, { (1 << 25), 0x80000000}, { (1 << 29), 0xC0000000}, };LOCAL int sysClkTicksPerSecond = 60; /* default 60 ticks/second */LOCAL FUNCPTR sysClkRoutine = NULL;LOCAL int sysClkArg = 0;LOCAL BOOL sysClkConnectFirstTime = TRUE;LOCAL BOOL sysClkRunning = FALSE;#ifdef INCLUDE_AUX_CLKLOCAL int sysAuxClkTicksPerSecond = AUX_CLK_RATE_DEFAULT;LOCAL FUNCPTR sysAuxClkRoutine = NULL;LOCAL int sysAuxClkArg = 0;LOCAL BOOL sysAuxClkRunning = FALSE;#endif /* INCLUDE_AUX_CLK */LOCAL int sysWdtTicksPerSecond = 1;LOCAL FUNCPTR sysWdtRoutine = NULL;LOCAL int sysWdtArg = 0;LOCAL BOOL sysWdtRunning = FALSE;LOCAL UINT32 pitCountVal; /* PIT counter value */#ifdef INCLUDE_AUX_CLKLOCAL UINT32 fitPeriodMask = 0x01000000; /* default FIT period: 2^21 */#endif /* INCLUDE_AUX_CLK */LOCAL UINT32 wdtPeriodMask = 0xC0000000; /* default WDT period: 2^29 */#ifdef INCLUDE_TIMESTAMPLOCAL BOOL sysTimestampRunning = FALSE; /* timestamp running flag */#endif /* INCLUDE_TIMESTAMP *//************************************************************************* sysClkInt - clock interrupt handler** This routine handles the clock interrupt on the PowerPC 405 architecture. It* is attached to the Programmable Interval Timer vector by the routine* sysClkConnect().** RETURNS : N/A*/LOCAL void sysClkInt (void) { /* Acknowledge PIT interrupt */ vxPitIntAck (); /* The PIT reloads itself automatically */ /* Execute the system clock routine */ if (sysClkRoutine != NULL) (*(FUNCPTR) 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. It also connects the* clock error interrupt service routine.** RETURNS: OK, or ERROR if the routine cannot be connected to the interrupt.** SEE ALSO: usrClock(), sysClkEnable()*/STATUS sysClkConnect ( FUNCPTR routine, /* routine to connect */ int arg /* argument with which to call the routine */ ) { if (sysClkConnectFirstTime) { sysHwInit2(); sysClkConnectFirstTime = FALSE; } sysClkRoutine = routine; sysClkArg = arg; return (OK); }/************************************************************************* 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) { /* clear the pending PIT interrupt */ vxTsrSet (_PPC403_TSR_PIS); /* load the PIT counter and the hidden register with interval value */ vxPitSet (pitCountVal); /* Enable the PIT interrupt & enable autoreload */ vxTcrSet (vxTcrGet() | _PPC403_TCR_PIE | _PPC403_TCR_ARE); /* set the running flag */ sysClkRunning = TRUE; } }/************************************************************************* sysClkDisable - turn off system clock interrupts** This routine disables system clock interrupts.** RETURNS: N/A** SEE ALSO: sysClkEnable()*/void sysClkDisable (void) { if (sysClkRunning) { /* disable the PIT interrupt and auto-reload capability */ vxTcrSet (vxTcrGet() & ~ (_PPC403_TCR_PIE | _PPC403_TCR_ARE)); /* clear the PIT counter */ vxPitSet (0); /* clear the pending PIT interrupt */ vxTsrSet (_PPC403_TSR_PIS); /* reset the running flag */ sysClkRunning = FALSE; } }/************************************************************************* 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 does not* enable system clock interrupts. 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); /* save the clock speed */ sysClkTicksPerSecond = ticksPerSecond; /* * compute the value to load in the decrementor. The new value will be * load in the decrementor after the end of the current period */ pitCountVal = sysTimerClkFreq / ticksPerSecond; /* Update the PIT interval FIX 11/27/00 */ vxPitSet (pitCountVal); return (OK); }#ifdef INCLUDE_AUX_CLK/************************************************************************* sysAuxClkInt - auxilary clock interrupt handler** This routine handles the auxilary clock interrupt on the PowerPC 405* architecture. It is attached to the Fix Interval Timer vector by the routine* sysAuxClkConnect().** RETURNS : N/A*/LOCAL void sysAuxClkInt (void) { vxFitIntAck (); /* acknowledge FIT interrupt */ /* program TCR with the FIT period */ vxTcrSet ((vxTcrGet() & ~_PPC403_TCR_FP) | fitPeriodMask); /* execute the system clock routine */ if (sysAuxClkRoutine != NULL) (*(FUNCPTR) 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: excIntConnectTimer(), sysAuxClkEnable()*/STATUS sysAuxClkConnect ( FUNCPTR routine, /* routine called at each aux. clock interrupt */ int arg /* argument to auxiliary clock interrupt */ ) { sysAuxClkRoutine = routine; sysAuxClkArg = arg; return (OK); }/************************************************************************* sysAuxClkEnable - turn on auxiliary clock interrupts** This routine enables auxiliary clock interrupts.** RETURNS: N/A** SEE ALSO: sysAuxClkConnect(), sysAuxClkDisable(), sysAuxClkRateSet()*/void sysAuxClkEnable (void) { if (!sysAuxClkRunning) { /* clear the pending FIT interrupt */ vxTsrSet (_PPC403_TSR_FIS); /* program TCR with the FIT period */ vxTcrSet ((vxTcrGet() & ~_PPC403_TCR_FP) | fitPeriodMask); /* Enable the FIT interrupt */ vxTcrSet (vxTcrGet() | _PPC403_TCR_FIE); /* set the running flag */ sysAuxClkRunning = TRUE; } }/************************************************************************* sysAuxClkDisable - turn off auxiliary clock interrupts** This routine disables auxiliary clock interrupts.*** RETURNS: N/A** SEE ALSO: sysAuxClkEnable()*/void sysAuxClkDisable (void) { if (sysAuxClkRunning) { /* disable the FIT interrupt */ vxTcrSet (vxTcrGet() & ~ (_PPC403_TCR_FIE)); /* clear the pending FIT interrupt */ vxTsrSet (_PPC403_TSR_FIS); /* reset the running flag */ sysAuxClkRunning = FALSE; } }/************************************************************************* sysAuxClkRateGet - get the auxiliary clock rate
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -