xref: /Kernel-v10.6.2/portable/ThirdParty/GCC/Xtensa_ESP32/xtensa_init.c (revision 963abe6c4833e7c969279b537c103d7a0bdd5116)
1 /*
2  * SPDX-FileCopyrightText: 2015-2019 Cadence Design Systems, Inc.
3  *
4  * SPDX-License-Identifier: MIT
5  *
6  * SPDX-FileContributor: 2016-2022 Espressif Systems (Shanghai) CO LTD
7  */
8 /*
9  * Copyright (c) 2015-2019 Cadence Design Systems, Inc.
10  *
11  * Permission is hereby granted, free of charge, to any person obtaining
12  * a copy of this software and associated documentation files (the
13  * "Software"), to deal in the Software without restriction, including
14  * without limitation the rights to use, copy, modify, merge, publish,
15  * distribute, sublicense, and/or sell copies of the Software, and to
16  * permit persons to whom the Software is furnished to do so, subject to
17  * the following conditions:
18  *
19  * The above copyright notice and this permission notice shall be included
20  * in all copies or substantial portions of the Software.
21  *
22  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
25  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
26  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
27  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
28  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29  */
30 
31 /*******************************************************************************
32 *
33 *       XTENSA INITIALIZATION ROUTINES CODED IN C
34 *
35 *  This file contains miscellaneous Xtensa RTOS-generic initialization functions
36 *  that are implemented in C.
37 *
38 *******************************************************************************/
39 
40 
41 #ifdef XT_BOARD
42 #include "xtensa/xtbsp.h"
43 #endif
44 
45 #include "xtensa_rtos.h"
46 #include "sdkconfig.h"
47 #include "esp_idf_version.h"
48 #if (ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(4, 2, 0))
49 #include    "esp_clk.h"
50 #else
51 #if CONFIG_IDF_TARGET_ESP32
52 #include "esp32/clk.h"
53 #elif CONFIG_IDF_TARGET_ESP32S2
54 #include "esp32s2/clk.h"
55 #elif CONFIG_IDF_TARGET_ESP32S3
56 #include "esp32s3/clk.h"
57 #endif
58 #endif /* ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(4, 2, 0) */
59 
60 #ifdef XT_RTOS_TIMER_INT
61 
62 unsigned _xt_tick_divisor = 0;  /* cached number of cycles per tick */
63 
_xt_tick_divisor_init(void)64 void _xt_tick_divisor_init(void)
65 {
66     _xt_tick_divisor = esp_clk_cpu_freq() / XT_TICK_PER_SEC;
67 }
68 
69 /* Deprecated, to be removed */
xt_clock_freq(void)70 int xt_clock_freq(void)
71 {
72     return esp_clk_cpu_freq();
73 }
74 
75 #endif /* XT_RTOS_TIMER_INT */
76