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 51# This target provides the backend for pw::thread::Id. 52pw_source_set("id") { 53 public_configs = [ 54 ":public_include_path", 55 ":backend_config", 56 ] 57 public_deps = [ 58 "$dir_pw_assert", 59 "$dir_pw_interrupt:context", 60 "$dir_pw_third_party/threadx", 61 ] 62 public = [ 63 "public/pw_thread_threadx/id_inline.h", 64 "public/pw_thread_threadx/id_native.h", 65 "public_overrides/pw_thread_backend/id_inline.h", 66 "public_overrides/pw_thread_backend/id_native.h", 67 ] 68 deps = [ "$dir_pw_thread:id.facade" ] 69} 70 71if (pw_chrono_SYSTEM_CLOCK_BACKEND != "" && pw_thread_SLEEP_BACKEND != "") { 72 pw_build_assert("check_system_clock_backend") { 73 condition = 74 pw_thread_OVERRIDE_SYSTEM_CLOCK_BACKEND_CHECK || 75 pw_chrono_SYSTEM_CLOCK_BACKEND == "$dir_pw_chrono_threadx:system_clock" 76 message = "The ThreadX pw::this_thread::sleep_{for,until} backend only " + 77 "works with the ThreadX pw::chrono::SystemClock backend." 78 } 79 80 # This target provides the backend for pw::this_thread::sleep_{for,until}. 81 pw_source_set("sleep") { 82 public_configs = [ 83 ":public_include_path", 84 ":backend_config", 85 ] 86 public = [ 87 "public/pw_thread_threadx/sleep_inline.h", 88 "public_overrides/pw_thread_backend/sleep_inline.h", 89 ] 90 public_deps = [ "$dir_pw_chrono:system_clock" ] 91 sources = [ "sleep.cc" ] 92 deps = [ 93 ":check_system_clock_backend", 94 "$dir_pw_assert", 95 "$dir_pw_chrono_threadx:system_clock", 96 "$dir_pw_third_party/threadx", 97 "$dir_pw_thread:id", 98 ] 99 } 100} 101 102# This target provides the backend for pw::thread::Thread and the headers needed 103# for thread creation. 104pw_source_set("thread") { 105 public_configs = [ 106 ":public_include_path", 107 ":backend_config", 108 ] 109 public_deps = [ 110 ":config", 111 "$dir_pw_assert", 112 "$dir_pw_string", 113 "$dir_pw_third_party/threadx", 114 "$dir_pw_thread:id", 115 "$dir_pw_thread:thread.facade", 116 ] 117 public = [ 118 "public/pw_thread_threadx/context.h", 119 "public/pw_thread_threadx/options.h", 120 "public/pw_thread_threadx/thread_inline.h", 121 "public/pw_thread_threadx/thread_native.h", 122 "public_overrides/pw_thread_backend/thread_inline.h", 123 "public_overrides/pw_thread_backend/thread_native.h", 124 ] 125 allow_circular_includes_from = [ "$dir_pw_thread:thread.facade" ] 126 sources = [ "thread.cc" ] 127} 128 129# This target provides the backend for pw::this_thread::yield. 130pw_source_set("yield") { 131 public_configs = [ 132 ":public_include_path", 133 ":backend_config", 134 ] 135 public = [ 136 "public/pw_thread_threadx/yield_inline.h", 137 "public_overrides/pw_thread_backend/yield_inline.h", 138 ] 139 public_deps = [ 140 "$dir_pw_assert", 141 "$dir_pw_third_party/threadx", 142 "$dir_pw_thread:id", 143 ] 144 deps = [ "$dir_pw_thread:yield.facade" ] 145} 146 147pw_source_set("util") { 148 public_configs = [ ":public_include_path" ] 149 public_deps = [ 150 "$dir_pw_third_party/threadx", 151 dir_pw_function, 152 dir_pw_status, 153 ] 154 public = [ "public/pw_thread_threadx/util.h" ] 155 sources = [ "util.cc" ] 156} 157 158pw_source_set("snapshot") { 159 public_configs = [ ":public_include_path" ] 160 public_deps = [ 161 ":config", 162 "$dir_pw_third_party/threadx", 163 "$dir_pw_thread:protos.pwpb", 164 "$dir_pw_thread:snapshot", 165 dir_pw_bytes, 166 dir_pw_function, 167 dir_pw_log, 168 dir_pw_protobuf, 169 dir_pw_status, 170 ] 171 public = [ "public/pw_thread_threadx/snapshot.h" ] 172 sources = [ "snapshot.cc" ] 173 deps = [ 174 ":util", 175 dir_pw_log, 176 ] 177} 178 179pw_test_group("tests") { 180 tests = [ ":thread_backend_test" ] 181} 182 183pw_source_set("test_threads") { 184 public_deps = [ "$dir_pw_thread:test_threads" ] 185 sources = [ "test_threads.cc" ] 186 deps = [ 187 "$dir_pw_chrono:system_clock", 188 "$dir_pw_thread:sleep", 189 "$dir_pw_thread:thread", 190 dir_pw_assert, 191 dir_pw_log, 192 ] 193} 194 195pw_test("thread_backend_test") { 196 enable_if = pw_thread_THREAD_BACKEND == "$dir_pw_thread_threadx:thread" 197 deps = [ 198 ":test_threads", 199 "$dir_pw_thread:thread_facade_test", 200 ] 201} 202 203pw_doc_group("docs") { 204 sources = [ "docs.rst" ] 205} 206