system_time.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // Copyright 2020 Espressif Systems (Shanghai) PTE LTD
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #include "esp_system.h"
  15. #include "esp_attr.h"
  16. #include "soc/rtc.h"
  17. #include "freertos/FreeRTOS.h"
  18. #include "sdkconfig.h"
  19. #if CONFIG_IDF_TARGET_ESP32
  20. #include "esp32/rtc.h"
  21. #elif CONFIG_IDF_TARGET_ESP32S2
  22. #include "esp32s2/rtc.h"
  23. #elif CONFIG_IDF_TARGET_ESP32S3
  24. #include "esp32s3/rtc.h"
  25. #elif CONFIG_IDF_TARGET_ESP32C3
  26. #include "esp32c3/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. }