/************************************************************************************************** * @fn macMcuTimer2Isr * * @brief Interrupt service routine for timer2, the MAC timer. * * @param none * * @return none ************************************************************************************************** */ HAL_ISR_FUNCTION( macMcuTimer2Isr, T2_VECTOR ) { uint8 t2irqm; uint8 t2irqf; HAL_ENTER_ISR(); t2irqm = T2IRQM; t2irqf = T2IRQF; /*------------------------------------------------------------------------------------------------ * Overflow compare interrupt - triggers when then overflow counter is * equal to the overflow compare register. */ if ((t2irqf & TIMER2_OVF_COMPARE1F) & t2irqm) { /* call function for dealing with the timer compare interrupt */ macBackoffTimerCompareIsr(); /* clear overflow compare interrupt flag */ T2IRQF = ~TIMER2_OVF_COMPARE1F; } /*------------------------------------------------------------------------------------------------ * Overflow compare interrupt - triggers when then overflow counter is * equal to the overflow compare register. */ if ((t2irqf & TIMER2_OVF_PERF) & t2irqm) { /* call function for dealing with the timer compare interrupt */ macBackoffTimerPeriodIsr(); /* clear overflow compare interrupt flag */ T2IRQF = ~TIMER2_OVF_PERF; } /*------------------------------------------------------------------------------------------------ * Overflow interrupt - triggers when the hardware timer rolls over. */ else if ((t2irqf & TIMER2_PERF) & t2irqm) { /* call energy detect interrupt function, this interrupt not used for any other functionality */ mcuRecordMaxRssiIsr(); /* clear the interrupt flag */ T2IRQF = ~TIMER2_PERF; } CLEAR_SLEEP_MODE(); HAL_EXIT_ISR(); }
/************************************************************************************************** * @fn macMcuTimer2OverflowWorkaround * * @brief For CC2530, T2 interrupt won’t be generated when the current count is greater than * the comparator. The interrupt is only generated when the current count is equal to * the comparator. When the CC2530 is waking up from sleep, there is a small window * that the count may be grater than the comparator, therefore, missing the interrupt. * This workaround will call the T2 ISR when the current T2 count is greater than the * comparator. * * @param none * * @return none ************************************************************************************************** */ void macMcuTimer2OverflowWorkaround(void) { if (T2IRQM & TIMER2_OVF_COMPARE1F) { /* T2 comapre 1 interrupt is enabled but T2 compare 1 intererrupt is not generated */ if (!(T2IRQF & TIMER2_OVF_COMPARE1F)) { if (MAC_RADIO_BACKOFF_COUNT() > macMcuOverflowGetCompare()) { /* Set the flag to trigger the timer compare interrupt */ macBackoffTimerCompareIsr(); T2IRQF = ~TIMER2_OVF_COMPARE1F; } } } }