diff --git a/CMakeLists.txt b/CMakeLists.txt index 006a3b5..968f9a7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -146,21 +146,83 @@ if(FREERTOS_PORT STREQUAL "GCC_XTENSA_ESP32") target_link_libraries(freertos_config INTERFACE idf::xtensa) endif() - if(DEFINED ENV{IDF_PATH}) - set(_idf_xtensa_include "$ENV{IDF_PATH}/components/xtensa/include") - if(EXISTS "${_idf_xtensa_include}/xtensa/hal.h") - target_include_directories(freertos_config - INTERFACE - $ + if(DEFINED ENV{IDF_PATH} AND NOT "$ENV{IDF_PATH}" STREQUAL "") + set(_idf_path "$ENV{IDF_PATH}") + elseif(DEFINED IDF_PATH AND NOT "${IDF_PATH}" STREQUAL "") + set(_idf_path "${IDF_PATH}") + endif() + + if(DEFINED _idf_path) + set(DMOSI_IDF_PATH "${_idf_path}") + + set(_idf_esp32_include_dirs + "${_idf_path}/components/xtensa/include" + "${_idf_path}/components/esp_hw_support/include" + "${_idf_path}/components/esp_hw_support/include/soc" + "${_idf_path}/components/hal/include" + "${_idf_path}/components/soc/include" + "${_idf_path}/components/esp_rom/include" + "${_idf_path}/components/esp_common/include" + "${_idf_path}/components/esp_system/include" + "${_idf_path}/components/esp_timer/include" + "${_idf_path}/components/log/include" + "${_idf_path}/components/heap/include" + ) + + if(DEFINED DMOD_CPU AND NOT "${DMOD_CPU}" STREQUAL "") + list(APPEND _idf_esp32_include_dirs + "${_idf_path}/components/xtensa/${DMOD_CPU}/include" + "${_idf_path}/components/hal/${DMOD_CPU}/include" + "${_idf_path}/components/soc/${DMOD_CPU}/include" + "${_idf_path}/components/esp_rom/include/${DMOD_CPU}" ) endif() - unset(_idf_xtensa_include) + + foreach(_idf_include_dir IN LISTS _idf_esp32_include_dirs) + if(EXISTS "${_idf_include_dir}") + target_include_directories(freertos_config + INTERFACE + $ + ) + endif() + endforeach() + + unset(_idf_include_dir) + unset(_idf_esp32_include_dirs) + unset(_idf_path) endif() + + target_compile_definitions(freertos_config + INTERFACE + portNUM_PROCESSORS=1 + ) endif() # Add FreeRTOS subdirectory add_subdirectory(lib/freertos) +if(FREERTOS_PORT STREQUAL "GCC_XTENSA_ESP32" AND DEFINED DMOSI_IDF_PATH) + set(_dmosi_xtensa_asm_sources + "${DMOSI_IDF_PATH}/components/xtensa/xtensa_intr_asm.S" + "${DMOSI_IDF_PATH}/components/esp_system/port/arch/xtensa/panic_handler_asm.S" + ) + + foreach(_dmosi_xtensa_asm_source IN LISTS _dmosi_xtensa_asm_sources) + if(EXISTS "${_dmosi_xtensa_asm_source}") + target_sources(freertos_kernel_port PRIVATE "${_dmosi_xtensa_asm_source}") + endif() + endforeach() + + target_sources(freertos_kernel_port PRIVATE + "${CMAKE_SOURCE_DIR}/src/arch/xtensa/xtensa_compat_stubs.c" + ) + + target_compile_definitions(freertos_kernel_port PRIVATE XT_SIMULATOR=1) + + unset(_dmosi_xtensa_asm_source) + unset(_dmosi_xtensa_asm_sources) +endif() + # ====================================================================== # DMOSI Process Management # ====================================================================== @@ -201,6 +263,10 @@ target_compile_definitions(dmosi_freertos PRIVATE # Treat warnings as errors for this project's sources target_compile_options(dmosi_freertos PRIVATE -Wall -Wextra -Werror) +if(FREERTOS_PORT STREQUAL "GCC_XTENSA_ESP32") + target_compile_options(dmosi_freertos PRIVATE -Wno-unused-parameter) +endif() + # ====================================================================== # Tests # ====================================================================== diff --git a/cmake/arch_mapping.cmake b/cmake/arch_mapping.cmake index 218a020..c3b7abd 100644 --- a/cmake/arch_mapping.cmake +++ b/cmake/arch_mapping.cmake @@ -118,10 +118,13 @@ if(_compiler STREQUAL "gcc") set(FREERTOS_PORT "GCC_RISC_V_GENERIC") set(FREERTOS_ARCH_CONFIG_SUBDIR "risc_v") - # --- Xtensa / ESP32 -------------------------------------------------- + # --- Xtensa / ESP32 / ESP32-S3 (LX6 and LX7 cores) ----------------- elseif(_family STREQUAL "xtensa_esp32" OR _family STREQUAL "esp32" OR (_arch STREQUAL "xtensa" AND _family STREQUAL "esp32") - OR _arch STREQUAL "xtensa_esp32") + OR (_arch STREQUAL "xtensa" AND _family STREQUAL "esp32s3") + OR _arch STREQUAL "xtensa_esp32" + OR (_arch STREQUAL "xtensa" AND _family STREQUAL "lx7") + OR (_arch STREQUAL "xtensa" AND _family STREQUAL "lx6")) set(FREERTOS_PORT "GCC_XTENSA_ESP32") set(FREERTOS_ARCH_CONFIG_SUBDIR "xtensa_esp32") diff --git a/config/FreeRTOSConfig.h b/config/FreeRTOSConfig.h index 885f3bb..221691e 100644 --- a/config/FreeRTOSConfig.h +++ b/config/FreeRTOSConfig.h @@ -48,7 +48,9 @@ * include path when DMOSI_ARCH and DMOSI_ARCH_FAMILY are set in CMake. * If no arch directory is configured, config/FreeRTOSConfigArch.h is used. */ #include "FreeRTOSConfigArch.h" +#ifndef __ASSEMBLER__ #include "dmod_sal.h" +#endif /******************************************************************************/ /* Hardware description related definitions. **********************************/ @@ -409,12 +411,14 @@ * no-op because Dmod_GetUptime() does not require explicit timer setup. * Override these macros in the architecture-specific FreeRTOSConfigArch.h * (or your application's config) if a higher-resolution counter is needed. */ -#ifndef portCONFIGURE_TIMER_FOR_RUN_TIME_STATS - #define portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() do {} while( 0 ) -#endif - -#ifndef portGET_RUN_TIME_COUNTER_VALUE - #define portGET_RUN_TIME_COUNTER_VALUE() Dmod_GetUptime() +#if !defined(__XTENSA__) + #ifndef portCONFIGURE_TIMER_FOR_RUN_TIME_STATS + #define portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() do {} while( 0 ) + #endif + + #ifndef portGET_RUN_TIME_COUNTER_VALUE + #define portGET_RUN_TIME_COUNTER_VALUE() Dmod_GetUptime() + #endif #endif /* configRUN_TIME_COUNTER_TYPE must match the return type of the counter macro diff --git a/config/arch/xtensa_esp32/FreeRTOSConfigArch.h b/config/arch/xtensa_esp32/FreeRTOSConfigArch.h index 3850a79..65aed3b 100644 --- a/config/arch/xtensa_esp32/FreeRTOSConfigArch.h +++ b/config/arch/xtensa_esp32/FreeRTOSConfigArch.h @@ -11,4 +11,19 @@ #define DMOSI_TICK_TYPE_WIDTH_IN_BITS TICK_TYPE_WIDTH_32_BITS #endif +/* The Xtensa ESP32 port's FreeRTOSConfig_arch.h unconditionally defines + * configMAX_SYSCALL_INTERRUPT_PRIORITY to XCHAL_EXCM_LEVEL. Pre-define it + * here so that FreeRTOSConfig.h does not set it to the generic default of 0, + * which would cause a redefinition warning and assembler errors in the Xtensa + * context-save/restore code (xtensa_context.S). + * + * XCHAL_EXCM_LEVEL is provided by the Xtensa HAL ( for + * assembler translation units and for C translation + * units). Both are included by xtensa_rtos.h before it includes + * FreeRTOSConfig.h, so XCHAL_EXCM_LEVEL is always in scope when this file + * is processed as part of a GCC_XTENSA_ESP32 build. */ +#ifndef configMAX_SYSCALL_INTERRUPT_PRIORITY + #define configMAX_SYSCALL_INTERRUPT_PRIORITY XCHAL_EXCM_LEVEL +#endif + #endif /* FREERTOS_CONFIG_ARCH_H */ diff --git a/config/arch/xtensa_esp32/esp_crosscore_int.h b/config/arch/xtensa_esp32/esp_crosscore_int.h new file mode 100644 index 0000000..59b1623 --- /dev/null +++ b/config/arch/xtensa_esp32/esp_crosscore_int.h @@ -0,0 +1,6 @@ +#ifndef ESP_CROSSCORE_INT_COMPAT_H +#define ESP_CROSSCORE_INT_COMPAT_H + +#include "esp_private/crosscore_int.h" + +#endif diff --git a/config/arch/xtensa_esp32/esp_idf_version.h b/config/arch/xtensa_esp32/esp_idf_version.h new file mode 100644 index 0000000..fe920bd --- /dev/null +++ b/config/arch/xtensa_esp32/esp_idf_version.h @@ -0,0 +1,27 @@ +/* + * Minimal esp_idf_version.h stub for standalone FreeRTOS builds outside + * ESP-IDF. + * + * The GCC_XTENSA_ESP32 FreeRTOS port sources include this header and guard + * code behind version comparisons. When building without the ESP-IDF build + * system, this stub is used as a fallback. + * + * This standalone profile is aligned with ESP-IDF 4.4.x used by the toolchain. + * Matching the real IDF major/minor version ensures Xtensa FreeRTOS port code + * selects compatible include paths and APIs for ESP32-S3. + * + * In a real ESP-IDF build (via idf.py), the generated esp_idf_version.h is + * placed earlier in the include path and shadows this file automatically. + */ + +#ifndef ESP_IDF_VERSION_H +#define ESP_IDF_VERSION_H + +/** Encode a version as a single 24-bit integer (same as ESP-IDF's macro). */ +#define ESP_IDF_VERSION_VAL(major, minor, patch) \ + (((major) << 16) | ((minor) << 8) | (patch)) + +/** Reported ESP-IDF version for standalone builds. */ +#define ESP_IDF_VERSION ESP_IDF_VERSION_VAL(4, 4, 7) + +#endif /* ESP_IDF_VERSION_H */ diff --git a/config/arch/xtensa_esp32/sdkconfig.h b/config/arch/xtensa_esp32/sdkconfig.h new file mode 100644 index 0000000..94cd143 --- /dev/null +++ b/config/arch/xtensa_esp32/sdkconfig.h @@ -0,0 +1,41 @@ +/* + * Minimal sdkconfig.h stub for standalone FreeRTOS builds outside ESP-IDF. + * + * When the GCC_XTENSA_ESP32 FreeRTOS port is used without the ESP-IDF build + * system, sdkconfig.h (normally auto-generated by ESP-IDF's Kconfig) is not + * available. This stub provides the minimum set of CONFIG_* symbols consumed + * by the port headers and assembly sources so that the build succeeds. + * + * In a real ESP-IDF build (via idf.py), the generated sdkconfig.h is placed + * earlier in the include path and shadows this file automatically. + */ + +#ifndef SDKCONFIG_STUB_H +#define SDKCONFIG_STUB_H + +/* Use Xtensa internal timer 0 as the FreeRTOS tick source. + * Exactly one of CONFIG_FREERTOS_CORETIMER_0 / _1 must be defined. */ +#define CONFIG_FREERTOS_CORETIMER_0 1 + +/* ISR interrupt-handler stack size in bytes. + * 1792 is the ESP-IDF default and is already a multiple of the required + * 16-byte stack alignment (configSTACK_ALIGNMENT). */ +#define CONFIG_FREERTOS_ISR_STACKSIZE 1792 + +/* Target selection used by ESP-IDF Xtensa FreeRTOS port sources. */ +#ifndef CONFIG_IDF_TARGET_ESP32S3 + #define CONFIG_IDF_TARGET_ESP32S3 1 +#endif + +/* Single-core standalone default for this build profile. */ +#ifndef CONFIG_FREERTOS_NO_AFFINITY + #define CONFIG_FREERTOS_NO_AFFINITY -1 +#endif + +/* Minimum logging-related options consumed by esp_log.h macros. */ +#define CONFIG_LOG_MAXIMUM_LEVEL 3 +#define CONFIG_LOG_COLORS 0 +#define CONFIG_LOG_TIMESTAMP_SOURCE_RTOS 0 +#define CONFIG_LOG_TIMESTAMP_SOURCE_SYSTEM 1 + +#endif /* SDKCONFIG_STUB_H */ diff --git a/config/sdkconfig.h b/config/sdkconfig.h new file mode 100644 index 0000000..40aea0c --- /dev/null +++ b/config/sdkconfig.h @@ -0,0 +1,74 @@ +#pragma once + +#ifndef CONFIG_IDF_TARGET_ESP32S3 +#define CONFIG_IDF_TARGET_ESP32S3 1 +#endif +#ifndef CONFIG_IDF_TARGET_ESP32 +#define CONFIG_IDF_TARGET_ESP32 0 +#endif +#ifndef CONFIG_IDF_TARGET_ESP32S2 +#define CONFIG_IDF_TARGET_ESP32S2 0 +#endif +#ifndef CONFIG_IDF_TARGET_ESP32C3 +#define CONFIG_IDF_TARGET_ESP32C3 0 +#endif +#ifndef CONFIG_IDF_TARGET_ESP32H2 +#define CONFIG_IDF_TARGET_ESP32H2 0 +#endif + +#ifndef CONFIG_FREERTOS_NO_AFFINITY +#define CONFIG_FREERTOS_NO_AFFINITY (-1) +#endif +#define CONFIG_FREERTOS_UNICORE 1 +#define CONFIG_ESP_SYSTEM_SINGLE_CORE_MODE 1 + +#define CONFIG_FREERTOS_HZ 100 +#define CONFIG_FREERTOS_ISR_STACKSIZE 1536 + +#define CONFIG_FREERTOS_CORETIMER_0 1 +#define CONFIG_FREERTOS_CORETIMER_1 0 +#define CONFIG_FREERTOS_SYSTICK_USES_CCOUNT 1 +#define CONFIG_FREERTOS_SYSTICK_USES_SYSTIMER 0 +#define CONFIG_FREERTOS_CORETIMER_SYSTIMER_LVL3 0 + +#define CONFIG_FREERTOS_TASK_FUNCTION_WRAPPER 0 +#define CONFIG_FREERTOS_FPU_IN_ISR 0 +#define CONFIG_FREERTOS_INTERRUPT_BACKTRACE 0 +#define CONFIG_FREERTOS_RUN_TIME_STATS_USING_ESP_TIMER 0 +#define CONFIG_FREERTOS_OPTIMIZED_SCHEDULER 0 +#define CONFIG_FREERTOS_ASSERT_DISABLE 1 +#define CONFIG_FREERTOS_ASSERT_ON_UNTESTED_FUNCTION 0 + +#define CONFIG_ESP32_DEBUG_OCDAWARE 0 +#define CONFIG_ESP_INT_WDT 0 +#define CONFIG_ESP_TASK_WDT 0 +#define CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU0 0 +#define CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU1 0 +#define CONFIG_ESP_TASK_WDT_PANIC 0 +#define CONFIG_ESP_TASK_WDT_TIMEOUT_S 5 + +#define CONFIG_PM_ENABLE 0 +#define CONFIG_PM_TRACE 0 + +#define CONFIG_SPIRAM 0 +#define CONFIG_SPIRAM_SUPPORT 0 +#define CONFIG_SPIRAM_ALLOW_STACK_EXTERNAL_MEMORY 0 +#define CONFIG_SPIRAM_MALLOC_RESERVE_INTERNAL 0 +#define CONFIG_SPIRAM_SPEED_40M 0 +#define CONFIG_SPIRAM_SPEED_80M 0 +#define CONFIG_ESP32_SPIRAM_SUPPORT 0 +#define CONFIG_ESP32S3_SPIRAM_SUPPORT 0 + +#define CONFIG_BTDM_CTRL_HLI 0 +#define CONFIG_BTDM_CTRL_PINNED_TO_CORE 0 +#define CONFIG_APPTRACE_SV_ENABLE 0 + +#define CONFIG_LOG_MAXIMUM_LEVEL 3 + +#define CONFIG_ESPTOOLPY_FLASHFREQ_26M 0 +#define CONFIG_ESPTOOLPY_FLASHFREQ_40M 1 +#define CONFIG_ESPTOOLPY_FLASHFREQ_80M 0 +#define CONFIG_ESPTOOLPY_FLASHMODE_DIO 1 +#define CONFIG_ESPTOOLPY_FLASHMODE_DOUT 0 +#define CONFIG_ESPTOOLPY_FLASHMODE_QIO 0 +#define CONFIG_ESPTOOLPY_FLASHMODE_QOUT 0 diff --git a/lib/dmosi-proc b/lib/dmosi-proc index 72e27d4..4e8bce6 160000 --- a/lib/dmosi-proc +++ b/lib/dmosi-proc @@ -1 +1 @@ -Subproject commit 72e27d49ea56e585eac7917996e60bb6fa1bdb8a +Subproject commit 4e8bce64d9599ee539b5e5e84a8731312125d32b diff --git a/src/dmosi_heap.c b/src/dmosi_heap.c index 23fc3e9..7a15ca5 100644 --- a/src/dmosi_heap.c +++ b/src/dmosi_heap.c @@ -37,6 +37,7 @@ void vPortFree(void* ptr) * Since we are using a custom allocator, we return 0 to indicate that this information * is not available. */ +#if !defined(__XTENSA__) size_t xPortGetFreeHeapSize(void) { return 0; @@ -53,6 +54,7 @@ size_t xPortGetMinimumEverFreeHeapSize(void) { return 0; } +#endif /** * @brief Initialize memory blocks (not needed for custom allocator)