• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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      "-Wno-redundant-decls",
50    ]
51    visibility = [ ":*" ]
52  }
53
54  config("public_includes") {
55    include_dirs = [ "$dir_pw_third_party_freertos/include" ]
56    visibility = [ ":*" ]
57  }
58
59  pw_source_set("freertos") {
60    public_configs = [ ":public_includes" ]
61    allow_circular_includes_from = [
62      pw_third_party_freertos_PORT,
63      ":freertos_tasks",
64    ]
65    public_deps = [
66      pw_third_party_freertos_CONFIG,
67      pw_third_party_freertos_PORT,
68    ]
69    public = [
70      "$dir_pw_third_party_freertos/include/FreeRTOS.h",
71      "$dir_pw_third_party_freertos/include/StackMacros.h",
72      "$dir_pw_third_party_freertos/include/croutine.h",
73      "$dir_pw_third_party_freertos/include/deprecated_definitions.h",
74      "$dir_pw_third_party_freertos/include/event_groups.h",
75      "$dir_pw_third_party_freertos/include/list.h",
76      "$dir_pw_third_party_freertos/include/message_buffer.h",
77      "$dir_pw_third_party_freertos/include/mpu_prototypes.h",
78      "$dir_pw_third_party_freertos/include/mpu_wrappers.h",
79      "$dir_pw_third_party_freertos/include/portable.h",
80      "$dir_pw_third_party_freertos/include/projdefs.h",
81      "$dir_pw_third_party_freertos/include/queue.h",
82      "$dir_pw_third_party_freertos/include/semphr.h",
83      "$dir_pw_third_party_freertos/include/stack_macros.h",
84      "$dir_pw_third_party_freertos/include/stream_buffer.h",
85      "$dir_pw_third_party_freertos/include/task.h",
86      "$dir_pw_third_party_freertos/include/timers.h",
87    ]
88    configs = [ ":disable_warnings" ]
89    sources = [
90      "$dir_pw_third_party_freertos/croutine.c",
91      "$dir_pw_third_party_freertos/event_groups.c",
92      "$dir_pw_third_party_freertos/list.c",
93      "$dir_pw_third_party_freertos/queue.c",
94      "$dir_pw_third_party_freertos/stream_buffer.c",
95      "$dir_pw_third_party_freertos/timers.c",
96    ]
97    deps = [ ":freertos_tasks" ]
98  }
99
100  # In order to link against internal kernel data structures through the use of
101  # extern "C", statics can be optionally disabled for the tasks.c source file
102  # to enable use of things like pw_thread_freertos/util.h's ForEachThread.
103  config("disable_statics") {
104    cflags = [
105      "-Dstatic=",
106      "-DPW_THIRD_PARTY_FREERTOS_NO_STATICS=1",
107    ]
108    visibility = [ ":*" ]
109  }
110
111  pw_source_set("freertos_tasks") {
112    public_configs = [ ":public_includes" ]
113    configs = [ ":disable_warnings" ]
114    if (pw_third_party_freertos_DISABLE_TASKS_STATICS) {
115      configs += [ ":disable_statics" ]
116    }
117    sources = [ "$dir_pw_third_party_freertos/tasks.c" ]
118    deps = [
119      pw_third_party_freertos_CONFIG,
120      pw_third_party_freertos_PORT,
121    ]
122  }
123
124  # ARM CM33 port of FreeRTOS
125  config("arm_cm33_includes") {
126    include_dirs =
127        [ "$dir_pw_third_party_freertos/portable/GCC/ARM_CM33_NTZ/non_secure" ]
128    visibility = [ ":arm_cm33" ]
129  }
130
131  pw_source_set("arm_cm33") {
132    public_configs = [
133      ":arm_cm33_includes",
134      ":public_includes",
135    ]
136    public_deps = [ pw_third_party_freertos_CONFIG ]
137    public = [
138      "$dir_pw_third_party_freertos/portable/GCC/ARM_CM33_NTZ/non_secure/portasm.h",
139      "$dir_pw_third_party_freertos/portable/GCC/ARM_CM33_NTZ/non_secure/portmacro.h",
140    ]
141    sources = [
142      "$dir_pw_third_party_freertos/portable/GCC/ARM_CM33_NTZ/non_secure/port.c",
143      "$dir_pw_third_party_freertos/portable/GCC/ARM_CM33_NTZ/non_secure/portasm.c",
144    ]
145    configs = [ ":disable_warnings" ]
146  }
147
148  # ARM CM7 port of FreeRTOS
149  config("arm_cm7_includes") {
150    include_dirs = [ "$dir_pw_third_party_freertos/portable/GCC/ARM_CM7/r0p1" ]
151    visibility = [ ":arm_cm7" ]
152  }
153
154  # NB: Use :arm_cm7_after_r0p1 instead if you can
155  pw_source_set("arm_cm7") {
156    public_configs = [
157      ":arm_cm7_includes",
158      ":public_includes",
159    ]
160    public_deps = [ pw_third_party_freertos_CONFIG ]
161    public =
162        [ "$dir_pw_third_party_freertos/portable/GCC/ARM_CM7/r0p1/portmacro.h" ]
163    sources =
164        [ "$dir_pw_third_party_freertos/portable/GCC/ARM_CM7/r0p1/port.c" ]
165    configs = [ ":disable_warnings" ]
166  }
167
168  # CM7 r0p0 and r0p1 cores have errata that requires workarounds. Freertos
169  # recommends using the CM4F port on newer CM7 core revisions for better
170  # performance.
171  # See Freertos' ARM_CM7/ReadMe.txt.
172  pw_source_set("arm_cm7_after_r0p1") {
173    public_deps = [ ":arm_cm4f" ]
174  }
175
176  # ARM CM4F port of FreeRTOS.
177  config("arm_cm4f_includes") {
178    include_dirs = [ "$dir_pw_third_party_freertos/portable/GCC/ARM_CM4F" ]
179    visibility = [ ":arm_cm4f" ]
180  }
181
182  pw_source_set("arm_cm4f") {
183    public_configs = [
184      ":arm_cm4f_includes",
185      ":public_includes",
186    ]
187    public_deps = [ pw_third_party_freertos_CONFIG ]
188    public =
189        [ "$dir_pw_third_party_freertos/portable/GCC/ARM_CM4F/portmacro.h" ]
190    sources = [ "$dir_pw_third_party_freertos/portable/GCC/ARM_CM4F/port.c" ]
191    configs = [ ":disable_warnings" ]
192  }
193
194  # ARM CM3 port of FreeRTOS.
195  config("arm_cm3_includes") {
196    include_dirs = [ "$dir_pw_third_party_freertos/portable/GCC/ARM_CM3" ]
197    visibility = [ ":arm_cm3" ]
198  }
199
200  pw_source_set("arm_cm3") {
201    public_configs = [
202      ":arm_cm3_includes",
203      ":public_includes",
204    ]
205    public_deps = [ pw_third_party_freertos_CONFIG ]
206    public = [ "$dir_pw_third_party_freertos/portable/GCC/ARM_CM3/portmacro.h" ]
207    sources = [ "$dir_pw_third_party_freertos/portable/GCC/ARM_CM3/port.c" ]
208    configs = [ ":disable_warnings" ]
209  }
210
211  # ARM CM0 port of FreeRTOS.
212  config("arm_cm0_includes") {
213    include_dirs = [ "$dir_pw_third_party_freertos/portable/GCC/ARM_CM0" ]
214    visibility = [ ":arm_cm0" ]
215  }
216
217  pw_source_set("arm_cm0") {
218    public_configs = [
219      ":arm_cm0_includes",
220      ":public_includes",
221    ]
222    public_deps = [ pw_third_party_freertos_CONFIG ]
223    public = [ "$dir_pw_third_party_freertos/portable/GCC/ARM_CM0/portmacro.h" ]
224    sources = [ "$dir_pw_third_party_freertos/portable/GCC/ARM_CM0/port.c" ]
225    configs = [ ":disable_warnings" ]
226  }
227}
228
229config("public_include_path") {
230  include_dirs = [ "public" ]
231  visibility = [ ":*" ]
232}
233
234pw_source_set("config_assert") {
235  public_configs = [ ":public_include_path" ]
236  public_deps = [ dir_pw_assert ]
237  public = [ "public/pw_third_party/freertos/config_assert.h" ]
238}
239
240pw_source_set("support") {
241  deps = [
242    "$dir_pw_string:util",
243    "$dir_pw_third_party/freertos",
244    dir_pw_assert,
245  ]
246  sources = [
247    "pw_assert_malloc_failed_hook.cc",
248    "pw_assert_stack_overflow_hook.cc",
249    "static_task_allocation.cc",
250  ]
251}
252
253pw_doc_group("docs") {
254  sources = [ "docs.rst" ]
255}
256