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

📄 time.c

📁 mp3量不要让站长把时间都花费在为您修正说明上。压缩包解压时不能有密码。系统会自动删除debug和release目录
💻 C
字号:
/*****************************************************************/
/*                                                                            */
/*  TIME.C:  Time Functions for 1000Hz Clock Tick                             */
/*                                                                            */
/*****************************************************************/
/* 20071206: modified by Michale Zhang (bozai)   */
/*																	*/
/*  ported to arm-elf-gcc / WinARM by Martin Thomas, KL, .de                  */
/*  <eversmith@heizung-thomas.de>                                             */
/*  modifications Copyright Martin Thomas 2005                                */
/*                                                                            */
/*  Based on a file that has been a part of the uVision/ARM development       */
/*  tools, Copyright KEIL ELEKTRONIK GmbH 2002-2004                           */
/*****************************************************************/

#include "Board.h"
#include "interrupt_utils.h"
#include "Time.h"

#ifdef ERAM				/* Fast IRQ functions Run in RAM  - see board.h */
#define ATTR RAMFUNC
#else
#define ATTR
#endif

#define TCK  1000								/* Timer Clock  */

#define PIV  ((MCK/TCK/16)-1)					/* Periodic Interval Value */

volatile unsigned long timeval;					/* Current Time Tick */

void  NACKEDFUNC ATTR system_int (void)	/* System Interrupt Handler */
{        
	volatile AT91S_PITC * pPIT = AT91C_BASE_PITC;

	ISR_ENTRY();

	if (pPIT->PITC_PISR & AT91C_PITC_PITS)		/* Check PIT Interrupt */
	{  
		timeval++;							/* Increment Time Tick */
		*AT91C_AIC_EOICR = pPIT->PITC_PIVR;	/* Ack & End of Interrupt */
	}
	else 
	{
		*AT91C_AIC_EOICR = 0;				/* End of Interrupt */
	}
  
	ISR_EXIT();
}


void init_timer (void) 				/* Setup PIT with Interrupt */
{                    
	volatile AT91S_AIC * pAIC = AT91C_BASE_AIC;

	*AT91C_PITC_PIMR = AT91C_PITC_PITIEN |	/* PIT Interrupt Enable */ 
                     AT91C_PITC_PITEN  |				/* PIT Enable */
                     PIV;							/* Periodic Interval Value */ 

	/* Setup System Interrupt Mode and Vector with Priority 7 and Enable it */
	pAIC->AIC_SMR[AT91C_ID_SYS] = AT91C_AIC_SRCTYPE_INT_POSITIVE_EDGE | 7;
  
	pAIC->AIC_SVR[AT91C_ID_SYS] = (unsigned long) system_int;
	pAIC->AIC_IECR = (1 << AT91C_ID_SYS);  
}


void wait(unsigned long time)
{
	unsigned long tick;
	
	tick = timeval;
	
	/* Wait for specified Time */
	while ((unsigned long)(timeval - tick) < time);
}

⌨️ 快捷键说明

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