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

📄 at91timer.c

📁 ARM板驱动程序源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/* at91Timer.c - at91rm9200 timer driver */#include "vxWorks.h"#include "intLib.h"#include "errno.h"#include "drv/timer/timerDev.h"#include "drv/timer/timestampDev.h"#include "config.h"#include "drv/intrCtl/at91Intr.h"#include "drv/timer/at91Timer.h"#include "drv/sio/at91Sio.h"#define CLOCK_TICK_RATE		(AT91C_SLOW_CLOCK)#define LATCH  ((CLOCK_TICK_RATE + HZ/2) / HZ)	/* For divider */#define HZ  100/* Local forward declarations */LOCAL BOOL sysClkConnectFirstTime       = TRUE;LOCAL FUNCPTR sysClkRoutine             = NULL;LOCAL int sysClkArg                     = 0;LOCAL int sysClkRunning                 = FALSE;LOCAL int sysClkTicksPerSecond          = DEF_SYS_CLK_TICKS;LOCAL BOOL sysAuxClkConnectFirstTime    = TRUE;LOCAL FUNCPTR sysAuxClkRoutine          = NULL;LOCAL int sysAuxClkArg                  = 0;LOCAL int sysAuxClkRunning              = FALSE;LOCAL int sysAuxClkTicksPerSecond       = DEF_SYS_AUX_CLK_TICKS;#ifdef  INCLUDE_TIMESTAMPLOCAL BOOL sysTimestampConnectFirstTime = TRUE;LOCAL FUNCPTR sysTimestampRoutine       = NULL;LOCAL int sysTimestampArg               = 0;LOCAL BOOL sysTimestampRunning          = FALSE;#endif  /* INCLUDE_TIMESTAMP *//********************************************************************************* sysClkInt - clock interrupt handler** This routine handles the clock interrupt on the at91rm9200 architecture. It is* attached to the INT_VEC_SYS vector by the routine sysClkConnect().** RETURNS : N/A*/LOCAL void sysClkInt(void){    /* Clear interrupt. *//*    *S3C2510_TIC |= S3C2510_TIC_T5;*/    unsigned int st_sr = AT91_SYS->ST_SR;    unsigned int dbgu_sr = AT91_SYS->DBGU_CSR;  #ifdef INCLUDE_LED    {        static int count = 0;        if (!(count % (sysClkRateGet() / 2)))        {            if (!(count % sysClkRateGet()))            {                LED_ON(LED1_MASK);            }            else            {                LED_OFF(LED1_MASK);            }        }        if (!(count % (sysClkRateGet() / 10)))        {            LED_OFF(LED6_MASK | LED7_MASK | LED8_MASK);        }        count++;    }#endif  /* INCLUDE_LED */ 	if (st_sr & AT91C_ST_PITS) {		    /* Call system clock service routine. */	    if (sysClkRoutine && sysClkRunning)	    {	        (*sysClkRoutine)(sysClkArg);	    }	}else	if(dbgu_sr &  (AT91C_US_RXRDY| AT91C_US_TXEMPTY ))	{		at91SioInt(0);	}}/********************************************************************************* 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: intConnect(), usrClock(), sysClkEnable()*/STATUS sysClkConnect(    FUNCPTR routine,                                        /* routine called at each clock interrupt */    int arg                                                 /* argument to clock interrupt routine */    ){    if (sysClkConnectFirstTime)    {        sysHwInit2();	/* Disable all timer interrupts */	AT91_SYS->ST_IDR = AT91C_ST_PITS | AT91C_ST_WDOVF | AT91C_ST_RTTINC | AT91C_ST_ALMS;	(void) AT91_SYS->ST_SR;		/* Clear any pending interrupts */	/*	 * Make IRQs happen for the system timer.	 *//*	timer_irq.handler = at91rm9200_timer_interrupt;*//*	timer_irq.flags = SA_SHIRQ | SA_INTERRUPT;*//*	setup_arm_irq(AT91C_ID_SYS, &timer_irq);*//*	gettimeoffset = at91rm9200_gettimeoffset;*/	/* Set initial alarm to 0 */	AT91_SYS->ST_RTAR = 0;	/* Real time counter incremented every 30.51758 microseconds */	AT91_SYS->ST_RTMR = 1;	/* Set Period Interval timer */	AT91_SYS->ST_PIMR = LATCH;	/* Change the kernel's 'tick' value to 10009 usec. (the default is 10000) *//*	tick = (LATCH * 1000000) / CLOCK_TICK_RATE;*/	/* Enable Period Interval Timer interrupt */	AT91_SYS->ST_IER = AT91C_ST_PITS;          /* Connect and enable interrupt. */        intConnect(INT_VEC_SYS, (VOIDFUNCPTR)sysClkInt, 0);        intEnable(INT_LVL_SYS);        sysClkConnectFirstTime = FALSE;   }    sysClkRoutine   = routine;    sysClkArg       = arg;    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 timer. */      /*  *S3C2510_TMOD &= ~S3C2510_TMOD_TE5;*/	AT91_SYS->ST_IDR = AT91C_ST_PITS | AT91C_ST_WDOVF | AT91C_ST_RTTINC | AT91C_ST_ALMS;        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){    if (!sysClkRunning)    {        /* Calculate the timer interval. */       /* *S3C2510_TDATA5 = SPLL_FREQ * 1000 * 1000 / sysClkTicksPerSecond - 1;*//*	AT91_SYS->ST_CRTR = SPLL_FREQ * 1000 * 1000 / sysClkTicksPerSecond - 1;*/        /* Enable timer. */       /* *S3C2510_TMOD |= S3C2510_TMOD_TE5; */	AT91_SYS->ST_IER = AT91C_ST_PITS ;/*| AT91C_ST_WDOVF | AT91C_ST_RTTINC | AT91C_ST_ALMS;*/        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;    if (sysClkRunning)    {        sysClkDisable();        sysClkEnable();    }    /*    LED_ON(LED8_MASK);*/        return OK;}/********************************************************************************* sysAuxClkInt - auxiliary clock interrupt handler** This routine handles the auxiliary clock interrupton the S3C9500 architecture.* It is attached to the TIMER5 vector by the routine sysAuxClkConnect().** RETURNS : N/A*/LOCAL void sysAuxClkInt(void){    /* Clear interrupt. */   /* *S3C2510_TIC |= S3C2510_TIC_T4;*/    /* Call auxiliary clock service routine. */    if (sysAuxClkRoutine && sysAuxClkRunning)    {        (*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 auxiliary clock interrupt */    int arg                                                 /* argument to auxiliary clock interrupt routine */    ){    if (sysAuxClkConnectFirstTime)    {        /* Enable peripheral clock. */        /* *S3C2510_PCLKDIS &= ~S3C2510_PCLKDIS_TIMER4;*/        /* Interval mode. */        /* *S3C2510_TMOD &= ~S3C2510_TMOD_TMD4;*/	AT91PS_TC tc = (AT91PS_TC) AT91C_BASE_TC0 ; 	tc->TC_CCR |= AT91C_TC_CLKEN ;

⌨️ 快捷键说明

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