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

📄 timer.c

📁 一个基于s3c2410平台的monitor程序
💻 C
字号:
//==========================
//file:timer.c
//Discription:include some method used by the monitor program
//Author: Decell.Zhou
//Versions:
//=========================
#include "timer.h"

#define ENTER_CRITICAL() SET_IF()

#define EXIT_CRITICAL() CLR_IF()

static char timerCount = 0;
			

//============[ISR_timer0]=======
//Discription: the ISR for the timer0
//Pram: none
//return:none
//version
//===============================

static void __irq ISR_timer0(void){
	rSRCPND = rSRCPND;//clear the interrupt
	rINTPND = rINTPND;
	if(timerCount == 0){
		timerCount = 0;
	}else{
		timerCount--;
	}
	
}

//============[timerInit]=======
//Discription: this method is used to initial the timer
//Pram: none
//return:none
//version:
//==============================
void timerInit(void){
	//timer setting:
	//PCLK = 266.00Mhz / 4 = 66.5 Mhz
	//divider = 4
	//prescale = 255
	//timer count = 64942
	//timer interval = 64942*(1/(66500000/4/256)) = 1.000009 sec
	
	//first,setting the right clock , the right prescale and divied value
	ChangeMPllValue(0x7d,0x1,0x1);    // FCLK=266MHz
	rTCFG0 |= (0xff<<0);	//prescale = 255
	rTCFG1 |= (0x1<<0); 	//divider = 4
	//second,setting the right TCNT, enable the auto reload, enable manual update
	rTCNTB0 = 0xfd9c;	//TCNTB = 64942
	rTCON |= (0x1<<1)|(0x1<<3);	//manual update on,autoreload on
	//third, install the isr for the timer
#ifdef	NOR_BOOT
	pISR_TIMER0 = (int)ISR_timer0 + 0x30000000;
#else
	pISR_TIMER0 = (int)ISR_timer0;
#endif
	
	//at last,change the uart setting because we change the PCLK
	Uart_Init((266000000/4),115200);

}

//============[timerStart]======
//Discription: this method is used to start the timer
//Pram: none
//return: none
//version: none
//==============================
void timerStart(void){
	//clear the timer gobal varible
	timerCount = 0;
	//enable the timer int mask
	rINTMSK = ~(0x1<<10);// enable the timer0 interrupt
	//disable the manual update,turn on the timer
	rTCON &= ~(0x1<<1);//disable the timer
	rTCON |= (0x1<<0);//turn on the timer;
}

//============[timerStop]======
//Discription: this method is used to stop the timer
//Pram: none
//return: none
//version: none
//==============================
void timerStop(void){
	//turn off the timer
	rTCON &= ~(0x1<<0);
	//disable the timer0 interrput
	rINTMSK |= (0x1<<10); 
	

}

//============[setTimer]========
//Discription: this method is used to setup the timeout count for the timer
//Pram: 
//		int|second|the time out time is defined in second
//return:none
//==============================
void setTimer(int second){
	ENTER_CRITICAL();
	timerCount = second;
	EXIT_CRITICAL();
}

//============[timerExpire]=====
//Discription: this method checks to see if the timer has timeout
//Pram: none
//return:
//		0|do not timeout
//		1|has been timeout
//==============================
char timerExpire(void){
	if(timerCount == 0){
		return 1;
	}else{
		return 0;
	}
}


⌨️ 快捷键说明

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