1# Copyright 2020 The Pigweed Authors 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); you may not 4# use this file except in compliance with the License. You may obtain a copy of 5# the License at 6# 7# https://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12# License for the specific language governing permissions and limitations under 13# the License. 14 15import("//build_overrides/pigweed.gni") 16 17import("$dir_pigweed/third_party/freertos/freertos.gni") 18import("$dir_pw_build/error.gni") 19import("$dir_pw_build/facade.gni") 20import("$dir_pw_build/module_config.gni") 21import("$dir_pw_build/target_types.gni") 22import("$dir_pw_chrono/backend.gni") 23import("$dir_pw_docgen/docs.gni") 24import("$dir_pw_thread/backend.gni") 25import("$dir_pw_thread_freertos/backend.gni") 26import("$dir_pw_unit_test/test.gni") 27 28declare_args() { 29 # The build target that overrides the default configuration options for this 30 # module. This should point to a source set that provides defines through a 31 # public config (which may -include a file or add defines directly). 32 pw_thread_freertos_CONFIG = pw_build_DEFAULT_MODULE_CONFIG 33} 34 35config("public_include_path") { 36 include_dirs = [ "public" ] 37 visibility = [ ":*" ] 38} 39 40pw_source_set("config") { 41 public = [ "public/pw_thread_freertos/config.h" ] 42 public_configs = [ ":public_include_path" ] 43 public_deps = [ 44 "$dir_pw_third_party/freertos", 45 pw_thread_freertos_CONFIG, 46 ] 47} 48 49config("id_public_overrides") { 50 include_dirs = [ "id_public_overrides" ] 51 visibility = [ ":*" ] 52} 53 54# This target provides the backend for pw::thread::Id & pw::this_thread::get_id. 55pw_source_set("id") { 56 public_configs = [ 57 ":public_include_path", 58 ":id_public_overrides", 59 ] 60 public_deps = [ 61 "$dir_pw_assert", 62 "$dir_pw_interrupt:context", 63 "$dir_pw_third_party/freertos", 64 ] 65 public = [ 66 "id_public_overrides/pw_thread_backend/id_inline.h", 67 "id_public_overrides/pw_thread_backend/id_native.h", 68 "public/pw_thread_freertos/id_inline.h", 69 "public/pw_thread_freertos/id_native.h", 70 ] 71 deps = [ "$dir_pw_thread:id.facade" ] 72} 73 74pw_build_assert("check_system_clock_backend") { 75 condition = 76 pw_chrono_SYSTEM_CLOCK_BACKEND == "" || 77 pw_chrono_SYSTEM_CLOCK_BACKEND == "$dir_pw_chrono_freertos:system_clock" 78 message = "This FreeRTOS backend only works with the FreeRTOS " + 79 "pw::chrono::SystemClock backend " + 80 "(pw_chrono_SYSTEM_CLOCK_BACKEND = " + 81 "\"$dir_pw_chrono_freertos:system_clock\")" 82 visibility = [ ":*" ] 83} 84 85config("sleep_public_overrides") { 86 include_dirs = [ "sleep_public_overrides" ] 87 visibility = [ ":*" ] 88} 89 90# This target provides the backend for pw::this_thread::sleep_{for,until}. 91pw_source_set("sleep") { 92 public_configs = [ 93 ":public_include_path", 94 ":sleep_public_overrides", 95 ] 96 public = [ 97 "public/pw_thread_freertos/sleep_inline.h", 98 "sleep_public_overrides/pw_thread_backend/sleep_inline.h", 99 ] 100 public_deps = [ "$dir_pw_chrono:system_clock" ] 101 sources = [ "sleep.cc" ] 102 deps = [ 103 ":check_system_clock_backend", 104 "$dir_pw_assert", 105 "$dir_pw_chrono_freertos:system_clock", 106 "$dir_pw_third_party/freertos", 107 "$dir_pw_thread:id", 108 "$dir_pw_thread:sleep.facade", 109 ] 110} 111 112config("thread_public_overrides") { 113 include_dirs = [ "thread_public_overrides" ] 114 visibility = [ ":*" ] 115} 116 117# This target provides the backend for pw::thread::Thread and the headers needed 118# for thread creation. 119pw_source_set("thread") { 120 public_configs = [ 121 ":public_include_path", 122 ":thread_public_overrides", 123 ] 124 public_deps = [ 125 ":config", 126 "$dir_pw_assert", 127 "$dir_pw_string", 128 "$dir_pw_third_party/freertos", 129 "$dir_pw_thread:id", 130 "$dir_pw_thread:thread.facade", 131 dir_pw_span, 132 ] 133 public = [ 134 "public/pw_thread_freertos/context.h", 135 "public/pw_thread_freertos/options.h", 136 "public/pw_thread_freertos/thread_inline.h", 137 "public/pw_thread_freertos/thread_native.h", 138 "thread_public_overrides/pw_thread_backend/thread_inline.h", 139 "thread_public_overrides/pw_thread_backend/thread_native.h", 140 ] 141 allow_circular_includes_from = [ "$dir_pw_thread:thread.facade" ] 142 sources = [ "thread.cc" ] 143} 144 145# This target provides the backend for pw::thread::thread_iteration. 146if (pw_thread_freertos_FREERTOS_TSKTCB_BACKEND != "") { 147 pw_source_set("thread_iteration") { 148 public_configs = [ ":thread_public_overrides" ] 149 deps = [ 150 ":freertos_tsktcb", 151 "$dir_pw_third_party/freertos", 152 "$dir_pw_thread:thread_info", 153 "$dir_pw_thread:thread_iteration.facade", 154 "$dir_pw_thread_freertos:util", 155 dir_pw_function, 156 dir_pw_span, 157 dir_pw_status, 158 ] 159 sources = [ 160 "pw_thread_freertos_private/thread_iteration.h", 161 "thread_iteration.cc", 162 ] 163 } 164} 165 166config("yield_public_overrides") { 167 include_dirs = [ "yield_public_overrides" ] 168 visibility = [ ":*" ] 169} 170 171# This target provides the backend for pw::this_thread::yield. 172pw_source_set("yield") { 173 public_configs = [ 174 ":public_include_path", 175 ":yield_public_overrides", 176 ] 177 public = [ 178 "public/pw_thread_freertos/yield_inline.h", 179 "yield_public_overrides/pw_thread_backend/yield_inline.h", 180 ] 181 public_deps = [ 182 "$dir_pw_assert", 183 "$dir_pw_third_party/freertos", 184 "$dir_pw_thread:id", 185 ] 186 deps = [ "$dir_pw_thread:yield.facade" ] 187} 188 189pw_source_set("util") { 190 public_configs = [ ":public_include_path" ] 191 public_deps = [ 192 "$dir_pw_third_party/freertos", 193 dir_pw_function, 194 dir_pw_span, 195 dir_pw_status, 196 ] 197 public = [ "public/pw_thread_freertos/util.h" ] 198 deps = [ dir_pw_log ] 199 sources = [ "util.cc" ] 200} 201 202# Action to generate `freertos_tsktcb.h` for 203# pw_thread_freertos_FREERTOS_TSKTCB_BACKEND. 204if (dir_pw_third_party_freertos != "") { 205 pw_python_action("generate_freertos_tsktcb") { 206 _out_path = "${target_gen_dir}/public_overrides/pw_thread_freertos_backend/freertos_tsktcb.h" 207 script = "py/pw_thread_freertos/generate_freertos_tsktcb.py" 208 args = [ 209 "--freertos-src-dir", 210 rebase_path(dir_pw_third_party_freertos, root_build_dir), 211 "-o", 212 rebase_path(_out_path, root_build_dir), 213 ] 214 outputs = [ _out_path ] 215 visibility = [ ":auto_freertos_tsktcb" ] 216 } 217 218 config("auto_freertos_include_path") { 219 include_dirs = [ "${target_gen_dir}/public_overrides" ] 220 visibility = [ ":auto_freertos_tsktcb" ] 221 } 222 223 # Source set that provides backend for automatically generated 224 # `freertos_tsktcb.h` header. 225 pw_source_set("auto_freertos_tsktcb") { 226 public_configs = [ ":auto_freertos_include_path" ] 227 public = [ "${target_gen_dir}/public_overrides/pw_thread_freertos_backend/freertos_tsktcb.h" ] 228 public_deps = [ "$dir_pw_third_party/freertos" ] 229 deps = [ ":generate_freertos_tsktcb" ] 230 visibility = [ ":freertos_tsktcb" ] 231 } 232} 233 234pw_facade("freertos_tsktcb") { 235 backend = pw_thread_freertos_FREERTOS_TSKTCB_BACKEND 236 public_configs = [ ":public_include_path" ] 237 public = [ "public/pw_thread_freertos/freertos_tsktcb.h" ] 238 public_deps = [ "$dir_pw_third_party/freertos" ] 239} 240 241pw_source_set("snapshot") { 242 public_configs = [ ":public_include_path" ] 243 public_deps = [ 244 ":config", 245 "$dir_pw_third_party/freertos", 246 "$dir_pw_thread:protos.pwpb", 247 "$dir_pw_thread:snapshot", 248 dir_pw_function, 249 dir_pw_protobuf, 250 dir_pw_status, 251 ] 252 public = [ "public/pw_thread_freertos/snapshot.h" ] 253 sources = [ "snapshot.cc" ] 254 deps = [ 255 ":freertos_tsktcb", 256 ":util", 257 dir_pw_function, 258 dir_pw_log, 259 ] 260} 261 262pw_test_group("tests") { 263 tests = [ 264 ":dynamic_thread_backend_test", 265 ":static_thread_backend_test", 266 ] 267 if (pw_thread_freertos_FREERTOS_TSKTCB_BACKEND != "") { 268 tests += [ ":thread_iteration_test" ] 269 } 270} 271 272if (pw_thread_freertos_FREERTOS_TSKTCB_BACKEND != "") { 273 pw_test("thread_iteration_test") { 274 enable_if = pw_thread_THREAD_BACKEND == "$dir_pw_thread_freertos:thread" 275 sources = [ 276 "pw_thread_freertos_private/thread_iteration.h", 277 "thread_iteration_test.cc", 278 ] 279 deps = [ 280 ":freertos_tsktcb", 281 ":static_test_threads", 282 ":thread_iteration", 283 "$dir_pw_bytes", 284 "$dir_pw_span", 285 "$dir_pw_string:builder", 286 "$dir_pw_string:util", 287 "$dir_pw_sync:thread_notification", 288 "$dir_pw_third_party/freertos", 289 "$dir_pw_thread:test_threads", 290 "$dir_pw_thread:thread", 291 "$dir_pw_thread:thread_info", 292 "$dir_pw_thread:thread_iteration", 293 ] 294 } 295} 296 297pw_source_set("dynamic_test_threads") { 298 public_deps = [ "$dir_pw_thread:test_threads" ] 299 sources = [ "dynamic_test_threads.cc" ] 300 deps = [ 301 "$dir_pw_chrono:system_clock", 302 "$dir_pw_thread:sleep", 303 "$dir_pw_thread:thread", 304 ] 305} 306 307pw_test("dynamic_thread_backend_test") { 308 enable_if = pw_thread_THREAD_BACKEND == "$dir_pw_thread_freertos:thread" 309 deps = [ 310 ":dynamic_test_threads", 311 "$dir_pw_thread:thread_facade_test", 312 ] 313} 314 315pw_source_set("static_test_threads") { 316 public_deps = [ "$dir_pw_thread:test_threads" ] 317 sources = [ "static_test_threads.cc" ] 318 deps = [ 319 "$dir_pw_chrono:system_clock", 320 "$dir_pw_thread:sleep", 321 "$dir_pw_thread:thread", 322 ] 323} 324 325pw_test("static_thread_backend_test") { 326 enable_if = pw_thread_THREAD_BACKEND == "$dir_pw_thread_freertos:thread" 327 deps = [ 328 ":static_test_threads", 329 "$dir_pw_thread:thread_facade_test", 330 ] 331} 332 333pw_doc_group("docs") { 334 sources = [ "docs.rst" ] 335} 336