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

📄 at91timer.c

📁 (1)基于部分u-boot代码自己调试的vxworks BSP (2)实现了nand/nor flash的tffs文件系统 (3)实现了对spi dataflash的访问 (4)实现了对启动参数
💻 C
📖 第 1 页 / 共 3 页
字号:
    }}#endif /* INCLUDE_ST_RTT */#ifdef INCLUDE_AUX_CLK/********************************************************************************* sysAuxClkInt - auxiliary clock interrupt handler*** RETURNS : N/A*/LOCAL void sysAuxClkInt(void){	/*clear the interrupt  wurj*/	AT91PS_TC tc = AT91C_BASE_TC0;	if(0 == ((tc->TC_SR) & AT91C_TC_CPCS))	{		return;	}	/* Call auxiliary clock service routine. */	if (sysAuxClkRoutine && sysAuxClkRunning)	{	    (*sysAuxClkRoutine)(sysAuxClkArg);	}}/********************************************************************************* sysAuxClkConnect - connect a routine to the auxiliary clock interrupt,*                     this interrupt is caused by TC0 of AT91RM9200** 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 */    ){    AT91PS_TC tc = (AT91PS_TC) AT91C_BASE_TC0 ;     if (sysAuxClkConnectFirstTime)        {        /* enables TC0 clock */        *AT91C_PMC_PCER = 1 << AT91C_ID_TC0;  /* 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;                tc->TC_CMR = AT91C_TC_TIMER_DIV4_CLOCK | AT91C_TC_CPCTRG;		                tc->TC_RC = AT91C_TIMER_CLOCK4/sysAuxClkTicksPerSecond;                /* 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(INT_VEC_TC0, (VOIDFUNCPTR)sysAuxClkInt, 0);        intEnable(INT_LVL_TC0);    }	    sysAuxClkRoutine    = routine;    sysAuxClkArg        = arg;	    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)    {        AT91C_BASE_TC0->TC_IDR = AT91C_TC_CPCS ;                sysAuxClkRunning = FALSE;    }}/********************************************************************************* 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()*/void sysAuxClkEnable(void){    if (!sysAuxClkRunning)    {        AT91C_BASE_TC0->TC_CCR = AT91C_TC_SWTRG;        AT91C_BASE_TC0->TC_IER = AT91C_TC_CPCS ;        sysAuxClkRunning = TRUE;    }}/********************************************************************************* 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 sysAuxClkRateGet(void){    return (sysAuxClkTicksPerSecond);}/********************************************************************************* 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 sysAuxClkRateSet(    int ticksPerSecond                                      /* number of clock interrupts per second */    ){    if ((ticksPerSecond < AUX_CLK_RATE_MIN) || (ticksPerSecond > AUX_CLK_RATE_MAX))    {        return ERROR;    }    sysAuxClkTicksPerSecond = ticksPerSecond;    if (sysAuxClkRunning)    {        sysAuxClkDisable();            }    AT91C_BASE_TC0->TC_RC = AT91C_TIMER_CLOCK4/ticksPerSecond;    sysAuxClkEnable();    return OK;}#endif /* INCLUDE_AUX_CLK */#ifdef  INCLUDE_TIMESTAMPSTATUS AT91CRtcBaseTimestampInit (    UINT32 century,       /* Current Century range : 19 - 20 */    UINT32 year,          /* Current Year range : 00 - 99 */    UINT32 mounth,        /* Current Month range : 01 - 12 */       UINT32 day,           /* Current Day range : 1 - 7 */         UINT32 date,           /* Current Date range : 01 - 31 */    UINT32 hour,          /* Current Hour range : 1 - 23 */    UINT32 minute,        /* Current Minute : 0 - 59 */     UINT32 second         /* Current Second : 0 - 59 */){    if ( (century!= 20) || (century!= 19) ||    	 (year > 99) ||    	 (mounth == 0) || (mounth > 12) ||    	 (day == 0) || (day > 7) ||    	 (date == 0) || (date > 31) ||    	 (hour == 0) || (hour > 23) ||    	 (minute  > 59) ||    	 (second  > 59) 		)    {        return ERROR;    }	    if (sysTimestampBaseSetFirstTime)    {        sysTimestampBase.century = century;    	sysTimestampBase.year    = year;    	sysTimestampBase.mounth  = mounth;        sysTimestampBase.day     = day;    	sysTimestampBase.date    = date;    	sysTimestampBase.hour    = hour;    	sysTimestampBase.minute  = minute;    	sysTimestampBase.second  = second;   		sysTimestampBaseSetFirstTime = FALSE;    }	return OK;}STATUS AT91CRtcSetTimestamp(    UINT32 century,       /* Current Century range : 19 - 20 */    UINT32 year,          /* Current Year range : 00 - 99 */    UINT32 mounth,        /* Current Month range : 01 - 12 */       UINT32 day,           /* Current Day range : 1 - 7 */         UINT32 date,           /* Current Date range : 01 - 31 */    UINT32 hour,          /* Current Hour range : 1 - 23 */    UINT32 minute,        /* Current Minute : 0 - 59 */     UINT32 second         /* Current Second : 0 - 59 */){    INT32 timeout = 10000;	UINT32 RTC_TIMR_value = 0;	UINT32 RTC_CALR_value = 0;    if ( (century!= 20) || (century!= 19) ||    	 (year > 99) ||    	 (mounth == 0) || (mounth > 12) ||    	 (day == 0) || (day > 7) ||    	 (date == 0) || (date > 31) ||    	 (hour == 0) || (hour > 23) ||    	 (minute  > 59) ||    	 (second  > 59) 		)    {        return ERROR;    }	    sysTimestampRunning = FALSE;    /* Clear the ack status bit in the RTC_SR */    AT91C_BASE_RTC->RTC_SR = AT91C_RTC_ACKUPD;	/* Count the register value according to the input time and date */    RTC_CALR_value = ((hour << 16) & AT91C_RTC_HOUR) |		             ((minute << 8) & AT91C_RTC_MIN) |		             (second & AT91C_RTC_SEC);		             	RTC_TIMR_value = ((date << 24) & AT91C_RTC_DATE) |		             ((day << 21) & AT91C_RTC_DAY) |		             ((mounth << 16) & AT91C_RTC_MONTH) |		             ((year << 8) & AT91C_RTC_YEAR) |		             ((century << 8) & AT91C_RTC_CENT);	/* Stop the RTC cal*/    AT91C_BASE_RTC->RTC_CR |= AT91C_RTC_UPDCAL;    /* Polling if we can update the RTC cal*/	while (!(AT91C_BASE_RTC->RTC_SR & AT91C_RTC_ACKUPD) && 		    (timeout-- !=0));	    if (timeout == 0)    {        return ERROR;    }    AT91C_BASE_RTC->RTC_CALR = RTC_CALR_value;	AT91C_BASE_RTC->RTC_CR &= ~AT91C_RTC_UPDCAL;	    /* Stop the RTC time*/    AT91C_BASE_RTC->RTC_CR |= AT91C_RTC_UPDTIM;    /* Polling if we can update the RTC time*/	while (!(AT91C_BASE_RTC->RTC_SR & AT91C_RTC_ACKUPD) && 		    (timeout-- !=0));	    if (timeout == 0)    {        return ERROR;    }		AT91C_BASE_RTC->RTC_TIMR = RTC_TIMR_value;    AT91C_BASE_RTC->RTC_CR &= ~AT91C_RTC_UPDTIM;	sysTimestampRunning = TRUE;	    return OK;}/********************************************************************************* sysTimestampInt - timestamp timer interrupt handler** This rountine handles the timestamp timer interrupt. A user routine is called,* if one was connected by sysTimestampConnect().** RETURNS: N/A** SEE ALSO: sysTimestampConnect()*/void sysTimestampInt(void){    /* Clear interrupt. */    /**S3C2510_TIC |= S3C2510_TIC_T3;*/		/* Call timestamp timer service routine. */    if (sysTimestampRoutine && sysTimestampRunning)    {        (*sysTimestampRoutine)(sysTimestampArg);    }}/********************************************************************************* sysTimestampConnect - connect a user routine to the timestamp timer interrupt** This routine specifies the user interrupt routine to be called at each* timestamp timer interrupt. It does not enable the timestamp timer itself.** RETURNS: OK, or ERROR if sysTimestampInt() interrupt handler is not used.*/STATUS sysTimestampConnect(    FUNCPTR routine,                                        /* routine called at each timestamp timer interrupt */    int arg                                                 /* argument to timestamp timer interrupt routine */    ){    if (sysTimestampConnectFirstTime)    {        /* Selecte 24-hour mode. */        AT91C_BASE_RTC->RTC_MR = AT91C_RTC_24HRMOD;	        sysTimestampConnectFirstTime = FALSE;    }    sysTimestampRoutine = routine;    sysTimestampArg     = arg;    return OK;}/********************************************************************************* sysTimestampDisable - turn off auxiliary clock interrupts** This routine disables auxiliary clock interrupts.** RETURNS: OK, always** SEE ALSO: sysTimestampEnable()*/STATUS sysTimestampDisable(void){    if (sysTimestampRunning)    {        AT91C_BASE_RTC->RTC_CR |= (AT91C_RTC_UPDTIM | AT91C_RTC_UPDCAL);        sysTimestampRunning = FALSE;    }    return OK;}

⌨️ 快捷键说明

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