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 
15 #include "esp_system.h"
16 #include "esp_attr.h"
17 
18 #include "soc/rtc.h"
19 
20 #include "freertos/FreeRTOS.h"
21 
22 #include "sdkconfig.h"
23 
24 #if CONFIG_IDF_TARGET_ESP32
25 #include "esp32/rtc.h"
26 #elif CONFIG_IDF_TARGET_ESP32S2
27 #include "esp32s2/rtc.h"
28 #elif CONFIG_IDF_TARGET_ESP32S3
29 #include "esp32s3/rtc.h"
30 #elif CONFIG_IDF_TARGET_ESP32C3
31 #include "esp32c3/rtc.h"
32 #elif CONFIG_IDF_TARGET_ESP32H2
33 #include "esp32h2/rtc.h"
34 #endif
35 
36 #include "esp_private/startup_internal.h"
37 
38 // A component in the build should provide strong implementations that make use of
39 // and actual hardware timer to provide timekeeping functions.
esp_system_get_time(void)40 int64_t IRAM_ATTR __attribute__((weak)) esp_system_get_time(void)
41 {
42     int64_t t = 0;
43     t = (esp_rtc_get_time_us() - g_startup_time);
44     return t;
45 }
46 
esp_system_get_time_resolution(void)47 uint32_t IRAM_ATTR __attribute__((weak)) esp_system_get_time_resolution(void)
48 {
49     return 1000000000L / rtc_clk_slow_freq_get_hz();
50 }
51