]> granicus.if.org Git - esp-idf/commitdiff
soc/rtc: round APB clock frequency to nearest MHz
authorIvan Grokhotkov <ivan@espressif.com>
Mon, 21 Aug 2017 14:33:52 +0000 (22:33 +0800)
committerIvan Grokhotkov <ivan@espressif.com>
Fri, 1 Sep 2017 02:34:36 +0000 (10:34 +0800)
components/soc/esp32/rtc_clk.c

index 7f6d9929196248080f8a6ebba9c8944b48eb5405..aee0a39ff1ec605882d7b4e1281adf9ab0615b75 100644 (file)
@@ -500,7 +500,11 @@ void rtc_clk_apb_freq_update(uint32_t apb_freq)
 
 uint32_t rtc_clk_apb_freq_get()
 {
-    return reg_val_to_clk_val(READ_PERI_REG(RTC_APB_FREQ_REG)) << 12;
+    uint32_t freq_hz = reg_val_to_clk_val(READ_PERI_REG(RTC_APB_FREQ_REG)) << 12;
+    // round to the nearest MHz
+    freq_hz += MHZ / 2;
+    uint32_t remainder = freq_hz % MHZ;
+    return freq_hz - remainder;
 }