Explorar o código

esp32: move esp_clk functions

Renz Bagaporo %!s(int64=5) %!d(string=hai) anos
pai
achega
e6edf34e82
Modificáronse 30 ficheiros con 180 adicións e 693 borrados
  1. 1 1
      components/bt/controller/esp32c3/bt.c
  2. 1 1
      components/bt/controller/esp32s3/bt.c
  3. 0 1
      components/esp32/CMakeLists.txt
  4. 0 52
      components/esp32/clk.c
  5. 1 2
      components/esp32c3/CMakeLists.txt
  6. 0 84
      components/esp32c3/include/esp32c3/clk.h
  7. 0 77
      components/esp32c3/include/esp_clk.h
  8. 0 1
      components/esp32s2/CMakeLists.txt
  9. 0 84
      components/esp32s2/include/esp32s2/clk.h
  10. 0 83
      components/esp32s2/include/esp_clk.h
  11. 1 2
      components/esp32s3/CMakeLists.txt
  12. 0 84
      components/esp32s3/include/esp32s3/clk.h
  13. 0 77
      components/esp32s3/include/esp_clk.h
  14. 2 2
      components/esp_hw_support/CMakeLists.txt
  15. 1 1
      components/esp_hw_support/component.mk
  16. 139 0
      components/esp_hw_support/esp_clk.c
  17. 0 0
      components/esp_hw_support/include/esp_clk.h
  18. 1 1
      components/esp_hw_support/include/esp_private/esp_clk.h
  19. 3 25
      components/esp_hw_support/include/soc/esp32/clk.h
  20. 3 25
      components/esp_hw_support/include/soc/esp32c3/clk.h
  21. 2 32
      components/esp_hw_support/include/soc/esp32s2/clk.h
  22. 16 0
      components/esp_hw_support/include/soc/esp32s3/clk.h
  23. 3 3
      components/esp_pm/linker.lf
  24. 1 0
      components/fatfs/test_fatfs_host/Makefile.files
  25. 0 55
      components/newlib/port/esp_time_impl.c
  26. 1 0
      components/spi_flash/flash_ops.c
  27. 1 0
      components/spi_flash/sim/Makefile.files
  28. 1 0
      components/spi_flash/sim/stubs/Makefile.files
  29. 1 0
      components/spiffs/test_spiffs_host/Makefile.files
  30. 1 0
      components/wear_levelling/test_wl_host/Makefile.files

+ 1 - 1
components/bt/controller/esp32c3/bt.c

@@ -40,7 +40,7 @@
 #include "soc/rtc.h"
 #include "soc/rtc_cntl_reg.h"
 #include "soc/soc_memory_layout.h"
-#include "esp_clk.h"
+#include "esp32c3/clk.h"
 #include "esp_coexist_internal.h"
 #include "esp32c3/rom/rom_layout.h"
 #include "esp_timer.h"

+ 1 - 1
components/bt/controller/esp32s3/bt.c

@@ -41,7 +41,7 @@
 #include "soc/rtc.h"
 #include "soc/rtc_cntl_reg.h"
 #include "soc/soc_memory_layout.h"
-#include "esp_clk.h"
+#include "esp32c3/clk.h"
 #include "esp_coexist_internal.h"
 
 #if CONFIG_BT_ENABLED

+ 0 - 1
components/esp32/CMakeLists.txt

