|
Hi everyone,
I am working with the AT91SAM7X256 evaluation board and I would like to create a timer using the waveform mode (I am using TC1). I tried the Atmel example for the AT917S64 and I adapted it to my board, but it is not working. Indeed, the timer does not start (I used LEDs to check it). I have checked topics about TC in this forum, but none of them seemed to deal with my problem, so some help would be appreciated.
Here is my code:
Main.c
int main( void ) { /* Setup any hardware that has not already been configured by the low level init routines. */ prvSetupHardware(); AT91F_TC1_CfgPIO(); //configure PIO to drive TC1 signal
timer_init();//initialization of the timer
vParTestSetLED(1, 0); //LED DS2 is switched on //* Start timer1 AT91C_BASE_TC1->TC_CCR = AT91C_TC_SWTRG |AT91C_TC_CLKEN ; vParTestSetLED(0, 0);// LED DS1 should be switched on but it is not the case
}
Timer.c :
void AT91F_TC_Open ( AT91PS_TC TC_pt, unsigned int Mode, unsigned int TimerId) //* Begin { 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 ; //* End }
void timer1_c_irq_handler(void) { AT91PS_TC TC_pt = AT91C_BASE_TC1; unsigned int dummy; //* Acknowledge interrupt status dummy = TC_pt->TC_SR; //* Suppress warning variable "dummy" was set but never used dummy = dummy; count_timer1_interrupt++; numCycleRead++; }
void timer_init ( void ) //* Begin { unsigned int oldHandler; unsigned int mask ;
count_timer1_interrupt=0;
//* Open timer1 AT91F_TC_Open(AT91C_BASE_TC1,AT91C_TC_WAVESEL_UP_AUTO ,AT91C_ID_TC1);
//* Open Timer 1 interrupt
oldHandler = AT91C_BASE_AIC->AIC_SVR[TIMER1_INTERRUPT_LEVEL]; mask = 0x1 << TIMER1_INTERRUPT_LEVEL ; //* Disable the interrupt on the interrupt controller AT91C_BASE_AIC->AIC_IDCR = mask ; //* Save the interrupt handler routine pointer and the interrupt priority AT91C_BASE_AIC->AIC_SVR[TIMER1_INTERRUPT_LEVEL] = (unsigned int) timer1_c_irq_handler ; //* Store the Source Mode Register AT91C_BASE_AIC->AIC_SMR[TIMER1_INTERRUPT_LEVEL] = AT91C_AIC_SRCTYPE_INT_HIGH_LEVEL | AT91C_ID_TC1 ; //* Clear the interrupt on the interrupt controller AT91C_BASE_AIC->AIC_ICCR = mask ; AT91C_BASE_TC1->TC_IER = AT91C_TC_CPCS; // IRQ enable CPC AT91F_AIC_EnableIt (AT91C_BASE_AIC, AT91C_ID_TC1);
//* End }
Sorry for the long post ; thanks for answering.
|