ST timer problems

Hello,

Could you help to install the ST timer on the AT91Rm9200? I don't know how to setup the AIC registers correct. Maybe there are more than one big mistake.

void initialize_pit()
{
        unsigned int  flag, period, irq_id, mask, oldHandler, src_type, priority;
        volatile int status;
        void *newHandler;

        //period
    Timer0->ST_PIMR = period << 5;

        AT91F_ST_SetPeriodInterval(Timer0, period);
        //state
        //status = Timer0->ST_SR;

        //enable interrupt
        flag=1;
        Timer0->ST_IER = flag;

        AT91F_ST_EnableIt( Timer0, flag);

        //enable PMC
        AT91F_PMC_EnablePeriphClock(AT91C_BASE_PMC, 1 << AT91C_ID_IRQ0);

        //config AIC
        irq_id = 0;
        oldHandler = pAic->AIC_SVR[irq_id];
        mask = 0x1 << irq_id;
        pAic->AIC_IDCR = mask ;
        pAic->AIC_SVR[irq_id] = (unsigned int) newHandler ;

        //* Store the Source Mode Register
    pAic->AIC_SMR[irq_id] = src_type | priority  ;


        AT91F_AIC_ConfigureIt(pAic, irq_id, priority, src_type, newHandler);

        //enable AIC
        AT91F_AIC_EnableIt(pAic, 1);
}

I hope somebody could help me with this problem...

best regards
johannes

Parents
  • Timer0->ST_PIMR = period << 5;
    

    Your code doesn't show the definition/declaration of Timer0. If the problem is there, it's impossible for anyone not having access to the code to spot.

    //enable PMC
            AT91F_PMC_EnablePeriphClock(AT91C_BASE_PMC, 1 << AT91C_ID_IRQ0);
    

    I'm not sure what this line is supposed to do. The AIC is continuously clocked (see device datasheet, p. 241, 22.6.2.).

         irq_id = 0;
    

    IRQ ID 0 is the interrupt of the AIC itself. The system interrupts have the IRQ ID 1. Refer to the device datasheet, p. 21.

    pAic->AIC_SVR[irq_id] = (unsigned int) newHandler ;
    

    I don't think the code assigns a value to newHandler anywhere. Basically, this sets the interrupt vector to a random address. That's a surefire way to get undefined behavior.

    pAic->AIC_SMR[irq_id] = src_type | priority  ;
    

    priority never has a value assigned to it anywhere. This doesn't just set the priority to a random value, it may also set the source type to a random value.
    Oh. src_type also never has a value assigned to it, either.

    AT91F_AIC_ConfigureIt(pAic, irq_id, priority, src_type, newHandler);
    

    The code first tries to configure the interrupt "by hand" and then does so again by using the function.

Reply
  • Timer0->ST_PIMR = period << 5;
    

    Your code doesn't show the definition/declaration of Timer0. If the problem is there, it's impossible for anyone not having access to the code to spot.

    //enable PMC
            AT91F_PMC_EnablePeriphClock(AT91C_BASE_PMC, 1 << AT91C_ID_IRQ0);
    

    I'm not sure what this line is supposed to do. The AIC is continuously clocked (see device datasheet, p. 241, 22.6.2.).

         irq_id = 0;
    

    IRQ ID 0 is the interrupt of the AIC itself. The system interrupts have the IRQ ID 1. Refer to the device datasheet, p. 21.

    pAic->AIC_SVR[irq_id] = (unsigned int) newHandler ;
    

    I don't think the code assigns a value to newHandler anywhere. Basically, this sets the interrupt vector to a random address. That's a surefire way to get undefined behavior.

    pAic->AIC_SMR[irq_id] = src_type | priority  ;
    

    priority never has a value assigned to it anywhere. This doesn't just set the priority to a random value, it may also set the source type to a random value.
    Oh. src_type also never has a value assigned to it, either.

    AT91F_AIC_ConfigureIt(pAic, irq_id, priority, src_type, newHandler);
    

    The code first tries to configure the interrupt "by hand" and then does so again by using the function.

Children
More questions in this forum