esp-idf/components/esp_system/system_time.c

47 lines
1.1 KiB
C
Raw Normal View History

/*
2022-01-17 21:32:56 -05:00
* SPDX-FileCopyrightText: 2020-2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "esp_system.h"
#include "esp_attr.h"
#include "soc/rtc.h"
#include "freertos/FreeRTOS.h"
#include "sdkconfig.h"
#if CONFIG_IDF_TARGET_ESP32
#include "esp32/rtc.h"
#elif CONFIG_IDF_TARGET_ESP32S2
#include "esp32s2/rtc.h"
2020-07-29 01:13:51 -04:00
#elif CONFIG_IDF_TARGET_ESP32S3
#include "esp32s3/rtc.h"
#elif CONFIG_IDF_TARGET_ESP32C3
#include "esp32c3/rtc.h"
2022-10-19 03:57:24 -04:00
#elif CONFIG_IDF_TARGET_ESP32H4
#include "esp32h4/rtc.h"
2022-01-17 21:32:56 -05:00
#elif CONFIG_IDF_TARGET_ESP32C2
#include "esp32c2/rtc.h"
2022-07-12 08:42:28 -04:00
#elif CONFIG_IDF_TARGET_ESP32C6
#include "esp32c6/rtc.h"
#endif
#include "esp_private/startup_internal.h"
// A component in the build should provide strong implementations that make use of
// and actual hardware timer to provide timekeeping functions.
int64_t IRAM_ATTR __attribute__((weak)) esp_system_get_time(void)
{
int64_t t = 0;
t = (esp_rtc_get_time_us() - g_startup_time);
return t;
}
uint32_t IRAM_ATTR __attribute__((weak)) esp_system_get_time_resolution(void)
{
return 1000000000L / rtc_clk_slow_freq_get_hz();
}