xref: /aosp_15_r20/external/pigweed/third_party/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/target_types.gni")
19import("$dir_pw_docgen/docs.gni")
20import("freertos.gni")
21
22# This file defines a GN source_set for an external installation of freertos.
23# To use, checkout the freertos source into a directory, then set the build arg
24# dir_pw_third_party_freertos to point to that directory. The freertos library
25# will be available in GN at "$dir_pw_third_party/freertos".
26if (dir_pw_third_party_freertos == "") {
27  group("freertos") {
28  }
29} else if (pw_third_party_freertos_PORT == "") {
30  pw_error("freertos") {
31    message_lines = [
32      "FreeRTOS is being used by $current_toolchain, but pw_third_party_freertos_PORT is not set.",
33      "If this toolchain is intentionally using FreeRTOS, ensure your toolchain configuration for this target sets pw_third_party_freertos_PORT.",
34    ]
35  }
36} else if (pw_third_party_freertos_CONFIG == "") {
37  pw_error("freertos") {
38    message_lines = [
39      "FreeRTOS is being used by $current_toolchain, but pw_third_party_freertos_CONFIG is not set.",
40      "If this toolchain is intentionally using FreeRTOS, ensure your toolchain configuration for this target sets pw_third_party_freertos_CONFIG.",
41    ]
42  }
43} else {
44  config("disable_warnings") {
45    cflags = [
46      "-Wno-unused-parameter",
47      "-Wno-cast-qual",
48      "-Wno-int-in-bool-context",
49    ]
50    visibility = [ ":*" ]
51  }
52
53  config("public_includes") {
54    include_dirs = [ "$dir_pw_third_party_freertos/include" ]
55    visibility = [ ":*" ]
56  }
57
58  pw_source_set("freertos") {
59    public_configs = [ ":public_includes" ]
60    allow_circular_includes_from = [
61      pw_third_party_freertos_PORT,
62      ":freertos_tasks",
63    ]
64    public_deps = [
65      pw_third_party_freertos_CONFIG,
66      pw_third_party_freertos_PORT,
67    ]
68    public = [
69      "$dir_pw_third_party_freertos/include/FreeRTOS.h",
70      "$dir_pw_third_party_freertos/include/StackMacros.h",
71      "$dir_pw_third_party_freertos/include/croutine.h",
72      "$dir_pw_third_party_freertos/include/deprecated_definitions.h",
73      "$dir_pw_third_party_freertos/include/event_groups.h",
74      "$dir_pw_third_party_freertos/include/list.h",
75      "$dir_pw_third_party_freertos/include/message_buffer.h",
76      "$dir_pw_third_party_freertos/include/mpu_prototypes.h",
77      "$dir_pw_third_party_freertos/include/mpu_wrappers.h",
78      "$dir_pw_third_party_freertos/include/portable.h",
79      "$dir_pw_third_party_freertos/include/projdefs.h",
80      "$dir_pw_third_party_freertos/include/queue.h",
81      "$dir_pw_third_party_freertos/include/semphr.h",
82      "$dir_pw_third_party_freertos/include/stack_macros.h",
83      "$dir_pw_third_party_freertos/include/stream_buffer.h",
84      "$dir_pw_third_party_freertos/include/task.h",
85      "$dir_pw_third_party_freertos/include/timers.h",
86    ]
87    configs = [ ":disable_warnings" ]
88    sources = [
89      "$dir_pw_third_party_freertos/croutine.c",
90      "$dir_pw_third_party_freertos/event_groups.c",
91      "$dir_pw_third_party_freertos/list.c",
92      "$dir_pw_third_party_freertos/queue.c",
93      "$dir_pw_third_party_freertos/stream_buffer.c",
94      "$dir_pw_third_party_freertos/timers.c",
95    ]
96    deps = [ ":freertos_tasks" ]
97  }
98
99  # In order to link against internal kernel data structures through the use of
100  # extern "C", statics can be optionally disabled for the tasks.c source file
101  # to enable use of things like pw_thread_freertos/util.h's ForEachThread.
102  config("disable_statics") {
103    cflags = [
104      "-Dstatic=",
105      "-DPW_THIRD_PARTY_FREERTOS_NO_STATICS=1",
106    ]
107    visibility = [ ":*" ]
108  }
109
110  pw_source_set("freertos_tasks") {
111    public_configs = [ ":public_includes" ]
112    configs = [ ":disable_warnings" ]
113    if (pw_third_party_freertos_DISABLE_TASKS_STATICS) {
114      configs += [ ":disable_statics" ]
115    }
116    sources = [ "$dir_pw_third_party_freertos/tasks.c" ]
117    deps = [
118      pw_third_party_freertos_CONFIG,
119      pw_third_party_freertos_PORT,
120    ]
121  }
122
123  # ARM CM33 port of FreeRTOS
124  config("arm_cm33_includes") {
125    include_dirs =
126        [ "$dir_pw_third_party_freertos/portable/GCC/ARM_CM33_NTZ/non_secure" ]
127    visibility = [ ":arm_cm33" ]
128  }
129
130  pw_source_set("arm_cm33") {
131    public_configs = [
132      ":arm_cm33_includes",
133      ":public_includes",
134    ]
135    public_deps = [ pw_third_party_freertos_CONFIG ]
136    public = [
137      "$dir_pw_third_party_freertos/portable/GCC/ARM_CM33_NTZ/non_secure/portasm.h",
138      "$dir_pw_third_party_freertos/portable/GCC/ARM_CM33_NTZ/non_secure/portmacro.h",
139    ]
140    sources = [
141      "$dir_pw_third_party_freertos/portable/GCC/ARM_CM33_NTZ/non_secure/port.c",
142      "$dir_pw_third_party_freertos/portable/GCC/ARM_CM33_NTZ/non_secure/portasm.c",
143    ]
144    configs = [ ":disable_warnings" ]
145  }
146
147  # ARM CM7 port of FreeRTOS
148  config("arm_cm7_includes") {
149    include_dirs = [ "$dir_pw_third_party_freertos/portable/GCC/ARM_CM7/r0p1" ]
150    visibility = [ ":arm_cm7" ]
151  }
152
153  # NB: Use :arm_cm7_after_r0p1 instead if you can
154  pw_source_set("arm_cm7") {
155    public_configs = [
156      ":arm_cm7_includes",
157      ":public_includes",
158    ]
159    public_deps = [ pw_third_party_freertos_CONFIG ]
160    public =
161        [ "$dir_pw_third_party_freertos/portable/GCC/ARM_CM7/r0p1/portmacro.h" ]
162    sources =
163        [ "$dir_pw_third_party_freertos/portable/GCC/ARM_CM7/r0p1/port.c" ]
164    configs = [ ":disable_warnings" ]
165  }
166
167  # CM7 r0p0 and r0p1 cores have errata that requires workarounds. Freertos
168  # recommends using the CM4F port on newer CM7 core revisions for better
169  # performance.
170  # See Freertos' ARM_CM7/ReadMe.txt.
171  pw_source_set("arm_cm7_after_r0p1") {
172    public_deps = [ ":arm_cm4f" ]
173  }
174
175  # ARM CM4F port of FreeRTOS.
176  config("arm_cm4f_includes") {
177    include_dirs = [ "$dir_pw_third_party_freertos/portable/GCC/ARM_CM4F" ]
178    visibility = [ ":arm_cm4f" ]
179  }
180
181  pw_source_set("arm_cm4f") {
182    public_configs = [
183      ":arm_cm4f_includes",
184      ":public_includes",
185    ]
186    public_deps = [ pw_third_party_freertos_CONFIG ]
187    public =
188        [ "$dir_pw_third_party_freertos/portable/GCC/ARM_CM4F/portmacro.h" ]
189    sources = [ "$dir_pw_third_party_freertos/portable/GCC/ARM_CM4F/port.c" ]
190    configs = [ ":disable_warnings" ]
191  }
192
193  # ARM CM3 port of FreeRTOS.
194  config("arm_cm3_includes") {
195    include_dirs = [ "$dir_pw_third_party_freertos/portable/GCC/ARM_CM3" ]
196    visibility = [ ":arm_cm3" ]
197  }
198
199  pw_source_set("arm_cm3") {
200    public_configs = [
201      ":arm_cm3_includes",
202      ":public_includes",
203    ]
204    public_deps = [ pw_third_party_freertos_CONFIG ]
205    public = [ "$dir_pw_third_party_freertos/portable/GCC/ARM_CM3/portmacro.h" ]
206    sources = [ "$dir_pw_third_party_freertos/portable/GCC/ARM_CM3/port.c" ]
207    configs = [ ":disable_warnings" ]
208  }
209
210  # ARM CM0 port of FreeRTOS.
211  config("arm_cm0_includes") {
212    include_dirs = [ "$dir_pw_third_party_freertos/portable/GCC/ARM_CM0" ]
213    visibility = [ ":arm_cm0" ]
214  }
215
216  pw_source_set("arm_cm0") {
217    public_configs = [
218      ":arm_cm0_includes",
219      ":public_includes",
220    ]
221    public_deps = [ pw_third_party_freertos_CONFIG ]
222    public = [ "$dir_pw_third_party_freertos/portable/GCC/ARM_CM0/portmacro.h" ]
223    sources = [ "$dir_pw_third_party_freertos/portable/GCC/ARM_CM0/port.c" ]
224    configs = [ ":disable_warnings" ]
225  }
226}
227
228config("public_include_path") {
229  include_dirs = [ "public" ]
230  visibility = [ ":*" ]
231}
232
233pw_source_set("config_assert") {
234  public_configs = [ ":public_include_path" ]
235  public_deps = [ dir_pw_assert ]
236  public = [ "public/pw_third_party/freertos/config_assert.h" ]
237}
238
239pw_source_set("support") {
240  deps = [
241    "$dir_pw_string:util",
242    "$dir_pw_third_party/freertos",
243    dir_pw_assert,
244  ]
245  sources = [
246    "pw_assert_malloc_failed_hook.cc",
247    "pw_assert_stack_overflow_hook.cc",
248    "static_task_allocation.cc",
249  ]
250}
251
252pw_doc_group("docs") {
253  sources = [ "docs.rst" ]
254}
255