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

📄 at91vxwtimer.c

📁 包含makefile config.h rominit romstart userinit 等等文件
💻 C
📖 第 1 页 / 共 2 页
字号:
/* sndsTimer.c - AT91RM9200 TimerCounter library *//*modification history--------------------2004/10/25 this file is modified form VxWorks demo bsp integrator920t*//*DESCRIPTIONINCLUDES:sndstimer.htimestampDev.h*//* includes */#include "drv/timer/timerDev.h"#include "drv/timer/timestampDev.h"/* defines *//* The default is to assume memory mapped I/O */#ifndef AT91_TIMER_INT_ENABLE#define AT91_TIMER_INT_ENABLE(level) intEnable(level)#endif#ifndef AT91_TIMER_INT_DISABLE#define AT91_TIMER_INT_DISABLE(level) intDisable(level)#endif/* locals */LOCAL FUNCPTR sysClkRoutine	= NULL; /* routine to call on clock tick */LOCAL int sysClkArg		= 0; /* its argument */LOCAL int sysClkRunning		= FALSE;LOCAL int sysClkTicksPerSecond	= 60;LOCAL FUNCPTR sysAuxClkRoutine	= NULL;LOCAL int sysAuxClkArg		= 0;LOCAL int sysAuxClkRunning	= FALSE;LOCAL int sysAuxClkTicksPerSecond = 100;LOCAL int sysAuxClkTicks;#ifdef INCLUDE_TIMESTAMPLOCAL BOOL	sysTimestampRunning	= FALSE; /* running flag */LOCAL int	sysTimestampPeriodValue	= 0;  /* Max counter value */LOCAL FUNCPTR	sysTimestampRoutine	= NULL;  /* routine to call on intr */LOCAL int	sysTimestampArg		= 0;     /* arg for routine */      void	sysTimestampInt (void);		 /* forward declaration */#endif  /* INCLUDE_TIMESTAMP *//********************************************************************************* sysClkInt - interrupt level processing for system clock** This routine handles an system clock interrupt.  It acknowledges the* interrupt and calls the routine installed by sysClkConnect().*/void TimerCounter_Global_Init(){	/* set two block extern clock input to none ? */	((AT91_REG*)TIMER0_BASE_ADDR)[ TC_BMR_OFFSET/4 ] = TC0_BMR_VALUE;	((AT91_REG*)TIMER3_BASE_ADDR)[ TC_BMR_OFFSET/4 ] = TC0_BMR_VALUE;	/* set all timer to be quite state: disabled wave mode, MASTER CLOCK/128 as clock source */	( (TimerCounter*)TIMER0_BASE_ADDR ) ->TC_CCR = TIMER0_CCR_CLKDIS;	( (TimerCounter*)TIMER0_BASE_ADDR ) ->TC_CMR = ((1<<15)|(0x3));	( (TimerCounter*)TIMER1_BASE_ADDR ) ->TC_CCR = TIMER0_CCR_CLKDIS;	( (TimerCounter*)TIMER1_BASE_ADDR ) ->TC_CMR = ((1<<15)|(0x3));	( (TimerCounter*)TIMER2_BASE_ADDR ) ->TC_CCR = TIMER0_CCR_CLKDIS;	( (TimerCounter*)TIMER2_BASE_ADDR ) ->TC_CMR = ((1<<15)|(0x3));	( (TimerCounter*)TIMER3_BASE_ADDR ) ->TC_CCR = TIMER0_CCR_CLKDIS;	( (TimerCounter*)TIMER3_BASE_ADDR ) ->TC_CMR = ((1<<15)|(0x3));		( (TimerCounter*)TIMER4_BASE_ADDR ) ->TC_CCR = TIMER0_CCR_CLKDIS;	( (TimerCounter*)TIMER4_BASE_ADDR ) ->TC_CMR = ((1<<15)|(0x3));		( (TimerCounter*)TIMER5_BASE_ADDR ) ->TC_CCR = TIMER0_CCR_CLKDIS;	( (TimerCounter*)TIMER5_BASE_ADDR ) ->TC_CMR = ((1<<15)|(0x3));}/* *	this routine is used for  *	1. system period timer interrupt *	2. DBGU interrupt * */extern AT91_DBGU_CHAN at91DBGUChan;void sysClkInt (void){	static UINT32 counter;	UINT32 status;	SYSTIMER_S* pst = (SYSTIMER_S*)( SYSTIMER_BASE_ADDR );	DBGU_S* pdbgu = ( DBGU_S* )( DBGU_BASE_ADDR );	/*	 *	check vxworks system timer interrupt	 */	status = pst ->ST_SR;	if( ( sysClkRunning == TRUE ) && (  status & ST_SR_PITS ) && ( sysClkRoutine != NULL ) )	{		/* call system clock service routine */		(* sysClkRoutine) (sysClkArg);	}	/*	 *	check DBGU interrupt	 */		if( at91DBGUChan.intrmode )	{		status = ( (pdbgu ->DBGU_CSR)			&( DBGU_CSR_OVRE | DBGU_CSR_FRAME | DBGU_CSR_PARE | DBGU_CSR_TXRDY | DBGU_CSR_RXRDY ) );		if( status ) AT91DBGUInt( &at91DBGUChan );	}}/********************************************************************************* 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 */){	static BOOL beenHere = FALSE;	if (!beenHere)	{		beenHere = TRUE;		sysHwInit2 ();	}	sysClkRoutine   = NULL;	sysClkArg	    = arg;	sysClkRoutine   = routine;	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)	{		/*		 *	disable ST period interrupt		 */		( (SYSTIMER_S*)( SYSTIMER_BASE_ADDR ) ) ->ST_IDR = 0xFFFFFFFF;		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){	UINT32 sysClkTicks;	SYSTIMER_S* pst;	if (!sysClkRunning)	{		/*		 * Calculate the number of ticks of the timer clock that this		 * period requires.  Do this once, here, so that the timer interrupt		 * routine does not need to perform a division.		 */		sysClkTicks = ( SLOW_RATE_CLK / sysClkTicksPerSecond );		pst = (SYSTIMER_S*)( SYSTIMER_BASE_ADDR );		pst ->ST_PIMR = sysClkTicks;		/*		 *	dummy read status reg to clear interrupt status		 */		sysClkTicks = pst ->ST_SR;		pst ->ST_IER = ST_IE_DR_PITS;		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);	if ( sysClkRunning )	{		sysClkDisable ();		sysClkTicksPerSecond = ticksPerSecond;		sysClkEnable ();	}	return (OK);}/********************************************************************************* 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 */	int dummy = ((TimerCounter*)TIMER0_BASE_ADDR)->TC_SR;	    if (sysAuxClkRoutine != NULL)		(*sysAuxClkRoutine) (sysAuxClkArg);}/********************************************************************************* 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	= NULL;    sysAuxClkArg	= arg;    sysAuxClkRoutine	= routine;    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)	{		AT91_TIMER_INT_DISABLE ( INT_LVL_TC0 );		((TimerCounter*)TIMER0_BASE_ADDR)->TC_IDR = (AT91_REG)( TIMER0_IDR_VALUE | TIMER0_IER_VALUE );		((TimerCounter*)TIMER0_BASE_ADDR)->TC_CCR = (AT91_REG)TIMER0_CCR_CLKDIS;		sysAuxClkRunning = FALSE;	}}/********************************************************************************* sysAuxClkEnable - turn on auxiliary clock interrupts** This routine enables auxiliary clock interrupts.** RETURNS: N/A** SEE ALSO: sysAuxClkConnect(), sysAuxClkDisable(), sysAuxClkRateSet()*/void sysAuxClkEnable (void){    UINT32 sysClkTicks;	TimerCounter* ptc0 = (TimerCounter*)TIMER0_BASE_ADDR;/*    static connected = FALSE;    if (!connected)	{		intConnect ( INT_VEC_TC1, sysAuxClkInt, 0 );		connected = TRUE;

⌨️ 快捷键说明

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