1# Copyright 2021 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_pw_build/error.gni") 18import("$dir_pw_build/module_config.gni") 19import("$dir_pw_build/target_types.gni") 20import("$dir_pw_chrono/backend.gni") 21import("$dir_pw_docgen/docs.gni") 22import("$dir_pw_thread/backend.gni") 23import("$dir_pw_unit_test/test.gni") 24 25declare_args() { 26 # The build target that overrides the default configuration options for this 27 # module. This should point to a source set that provides defines through a 28 # public config (which may -include a file or add defines directly). 29 pw_thread_threadx_CONFIG = pw_build_DEFAULT_MODULE_CONFIG 30} 31 32config("public_include_path") { 33 include_dirs = [ "public" ] 34 visibility = [ ":*" ] 35} 36 37config("backend_config") { 38 include_dirs = [ "public_overrides" ] 39 visibility = [ ":*" ] 40} 41 42pw_source_set("config") { 43 public = [ "public/pw_thread_threadx/config.h" ] 44 public_configs = [ ":public_include_path" ] 45 public_deps = [ 46 "$dir_pw_third_party/threadx", 47 pw_thread_threadx_CONFIG, 48 ] 49} 50 51config("id_public_overrides") { 52 include_dirs = [ "id_public_overrides" ] 53 visibility = [ ":*" ] 54} 55 56# This target provides the backend for pw::thread::Id. 57pw_source_set("id") { 58 public_configs = [ 59 ":public_include_path", 60 ":id_public_overrides", 61 ] 62 public_deps = [ 63 "$dir_pw_assert", 64 "$dir_pw_interrupt:context", 65 "$dir_pw_third_party/threadx", 66 ] 67 public = [ 68 "id_public_overrides/pw_thread_backend/id_inline.h", 69 "id_public_overrides/pw_thread_backend/id_native.h", 70 "public/pw_thread_threadx/id_inline.h", 71 "public/pw_thread_threadx/id_native.h", 72 ] 73 deps = [ "$dir_pw_thread:id.facade" ] 74} 75 76if (pw_chrono_SYSTEM_CLOCK_BACKEND != "" && pw_thread_SLEEP_BACKEND != "") { 77 pw_build_assert("check_system_clock_backend") { 78 condition = 79 pw_thread_OVERRIDE_SYSTEM_CLOCK_BACKEND_CHECK || 80 pw_chrono_SYSTEM_CLOCK_BACKEND == "$dir_pw_chrono_threadx:system_clock" 81 message = "The ThreadX pw::this_thread::sleep_{for,until} backend only " + 82 "works with the ThreadX pw::chrono::SystemClock backend." 83 } 84 85 config("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}. 91 pw_source_set("sleep") { 92 public_configs = [ 93 ":public_include_path", 94 ":sleep_public_overrides", 95 ] 96 public = [ 97 "public/pw_thread_threadx/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_threadx:system_clock", 106 "$dir_pw_third_party/threadx", 107 "$dir_pw_thread:id", 108 ] 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/threadx", 129 "$dir_pw_thread:deprecated_or_new_thread_function", 130 "$dir_pw_thread:id", 131 "$dir_pw_thread:thread.facade", 132 dir_pw_span, 133 ] 134 public = [ 135 "public/pw_thread_threadx/context.h", 136 "public/pw_thread_threadx/options.h", 137 "public/pw_thread_threadx/thread_inline.h", 138 "public/pw_thread_threadx/thread_native.h", 139 "thread_public_overrides/pw_thread_backend/thread_inline.h", 140 "thread_public_overrides/pw_thread_backend/thread_native.h", 141 ] 142 allow_circular_includes_from = [ "$dir_pw_thread:thread.facade" ] 143 sources = [ "thread.cc" ] 144} 145 146config("yield_public_overrides") { 147 include_dirs = [ "yield_public_overrides" ] 148 visibility = [ ":*" ] 149} 150 151# This target provides the backend for pw::this_thread::yield. 152pw_source_set("yield") { 153 public_configs = [ 154 ":public_include_path", 155 ":yield_public_overrides", 156 ] 157 public = [ 158 "public/pw_thread_threadx/yield_inline.h", 159 "yield_public_overrides/pw_thread_backend/yield_inline.h", 160 ] 161 public_deps = [ 162 "$dir_pw_assert", 163 "$dir_pw_third_party/threadx", 164 "$dir_pw_thread:id", 165 ] 166 deps = [ "$dir_pw_thread:yield.facade" ] 167} 168 169pw_source_set("util") { 170 public_configs = [ ":public_include_path" ] 171 public_deps = [ 172 "$dir_pw_third_party/threadx", 173 dir_pw_function, 174 dir_pw_status, 175 ] 176 public = [ "public/pw_thread_threadx/util.h" ] 177 sources = [ "util.cc" ] 178} 179 180pw_source_set("snapshot") { 181 public_configs = [ ":public_include_path" ] 182 public_deps = [ 183 ":config", 184 "$dir_pw_third_party/threadx", 185 "$dir_pw_thread:protos.pwpb", 186 "$dir_pw_thread:snapshot", 187 dir_pw_bytes, 188 dir_pw_function, 189 dir_pw_log, 190 dir_pw_protobuf, 191 dir_pw_status, 192 ] 193 public = [ "public/pw_thread_threadx/snapshot.h" ] 194 sources = [ "snapshot.cc" ] 195 deps = [ 196 ":util", 197 dir_pw_log, 198 ] 199} 200 201pw_test_group("tests") { 202 tests = [ ":thread_backend_test" ] 203} 204 205pw_source_set("non_portable_test_thread_options") { 206 public_deps = [ "$dir_pw_thread:non_portable_test_thread_options" ] 207 sources = [ "test_threads.cc" ] 208 deps = [ 209 "$dir_pw_chrono:system_clock", 210 "$dir_pw_thread:sleep", 211 "$dir_pw_thread:thread", 212 dir_pw_assert, 213 dir_pw_log, 214 ] 215} 216 217pw_test("thread_backend_test") { 218 enable_if = pw_thread_THREAD_BACKEND == "$dir_pw_thread_threadx:thread" 219 deps = [ 220 ":non_portable_test_thread_options", 221 "$dir_pw_thread:thread_facade_test", 222 ] 223} 224 225pw_doc_group("docs") { 226 sources = [ "docs.rst" ] 227} 228