1 /*
2  * SPDX-FileCopyrightText: 2010-2021 Espressif Systems (Shanghai) CO LTD
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 #include "sdkconfig.h"
7 #include "soc/soc.h"
8 #ifndef CONFIG_IDF_TARGET_ESP32
9 #include "soc/system_reg.h"
10 #endif // not CONFIG_IDF_TARGET_ESP32
11 #include "soc/rtc.h"
12 #if CONFIG_IDF_TARGET_ESP32
13 #include "esp32/rom/rtc.h"
14 #elif CONFIG_IDF_TARGET_ESP32S2
15 #include "esp32s2/rom/rtc.h"
16 #elif CONFIG_IDF_TARGET_ESP32S3
17 #include "esp32s3/rom/rtc.h"
18 #elif CONFIG_IDF_TARGET_ESP32C3
19 #include "esp32c3/rom/rtc.h"
20 #elif CONFIG_IDF_TARGET_ESP32C2
21 #include "esp32c2/rom/rtc.h"
22 #elif CONFIG_IDF_TARGET_ESP32C6
23 #include "esp32c6/rom/rtc.h"
24 #include "esp_private/esp_pmu.h"
25 #elif CONFIG_IDF_TARGET_ESP32H2
26 #include "esp32h2/rom/rtc.h"
27 #endif
28 #include "esp_log.h"
29 #include "esp_rom_sys.h"
30 #include "esp_rom_uart.h"
31 #include "esp_attr.h"
32 
33 static const char *TAG = "fpga";
34 
s_warn(void)35 static void s_warn(void)
36 {
37     ESP_EARLY_LOGW(TAG, "Project configuration is for internal FPGA use, not all functions will work");
38 }
39 
bootloader_clock_configure(void)40 void bootloader_clock_configure(void)
41 {
42     s_warn();
43     esp_rom_uart_tx_wait_idle(0);
44 
45     uint32_t xtal_freq_mhz = 40;
46 #ifdef CONFIG_IDF_TARGET_ESP32S2
47     uint32_t apb_freq_hz = 20000000;
48 #else
49     uint32_t apb_freq_hz = CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ * 1000000;
50 #endif // CONFIG_IDF_TARGET_ESP32S2
51     esp_rom_set_cpu_ticks_per_us(apb_freq_hz / 1000000);
52 #ifdef RTC_APB_FREQ_REG
53     REG_WRITE(RTC_APB_FREQ_REG, (apb_freq_hz >> 12) | ((apb_freq_hz >> 12) << 16));
54 #endif
55     REG_WRITE(RTC_XTAL_FREQ_REG, (xtal_freq_mhz) | ((xtal_freq_mhz) << 16));
56 }
57 
58 /* Placed in IRAM since test_apps expects it to be */
bootloader_fill_random(void * buffer,size_t length)59 void IRAM_ATTR bootloader_fill_random(void *buffer, size_t length)
60 {
61     uint8_t *buffer_bytes = (uint8_t *)buffer;
62     for (int i = 0; i < length; i++) {
63         buffer_bytes[i] = 0x5A;
64     }
65 }
66 
esp_clk_init(void)67 void esp_clk_init(void)
68 {
69     s_warn();
70 #if SOC_PMU_SUPPORTED
71     pmu_init();
72 #endif
73 }
74 
esp_perip_clk_init(void)75 void esp_perip_clk_init(void)
76 {
77 
78 }
79 
80 /**
81  * @brief No-op function, used to force linking this file
82  *
83  */
esp_common_include_fpga_overrides(void)84 void esp_common_include_fpga_overrides(void)
85 {
86 }
87