forked from espressif/esp-idf
esp32: move esp_clk functions
This commit is contained in:
@@ -40,7 +40,7 @@
|
||||
#include "soc/rtc.h"
|
||||
#include "soc/rtc_cntl_reg.h"
|
||||
#include "soc/soc_memory_layout.h"
|
||||
#include "esp_clk.h"
|
||||
#include "esp32c3/clk.h"
|
||||
#include "esp_coexist_internal.h"
|
||||
#include "esp32c3/rom/rom_layout.h"
|
||||
#include "esp_timer.h"
|
||||
|
@@ -41,7 +41,7 @@
|
||||
#include "soc/rtc.h"
|
||||
#include "soc/rtc_cntl_reg.h"
|
||||
#include "soc/soc_memory_layout.h"
|
||||
#include "esp_clk.h"
|
||||
#include "esp32c3/clk.h"
|
||||
#include "esp_coexist_internal.h"
|
||||
|
||||
#if CONFIG_BT_ENABLED
|
||||
|
@@ -13,7 +13,6 @@ else()
|
||||
# Regular app build
|
||||
set(srcs
|
||||
"cache_sram_mmu.c"
|
||||
"clk.c"
|
||||
"dport_access.c"
|
||||
"esp_himem.c"
|
||||
"spiram.c"
|
||||
|
@@ -1,52 +0,0 @@
|
||||
// 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.
|
||||
|
||||
#include <stdint.h>
|
||||
#include <sys/param.h>
|
||||
|
||||
#include "esp_attr.h"
|
||||
#include "soc/rtc.h"
|
||||
#include "esp32/clk.h"
|
||||
|
||||
#define MHZ (1000000)
|
||||
|
||||
// g_ticks_us defined in ROMs for PRO and APP CPU
|
||||
extern uint32_t g_ticks_per_us_pro;
|
||||
#ifndef CONFIG_FREERTOS_UNICORE
|
||||
extern uint32_t g_ticks_per_us_app;
|
||||
#endif
|
||||
|
||||
int IRAM_ATTR esp_clk_cpu_freq(void)
|
||||
{
|
||||
return g_ticks_per_us_pro * MHZ;
|
||||
}
|
||||
|
||||
int IRAM_ATTR esp_clk_apb_freq(void)
|
||||
{
|
||||
return MIN(g_ticks_per_us_pro, 80) * MHZ;
|
||||
}
|
||||
|
||||
int IRAM_ATTR esp_clk_xtal_freq(void)
|
||||
{
|
||||
return rtc_clk_xtal_freq_get() * MHZ;
|
||||
}
|
||||
|
||||
void IRAM_ATTR ets_update_cpu_frequency(uint32_t ticks_per_us)
|
||||
{
|
||||
/* Update scale factors used by esp_rom_delay_us */
|
||||
g_ticks_per_us_pro = ticks_per_us;
|
||||
#ifndef CONFIG_FREERTOS_UNICORE
|
||||
g_ticks_per_us_app = ticks_per_us;
|
||||
#endif
|
||||
}
|
@@ -11,8 +11,7 @@ if(BOOTLOADER_BUILD)
|
||||
else()
|
||||
# Regular app build
|
||||
|
||||
set(srcs "clk.c"
|
||||
"dport_access.c"
|
||||
set(srcs "dport_access.c"
|
||||
"esp_hmac.c"
|
||||
"esp_ds.c"
|
||||
"esp_crypto_lock.c"
|
||||
|
@@ -1,84 +0,0 @@
|
||||
// Copyright 2015-2020 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 esp_clk.h
|
||||
*
|
||||
* This file contains declarations of clock related functions.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Get the calibration value of RTC slow clock
|
||||
*
|
||||
* The value is in the same format as returned by rtc_clk_cal (microseconds,
|
||||
* in Q13.19 fixed-point format).
|
||||
*
|
||||
* @return the calibration value obtained using rtc_clk_cal, at startup time
|
||||
*/
|
||||
uint32_t esp_clk_slowclk_cal_get(void);
|
||||
|
||||
/**
|
||||
* @brief Update the calibration value of RTC slow clock
|
||||
*
|
||||
* The value has to be in the same format as returned by rtc_clk_cal (microseconds,
|
||||
* in Q13.19 fixed-point format).
|
||||
* This value is used by timekeeping functions (such as gettimeofday) to
|
||||
* calculate current time based on RTC counter value.
|
||||
* @param value calibration value obtained using rtc_clk_cal
|
||||
*/
|
||||
void esp_clk_slowclk_cal_set(uint32_t value);
|
||||
|
||||
/**
|
||||
* @brief Return current CPU clock frequency
|
||||
* When frequency switching is performed, this frequency may change.
|
||||
* However it is guaranteed that the frequency never changes with a critical
|
||||
* section.
|
||||
*
|
||||
* @return CPU clock frequency, in Hz
|
||||
*/
|
||||
int esp_clk_cpu_freq(void);
|
||||
|
||||
/**
|
||||
* @brief Return current APB clock frequency
|
||||
*
|
||||
* When frequency switching is performed, this frequency may change.
|
||||
* However it is guaranteed that the frequency never changes with a critical
|
||||
* section.
|
||||
*
|
||||
* @return APB clock frequency, in Hz
|
||||
*/
|
||||
int esp_clk_apb_freq(void);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Read value of RTC counter, converting it to microseconds
|
||||
* @attention The value returned by this function may change abruptly when
|
||||
* calibration value of RTC counter is updated via esp_clk_slowclk_cal_set
|
||||
* function. This should not happen unless application calls esp_clk_slowclk_cal_set.
|
||||
* In ESP-IDF, esp_clk_slowclk_cal_set is only called in startup code.
|
||||
*
|
||||
* @return Value or RTC counter, expressed in microseconds
|
||||
*/
|
||||
uint64_t esp_clk_rtc_time(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
@@ -1,77 +0,0 @@
|
||||
// Copyright 2015-2020 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>
|
||||
|
||||
/**
|
||||
* @file esp_clk.h
|
||||
*
|
||||
* This file contains declarations of clock related functions.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Get the calibration value of RTC slow clock
|
||||
*
|
||||
* The value is in the same format as returned by rtc_clk_cal (microseconds,
|
||||
* in Q13.19 fixed-point format).
|
||||
*
|
||||
* @return the calibration value obtained using rtc_clk_cal, at startup time
|
||||
*/
|
||||
uint32_t esp_clk_slowclk_cal_get(void);
|
||||
|
||||
/**
|
||||
* @brief Update the calibration value of RTC slow clock
|
||||
*
|
||||
* The value has to be in the same format as returned by rtc_clk_cal (microseconds,
|
||||
* in Q13.19 fixed-point format).
|
||||
* This value is used by timekeeping functions (such as gettimeofday) to
|
||||
* calculate current time based on RTC counter value.
|
||||
* @param value calibration value obtained using rtc_clk_cal
|
||||
*/
|
||||
void esp_clk_slowclk_cal_set(uint32_t value);
|
||||
|
||||
/**
|
||||
* @brief Return current CPU clock frequency
|
||||
* When frequency switching is performed, this frequency may change.
|
||||
* However it is guaranteed that the frequency never changes with a critical
|
||||
* section.
|
||||
*
|
||||
* @return CPU clock frequency, in Hz
|
||||
*/
|
||||
int esp_clk_cpu_freq(void);
|
||||
|
||||
/**
|
||||
* @brief Return current APB clock frequency
|
||||
*
|
||||
* When frequency switching is performed, this frequency may change.
|
||||
* However it is guaranteed that the frequency never changes with a critical
|
||||
* section.
|
||||
*
|
||||
* @return APB clock frequency, in Hz
|
||||
*/
|
||||
int esp_clk_apb_freq(void);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Read value of RTC counter, converting it to microseconds
|
||||
* @attention The value returned by this function may change abruptly when
|
||||
* calibration value of RTC counter is updated via esp_clk_slowclk_cal_set
|
||||
* function. This should not happen unless application calls esp_clk_slowclk_cal_set.
|
||||
* In ESP-IDF, esp_clk_slowclk_cal_set is only called in startup code.
|
||||
*
|
||||
* @return Value or RTC counter, expressed in microseconds
|
||||
*/
|
||||
uint64_t esp_clk_rtc_time(void);
|
@@ -12,7 +12,6 @@ else()
|
||||
# Regular app build
|
||||
|
||||
set(srcs "memprot.c"
|
||||
"clk.c"
|
||||
"dport_access.c"
|
||||
"spiram.c"
|
||||
"spiram_psram.c"
|
||||
|
@@ -1,84 +0,0 @@
|
||||
// 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 esp_clk.h
|
||||
*
|
||||
* This file contains declarations of clock related functions.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Get the calibration value of RTC slow clock
|
||||
*
|
||||
* The value is in the same format as returned by rtc_clk_cal (microseconds,
|
||||
* in Q13.19 fixed-point format).
|
||||
*
|
||||
* @return the calibration value obtained using rtc_clk_cal, at startup time
|
||||
*/
|
||||
uint32_t esp_clk_slowclk_cal_get(void);
|
||||
|
||||
/**
|
||||
* @brief Update the calibration value of RTC slow clock
|
||||
*
|
||||
* The value has to be in the same format as returned by rtc_clk_cal (microseconds,
|
||||
* in Q13.19 fixed-point format).
|
||||
* This value is used by timekeeping functions (such as gettimeofday) to
|
||||
* calculate current time based on RTC counter value.
|
||||
* @param value calibration value obtained using rtc_clk_cal
|
||||
*/
|
||||
void esp_clk_slowclk_cal_set(uint32_t value);
|
||||
|
||||
/**
|
||||
* @brief Return current CPU clock frequency
|
||||
* When frequency switching is performed, this frequency may change.
|
||||
* However it is guaranteed that the frequency never changes with a critical
|
||||
* section.
|
||||
*
|
||||
* @return CPU clock frequency, in Hz
|
||||
*/
|
||||
int esp_clk_cpu_freq(void);
|
||||
|
||||
/**
|
||||
* @brief Return current APB clock frequency
|
||||
*
|
||||
* When frequency switching is performed, this frequency may change.
|
||||
* However it is guaranteed that the frequency never changes with a critical
|
||||
* section.
|
||||
*
|
||||
* @return APB clock frequency, in Hz
|
||||
*/
|
||||
int esp_clk_apb_freq(void);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Read value of RTC counter, converting it to microseconds
|
||||
* @attention The value returned by this function may change abruptly when
|
||||
* calibration value of RTC counter is updated via esp_clk_slowclk_cal_set
|
||||
* function. This should not happen unless application calls esp_clk_slowclk_cal_set.
|
||||
* In ESP-IDF, esp_clk_slowclk_cal_set is only called in startup code.
|
||||
*
|
||||
* @return Value or RTC counter, expressed in microseconds
|
||||
*/
|
||||
uint64_t esp_clk_rtc_time(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
@@ -1,83 +0,0 @@
|
||||
// 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
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @file esp_clk.h
|
||||
*
|
||||
* This file contains declarations of clock related functions.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Get the calibration value of RTC slow clock
|
||||
*
|
||||
* The value is in the same format as returned by rtc_clk_cal (microseconds,
|
||||
* in Q13.19 fixed-point format).
|
||||
*
|
||||
* @return the calibration value obtained using rtc_clk_cal, at startup time
|
||||
*/
|
||||
uint32_t esp_clk_slowclk_cal_get(void);
|
||||
|
||||
/**
|
||||
* @brief Update the calibration value of RTC slow clock
|
||||
*
|
||||
* The value has to be in the same format as returned by rtc_clk_cal (microseconds,
|
||||
* in Q13.19 fixed-point format).
|
||||
* This value is used by timekeeping functions (such as gettimeofday) to
|
||||
* calculate current time based on RTC counter value.
|
||||
* @param value calibration value obtained using rtc_clk_cal
|
||||
*/
|
||||
void esp_clk_slowclk_cal_set(uint32_t value);
|
||||
|
||||
/**
|
||||
* @brief Return current CPU clock frequency
|
||||
* When frequency switching is performed, this frequency may change.
|
||||
* However it is guaranteed that the frequency never changes with a critical
|
||||
* section.
|
||||
*
|
||||
* @return CPU clock frequency, in Hz
|
||||
*/
|
||||
int esp_clk_cpu_freq(void);
|
||||
|
||||
/**
|
||||
* @brief Return current APB clock frequency
|
||||
*
|
||||
* When frequency switching is performed, this frequency may change.
|
||||
* However it is guaranteed that the frequency never changes with a critical
|
||||
* section.
|
||||
*
|
||||
* @return APB clock frequency, in Hz
|
||||
*/
|
||||
int esp_clk_apb_freq(void);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Read value of RTC counter, converting it to microseconds
|
||||
* @attention The value returned by this function may change abruptly when
|
||||
* calibration value of RTC counter is updated via esp_clk_slowclk_cal_set
|
||||
* function. This should not happen unless application calls esp_clk_slowclk_cal_set.
|
||||
* In ESP-IDF, esp_clk_slowclk_cal_set is only called in startup code.
|
||||
*
|
||||
* @return Value or RTC counter, expressed in microseconds
|
||||
*/
|
||||
uint64_t esp_clk_rtc_time(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
@@ -12,8 +12,7 @@ if(BOOTLOADER_BUILD)
|
||||
else()
|
||||
# Regular app build
|
||||
|
||||
set(srcs "clk.c"
|
||||
"dport_access.c"
|
||||
set(srcs "dport_access.c"
|
||||
"esp_crypto_lock.c"
|
||||
"memprot.c"
|
||||
"spiram.c"
|
||||
|
@@ -1,84 +0,0 @@
|
||||
// Copyright 2015-2020 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 esp_clk.h
|
||||
*
|
||||
* This file contains declarations of clock related functions.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Get the calibration value of RTC slow clock
|
||||
*
|
||||
* The value is in the same format as returned by rtc_clk_cal (microseconds,
|
||||
* in Q13.19 fixed-point format).
|
||||
*
|
||||
* @return the calibration value obtained using rtc_clk_cal, at startup time
|
||||
*/
|
||||
uint32_t esp_clk_slowclk_cal_get(void);
|
||||
|
||||
/**
|
||||
* @brief Update the calibration value of RTC slow clock
|
||||
*
|
||||
* The value has to be in the same format as returned by rtc_clk_cal (microseconds,
|
||||
* in Q13.19 fixed-point format).
|
||||
* This value is used by timekeeping functions (such as gettimeofday) to
|
||||
* calculate current time based on RTC counter value.
|
||||
* @param value calibration value obtained using rtc_clk_cal
|
||||
*/
|
||||
void esp_clk_slowclk_cal_set(uint32_t value);
|
||||
|
||||
/**
|
||||
* @brief Return current CPU clock frequency
|
||||
* When frequency switching is performed, this frequency may change.
|
||||
* However it is guaranteed that the frequency never changes with a critical
|
||||
* section.
|
||||
*
|
||||
* @return CPU clock frequency, in Hz
|
||||
*/
|
||||
int esp_clk_cpu_freq(void);
|
||||
|
||||
/**
|
||||
* @brief Return current APB clock frequency
|
||||
*
|
||||
* When frequency switching is performed, this frequency may change.
|
||||
* However it is guaranteed that the frequency never changes with a critical
|
||||
* section.
|
||||
*
|
||||
* @return APB clock frequency, in Hz
|
||||
*/
|
||||
int esp_clk_apb_freq(void);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Read value of RTC counter, converting it to microseconds
|
||||
* @attention The value returned by this function may change abruptly when
|
||||
* calibration value of RTC counter is updated via esp_clk_slowclk_cal_set
|
||||
* function. This should not happen unless application calls esp_clk_slowclk_cal_set.
|
||||
* In ESP-IDF, esp_clk_slowclk_cal_set is only called in startup code.
|
||||
*
|
||||
* @return Value or RTC counter, expressed in microseconds
|
||||
*/
|
||||
uint64_t esp_clk_rtc_time(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
@@ -1,77 +0,0 @@
|
||||
// Copyright 2015-2020 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>
|
||||
|
||||
/**
|
||||
* @file esp_clk.h
|
||||
*
|
||||
* This file contains declarations of clock related functions.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Get the calibration value of RTC slow clock
|
||||
*
|
||||
* The value is in the same format as returned by rtc_clk_cal (microseconds,
|
||||
* in Q13.19 fixed-point format).
|
||||
*
|
||||
* @return the calibration value obtained using rtc_clk_cal, at startup time
|
||||
*/
|
||||
uint32_t esp_clk_slowclk_cal_get(void);
|
||||
|
||||
/**
|
||||
* @brief Update the calibration value of RTC slow clock
|
||||
*
|
||||
* The value has to be in the same format as returned by rtc_clk_cal (microseconds,
|
||||
* in Q13.19 fixed-point format).
|
||||
* This value is used by timekeeping functions (such as gettimeofday) to
|
||||
* calculate current time based on RTC counter value.
|
||||
* @param value calibration value obtained using rtc_clk_cal
|
||||
*/
|
||||
void esp_clk_slowclk_cal_set(uint32_t value);
|
||||
|
||||
/**
|
||||
* @brief Return current CPU clock frequency
|
||||
* When frequency switching is performed, this frequency may change.
|
||||
* However it is guaranteed that the frequency never changes with a critical
|
||||
* section.
|
||||
*
|
||||
* @return CPU clock frequency, in Hz
|
||||
*/
|
||||
int esp_clk_cpu_freq(void);
|
||||
|
||||
/**
|
||||
* @brief Return current APB clock frequency
|
||||
*
|
||||
* When frequency switching is performed, this frequency may change.
|
||||
* However it is guaranteed that the frequency never changes with a critical
|
||||
* section.
|
||||
*
|
||||
* @return APB clock frequency, in Hz
|
||||
*/
|
||||
int esp_clk_apb_freq(void);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Read value of RTC counter, converting it to microseconds
|
||||
* @attention The value returned by this function may change abruptly when
|
||||
* calibration value of RTC counter is updated via esp_clk_slowclk_cal_set
|
||||
* function. This should not happen unless application calls esp_clk_slowclk_cal_set.
|
||||
* In ESP-IDF, esp_clk_slowclk_cal_set is only called in startup code.
|
||||
*
|
||||
* @return Value or RTC counter, expressed in microseconds
|
||||
*/
|
||||
uint64_t esp_clk_rtc_time(void);
|
@@ -7,11 +7,11 @@ endif()
|
||||
|
||||
set(srcs "compare_set.c" "cpu_util.c")
|
||||
if(NOT BOOTLOADER_BUILD)
|
||||
list(APPEND srcs "clk_ctrl_os.c" "mac_addr.c" "hw_random.c")
|
||||
list(APPEND srcs "esp_clk.c" "clk_ctrl_os.c" "mac_addr.c" "hw_random.c")
|
||||
endif()
|
||||
|
||||
idf_component_register(SRCS ${srcs}
|
||||
INCLUDE_DIRS include
|
||||
INCLUDE_DIRS include include/soc
|
||||
REQUIRES ${requires}
|
||||
PRIV_REQUIRES efuse
|
||||
LDFRAGMENTS linker.lf)
|
||||
|
@@ -1,5 +1,5 @@
|
||||
COMPONENT_SRCDIRS := . port/$(IDF_TARGET)
|
||||
COMPONENT_ADD_INCLUDEDIRS := . include port/$(IDF_TARGET)/private_include
|
||||
COMPONENT_ADD_INCLUDEDIRS := . include include/soc port/$(IDF_TARGET)/private_include
|
||||
COMPONENT_ADD_LDFRAGMENTS := linker.lf
|
||||
|
||||
port/$(IDF_TARGET)/rtc_clk.o: CFLAGS += -fno-jump-tables -fno-tree-switch-conversion
|
||||
|
139
components/esp_hw_support/esp_clk.c
Normal file
139
components/esp_hw_support/esp_clk.c
Normal file
@@ -0,0 +1,139 @@
|
||||
// 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.
|
||||
|
||||
#include <stdint.h>
|
||||
#include <sys/param.h>
|
||||
|
||||
#include "esp_attr.h"
|
||||
#include "soc/rtc.h"
|
||||
|
||||
#if CONFIG_IDF_TARGET_ESP32
|
||||
#include "esp32/rom/rtc.h"
|
||||
#include "esp32/clk.h"
|
||||
#include "esp32/rtc.h"
|
||||
#elif CONFIG_IDF_TARGET_ESP32S2
|
||||
#include "esp32s2/rom/rtc.h"
|
||||
#include "esp32s2/clk.h"
|
||||
#include "esp32s2/rtc.h"
|
||||
#elif CONFIG_IDF_TARGET_ESP32S3
|
||||
#include "esp32s3/rom/rtc.h"
|
||||
#include "esp32s3/clk.h"
|
||||
#include "esp32s3/rtc.h"
|
||||
#include "esp32s3/rom/ets_sys.h"
|
||||
#elif CONFIG_IDF_TARGET_ESP32C3
|
||||
#include "esp32c3/rom/rtc.h"
|
||||
#include "esp32c3/clk.h"
|
||||
#include "esp32c3/rtc.h"
|
||||
#endif
|
||||
|
||||
#define MHZ (1000000)
|
||||
|
||||
// g_ticks_us defined in ROMs for PRO and APP CPU
|
||||
extern uint32_t g_ticks_per_us_pro;
|
||||
#if CONFIG_IDF_TARGET_ESP32
|
||||
#ifndef CONFIG_FREERTOS_UNICORE
|
||||
extern uint32_t g_ticks_per_us_app;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
static _lock_t s_esp_rtc_time_lock;
|
||||
static RTC_DATA_ATTR uint64_t s_esp_rtc_time_us = 0, s_rtc_last_ticks = 0;
|
||||
|
||||
int IRAM_ATTR esp_clk_cpu_freq(void)
|
||||
{
|
||||
#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3
|
||||
return ets_get_cpu_frequency() * MHZ;
|
||||
#else
|
||||
return g_ticks_per_us_pro * MHZ;
|
||||
#endif
|
||||
}
|
||||
|
||||
int IRAM_ATTR esp_clk_apb_freq(void)
|
||||
{
|
||||
#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3
|
||||
return MIN(ets_get_cpu_frequency(), 81) * MHZ;
|
||||
#else
|
||||
return MIN(g_ticks_per_us_pro, 80) * MHZ;
|
||||
#endif
|
||||
}
|
||||
|
||||
int IRAM_ATTR esp_clk_xtal_freq(void)
|
||||
{
|
||||
return rtc_clk_xtal_freq_get() * MHZ;
|
||||
}
|
||||
|
||||
#ifndef CONFIG_IDF_TARGET_ESP32C3
|
||||
void IRAM_ATTR ets_update_cpu_frequency(uint32_t ticks_per_us)
|
||||
{
|
||||
/* Update scale factors used by esp_rom_delay_us */
|
||||
g_ticks_per_us_pro = ticks_per_us;
|
||||
#if CONFIG_IDF_TARGET_ESP32
|
||||
#ifndef CONFIG_FREERTOS_UNICORE
|
||||
g_ticks_per_us_app = ticks_per_us;
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
uint64_t esp_rtc_get_time_us(void)
|
||||
{
|
||||
_lock_acquire(&s_esp_rtc_time_lock);
|
||||
const uint32_t cal = esp_clk_slowclk_cal_get();
|
||||
const uint64_t rtc_this_ticks = rtc_time_get();
|
||||
const uint64_t ticks = rtc_this_ticks - s_rtc_last_ticks;
|
||||
/* 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;
|
||||
const uint64_t delta_time_us = ((ticks_low * cal) >> RTC_CLK_CAL_FRACT) +
|
||||
((ticks_high * cal) << (32 - RTC_CLK_CAL_FRACT));
|
||||
s_esp_rtc_time_us += delta_time_us;
|
||||
s_rtc_last_ticks = rtc_this_ticks;
|
||||
_lock_release(&s_esp_rtc_time_lock);
|
||||
return s_esp_rtc_time_us;
|
||||
}
|
||||
|
||||
void esp_clk_slowclk_cal_set(uint32_t new_cal)
|
||||
{
|
||||
#if defined(CONFIG_ESP_TIME_FUNCS_USE_RTC_TIMER)
|
||||
/* To force monotonic time values even when clock calibration value changes,
|
||||
* we adjust esp_rtc_time
|
||||
*/
|
||||
esp_rtc_get_time_us();
|
||||
#endif // CONFIG_ESP_TIME_FUNCS_USE_RTC_TIMER
|
||||
REG_WRITE(RTC_SLOW_CLK_CAL_REG, new_cal);
|
||||
}
|
||||
|
||||
uint32_t esp_clk_slowclk_cal_get(void)
|
||||
{
|
||||
return REG_READ(RTC_SLOW_CLK_CAL_REG);
|
||||
}
|
||||
|
||||
uint64_t esp_clk_rtc_time(void)
|
||||
{
|
||||
#ifdef CONFIG_ESP_TIME_FUNCS_USE_RTC_TIMER
|
||||
return esp_rtc_get_time_us();
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
@@ -20,7 +20,7 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @file esp32/clk.h
|
||||
* @file esp_clk.h
|
||||
*
|
||||
* This file contains declarations of clock related functions.
|
||||
*/
|
@@ -1,4 +1,4 @@
|
||||
// Copyright 2015-2020 Espressif Systems (Shanghai) PTE LTD
|
||||
// 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.
|
||||
@@ -12,27 +12,5 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <stdint.h>
|
||||
#include <sys/param.h>
|
||||
|
||||
#include "esp_attr.h"
|
||||
#include "esp32s3/clk.h"
|
||||
#include "esp32s3/rom/ets_sys.h"
|
||||
#include "soc/rtc.h"
|
||||
|
||||
#define MHZ (1000000)
|
||||
|
||||
int IRAM_ATTR esp_clk_cpu_freq(void)
|
||||
{
|
||||
return ets_get_cpu_frequency() * MHZ;
|
||||
}
|
||||
|
||||
int IRAM_ATTR esp_clk_apb_freq(void)
|
||||
{
|
||||
return MIN(ets_get_cpu_frequency(), 80) * MHZ;
|
||||
}
|
||||
|
||||
int IRAM_ATTR esp_clk_xtal_freq(void)
|
||||
{
|
||||
return rtc_clk_xtal_freq_get() * MHZ;
|
||||
}
|
||||
#pragma once
|
||||
#include "esp_private/esp_clk.h"
|
@@ -1,4 +1,4 @@
|
||||
// Copyright 2015-2020 Espressif Systems (Shanghai) PTE LTD
|
||||
// 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.
|
||||
@@ -12,27 +12,5 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <stdint.h>
|
||||
#include <sys/param.h>
|
||||
|
||||
#include "esp_attr.h"
|
||||
#include "soc/rtc.h"
|
||||
#include "esp32c3/clk.h"
|
||||
#include "esp32c3/rom/ets_sys.h"
|
||||
|
||||
#define MHZ (1000000)
|
||||
|
||||
int IRAM_ATTR esp_clk_cpu_freq(void)
|
||||
{
|
||||
return ets_get_cpu_frequency() * MHZ;
|
||||
}
|
||||
|
||||
int IRAM_ATTR esp_clk_apb_freq(void)
|
||||
{
|
||||
return MIN(80, ets_get_cpu_frequency()) * MHZ;
|
||||
}
|
||||
|
||||
int IRAM_ATTR esp_clk_xtal_freq(void)
|
||||
{
|
||||
return rtc_clk_xtal_freq_get() * MHZ;
|
||||
}
|
||||
#pragma once
|
||||
#include "esp_private/esp_clk.h"
|
@@ -12,35 +12,5 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <stdint.h>
|
||||
#include <sys/param.h>
|
||||
|
||||
#include "esp_attr.h"
|
||||
#include "soc/rtc.h"
|
||||
#include "esp32s2/clk.h"
|
||||
|
||||
#define MHZ (1000000)
|
||||
|
||||
// g_ticks_us defined in ROMs
|
||||
extern uint32_t g_ticks_per_us_pro;
|
||||
|
||||
int IRAM_ATTR esp_clk_cpu_freq(void)
|
||||
{
|
||||
return g_ticks_per_us_pro * MHZ;
|
||||
}
|
||||
|
||||
int IRAM_ATTR esp_clk_apb_freq(void)
|
||||
{
|
||||
return MIN(g_ticks_per_us_pro, 80) * MHZ;
|
||||
}
|
||||
|
||||
int IRAM_ATTR esp_clk_xtal_freq(void)
|
||||
{
|
||||
return rtc_clk_xtal_freq_get() * MHZ;
|
||||
}
|
||||
|
||||
void IRAM_ATTR ets_update_cpu_frequency(uint32_t ticks_per_us)
|
||||
{
|
||||
/* Update scale factors used by esp_rom_delay_us */
|
||||
g_ticks_per_us_pro = ticks_per_us;
|
||||
}
|
||||
#pragma once
|
||||
#include "esp_private/esp_clk.h"
|
16
components/esp_hw_support/include/soc/esp32s3/clk.h
Normal file
16
components/esp_hw_support/include/soc/esp32s3/clk.h
Normal file
@@ -0,0 +1,16 @@
|
||||
// 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 "esp_private/esp_clk.h"
|
@@ -12,6 +12,9 @@ archive: libesp_hw_support.a
|
||||
entries:
|
||||
if PM_SLP_IRAM_OPT = y:
|
||||
rtc_init:rtc_vddsdio_get_config (noflash)
|
||||
esp_clk:esp_clk_slowclk_cal_set (noflash)
|
||||
esp_clk:esp_clk_slowclk_cal_get (noflash)
|
||||
esp_clk:esp_rtc_get_time_us (noflash)
|
||||
|
||||
[mapping:esp_system_pm]
|
||||
archive: libesp_system.a
|
||||
@@ -47,9 +50,6 @@ entries:
|
||||
if PM_SLP_IRAM_OPT = y:
|
||||
esp_time_impl:esp_time_impl_set_boot_time (noflash)
|
||||
esp_time_impl:esp_time_impl_get_boot_time (noflash)
|
||||
esp_time_impl:esp_clk_slowclk_cal_get (noflash)
|
||||
esp_time_impl:esp_rtc_get_time_us (noflash)
|
||||
esp_time_impl:esp_clk_slowclk_cal_set (noflash)
|
||||
esp_time_impl:esp_set_time_from_rtc (noflash)
|
||||
|
||||
[mapping:driver_pm]
|
||||
|
@@ -25,6 +25,7 @@ INCLUDE_DIRS := \
|
||||
$(addprefix ../../../components/, \
|
||||
esp_rom/include \
|
||||
esp_hw_support/include \
|
||||
esp_hw_support/include/soc \
|
||||
esp_system/include \
|
||||
xtensa/include \
|
||||
xtensa/esp32/include \
|
||||
|
@@ -60,9 +60,6 @@ static uint64_t s_boot_time; // when RTC is used to persist time, two RTC_STORE
|
||||
|
||||
static _lock_t s_boot_time_lock;
|
||||
|
||||
static _lock_t s_esp_rtc_time_lock;
|
||||
static RTC_DATA_ATTR uint64_t s_esp_rtc_time_us = 0, s_rtc_last_ticks = 0;
|
||||
|
||||
#if defined( CONFIG_ESP_TIME_FUNCS_USE_ESP_TIMER ) || defined( CONFIG_ESP_TIME_FUNCS_USE_RTC_TIMER )
|
||||
uint64_t esp_time_impl_get_time_since_boot(void)
|
||||
{
|
||||
@@ -106,15 +103,6 @@ void esp_time_impl_set_boot_time(uint64_t time_us)
|
||||
_lock_release(&s_boot_time_lock);
|
||||
}
|
||||
|
||||
uint64_t esp_clk_rtc_time(void)
|
||||
{
|
||||
#ifdef CONFIG_ESP_TIME_FUNCS_USE_RTC_TIMER
|
||||
return esp_rtc_get_time_us();
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
uint64_t esp_time_impl_get_boot_time(void)
|
||||
{
|
||||
uint64_t result;
|
||||
@@ -128,49 +116,6 @@ uint64_t esp_time_impl_get_boot_time(void)
|
||||
return result;
|
||||
}
|
||||
|
||||
uint32_t esp_clk_slowclk_cal_get(void)
|
||||
{
|
||||
return REG_READ(RTC_SLOW_CLK_CAL_REG);
|
||||
}
|
||||
|
||||
uint64_t esp_rtc_get_time_us(void)
|
||||
{
|
||||
_lock_acquire(&s_esp_rtc_time_lock);
|
||||
const uint32_t cal = esp_clk_slowclk_cal_get();
|
||||
const uint64_t rtc_this_ticks = rtc_time_get();
|
||||
const uint64_t ticks = rtc_this_ticks - s_rtc_last_ticks;
|
||||
/* 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;
|
||||
const uint64_t delta_time_us = ((ticks_low * cal) >> RTC_CLK_CAL_FRACT) +
|
||||
((ticks_high * cal) << (32 - RTC_CLK_CAL_FRACT));
|
||||
s_esp_rtc_time_us += delta_time_us;
|
||||
s_rtc_last_ticks = rtc_this_ticks;
|
||||
_lock_release(&s_esp_rtc_time_lock);
|
||||
return s_esp_rtc_time_us;
|
||||
}
|
||||
|
||||
void esp_clk_slowclk_cal_set(uint32_t new_cal)
|
||||
{
|
||||
#if defined(CONFIG_ESP_TIME_FUNCS_USE_RTC_TIMER)
|
||||
/* To force monotonic time values even when clock calibration value changes,
|
||||
* we adjust esp_rtc_time
|
||||
*/
|
||||
esp_rtc_get_time_us();
|
||||
#endif // CONFIG_ESP_TIME_FUNCS_USE_RTC_TIMER
|
||||
REG_WRITE(RTC_SLOW_CLK_CAL_REG, new_cal);
|
||||
}
|
||||
|
||||
void esp_set_time_from_rtc(void)
|
||||
{
|
||||
#if defined( CONFIG_ESP_TIME_FUNCS_USE_ESP_TIMER ) && defined( CONFIG_ESP_TIME_FUNCS_USE_RTC_TIMER )
|
||||
|
@@ -40,6 +40,7 @@
|
||||
#include "esp32s3/rom/spi_flash.h"
|
||||
#include "esp32s3/rom/cache.h"
|
||||
#include "esp32s3/clk.h"
|
||||
#include "esp32s3/clk.h"
|
||||
#elif CONFIG_IDF_TARGET_ESP32C3
|
||||
#include "esp32c3/rom/cache.h"
|
||||
#include "esp32c3/rom/spi_flash.h"
|
||||
|
@@ -27,6 +27,7 @@ INCLUDE_DIRS := \
|
||||
esp_rom/include \
|
||||
esp_common/include \
|
||||
esp_hw_support/include \
|
||||
esp_hw_support/include/soc \
|
||||
esp_system/include \
|
||||
xtensa/include \
|
||||
xtensa/esp32/include \
|
||||
|
@@ -21,6 +21,7 @@ INCLUDE_DIRS := \
|
||||
$(addprefix ../../../../components/, \
|
||||
esp_common/include \
|
||||
esp_hw_support/include \
|
||||
esp_hw_support/include/soc \
|
||||
esp_system/include \
|
||||
soc/esp32/include \
|
||||
soc/include \
|
||||
|
@@ -26,6 +26,7 @@ INCLUDE_DIRS := \
|
||||
esp_rom/include \
|
||||
esp_common/include \
|
||||
esp_hw_support/include \
|
||||
esp_hw_support/include/soc \
|
||||
esp_system/include \
|
||||
xtensa/include \
|
||||
xtensa/esp32/include \
|
||||
|
@@ -26,6 +26,7 @@ INCLUDE_DIRS := \
|
||||
esp_system/include \
|
||||
esp_common/include \
|
||||
esp_hw_support/include \
|
||||
esp_hw_support/include/soc \
|
||||
xtensa/include \
|
||||
xtensa/esp32/include \
|
||||
soc/esp32/include \
|
||||
|
Reference in New Issue
Block a user