📄 mpc8240auxclk.c
字号:
/* mpc8240AuxClk.c - Mpc8240 EPIC Timer (Aux Clk) library */
/* Copyright 1999-2000 Wind River Systems, Inc. */
/* Copyright 1999-2000 Motorola, Inc. All Rights Reserved */
/*
modification history
--------------------
01a,28feb00,rhk created from version 01e, MV2100 BSP.
*/
/*
DESCRIPTION
This timer contains routines to use timer 0 on the EPIC as the auxiliary
clock.
*/
/* includes */
#include "prpmc600.h"
/* defines */
#define EPIC_TIMER_CNT (DEC_CLOCK_FREQ / 8)
/* locals */
LOCAL void sysAuxClkInt ();
LOCAL STATUS sysAuxClkInit();
LOCAL FUNCPTR sysAuxClkRoutine = NULL;
LOCAL int sysAuxClkArg = NULL;
LOCAL int sysAuxClkTicksPerSecond = 100;
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 - mpc8240 aux. clock initialization routine
*
* This routine should be called before calling any other routine in this
* module.
*
* RETURNS: OK, or ERROR.
*/
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, 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 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 + -