📄 mpc8240auxclk1.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_CNT1 (DEC_CLOCK_FREQ / 8)
/* locals */
LOCAL void sysAuxClk1Int ();
LOCAL STATUS sysAuxClk1Init();
LOCAL FUNCPTR sysAuxClk1Routine = NULL;
LOCAL int sysAuxClk1Arg = NULL;
LOCAL int sysAuxClk1TicksPerSecond = 100;
LOCAL BOOL sysAuxClk1Connected = FALSE;
LOCAL int sysAuxClk1Running = FALSE;
/* externals */
IMPORT void sysPciOutLong (UINT32, UINT32);
/******************************************************************************
*
* sysAuxClk1Int - 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 sysAuxClk1Int (void)
{
if (sysAuxClk1Routine != NULL)
(*sysAuxClk1Routine) (sysAuxClk1Arg);
}
/*****************************************************************************
*
* sysAuxClk1Init - mpc8240 aux. clock initialization routine
*
* This routine should be called before calling any other routine in this
* module.
*
* RETURNS: OK, or ERROR.
*/
STATUS sysAuxClk1Init (void)
{
/* disable counter */
sysPciOutLong ((UINT32)EPIC_TIMER1_BASE_CT_REG, (0xffffffff) );
SYNC; /* synchronize */
/* setup timer frequency register */
sysPciOutLong ((UINT32)EPIC_TIMER_FREQ_REG, (UINT32)EPIC_TIMER_CNT1);
/* interrupt unmasked, priority level 15, vector TIMER1_INT_VEC. */
sysPciOutLong ((UINT32)EPIC_TIMER1_VEC_PRI_REG,
(( EPIC_GTVP_PRI_15 | (TIMER1_INT_VEC) ) & ~EPIC_GTVP_M));
/* interrupt directed at processor 0 */
sysPciOutLong ((UINT32)EPIC_TIMER1_DEST_REG, EPIC_GTD_P0);
SYNC; /* synchronize */
sysAuxClk1Running = 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 sysAuxClk1Connect
(
FUNCPTR routine, /* routine called at each aux clock interrupt */
int arg /* argument with which to call routine */
)
{
sysAuxClk1Routine = routine;
sysAuxClk1Arg = arg;
sysAuxClk1Connected = TRUE;
return (OK);
}
/******************************************************************************
*
* sysAuxClkDisable - turn off auxiliary clock interrupts
*
* This routine disables auxiliary clock interrupts.
*
* RETURNS: N/A
*
* SEE ALSO: sysAuxClkEnable()
*/
void sysAuxClk1Disable (void)
{
if (sysAuxClk1Running)
{
/* disable counter */
sysPciOutLong ((UINT32)EPIC_TIMER1_BASE_CT_REG, 0xffffffff);
SYNC; /* synchronize */
sysAuxClk1Running = FALSE;
}
}
/******************************************************************************
*
* sysAuxClkEnable - turn on auxiliary clock interrupts
*
* This routine enables auxiliary clock interrupts.
*
* RETURNS: N/A
*
* SEE ALSO: sysAuxClk1Disable()
*/
void sysAuxClk1Enable (void)
{
if (!sysAuxClk1Running)
{
/* enable counter and write value to count from */
sysPciOutLong ((UINT32)EPIC_TIMER1_BASE_CT_REG,
((EPIC_TIMER_CNT1/sysAuxClk1TicksPerSecond) &
EPIC_GTBC_C_MASK));
SYNC; /* synchronize */
sysAuxClk1Running = 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: sysAuxClk1Enable(), sysAuxClkRateSet()
*/
int sysAuxClk1RateGet (void)
{
return (sysAuxClk1TicksPerSecond);
}
/******************************************************************************
*
* 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: sysAuxClk1Enable(), sysAuxClk1RateGet()
*/
STATUS sysAuxClk1RateSet
(
int ticksPerSecond /* number of clock interrupts per second */
)
{
if (ticksPerSecond < AUX_CLK_RATE_MIN ||
ticksPerSecond > AUX_CLK_RATE_MAX)
return (ERROR);
sysAuxClk1TicksPerSecond = ticksPerSecond;
if (sysAuxClk1Running)
{
sysAuxClk1Disable ();
sysAuxClk1Enable ();
}
return (OK);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -