system_time.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*
  2. * SPDX-FileCopyrightText: 2020-2022 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #include "esp_system.h"
  7. #include "esp_attr.h"
  8. #include "soc/rtc.h"
  9. #include "freertos/FreeRTOS.h"
  10. #include "sdkconfig.h"
  11. #if CONFIG_IDF_TARGET_ESP32
  12. #include "esp32/rtc.h"
  13. #elif CONFIG_IDF_TARGET_ESP32S2
  14. #include "esp32s2/rtc.h"
  15. #elif CONFIG_IDF_TARGET_ESP32S3
  16. #include "esp32s3/rtc.h"
  17. #elif CONFIG_IDF_TARGET_ESP32C3
  18. #include "esp32c3/rtc.h"
  19. #elif CONFIG_IDF_TARGET_ESP32C2
  20. #include "esp32c2/rtc.h"
  21. #elif CONFIG_IDF_TARGET_ESP32C6
  22. #include "esp32c6/rtc.h"
  23. #elif CONFIG_IDF_TARGET_ESP32H2
  24. #include "esp32h2/rtc.h"
  25. #elif CONFIG_IDF_TARGET_ESP32P4
  26. #include "esp32p4/rtc.h"
  27. #endif
  28. #include "esp_private/startup_internal.h"
  29. // A component in the build should provide strong implementations that make use of
  30. // and actual hardware timer to provide timekeeping functions.
  31. int64_t IRAM_ATTR __attribute__((weak)) esp_system_get_time(void)
  32. {
  33. int64_t t = 0;
  34. t = (esp_rtc_get_time_us() - g_startup_time);
  35. return t;
  36. }
  37. uint32_t IRAM_ATTR __attribute__((weak)) esp_system_get_time_resolution(void)
  38. {
  39. return 1000000000L / rtc_clk_slow_freq_get_hz();
  40. }