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

📄 systimer.c

📁 嵌入式操作系统VxWorks中板级支持包文件
💻 C
📖 第 1 页 / 共 2 页
字号:
/* template sysTimer.c - template processor timer library *//* Copyright 2001 Wind River Systems, Inc. */#include "copyright_wrs.h"/*modification history--------------------01b,28may02,scm  remove actual reference to iq80321...01a,09jan02,scm  Created from ../target/config/ibrh80200/sysTimer.c.*//*   TODO - Fill in this file with I/O addresses and related constants for the          template BSP. Anything with "template" as a prefix needs to examined           and re-named to id the BSP (i.e. iq80321, iq80310, etc.) *//*DESCRIPTIONThis library contains routines to manipulate the timer functions.interface functions:sysclkInt()       - clock interrupt handlersysclkConnect()   - connect a routine to the clock interruptsysclkDisable()   - turn off system clock interruptssysclkEnable()    - turn on system clock interruptssysclkRateGet()   - get the system clock rate oscillations per secondsysclkPeriod()    - get the period of the timer (tick counter rollover)sysclkFreq()      - get a timer clock frequencysysclkTimestamp() - get a tick counter countNote: There are two different types of ticks referred to.  The frequencytick and the counter tick.  The frequency tick refers to the timer clockoscillations per second and the couter ticks refer to the number of times(ticks) a register decreases until roll over.The macros SYS_CLK_RATE_MIN, SYS_CLK_RATE_MAX, and must be defined toprovide parameter checking for the sysClkRateSet() routine.*/#include "drv/timer/timerDev.h"#ifdef INCLUDE_TIMESTAMP#include "drv/timer/timestampDev.h"#endif/*  * Core Frequency is 600MHz, * divided by 16, (template_TMR_CSEL_CORE16), will give us 37.5MHz * at 60 ticks per sec we will need a rollover of 625000 */UINT32 _busClockRate = 37500000;/* Locals */LOCAL int     sysClockTicksPerSecond    = 60;LOCAL UINT32  sysClockTimerRollOver     = 625000;   /* at 37.5Mhz clock = 60 ticks per sec. */LOCAL BOOL    sysClkConnected       = FALSE;LOCAL BOOL    sysClkRunning         = FALSE;LOCAL FUNCPTR sysClkRoutine         = (FUNCPTR) NULL;LOCAL int     sysClkArg             = (int) NULL;#ifdef INCLUDE_AUX_CLKLOCAL int     sysAuxClockTicksPerSecond = 60;LOCAL UINT32  sysAuxClockTimerRollOver  = 625000;   /* at 37.5Mhz clock = 60 ticks per sec. */LOCAL BOOL    sysAuxClkConnected    = FALSE;LOCAL BOOL    sysAuxClkRunning      = FALSE;LOCAL FUNCPTR sysAuxClkRoutine      = (FUNCPTR) NULL;LOCAL int     sysAuxClkArg          = (int) NULL;#endif#ifdef INCLUDE_TIMESTAMPLOCAL BOOL    sysTimestampRunning   = FALSE;#endif/* routines found in sysTimer.s */IMPORT void sysClear_TISR0 (void);IMPORT void sysEnable_Reload_TMR0 (void);IMPORT void sysDisable_TMR0 (void);IMPORT void sysWrite_TCR0 (UINT32 reg);IMPORT void sysWrite_TRR0 (UINT32 reg);IMPORT void sysEnable_TMR0 (void);IMPORT void sysWrite_CSel_TMR0 (UINT32 val);IMPORT void sysClear_TISR1 (void);IMPORT void sysEnable_Reload_TMR1 (void);IMPORT void sysDisable_TMR1 (void);IMPORT void sysWrite_TCR1 (UINT32 reg);IMPORT void sysWrite_TRR1 (UINT32 reg);IMPORT void sysEnable_TMR1 (void);IMPORT void sysWrite_CSel_TMR1 (UINT32 val);IMPORT UINT32 sysRead_TCR0 (void);/********************************************************************************* sysClkInt - interrupt level processing for system clock** This routine handles an auxiliary clock interrupt.  It acknowledges the* interrupt and calls the routine installed by sysClkConnect().*/LOCAL void sysClkInt (void)     {     if ((sysClkRoutine != NULL) && sysClkRunning)	 (*(FUNCPTR) sysClkRoutine) (sysClkArg);     sysClear_TISR0 ();     /* The timer is free running and as such it has already reloaded      * and is counting down      */     }/***************************************************************************** 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.** RETURN: OK, or ERROR if the routine cannot be connected to the interrupt.** SEE ALSO: intConnect(), usrClock(), sysClkEnable()*/STATUS sysClkConnect    (    FUNCPTR routine,    /* routine called at each system clock interrupt */    int     arg         /* argument with which to call routine           */    )    {    int locKey;    sysClkRoutine   = routine;    sysClkArg       = arg;    if(!sysClkConnected)	{        sysHwInit2 ();        (void)intConnect (INUM_TO_IVEC(template_INT_TMR0), sysClkInt, 0);        /* Lock Interrupts */        locKey = intLock();        sysEnable_Reload_TMR0 ();        /* UnLock Interrupts */        intUnlock (locKey);        sysClkConnected = TRUE;	}    return (OK);    }/***************************************************************************** sysClkDisable - turn off system clock interrupts** This routine disables system clock interrupts.** RETURNS: N/A** SEE ALSO: sysClkEnable()*/void sysClkDisable (void)    {    int locKey;    if (sysClkRunning)        {        intDisable(template_INT_TMR0);        /* Lock Interrupts */        locKey = intLock();        sysDisable_TMR0 ();        /* UnLock Interrupts */        intUnlock (locKey);        sysClkRunning = FALSE;        }    }/***************************************************************************** sysClkEnable - turn on system clock interrupts** This routine enables system clock interrupts.** RETURNS: N/A** SEE ALSO: sysClkDisable(), sysClkRateSet()*/void sysClkEnable (void)    {    int locKey;    if (!sysClkRunning)        {        /* Lock Interrupts */        locKey = intLock();        sysWrite_TCR0 (sysClockTimerRollOver);        sysWrite_TRR0 (sysClockTimerRollOver);        sysEnable_TMR0 ();        /* UnLock Interrupts */        intUnlock (locKey);        intEnable(template_INT_TMR0);        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 (sysClockTicksPerSecond);    }/***************************************************************************** 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 */    )    {    int locKey;    if (ticksPerSecond < SYS_CLK_RATE_MIN || ticksPerSecond > SYS_CLK_RATE_MAX)    return (ERROR);    /* Lock Interrupts */    locKey = intLock();    /* 600MHz/16 = 37.5MHz, at 37.5Mhz clock, 60 ticks per sec. requires rollover of 625000 */    sysWrite_CSel_TMR0 (template_TMR_CSEL_CORE16);    /* UnLock Interrupts */    intUnlock (locKey);    sysClockTicksPerSecond = ticksPerSecond;    sysClockTimerRollOver = (_busClockRate / sysClockTicksPerSecond);    if (sysClkRunning)        {        sysClkDisable ();        sysClkEnable ();        }    return (OK);    }#ifdef INCLUDE_AUX_CLK/********************************************************************************* 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)    {    /* call auxiliary clock service routine */    if (sysAuxClkRoutine != NULL)	(*sysAuxClkRoutine) (sysAuxClkArg);     sysClear_TISR1 ();     /* The timer is free running and as such it has already reloaded      * and is counting down      */    }/***************************************************************************** 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 with which to call routine         */    )    {    int locKey;

⌨️ 快捷键说明

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