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

📄 at91timer.c

📁 (1)基于部分u-boot代码自己调试的vxworks BSP (2)实现了nand/nor flash的tffs文件系统 (3)实现了对spi dataflash的访问 (4)实现了对启动参数
💻 C
📖 第 1 页 / 共 3 页
字号:
/********************************************************************************* sysTimestampEnable - initialize and enable the timestamp timer** This routine connects interrupts, and enables the timer device** RETURNS: TRUE always*/STATUS sysTimestampEnable(void){    if (!sysTimestampRunning)    {        AT91C_BASE_RTC->RTC_CR &= ~(AT91C_RTC_UPDTIM | AT91C_RTC_UPDCAL);        sysTimestampRunning = TRUE;    }    return OK;}/********************************************************************************* sysTimestampPeriod - get the period of a timestamp timer ** This routine gets the period of the timestamp timer, in ticks. The period, or* terminal count, is the number of ticks to which the timestamp timer counts* before rolling over and restarting the counting process.** RETURNS: The period of the timestamp timer in counter ticks.*/UINT32 sysTimestampPeriod(void){    return (1);}/********************************************************************************* sysTimestampFreq - get a timestamp timer clock frequency** This routine gets the frequency of the timer clock, in ticks per second. The* rate of the timestamp timer is set explicitly by the hardware and typically* cannot be altered.** RETURNS: The timestamp timer clock frequency, in ticks per second.*/UINT32 sysTimestampFreq(void){    return (1);}/********************************************************************************* sysTimestamp - get a timestamp timer tick count** This routine returns the current value of the timestamp timer tick counter.* The tick count can be converted to seconds by dividing it by the return of* sysTimestampFreq().** This routine should be called with interrupts locked. If interrupts are not* locked, sysTimestampLock() should be used instead.** RETURNS: The current timestamp timer tick count.** SEE ALSO: sysTimestampFreq(), sysTimestampLock()*/UINT32 sysTimestamp(void){    UINT32 runtime = 0;    return (runtime);}/********************************************************************************* sysTimestampLock - lock interrupts and get the timestamp timer tick count** This routine locks interrupts when the tick counter must be stopped in order* to read it or when two independent counters must be read. It then returns the* current value of the timestamp timer tick counter.* * The tick count can be converted to seconds by dividing it by the return of* sysTimestampFreq().** If interrupts are already locked, sysTimestamp() should be used instead.** RETURNS: The current timestamp timer tick count.** SEE ALSO: sysTimestampFreq(), sysTimestamp()*/UINT32 sysTimestampLock(void){    return (1);}#endif  /* INCLUDE_TIMESTAMP */#ifdef INCLUDE_TIMER_COUNTERSLOCAL void TimerCounter0ISR(void){	/*clear the interrupt  wurj*/	AT91PS_TC tc = at91rm9200timercounter[TIMER_COUNTER0].TCRegBaseAddr;	/*clear the interrupt */	if(0 == ((tc->TC_SR) & AT91C_TC_CPCS))	{		return;	}#if 0	/*clear the interrupt*/	AT91F_AIC_ClearIt(AT91C_BASE_AIC, INT_LVL_TC0);#endif/*this mode not been test*/	if (at91rm9200timercounter[TIMER_COUNTER0].TimerCounterRoutine &&		 at91rm9200timercounter[TIMER_COUNTER0].TimerCounterRunning)	{	    at91rm9200timercounter[TIMER_COUNTER0].TimerCounterRoutine(at91rm9200timercounter[TIMER_COUNTER0].TimerCounterArg);	}      }LOCAL void TimerCounter1ISR(void){   	/*clear the interrupt*/	AT91PS_TC tc = at91rm9200timercounter[TIMER_COUNTER1].TCRegBaseAddr;	if(0 == ((tc->TC_SR) & AT91C_TC_CPCS))	{		return;	}	if (at91rm9200timercounter[TIMER_COUNTER1].TimerCounterRoutine &&		 at91rm9200timercounter[TIMER_COUNTER1].TimerCounterRunning)	{        	    at91rm9200timercounter[TIMER_COUNTER1].TimerCounterRoutine(at91rm9200timercounter[TIMER_COUNTER1].TimerCounterArg);	}      }LOCAL void TimerCounter2ISR(void){	/*clear the interrupt*/	AT91PS_TC tc = at91rm9200timercounter[TIMER_COUNTER2].TCRegBaseAddr;	if(0 == ((tc->TC_SR) & AT91C_TC_CPCS))	{		return;	}	if (at91rm9200timercounter[TIMER_COUNTER2].TimerCounterRoutine &&		 at91rm9200timercounter[TIMER_COUNTER2].TimerCounterRunning)	{	    at91rm9200timercounter[TIMER_COUNTER2].TimerCounterRoutine(at91rm9200timercounter[TIMER_COUNTER2].TimerCounterArg);	}      }LOCAL void TimerCounter3ISR(void){	/*clear the interrupt*/	AT91PS_TC tc = at91rm9200timercounter[TIMER_COUNTER3].TCRegBaseAddr;	if(0 == ((tc->TC_SR) & AT91C_TC_CPCS))	{		return;	}	if (at91rm9200timercounter[TIMER_COUNTER3].TimerCounterRoutine &&		 at91rm9200timercounter[TIMER_COUNTER3].TimerCounterRunning)	{	    at91rm9200timercounter[TIMER_COUNTER3].TimerCounterRoutine(at91rm9200timercounter[TIMER_COUNTER3].TimerCounterArg);	}      }LOCAL void TimerCounter4ISR(void){	/*clear the interrupt*/	AT91PS_TC tc = at91rm9200timercounter[TIMER_COUNTER4].TCRegBaseAddr;	if(0 == ((tc->TC_SR) & AT91C_TC_CPCS))	{		return;	}	if (at91rm9200timercounter[TIMER_COUNTER4].TimerCounterRoutine &&		 at91rm9200timercounter[TIMER_COUNTER4].TimerCounterRunning)	{	    at91rm9200timercounter[TIMER_COUNTER4].TimerCounterRoutine(at91rm9200timercounter[TIMER_COUNTER4].TimerCounterArg);	}      } LOCAL void TimerCounter5ISR(void){	/*clear the interrupt*/	AT91PS_TC tc = at91rm9200timercounter[TIMER_COUNTER5].TCRegBaseAddr;	if(0 == ((tc->TC_SR) & AT91C_TC_CPCS))	{		return;	}	if (at91rm9200timercounter[TIMER_COUNTER5].TimerCounterRoutine &&		 at91rm9200timercounter[TIMER_COUNTER5].TimerCounterRunning)	{	    at91rm9200timercounter[TIMER_COUNTER5].TimerCounterRoutine(at91rm9200timercounter[TIMER_COUNTER5].TimerCounterArg);	}      }STATUS TimerCounterConnect(	UINT32 timercounternum,    FUNCPTR routine,          /* routine called at each auxiliary clock interrupt */    int arg                   /* argument to auxiliary clock interrupt routine */    ){    AT91PS_TC tc = NULL;    if (timercounternum > 5)	    return ERROR;			    tc = at91rm9200timercounter[timercounternum].TCRegBaseAddr;	    if (at91rm9200timercounter[timercounternum].TimerCounterConnectFirstTime)        {        /* enables TC clock */        *AT91C_PMC_PCER = 1 << (AT91C_ID_TC0 + timercounternum);  /* enable clock */                /* TC0 register init */        tc->TC_CCR = AT91C_TC_CLKDIS;        tc->TC_IDR = ~0ul;        tc->TC_SR;                /* TC global configuration register init */        *AT91C_TCB0_BCR = 0;        *AT91C_TCB0_BMR = AT91C_TCB_TC0XC0S_NONE | AT91C_TCB_TC1XC1S_NONE | AT91C_TCB_TC2XC2S_NONE;        *AT91C_TCB1_BCR = 0;        *AT91C_TCB1_BMR = AT91C_TCB_TC0XC0S_NONE | AT91C_TCB_TC1XC1S_NONE | AT91C_TCB_TC2XC2S_NONE;                      tc->TC_CMR = AT91C_TC_TIMER_DIV4_CLOCK | AT91C_TC_CPCTRG;		                tc->TC_RC = AT91C_TIMER_CLOCK4/at91rm9200timercounter[timercounternum].TimerCounterTicksPerSecond;                /* we enalbe the clock and use software trigget to start the clock */        tc->TC_CCR = AT91C_TC_CLKEN | AT91C_TC_SWTRG;                /* Connect and enable interrupt.*/         intConnect(INUM_TO_IVEC(INT_LVL_TC0 + timercounternum),                    (VOIDFUNCPTR)at91rm9200timercounter[timercounternum].TimerCounterISR,                    0);        intEnable(INT_LVL_TC0 + timercounternum);		at91rm9200timercounter[timercounternum].TimerCounterConnectFirstTime = FALSE;    }	    at91rm9200timercounter[timercounternum].TimerCounterRoutine    = routine;    at91rm9200timercounter[timercounternum].TimerCounterArg        = arg;	    return OK;}/********************************************************************************* sysAuxClkDisable - turn off auxiliary clock interrupts** This routine disables auxiliary clock interrupts.** RETURNS: N/A** SEE ALSO: sysAuxClkEnable()*/STATUS TimerCounterDisable(UINT32 timercounternum){    AT91PS_TC tc = NULL;    if (timercounternum > 5)	    return ERROR;			    tc = at91rm9200timercounter[timercounternum].TCRegBaseAddr;	    if (at91rm9200timercounter[timercounternum].TimerCounterRunning)    {        tc->TC_IDR = AT91C_TC_CPCS ;                at91rm9200timercounter[timercounternum].TimerCounterRunning = FALSE;    }	return OK;}/********************************************************************************* sysAuxClkEnable - turn on auxiliary clock interrupts** This routine enables auxiliary clock interrupts. The timer is used in* "reference mode" i.e. a value is programmed into the reference register and an* interrupt occurs when the timer reaches that value. ** RETURNS: N/A** SEE ALSO: sysAuxClkConnect(), sysAuxClkDisable(), sysAuxClkRateSet()*/STATUS TimerCounterEnable(UINT32 timercounternum){    AT91PS_TC tc = NULL;    if (timercounternum > 5)	    return ERROR;			    tc = at91rm9200timercounter[timercounternum].TCRegBaseAddr;	    if (!at91rm9200timercounter[timercounternum].TimerCounterRunning)    {        tc->TC_CCR = AT91C_TC_SWTRG;        tc->TC_IER = AT91C_TC_CPCS ;		at91rm9200timercounter[timercounternum].TimerCounterRunning = TRUE;    }	return OK;}/********************************************************************************* sysAuxClkRateGet - get the auxiliary clock rate** This routine returns the interrupt rate of the auxiliary clock.** RETURNS: The number of ticks per second of the auxiliary clock.** SEE ALSO: sysAuxClkEnable(), sysAuxClkRateSet()*/int TimerCounterRateGet(UINT32 timercounternum){    return (at91rm9200timercounter[timercounternum].TimerCounterTicksPerSecond);}/********************************************************************************* sysAuxClkRateSet - set the auxiliary clock rate** This routine sets the interrupt rate of the auxiliary clock. It does not* enable auxiliary clock interrupts.** RETURNS: OK, or ERROR if the tick rate is invalid or the timer cannot be set.** SEE ALSO: sysAuxClkEnable(), sysAuxClkRateGet()*/STATUS TimerCounterRateSet(    UINT32 timercounternum,    int ticksPerSecond                                      /* number of clock interrupts per second */    ){    AT91PS_TC tc = NULL;    if (timercounternum > 5)	    return ERROR;				    if ((ticksPerSecond < TIMER_COUNTER_RATE_MIN) || (ticksPerSecond > TIMER_COUNTER_RATE_MAX))    {        return ERROR;    }	    tc = at91rm9200timercounter[timercounternum].TCRegBaseAddr;    at91rm9200timercounter[timercounternum].TimerCounterTicksPerSecond = ticksPerSecond;    if (at91rm9200timercounter[timercounternum].TimerCounterRunning)    {        TimerCounterDisable(timercounternum);            }    tc->TC_RC = AT91C_TIMER_CLOCK4/ticksPerSecond;    TimerCounterEnable(timercounternum);    return OK;}#endif /* INCLUDE_TIMER_COUNTERS */

⌨️ 快捷键说明

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