@@ -13,7 +13,6 @@ else()
     # Regular app build
     set(srcs
         "cache_sram_mmu.c"
-        "clk.c"
         "dport_access.c"
         "esp_himem.c"
         "spiram.c"

+ 0 - 52
components/esp32/clk.c

@@ -1,52 +0,0 @@
-// Copyright 2015-2017 Espressif Systems (Shanghai) PTE LTD
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//     http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#include <stdint.h>
-#include <sys/param.h>
-
-#include "esp_attr.h"
-#include "soc/rtc.h"
-#include "esp32/clk.h"
-
-#define MHZ (1000000)
-
-// g_ticks_us defined in ROMs for PRO and APP CPU
-extern uint32_t g_ticks_per_us_pro;
-#ifndef CONFIG_FREERTOS_UNICORE
-extern uint32_t g_ticks_per_us_app;
-#endif
-
-int IRAM_ATTR esp_clk_cpu_freq(void)
-{
-    return g_ticks_per_us_pro * MHZ;
-}
-
-int IRAM_ATTR esp_clk_apb_freq(void)
-{
-    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)
-{
-    /* Update scale factors used by esp_rom_delay_us */
-    g_ticks_per_us_pro = ticks_per_us;
-#ifndef CONFIG_FREERTOS_UNICORE
-    g_ticks_per_us_app = ticks_per_us;
-#endif
-}

+ 1 - 2
components/esp32c3/CMakeLists.txt

@@ -11,8 +11,7 @@ if(BOOTLOADER_BUILD)
 else()
     # Regular app build
 
-    set(srcs "clk.c"
-             "dport_access.c"
+    set(srcs "dport_access.c"
              "esp_hmac.c"
              "esp_ds.c"
              "esp_crypto_lock.c"

+ 0 - 84
components/esp32c3/include/esp32c3/clk.h

@@ -1,84 +0,0 @@
-// Copyright 2015-2020 Espressif Systems (Shanghai) PTE LTD
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//     http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#pragma once
-#include <stdint.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/**
- * @file esp_clk.h
- *
- * This file contains declarations of clock related functions.
- */
-
-/**
- * @brief Get the calibration value of RTC slow clock
- *
- * The value is in the same format as returned by rtc_clk_cal (microseconds,
- * in Q13.19 fixed-point format).
- *
- * @return the calibration value obtained using rtc_clk_cal, at startup time
- */
-uint32_t esp_clk_slowclk_cal_get(void);
-
-/**
- * @brief Update the calibration value of RTC slow clock
- *
- * The value has to be in the same format as returned by rtc_clk_cal (microseconds,
- * in Q13.19 fixed-point format).
- * This value is used by timekeeping functions (such as gettimeofday) to
- * calculate current time based on RTC counter value.
- * @param value calibration value obtained using rtc_clk_cal
- */
-void esp_clk_slowclk_cal_set(uint32_t value);
-
-/**
- * @brief Return current CPU clock frequency
- * When frequency switching is performed, this frequency may change.
- * However it is guaranteed that the frequency never changes with a critical
- * section.
- *
- * @return CPU clock frequency, in Hz
- */
-int esp_clk_cpu_freq(void);
-
-/**
- * @brief Return current APB clock frequency
- *
- * When frequency switching is performed, this frequency may change.
- * However it is guaranteed that the frequency never changes with a critical
- * section.
- *
- * @return APB clock frequency, in Hz
- */
-int esp_clk_apb_freq(void);
-
-
-/**
- * @brief Read value of RTC counter, converting it to microseconds
- * @attention The value returned by this function may change abruptly when
- * calibration value of RTC counter is updated via esp_clk_slowclk_cal_set
- * function. This should not happen unless application calls esp_clk_slowclk_cal_set.
- * In ESP-IDF, esp_clk_slowclk_cal_set is only called in startup code.
- *
- * @return Value or RTC counter, expressed in microseconds
- */
-uint64_t esp_clk_rtc_time(void);
-
-#ifdef __cplusplus
-}
-#endif

+ 0 - 77
components/esp32c3/include/esp_clk.h

@@ -1,77 +0,0 @@
-// Copyright 2015-2020 Espressif Systems (Shanghai) PTE LTD
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//     http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#pragma once
-
-#include <stdint.h>
-
-/**
- * @file esp_clk.h
- *
- * This file contains declarations of clock related functions.
- */
-
-/**
- * @brief Get the calibration value of RTC slow clock
- *
- * The value is in the same format as returned by rtc_clk_cal (microseconds,
- * in Q13.19 fixed-point format).
- *
- * @return the calibration value obtained using rtc_clk_cal, at startup time
- */
-uint32_t esp_clk_slowclk_cal_get(void);
-
-/**
- * @brief Update the calibration value of RTC slow clock
- *
- * The value has to be in the same format as returned by rtc_clk_cal (microseconds,
- * in Q13.19 fixed-point format).
- * This value is used by timekeeping functions (such as gettimeofday) to
- * calculate current time based on RTC counter value.
- * @param value calibration value obtained using rtc_clk_cal
- */
-void esp_clk_slowclk_cal_set(uint32_t value);
-
-/**
- * @brief Return current CPU clock frequency
- * When frequency switching is performed, this frequency may change.
- * However it is guaranteed that the frequency never changes with a critical
- * section.
- *
- * @return CPU clock frequency, in Hz
- */
-int esp_clk_cpu_freq(void);
-
-/**
- * @brief Return current APB clock frequency
- *
- * When frequency switching is performed, this frequency may change.
- * However it is guaranteed that the frequency never changes with a critical
- * section.
- *
- * @return APB clock frequency, in Hz
- */
-int esp_clk_apb_freq(void);
-
-
-/**
- * @brief Read value of RTC counter, converting it to microseconds
- * @attention The value returned by this function may change abruptly when
- * calibration value of RTC counter is updated via esp_clk_slowclk_cal_set
- * function. This should not happen unless application calls esp_clk_slowclk_cal_set.
- * In ESP-IDF, esp_clk_slowclk_cal_set is only called in startup code.
- *
- * @return Value or RTC counter, expressed in microseconds
- */
-uint64_t esp_clk_rtc_time(void);

+ 0 - 1
components/esp32s2/CMakeLists.txt

@@ -12,7 +12,6 @@ else()
     # Regular app build
 
     set(srcs "memprot.c"
-             "clk.c"
              "dport_access.c"
              "spiram.c"
              "spiram_psram.c"

+ 0 - 84
components/esp32s2/include/esp32s2/clk.h

@@ -1,84 +0,0 @@
-// Copyright 2015-2017 Espressif Systems (Shanghai) PTE LTD
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//     http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#pragma once
-#include <stdint.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/**
- * @file esp_clk.h
- *
- * This file contains declarations of clock related functions.
- */
-
-/**
- * @brief Get the calibration value of RTC slow clock
- *
- * The value is in the same format as returned by rtc_clk_cal (microseconds,
- * in Q13.19 fixed-point format).
- *
- * @return the calibration value obtained using rtc_clk_cal, at startup time
- */
-uint32_t esp_clk_slowclk_cal_get(void);
-
-/**
- * @brief Update the calibration value of RTC slow clock
- *
- * The value has to be in the same format as returned by rtc_clk_cal (microseconds,
- * in Q13.19 fixed-point format).
- * This value is used by timekeeping functions (such as gettimeofday) to
- * calculate current time based on RTC counter value.
- * @param value calibration value obtained using rtc_clk_cal
- */
-void esp_clk_slowclk_cal_set(uint32_t value);
-
-/**
- * @brief Return current CPU clock frequency
- * When frequency switching is performed, this frequency may change.
- * However it is guaranteed that the frequency never changes with a critical
- * section.
- *
- * @return CPU clock frequency, in Hz
- */
-int esp_clk_cpu_freq(void);
-
-/**
- * @brief Return current APB clock frequency
- *
- * When frequency switching is performed, this frequency may change.
- * However it is guaranteed that the frequency never changes with a critical
- * section.
- *
- * @return APB clock frequency, in Hz
- */
-int esp_clk_apb_freq(void);
-
-
-/**
- * @brief Read value of RTC counter, converting it to microseconds
- * @attention The value returned by this function may change abruptly when
- * calibration value of RTC counter is updated via esp_clk_slowclk_cal_set
- * function. This should not happen unless application calls esp_clk_slowclk_cal_set.
- * In ESP-IDF, esp_clk_slowclk_cal_set is only called in startup code.
- *
- * @return Value or RTC counter, expressed in microseconds
- */
-uint64_t esp_clk_rtc_time(void);
-
-#ifdef __cplusplus
-}
-#endif

+ 0 - 83
components/esp32s2/include/esp_clk.h

@@ -1,83 +0,0 @@
-// Copyright 2015-2017 Espressif Systems (Shanghai) PTE LTD
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//     http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#pragma once
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/**
- * @file esp_clk.h
- *
- * This file contains declarations of clock related functions.
- */
-
-/**
- * @brief Get the calibration value of RTC slow clock
- *
- * The value is in the same format as returned by rtc_clk_cal (microseconds,
- * in Q13.19 fixed-point format).
- *
- * @return the calibration value obtained using rtc_clk_cal, at startup time
- */
-uint32_t esp_clk_slowclk_cal_get(void);
-
-/**
- * @brief Update the calibration value of RTC slow clock
- *
- * The value has to be in the same format as returned by rtc_clk_cal (microseconds,
- * in Q13.19 fixed-point format).
- * This value is used by timekeeping functions (such as gettimeofday) to
- * calculate current time based on RTC counter value.
- * @param value calibration value obtained using rtc_clk_cal
- */
-void esp_clk_slowclk_cal_set(uint32_t value);
-
-/**
- * @brief Return current CPU clock frequency
- * When frequency switching is performed, this frequency may change.
- * However it is guaranteed that the frequency never changes with a critical
- * section.
- *
- * @return CPU clock frequency, in Hz
- */
-int esp_clk_cpu_freq(void);
-
-/**
- * @brief Return current APB clock frequency
- *
- * When frequency switching is performed, this frequency may change.
- * However it is guaranteed that the frequency never changes with a critical
- * section.
- *
- * @return APB clock frequency, in Hz
- */
-int esp_clk_apb_freq(void);
-
-
-/**
- * @brief Read value of RTC counter, converting it to microseconds
- * @attention The value returned by this function may change abruptly when
- * calibration value of RTC counter is updated via esp_clk_slowclk_cal_set
- * function. This should not happen unless application calls esp_clk_slowclk_cal_set.
- * In ESP-IDF, esp_clk_slowclk_cal_set is only called in startup code.
- *
- * @return Value or RTC counter, expressed in microseconds
- */
-uint64_t esp_clk_rtc_time(void);
-
-#ifdef __cplusplus
-}
-#endif

+ 1 - 2
components/esp32s3/CMakeLists.txt

@@ -12,8 +12,7 @@ if(BOOTLOADER_BUILD)
 else()
     # Regular app build
 
-    set(srcs "clk.c"
-             "dport_access.c"
+    set(srcs "dport_access.c"
              "esp_crypto_lock.c"
              "memprot.c"
              "spiram.c"

+ 0 - 84
components/esp32s3/include/esp32s3/clk.h

@@ -1,84 +0,0 @@
-// Copyright 2015-2020 Espressif Systems (Shanghai) PTE LTD
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//     http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#pragma once
-#include <stdint.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/**
- * @file esp_clk.h
- *
- * This file contains declarations of clock related functions.
- */
-
-/**
- * @brief Get the calibration value of RTC slow clock
- *
- * The value is in the same format as returned by rtc_clk_cal (microseconds,
- * in Q13.19 fixed-point format).
- *
- * @return the calibration value obtained using rtc_clk_cal, at startup time
- */
-uint32_t esp_clk_slowclk_cal_get(void);
-
-/**
- * @brief Update the calibration value of RTC slow clock
- *
- * The value has to be in the same format as returned by rtc_clk_cal (microseconds,
- * in Q13.19 fixed-point format).
- * This value is used by timekeeping functions (such as gettimeofday) to
- * calculate current time based on RTC counter value.
- * @param value calibration value obtained using rtc_clk_cal
- */
-void esp_clk_slowclk_cal_set(uint32_t value);
-
-/**
- * @brief Return current CPU clock frequency
- * When frequency switching is performed, this frequency may change.
- * However it is guaranteed that the frequency never changes with a critical
- * section.
- *
- * @return CPU clock frequency, in Hz
- */
-int esp_clk_cpu_freq(void);
-
-/**
- * @brief Return current APB clock frequency
- *
- * When frequency switching is performed, this frequency may change.
- * However it is guaranteed that the frequency never changes with a critical
- * section.
- *
- * @return APB clock frequency, in Hz
- */
-int esp_clk_apb_freq(void);
-
-
-/**
- * @brief Read value of RTC counter, converting it to microseconds
- * @attention The value returned by this function may change abruptly when
- * calibration value of RTC counter is updated via esp_clk_slowclk_cal_set
- * function. This should not happen unless application calls esp_clk_slowclk_cal_set.
- * In ESP-IDF, esp_clk_slowclk_cal_set is only called in startup code.
- *
- * @return Value or RTC counter, expressed in microseconds
- */
-uint64_t esp_clk_rtc_time(void);
-
-#ifdef __cplusplus
-}
-#endif

+ 0 - 77
components/esp32s3/include/esp_clk.h

@@ -1,77 +0,0 @@
-// Copyright 2015-2020 Espressif Systems (Shanghai) PTE LTD
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//     http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#pragma once
-
-#include <stdint.h>
-
-/**
- * @file esp_clk.h
- *
- * This file contains declarations of clock related functions.
- */
-
-/**
- * @brief Get the calibration value of RTC slow clock
- *
- * The value is in the same format as returned by rtc_clk_cal (microseconds,
- * in Q13.19 fixed-point format).
- *
- * @return the calibration value obtained using rtc_clk_cal, at startup time
- */
-uint32_t esp_clk_slowclk_cal_get(void);
-
-/**
- * @brief Update the calibration value of RTC slow clock
- *
- * The value has to be in the same format as returned by rtc_clk_cal (microseconds,
- * in Q13.19 fixed-point format).
- * This value is used by timekeeping functions (such as gettimeofday) to
- * calculate current time based on RTC counter value.
- * @param value calibration value obtained using rtc_clk_cal
- */
-void esp_clk_slowclk_cal_set(uint32_t value);
-
-/**
- * @brief Return current CPU clock frequency
- * When frequency switching is performed, this frequency may change.
- * However it is guaranteed that the frequency never changes with a critical
- * section.
- *
- * @return CPU clock frequency, in Hz
- */
-int esp_clk_cpu_freq(void);
-
-/**
- * @brief Return current APB clock frequency
- *
- * When frequency switching is performed, this frequency may change.
- * However it is guaranteed that the frequency never changes with a critical
- * section.
- *
- * @return APB clock frequency, in Hz
- */
-int esp_clk_apb_freq(void);
-
-
-/**
- * @brief Read value of RTC counter, converting it to microseconds
- * @attention The value returned by this function may change abruptly when
- * calibration value of RTC counter is updated via esp_clk_slowclk_cal_set
- * function. This should not happen unless application calls esp_clk_slowclk_cal_set.
- * In ESP-IDF, esp_clk_slowclk_cal_set is only called in startup code.
- *
- * @return Value or RTC counter, expressed in microseconds
- */
-uint64_t esp_clk_rtc_time(void);

+ 2 - 2
components/esp_hw_support/CMakeLists.txt

@@ -7,11 +7,11 @@ endif()
 
 set(srcs "compare_set.c" "cpu_util.c")
 if(NOT BOOTLOADER_BUILD)
-    list(APPEND srcs "clk_ctrl_os.c" "mac_addr.c" "hw_random.c")
+    list(APPEND srcs "esp_clk.c" "clk_ctrl_os.c" "mac_addr.c" "hw_random.c")
 endif()
 
 idf_component_register(SRCS ${srcs}
-                       INCLUDE_DIRS include
+                       INCLUDE_DIRS include include/soc
                        REQUIRES ${requires}
                        PRIV_REQUIRES efuse
                        LDFRAGMENTS linker.lf)

+ 1 - 1
components/esp_hw_support/component.mk

@@ -1,5 +1,5 @@
 COMPONENT_SRCDIRS := . port/$(IDF_TARGET)
-COMPONENT_ADD_INCLUDEDIRS := . include port/$(IDF_TARGET)/private_include
+COMPONENT_ADD_INCLUDEDIRS := . include include/soc port/$(IDF_TARGET)/private_include
 COMPONENT_ADD_LDFRAGMENTS := linker.lf
 
 port/$(IDF_TARGET)/rtc_clk.o: CFLAGS += -fno-jump-tables -fno-tree-switch-conversion

+ 139 - 0
components/esp_hw_support/esp_clk.c

@@ -0,0 +1,139 @@
+// Copyright 2015-2017 Espressif Systems (Shanghai) PTE LTD
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include <stdint.h>
+#include <sys/param.h>
+
+#include "esp_attr.h"
+#include "soc/rtc.h"
+
+#if CONFIG_IDF_TARGET_ESP32
+#include "esp32/rom/rtc.h"
+#include "esp32/clk.h"
+#include "esp32/rtc.h"
+#elif CONFIG_IDF_TARGET_ESP32S2
+#include "esp32s2/rom/rtc.h"
+#include "esp32s2/clk.h"
+#include "esp32s2/rtc.h"
+#elif CONFIG_IDF_TARGET_ESP32S3
+#include "esp32s3/rom/rtc.h"
+#include "esp32s3/clk.h"
+#include "esp32s3/rtc.h"
+#include "esp32s3/rom/ets_sys.h"
+#elif CONFIG_IDF_TARGET_ESP32C3
+#include "esp32c3/rom/rtc.h"
+#include "esp32c3/clk.h"
+#include "esp32c3/rtc.h"
+#endif
+
+#define MHZ (1000000)
+
+// g_ticks_us defined in ROMs for PRO and APP CPU
+extern uint32_t g_ticks_per_us_pro;
+#if CONFIG_IDF_TARGET_ESP32
+#ifndef CONFIG_FREERTOS_UNICORE
+extern uint32_t g_ticks_per_us_app;
+#endif
+#endif
+
+static _lock_t s_esp_rtc_time_lock;
+static RTC_DATA_ATTR uint64_t s_esp_rtc_time_us = 0, s_rtc_last_ticks = 0;
+
+int IRAM_ATTR esp_clk_cpu_freq(void)
+{
+#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3
+    return ets_get_cpu_frequency() * MHZ;
+#else
+    return g_ticks_per_us_pro * MHZ;
+#endif
+}
+
+int IRAM_ATTR esp_clk_apb_freq(void)
+{
+#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3
+    return MIN(ets_get_cpu_frequency(), 81) * MHZ;
+#else
+    return MIN(g_ticks_per_us_pro, 80) * MHZ;
+#endif
+}
+
+int IRAM_ATTR esp_clk_xtal_freq(void)
+{
+    return rtc_clk_xtal_freq_get() * MHZ;
+}
+
+#ifndef CONFIG_IDF_TARGET_ESP32C3
+void IRAM_ATTR ets_update_cpu_frequency(uint32_t ticks_per_us)
+{
+    /* Update scale factors used by esp_rom_delay_us */
+    g_ticks_per_us_pro = ticks_per_us;
+#if CONFIG_IDF_TARGET_ESP32
+#ifndef CONFIG_FREERTOS_UNICORE
+    g_ticks_per_us_app = ticks_per_us;
+#endif
+#endif
+}
+#endif
+
+uint64_t esp_rtc_get_time_us(void)
+{
+    _lock_acquire(&s_esp_rtc_time_lock);
+    const uint32_t cal = esp_clk_slowclk_cal_get();
+    const uint64_t rtc_this_ticks = rtc_time_get();
+    const uint64_t ticks = rtc_this_ticks - s_rtc_last_ticks;
+    /* RTC counter result is up to 2^48, calibration factor is up to 2^24,
+     * for a 32kHz clock. We need to calculate (assuming no overflow):
+     *   (ticks * cal) >> RTC_CLK_CAL_FRACT
+     *
+     * An overflow in the (ticks * cal) multiplication would cause time to
+     * wrap around after approximately 13 days, which is probably not enough
+     * for some applications.
+     * Therefore multiplication is split into two terms, for the lower 32-bit
+     * and the upper 16-bit parts of "ticks", i.e.:
+     *   ((ticks_low + 2^32 * ticks_high) * cal) >> RTC_CLK_CAL_FRACT
+     */
+    const uint64_t ticks_low = ticks & UINT32_MAX;
+    const uint64_t ticks_high = ticks >> 32;
+    const uint64_t delta_time_us = ((ticks_low * cal) >> RTC_CLK_CAL_FRACT) +
+           ((ticks_high * cal) << (32 - RTC_CLK_CAL_FRACT));
+    s_esp_rtc_time_us += delta_time_us;
+    s_rtc_last_ticks = rtc_this_ticks;
+    _lock_release(&s_esp_rtc_time_lock);
+    return s_esp_rtc_time_us;
+}
+
+void esp_clk_slowclk_cal_set(uint32_t new_cal)
+{
+#if defined(CONFIG_ESP_TIME_FUNCS_USE_RTC_TIMER)
+    /* To force monotonic time values even when clock calibration value changes,
+     * we adjust esp_rtc_time
+     */
+    esp_rtc_get_time_us();
+#endif // CONFIG_ESP_TIME_FUNCS_USE_RTC_TIMER
+    REG_WRITE(RTC_SLOW_CLK_CAL_REG, new_cal);
+}
+
+uint32_t esp_clk_slowclk_cal_get(void)
+{
+    return REG_READ(RTC_SLOW_CLK_CAL_REG);
+}
+
+uint64_t esp_clk_rtc_time(void)
+{
+#ifdef CONFIG_ESP_TIME_FUNCS_USE_RTC_TIMER
+    return esp_rtc_get_time_us();
+#else
+    return 0;
+#endif
+}

+ 0 - 0
components/esp32/include/esp_clk.h → components/esp_hw_support/include/esp_clk.h


+ 1 - 1
components/esp32/include/esp32/clk.h → components/esp_hw_support/include/esp_private/esp_clk.h

@@ -20,7 +20,7 @@ extern "C" {
 #endif
 
 /**
- * @file esp32/clk.h
+ * @file esp_clk.h
  *
  * This file contains declarations of clock related functions.
  */

+ 3 - 25
components/esp32s3/clk.c → components/esp_hw_support/include/soc/esp32/clk.h

@@ -1,4 +1,4 @@
-// Copyright 2015-2020 Espressif Systems (Shanghai) PTE LTD
+// Copyright 2015-2017 Espressif Systems (Shanghai) PTE LTD
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
@@ -12,27 +12,5 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-#include <stdint.h>
-#include <sys/param.h>
-
-#include "esp_attr.h"
-#include "esp32s3/clk.h"
-#include "esp32s3/rom/ets_sys.h"
-#include "soc/rtc.h"
-
-#define MHZ (1000000)
-
-int IRAM_ATTR esp_clk_cpu_freq(void)
-{
-    return ets_get_cpu_frequency() * MHZ;
-}
-
-int IRAM_ATTR esp_clk_apb_freq(void)
-{
-    return MIN(ets_get_cpu_frequency(), 80) * MHZ;
-}
-
-int IRAM_ATTR esp_clk_xtal_freq(void)
-{
-    return rtc_clk_xtal_freq_get() * MHZ;
-}
+#pragma once
+#include "esp_private/esp_clk.h"

+ 3 - 25
components/esp32c3/clk.c → components/esp_hw_support/include/soc/esp32c3/clk.h

@@ -1,4 +1,4 @@
-// Copyright 2015-2020 Espressif Systems (Shanghai) PTE LTD
+// Copyright 2015-2017 Espressif Systems (Shanghai) PTE LTD
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
@@ -12,27 +12,5 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-#include <stdint.h>
-#include <sys/param.h>
-
-#include "esp_attr.h"
-#include "soc/rtc.h"
-#include "esp32c3/clk.h"
-#include "esp32c3/rom/ets_sys.h"
-
-#define MHZ (1000000)
-
-int IRAM_ATTR esp_clk_cpu_freq(void)
-{
-    return ets_get_cpu_frequency() * MHZ;
-}
-
-int IRAM_ATTR esp_clk_apb_freq(void)
-{
-    return MIN(80, ets_get_cpu_frequency()) * MHZ;
-}
-
-int IRAM_ATTR esp_clk_xtal_freq(void)
-{
-    return rtc_clk_xtal_freq_get() * MHZ;
-}
+#pragma once
+#include "esp_private/esp_clk.h"

+ 2 - 32
components/esp32s2/clk.c → components/esp_hw_support/include/soc/esp32s2/clk.h

@@ -12,35 +12,5 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-#include <stdint.h>
-#include <sys/param.h>
-
-#include "esp_attr.h"
-#include "soc/rtc.h"
-#include "esp32s2/clk.h"
-
-#define MHZ (1000000)
-
-// g_ticks_us defined in ROMs
-extern uint32_t g_ticks_per_us_pro;
-
-int IRAM_ATTR esp_clk_cpu_freq(void)
-{
-    return g_ticks_per_us_pro * MHZ;
-}
-
-int IRAM_ATTR esp_clk_apb_freq(void)
-{
-    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)
-{
-    /* Update scale factors used by esp_rom_delay_us */
-    g_ticks_per_us_pro = ticks_per_us;
-}
+#pragma once
+#include "esp_private/esp_clk.h"

+ 16 - 0
components/esp_hw_support/include/soc/esp32s3/clk.h

@@ -0,0 +1,16 @@
+// Copyright 2015-2017 Espressif Systems (Shanghai) PTE LTD
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#pragma once
+#include "esp_private/esp_clk.h"

+ 3 - 3
components/esp_pm/linker.lf

@@ -12,6 +12,9 @@ archive: libesp_hw_support.a
 entries:
     if PM_SLP_IRAM_OPT = y:
         rtc_init:rtc_vddsdio_get_config (noflash)
+        esp_clk:esp_clk_slowclk_cal_set (noflash)
+        esp_clk:esp_clk_slowclk_cal_get (noflash)
+        esp_clk:esp_rtc_get_time_us (noflash)
 
 [mapping:esp_system_pm]
 archive: libesp_system.a
@@ -47,9 +50,6 @@ entries:
     if PM_SLP_IRAM_OPT = y:
         esp_time_impl:esp_time_impl_set_boot_time (noflash)
         esp_time_impl:esp_time_impl_get_boot_time (noflash)
-        esp_time_impl:esp_clk_slowclk_cal_get (noflash)
-        esp_time_impl:esp_rtc_get_time_us (noflash)
-        esp_time_impl:esp_clk_slowclk_cal_set (noflash)
         esp_time_impl:esp_set_time_from_rtc (noflash)
 
 [mapping:driver_pm]

+ 1 - 0
components/fatfs/test_fatfs_host/Makefile.files

@@ -25,6 +25,7 @@ INCLUDE_DIRS := \
 	$(addprefix ../../../components/, \
 		esp_rom/include \
 		esp_hw_support/include \
+		esp_hw_support/include/soc \
 		esp_system/include \
 		xtensa/include \
 		xtensa/esp32/include \

+ 0 - 55
components/newlib/port/esp_time_impl.c

@@ -60,9 +60,6 @@ static uint64_t s_boot_time; // when RTC is used to persist time, two RTC_STORE
 
 static _lock_t s_boot_time_lock;
 
-static _lock_t s_esp_rtc_time_lock;
-static RTC_DATA_ATTR uint64_t s_esp_rtc_time_us = 0, s_rtc_last_ticks = 0;
-
 #if defined( CONFIG_ESP_TIME_FUNCS_USE_ESP_TIMER ) || defined( CONFIG_ESP_TIME_FUNCS_USE_RTC_TIMER )
 uint64_t esp_time_impl_get_time_since_boot(void)
 {
@@ -106,15 +103,6 @@ void esp_time_impl_set_boot_time(uint64_t time_us)
     _lock_release(&s_boot_time_lock);
 }
 
-uint64_t esp_clk_rtc_time(void)
-{
-#ifdef CONFIG_ESP_TIME_FUNCS_USE_RTC_TIMER
-    return esp_rtc_get_time_us();
-#else
-    return 0;
-#endif
-}
-
 uint64_t esp_time_impl_get_boot_time(void)
 {
     uint64_t result;
@@ -128,49 +116,6 @@ uint64_t esp_time_impl_get_boot_time(void)
     return result;
 }
 
-uint32_t esp_clk_slowclk_cal_get(void)
-{
-    return REG_READ(RTC_SLOW_CLK_CAL_REG);
-}
-
-uint64_t esp_rtc_get_time_us(void)
-{
-    _lock_acquire(&s_esp_rtc_time_lock);
-    const uint32_t cal = esp_clk_slowclk_cal_get();
-    const uint64_t rtc_this_ticks = rtc_time_get();
-    const uint64_t ticks = rtc_this_ticks - s_rtc_last_ticks;
-    /* RTC counter result is up to 2^48, calibration factor is up to 2^24,
-     * for a 32kHz clock. We need to calculate (assuming no overflow):
-     *   (ticks * cal) >> RTC_CLK_CAL_FRACT
-     *
-     * An overflow in the (ticks * cal) multiplication would cause time to
-     * wrap around after approximately 13 days, which is probably not enough
-     * for some applications.
-     * Therefore multiplication is split into two terms, for the lower 32-bit
-     * and the upper 16-bit parts of "ticks", i.e.:
-     *   ((ticks_low + 2^32 * ticks_high) * cal) >> RTC_CLK_CAL_FRACT
-     */
-    const uint64_t ticks_low = ticks & UINT32_MAX;
-    const uint64_t ticks_high = ticks >> 32;
-    const uint64_t delta_time_us = ((ticks_low * cal) >> RTC_CLK_CAL_FRACT) +
-           ((ticks_high * cal) << (32 - RTC_CLK_CAL_FRACT));
-    s_esp_rtc_time_us += delta_time_us;
-    s_rtc_last_ticks = rtc_this_ticks;
-    _lock_release(&s_esp_rtc_time_lock);
-    return s_esp_rtc_time_us;
-}
-
-void esp_clk_slowclk_cal_set(uint32_t new_cal)
-{
-#if defined(CONFIG_ESP_TIME_FUNCS_USE_RTC_TIMER)
-    /* To force monotonic time values even when clock calibration value changes,
-     * we adjust esp_rtc_time
-     */
-    esp_rtc_get_time_us();
-#endif // CONFIG_ESP_TIME_FUNCS_USE_RTC_TIMER
-    REG_WRITE(RTC_SLOW_CLK_CAL_REG, new_cal);
-}
-
 void esp_set_time_from_rtc(void)
 {
 #if defined( CONFIG_ESP_TIME_FUNCS_USE_ESP_TIMER ) && defined( CONFIG_ESP_TIME_FUNCS_USE_RTC_TIMER )

+ 1 - 0
components/spi_flash/flash_ops.c

@@ -40,6 +40,7 @@
 #include "esp32s3/rom/spi_flash.h"
 #include "esp32s3/rom/cache.h"
 #include "esp32s3/clk.h"
+#include "esp32s3/clk.h"
 #elif CONFIG_IDF_TARGET_ESP32C3
 #include "esp32c3/rom/cache.h"
 #include "esp32c3/rom/spi_flash.h"

+ 1 - 0
components/spi_flash/sim/Makefile.files

@@ -27,6 +27,7 @@ INCLUDE_DIRS := \
 	esp_rom/include \
 	esp_common/include \
 	esp_hw_support/include \
+	esp_hw_support/include/soc \
 	esp_system/include \
 	xtensa/include \
 	xtensa/esp32/include \

+ 1 - 0
components/spi_flash/sim/stubs/Makefile.files

@@ -21,6 +21,7 @@ INCLUDE_DIRS := \
 	$(addprefix ../../../../components/, \
 	esp_common/include \
 	esp_hw_support/include \
+	esp_hw_support/include/soc \
 	esp_system/include \
 	soc/esp32/include \
 	soc/include \

+ 1 - 0
components/spiffs/test_spiffs_host/Makefile.files

@@ -26,6 +26,7 @@ INCLUDE_DIRS := \
 	esp_rom/include \
 	esp_common/include \
 	esp_hw_support/include \
+	esp_hw_support/include/soc \
 	esp_system/include \
 	xtensa/include \
 	xtensa/esp32/include \

+ 1 - 0
components/wear_levelling/test_wl_host/Makefile.files

@@ -26,6 +26,7 @@ INCLUDE_DIRS := \
 	esp_system/include \
 	esp_common/include \
 	esp_hw_support/include \
+	esp_hw_support/include/soc \
 	xtensa/include \
 	xtensa/esp32/include \
 	soc/esp32/include \