]> granicus.if.org Git - esp-idf/commitdiff
esp_clk.h: add esp_clk_xtal_freq
authorIvan Grokhotkov <ivan@espressif.com>
Sun, 29 Jul 2018 06:34:49 +0000 (09:34 +0300)
committerIvan Grokhotkov <ivan@espressif.com>
Tue, 21 Aug 2018 05:02:03 +0000 (13:02 +0800)
This adds a user API for getting the XTAL frequency

components/esp32/clk.c
components/esp32/include/esp_clk.h

index 4b1f0369c7b56ee14ac8d24f2338ade5fc2de247..9b00977744a542d34c517d1afa8882240b553fe3 100644 (file)
@@ -109,12 +109,17 @@ void esp_clk_init(void)
 
 int IRAM_ATTR esp_clk_cpu_freq(void)
 {
-    return g_ticks_per_us_pro * 1000000;
+    return g_ticks_per_us_pro * MHZ;
 }
 
 int IRAM_ATTR esp_clk_apb_freq(void)
 {
-    return MIN(g_ticks_per_us_pro, 80) * 1000000;
+    return MIN(g_ticks_per_us_pro, 80) * MHZ;
+}
+
+int IRAM_ATTR esp_clk_xtal_freq(void)
+{
+    return rtc_clk_xtal_freq_get() * MHZ;
 }
 
 void IRAM_ATTR ets_update_cpu_frequency(uint32_t ticks_per_us)
index 6526aa92724fbdc98001dfab8739b9fa3b9a51a0..1a91d26f91c47bc91037b823b9b981b13cd9a3e7 100644 (file)
@@ -62,6 +62,17 @@ int esp_clk_cpu_freq(void);
  */
 int esp_clk_apb_freq(void);
 
+/**
+ * @brief Return frequency of the main XTAL
+ *
+ * Frequency of the main XTAL can be either auto-detected or set at compile
+ * time (see CONFIG_ESP32_XTAL_FREQ_SEL sdkconfig option). In both cases, this
+ * function returns the actual value at run time.
+ *
+ * @return XTAL frequency, in Hz
+ */
+int esp_clk_xtal_freq(void);
+
 
 /**
  * @brief Read value of RTC counter, converting it to microseconds