Skip to content

Commit

Permalink
third_party/freertos: Add bazel support for malloc implementation
Browse files Browse the repository at this point in the history
Adds a constraint that can be used to select the malloc implementation,
with a default of no implementation.

Change-Id: I6d90e603f41efe9f3c58a67f4778546930b08866
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/151652
Reviewed-by: Austin Foxley <afoxley@google.com>
Reviewed-by: Keir Mierle <keir@google.com>
Commit-Queue: Scott James Remnant <keybuk@google.com>
  • Loading branch information
keybuk authored and CQ Bot Account committed Jun 16, 2023
1 parent 78abfa4 commit a32e043
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 26 deletions.
103 changes: 77 additions & 26 deletions third_party/freertos/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ pw_cc_library(
"//conditions:default": [],
}),
deps = [
":freertos_malloc",
":pigweed_tasks_c",
"@pigweed_config//:freertos_config",
],
Expand All @@ -112,6 +113,37 @@ pw_cc_library(
alwayslink = 1,
)

# Headers transitively included by using "FreeRTOS.h"
pw_cc_library(
name = "freertos_headers",
hdrs = [
"include/FreeRTOS.h",
"include/deprecated_definitions.h",
"include/list.h",
"include/mpu_wrappers.h",
"include/portable.h",
"include/projdefs.h",
"include/stack_macros.h",
"include/task.h",
"include/timers.h",
] + select({
":port_ARM_CM33_NTZ": ["portable/GCC/ARM_CM33_NTZ/non_secure/portmacro.h"],
":port_ARM_CM4F": ["portable/GCC/ARM_CM4F/portmacro.h"],
":port_ARM_CM7": ["portable/GCC/ARM_CM7/r0p1/portmacro.h"],
"//conditions:default": [],
}),
includes = [
"include/",
] + select({
":port_ARM_CM33_NTZ": ["portable/GCC/ARM_CM33_NTZ/non_secure"],
":port_ARM_CM4F": ["portable/GCC/ARM_CM4F/"],
":port_ARM_CM7": ["portable/GCC/ARM_CM7/r0p1/"],
"//conditions:default": [],
}),
visibility = ["//visibility:private"],
deps = ["@pigweed_config//:freertos_config"],
)

# Constraint setting used to determine if task statics should be disabled.
constraint_setting(
name = "disable_tasks_statics_setting",
Expand All @@ -137,38 +169,13 @@ pw_cc_library(
],
"//conditions:default": [],
}),
includes = [
"include/",
] + select({
":port_ARM_CM33_NTZ": ["portable/GCC/ARM_CM33_NTZ/non_secure"],
":port_ARM_CM4F": ["portable/GCC/ARM_CM4F/"],
":port_ARM_CM7": ["portable/GCC/ARM_CM7/r0p1/"],
"//conditions:default": [],
}),
local_defines = select({
":disable_task_statics": [
"static=",
],
"//conditions:default": [],
}),
# tasks.c transitively includes all these headers :/
textual_hdrs = [
"include/FreeRTOS.h",
"include/portable.h",
"include/projdefs.h",
"include/list.h",
"include/deprecated_definitions.h",
"include/mpu_wrappers.h",
"include/stack_macros.h",
"include/task.h",
"include/timers.h",
] + select({
":port_ARM_CM33_NTZ": ["portable/GCC/ARM_CM33_NTZ/non_secure/portmacro.h"],
":port_ARM_CM4F": ["portable/GCC/ARM_CM4F/portmacro.h"],
":port_ARM_CM7": ["portable/GCC/ARM_CM7/r0p1/portmacro.h"],
"//conditions:default": [],
}),
deps = ["@pigweed_config//:freertos_config"],
deps = [":freertos_headers"],
)

# Constraint setting used to select the FreeRTOSConfig version.
Expand All @@ -191,6 +198,50 @@ pw_cc_library(
target_compatible_with = ["@platforms//:incompatible"],
)

# Constraint setting for malloc implementation.
constraint_setting(
name = "malloc",
default_constraint_value = ":no_malloc",
)

constraint_value(
name = "no_malloc",
constraint_setting = ":malloc",
)

constraint_value(
name = "malloc_heap_1",
constraint_setting = ":malloc",
)

constraint_value(
name = "malloc_heap_2",
constraint_setting = ":malloc",
)

constraint_value(
name = "malloc_heap_3",
constraint_setting = ":malloc",
)

constraint_value(
name = "malloc_heap_4",
constraint_setting = ":malloc",
)

pw_cc_library(
name = "freertos_malloc",
srcs = select({
":malloc_heap_1": ["portable/MemMang/heap_1.c"],
":malloc_heap_2": ["portable/MemMang/heap_2.c"],
":malloc_heap_3": ["portable/MemMang/heap_3.c"],
":malloc_heap_4": ["portable/MemMang/heap_4.c"],
":no_malloc": [],
}),
visibility = ["//visibility:private"],
deps = [":freertos_headers"],
)

# Exported for
# pw_thread_freertos/py/pw_thread_freertos/generate_freertos_tsktcb.py
exports_files(
Expand Down
3 changes: 3 additions & 0 deletions third_party/freertos/docs.rst
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ values for the following settings:

* ``//third_party/freertos:port``, to set which FreeRTOS port to use. You can
select a value from those defined in ``third_party/freertos/BUILD.bazel``.
* ``//third_party/freertos:malloc``, to set which FreeRTOS malloc
implementation to use. You can select a value from those defined in
``third_party/freertos/BUILD.bazel``.
* ``//third_party/freertos:disable_task_statics_setting``, to determine
whether statics should be disabled during compilation of the tasks.c source
file (see next section). This setting has only two possible values, also
Expand Down

0 comments on commit a32e043

Please sign in to comment.