Ver código fonte

clk: Fix the overflow when setting ccount

The multiplication will be overflow when using 160 or 240 MHz, this can lead the inaccuracy of log time stamp in startup.
Wu Jian Gang 7 anos atrás
pai
commit
4d3762a8df
2 arquivos alterados com 2 adições e 2 exclusões
  1. 1 1
      components/esp32/clk.c
  2. 1 1
      components/soc/esp32/rtc_clk_init.c

+ 1 - 1
components/esp32/clk.c

@@ -136,7 +136,7 @@ void esp_clk_init(void)
     rtc_clk_cpu_freq_set_config(&new_config);
     rtc_clk_cpu_freq_set_config(&new_config);
 
 
     // Re calculate the ccount to make time calculation correct.
     // Re calculate the ccount to make time calculation correct.
-    XTHAL_SET_CCOUNT( XTHAL_GET_CCOUNT() * new_freq_mhz / old_freq_mhz );
+    XTHAL_SET_CCOUNT( (uint64_t)XTHAL_GET_CCOUNT() * new_freq_mhz / old_freq_mhz );
 }
 }
 
 
 int IRAM_ATTR esp_clk_cpu_freq(void)
 int IRAM_ATTR esp_clk_cpu_freq(void)

+ 1 - 1
components/soc/esp32/rtc_clk_init.c

@@ -128,7 +128,7 @@ void rtc_clk_init(rtc_clk_config_t cfg)
     REG_WRITE(APB_CTRL_PLL_TICK_CONF_REG, APB_CLK_FREQ / MHZ - 1); /* Under PLL, APB frequency is always 80MHz */
     REG_WRITE(APB_CTRL_PLL_TICK_CONF_REG, APB_CLK_FREQ / MHZ - 1); /* Under PLL, APB frequency is always 80MHz */
 
 
     /* Re-calculate the ccount to make time calculation correct. */
     /* Re-calculate the ccount to make time calculation correct. */
-    XTHAL_SET_CCOUNT( XTHAL_GET_CCOUNT() * cfg.cpu_freq_mhz / freq_before );
+    XTHAL_SET_CCOUNT( (uint64_t)XTHAL_GET_CCOUNT() * cfg.cpu_freq_mhz / freq_before );
 
 
     /* Slow & fast clocks setup */
     /* Slow & fast clocks setup */
     if (cfg.slow_freq == RTC_SLOW_FREQ_32K_XTAL) {
     if (cfg.slow_freq == RTC_SLOW_FREQ_32K_XTAL) {