📄 timer.c
字号:
/******************************************************************************************/
/* */
/* FILE NAME :timer.c */
/* */
/* DESCRIPTION :Timer initialization and handler */
/* */
/* AUTHOR :Leon */
/* */
/* NOTE :Must undefine USE_PROFILER for no ptick */
/* */
/* FUNCTIONS :clock_init() */
/* timer1_handle () */
/* clock_c() */
/******************************************************************************************/
#include "conreg.h"
#include "timer.h"
#include "uart.h"
//#include "..\cobsp\sams_arm\includes.h"
/******************************************************************************************/
/*called by ipstart */
/*use timer1 to clock ctick */
/******************************************************************************************/
extern void Interrupt_Init(void);
#if AT91_MCK==24000000
#if 0
unsigned long count0;
unsigned long count1;
#else
unsigned long cticks;
#endif
void clock_init(void)
{
TC0_CCR=0x02; /*Disable the Clock Counter*/
TC0_CMR=0x00004004; /*Choose MCK/1024,RC compare trigger enable*/
TC0_IDR=0xEF; /*RC compare interruput Enable*/
TC0_IER=0x10; /*Validate the RC compare interruput*/
TC0_RC=AT91_MCK/1024/TPS; /*Time counter ms: ->AT91_MCK/1024/TPS*/
TC0_CCR= 0x01; /*Enabled the Clock Counter */
// TC0_CCR= 0x05; /*Software trigger command*/
TC0_CCR= 0x04; /*Software trigger command*/
#if 0
TC0_CCR= 0x01; /*TC0 Enabled*/
TC1_CCR=0x02; /*Disable the Clock Counter*/
TC1_CMR=0x00004004; /*Choose MCK/1024,RC compare trigger enable*/
TC1_IDR=0xEF; /*RC compare interruput Enable*/
TC1_IER=0x10; /*Validate the RC compare interruput*/
TC1_RC=AT91_MCK/1024/TPS; /*Time counter :ms ->AT91_MCK/1024/TPS*/
count0=0x0;
count1=0x0;
#else
cticks=0x0;
#endif
}
#else
unsigned long cticks;
void
clock_init(void)
{ //int init already in uart_init
TC0_CCR=0x02;/*TC0 Disable*/
TC0_CMR=0x4004;/*MCKI/1024 32768000/1024=32000Hz*/
TC0_IDR=0xEF;/*RC compare interruput Enable*/
TC0_IER=0x10;
TC0_RC=32000/TPS;/*Time counter*/
// 32000/TPS
TC0_CCR= 0x01;/*TC0 Enabled*/
TC0_CCR= 0x04;/*TC_CCR ,TC2 start*/
cticks=0x0;
}
#endif
/******************************************************************************************/
/*Timer1 interrupt handle routine */
/******************************************************************************************/
void
timer0_handler()
{
volatile int *TC0_SReg = (int *)TC0_SR;
volatile int temp;
/* modified by Stephen Yee*/
temp= AIC_ICCR;
temp |= 0x10; /* clear TC0 interrupt*/
AIC_ICCR = temp;
// AIC_ICCR=0xffffffff;
temp=AIC_IPR;
temp=(int)TC0_SReg;
cticks++;
OSTimeTick();
}
/******************************************************************************************/
/*Just for linking void function */
/******************************************************************************************/
void
clock_c(void)
{
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -