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

📄 systimer.c

📁 博创PXA270-S开发箱的VxWorks BSP驱动(含注释)
💻 C
📖 第 1 页 / 共 2 页
字号:
/* pxa270 sysTimer.c - pxa270 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          pxa270 BSP. Anything with "pxa270" 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#include "pxa270.h"/*  * Core Frequency is 600MHz, * divided by 16, (pxa270_TMR_CSEL_CORE16), will give us 37.5MHz * at 60 ticks per sec we will need a rollover of 625000 */UINT32 _busClockRate = 3250000;/* Locals */LOCAL int     sysClockTicksPerSecond    = 60;LOCAL UINT32  sysClockTimerRollOver     = 54167;   /* 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/********************************************************************************* 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);    *((UINT32*)pxa270_OSCR0) = 0;    *((UINT32*)pxa270_OSSR) = 1;	/*	pxa_serial_write1(22);	*/     /* 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           */    )    {    sysClkRoutine   = routine;    sysClkArg       = arg;    if(!sysClkConnected)	{        sysHwInit2 ();        (void)intConnect (INUM_TO_IVEC(IRQ_OST0), sysClkInt, 0);        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(IRQ_OST0);        /* Lock Interrupts */        locKey = intLock();        *((UINT32*)pxa270_OSCR0) = 0;		*((UINT32*)pxa270_OSSR) = 0;		*((UINT32*)pxa270_OSMR0) = 0;		*((UINT32*)pxa270_OIER) &= ~(0x1);	        /* 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();		*((UINT32*)pxa270_OSCR0) = 0;		*((UINT32*)pxa270_OSSR) = 0;		*((UINT32*)pxa270_OSMR0) = sysClockTimerRollOver;		*((UINT32*)pxa270_OIER) |= 0x1;                /* UnLock Interrupts */        intUnlock (locKey);        intEnable(IRQ_OST0);        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();*((UINT32*)pxa270_OIER) = 0x0;   *((UINT32*)pxa270_OSCR0) = 0;	*((UINT32*)pxa270_OSMR0) = sysClockTimerRollOver;    /* UnLock Interrupts */    intUnlock (locKey);    sysClockTicksPerSecond = ticksPerSecond;        if (sysClkRunning)        {        sysClkDisable ();        sysClkEnable ();        }    return (OK);    }void clkDelay(int delay){	int i;	for(i=0; i<delay; i++);		}#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;    sysAuxClkRoutine   = routine;    sysAuxClkArg       = arg;    if(!sysAuxClkConnected)	{        (void)intConnect (INUM_TO_IVEC(pxa270_INT_TMR1), sysAuxClkInt, 0);

⌨️ 快捷键说明

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