本帖最后由 povypeng 于 2010-3-1 21:38 编辑
void AT91F_TC_Open ( AT91PS_TC TC_pt, unsigned int Mode, unsigned int TimerId)
{
unsigned int dummy;
//* First, enable the clock of the TIMER
AT91F_PMC_EnablePeriphClock ( AT91C_BASE_PMC, 1<< TimerId ) ;
//* Disable the clock and the interrupts
TC_pt->TC_CCR = AT91C_TC_CLKDIS ;
TC_pt->TC_IDR = 0xFFFFFFFF ;
//* Clear status bit
dummy = TC_pt->TC_SR;
//* Suppress warning variable "dummy" was set but never used
dummy = dummy;
//* Set the Mode of the Timer Counter
TC_pt->TC_CMR = Mode ;//可设置时钟分频
//* Enable the clock
TC_pt->TC_CCR = AT91C_TC_CLKEN ;
//* End
}
__inline void AT91F_AIC_Trig (
AT91PS_AIC pAic, // \arg pointer to the AIC registers
unsigned int irq_id) // \arg interrupt number
{
pAic->AIC_ISCR = (0x1 << irq_id) ;// 置位中断,
}
void timer_init ( void )
//* Begin
{
//* Open timer0
//捕获模式; 1024分频;
AT91F_TC_Open(AT91C_BASE_TC0,TC_CLKS_MCK1024,AT91C_ID_TC0);
//* Open Timer 0 interrupt
//AIC高级中断控制;中断ID: 12; 优先级: 1; 电平敏感触发.
AT91F_AIC_ConfigureIt ( AT91C_BASE_AIC, AT91C_ID_TC0, TIMER0_INTERRUPT_LEVEL,AT91C_AIC_SRCTYPE_INT_LEVEL_SENSITIVE, timer0_c_irq_handler);
AT91C_BASE_TC0->TC_IER = AT91C_TC_CPCS; // IRQ enable CPC
//开AIC中断
AT91F_AIC_EnableIt (AT91C_BASE_AIC, AT91C_ID_TC0);
/ /置位中断,
AT91F_AIC_Trig (AT91C_BASE_AIC,AT91C_ID_TC0) ;
//* Start timer0,软件触发执行:计数器复位,时钟启动。
AT91C_BASE_TC0->TC_CCR = AT91C_TC_SWTRG ;
}
问题1:电平敏感触发如何指定是高电平还是低电平?
问题2:置位中断AT91F_AIC_Trig (AT91C_BASE_AIC,AT91C_ID_TC0) ;有什么作用?
问题3: 定时器在什么时候会产生中断,与开软件触发有什么关系?
我是初学者,望大家指教一下 |