CMakeLists.txt 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. # FreeRTOS Component Architecture
  2. #
  3. # The FreeRTOS component mainly contains
  4. # - Different FreeRTOS kernel implementations (namely IDF FreeRTOS and Amazon SMP FreeRTOS).
  5. # - Different ports of each architecture for each kernel implementaiton.
  6. # - IDF additions to FreeRTOS (e.g., features and API) to augment FreeRTOS
  7. #
  8. # The FreeRTOS component organizes its files as follows
  9. #
  10. # - `./config`
  11. # - Contains all "FreeRTOSConfig.h" files required by FreeRTOS
  12. # - `./esp_additions`
  13. # - Additional features added by ESP-IDF to augment FreeRTOS, and not part of the original kernel
  14. # - `./FreeRTOS-Kernel-...`
  15. # - Different FreeRTOS kernel implementations. Each implementaiton is kept in its own directory.
  16. # - Ports for the implementation are kept in `FreeRTOS-Kernel-.../portable/xxx/`\
  17. # - `./test_apps`
  18. # - Contains all unit tests/test apps for the FreeRTOS component.
  19. # - `./`
  20. # - Files common across all kernel implementations and all ports
  21. # Bootloader builds only needs FreeRTOS for config, not for anything else
  22. if(BOOTLOADER_BUILD)
  23. idf_component_register()
  24. return()
  25. endif()
  26. # Set some convenience variables
  27. idf_build_get_property(target IDF_TARGET)
  28. if(CONFIG_FREERTOS_SMP)
  29. set(kernel_impl "FreeRTOS-Kernel-SMP")
  30. else()
  31. set(kernel_impl "FreeRTOS-Kernel")
  32. endif()
  33. if(CONFIG_IDF_TARGET_ARCH_XTENSA)
  34. set(arch "xtensa")
  35. elseif(CONFIG_IDF_TARGET_ARCH_RISCV)
  36. set(arch "riscv")
  37. elseif(${target} STREQUAL "linux")
  38. set(arch "linux")
  39. endif()
  40. set(srcs "")
  41. set(include_dirs "")
  42. set(private_include_dirs "")
  43. set(private_requirements "")
  44. set(ldfragments "")
  45. # ---------------------------------------------------- Set Sources -----------------------------------------------------
  46. # Add common source files
  47. list(APPEND srcs
  48. "heap_idf.c")
  49. if((arch STREQUAL "xtensa") OR (arch STREQUAL "riscv"))
  50. list(APPEND srcs
  51. "app_startup.c"
  52. "port_common.c"
  53. "port_systick.c")
  54. endif()
  55. # Add FreeRTOS Kernel source files
  56. list(APPEND srcs
  57. "${kernel_impl}/list.c"
  58. "${kernel_impl}/queue.c"
  59. "${kernel_impl}/tasks.c"
  60. "${kernel_impl}/timers.c"
  61. "${kernel_impl}/event_groups.c"
  62. "${kernel_impl}/stream_buffer.c")
  63. # Add port source files
  64. list(APPEND srcs
  65. "${kernel_impl}/portable/${arch}/port.c")
  66. if(arch STREQUAL "linux")
  67. list(APPEND srcs
  68. "${kernel_impl}/portable/${arch}/utils/wait_for_event.c")
  69. if(kernel_impl STREQUAL "FreeRTOS-Kernel")
  70. list(APPEND srcs
  71. "${kernel_impl}/portable/${arch}/port_idf.c")
  72. endif()
  73. else()
  74. list(APPEND srcs
  75. "${kernel_impl}/portable/${arch}/portasm.S")
  76. endif()
  77. if(arch STREQUAL "xtensa")
  78. list(APPEND srcs
  79. "${kernel_impl}/portable/${arch}/xtensa_init.c"
  80. "${kernel_impl}/portable/${arch}/xtensa_overlay_os_hook.c")
  81. endif()
  82. # Add ESP-additions source files
  83. list(APPEND srcs
  84. "esp_additions/freertos_compatibility.c"
  85. "esp_additions/idf_additions.c")
  86. if(arch STREQUAL "linux")
  87. # Check if we need to address the FreeRTOS EINTR coexistence with linux system calls if we're building without
  88. # lwIP, we need to use linux system select which will receive EINTR event on every FreeRTOS interrupt, we
  89. # workaround this problem by wrapping select() to bypass and silence the EINTR events
  90. set(BYPASS_EINTR_ISSUE 0)
  91. idf_build_get_property(build_components BUILD_COMPONENTS)
  92. if(NOT "lwip" IN_LIST build_components)
  93. set(BYPASS_EINTR_ISSUE 1)
  94. list(APPEND srcs "esp_additions/FreeRTOSSimulator_wrappers.c")
  95. endif()
  96. endif()
  97. # ------------------------------------------------ Set Public Includes -------------------------------------------------
  98. # Add common public include directories
  99. list(APPEND include_dirs
  100. "config/include" # For `#include "freertos/FreeRTOSConfig.h"`
  101. "config/include/freertos" # For `#include "FreeRTOSConfig.h"`
  102. "config/${arch}/include") # For `#include "freertos/FreeRTOSConfig_arch.h"`
  103. # Add FreeRTOS Kernel public include directories
  104. list(APPEND include_dirs
  105. "${kernel_impl}/include") # FreeRTOS headers via `#include "freertos/xxx.h"`
  106. # Add port public include directories
  107. list(APPEND include_dirs
  108. "${kernel_impl}/portable/${arch}/include" # For port headers via `#include "freertos/...h"`
  109. "${kernel_impl}/portable/${arch}/include/freertos") # For port headers via `#include "...h"`
  110. # Add ESP-additions public include directories
  111. list(APPEND include_dirs
  112. "esp_additions/include") # For ESP-addition headers via
  113. # - `#include "freertos/...h"`
  114. # - `#include "esp_private/...h"`
  115. # ----------------------------------------------- Set Private Includes -------------------------------------------------
  116. # Add common private include directories
  117. if((arch STREQUAL "xtensa") OR (arch STREQUAL "riscv"))
  118. list(APPEND private_include_dirs
  119. ".") # For `#include "port_systick.h"
  120. endif()
  121. # Add FreeRTOS Kernel private include directories
  122. list(APPEND private_include_dirs
  123. "${kernel_impl}/include/freertos") # FreeRTOS headers via `#include "xxx.h"`
  124. # Add port private include directories
  125. if(arch STREQUAL "linux")
  126. list(APPEND private_include_dirs
  127. "${kernel_impl}/portable/${arch}/") # Linux port `#include "utils/wait_for_event.h"`
  128. endif()
  129. # Add ESP-additions private include directories
  130. list(APPEND private_include_dirs
  131. "esp_additions") # For `include "freertos_tasks_c_additions.h"`
  132. # ------------------------------------------------------- Misc ---------------------------------------------------------
  133. # Add linker fragments
  134. list(APPEND ldfragments
  135. "linker_common.lf")
  136. if((arch STREQUAL "xtensa") OR (arch STREQUAL "riscv"))
  137. if(kernel_impl STREQUAL "FreeRTOS-Kernel-SMP")
  138. list(APPEND ldfragments
  139. "linker_smp.lf")
  140. else()
  141. list(APPEND ldfragments
  142. "linker.lf")
  143. endif()
  144. endif()
  145. # ------------------------------------------------ Register Component --------------------------------------------------
  146. idf_component_register(SRCS ${srcs}
  147. INCLUDE_DIRS ${include_dirs}
  148. PRIV_INCLUDE_DIRS ${private_include_dirs}
  149. LDFRAGMENTS ${ldfragments}
  150. PRIV_REQUIRES ${private_requirements})
  151. if(arch STREQUAL "linux")
  152. target_compile_definitions(${COMPONENT_LIB} PUBLIC "projCOVERAGE_TEST=0")
  153. target_link_libraries(${COMPONENT_LIB} PUBLIC pthread)
  154. if(BYPASS_EINTR_ISSUE)
  155. target_link_libraries(${COMPONENT_LIB} INTERFACE "-Wl,--wrap=select")
  156. endif()
  157. else()
  158. idf_component_get_property(COMPONENT_DIR freertos COMPONENT_DIR)
  159. idf_component_set_property(freertos ORIG_INCLUDE_PATH "${COMPONENT_DIR}/${kernel_impl}/include/freertos/")
  160. if(CONFIG_FREERTOS_DEBUG_OCDAWARE)
  161. target_link_libraries(${COMPONENT_LIB} INTERFACE "-Wl,--undefined=FreeRTOS_openocd_params")
  162. endif()
  163. set_source_files_properties(
  164. tasks.c
  165. event_groups.c
  166. timers.c
  167. queue.c
  168. stream_buffer.c
  169. PROPERTIES COMPILE_DEFINITIONS
  170. _ESP_FREERTOS_INTERNAL
  171. )
  172. # The freertos component provides the `start_app` and `start_app_other_cores`
  173. # if it is included in the build. It then calls `app_main`
  174. # from the main task created, which must be provided by the user.
  175. # Like for `start_app` and `start_app_other_cores`,
  176. # we can't establish dependency on what we don't yet know, so we force the
  177. # linker to not drop this symbol.
  178. target_link_libraries(${COMPONENT_LIB} INTERFACE "-u app_main")
  179. if(CONFIG_APPTRACE_SV_ENABLE)
  180. # FreeRTOS headers have a dependency on app_trace when SystemView tracing is enabled
  181. idf_component_optional_requires(PUBLIC app_trace)
  182. elseif(CONFIG_APPTRACE_ENABLE)
  183. # [refactor-todo]: app_startup.c esp_startup_start_app_other_cores() has a dependency on esp_apptrace_init()
  184. # (called on CPU1). This should be resolved when link-time registration of startup functions is added.
  185. idf_component_optional_requires(PRIVATE app_trace)
  186. endif()
  187. if(CONFIG_ESP_SYSTEM_GDBSTUB_RUNTIME)
  188. # [refactor-todo]: app_startup.c esp_startup_start_app_other_cores() calls esp_gdbstub_init() (called on CPU0).
  189. # This should be resolved when link-time registration of startup functions is added.
  190. idf_component_optional_requires(PRIVATE esp_gdbstub)
  191. endif()
  192. if(CONFIG_FREERTOS_RUN_TIME_STATS_USING_ESP_TIMER)
  193. # [refactor-todo]: esp_timer is required by FreeRTOS when we use esp_timer_get_time() to do profiling
  194. # Introduce a port wrapper function to avoid including esp_timer.h into the public header
  195. idf_component_optional_requires(PUBLIC esp_timer)
  196. endif()
  197. if(CONFIG_SPIRAM)
  198. idf_component_optional_requires(PRIVATE esp_psram)
  199. endif()
  200. if(CONFIG_PM_TRACE)
  201. # esp_pm is required by port_systick.c for tracing
  202. idf_component_optional_requires(PRIVATE esp_pm)
  203. endif()
  204. endif()