xref: /aosp_15_r20/external/pigweed/pw_sync_freertos/BUILD.gn (revision 61c4878ac05f98d0ceed94b57d316916de578985)
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
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_sync/backend.gni")
23import("$dir_pw_thread/backend.gni")
24import("$dir_pw_unit_test/test.gni")
25
26declare_args() {
27  # The build target that overrides the default configuration options for this
28  # module. This should point to a source set that provides defines through a
29  # public config (which may -include a file or add defines directly).
30  pw_sync_freertos_CONFIG = pw_build_DEFAULT_MODULE_CONFIG
31}
32
33config("public_include_path") {
34  include_dirs = [ "public" ]
35  visibility = [ ":*" ]
36}
37
38config("backend_config") {
39  include_dirs = [ "public_overrides" ]
40  visibility = [ ":*" ]
41}
42
43pw_source_set("config") {
44  public = [ "public/pw_sync_freertos/config.h" ]
45  public_configs = [ ":public_include_path" ]
46  public_deps = [
47    "$dir_pw_third_party/freertos",
48    pw_sync_freertos_CONFIG,
49  ]
50}
51
52pw_build_assert("check_system_clock_backend") {
53  condition =
54      pw_chrono_SYSTEM_CLOCK_BACKEND == "" ||
55      pw_chrono_SYSTEM_CLOCK_BACKEND == "$dir_pw_chrono_freertos:system_clock"
56  message = "The FreeRTOS pw_sync backends only work with the FreeRTOS " +
57            "pw::chrono::SystemClock backend."
58  visibility = [ ":*" ]
59}
60
61# This target provides the backend for pw::sync::BinarySemaphore.
62pw_source_set("binary_semaphore") {
63  public_configs = [
64    ":public_include_path",
65    ":backend_config",
66  ]
67  public = [
68    "public/pw_sync_freertos/binary_semaphore_inline.h",
69    "public/pw_sync_freertos/binary_semaphore_native.h",
70    "public_overrides/pw_sync_backend/binary_semaphore_inline.h",
71    "public_overrides/pw_sync_backend/binary_semaphore_native.h",
72  ]
73  public_deps = [
74    "$dir_pw_assert",
75    "$dir_pw_chrono:system_clock",
76    "$dir_pw_chrono_freertos:system_clock",
77    "$dir_pw_interrupt:context",
78    "$dir_pw_third_party/freertos",
79  ]
80  sources = [ "binary_semaphore.cc" ]
81  deps = [
82    ":check_system_clock_backend",
83    "$dir_pw_sync:binary_semaphore.facade",
84  ]
85}
86
87# This target provides the backend for pw::sync::CountingSemaphore.
88pw_source_set("counting_semaphore") {
89  public_configs = [
90    ":public_include_path",
91    ":backend_config",
92  ]
93  public = [
94    "public/pw_sync_freertos/counting_semaphore_inline.h",
95    "public/pw_sync_freertos/counting_semaphore_native.h",
96    "public_overrides/pw_sync_backend/counting_semaphore_inline.h",
97    "public_overrides/pw_sync_backend/counting_semaphore_native.h",
98  ]
99  public_deps = [
100    "$dir_pw_assert",
101    "$dir_pw_chrono:system_clock",
102    "$dir_pw_chrono_freertos:system_clock",
103    "$dir_pw_interrupt:context",
104    "$dir_pw_third_party/freertos",
105  ]
106  sources = [ "counting_semaphore.cc" ]
107  deps = [
108    ":check_system_clock_backend",
109    "$dir_pw_sync:counting_semaphore.facade",
110  ]
111}
112
113# This target provides the backend for pw::sync::Mutex.
114pw_source_set("mutex") {
115  public_configs = [
116    ":public_include_path",
117    ":backend_config",
118  ]
119  public = [
120    "public/pw_sync_freertos/mutex_inline.h",
121    "public/pw_sync_freertos/mutex_native.h",
122    "public_overrides/pw_sync_backend/mutex_inline.h",
123    "public_overrides/pw_sync_backend/mutex_native.h",
124  ]
125  public_deps = [
126    "$dir_pw_assert",
127    "$dir_pw_interrupt:context",
128    "$dir_pw_sync:mutex.facade",
129    "$dir_pw_third_party/freertos",
130  ]
131}
132
133# This target provides the backend for pw::sync::TimedMutex.
134pw_source_set("timed_mutex") {
135  public_configs = [
136    ":public_include_path",
137    ":backend_config",
138  ]
139  public = [
140    "public/pw_sync_freertos/timed_mutex_inline.h",
141    "public_overrides/pw_sync_backend/timed_mutex_inline.h",
142  ]
143  public_deps = [
144    "$dir_pw_chrono:system_clock",
145    "$dir_pw_sync:timed_mutex.facade",
146  ]
147  sources = [ "timed_mutex.cc" ]
148  deps = [
149    ":check_system_clock_backend",
150    "$dir_pw_assert",
151    "$dir_pw_chrono_freertos:system_clock",
152    "$dir_pw_interrupt:context",
153    "$dir_pw_third_party/freertos",
154  ]
155}
156
157config("public_overrides_thread_notification_include_path") {
158  include_dirs = [ "public_overrides/thread_notification" ]
159  visibility = [ ":thread_notification" ]
160}
161
162# This target provides the backend for pw::sync::ThreadNotification based on
163# task notifications.
164pw_source_set("thread_notification") {
165  public_configs = [
166    ":public_include_path",
167    ":public_overrides_thread_notification_include_path",
168  ]
169  public = [
170    "public/pw_sync_freertos/thread_notification_inline.h",
171    "public/pw_sync_freertos/thread_notification_native.h",
172    "public_overrides/thread_notification/pw_sync_backend/thread_notification_inline.h",
173    "public_overrides/thread_notification/pw_sync_backend/thread_notification_native.h",
174  ]
175  public_deps = [
176    "$dir_pw_assert",
177    "$dir_pw_interrupt:context",
178    "$dir_pw_polyfill",
179    "$dir_pw_sync:interrupt_spin_lock",
180    "$dir_pw_sync:lock_annotations",
181    "$dir_pw_sync:thread_notification.facade",
182    "$dir_pw_third_party/freertos",
183  ]
184  sources = [ "thread_notification.cc" ]
185  deps = [ ":config" ]
186}
187
188config("public_overrides_timed_thread_notification_include_path") {
189  include_dirs = [ "public_overrides/timed_thread_notification" ]
190  visibility = [ ":timed_thread_notification" ]
191}
192
193# This target provides the backend for pw::sync::TimedThreadNotification based
194# on task notifications.
195pw_source_set("timed_thread_notification") {
196  public_configs = [
197    ":public_include_path",
198    ":public_overrides_timed_thread_notification_include_path",
199  ]
200  public = [
201    "public/pw_sync_freertos/timed_thread_notification_inline.h",
202    "public_overrides/timed_thread_notification/pw_sync_backend/timed_thread_notification_inline.h",
203  ]
204  public_deps = [
205    "$dir_pw_chrono:system_clock",
206    "$dir_pw_sync:interrupt_spin_lock",
207    "$dir_pw_sync:timed_thread_notification.facade",
208  ]
209  sources = [ "timed_thread_notification.cc" ]
210  deps = [
211    ":check_system_clock_backend",
212    ":config",
213    "$dir_pw_assert",
214    "$dir_pw_chrono_freertos:system_clock",
215    "$dir_pw_interrupt:context",
216    "$dir_pw_third_party/freertos",
217  ]
218}
219
220# This target provides the backend for pw::sync::InterruptSpinLock.
221pw_source_set("interrupt_spin_lock") {
222  public_configs = [
223    ":public_include_path",
224    ":backend_config",
225  ]
226  public = [
227    "public/pw_sync_freertos/interrupt_spin_lock_inline.h",
228    "public/pw_sync_freertos/interrupt_spin_lock_native.h",
229    "public_overrides/pw_sync_backend/interrupt_spin_lock_inline.h",
230    "public_overrides/pw_sync_backend/interrupt_spin_lock_native.h",
231  ]
232  public_deps = [ "$dir_pw_third_party/freertos" ]
233  sources = [ "interrupt_spin_lock.cc" ]
234  deps = [
235    "$dir_pw_assert",
236    "$dir_pw_interrupt:context",
237    "$dir_pw_sync:interrupt_spin_lock.facade",
238  ]
239}
240
241pw_test_group("tests") {
242  tests = [
243    ":thread_notification_test_with_static_threads",
244    ":timed_thread_notification_test_with_static_threads",
245  ]
246}
247
248# You can instantiate this with your own provided "$dir_pw_thread:non_portable_test_thread_options",
249# see ":thread_notification_test_with_static_threads" below as an example.
250pw_source_set("thread_notification_test") {
251  sources = [ "thread_notification_test.cc" ]
252  deps = [
253    "$dir_pw_chrono:system_clock",
254    "$dir_pw_sync:thread_notification",
255    "$dir_pw_third_party/freertos",
256    "$dir_pw_thread:non_portable_test_thread_options",
257    "$dir_pw_thread:sleep",
258    "$dir_pw_thread:thread",
259    "$dir_pw_unit_test",
260  ]
261}
262
263pw_test("thread_notification_test_with_static_threads") {
264  enable_if = pw_sync_THREAD_NOTIFICATION_BACKEND ==
265              "$dir_pw_sync_freertos:thread_notification" &&
266              pw_chrono_SYSTEM_CLOCK_BACKEND != "" &&
267              pw_thread_THREAD_BACKEND != "" && pw_thread_SLEEP_BACKEND != ""
268  deps = [
269    ":thread_notification_test",
270    "$dir_pw_thread_freertos:static_test_threads",
271  ]
272}
273
274# You can instantiate this with your own provided "$dir_pw_thread:non_portable_test_thread_options",
275# see ":timed_thread_notification_test_with_static_threads" below as an example.
276pw_source_set("timed_thread_notification_test") {
277  sources = [ "timed_thread_notification_test.cc" ]
278  deps = [
279    "$dir_pw_chrono:system_clock",
280    "$dir_pw_sync:timed_thread_notification",
281    "$dir_pw_third_party/freertos",
282    "$dir_pw_thread:non_portable_test_thread_options",
283    "$dir_pw_thread:sleep",
284    "$dir_pw_thread:thread",
285    "$dir_pw_unit_test",
286  ]
287}
288
289pw_test("timed_thread_notification_test_with_static_threads") {
290  enable_if = pw_sync_TIMED_THREAD_NOTIFICATION_BACKEND ==
291              "$dir_pw_sync_freertos:timed_thread_notification" &&
292              pw_chrono_SYSTEM_CLOCK_BACKEND != "" &&
293              pw_thread_THREAD_BACKEND != "" && pw_thread_SLEEP_BACKEND != ""
294  deps = [
295    ":timed_thread_notification_test",
296    "$dir_pw_thread_freertos:static_test_threads",
297  ]
298}
299
300pw_doc_group("docs") {
301  sources = [ "docs.rst" ]
302}
303