1 /*
2  * SPDX-FileCopyrightText: 2010-2023 Espressif Systems (Shanghai) CO LTD
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #include <stdint.h>
8 #include <stdbool.h>
9 #include "sdkconfig.h"
10 #include "esp_attr.h"
11 #include "soc/soc_caps.h"
12 #include "esp_rom_caps.h"
13 
esp_rom_install_channel_putc(int channel,void (* putc)(char c))14 IRAM_ATTR void esp_rom_install_channel_putc(int channel, void (*putc)(char c))
15 {
16     extern void ets_install_putc1(void (*p)(char c));
17     extern void ets_install_putc2(void (*p)(char c));
18     switch (channel) {
19     case 1:
20         ets_install_putc1(putc);
21         break;
22     case 2:
23         ets_install_putc2(putc);
24         break;
25     default:
26         break;
27     }
28 }
29 
30 #if ESP_ROM_HAS_ETS_PRINTF_BUG
esp_rom_install_uart_printf(void)31 IRAM_ATTR void esp_rom_install_uart_printf(void)
32 {
33     extern void ets_install_uart_printf(void);
34     extern bool g_uart_print;
35     extern bool g_usb_print;
36     // If ROM log is disabled permanently via eFuse or temporarily via RTC storage register,
37     // this ROM symbol will be set to false, and cause ``esp_rom_printf`` can't work on esp-idf side.
38     g_uart_print = true;
39     g_usb_print = true;
40     ets_install_uart_printf();
41 }
42 #endif
43 
44 #if CONFIG_IDF_TARGET_ESP32
45 extern uint32_t g_ticks_per_us_pro;
46 #if SOC_CPU_CORES_NUM > 1
47 #ifndef CONFIG_FREERTOS_UNICORE
48 extern uint32_t g_ticks_per_us_app;
49 #endif
50 #endif
esp_rom_set_cpu_ticks_per_us(uint32_t ticks_per_us)51 IRAM_ATTR void esp_rom_set_cpu_ticks_per_us(uint32_t ticks_per_us)
52 {
53     /* Update scale factors used by esp_rom_delay_us */
54     g_ticks_per_us_pro = ticks_per_us;
55 #if SOC_CPU_CORES_NUM > 1
56 #ifndef CONFIG_FREERTOS_UNICORE
57     g_ticks_per_us_app = ticks_per_us;
58 #endif
59 #endif
60 }
61 #endif // CONFIG_IDF_TARGET_ESP32
62