AnsweredAssumed Answered

Clearing PIT Timer Interrupt Flag causing exception

Question asked by Matt Lang on Mar 3, 2015
Latest reply on Mar 4, 2015 by Jorge_Gonzalez

I am using the PIT for a delay function. It sets up the timer based on the delay passed in and polls for the interrupt flag, stops the timer and exits. This has been working great. But then I set up a pin interrupt triggering on both rising and falling edges and then I call my delay function inside that interrupt. And It seems like if I write anything to the PIT registers it causes an exception. Goes to the defaultISR.

 

void usDelay(uint32_t us) {

  uint8_t i = 0;

  uint32_t count = (US_FREQ_BUS*us);

 

 

 

 

  //PIT_HAL_ClearIntFlag(g_pitBaseAddr[US_DELAY_INSTANCE], US_DELAY_CHAN);

  PIT_TFLG0 = 0x01;

 

 

  if(count > US_DELAY_TRIM) {

  PIT_DRV_SetTimerPeriodByCount(US_DELAY_INSTANCE, US_DELAY_CHAN, count - US_DELAY_TRIM);

  count = count - US_DELAY_TRIM;

  } else {

 

 

  PIT_DRV_SetTimerPeriodByCount(US_DELAY_INSTANCE, US_DELAY_CHAN, count);

  }

 

 

  PIT_HAL_StartTimer(g_pitBaseAddr[US_DELAY_INSTANCE], US_DELAY_CHAN);

 

 

  while(!PIT_HAL_IsIntPending(g_pitBaseAddr[US_DELAY_INSTANCE], US_DELAY_CHAN));

 

 

  PIT_HAL_StopTimer(g_pitBaseAddr[US_DELAY_INSTANCE], US_DELAY_CHAN);

 

 

}

 

 

In the debugger, the line   PIT_TFLG0 = 0x01; executes and then the next operation (does not matter what it is) causes the exception. But this only happens when I call this delay function from an interrupt.

Outcomes