📄 mpc107auxclk.c
字号:
/* mpc107AuxClk.c - MPC107 EPIC Timer (Aux Clk) library *//* Copyright 1999-2002 Wind River Systems, Inc. *//* Copyright 1999,2002 Motorola, Inc. All Rights Reserved */ /*modification history--------------------01b,15dec00,djs removed references to kahlua01a,02nov00,djs created from 01f,15jun00,dmw mv2100/kahluaAuxClk.c*/ /*DESCRIPTIONThis timer contains routines to use timer 0 on the EPIC as the auxiliaryclock.*//* includes */#include "lopec.h"/* defines */#define EPIC_TIMER_CNT (DEC_CLOCK_FREQ / 8)/* locals */LOCAL void sysAuxClkInt ();LOCAL STATUS sysAuxClkInit();LOCAL FUNCPTR sysAuxClkRoutine = NULL;LOCAL int sysAuxClkArg = 0;LOCAL int sysAuxClkTicksPerSecond = 60;LOCAL BOOL sysAuxClkConnected = FALSE;LOCAL int sysAuxClkRunning = FALSE;/* externals */IMPORT void sysPciOutLong (UINT32, UINT32);/******************************************************************************** sysAuxClkInt - handle an auxiliary clock interrupt from EPIC timer 0** This routine handles a EPIC timer 0 interrupt. It clears the interrupt* and calls the routine installed by sysAuxClkConnect().** RETURNS: N/A*/ LOCAL void sysAuxClkInt (void) { if (sysAuxClkRoutine != NULL) (*sysAuxClkRoutine) (sysAuxClkArg); } /******************************************************************************* sysAuxClkInit - MPC107 aux. clock initialization routine** This routine should be called before calling any other routine in this* module.** RETURNS: OK.*/ LOCAL STATUS sysAuxClkInit (void) { /* disable counter */ sysPciOutLong ((UINT32)EPIC_TIMER0_BASE_CT_REG, (0xffffffff) ); SYNC; /* synchronize */ /* setup timer frequency register */ sysPciOutLong ((UINT32)EPIC_TIMER_FREQ_REG, (UINT32)EPIC_TIMER_CNT); /* interrupt unmasked, priority level 15, vector TIMER0_INT_VEC. */ sysPciOutLong ((UINT32)EPIC_TIMER0_VEC_PRI_REG, (( EPIC_GTVP_PRI_15 | (TIMER0_INT_VEC) ) & ~EPIC_GTVP_M)); /* interrupt directed at processor 0 */ sysPciOutLong ((UINT32)EPIC_TIMER0_DEST_REG, EPIC_GTD_P0); SYNC; /* synchronize */ sysAuxClkRunning = FALSE; return (OK); }/******************************************************************************** sysAuxClkConnect - connect a routine to the auxiliary clock interrupt** This routine specifies the interrupt service routine to be called at each* auxiliary clock interrupt.** RETURNS: OK.** SEE ALSO: intConnect(), sysAuxClkEnable()*/ STATUS sysAuxClkConnect ( FUNCPTR routine, /* routine called at each aux clock interrupt */ int arg /* argument with which to call routine */ ) { sysAuxClkRoutine = routine; sysAuxClkArg = arg; sysAuxClkConnected = TRUE; 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) { /* disable counter */ sysPciOutLong ((UINT32)EPIC_TIMER0_BASE_CT_REG, 0xffffffff); SYNC; /* synchronize */ sysAuxClkRunning = FALSE; } }/******************************************************************************** sysAuxClkEnable - turn on auxiliary clock interrupts** This routine enables auxiliary clock interrupts.** RETURNS: N/A** SEE ALSO: sysAuxClkDisable()*/ void sysAuxClkEnable (void) { if (!sysAuxClkRunning) { /* enable counter and write value to count from */ sysPciOutLong ((UINT32)EPIC_TIMER0_BASE_CT_REG, ((EPIC_TIMER_CNT/sysAuxClkTicksPerSecond) & EPIC_GTBC_C_MASK)); SYNC; /* synchronize */ 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 is not* supported, since the auxiliary clock always runs at the same rate as the* system clock.** RETURNS: OK or ERROR.** 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 + -