system_time.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. #elif CONFIG_IDF_TARGET_ESP32H2
  28. #include "esp32h2/rtc.h"
  29. #endif
  30. #include "esp_private/startup_internal.h"
  31. // A component in the build should provide strong implementations that make use of
  32. // and actual hardware timer to provide timekeeping functions.
  33. int64_t IRAM_ATTR __attribute__((weak)) esp_system_get_time(void)
  34. {
  35. int64_t t = 0;
  36. t = (esp_rtc_get_time_us() - g_startup_time);
  37. return t;
  38. }
  39. uint32_t IRAM_ATTR __attribute__((weak)) esp_system_get_time_resolution(void)
  40. {
  41. return 1000000000L / rtc_clk_slow_freq_get_hz();
  42. }