⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sun4timer.c

📁 IXP425的BSP代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/* sun4Timer.c - sun1e timer library *//* Copyright 1984-1996 Wind River Systems, Inc. */#include "copyright_wrs.h"/*modification history--------------------01g,03dec96,wlf  doc: cleanup.01f,11oct96,dat  merged sun4TimerTS.c into this code.01e,11jun96,wlf  doc: cleanup.01d,22mar96,dds  tranferred the intConnects to sysLib.c. 01c,07dec94,rdc  tweeked sysTimestampEnable.01b,10nov94,jds  added timestamp support01a,10jun92,ccc  created by moving routines from sysLib.c of sun1e.*//*DESCRIPTIONThis library contains routines to manipulate the timer functions on thesun1e with a board-independent interface.  This library handles boththe system clock and the auxiliary clock functions.The BSP code is responsible for connecting appropriate interrupt serviceroutines to the interrupt hardware system.  The routines sysClkInt() andsysAuxClkInt() are the routines that should be called as a result ofthe appropriate interrupt request. Interrupt connect actions are normallydone as part of sysHwInit2().The macros SYS_CLK_RATE_MIN, SYS_CLK_RATE_MAX, AUX_CLK_RATE_MIN, andAUX_CLK_RATE_MAX must be defined to provide parameter checking for thesys[Aux]ClkRateSet() routines.If INCLUDE_TIMESTAMP is defined, then a timestamp interface for thistimer will be generated.*/#include "drv/timer/timerDev.h"#include "drv/timer/timestampDev.h"IMPORT	void	sysClkAck ();IMPORT	void	sysAuxClkAck ();/* Locals */ LOCAL int     sysClkTicksPerSecond = 60; LOCAL BOOL    sysClkRunning        = FALSE; LOCAL FUNCPTR sysClkRoutine        = NULL; LOCAL int     sysClkArg            = NULL; LOCAL int     auxClkTicksPerSecond = 60; LOCAL BOOL    sysAuxClkRunning     = FALSE; LOCAL FUNCPTR sysAuxClkRoutine     = NULL; LOCAL int     sysAuxClkArg         = NULL;LOCAL BOOL    sysTimestampRunning  = FALSE;     /* if running - TRUE */LOCAL FUNCPTR sysTimestampRoutine  = NULL;      /* user rollover routine */LOCAL int     sysTimestampArg      = NULL;      /* arg to user routine *//* globals *//**************************************************************************** sysClkInt - clock interrupt handler** This routine handles the clock interrupt.  It is attached to the clock* interrupt vector by the routine sysClkConnect().  The appropriate routine* is called and the interrupts are acknowledged.*/LOCAL void sysClkInt (void)    {    if (sysClkRoutine != NULL)        (*(FUNCPTR) sysClkRoutine) (sysClkArg);    sysClkAck ();    }/***************************************************************************** sysAuxClkInt - clock interrupt handler** This routine handles the clock interrupt.  It is attached to the clock* interrupt vector by the routine sysAuxClkConnect().  The appropriate* routine is called and the interrupts are acknowledged.** This routine supports both auxClock interrupts and timestamp interrupts.* It selects the routine based upon the last successful 'connect' routine,* either sysAuxClkConnect(), or sysTimestampConnect().  The appropriate* timer must also be enabled before the connected user routine is called.*/LOCAL void sysAuxClkInt (void)    {    if (sysAuxClkRunning && sysAuxClkRoutine != NULL)        (*(FUNCPTR) sysAuxClkRoutine) (sysAuxClkArg);    else if (sysTimestampRunning && sysTimestampRoutine != NULL)        (*(FUNCPTR) sysTimestampRoutine) (sysTimestampArg);    sysAuxClkAck ();    }/***************************************************************************** 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.** RETURNS: OK, or ERROR if the routine cannot be connected to the interrupt.** SEE ALSO: usrClock(), sysClkEnable()*/STATUS sysClkConnect    (    FUNCPTR routine,    /* routine called at each system clock interrupt */    int     arg         /* argument with which to call routine           */    )    {    sysClkRoutine     = NULL;    sysClkArg         = arg;    sysClkRoutine     = routine;    sysHwInit2 ();    return (OK);    } /***************************************************************************** sysClkDisable - turn off system clock interrupts** This routine disables system clock interrupts.** RETURNS: N/A** SEE ALSO: sysClkEnable()*/ void sysClkDisable (void)     {    if (sysClkRunning)        {        *SUN_IR         &= ~IR_ALL;     /* turn off interrupts */        *SUN_IR         &= ~IR_CLOCK10; /* turn off lvl 10 */        *SUN_IR         |= IR_ALL;      /* turn on interrupts */        sysClkRunning = FALSE;        }    }/***************************************************************************** sysClkEnable - turn on system clock interrupts** This routine enables system clock interrupts.** RETURNS: N/A** SEE ALSO: sysClkConnect(), sysClkDisable(), sysClkRateSet()*/void sysClkEnable (void)    {    unsigned int intRegister;    if (!sysClkRunning)        {        *SUN_IR         &= ~IR_ALL;     /* turn off interrupts */        intRegister = *SUN_LIMIT_0;     /* Clear interrupt at clock */        *SUN_IR         &= ~IR_CLOCK10; /* Clear interrupt pending */        *SUN_IR         |= IR_CLOCK10;  /* turn on lvl 10 */        *SUN_IR         |= IR_ALL;      /* turn on interrupts */        sysClkRunning = TRUE;        }    }/***************************************************************************** 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 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);    sysClkTicksPerSecond = ticksPerSecond;    *SUN_COUNTER_0 = 0;    *SUN_LIMIT_0 = (1000000 / ticksPerSecond) << 10;    *SUN_COUNTER_0 = 0;    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.  It does not enable auxiliary clock* interrupts.* * The auxilliary clock and the timestamp clock use the same hardware, only* one can be active at a time.  An error will result if an attempt is made* to use both.** RETURNS: OK, or ERROR if the timestamp clock is in use.** SEE ALSO: sysAuxClkDisconnect(), sysAuxClkEnable()*/STATUS sysAuxClkConnect    (    FUNCPTR routine,    /* routine called at each aux. clock interrupt */    int     parm        /* argument to auxiliary clock interrupt routine */    )    {    if (sysTimestampRunning)	return ERROR;    sysAuxClkRoutine   = routine;    sysAuxClkArg       = parm;    return (OK);    }/***************************************************************************** sysAuxClkDisconnect - clear the auxiliary clock routine** This routine disables the auxiliary clock interrupt, stops the timer,* and disconnects the routine currently connected to the auxiliary clock* interrupt.** RETURNS: N/A** SEE ALSO: sysAuxClkConnect(), sysAuxClkEnable()*/void sysAuxClkDisconnect (void)    {    /* disable the auxiliary clock interrupt */    sysAuxClkDisable ();    /* connect dummy routine, just in case */    sysAuxClkConnect ((FUNCPTR) logMsg, (int) "auxiliary clock interrupt\n");    }/***************************************************************************

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -