The solution to using HalTimerConfig to not enter the timer callback function

Recently, I was learning Z-STACK. I used a timer in my program, but I didn't want to write a timer driver, so I wanted to try the timer driver that comes with the protocol stack. I let the timer's callback function It outputs some debugging information from the serial port, but after the program is executed, I did not find the debugging information I added from the serial port assistant.
I call the timer's initialization function in the APP initialization function as follows:

HalTimerConfig(HAL_TIMER_0,HAL_TIMER_MODE_NORMAL,HAL_TIMER_CHANNEL_SINGLE,HAL_TIMER_CH_MODE_OVERFLOW,1,(halTimerCBack_t)&TIMER0_ISR_Handler);

HalTimerStart(HAL_TIMER_0,1000);

I tried to connect to the emulator to see what I could find. I set a breakpoint in the timer callback, but the program did not execute there. I checked the register information of the timer and found that the timer was enabled, and the interrupt flag of the timer It is also set, then the problem can be locked on the timer interrupt. I checked the interrupt enable register of the timer and found that the interrupt enable bit of the timer is not set, then the cause of the problem is clear, it is the timing When the timer is initialized, the timer interrupt enable bit is not turned on, resulting in the timer's callback function not being executed.

I debugged the code that turns on the timer interrupt, the code is as follows:

uint8 HalTimerInterruptEnable (uint8 hwtimerid, uint8 channelMode, bool enable)
{ 
  switch (channelMode)
  {
    case HAL_TIMER_CH_MODE_OVERFLOW:

      if (enable)
      {
        *(halTimerChannel[hwtimerid].TxOVF) |= halTimerChannel[hwtimerid].ovfbit;
      }
      else
      {
        *(halTimerChannel[hwtimerid].TxOVF) &= ((halTimerChannel[hwtimerid].ovfbit) ^ 0xFF);
      }
      break;

    case HAL_TIMER_CH_MODE_OUTPUT_COMPARE:
    case HAL_TIMER_CH_MODE_INPUT_CAPTURE:

      if (enable)
      {
        *(halTimerChannel[hwtimerid].TxCCTL) |= T134CCTL_IM;
      }
      else
      {
        *(halTimerChannel[hwtimerid].TxCCTL) &= ~(T134CCTL_IM);
      }
      break;

    default:
      return HAL_TIMER_INVALID_CH_MODE;
  }

  if (halTimerRecord[hwtimerid].intEnable)
  {
    IEN1 |= halTimerChannel[hwtimerid].intbit;
  }
  else
  {
    IEN1 &= ((halTimerChannel[hwtimerid].intbit) ^ 0xFF);
  }
  return HAL_TIMER_OK;
}

When the program is executed IEN1 |= halTimerChannel[hwtimerid].intbit;, the interrupt enable flag of the timer is not set, so I tried to modify the program. The modified code is as follows:

uint8 HalTimerInterruptEnable (uint8 hwtimerid, uint8 channelMode, bool enable)
{ 
  uint8 timer_isr_param[HW_TIMER_MAX] = {IEN1_T1IE,IEN1_T3IE,IEN1_T4IE};

  switch (channelMode)
  {
    case HAL_TIMER_CH_MODE_OVERFLOW:

      if (enable)
      {
        *(halTimerChannel[hwtimerid].TxOVF) |= halTimerChannel[hwtimerid].ovfbit;
      }
      else
      {
        *(halTimerChannel[hwtimerid].TxOVF) &= ((halTimerChannel[hwtimerid].ovfbit) ^ 0xFF);
      }
      break;

    case HAL_TIMER_CH_MODE_OUTPUT_COMPARE:
    case HAL_TIMER_CH_MODE_INPUT_CAPTURE:

      if (enable)
      {
        *(halTimerChannel[hwtimerid].TxCCTL) |= T134CCTL_IM;
      }
      else
      {
        *(halTimerChannel[hwtimerid].TxCCTL) &= ~(T134CCTL_IM);
      }
      break;

    default:
      return HAL_TIMER_INVALID_CH_MODE;
  }

  if (halTimerRecord[hwtimerid].intEnable)
  {
//    IEN1 |= halTimerChannel[hwtimerid].intbit;
      IEN1 |= timer_isr_param[hwtimerid];
  }
  else
  {
//    IEN1 &= ((halTimerChannel[hwtimerid].intbit) ^ 0xFF);
      IEN1 &= ~timer_isr_param[hwtimerid];
  }
  return HAL_TIMER_OK;
}

Then I wrote the compiled program to the microcontroller, and found that the serial port has output debugging information.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325582107&siteId=291194637