2023-05-08 04:37:59 -04:00
|
|
|
# FreeRTOS Component Architecture
|
|
|
|
#
|
|
|
|
# The FreeRTOS component mainly contains
|
|
|
|
# - Different FreeRTOS kernel implementations (namely IDF FreeRTOS and Amazon SMP FreeRTOS).
|
|
|
|
# - Different ports of each architecture for each kernel implementaiton.
|
|
|
|
# - IDF additions to FreeRTOS (e.g., features and API) to augment FreeRTOS
|
|
|
|
#
|
|
|
|
# The FreeRTOS component organizes its files as follows
|
|
|
|
#
|
|
|
|
# - `./config`
|
|
|
|
# - Contains all "FreeRTOSConfig.h" files required by FreeRTOS
|
|
|
|
# - `./esp_additions`
|
|
|
|
# - Additional features added by ESP-IDF to augment FreeRTOS, and not part of the original kernel
|
|
|
|
# - `./FreeRTOS-Kernel-...`
|
|
|
|
# - Different FreeRTOS kernel implementations. Each implementaiton is kept in its own directory.
|
|
|
|
# - Ports for the implementation are kept in `FreeRTOS-Kernel-.../portable/xxx/`\
|
|
|
|
# - `./test_apps`
|
|
|
|
# - Contains all unit tests/test apps for the FreeRTOS component.
|
|
|
|
# - `./`
|
|
|
|
# - Files common across all kernel implementations and all ports
|
|
|
|
|
|
|
|
# Bootloader builds only needs FreeRTOS for config, not for anything else
|
2019-08-08 01:33:45 -04:00
|
|
|
if(BOOTLOADER_BUILD)
|
|
|
|
idf_component_register()
|
|
|
|
return()
|
|
|
|
endif()
|
|
|
|
|
2023-05-08 04:37:59 -04:00
|
|
|
# Set some convenience variables
|
2020-11-05 23:03:21 -05:00
|
|
|
idf_build_get_property(target IDF_TARGET)
|
|
|
|
|
2022-10-13 11:52:40 -04:00
|
|
|
if(CONFIG_FREERTOS_SMP)
|
2023-05-08 04:37:59 -04:00
|
|
|
set(kernel_impl "FreeRTOS-Kernel-SMP")
|
2022-10-13 11:52:40 -04:00
|
|
|
else()
|
2023-09-26 05:47:16 -04:00
|
|
|
set(kernel_impl "FreeRTOS-Kernel")
|
2022-09-06 10:09:23 -04:00
|
|
|
endif()
|
|
|
|
|
2022-10-13 11:52:40 -04:00
|
|
|
if(CONFIG_IDF_TARGET_ARCH_XTENSA)
|
2023-05-08 04:37:59 -04:00
|
|
|
set(arch "xtensa")
|
2022-10-13 11:52:40 -04:00
|
|
|
elseif(CONFIG_IDF_TARGET_ARCH_RISCV)
|
2023-05-08 04:37:59 -04:00
|
|
|
set(arch "riscv")
|
2022-10-13 11:52:40 -04:00
|
|
|
elseif(${target} STREQUAL "linux")
|
2023-05-08 04:37:59 -04:00
|
|
|
set(arch "linux")
|
2022-10-13 11:52:40 -04:00
|
|
|
endif()
|
2022-05-17 03:21:15 -04:00
|
|
|
|
2023-05-08 04:37:59 -04:00
|
|
|
set(srcs "")
|
|
|
|
set(include_dirs "")
|
|
|
|
set(private_include_dirs "")
|
|
|
|
set(private_requirements "")
|
|
|
|
set(ldfragments "")
|
2022-10-13 11:52:40 -04:00
|
|
|
|
2023-05-08 04:37:59 -04:00
|
|
|
# ---------------------------------------------------- Set Sources -----------------------------------------------------
|
2023-04-20 23:08:27 -04:00
|
|
|
|
2023-05-08 04:37:59 -04:00
|
|
|
# Add common source files
|
|
|
|
list(APPEND srcs
|
|
|
|
"heap_idf.c")
|
2022-10-13 11:52:40 -04:00
|
|
|
|
2023-05-08 04:37:59 -04:00
|
|
|
if((arch STREQUAL "xtensa") OR (arch STREQUAL "riscv"))
|
|
|
|
list(APPEND srcs
|
|
|
|
"app_startup.c"
|
|
|
|
"port_common.c"
|
|
|
|
"port_systick.c")
|
|
|
|
endif()
|
2022-02-24 08:03:39 -05:00
|
|
|
|
2023-05-08 04:37:59 -04:00
|
|
|
# Add FreeRTOS Kernel source files
|
|
|
|
list(APPEND srcs
|
|
|
|
"${kernel_impl}/list.c"
|
|
|
|
"${kernel_impl}/queue.c"
|
|
|
|
"${kernel_impl}/tasks.c"
|
|
|
|
"${kernel_impl}/timers.c"
|
|
|
|
"${kernel_impl}/event_groups.c"
|
|
|
|
"${kernel_impl}/stream_buffer.c")
|
|
|
|
|
|
|
|
# Add port source files
|
2023-09-26 05:47:16 -04:00
|
|
|
list(APPEND srcs
|
|
|
|
"${kernel_impl}/portable/${arch}/port.c")
|
2023-05-08 04:37:59 -04:00
|
|
|
|
|
|
|
if(arch STREQUAL "linux")
|
2023-09-26 05:47:16 -04:00
|
|
|
list(APPEND srcs
|
|
|
|
"${kernel_impl}/portable/${arch}/utils/wait_for_event.c")
|
|
|
|
if(kernel_impl STREQUAL "FreeRTOS-Kernel")
|
2023-09-04 13:07:23 -04:00
|
|
|
list(APPEND srcs
|
2023-09-26 05:47:16 -04:00
|
|
|
"${kernel_impl}/portable/${arch}/port_idf.c")
|
2023-04-20 23:08:27 -04:00
|
|
|
endif()
|
2023-05-08 04:37:59 -04:00
|
|
|
else()
|
2023-09-26 05:47:16 -04:00
|
|
|
list(APPEND srcs
|
|
|
|
"${kernel_impl}/portable/${arch}/portasm.S")
|
2023-05-08 04:37:59 -04:00
|
|
|
endif()
|
|
|
|
|
|
|
|
if(arch STREQUAL "xtensa")
|
2023-09-26 05:47:16 -04:00
|
|
|
list(APPEND srcs
|
|
|
|
"${kernel_impl}/portable/${arch}/xtensa_init.c"
|
|
|
|
"${kernel_impl}/portable/${arch}/xtensa_overlay_os_hook.c")
|
2023-05-08 04:37:59 -04:00
|
|
|
endif()
|
2023-04-03 14:31:51 -04:00
|
|
|
|
2023-05-08 04:37:59 -04:00
|
|
|
# Add ESP-additions source files
|
|
|
|
list(APPEND srcs
|
2023-08-28 11:45:46 -04:00
|
|
|
"esp_additions/freertos_compatibility.c"
|
2023-05-08 04:37:59 -04:00
|
|
|
"esp_additions/idf_additions.c")
|
|
|
|
|
|
|
|
if(arch STREQUAL "linux")
|
|
|
|
# Check if we need to address the FreeRTOS EINTR coexistence with linux system calls if we're building without
|
2023-11-27 08:32:52 -05:00
|
|
|
# lwIP enabled, we need to use linux system select which will receive EINTR event on every FreeRTOS interrupt, we
|
2023-05-08 04:37:59 -04:00
|
|
|
# workaround this problem by wrapping select() to bypass and silence the EINTR events
|
2023-04-03 14:31:51 -04:00
|
|
|
set(BYPASS_EINTR_ISSUE 0)
|
2023-11-27 08:32:52 -05:00
|
|
|
if(NOT CONFIG_LWIP_ENABLE)
|
2023-04-03 14:31:51 -04:00
|
|
|
set(BYPASS_EINTR_ISSUE 1)
|
2023-05-08 04:37:59 -04:00
|
|
|
list(APPEND srcs "esp_additions/FreeRTOSSimulator_wrappers.c")
|
2023-04-03 14:31:51 -04:00
|
|
|
endif()
|
2023-05-08 04:37:59 -04:00
|
|
|
endif()
|
2023-04-03 14:31:51 -04:00
|
|
|
|
2023-05-08 04:37:59 -04:00
|
|
|
# ------------------------------------------------ Set Public Includes -------------------------------------------------
|
2022-02-24 08:03:39 -05:00
|
|
|
|
2023-05-08 04:37:59 -04:00
|
|
|
# Add common public include directories
|
|
|
|
list(APPEND include_dirs
|
|
|
|
"config/include" # For `#include "freertos/FreeRTOSConfig.h"`
|
|
|
|
"config/include/freertos" # For `#include "FreeRTOSConfig.h"`
|
|
|
|
"config/${arch}/include") # For `#include "freertos/FreeRTOSConfig_arch.h"`
|
2022-02-24 08:03:39 -05:00
|
|
|
|
2023-05-08 04:37:59 -04:00
|
|
|
# Add FreeRTOS Kernel public include directories
|
|
|
|
list(APPEND include_dirs
|
|
|
|
"${kernel_impl}/include") # FreeRTOS headers via `#include "freertos/xxx.h"`
|
|
|
|
|
|
|
|
# Add port public include directories
|
2023-09-26 05:47:16 -04:00
|
|
|
list(APPEND include_dirs
|
|
|
|
"${kernel_impl}/portable/${arch}/include" # For port headers via `#include "freertos/...h"`
|
|
|
|
"${kernel_impl}/portable/${arch}/include/freertos") # For port headers via `#include "...h"`
|
2023-05-08 04:37:59 -04:00
|
|
|
|
|
|
|
# Add ESP-additions public include directories
|
|
|
|
list(APPEND include_dirs
|
|
|
|
"esp_additions/include") # For ESP-addition headers via
|
|
|
|
# - `#include "freertos/...h"`
|
|
|
|
# - `#include "esp_private/...h"`
|
2022-02-24 08:03:39 -05:00
|
|
|
|
2023-05-08 04:37:59 -04:00
|
|
|
# ----------------------------------------------- Set Private Includes -------------------------------------------------
|
|
|
|
|
|
|
|
# Add common private include directories
|
|
|
|
if((arch STREQUAL "xtensa") OR (arch STREQUAL "riscv"))
|
|
|
|
list(APPEND private_include_dirs
|
|
|
|
".") # For `#include "port_systick.h"
|
2022-10-13 11:52:40 -04:00
|
|
|
endif()
|
|
|
|
|
2023-05-08 04:37:59 -04:00
|
|
|
# Add FreeRTOS Kernel private include directories
|
|
|
|
list(APPEND private_include_dirs
|
|
|
|
"${kernel_impl}/include/freertos") # FreeRTOS headers via `#include "xxx.h"`
|
|
|
|
|
|
|
|
# Add port private include directories
|
|
|
|
if(arch STREQUAL "linux")
|
2023-09-26 05:47:16 -04:00
|
|
|
list(APPEND private_include_dirs
|
|
|
|
"${kernel_impl}/portable/${arch}/") # Linux port `#include "utils/wait_for_event.h"`
|
2023-05-08 04:37:59 -04:00
|
|
|
endif()
|
|
|
|
|
|
|
|
# Add ESP-additions private include directories
|
|
|
|
list(APPEND private_include_dirs
|
|
|
|
"esp_additions") # For `include "freertos_tasks_c_additions.h"`
|
|
|
|
|
|
|
|
# ------------------------------------------------------- Misc ---------------------------------------------------------
|
2022-02-24 08:03:39 -05:00
|
|
|
|
2023-05-08 04:37:59 -04:00
|
|
|
# Add linker fragments
|
|
|
|
list(APPEND ldfragments
|
|
|
|
"linker_common.lf")
|
|
|
|
|
|
|
|
if((arch STREQUAL "xtensa") OR (arch STREQUAL "riscv"))
|
|
|
|
if(kernel_impl STREQUAL "FreeRTOS-Kernel-SMP")
|
|
|
|
list(APPEND ldfragments
|
|
|
|
"linker_smp.lf")
|
|
|
|
else()
|
|
|
|
list(APPEND ldfragments
|
|
|
|
"linker.lf")
|
|
|
|
endif()
|
2020-11-05 23:03:21 -05:00
|
|
|
endif()
|
2020-02-26 07:21:59 -05:00
|
|
|
|
2023-05-08 04:37:59 -04:00
|
|
|
# ------------------------------------------------ Register Component --------------------------------------------------
|
2023-04-10 11:46:58 -04:00
|
|
|
|
2023-05-08 04:37:59 -04:00
|
|
|
idf_component_register(SRCS ${srcs}
|
2020-01-17 09:44:13 -05:00
|
|
|
INCLUDE_DIRS ${include_dirs}
|
2023-05-08 04:37:59 -04:00
|
|
|
PRIV_INCLUDE_DIRS ${private_include_dirs}
|
|
|
|
LDFRAGMENTS ${ldfragments}
|
|
|
|
PRIV_REQUIRES ${private_requirements})
|
2020-11-10 02:40:01 -05:00
|
|
|
|
2023-05-08 04:37:59 -04:00
|
|
|
if(arch STREQUAL "linux")
|
2022-10-13 11:52:40 -04:00
|
|
|
target_compile_definitions(${COMPONENT_LIB} PUBLIC "projCOVERAGE_TEST=0")
|
|
|
|
target_link_libraries(${COMPONENT_LIB} PUBLIC pthread)
|
2023-04-03 14:31:51 -04:00
|
|
|
if(BYPASS_EINTR_ISSUE)
|
2023-11-27 08:32:52 -05:00
|
|
|
target_link_libraries(${COMPONENT_LIB} PRIVATE dl)
|
2023-04-03 14:31:51 -04:00
|
|
|
endif()
|
2023-12-21 06:45:29 -05:00
|
|
|
|
|
|
|
# Disable strict prototype warnings in upstream code
|
|
|
|
# (struct event * event_create() is missing 'void')
|
|
|
|
set_source_files_properties(
|
|
|
|
"${kernel_impl}/portable/${arch}/utils/wait_for_event.c"
|
|
|
|
PROPERTIES COMPILE_OPTIONS
|
|
|
|
"-Wno-strict-prototypes"
|
|
|
|
)
|
2022-08-24 06:31:45 -04:00
|
|
|
else()
|
2022-10-13 11:52:40 -04:00
|
|
|
idf_component_get_property(COMPONENT_DIR freertos COMPONENT_DIR)
|
2018-01-11 21:49:13 -05:00
|
|
|
|
2023-05-08 04:37:59 -04:00
|
|
|
idf_component_set_property(freertos ORIG_INCLUDE_PATH "${COMPONENT_DIR}/${kernel_impl}/include/freertos/")
|
2018-08-16 01:01:43 -04:00
|
|
|
|
2022-10-13 11:52:40 -04:00
|
|
|
if(CONFIG_FREERTOS_DEBUG_OCDAWARE)
|
|
|
|
target_link_libraries(${COMPONENT_LIB} INTERFACE "-Wl,--undefined=FreeRTOS_openocd_params")
|
|
|
|
endif()
|
2022-02-24 08:03:39 -05:00
|
|
|
|
2022-10-13 11:52:40 -04:00
|
|
|
set_source_files_properties(
|
|
|
|
tasks.c
|
|
|
|
event_groups.c
|
|
|
|
timers.c
|
|
|
|
queue.c
|
|
|
|
stream_buffer.c
|
|
|
|
PROPERTIES COMPILE_DEFINITIONS
|
|
|
|
_ESP_FREERTOS_INTERNAL
|
|
|
|
)
|
2022-04-16 02:34:22 -04:00
|
|
|
|
2022-10-13 11:52:40 -04:00
|
|
|
# The freertos component provides the `start_app` and `start_app_other_cores`
|
|
|
|
# if it is included in the build. It then calls `app_main`
|
|
|
|
# from the main task created, which must be provided by the user.
|
|
|
|
# Like for `start_app` and `start_app_other_cores`,
|
|
|
|
# we can't establish dependency on what we don't yet know, so we force the
|
|
|
|
# linker to not drop this symbol.
|
|
|
|
target_link_libraries(${COMPONENT_LIB} INTERFACE "-u app_main")
|
|
|
|
|
|
|
|
if(CONFIG_APPTRACE_SV_ENABLE)
|
|
|
|
# FreeRTOS headers have a dependency on app_trace when SystemView tracing is enabled
|
|
|
|
idf_component_optional_requires(PUBLIC app_trace)
|
|
|
|
elseif(CONFIG_APPTRACE_ENABLE)
|
2022-11-24 09:20:50 -05:00
|
|
|
# [refactor-todo]: app_startup.c esp_startup_start_app_other_cores() has a dependency on esp_apptrace_init()
|
|
|
|
# (called on CPU1). This should be resolved when link-time registration of startup functions is added.
|
2022-10-13 11:52:40 -04:00
|
|
|
idf_component_optional_requires(PRIVATE app_trace)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(CONFIG_ESP_SYSTEM_GDBSTUB_RUNTIME)
|
2022-11-24 09:20:50 -05:00
|
|
|
# [refactor-todo]: app_startup.c esp_startup_start_app_other_cores() calls esp_gdbstub_init() (called on CPU0).
|
|
|
|
# This should be resolved when link-time registration of startup functions is added.
|
2022-10-13 11:52:40 -04:00
|
|
|
idf_component_optional_requires(PRIVATE esp_gdbstub)
|
|
|
|
endif()
|
2022-05-10 22:32:56 -04:00
|
|
|
|
2022-10-13 11:52:40 -04:00
|
|
|
if(CONFIG_FREERTOS_RUN_TIME_STATS_USING_ESP_TIMER)
|
|
|
|
# [refactor-todo]: esp_timer is required by FreeRTOS when we use esp_timer_get_time() to do profiling
|
|
|
|
# Introduce a port wrapper function to avoid including esp_timer.h into the public header
|
|
|
|
idf_component_optional_requires(PUBLIC esp_timer)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(CONFIG_SPIRAM)
|
|
|
|
idf_component_optional_requires(PRIVATE esp_psram)
|
|
|
|
endif()
|
2022-10-31 05:39:17 -04:00
|
|
|
|
2023-05-08 04:37:59 -04:00
|
|
|
if(CONFIG_PM_TRACE)
|
|
|
|
# esp_pm is required by port_systick.c for tracing
|
|
|
|
idf_component_optional_requires(PRIVATE esp_pm)
|
|
|
|
endif()
|
|
|
|
|
2022-05-10 22:32:56 -04:00
|
|
|
endif()
|