s3c6410 定時(shí)器中斷的實(shí)現(xiàn)
five 32-bit timers
Timers 0 and 1 include a PWM function
Each timer has its own 32-bit down-counter which is driven by the timer clock. The down-counter is initially loaded
from the Timer Count Buffer register (TCNTBn). When the down-counter reaches zero, the timer interrupt request
is generated to inform the CPU that the timer operation is completed. When the timer down-counter reaches zero,
the value of corresponding TCNTBn can be automatically reloaded into the down-counter to start the next cycle.
However, if the timer stops, for example, by clearing the timer enable bit of TCONn during the timer running mode,
the value of TCNTBn will not be reloaded into the counter.
1 定時(shí)器0相關(guān)寄存器
1)TCON timer control register (與timer0相關(guān)的【3:0】,開(kāi)關(guān),手動(dòng)更新初值,自動(dòng)重裝初值(
當(dāng)TCNT0減到0后,從TCNTB0自動(dòng)裝到TCNT0)等)
2)TCNTB0 存著timer0的初值;
TCMPB0 存著timer0要比較的值(默認(rèn)為0,則tcnt0和tcmp0比較,)
3)TINT_CSTAT Interrupt Control And Status Register) 定時(shí)器中斷控制和timer0相關(guān)的就兩位,【0】位Timer 0 Interrupt Enable.
【5】位Timer 0 Interrupt Status Bit. Clears by writing 1on this bit.(該位在ISR中需要寫1清零)
4)TCFG0 Timer Configuration Register 0 that configures thetwo 8-bit Prescaler and DeadZone Length
設(shè)置各個(gè)timer的分頻因子低八位是timer0 和timer1相關(guān)的
5)VIC0INTENABLE 中斷使能控制 (32位對(duì)應(yīng)32個(gè)中斷源(注意是VIC0組的,timer0 在23位)
2timer0相關(guān)寄存器設(shè)置
Because an auto-reload operation of the timer occurs when the down counter reaches to 0, a starting value of the
TCNTn has to be defined by the user at first. In this case, the starting value has to be loaded by the manual
update bit. Take the following steps to start a Timer;
1) Write the initial value into TCNTBn and TCMPBn.
2) Set the manual update bit of the corresponding timer.
(Recommended setting the inverter on/off bit (whether using inverter or not)).
3) Set the start bit of the corresponding timer to start the timer and clear only manual update bit.
main.c中的timer0 init函數(shù)
void timer_init(void)
{
TINT_CSTAT |= 1<<0; //開(kāi)timer0中斷,允許timer0中斷發(fā)生
VIC0INTENABLE |= 1<<23; //開(kāi)timer0的使能(相當(dāng)于關(guān)掉mask)
TCFG0 = 0x42; //設(shè)置分頻因子
TCNTB0 = 0x1000; //設(shè)初值
TCON |= 1<<1; //開(kāi)Manual Update (Update TCNTB0,TCMPB0)設(shè)置初值后要更新TCNTB
TCON |= 1<<3; 、、//Auto Reload on 自動(dòng)重裝開(kāi)啟
TCON |= 1<<0; //timer0 open;
TCON &= ~(1<<1); 、//不再Update TCNTB0,TCMPB0
}
start.s 中的handler
irq_handler
;push rets to stack
stmfd sp!,{r0-r12,lr}
;handler
bl do_timer_irq //跳到相關(guān)執(zhí)行函數(shù)
;pop stack to regs
ldmfd sp!, {r0-r12,lr}
subs pc, lr,#4
接下來(lái)的和外部中斷相似了
當(dāng)timer0中斷發(fā)生時(shí),程序到IRQ異常向量表的入口0x18,在這使程序跳轉(zhuǎn)到IRQ_handler();在中斷服務(wù)函數(shù)(ISR)中需要將TCON的5位在開(kāi)始位置寫1清0;為下一個(gè)中斷
評(píng)論