system_time.c 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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_ESP32H2
  20. #include "esp32h2/rtc.h"
  21. #elif CONFIG_IDF_TARGET_ESP32C2
  22. #include "esp32c2/rtc.h"
  23. #endif
  24. #include "esp_private/startup_internal.h"
  25. // A component in the build should provide strong implementations that make use of
  26. // and actual hardware timer to provide timekeeping functions.
  27. int64_t IRAM_ATTR __attribute__((weak)) esp_system_get_time(void)
  28. {
  29. int64_t t = 0;
  30. t = (esp_rtc_get_time_us() - g_startup_time);
  31. return t;
  32. }
  33. uint32_t IRAM_ATTR __attribute__((weak)) esp_system_get_time_resolution(void)
  34. {
  35. return 1000000000L / rtc_clk_slow_freq_get_hz();
  36. }