• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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        ":port_ARM_CM33_NTZ": [
146            "portable/GCC/ARM_CM33_NTZ/non_secure/portasm.h",
147            "portable/GCC/ARM_CM33_NTZ/non_secure/portmacro.h",
148        ],
149        ":port_ARM_CM4F": ["portable/GCC/ARM_CM4F/portmacro.h"],
150        ":port_ARM_CM7": ["portable/GCC/ARM_CM7/r0p1/portmacro.h"],
151        ":port_Xtensa": [
152            "portable/ThirdParty/XCC/Xtensa/portbenchmark.h",
153            "portable/ThirdParty/XCC/Xtensa/portmacro.h",
154            "portable/ThirdParty/XCC/Xtensa/porttrace.h",
155            "portable/ThirdParty/XCC/Xtensa/xtensa_api.h",
156            "portable/ThirdParty/XCC/Xtensa/xtensa_config.h",
157            "portable/ThirdParty/XCC/Xtensa/xtensa_context.h",
158            "portable/ThirdParty/XCC/Xtensa/xtensa_rtos.h",
159            "portable/ThirdParty/XCC/Xtensa/xtensa_timer.h",
160        ],
161        "//conditions:default": [],
162    }),
163    includes = select({
164        ":port_ARM_CM0": ["portable/GCC/ARM_CM0/"],
165        ":port_ARM_CM3": ["portable/GCC/ARM_CM3/"],
166        ":port_ARM_CM33_NTZ": ["portable/GCC/ARM_CM33_NTZ/non_secure"],
167        ":port_ARM_CM4F": ["portable/GCC/ARM_CM4F/"],
168        ":port_ARM_CM7": ["portable/GCC/ARM_CM7/r0p1/"],
169        ":port_Xtensa": ["portable/ThirdParty/XCC/Xtensa"],
170        "//conditions:default": [],
171    }),
172)
173
174# Headers transitively included by using "FreeRTOS.h"
175cc_library(
176    name = "freertos_headers",
177    hdrs = [
178        "include/FreeRTOS.h",
179        "include/deprecated_definitions.h",
180        "include/list.h",
181        "include/mpu_wrappers.h",
182        "include/portable.h",
183        "include/projdefs.h",
184        "include/stack_macros.h",
185        "include/task.h",
186        "include/timers.h",
187    ],
188    includes = [
189        "include/",
190    ],
191    visibility = ["//visibility:private"],
192    deps = [
193        ":freertos_config",
194        ":freertos_port_headers",
195    ],
196)
197
198# Constraint setting used to determine if task statics should be disabled.
199constraint_setting(
200    name = "disable_tasks_statics_setting",
201    default_constraint_value = ":no_disable_task_statics",
202)
203
204constraint_value(
205    name = "disable_task_statics",
206    constraint_setting = ":disable_tasks_statics_setting",
207)
208
209constraint_value(
210    name = "no_disable_task_statics",
211    constraint_setting = ":disable_tasks_statics_setting",
212)
213
214cc_library(
215    name = "tasks_c",
216    srcs = ["tasks.c"],
217    local_defines = select({
218        ":disable_task_statics": [
219            "static=",
220        ],
221        "//conditions:default": [],
222    }),
223    deps = [":freertos_headers"],
224)
225
226# Constraint setting for malloc implementation.
227constraint_setting(
228    name = "malloc",
229    default_constraint_value = ":no_malloc",
230)
231
232constraint_value(
233    name = "no_malloc",
234    constraint_setting = ":malloc",
235)
236
237constraint_value(
238    name = "malloc_heap_1",
239    constraint_setting = ":malloc",
240)
241
242constraint_value(
243    name = "malloc_heap_2",
244    constraint_setting = ":malloc",
245)
246
247constraint_value(
248    name = "malloc_heap_3",
249    constraint_setting = ":malloc",
250)
251
252constraint_value(
253    name = "malloc_heap_4",
254    constraint_setting = ":malloc",
255)
256
257cc_library(
258    name = "freertos_malloc",
259    srcs = select({
260        ":malloc_heap_1": ["portable/MemMang/heap_1.c"],
261        ":malloc_heap_2": ["portable/MemMang/heap_2.c"],
262        ":malloc_heap_3": ["portable/MemMang/heap_3.c"],
263        ":malloc_heap_4": ["portable/MemMang/heap_4.c"],
264        ":no_malloc": [],
265    }),
266    visibility = ["//visibility:private"],
267    deps = [":freertos_headers"],
268)
269
270# Exported for
271# pw_thread_freertos/py/pw_thread_freertos/generate_freertos_tsktcb.py
272exports_files(
273    ["tasks.c"],
274)
275