/
CMakeLists.txt
251 lines (210 loc) · 9.11 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
# 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
if(BOOTLOADER_BUILD)
idf_component_register()
return()
endif()
# Set some convenience variables
idf_build_get_property(target IDF_TARGET)
if(CONFIG_FREERTOS_SMP)
set(kernel_impl "FreeRTOS-Kernel-SMP")
else()
set(kernel_impl "FreeRTOS-Kernel")
endif()
if(CONFIG_IDF_TARGET_ARCH_XTENSA)
set(arch "xtensa")
elseif(CONFIG_IDF_TARGET_ARCH_RISCV)
set(arch "riscv")
elseif(${target} STREQUAL "linux")
set(arch "linux")
endif()
set(srcs "")
set(include_dirs "")
set(private_include_dirs "")
set(private_requirements "")
set(ldfragments "")
# ---------------------------------------------------- Set Sources -----------------------------------------------------
# Add common source files
list(APPEND srcs
"heap_idf.c")
if((arch STREQUAL "xtensa") OR (arch STREQUAL "riscv"))
list(APPEND srcs
"app_startup.c"
"port_common.c"
"port_systick.c")
endif()
# 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
list(APPEND srcs
"${kernel_impl}/portable/${arch}/port.c")
if(arch STREQUAL "linux")
list(APPEND srcs
"${kernel_impl}/portable/${arch}/utils/wait_for_event.c")
if(kernel_impl STREQUAL "FreeRTOS-Kernel")
list(APPEND srcs
"${kernel_impl}/portable/${arch}/port_idf.c")
endif()
else()
list(APPEND srcs
"${kernel_impl}/portable/${arch}/portasm.S")
endif()
if(arch STREQUAL "xtensa")
list(APPEND srcs
"${kernel_impl}/portable/${arch}/xtensa_init.c"
"${kernel_impl}/portable/${arch}/xtensa_overlay_os_hook.c")
endif()
# Add ESP-additions source files
list(APPEND srcs
"esp_additions/freertos_compatibility.c"
"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
# lwIP enabled, we need to use linux system select which will receive EINTR event on every FreeRTOS interrupt, we
# workaround this problem by wrapping select() to bypass and silence the EINTR events
set(BYPASS_EINTR_ISSUE 0)
if(NOT CONFIG_LWIP_ENABLE)
set(BYPASS_EINTR_ISSUE 1)
list(APPEND srcs "esp_additions/FreeRTOSSimulator_wrappers.c")
endif()
endif()
# ------------------------------------------------ Set Public Includes -------------------------------------------------
# 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"`
# 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
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"`
# 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"`
# ----------------------------------------------- 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"
endif()
# 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")
list(APPEND private_include_dirs
"${kernel_impl}/portable/${arch}/") # Linux port `#include "utils/wait_for_event.h"`
endif()
# Add ESP-additions private include directories
list(APPEND private_include_dirs
"esp_additions") # For `include "freertos_tasks_c_additions.h"`
# ------------------------------------------------------- Misc ---------------------------------------------------------
# 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()
endif()
# ------------------------------------------------ Register Component --------------------------------------------------
idf_component_register(SRCS ${srcs}
INCLUDE_DIRS ${include_dirs}
PRIV_INCLUDE_DIRS ${private_include_dirs}
LDFRAGMENTS ${ldfragments}
PRIV_REQUIRES ${private_requirements})
if(arch STREQUAL "linux")
target_compile_definitions(${COMPONENT_LIB} PUBLIC "projCOVERAGE_TEST=0")
target_link_libraries(${COMPONENT_LIB} PUBLIC pthread)
if(BYPASS_EINTR_ISSUE)
target_link_libraries(${COMPONENT_LIB} PRIVATE dl)
endif()
# 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"
)
else()
idf_component_get_property(COMPONENT_DIR freertos COMPONENT_DIR)
idf_component_set_property(freertos ORIG_INCLUDE_PATH "${COMPONENT_DIR}/${kernel_impl}/include/freertos/")
if(CONFIG_FREERTOS_DEBUG_OCDAWARE)
target_link_libraries(${COMPONENT_LIB} INTERFACE "-Wl,--undefined=FreeRTOS_openocd_params")
endif()
set_source_files_properties(
tasks.c
event_groups.c
timers.c
queue.c
stream_buffer.c
PROPERTIES COMPILE_DEFINITIONS
_ESP_FREERTOS_INTERNAL
)
# 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)
# [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.
idf_component_optional_requires(PRIVATE app_trace)
endif()
if(CONFIG_ESP_SYSTEM_GDBSTUB_RUNTIME)
# [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.
idf_component_optional_requires(PRIVATE esp_gdbstub)
endif()
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()
if(CONFIG_PM_TRACE)
# esp_pm is required by port_systick.c for tracing
idf_component_optional_requires(PRIVATE esp_pm)
endif()
endif()