?? m5200slicetimer.c
字號:
/* m5200SliceTimer.c - MPC5200 Slice Timer library *//* Copyright 1984-2003 Wind River Systems, Inc. *//*modification history--------------------01b,24sep03,pdr fixed bugs, merge changes for SLT0.01a,15sep03,pdr written.*//*DESCRIPTIONThis driver provides the auxilliary clock support.The auxiliary clock will use the Slice Timer of the MPC5200.By the default the slice timer 1 is used for the auxiliary clock.If the slice timer 0 has to be used for the auxiliary clock(not recommended), then the macro AUX_CLOCK_SLT0 need to be definedand the macro USE_CRITICAL_INTERRUPTS need to be set to 1.The macros AUX_CLK_RATE_MIN, and AUX_CLK_RATE_MAX must be definedto provide parameter checking for the sysAuxClkRateSet() routines.INCLUDES:timestampDev.h, m5200SliceTimer.h*//* includes */#include "vxWorks.h"#include "config.h"#include "drv/timer/timerDev.h"#include "drv/timer/timestampDev.h"#include "drv/timer/m5200SliceTimer.h"/* defines *//* locals */LOCAL FUNCPTR sysAuxClkRoutine = NULL;LOCAL int sysAuxClkArg = 0;LOCAL BOOL sysAuxClkRunning = FALSE;LOCAL int sysAuxClkTicksPerSecond = 100;/********************************************************************************* 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) {#if defined(AUX_CLOCK_SLT0) && USE_CRITICAL_INTERRUPT /* Reset Slice Timer 0 Status Bit */ *SLT0_STATUS = SLT_STATUS_RESET; m5200IntAck(INUM_SLT0);#else /* Reset Slice Timer 1 Status Bit */ *SLT1_STATUS = SLT_STATUS_RESET; /* acknowledge the interrupt */#endif /* AUX_CLOCK_SLT0 */ /* 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()*/void sysAuxClkDisable (void) { if (sysAuxClkRunning) {#if defined(AUX_CLOCK_SLT0) && USE_CRITICAL_INTERRUPT /* Reset Slice Timer 0 */ *SLT0_CTRL = 0;#else /* Reset Slice Timer 1 */ *SLT1_CTRL = 0; intDisable(INUM_SLT1);#endif /* AUX_CLOCK_SLT0 */ sysAuxClkRunning = FALSE; } }/********************************************************************************* sysAuxClkEnable - turn on auxiliary clock interrupts** This routine enables auxiliary clock interrupts.** RETURNS: N/A** SEE ALSO: sysAuxClkConnect(), sysAuxClkDisable(), sysAuxClkRateSet()*/void sysAuxClkEnable (void) { static BOOL connected = FALSE; UINT32 countValue; if (!connected) {#if defined(AUX_CLOCK_SLT0) && USE_CRITICAL_INTERRUPT intConnect(IV_SLT0, (VOIDFUNCPTR) sysAuxClkInt, 0);#else intConnect(IV_SLT1, (VOIDFUNCPTR) sysAuxClkInt, 0);#endif /* AUX_CLOCK_SLT0 */ connected = TRUE; } if (!sysAuxClkRunning) { countValue = IPB_CLOCK / sysAuxClkTicksPerSecond;#if defined(AUX_CLOCK_SLT0) && USE_CRITICAL_INTERRUPT /* Reset Slice Timer 0 */ *SLT0_CTRL = 0; /* Reset Slice Timer 0 Status Bit */ *SLT0_STATUS = SLT_STATUS_RESET; /* Load Counter Value */ *SLT0_TCNT = (countValue & 0x00FFFFFF); /* Start Slice Timer 0 (Set Timer Enable Bit) */ *SLT0_CTRL = (SLT_CTRL_ENABLE|SLT_CTRL_INT_ENABLE); intEnable(INUM_SLT0);#else /* Reset Slice Timer 1 */ *SLT1_CTRL = 0; /* Reset Slice Timer 1 Status Bit */ *SLT1_STATUS = SLT_STATUS_RESET; /* Load Counter Value */ *SLT1_TCNT = (countValue & 0x00FFFFFF); /* Start Slice Timer 1 (Set Timer Enable Bit) */ *SLT1_CTRL = (SLT_CTRL_ENABLE|SLT_CTRL_INT_ENABLE|SLT_CTRL_RUN_WAIT); intEnable(INUM_SLT1);#endif /* AUX_CLOCK_SLT0 */ sysAuxClkRunning = TRUE; } }/********************************************************************************* sysAuxClkRateGet - get the auxiliary clock rate** This routine returns the interrupt rate of the auxiliary clock.** RETURNS: The number of ticks per second of the auxiliary clock.** SEE ALSO: sysAuxClkEnable(), sysAuxClkRateSet()*/int sysAuxClkRateGet (void) { return (sysAuxClkTicksPerSecond); }/********************************************************************************* sysAuxClkRateSet - set the auxiliary clock rate** This routine sets the interrupt rate of the auxiliary clock. It does not* enable auxiliary clock interrupts.** RETURNS: OK, or ERROR if the tick rate is invalid or the timer cannot be set.** SEE ALSO: sysAuxClkEnable(), sysAuxClkRateGet()*/STATUS sysAuxClkRateSet ( int ticksPerSecond /* number of clock interrupts per second */ ) { if (ticksPerSecond < AUX_CLK_RATE_MIN || ticksPerSecond > AUX_CLK_RATE_MAX) { return (ERROR); } sysAuxClkTicksPerSecond = ticksPerSecond; if (sysAuxClkRunning) { sysAuxClkDisable (); sysAuxClkEnable (); } return (OK); }
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -