kopia lustrzana https://github.com/espressif/esp-idf
66 wiersze
2.1 KiB
C
66 wiersze
2.1 KiB
C
/*
|
|
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
#include <stdint.h>
|
|
#include "esp_clk_tree.h"
|
|
#include "esp_err.h"
|
|
#include "esp_check.h"
|
|
#include "soc/rtc.h"
|
|
#include "hal/clk_tree_hal.h"
|
|
#include "hal/clk_tree_ll.h"
|
|
#include "esp_private/esp_clk_tree_common.h"
|
|
|
|
static const char *TAG = "esp_clk_tree";
|
|
|
|
esp_err_t esp_clk_tree_src_get_freq_hz(soc_module_clk_t clk_src, esp_clk_tree_src_freq_precision_t precision,
|
|
uint32_t *freq_value)
|
|
{
|
|
ESP_RETURN_ON_FALSE(clk_src > 0 && clk_src < SOC_MOD_CLK_INVALID, ESP_ERR_INVALID_ARG, TAG, "unknown clk src");
|
|
ESP_RETURN_ON_FALSE(precision < ESP_CLK_TREE_SRC_FREQ_PRECISION_INVALID, ESP_ERR_INVALID_ARG, TAG, "unknown precision");
|
|
ESP_RETURN_ON_FALSE(freq_value, ESP_ERR_INVALID_ARG, TAG, "null pointer");
|
|
|
|
uint32_t clk_src_freq = 0;
|
|
switch (clk_src) {
|
|
case SOC_MOD_CLK_CPU:
|
|
clk_src_freq = clk_hal_cpu_get_freq_hz();
|
|
break;
|
|
case SOC_MOD_CLK_XTAL:
|
|
clk_src_freq = clk_hal_xtal_get_freq_mhz() * MHZ;
|
|
break;
|
|
case SOC_MOD_CLK_PLL_F40M:
|
|
clk_src_freq = CLK_LL_PLL_40M_FREQ_MHZ * MHZ;
|
|
break;
|
|
case SOC_MOD_CLK_PLL_F60M:
|
|
clk_src_freq = CLK_LL_PLL_60M_FREQ_MHZ * MHZ;
|
|
break;
|
|
case SOC_MOD_CLK_PLL_F80M:
|
|
clk_src_freq = CLK_LL_PLL_80M_FREQ_MHZ * MHZ;
|
|
break;
|
|
case SOC_MOD_CLK_RTC_SLOW:
|
|
clk_src_freq = esp_clk_tree_lp_slow_get_freq_hz(precision);
|
|
break;
|
|
case SOC_MOD_CLK_RTC_FAST:
|
|
clk_src_freq = esp_clk_tree_lp_fast_get_freq_hz(precision);
|
|
break;
|
|
case SOC_MOD_CLK_RC_FAST:
|
|
clk_src_freq = esp_clk_tree_rc_fast_get_freq_hz(precision);
|
|
break;
|
|
case SOC_MOD_CLK_RC_FAST_D256:
|
|
clk_src_freq = esp_clk_tree_rc_fast_d256_get_freq_hz(precision);
|
|
break;
|
|
case SOC_MOD_CLK_OSC_SLOW:
|
|
clk_src_freq = esp_clk_tree_osc_slow_get_freq_hz(precision);
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
ESP_RETURN_ON_FALSE(clk_src_freq, ESP_FAIL, TAG,
|
|
"freq shouldn't be 0, calibration failed");
|
|
*freq_value = clk_src_freq;
|
|
return ESP_OK;
|
|
}
|