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 15load("@bazel_skylib//rules:run_binary.bzl", "run_binary") 16load("@rules_cc//cc:cc_library.bzl", "cc_library") 17load("@rules_python//sphinxdocs:sphinx_docs_library.bzl", "sphinx_docs_library") 18load("//pw_build:compatibility.bzl", "incompatible_with_mcu") 19load("//pw_unit_test:pw_cc_test.bzl", "pw_cc_test") 20 21package(default_visibility = ["//visibility:public"]) 22 23licenses(["notice"]) 24 25cc_library( 26 name = "id", 27 hdrs = [ 28 "id_public_overrides/pw_thread_backend/id_inline.h", 29 "id_public_overrides/pw_thread_backend/id_native.h", 30 ], 31 strip_include_prefix = "id_public_overrides", 32 deps = [ 33 ":id_private", 34 ], 35) 36 37cc_library( 38 name = "id_private", 39 hdrs = [ 40 "public/pw_thread_freertos/id_inline.h", 41 "public/pw_thread_freertos/id_native.h", 42 ], 43 strip_include_prefix = "public", 44 target_compatible_with = [ 45 "//pw_build/constraints/rtos:freertos", 46 ], 47 visibility = ["//visibility:private"], 48 deps = [ 49 "//pw_assert:assert", 50 "//pw_interrupt:context", 51 "//pw_thread:id.facade", 52 "@freertos", 53 ], 54) 55 56cc_library( 57 name = "sleep", 58 hdrs = [ 59 "sleep_public_overrides/pw_thread_backend/sleep_inline.h", 60 ], 61 strip_include_prefix = "sleep_public_overrides", 62 deps = [ 63 ":sleep_private", 64 ], 65) 66 67cc_library( 68 name = "sleep_private", 69 srcs = [ 70 "sleep.cc", 71 ], 72 hdrs = [ 73 "public/pw_thread_freertos/sleep_inline.h", 74 ], 75 implementation_deps = ["//pw_assert:check"], 76 strip_include_prefix = "public", 77 target_compatible_with = [ 78 "//pw_build/constraints/rtos:freertos", 79 ], 80 visibility = ["//visibility:private"], 81 deps = [ 82 "//pw_chrono:system_clock", 83 "//pw_thread:sleep.facade", 84 "//pw_thread:thread", 85 "@freertos", 86 ], 87) 88 89cc_library( 90 name = "thread", 91 srcs = [ 92 "thread.cc", 93 ], 94 hdrs = [ 95 "thread_public_overrides/pw_thread_backend/thread_inline.h", 96 "thread_public_overrides/pw_thread_backend/thread_native.h", 97 ], 98 implementation_deps = ["//pw_assert:check"], 99 strip_include_prefix = "thread_public_overrides", 100 deps = [ 101 ":freertos_tasktcb", 102 ":thread_private", 103 "//pw_preprocessor", 104 "//pw_thread:thread.facade", 105 "@freertos", 106 ], 107) 108 109cc_library( 110 name = "thread_private", 111 hdrs = [ 112 "public/pw_thread_freertos/config.h", 113 "public/pw_thread_freertos/context.h", 114 "public/pw_thread_freertos/options.h", 115 "public/pw_thread_freertos/thread_inline.h", 116 "public/pw_thread_freertos/thread_native.h", 117 ], 118 strip_include_prefix = "public", 119 target_compatible_with = [ 120 "//pw_build/constraints/rtos:freertos", 121 ], 122 visibility = ["//visibility:private"], 123 deps = [ 124 ":config_override", 125 ":id", 126 "//pw_assert:assert", 127 "//pw_function", 128 "//pw_string", 129 "//pw_sync:binary_semaphore", 130 "//pw_toolchain:constexpr_tag", 131 ], 132) 133 134cc_library( 135 name = "creation", 136 hdrs = [ 137 "thread_creation_public_overrides/pw_thread_backend/context.h", 138 "thread_creation_public_overrides/pw_thread_backend/options.h", 139 "thread_creation_public_overrides/pw_thread_backend/priority.h", 140 "thread_creation_public_overrides/pw_thread_backend/stack.h", 141 ], 142 strip_include_prefix = "thread_creation_public_overrides", 143 deps = ["@freertos"], 144) 145 146label_flag( 147 name = "config_override", 148 build_setting_default = "//pw_build:default_module_config", 149) 150 151cc_library( 152 name = "dynamic_test_threads", 153 srcs = [ 154 "dynamic_test_threads.cc", 155 ], 156 target_compatible_with = [ 157 "//pw_build/constraints/rtos:freertos", 158 ], 159 deps = [ 160 "//pw_chrono:system_clock", 161 "//pw_thread:non_portable_test_thread_options", 162 "//pw_thread:sleep", 163 "//pw_thread:thread.facade", 164 ], 165 alwayslink = 1, 166) 167 168pw_cc_test( 169 name = "dynamic_thread_backend_test", 170 # TODO: https://pwbug.dev/271465588 - This test fails on-device. 171 tags = ["do_not_run_test"], 172 deps = [ 173 ":dynamic_test_threads", 174 "//pw_thread:thread_facade_test", 175 ], 176) 177 178cc_library( 179 name = "static_test_threads", 180 srcs = [ 181 "static_test_threads.cc", 182 ], 183 target_compatible_with = [ 184 "//pw_build/constraints/rtos:freertos", 185 ], 186 deps = [ 187 "//pw_chrono:system_clock", 188 "//pw_thread:non_portable_test_thread_options", 189 "//pw_thread:sleep", 190 "//pw_thread:thread.facade", 191 ], 192 alwayslink = 1, 193) 194 195pw_cc_test( 196 name = "static_thread_backend_test", 197 deps = [ 198 ":static_test_threads", 199 "//pw_thread:thread_facade_test", 200 ], 201) 202 203cc_library( 204 name = "yield", 205 hdrs = [ 206 "yield_public_overrides/pw_thread_backend/yield_inline.h", 207 ], 208 strip_include_prefix = "yield_public_overrides", 209 deps = [ 210 ":yield_private", 211 ], 212) 213 214cc_library( 215 name = "yield_private", 216 hdrs = [ 217 "public/pw_thread_freertos/yield_inline.h", 218 ], 219 strip_include_prefix = "public", 220 visibility = ["//visibility:private"], 221 deps = [ 222 "//pw_assert:assert", 223 "//pw_thread:thread", 224 "//pw_thread:yield.facade", 225 "@freertos", 226 ], 227) 228 229cc_library( 230 name = "thread_iteration", 231 srcs = [ 232 "pw_thread_freertos_private/thread_iteration.h", 233 "thread_iteration.cc", 234 ], 235 target_compatible_with = [ 236 "//pw_build/constraints/rtos:freertos", 237 ], 238 deps = [ 239 ":freertos_tasktcb", 240 "//pw_function", 241 "//pw_span", 242 "//pw_status", 243 "//pw_thread:thread_info", 244 "//pw_thread:thread_iteration.facade", 245 "//pw_thread_freertos:util", 246 ], 247) 248 249pw_cc_test( 250 name = "thread_iteration_test", 251 srcs = [ 252 "pw_thread_freertos_private/thread_iteration.h", 253 "thread_iteration_test.cc", 254 ], 255 # TODO: https://pwbug.dev/271465588 - This test fails on-device. 256 tags = ["do_not_run_test"], 257 deps = [ 258 ":freertos_tasktcb", 259 ":static_test_threads", 260 ":thread_iteration", 261 "//pw_bytes", 262 "//pw_span", 263 "//pw_string:builder", 264 "//pw_string:util", 265 "//pw_sync:thread_notification", 266 "//pw_thread:non_portable_test_thread_options", 267 "//pw_thread:thread", 268 "//pw_thread:thread_info", 269 "//pw_thread:thread_iteration", 270 ], 271) 272 273cc_library( 274 name = "util", 275 srcs = [ 276 "util.cc", 277 ], 278 hdrs = [ 279 "public/pw_thread_freertos/util.h", 280 ], 281 strip_include_prefix = "public", 282 target_compatible_with = [ 283 "//pw_build/constraints/rtos:freertos", 284 ], 285 deps = [ 286 "//pw_function", 287 "//pw_log", 288 "//pw_span", 289 "//pw_status", 290 "@freertos", 291 ], 292) 293 294cc_library( 295 name = "snapshot", 296 srcs = [ 297 "snapshot.cc", 298 ], 299 hdrs = [ 300 "public/pw_thread_freertos/snapshot.h", 301 ], 302 # TODO: b/269204725 - Put this in the toolchain configuration instead. I 303 # would like to say `copts = ["-Wno-c++20-designator"]`, but arm-gcc tells 304 # me that's an "unrecognized command line option"; I think it may be a 305 # clang-only flag. 306 copts = ["-Wno-pedantic"], 307 strip_include_prefix = "public", 308 target_compatible_with = [ 309 "//pw_build/constraints/rtos:freertos", 310 ], 311 deps = [ 312 ":freertos_tasktcb", 313 ":util", 314 "//pw_function", 315 "//pw_log", 316 "//pw_protobuf", 317 "//pw_status", 318 "//pw_thread:snapshot", 319 "//pw_thread:thread_pwpb", 320 ], 321) 322 323cc_library( 324 name = "freertos_tasktcb", 325 hdrs = [ 326 "public/pw_thread_freertos/freertos_tsktcb.h", 327 ], 328 strip_include_prefix = "public", 329 deps = [ 330 ":freertos_tasktcb_private", 331 "@freertos", 332 ], 333) 334 335cc_library( 336 name = "freertos_tasktcb_private", 337 hdrs = [":generate_freertos_tsktcb"], 338 strip_include_prefix = "thread_public_overrides", 339 visibility = ["//visibility:private"], 340 deps = [ 341 "@freertos", 342 ], 343) 344 345run_binary( 346 name = "generate_freertos_tsktcb", 347 srcs = [ 348 "@freertos//:tasks.c", 349 ], 350 outs = [":thread_public_overrides/pw_thread_freertos_backend/freertos_tsktcb.h"], 351 args = [ 352 "--freertos-tasks-c=$(execpath @freertos//:tasks.c)", 353 "--output=$(execpath :thread_public_overrides/pw_thread_freertos_backend/freertos_tsktcb.h)", 354 ], 355 tool = "//pw_thread_freertos/py:generate_freertos_tsktcb", 356) 357 358cc_library( 359 name = "test_thread_context", 360 hdrs = [ 361 "test_thread_context_public_overrides/pw_thread_backend/test_thread_context_native.h", 362 ], 363 strip_include_prefix = "test_thread_context_public_overrides", 364 target_compatible_with = [ 365 "//pw_build/constraints/rtos:freertos", 366 ], 367 deps = [ 368 ":test_thread_context_private", 369 ], 370) 371 372cc_library( 373 name = "test_thread_context_private", 374 hdrs = [ 375 "public/pw_thread_freertos/test_thread_context_native.h", 376 ], 377 strip_include_prefix = "public", 378 target_compatible_with = [ 379 "//pw_build/constraints/rtos:freertos", 380 ], 381 visibility = ["//visibility:private"], 382 deps = [ 383 ":thread", 384 "//pw_thread:test_thread_context.facade", 385 ], 386) 387 388sphinx_docs_library( 389 name = "docs", 390 srcs = [ 391 "docs.rst", 392 ], 393 prefix = "pw_thread_freertos/", 394 target_compatible_with = incompatible_with_mcu(), 395) 396