[En-Nut-Discussion] AT91SAM7X256 TC1 Timer being disabled

Coleman Brumley cbrumley at gopolar.com
Wed Jul 8 22:34:39 CEST 2009


Hello everyone,

 

In my application, I've enabled the TC1 timer using the following code:

 

void RegisterTC1Timer(void (*handler) (void *))

{

    int dummy;

 

#if defined(MCU_AT91SAM7X256) || defined(MCU_AT91SAM9260)

    /* Enable TC1 clock. */

    outr(PMC_PCER, _BV(TC1_ID));

#endif

 

    /* Disable the Clock Counter */

    outr(TC1_CCR, TC_CLKDIS);

    /* Disable all interrupts */

    outr(TC1_IDR, 0xFFFFFFFF);

    /* Clear the status register. */

    dummy = inr(TC1_SR);

    /* Select divider and compare trigger */

    outr(TC1_CMR, TC_CLKS_MCK32 | TC_CPCTRG);

    /* Enable the Clock counter */

    outr(TC1_CCR, TC_CLKEN);

    /* Validate the RC compare interrupt */

    outr(TC1_IER, TC_CPCS);

 

    /* Register timer interrupt handler. */

    NutRegisterIrqHandler(&sig_TC1, handler, 0);

    /* Set to lowest priority. */

    NutIrqSetPriority(&sig_TC1, 0);

 

    /* Enable timer 0 interrupts */

    NutIrqEnable(&sig_TC1);

    //outr(AIC_IECR, _BV(TC1_ID));

 

#ifndef NUT_TICK_FREQ

#define NUT_TICK_FREQ   1000UL

#endif

    /* Set compare value for 1 ms. */

#if defined(AT91_PLL_MAINCK)      

    outr(TC1_RC, At91GetMasterClock() / (32 * NUT_TICK_FREQ));

#else

    outr(TC1_RC, NutGetCpuClock() / (32 * NUT_TICK_FREQ));

#endif

 

    /* Software trigger starts the clock. */

    outr(TC1_CCR, TC_SWTRG);

}

 

I then call RegisterTC1Timer(TC1TimerIntr); in some initialization code at
startup.  This function is pretty simple:

 

static void TC1TimerIntr(void *arg)

{      

       tc1_ticks++;  

       if(tc1ticks>=5)      //do something every 5ms

       {

              //do sometthing, set a flag, toggle a PIO pin, etc.

              tclticks=0;

       }      

}

 

What I'm finding, though, is that after some amount of time (several hours,
for instance) the TC1 interrupt is being disabled.  If I toggle a PIO pin in
TC1TimerIntr and the app gets in this state, then the PIO pin is not longer
being toggled.   I can find no reference to NutIrqDisable for sig_TC1 in the
code though.  

 

Has anyone else come across this type of scenario?  I'm using Nut/OS v4.6.4.


 

Best Regards,

Coleman




More information about the En-Nut-Discussion mailing list