1*61c4878aSAndroid Build Coastguard Worker# Copyright 2020 The Pigweed Authors 2*61c4878aSAndroid Build Coastguard Worker# 3*61c4878aSAndroid Build Coastguard Worker# Licensed under the Apache License, Version 2.0 (the "License"); you may not 4*61c4878aSAndroid Build Coastguard Worker# use this file except in compliance with the License. You may obtain a copy of 5*61c4878aSAndroid Build Coastguard Worker# the License at 6*61c4878aSAndroid Build Coastguard Worker# 7*61c4878aSAndroid Build Coastguard Worker# https://www.apache.org/licenses/LICENSE-2.0 8*61c4878aSAndroid Build Coastguard Worker# 9*61c4878aSAndroid Build Coastguard Worker# Unless required by applicable law or agreed to in writing, software 10*61c4878aSAndroid Build Coastguard Worker# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11*61c4878aSAndroid Build Coastguard Worker# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12*61c4878aSAndroid Build Coastguard Worker# License for the specific language governing permissions and limitations under 13*61c4878aSAndroid Build Coastguard Worker# the License. 14*61c4878aSAndroid Build Coastguard Worker 15*61c4878aSAndroid Build Coastguard Workerload("@bazel_skylib//rules:run_binary.bzl", "run_binary") 16*61c4878aSAndroid Build Coastguard Workerload("//pw_unit_test:pw_cc_test.bzl", "pw_cc_test") 17*61c4878aSAndroid Build Coastguard Worker 18*61c4878aSAndroid Build Coastguard Workerpackage(default_visibility = ["//visibility:public"]) 19*61c4878aSAndroid Build Coastguard Worker 20*61c4878aSAndroid Build Coastguard Workerlicenses(["notice"]) 21*61c4878aSAndroid Build Coastguard Worker 22*61c4878aSAndroid Build Coastguard Workercc_library( 23*61c4878aSAndroid Build Coastguard Worker name = "id", 24*61c4878aSAndroid Build Coastguard Worker hdrs = [ 25*61c4878aSAndroid Build Coastguard Worker "id_public_overrides/pw_thread_backend/id_inline.h", 26*61c4878aSAndroid Build Coastguard Worker "id_public_overrides/pw_thread_backend/id_native.h", 27*61c4878aSAndroid Build Coastguard Worker "public/pw_thread_freertos/id_inline.h", 28*61c4878aSAndroid Build Coastguard Worker "public/pw_thread_freertos/id_native.h", 29*61c4878aSAndroid Build Coastguard Worker ], 30*61c4878aSAndroid Build Coastguard Worker includes = [ 31*61c4878aSAndroid Build Coastguard Worker "id_public_overrides", 32*61c4878aSAndroid Build Coastguard Worker "public", 33*61c4878aSAndroid Build Coastguard Worker ], 34*61c4878aSAndroid Build Coastguard Worker target_compatible_with = [ 35*61c4878aSAndroid Build Coastguard Worker "//pw_build/constraints/rtos:freertos", 36*61c4878aSAndroid Build Coastguard Worker ], 37*61c4878aSAndroid Build Coastguard Worker deps = [ 38*61c4878aSAndroid Build Coastguard Worker "//pw_interrupt:context", 39*61c4878aSAndroid Build Coastguard Worker "//pw_thread:id.facade", 40*61c4878aSAndroid Build Coastguard Worker "@freertos", 41*61c4878aSAndroid Build Coastguard Worker ], 42*61c4878aSAndroid Build Coastguard Worker) 43*61c4878aSAndroid Build Coastguard Worker 44*61c4878aSAndroid Build Coastguard Workercc_library( 45*61c4878aSAndroid Build Coastguard Worker name = "sleep", 46*61c4878aSAndroid Build Coastguard Worker srcs = [ 47*61c4878aSAndroid Build Coastguard Worker "sleep.cc", 48*61c4878aSAndroid Build Coastguard Worker ], 49*61c4878aSAndroid Build Coastguard Worker hdrs = [ 50*61c4878aSAndroid Build Coastguard Worker "public/pw_thread_freertos/sleep_inline.h", 51*61c4878aSAndroid Build Coastguard Worker "sleep_public_overrides/pw_thread_backend/sleep_inline.h", 52*61c4878aSAndroid Build Coastguard Worker ], 53*61c4878aSAndroid Build Coastguard Worker includes = [ 54*61c4878aSAndroid Build Coastguard Worker "public", 55*61c4878aSAndroid Build Coastguard Worker "sleep_public_overrides", 56*61c4878aSAndroid Build Coastguard Worker ], 57*61c4878aSAndroid Build Coastguard Worker target_compatible_with = [ 58*61c4878aSAndroid Build Coastguard Worker "//pw_build/constraints/rtos:freertos", 59*61c4878aSAndroid Build Coastguard Worker ], 60*61c4878aSAndroid Build Coastguard Worker deps = [ 61*61c4878aSAndroid Build Coastguard Worker "//pw_assert", 62*61c4878aSAndroid Build Coastguard Worker "//pw_chrono:system_clock", 63*61c4878aSAndroid Build Coastguard Worker "//pw_thread:sleep.facade", 64*61c4878aSAndroid Build Coastguard Worker "//pw_thread:thread", 65*61c4878aSAndroid Build Coastguard Worker "@freertos", 66*61c4878aSAndroid Build Coastguard Worker ], 67*61c4878aSAndroid Build Coastguard Worker) 68*61c4878aSAndroid Build Coastguard Worker 69*61c4878aSAndroid Build Coastguard Workercc_library( 70*61c4878aSAndroid Build Coastguard Worker name = "thread", 71*61c4878aSAndroid Build Coastguard Worker srcs = [ 72*61c4878aSAndroid Build Coastguard Worker "thread.cc", 73*61c4878aSAndroid Build Coastguard Worker ], 74*61c4878aSAndroid Build Coastguard Worker hdrs = [ 75*61c4878aSAndroid Build Coastguard Worker "public/pw_thread_freertos/config.h", 76*61c4878aSAndroid Build Coastguard Worker "public/pw_thread_freertos/context.h", 77*61c4878aSAndroid Build Coastguard Worker "public/pw_thread_freertos/options.h", 78*61c4878aSAndroid Build Coastguard Worker "public/pw_thread_freertos/thread_inline.h", 79*61c4878aSAndroid Build Coastguard Worker "public/pw_thread_freertos/thread_native.h", 80*61c4878aSAndroid Build Coastguard Worker "thread_public_overrides/pw_thread_backend/thread_inline.h", 81*61c4878aSAndroid Build Coastguard Worker "thread_public_overrides/pw_thread_backend/thread_native.h", 82*61c4878aSAndroid Build Coastguard Worker ], 83*61c4878aSAndroid Build Coastguard Worker includes = [ 84*61c4878aSAndroid Build Coastguard Worker "public", 85*61c4878aSAndroid Build Coastguard Worker "thread_public_overrides", 86*61c4878aSAndroid Build Coastguard Worker ], 87*61c4878aSAndroid Build Coastguard Worker target_compatible_with = [ 88*61c4878aSAndroid Build Coastguard Worker "//pw_build/constraints/rtos:freertos", 89*61c4878aSAndroid Build Coastguard Worker ], 90*61c4878aSAndroid Build Coastguard Worker deps = [ 91*61c4878aSAndroid Build Coastguard Worker ":config_override", 92*61c4878aSAndroid Build Coastguard Worker ":id", 93*61c4878aSAndroid Build Coastguard Worker "//pw_assert", 94*61c4878aSAndroid Build Coastguard Worker "//pw_function", 95*61c4878aSAndroid Build Coastguard Worker "//pw_string", 96*61c4878aSAndroid Build Coastguard Worker "//pw_sync:binary_semaphore", 97*61c4878aSAndroid Build Coastguard Worker "//pw_thread:thread.facade", 98*61c4878aSAndroid Build Coastguard Worker ], 99*61c4878aSAndroid Build Coastguard Worker) 100*61c4878aSAndroid Build Coastguard Worker 101*61c4878aSAndroid Build Coastguard Workerlabel_flag( 102*61c4878aSAndroid Build Coastguard Worker name = "config_override", 103*61c4878aSAndroid Build Coastguard Worker build_setting_default = "//pw_build:default_module_config", 104*61c4878aSAndroid Build Coastguard Worker) 105*61c4878aSAndroid Build Coastguard Worker 106*61c4878aSAndroid Build Coastguard Workercc_library( 107*61c4878aSAndroid Build Coastguard Worker name = "dynamic_test_threads", 108*61c4878aSAndroid Build Coastguard Worker srcs = [ 109*61c4878aSAndroid Build Coastguard Worker "dynamic_test_threads.cc", 110*61c4878aSAndroid Build Coastguard Worker ], 111*61c4878aSAndroid Build Coastguard Worker target_compatible_with = [ 112*61c4878aSAndroid Build Coastguard Worker "//pw_build/constraints/rtos:freertos", 113*61c4878aSAndroid Build Coastguard Worker ], 114*61c4878aSAndroid Build Coastguard Worker deps = [ 115*61c4878aSAndroid Build Coastguard Worker "//pw_chrono:system_clock", 116*61c4878aSAndroid Build Coastguard Worker "//pw_thread:non_portable_test_thread_options", 117*61c4878aSAndroid Build Coastguard Worker "//pw_thread:sleep", 118*61c4878aSAndroid Build Coastguard Worker "//pw_thread:thread.facade", 119*61c4878aSAndroid Build Coastguard Worker ], 120*61c4878aSAndroid Build Coastguard Worker alwayslink = 1, 121*61c4878aSAndroid Build Coastguard Worker) 122*61c4878aSAndroid Build Coastguard Worker 123*61c4878aSAndroid Build Coastguard Workerpw_cc_test( 124*61c4878aSAndroid Build Coastguard Worker name = "dynamic_thread_backend_test", 125*61c4878aSAndroid Build Coastguard Worker # TODO: https://pwbug.dev/271465588 - This test fails on-device. 126*61c4878aSAndroid Build Coastguard Worker tags = ["do_not_run_test"], 127*61c4878aSAndroid Build Coastguard Worker deps = [ 128*61c4878aSAndroid Build Coastguard Worker ":dynamic_test_threads", 129*61c4878aSAndroid Build Coastguard Worker "//pw_thread:thread_facade_test", 130*61c4878aSAndroid Build Coastguard Worker ], 131*61c4878aSAndroid Build Coastguard Worker) 132*61c4878aSAndroid Build Coastguard Worker 133*61c4878aSAndroid Build Coastguard Workercc_library( 134*61c4878aSAndroid Build Coastguard Worker name = "static_test_threads", 135*61c4878aSAndroid Build Coastguard Worker srcs = [ 136*61c4878aSAndroid Build Coastguard Worker "static_test_threads.cc", 137*61c4878aSAndroid Build Coastguard Worker ], 138*61c4878aSAndroid Build Coastguard Worker target_compatible_with = [ 139*61c4878aSAndroid Build Coastguard Worker "//pw_build/constraints/rtos:freertos", 140*61c4878aSAndroid Build Coastguard Worker ], 141*61c4878aSAndroid Build Coastguard Worker deps = [ 142*61c4878aSAndroid Build Coastguard Worker "//pw_chrono:system_clock", 143*61c4878aSAndroid Build Coastguard Worker "//pw_thread:non_portable_test_thread_options", 144*61c4878aSAndroid Build Coastguard Worker "//pw_thread:sleep", 145*61c4878aSAndroid Build Coastguard Worker "//pw_thread:thread.facade", 146*61c4878aSAndroid Build Coastguard Worker ], 147*61c4878aSAndroid Build Coastguard Worker alwayslink = 1, 148*61c4878aSAndroid Build Coastguard Worker) 149*61c4878aSAndroid Build Coastguard Worker 150*61c4878aSAndroid Build Coastguard Workerpw_cc_test( 151*61c4878aSAndroid Build Coastguard Worker name = "static_thread_backend_test", 152*61c4878aSAndroid Build Coastguard Worker deps = [ 153*61c4878aSAndroid Build Coastguard Worker ":static_test_threads", 154*61c4878aSAndroid Build Coastguard Worker "//pw_thread:thread_facade_test", 155*61c4878aSAndroid Build Coastguard Worker ], 156*61c4878aSAndroid Build Coastguard Worker) 157*61c4878aSAndroid Build Coastguard Worker 158*61c4878aSAndroid Build Coastguard Workercc_library( 159*61c4878aSAndroid Build Coastguard Worker name = "yield", 160*61c4878aSAndroid Build Coastguard Worker hdrs = [ 161*61c4878aSAndroid Build Coastguard Worker "public/pw_thread_freertos/yield_inline.h", 162*61c4878aSAndroid Build Coastguard Worker "yield_public_overrides/pw_thread_backend/yield_inline.h", 163*61c4878aSAndroid Build Coastguard Worker ], 164*61c4878aSAndroid Build Coastguard Worker includes = [ 165*61c4878aSAndroid Build Coastguard Worker "public", 166*61c4878aSAndroid Build Coastguard Worker "yield_public_overrides", 167*61c4878aSAndroid Build Coastguard Worker ], 168*61c4878aSAndroid Build Coastguard Worker deps = [ 169*61c4878aSAndroid Build Coastguard Worker "//pw_thread:thread", 170*61c4878aSAndroid Build Coastguard Worker "//pw_thread:yield.facade", 171*61c4878aSAndroid Build Coastguard Worker "@freertos", 172*61c4878aSAndroid Build Coastguard Worker ], 173*61c4878aSAndroid Build Coastguard Worker) 174*61c4878aSAndroid Build Coastguard Worker 175*61c4878aSAndroid Build Coastguard Workercc_library( 176*61c4878aSAndroid Build Coastguard Worker name = "thread_iteration", 177*61c4878aSAndroid Build Coastguard Worker srcs = [ 178*61c4878aSAndroid Build Coastguard Worker "pw_thread_freertos_private/thread_iteration.h", 179*61c4878aSAndroid Build Coastguard Worker "thread_iteration.cc", 180*61c4878aSAndroid Build Coastguard Worker ], 181*61c4878aSAndroid Build Coastguard Worker target_compatible_with = [ 182*61c4878aSAndroid Build Coastguard Worker "//pw_build/constraints/rtos:freertos", 183*61c4878aSAndroid Build Coastguard Worker ], 184*61c4878aSAndroid Build Coastguard Worker deps = [ 185*61c4878aSAndroid Build Coastguard Worker ":freertos_tasktcb", 186*61c4878aSAndroid Build Coastguard Worker "//pw_function", 187*61c4878aSAndroid Build Coastguard Worker "//pw_span", 188*61c4878aSAndroid Build Coastguard Worker "//pw_status", 189*61c4878aSAndroid Build Coastguard Worker "//pw_thread:thread_info", 190*61c4878aSAndroid Build Coastguard Worker "//pw_thread:thread_iteration.facade", 191*61c4878aSAndroid Build Coastguard Worker "//pw_thread_freertos:util", 192*61c4878aSAndroid Build Coastguard Worker ], 193*61c4878aSAndroid Build Coastguard Worker) 194*61c4878aSAndroid Build Coastguard Worker 195*61c4878aSAndroid Build Coastguard Workerpw_cc_test( 196*61c4878aSAndroid Build Coastguard Worker name = "thread_iteration_test", 197*61c4878aSAndroid Build Coastguard Worker srcs = [ 198*61c4878aSAndroid Build Coastguard Worker "pw_thread_freertos_private/thread_iteration.h", 199*61c4878aSAndroid Build Coastguard Worker "thread_iteration_test.cc", 200*61c4878aSAndroid Build Coastguard Worker ], 201*61c4878aSAndroid Build Coastguard Worker # TODO: https://pwbug.dev/271465588 - This test fails on-device. 202*61c4878aSAndroid Build Coastguard Worker tags = ["do_not_run_test"], 203*61c4878aSAndroid Build Coastguard Worker deps = [ 204*61c4878aSAndroid Build Coastguard Worker ":freertos_tasktcb", 205*61c4878aSAndroid Build Coastguard Worker ":static_test_threads", 206*61c4878aSAndroid Build Coastguard Worker ":thread_iteration", 207*61c4878aSAndroid Build Coastguard Worker "//pw_bytes", 208*61c4878aSAndroid Build Coastguard Worker "//pw_span", 209*61c4878aSAndroid Build Coastguard Worker "//pw_string:builder", 210*61c4878aSAndroid Build Coastguard Worker "//pw_string:util", 211*61c4878aSAndroid Build Coastguard Worker "//pw_sync:thread_notification", 212*61c4878aSAndroid Build Coastguard Worker "//pw_thread:non_portable_test_thread_options", 213*61c4878aSAndroid Build Coastguard Worker "//pw_thread:thread", 214*61c4878aSAndroid Build Coastguard Worker "//pw_thread:thread_info", 215*61c4878aSAndroid Build Coastguard Worker "//pw_thread:thread_iteration", 216*61c4878aSAndroid Build Coastguard Worker ], 217*61c4878aSAndroid Build Coastguard Worker) 218*61c4878aSAndroid Build Coastguard Worker 219*61c4878aSAndroid Build Coastguard Workercc_library( 220*61c4878aSAndroid Build Coastguard Worker name = "util", 221*61c4878aSAndroid Build Coastguard Worker srcs = [ 222*61c4878aSAndroid Build Coastguard Worker "util.cc", 223*61c4878aSAndroid Build Coastguard Worker ], 224*61c4878aSAndroid Build Coastguard Worker hdrs = [ 225*61c4878aSAndroid Build Coastguard Worker "public/pw_thread_freertos/util.h", 226*61c4878aSAndroid Build Coastguard Worker ], 227*61c4878aSAndroid Build Coastguard Worker strip_include_prefix = "public", 228*61c4878aSAndroid Build Coastguard Worker target_compatible_with = [ 229*61c4878aSAndroid Build Coastguard Worker "//pw_build/constraints/rtos:freertos", 230*61c4878aSAndroid Build Coastguard Worker ], 231*61c4878aSAndroid Build Coastguard Worker deps = [ 232*61c4878aSAndroid Build Coastguard Worker "//pw_function", 233*61c4878aSAndroid Build Coastguard Worker "//pw_log", 234*61c4878aSAndroid Build Coastguard Worker "//pw_span", 235*61c4878aSAndroid Build Coastguard Worker "//pw_status", 236*61c4878aSAndroid Build Coastguard Worker "@freertos", 237*61c4878aSAndroid Build Coastguard Worker ], 238*61c4878aSAndroid Build Coastguard Worker) 239*61c4878aSAndroid Build Coastguard Worker 240*61c4878aSAndroid Build Coastguard Workercc_library( 241*61c4878aSAndroid Build Coastguard Worker name = "snapshot", 242*61c4878aSAndroid Build Coastguard Worker srcs = [ 243*61c4878aSAndroid Build Coastguard Worker "snapshot.cc", 244*61c4878aSAndroid Build Coastguard Worker ], 245*61c4878aSAndroid Build Coastguard Worker hdrs = [ 246*61c4878aSAndroid Build Coastguard Worker "public/pw_thread_freertos/snapshot.h", 247*61c4878aSAndroid Build Coastguard Worker ], 248*61c4878aSAndroid Build Coastguard Worker # TODO: b/269204725 - Put this in the toolchain configuration instead. I 249*61c4878aSAndroid Build Coastguard Worker # would like to say `copts = ["-Wno-c++20-designator"]`, but arm-gcc tells 250*61c4878aSAndroid Build Coastguard Worker # me that's an "unrecognized command line option"; I think it may be a 251*61c4878aSAndroid Build Coastguard Worker # clang-only flag. 252*61c4878aSAndroid Build Coastguard Worker copts = ["-Wno-pedantic"], 253*61c4878aSAndroid Build Coastguard Worker target_compatible_with = [ 254*61c4878aSAndroid Build Coastguard Worker "//pw_build/constraints/rtos:freertos", 255*61c4878aSAndroid Build Coastguard Worker ], 256*61c4878aSAndroid Build Coastguard Worker deps = [ 257*61c4878aSAndroid Build Coastguard Worker ":freertos_tasktcb", 258*61c4878aSAndroid Build Coastguard Worker ":util", 259*61c4878aSAndroid Build Coastguard Worker "//pw_function", 260*61c4878aSAndroid Build Coastguard Worker "//pw_log", 261*61c4878aSAndroid Build Coastguard Worker "//pw_protobuf", 262*61c4878aSAndroid Build Coastguard Worker "//pw_status", 263*61c4878aSAndroid Build Coastguard Worker "//pw_thread:snapshot", 264*61c4878aSAndroid Build Coastguard Worker "//pw_thread:thread_pwpb", 265*61c4878aSAndroid Build Coastguard Worker ], 266*61c4878aSAndroid Build Coastguard Worker) 267*61c4878aSAndroid Build Coastguard Worker 268*61c4878aSAndroid Build Coastguard Workercc_library( 269*61c4878aSAndroid Build Coastguard Worker name = "freertos_tasktcb", 270*61c4878aSAndroid Build Coastguard Worker hdrs = [ 271*61c4878aSAndroid Build Coastguard Worker "public/pw_thread_freertos/freertos_tsktcb.h", 272*61c4878aSAndroid Build Coastguard Worker ":generate_freertos_tsktcb", 273*61c4878aSAndroid Build Coastguard Worker ], 274*61c4878aSAndroid Build Coastguard Worker includes = [ 275*61c4878aSAndroid Build Coastguard Worker "public", 276*61c4878aSAndroid Build Coastguard Worker "thread_public_overrides", 277*61c4878aSAndroid Build Coastguard Worker ], 278*61c4878aSAndroid Build Coastguard Worker) 279*61c4878aSAndroid Build Coastguard Worker 280*61c4878aSAndroid Build Coastguard Workerrun_binary( 281*61c4878aSAndroid Build Coastguard Worker name = "generate_freertos_tsktcb", 282*61c4878aSAndroid Build Coastguard Worker srcs = [ 283*61c4878aSAndroid Build Coastguard Worker "@freertos//:tasks.c", 284*61c4878aSAndroid Build Coastguard Worker ], 285*61c4878aSAndroid Build Coastguard Worker outs = [":thread_public_overrides/pw_thread_freertos_backend/freertos_tsktcb.h"], 286*61c4878aSAndroid Build Coastguard Worker args = [ 287*61c4878aSAndroid Build Coastguard Worker "--freertos-tasks-c=$(location @freertos//:tasks.c)", 288*61c4878aSAndroid Build Coastguard Worker "--output=$(location :thread_public_overrides/pw_thread_freertos_backend/freertos_tsktcb.h)", 289*61c4878aSAndroid Build Coastguard Worker ], 290*61c4878aSAndroid Build Coastguard Worker tool = "//pw_thread_freertos/py:generate_freertos_tsktcb", 291*61c4878aSAndroid Build Coastguard Worker) 292*61c4878aSAndroid Build Coastguard Worker 293*61c4878aSAndroid Build Coastguard Workercc_library( 294*61c4878aSAndroid Build Coastguard Worker name = "test_thread_context", 295*61c4878aSAndroid Build Coastguard Worker hdrs = [ 296*61c4878aSAndroid Build Coastguard Worker "public/pw_thread_freertos/test_thread_context_native.h", 297*61c4878aSAndroid Build Coastguard Worker "test_thread_context_public_overrides/pw_thread_backend/test_thread_context_native.h", 298*61c4878aSAndroid Build Coastguard Worker ], 299*61c4878aSAndroid Build Coastguard Worker includes = [ 300*61c4878aSAndroid Build Coastguard Worker "public", 301*61c4878aSAndroid Build Coastguard Worker "test_thread_context_public_overrides", 302*61c4878aSAndroid Build Coastguard Worker ], 303*61c4878aSAndroid Build Coastguard Worker target_compatible_with = [ 304*61c4878aSAndroid Build Coastguard Worker "//pw_build/constraints/rtos:freertos", 305*61c4878aSAndroid Build Coastguard Worker ], 306*61c4878aSAndroid Build Coastguard Worker deps = [ 307*61c4878aSAndroid Build Coastguard Worker ":thread", 308*61c4878aSAndroid Build Coastguard Worker "//pw_thread:test_thread_context.facade", 309*61c4878aSAndroid Build Coastguard Worker ], 310*61c4878aSAndroid Build Coastguard Worker) 311