1 /* 2 * Copyright (c) 2021 Espressif Systems (Shanghai) Co., Ltd. 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #ifndef _STUBS_H_ 8 #define _STUBS_H_ 9 10 /* Required for C99 compilation (required for GCC-8.x version, 11 * where typeof is used instead of __typeof__) 12 */ 13 #ifndef typeof 14 #define typeof __typeof__ 15 #endif 16 17 #include <zephyr/devicetree.h> 18 19 #if defined(CONFIG_SOC_ESP32) || defined(CONFIG_SOC_ESP32_NET) 20 #define DT_CPU_COMPAT cdns_tensilica_xtensa_lx6 21 #elif defined(CONFIG_SOC_ESP32S2) || defined(CONFIG_SOC_ESP32S3) 22 #define DT_CPU_COMPAT cdns_tensilica_xtensa_lx7 23 #elif CONFIG_IDF_TARGET_ESP32C3 24 #define DT_CPU_COMPAT espressif_riscv 25 #endif 26 27 #define ESP_SOC_DEFAULT_CPU_FREQ_MHZ ((DT_PROP(DT_INST(0, DT_CPU_COMPAT), clock_frequency)) / 1000000) 28 #define ESP_SOC_DEFAULT_RTC_CLK_CAL_CYCLES 1024 29 30 #if defined(CONFIG_SOC_ESP32) 31 #define CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ ESP_SOC_DEFAULT_CPU_FREQ_MHZ 32 #elif defined(CONFIG_SOC_ESP32S2) 33 #define CONFIG_ESP32S2_DEFAULT_CPU_FREQ_MHZ ESP_SOC_DEFAULT_CPU_FREQ_MHZ 34 #elif defined(CONFIG_SOC_ESP32S3) 35 #define CONFIG_ESP32S3_DEFAULT_CPU_FREQ_MHZ ESP_SOC_DEFAULT_CPU_FREQ_MHZ 36 #elif defined(CONFIG_SOC_ESP32C3) 37 #define CONFIG_ESP32C3_DEFAULT_CPU_FREQ_MHZ ESP_SOC_DEFAULT_CPU_FREQ_MHZ 38 #endif 39 40 /* Extract configuration from the devicetree */ 41 #if DT_NODE_HAS_STATUS(DT_NODELABEL(uart0), okay) && \ 42 DT_PROP_BY_IDX(DT_NODELABEL(uart0), reg, 0) == \ 43 DT_PROP_BY_IDX(DT_CHOSEN(zephyr_console), reg, 0) 44 #define CONFIG_ESP_CONSOLE_UART 1 45 #define CONFIG_ESP_CONSOLE_UART_NUM 0 46 #define CONFIG_ESP_CONSOLE_UART_BAUDRATE DT_PROP(DT_NODELABEL(uart0), current_speed) 47 48 #elif DT_NODE_HAS_STATUS(DT_NODELABEL(uart1), okay) && \ 49 DT_PROP_BY_IDX(DT_NODELABEL(uart1), reg, 0) == \ 50 DT_PROP_BY_IDX(DT_CHOSEN(zephyr_console), reg, 0) 51 #define CONFIG_ESP_CONSOLE_UART 1 52 #define CONFIG_ESP_CONSOLE_UART_NUM 1 53 #define CONFIG_ESP_CONSOLE_UART_BAUDRATE DT_PROP(DT_NODELABEL(uart1), current_speed) 54 55 #elif DT_NODE_HAS_STATUS(DT_NODELABEL(uart2), okay) && \ 56 DT_PROP_BY_IDX(DT_NODELABEL(uart2), reg, 0) == \ 57 DT_PROP_BY_IDX(DT_CHOSEN(zephyr_console), reg, 0) 58 #define CONFIG_ESP_CONSOLE_UART 1 59 #define CONFIG_ESP_CONSOLE_UART_NUM 2 60 #define CONFIG_ESP_CONSOLE_UART_BAUDRATE DT_PROP(DT_NODELABEL(uart2), current_speed) 61 62 #else 63 64 #define CONFIG_ESP_CONSOLE_UART_NONE 65 #define CONFIG_ESP_CONSOLE_UART_NUM -1 66 67 #endif 68 69 #endif /* _STUBS_H_ */ 70