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 "esp_osal/esp_osal.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 #endif 33 34 #include "esp_private/startup_internal.h" 35 36 // A component in the build should provide strong implementations that make use of 37 // and actual hardware timer to provide timekeeping functions. esp_system_get_time(void)38int64_t IRAM_ATTR __attribute__((weak)) esp_system_get_time(void) 39 { 40 int64_t t = 0; 41 t = (esp_rtc_get_time_us() - g_startup_time); 42 return t; 43 } 44 esp_system_get_time_resolution(void)45uint32_t IRAM_ATTR __attribute__((weak)) esp_system_get_time_resolution(void) 46 { 47 return 1000000000L / rtc_clk_slow_freq_get_hz(); 48 } 49