mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-03 20:54:32 +02:00
newlib: move some functions to soc, esp32, esp32s2
This commit is contained in:
39
components/esp32/include/esp32/rtc.h
Normal file
39
components/esp32/include/esp32/rtc.h
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
// Copyright 2015-2017 Espressif Systems (Shanghai) PTE LTD
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file esp32/rtc.h
|
||||||
|
*
|
||||||
|
* This file contains declarations of rtc related functions.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get current value of RTC counter in microseconds
|
||||||
|
*
|
||||||
|
* Note: this function may take up to 1 RTC_SLOW_CLK cycle to execute
|
||||||
|
*
|
||||||
|
* @return current value of RTC counter in microseconds
|
||||||
|
*/
|
||||||
|
uint64_t esp_rtc_get_time_us(void);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
39
components/esp32s2/include/esp32s2/rtc.h
Normal file
39
components/esp32s2/include/esp32s2/rtc.h
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
// Copyright 2015-2017 Espressif Systems (Shanghai) PTE LTD
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file esp32s2/rtc.h
|
||||||
|
*
|
||||||
|
* This file contains declarations of rtc related functions.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get current value of RTC counter in microseconds
|
||||||
|
*
|
||||||
|
* Note: this function may take up to 1 RTC_SLOW_CLK cycle to execute
|
||||||
|
*
|
||||||
|
* @return current value of RTC counter in microseconds
|
||||||
|
*/
|
||||||
|
uint64_t esp_rtc_get_time_us(void);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
@@ -30,11 +30,13 @@
|
|||||||
#include "sdkconfig.h"
|
#include "sdkconfig.h"
|
||||||
|
|
||||||
#if CONFIG_IDF_TARGET_ESP32
|
#if CONFIG_IDF_TARGET_ESP32
|
||||||
|
#include "esp32/rtc.h"
|
||||||
#include "esp32/cache_err_int.h"
|
#include "esp32/cache_err_int.h"
|
||||||
#include "esp32/rom/cache.h"
|
#include "esp32/rom/cache.h"
|
||||||
#include "esp32/rom/rtc.h"
|
#include "esp32/rom/rtc.h"
|
||||||
#include "esp32/spiram.h"
|
#include "esp32/spiram.h"
|
||||||
#elif CONFIG_IDF_TARGET_ESP32S2
|
#elif CONFIG_IDF_TARGET_ESP32S2
|
||||||
|
#include "esp32s2/rtc.h"
|
||||||
#include "esp32s2/brownout.h"
|
#include "esp32s2/brownout.h"
|
||||||
#include "esp32s2/cache_err_int.h"
|
#include "esp32s2/cache_err_int.h"
|
||||||
#include "esp32s2/rom/cache.h"
|
#include "esp32s2/rom/cache.h"
|
||||||
|
@@ -30,9 +30,11 @@
|
|||||||
#if CONFIG_IDF_TARGET_ESP32
|
#if CONFIG_IDF_TARGET_ESP32
|
||||||
#include "esp32/rom/rtc.h"
|
#include "esp32/rom/rtc.h"
|
||||||
#include "esp32/clk.h"
|
#include "esp32/clk.h"
|
||||||
|
#include "esp32/rtc.h"
|
||||||
#elif CONFIG_IDF_TARGET_ESP32S2
|
#elif CONFIG_IDF_TARGET_ESP32S2
|
||||||
#include "esp32s2/rom/rtc.h"
|
#include "esp32s2/rom/rtc.h"
|
||||||
#include "esp32s2/clk.h"
|
#include "esp32s2/clk.h"
|
||||||
|
#include "esp32s2/rtc.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined( CONFIG_ESP32_TIME_SYSCALL_USE_RTC ) \
|
#if defined( CONFIG_ESP32_TIME_SYSCALL_USE_RTC ) \
|
||||||
@@ -61,29 +63,6 @@ static uint64_t s_boot_time; // when RTC is used to persist time, two RTC_STORE
|
|||||||
|
|
||||||
static spinlock_t s_time_lock = SPINLOCK_INITIALIZER;
|
static spinlock_t s_time_lock = SPINLOCK_INITIALIZER;
|
||||||
|
|
||||||
#ifdef WITH_RTC
|
|
||||||
static uint64_t get_rtc_time_us(void)
|
|
||||||
{
|
|
||||||
const uint64_t ticks = rtc_time_get();
|
|
||||||
const uint32_t cal = esp_clk_slowclk_cal_get();
|
|
||||||
/* RTC counter result is up to 2^48, calibration factor is up to 2^24,
|
|
||||||
* for a 32kHz clock. We need to calculate (assuming no overflow):
|
|
||||||
* (ticks * cal) >> RTC_CLK_CAL_FRACT
|
|
||||||
*
|
|
||||||
* An overflow in the (ticks * cal) multiplication would cause time to
|
|
||||||
* wrap around after approximately 13 days, which is probably not enough
|
|
||||||
* for some applications.
|
|
||||||
* Therefore multiplication is split into two terms, for the lower 32-bit
|
|
||||||
* and the upper 16-bit parts of "ticks", i.e.:
|
|
||||||
* ((ticks_low + 2^32 * ticks_high) * cal) >> RTC_CLK_CAL_FRACT
|
|
||||||
*/
|
|
||||||
const uint64_t ticks_low = ticks & UINT32_MAX;
|
|
||||||
const uint64_t ticks_high = ticks >> 32;
|
|
||||||
return ((ticks_low * cal) >> RTC_CLK_CAL_FRACT) +
|
|
||||||
((ticks_high * cal) << (32 - RTC_CLK_CAL_FRACT));
|
|
||||||
}
|
|
||||||
#endif // WITH_RTC
|
|
||||||
|
|
||||||
#if defined( WITH_FRC ) || defined( WITH_RTC )
|
#if defined( WITH_FRC ) || defined( WITH_RTC )
|
||||||
uint64_t esp_time_impl_get_time_since_boot(void)
|
uint64_t esp_time_impl_get_time_since_boot(void)
|
||||||
{
|
{
|
||||||
@@ -96,7 +75,7 @@ uint64_t esp_time_impl_get_time_since_boot(void)
|
|||||||
microseconds = esp_timer_get_time();
|
microseconds = esp_timer_get_time();
|
||||||
#endif // WITH_RTC
|
#endif // WITH_RTC
|
||||||
#elif defined(WITH_RTC)
|
#elif defined(WITH_RTC)
|
||||||
microseconds = get_rtc_time_us();
|
microseconds = esp_rtc_get_time_us();
|
||||||
#endif // WITH_FRC
|
#endif // WITH_FRC
|
||||||
return microseconds;
|
return microseconds;
|
||||||
}
|
}
|
||||||
@@ -106,7 +85,7 @@ uint64_t esp_time_impl_get_time(void)
|
|||||||
#if defined( WITH_FRC )
|
#if defined( WITH_FRC )
|
||||||
return esp_timer_get_time();
|
return esp_timer_get_time();
|
||||||
#elif defined( WITH_RTC )
|
#elif defined( WITH_RTC )
|
||||||
return get_rtc_time_us();
|
return esp_rtc_get_time_us();
|
||||||
#endif // WITH_FRC
|
#endif // WITH_FRC
|
||||||
}
|
}
|
||||||
#endif // defined( WITH_FRC ) || defined( WITH_RTC )
|
#endif // defined( WITH_FRC ) || defined( WITH_RTC )
|
||||||
@@ -151,6 +130,27 @@ uint32_t esp_clk_slowclk_cal_get(void)
|
|||||||
return REG_READ(RTC_SLOW_CLK_CAL_REG);
|
return REG_READ(RTC_SLOW_CLK_CAL_REG);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint64_t esp_rtc_get_time_us(void)
|
||||||
|
{
|
||||||
|
const uint64_t ticks = rtc_time_get();
|
||||||
|
const uint32_t cal = esp_clk_slowclk_cal_get();
|
||||||
|
/* RTC counter result is up to 2^48, calibration factor is up to 2^24,
|
||||||
|
* for a 32kHz clock. We need to calculate (assuming no overflow):
|
||||||
|
* (ticks * cal) >> RTC_CLK_CAL_FRACT
|
||||||
|
*
|
||||||
|
* An overflow in the (ticks * cal) multiplication would cause time to
|
||||||
|
* wrap around after approximately 13 days, which is probably not enough
|
||||||
|
* for some applications.
|
||||||
|
* Therefore multiplication is split into two terms, for the lower 32-bit
|
||||||
|
* and the upper 16-bit parts of "ticks", i.e.:
|
||||||
|
* ((ticks_low + 2^32 * ticks_high) * cal) >> RTC_CLK_CAL_FRACT
|
||||||
|
*/
|
||||||
|
const uint64_t ticks_low = ticks & UINT32_MAX;
|
||||||
|
const uint64_t ticks_high = ticks >> 32;
|
||||||
|
return ((ticks_low * cal) >> RTC_CLK_CAL_FRACT) +
|
||||||
|
((ticks_high * cal) << (32 - RTC_CLK_CAL_FRACT));
|
||||||
|
}
|
||||||
|
|
||||||
void esp_clk_slowclk_cal_set(uint32_t new_cal)
|
void esp_clk_slowclk_cal_set(uint32_t new_cal)
|
||||||
{
|
{
|
||||||
#if defined(WITH_RTC)
|
#if defined(WITH_RTC)
|
||||||
@@ -175,7 +175,7 @@ void esp_set_time_from_rtc(void)
|
|||||||
{
|
{
|
||||||
#if defined( WITH_FRC ) && defined( WITH_RTC )
|
#if defined( WITH_FRC ) && defined( WITH_RTC )
|
||||||
// initialize time from RTC clock
|
// initialize time from RTC clock
|
||||||
s_microseconds_offset = get_rtc_time_us() - esp_timer_get_time();
|
s_microseconds_offset = esp_rtc_get_time_us() - esp_timer_get_time();
|
||||||
#endif // WITH_FRC && WITH_RTC
|
#endif // WITH_FRC && WITH_RTC
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -185,7 +185,7 @@ void esp_sync_counters_rtc_and_frc(void)
|
|||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
gettimeofday(&tv, NULL);
|
gettimeofday(&tv, NULL);
|
||||||
settimeofday(&tv, NULL);
|
settimeofday(&tv, NULL);
|
||||||
int64_t s_microseconds_offset_cur = get_rtc_time_us() - esp_timer_get_time();
|
int64_t s_microseconds_offset_cur = esp_rtc_get_time_us() - esp_timer_get_time();
|
||||||
esp_time_impl_set_boot_time(esp_time_impl_get_boot_time() + ((int64_t)s_microseconds_offset - s_microseconds_offset_cur));
|
esp_time_impl_set_boot_time(esp_time_impl_get_boot_time() + ((int64_t)s_microseconds_offset - s_microseconds_offset_cur));
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@@ -645,6 +645,8 @@ rtc_vddsdio_config_t rtc_vddsdio_get_config(void);
|
|||||||
*/
|
*/
|
||||||
void rtc_vddsdio_set_config(rtc_vddsdio_config_t config);
|
void rtc_vddsdio_set_config(rtc_vddsdio_config_t config);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@@ -809,6 +809,7 @@ rtc_vddsdio_config_t rtc_vddsdio_get_config(void);
|
|||||||
*/
|
*/
|
||||||
void rtc_vddsdio_set_config(rtc_vddsdio_config_t config);
|
void rtc_vddsdio_set_config(rtc_vddsdio_config_t config);
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@@ -184,4 +184,3 @@ void rtc_clk_wait_for_slow_cycle(void) //This function may not by useful any mor
|
|||||||
esp_rom_delay_us(1);
|
esp_rom_delay_us(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user