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

📄 m68360timer.c

📁 IXP425的BSP代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/* m68360Timer.c - Motorola MC68360 timer library *//* Copyright 1984-1997 Wind River Systems, Inc. */#include "copyright_wrs.h"/*modification history--------------------01f,13may97,map  updated *Enable(), and *Disable() to use STP bits [SPR# 8473]                 fixed prescaler use in sysTimestamp*() [SPR# 8433]01e,31oct96,wlf  doc: cleanup.01d,28may96,dat  fixed SPR #5430, fixed clearing of status flags01c,12nov94,kdl	 made include of timestampDev.h conditional on INCLUDE_TIMESTAMP01b,10jun94,jds	 included timestamp driver functionality01a,01aug93,dzb  derived from version 01c of timer/m68302Timer.c.*//*DESCRIPTIONThis library contains routines to manipulate the timer functions on theMotorola MC68360.  This library handles both the system clock and the auxiliaryclock functions.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.*//* locals */LOCAL FUNCPTR sysClkRoutine	= NULL; /* routine to call on clock interrupt */LOCAL int sysClkArg		= NULL; /* its argument */LOCAL int sysClkRunning		= FALSE;LOCAL int sysClkConnected	= FALSE;LOCAL int sysClkTicksPerSecond	= 60;LOCAL FUNCPTR sysAuxClkRoutine	= NULL; /* routine to call on clock interrupt */LOCAL int sysAuxClkArg		= NULL; /* its argument */LOCAL int sysAuxClkRunning	= FALSE;LOCAL int auxClkConnected	= FALSE;LOCAL int auxClkTicksPerSecond	= 60;#ifdef  INCLUDE_TIMESTAMP#include "drv/timer/timestampDev.h"LOCAL BOOL    sysTimestampRunning  = FALSE;     /* if running - TRUE */LOCAL FUNCPTR sysTimestampRoutine  = NULL;      /* user rollover routine */LOCAL int     sysTimestampArg      = NULL;      /* arg to user routine */#endif  /* INCLUDE_TIMESTAMP *//********************************************************************************* sysClkInt - system clock interrupt handler** This routine handles the system clock interrupt.  It calls a user routine* if one was specified by the routine sysClkConnect().*/LOCAL void sysClkInt (void)    {    *M360_CPM_TER1(SYS_TMR_BASE) |= TMR_TER_REF;     /* clear event register */    *M360_CPM_CISR(SYS_TMR_BASE) = CPIC_CIXR_TMR1;  /* clear in-service bit */    if (sysClkRoutine != NULL)        (*sysClkRoutine) (sysClkArg);    }/********************************************************************************* sysAuxClkInt - auxiliary clock interrupt handler** This routine handles the auxiliary clock interrupt.  It calls a user routine* if one was specified by the routine sysAuxClkConnect().*/LOCAL void sysAuxClkInt (void)    {    *M360_CPM_TER2(AUX_TMR_BASE) |= TMR_TER_REF;     /* clear event register */    *M360_CPM_CISR(AUX_TMR_BASE) = CPIC_CIXR_TMR2;  /* clear in-service bit */    if (sysAuxClkRoutine != NULL)        (*sysAuxClkRoutine) (sysAuxClkArg);    }/********************************************************************************* 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 to be called at each clock interrupt */    int     arg		/* argument with which to call routine          */    )    {    sysHwInit2 ();	/* XXX for now -- needs to be in usrConfig.c */    sysClkRoutine   = routine;    sysClkArg       = arg;    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)    {    if (sysClkRunning)	{	*M360_CPM_CIMR(SYS_TMR_BASE) &= ~CPIC_CIXR_TMR1; /* disable interrupt */	*M360_CPM_TGCR(SYS_TMR_BASE) |= TMR_TGCR_STP1;	 /* stop the timer */	sysClkRunning = FALSE;			/* clock is no longer running */	}    }/********************************************************************************* sysClkEnable - turn on system clock interrupts** This routine enables system clock interrupts.** RETURNS: N/A** SEE ALSO: sysClkConnect(), sysClkDisable(), sysClkRateSet()*/void sysClkEnable (void)    {    UINT32  tempDiv = SYS_CPU_FREQ / (sysClkTicksPerSecond << 8);    if ((!sysClkRunning) && (tempDiv <= USHRT_MAX * 16))	{        /* start, reset, but disable timer 1 */                *M360_CPM_TGCR(SYS_TMR_BASE) &= ~(TMR_TGCR_RST1 | TMR_TGCR_STP1);        *M360_CPM_TCN1(SYS_TMR_BASE) = 0x0;		/* reset timer count */	if (tempDiv <= USHRT_MAX)	    {            *M360_CPM_TRR1(SYS_TMR_BASE) = (UINT16) tempDiv;            *M360_CPM_TMR1(SYS_TMR_BASE) = TMR_TMR_ICLK_CLK | TMR_TMR_ORI |                                           TMR_TMR_FRR | (TMR_TMR_PS & 0xff00);	    }	else	    {            *M360_CPM_TRR1(SYS_TMR_BASE) = (UINT16) (tempDiv / 16);            *M360_CPM_TMR1(SYS_TMR_BASE) = TMR_TMR_ICLK_CLK16 | TMR_TMR_ORI |                                           TMR_TMR_FRR | (TMR_TMR_PS & 0xff00);	    }         *M360_CPM_TER1(SYS_TMR_BASE) = 0xffff;		/* clear event */        *M360_CPM_CIMR(SYS_TMR_BASE) |= CPIC_CIXR_TMR1; /* unmask interupt */        *M360_CPM_TGCR(SYS_TMR_BASE) |= TMR_TGCR_RST1;	/* enable timer 1 */	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 does not* enable system clock interrupts.  Normally, 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;    if (sysClkRunning)	{	sysClkDisable ();	sysClkEnable ();	}    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.** 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 to auxiliary clock interrupt routine */    )    {    sysAuxClkRoutine   = routine;    sysAuxClkArg       = arg;    auxClkConnected    = 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)	{	*M360_CPM_CIMR(AUX_TMR_BASE) &= ~CPIC_CIXR_TMR2; /* disable interrupt */	*M360_CPM_TGCR(AUX_TMR_BASE) |= TMR_TGCR_STP2;	 /* stop the timer */	sysAuxClkRunning = FALSE;		/* clock is no longer running */	}    }/********************************************************************************* sysAuxClkEnable - turn on auxiliary clock interrupts** This routine enables auxiliary clock interrupts.** RETURNS: N/A

⌨️ 快捷键说明

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