xref: /aosp_15_r20/external/pigweed/third_party/freertos/freertos.BUILD.bazel (revision 61c4878ac05f98d0ceed94b57d316916de578985)
1# Copyright 2024 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
15# This is a BUILD.bazel file template for FreeRTOS.
16#
17# TODO(b/326625641): Contribute this to upstream FreeRTOS.
18
19# buildifier: disable=module-docstring
20package(default_visibility = ["//visibility:public"])
21
22# Label flag that points to the cc_library target providing freertos_config.h.
23label_flag(
24    name = "freertos_config",
25    build_setting_default = ":default_freertos_config",
26)
27
28cc_library(
29    name = "default_freertos_config",
30    # The "default" config is not compatible with any configuration: you can't
31    # build FreeRTOS without choosing a config.
32    target_compatible_with = ["@platforms//:incompatible"],
33)
34
35# Constraint setting used to select the FreeRTOSConfig version.
36constraint_setting(
37    name = "freertos_config_setting",
38)
39
40constraint_setting(
41    name = "port",
42)
43
44# Cortex-M33 with No TrustZone
45constraint_value(
46    name = "port_ARM_CM33_NTZ",
47    constraint_setting = ":port",
48)
49
50constraint_value(
51    name = "port_ARM_CM4F",
52    constraint_setting = ":port",
53)
54
55constraint_value(
56    name = "port_ARM_CM0",
57    constraint_setting = ":port",
58)
59
60constraint_value(
61    name = "port_ARM_CM3",
62    constraint_setting = ":port",
63)
64
65constraint_value(
66    name = "port_ARM_CM7",
67    constraint_setting = ":port",
68)
69
70constraint_value(
71    name = "port_Xtensa",
72    constraint_setting = ":port",
73)
74
75cc_library(
76    name = "freertos",
77    srcs = [
78        "croutine.c",
79        "event_groups.c",
80        "list.c",
81        "queue.c",
82        "stream_buffer.c",
83        "timers.c",
84    ] + select({
85        ":port_ARM_CM0": ["portable/GCC/ARM_CM0/port.c"],
86        ":port_ARM_CM3": ["portable/GCC/ARM_CM3/port.c"],
87        ":port_ARM_CM33_NTZ": [
88            "portable/GCC/ARM_CM33_NTZ/non_secure/port.c",
89            "portable/GCC/ARM_CM33_NTZ/non_secure/portasm.c",
90        ],
91        ":port_ARM_CM4F": ["portable/GCC/ARM_CM4F/port.c"],
92        ":port_ARM_CM7": ["portable/GCC/ARM_CM7/r0p1/port.c"],
93        ":port_Xtensa": [
94            "portable/ThirdParty/XCC/Xtensa/mpu.S",
95            "portable/ThirdParty/XCC/Xtensa/port.c",
96            "portable/ThirdParty/XCC/Xtensa/portasm.S",
97            "portable/ThirdParty/XCC/Xtensa/portclib.c",
98            "portable/ThirdParty/XCC/Xtensa/portmpu.c",
99            "portable/ThirdParty/XCC/Xtensa/xtensa_context.S",
100            "portable/ThirdParty/XCC/Xtensa/xtensa_coproc_handler.S",
101            "portable/ThirdParty/XCC/Xtensa/xtensa_intr.c",
102            "portable/ThirdParty/XCC/Xtensa/xtensa_intr_asm.S",
103            "portable/ThirdParty/XCC/Xtensa/xtensa_intr_wrapper.c",
104            "portable/ThirdParty/XCC/Xtensa/xtensa_overlay_os_hook.c",
105            "portable/ThirdParty/XCC/Xtensa/xtensa_vectors.S",
106        ],
107        "//conditions:default": [],
108    }),
109    includes = ["include/"],
110    textual_hdrs = [
111        "include/FreeRTOS.h",
112        "include/StackMacros.h",
113        "include/croutine.h",
114        "include/deprecated_definitions.h",
115        "include/event_groups.h",
116        "include/list.h",
117        "include/message_buffer.h",
118        "include/mpu_wrappers.h",
119        "include/portable.h",
120        "include/projdefs.h",
121        "include/queue.h",
122        "include/semphr.h",
123        "include/stack_macros.h",
124        "include/stream_buffer.h",
125        "include/task.h",
126        "include/timers.h",
127    ],
128    deps = [
129        ":freertos_config",
130        ":freertos_malloc",
131        ":freertos_port_headers",
132        ":tasks_c",
133    ],
134    # Required because breaking out tasks_c results in the dependencies between
135    # the libraries not being quite correct: to link tasks_c you actually need
136    # a bunch of the source files from here (e.g., list.c).
137    alwayslink = 1,
138)
139
140cc_library(
141    name = "freertos_port_headers",
142    hdrs = select({
143        ":port_ARM_CM0": ["portable/GCC/ARM_CM0/portmacro.h"],
144        ":port_ARM_CM3": ["portable/GCC/ARM_CM3/portmacro.h"],
145        # TODO: https://pwbug.dev/352591911 - Decide if we should support older
146        # versions that are missing portmacrocommon.h.
147        ":port_ARM_CM33_NTZ": glob(["portable/GCC/ARM_CM33_NTZ/non_secure/*.h"]),
148        ":port_ARM_CM4F": ["portable/GCC/ARM_CM4F/portmacro.h"],
149        ":port_ARM_CM7": ["portable/GCC/ARM_CM7/r0p1/portmacro.h"],
150        ":port_Xtensa": [
151            "portable/ThirdParty/XCC/Xtensa/portbenchmark.h",
152            "portable/ThirdParty/XCC/Xtensa/portmacro.h",
153            "portable/ThirdParty/XCC/Xtensa/porttrace.h",
154            "portable/ThirdParty/XCC/Xtensa/xtensa_api.h",
155            "portable/ThirdParty/XCC/Xtensa/xtensa_config.h",
156            "portable/ThirdParty/XCC/Xtensa/xtensa_context.h",
157            "portable/ThirdParty/XCC/Xtensa/xtensa_rtos.h",
158            "portable/ThirdParty/XCC/Xtensa/xtensa_timer.h",
159        ],
160        "//conditions:default": [],
161    }),
162    includes = select({
163        ":port_ARM_CM0": ["portable/GCC/ARM_CM0/"],
164        ":port_ARM_CM3": ["portable/GCC/ARM_CM3/"],
165        ":port_ARM_CM33_NTZ": ["portable/GCC/ARM_CM33_NTZ/non_secure"],
166        ":port_ARM_CM4F": ["portable/GCC/ARM_CM4F/"],
167        ":port_ARM_CM7": ["portable/GCC/ARM_CM7/r0p1/"],
168        ":port_Xtensa": ["portable/ThirdParty/XCC/Xtensa"],
169        "//conditions:default": [],
170    }),
171)
172
173# Headers transitively included by using "FreeRTOS.h"
174cc_library(
175    name = "freertos_headers",
176    hdrs = [
177        "include/FreeRTOS.h",
178        "include/deprecated_definitions.h",
179        "include/list.h",
180        "include/mpu_wrappers.h",
181        "include/portable.h",
182        "include/projdefs.h",
183        "include/stack_macros.h",
184        "include/task.h",
185        "include/timers.h",
186    ],
187    includes = [
188        "include/",
189    ],
190    visibility = ["//visibility:private"],
191    deps = [
192        ":freertos_config",
193        ":freertos_port_headers",
194    ],
195)
196
197# Constraint setting used to determine if task statics should be disabled.
198constraint_setting(
199    name = "disable_tasks_statics_setting",
200    default_constraint_value = ":no_disable_task_statics",
201)
202
203constraint_value(
204    name = "disable_task_statics",
205    constraint_setting = ":disable_tasks_statics_setting",
206)
207
208constraint_value(
209    name = "no_disable_task_statics",
210    constraint_setting = ":disable_tasks_statics_setting",
211)
212
213cc_library(
214    name = "tasks_c",
215    srcs = ["tasks.c"],
216    copts = [
217        "-Wno-cast-qual",
218    ],
219    local_defines = select({
220        ":disable_task_statics": [
221            "static=",
222        ],
223        "//conditions:default": [],
224    }),
225    deps = [":freertos_headers"],
226)
227
228# Constraint setting for malloc implementation.
229constraint_setting(
230    name = "malloc",
231    default_constraint_value = ":no_malloc",
232)
233
234constraint_value(
235    name = "no_malloc",
236    constraint_setting = ":malloc",
237)
238
239constraint_value(
240    name = "malloc_heap_1",
241    constraint_setting = ":malloc",
242)
243
244constraint_value(
245    name = "malloc_heap_2",
246    constraint_setting = ":malloc",
247)
248
249constraint_value(
250    name = "malloc_heap_3",
251    constraint_setting = ":malloc",
252)
253
254constraint_value(
255    name = "malloc_heap_4",
256    constraint_setting = ":malloc",
257)
258
259cc_library(
260    name = "freertos_malloc",
261    srcs = select({
262        ":malloc_heap_1": ["portable/MemMang/heap_1.c"],
263        ":malloc_heap_2": ["portable/MemMang/heap_2.c"],
264        ":malloc_heap_3": ["portable/MemMang/heap_3.c"],
265        ":malloc_heap_4": ["portable/MemMang/heap_4.c"],
266        ":no_malloc": [],
267    }),
268    visibility = ["//visibility:private"],
269    deps = [":freertos_headers"],
270)
271
272# Exported for
273# pw_thread_freertos/py/pw_thread_freertos/generate_freertos_tsktcb.py
274exports_files(
275    ["tasks.c"],
276)
277