微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > s3c6410 定时器中断的实现

s3c6410 定时器中断的实现

时间:11-11 来源:互联网 点击:
6410手册中的相关内容

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 定时器0相关寄存器

1)TCON timer control register (与timer0相关的,开关,手动更新初值,自动重装初值(
当TCNT0减到0后,从TCNTB0自动装到TCNT0)等)

2)TCNTB0 存着timer0的初值;
TCMPB0 存着timer0要比较的值(默认为0,则tcnt0和tcmp0比较,)
3)TINT_CSTAT Interrupt Control And Status Register) 定时器中断控制和timer0相关的就两位,位Timer 0 Interrupt Enable.
位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
设置各个timer的分频因子低八位是timer0 和timer1相关的
5)VIC0INTENABLE 中断使能控制 (32位对应32个中断源(注意是VIC0组的,timer0 在23位)

2timer0相关寄存器设置

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函数
void timer_init(void)
{
TINT_CSTAT |= 1<0; //开timer0中断,允许timer0中断发生
VIC0INTENABLE |= 1<23; //开timer0的使能(相当于关掉mask)
TCFG0 = 0x42; //设置分频因子

TCNTB0 = 0x1000; //设初值
TCON |= 1<1; //开Manual Update (Update TCNTB0,TCMPB0)设置初值后要更新TCNTB
TCON |= 1<3; 、、//Auto Reload on 自动重装开启
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 //跳到相关执行函数
;pop stack to regs
ldmfd sp!, {r0-r12,lr}
subs pc, lr,#4

接下来的和外部中断相似了
当timer0中断发生时,程序到IRQ异常向量表的入口0x18,在这使程序跳转到IRQ_handler();在中断服务函数(ISR)中需要将TCON的5位在开始位置写1清0;为下一个中断

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top