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