?? timer.c
字號:
/*
* file:
* timer.c
* description:
* timer controller code.
*/
void timer_ctrl_init(unsigned long pclk, int ms)
{
rTCON &= ~(0x0f0f);
/* TCLK = 2M */
rTCFG0 &= ~(0xff);
rTCFG0 |= (unsigned int)(pclk/2000000) - 1;
/* TCLK / 2 = 1M */
rTCFG1 &= ~(0xff);
rTCNTB0 = ms * 1000 - 1;
rTCMPB0 = 0;
rTCNTB1 = 0xffff;
rTCMPB1 = 0;
rTCON |= (0x0b0b);
rTCON &= ~(0x0f0f);
}
int timer_ctrl_get_irq(void)
{
int bit, irq;
bit = BIT_TIMER0;
for(irq=0; irq<32; irq++)
{
if(bit & 0x1)
break;
bit >>= 1;
}
return irq;
}
unsigned int timer_ctrl_get_count(void)
{
/* resolution of 1us */
return rTCNTO0;
}
void timer_ctrl_start(void)
{
/* Start timer */
rTCON &= ~(0x0f0f);
rTCON |= (0x0909);
}
void timer_ctrl_udelay(unsigned long usec)
{
unsigned long now, time = 0;
unsigned long last = rTCNTO1;
while(time < usec)
{
now = rTCNTO1;
if(now <= last)
time += last - now;
else
time += 0x10000 - last - now;
last = now;
}
}
/* end of file */
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -