This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

timer interrupt disable & enable - pending interrupts

Hi,

working with a LPC1758 I´ve installed a timer. In the interrupt routine I've several values which will be updated according to the current state. Is it the right approach to disable the timer interrupt getting the current value of these values? After enabling the timer again, will I also be able to catch a timer interrupt which occurred during the interrupt disable time? I couldn't found any useful information in the lpc17xx user manual.

volatile unsigned char flag1 = false;
volatile unsigned char flag2 = false;
volatile unsigned char flag1_value = 0;
volatile unsigned char flag2_value = 0;

void TIMER0_IRQHandler (void)
{
/* value 1 */
  if(flag1_value)
  {
    flag1_value--;
    if(!flag1_value)
        flag1= true;
  }
/* value 2 */
  if(flag2_value)
  {
    flag2_value--;
    if(!flag2_value)
        flag2= true;
  }
LPC_TIM0->IR = 0x3<<0; /* clear interrupt flag */
}

void SetValue(unsigned char flag, unsigned char value)
{
  NVIC_DisableIRQ(TIMER0_IRQn);
  switch(flag)
  {
   case 1:
     flag1_value = value;
     break;
   case 2:
     flag2_value = value;
     break;
  }

  NVIC_EnableIRQ(TIMER0_IRQn);
}

unsigned char GetValueFlag(unsigned char flag)
{
  unsigned char rtn = 0x00;
  NVIC_DisableIRQ(TIMER0_IRQn);
  switch(flag)
  {
   case 1:
    rtn = flag1;
    flag1 = false;
    break;
  case 2:
    rtn = flag2;
    flag2 = false;
    break;
  }
  NVIC_EnableIRQ(TIMER0_IRQn);
  return rtn;
}

best regards
Lars

0