/* Calculate new CCOMPARE value based on s_ccount_{mul,div}. 
Adjusts CCOMPARE value so that the interrupt happens at the same time as it would happen without the frequency change. Assumes that the new_frequency = old_frequency * s_ccount_mul / s_ccount_div.  */
static void IRAM_ATTR update_ccompare()
/* Calculate new CCOMPARE value based on s_ccount_{mul,div}. 
Adjusts CCOMPARE value so that the interrupt happens at the same time as it would happen without the frequency change. Assumes that the new_frequency = old_frequency * s_ccount_mul / s_ccount_div.  */
static void IRAM_ATTR update_ccompare()
{
    uint32_t ccount = XTHAL_GET_CCOUNT();
    uint32_t ccompare = XTHAL_GET_CCOMPARE(XT_TIMER_INDEX);
    if ((ccompare - CCOMPARE_MIN_CYCLES_IN_FUTURE) - ccount < UINT32_MAX / 2) {
        uint32_t diff = ccompare - ccount;
        uint32_t diff_scaled = (diff * s_ccount_mul + s_ccount_div - 1) / s_ccount_div;
        if (diff_scaled < _xt_tick_divisor) {
            uint32_t new_ccompare = ccount + diff_scaled;
            XTHAL_SET_CCOMPARE(XT_TIMER_INDEX, new_ccompare);
        }
    }
}