diff --git a/.bazelrc b/.bazelrc index 8ad686cdcda..97c452d516e 100644 --- a/.bazelrc +++ b/.bazelrc @@ -8,5 +8,6 @@ build:s32k148_relwithdebinfo --config=s32k148 build:s32k148_relwithdebinfo --copt=-g3 build:s32k148_relwithdebinfo --copt=-O2 build:s32k148_relwithdebinfo --copt=-DNDEBUG - +build:s32k148_threadx --config=s32k148 +build:s32k148_threadx --//bazel/config/rtos=threadx test --//bazel/config/executable_config=unit_test diff --git a/executables/referenceApp/platforms/posix/main/BUILD.bazel b/executables/referenceApp/platforms/posix/main/BUILD.bazel index ad8bffed700..ca5c65479cd 100644 --- a/executables/referenceApp/platforms/posix/main/BUILD.bazel +++ b/executables/referenceApp/platforms/posix/main/BUILD.bazel @@ -12,8 +12,36 @@ load("@rules_cc//cc:cc_library.bzl", "cc_library") cc_library( name = "freertos_os_hooks", - srcs = ["src/osHooks/freertos/osHooks.cpp"], + srcs = select({ + "//bazel/config/rtos:support_freertos": [ + "src/osHooks/freertos/osHooks.cpp", + ], + "//conditions:default": [], + }), + implementation_deps = select({ + "//bazel/config/rtos:support_freertos": [ + "//libs/3rdparty/freeRtos:freertos_headers", + ], + "//conditions:default": [], + }), target_compatible_with = ["@platforms//os:linux"], visibility = ["//libs/3rdparty/freeRtos:__pkg__"], - deps = ["//libs/3rdparty/freeRtos:freertos_headers"], +) + +cc_library( + name = "threadx_os_hooks", + srcs = select({ + "//bazel/config/rtos:support_threadx": [ + "src/osHooks/threadx/osHooks.cpp", + ], + "//conditions:default": [], + }), + implementation_deps = select({ + "//bazel/config/rtos:support_threadx": [ + "//libs/3rdparty/threadx:threadx_headers", + ], + "//conditions:default": [], + }), + target_compatible_with = ["@platforms//os:linux"], + visibility = ["//libs/3rdparty/threadx:__pkg__"], ) diff --git a/executables/referenceApp/platforms/posix/threadXCoreConfiguration/BUILD.bazel b/executables/referenceApp/platforms/posix/threadXCoreConfiguration/BUILD.bazel new file mode 100644 index 00000000000..444b63673ea --- /dev/null +++ b/executables/referenceApp/platforms/posix/threadXCoreConfiguration/BUILD.bazel @@ -0,0 +1,18 @@ +# ******************************************************************************* +# Copyright (c) 2026 Accenture +# +# This program and the accompanying materials are made available under the +# terms of the Apache License Version 2.0 which is available at +# https://www.apache.org/licenses/LICENSE-2.0 +# +# SPDX-License-Identifier: Apache-2.0 +# ******************************************************************************* + +load("@rules_cc//cc:cc_library.bzl", "cc_library") + +cc_library( + name = "threadx_core_configuration", + hdrs = ["include/tx_user.h"], + strip_include_prefix = "include", + visibility = ["//visibility:public"], +) diff --git a/executables/referenceApp/platforms/s32k148evb/main/BUILD.bazel b/executables/referenceApp/platforms/s32k148evb/main/BUILD.bazel index a53f927f342..a18ae14e097 100644 --- a/executables/referenceApp/platforms/s32k148evb/main/BUILD.bazel +++ b/executables/referenceApp/platforms/s32k148evb/main/BUILD.bazel @@ -12,11 +12,47 @@ load("@rules_cc//cc:cc_library.bzl", "cc_library") cc_library( name = "freertos_os_hooks", - srcs = ["src/osHooks/freertos/osHooks.cpp"], + srcs = select({ + "//bazel/config/rtos:support_freertos": [ + "src/osHooks/freertos/osHooks.cpp", + ], + "//conditions:default": [], + }), + implementation_deps = select({ + "//bazel/config/rtos:support_freertos": [ + "//libs/3rdparty/freeRtos:freertos_headers", + "//libs/bsw/common", + ], + "//conditions:default": [], + }), target_compatible_with = ["//bazel/platform/constraints/soc:s32k148"], visibility = ["//libs/3rdparty/freeRtos:__pkg__"], - deps = [ - "//libs/3rdparty/freeRtos:freertos_headers", - "//libs/bsw/common", - ], +) + +cc_library( + name = "threadx_os_hooks", + srcs = select({ + "//bazel/config/rtos:support_threadx": [ + "src/osHooks/threadx/osHooks.cpp", + ], + "//conditions:default": [], + }), + hdrs = select({ + "//bazel/config/rtos:support_threadx": [ + "include/osHooks/threadx/osHooks.h", + ], + "//conditions:default": [], + }), + implementation_deps = select({ + "//bazel/config/rtos:support_threadx": [ + "//libs/3rdparty/threadx:threadx_headers", + "//libs/bsw/asyncThreadX:threadx_configuration", + "//libs/bsw/common", + "//platforms/s32k1xx/3rdparty/threadx:threadx_cortex_m4", + ], + "//conditions:default": [], + }), + strip_include_prefix = "include/osHooks/threadx", + target_compatible_with = ["//bazel/platform/constraints/soc:s32k148"], + visibility = ["//libs/3rdparty/threadx:__pkg__"], ) diff --git a/executables/referenceApp/platforms/s32k148evb/threadXCoreConfiguration/BUILD.bazel b/executables/referenceApp/platforms/s32k148evb/threadXCoreConfiguration/BUILD.bazel new file mode 100644 index 00000000000..9a759e042cf --- /dev/null +++ b/executables/referenceApp/platforms/s32k148evb/threadXCoreConfiguration/BUILD.bazel @@ -0,0 +1,19 @@ +# ******************************************************************************* +# Copyright (c) 2026 Accenture +# +# This program and the accompanying materials are made available under the +# terms of the Apache License Version 2.0 which is available at +# https://www.apache.org/licenses/LICENSE-2.0 +# +# SPDX-License-Identifier: Apache-2.0 +# ******************************************************************************* + +load("@rules_cc//cc:cc_library.bzl", "cc_library") + +cc_library( + name = "threadx_core_configuration", + hdrs = ["include/tx_user.h"], + strip_include_prefix = "include", + target_compatible_with = ["//bazel/platform/constraints/soc:s32k148"], + visibility = ["//visibility:public"], +) diff --git a/libs/3rdparty/freeRtos/BUILD.bazel b/libs/3rdparty/freeRtos/BUILD.bazel index 9fe26dbcd49..668dc1c7a1e 100644 --- a/libs/3rdparty/freeRtos/BUILD.bazel +++ b/libs/3rdparty/freeRtos/BUILD.bazel @@ -72,36 +72,51 @@ label_flag( cc_library( name = "freertos_headers", - hdrs = glob(["include/**/*.h"]), + hdrs = select({ + "//bazel/config/rtos:support_freertos": glob(["include/**/*.h"]), + "//conditions:default": [], + }), strip_include_prefix = "include", visibility = ["//visibility:public"], - deps = [ - ":freertos_port", - "//libs/bsw/asyncFreeRtos:freertos_configuration", - ], + deps = select({ + "//bazel/config/rtos:support_freertos": [ + ":freertos_port", + "//libs/bsw/asyncFreeRtos:freertos_configuration", + ], + "//conditions:default": [], + }), ) # Circular dependency present on the CMake side: freeRtos -> freeRtosPortImpl -> freeRtos # Split off freertos_headers and freertos_port_impl to break the circular dependency for Bazel cc_library( name = "freertos", - srcs = [ - "src/croutine.c", - "src/event_groups.c", - "src/list.c", - "src/queue.c", - "src/stream_buffer.c", - "src/tasks.c", - "src/timers.c", - ], + srcs = select({ + "//bazel/config/rtos:support_freertos": [ + "src/croutine.c", + "src/event_groups.c", + "src/list.c", + "src/queue.c", + "src/stream_buffer.c", + "src/tasks.c", + "src/timers.c", + ], + "//conditions:default": [], + }), copts = ["-Wno-unused-variable"], - implementation_deps = [ - ":freertos_os_hooks", - ":freertos_port_impl", - ], + implementation_deps = select({ + "//bazel/config/rtos:support_freertos": [ + ":freertos_os_hooks", + ":freertos_port_impl", + ], + "//conditions:default": [], + }), visibility = ["//visibility:public"], - deps = [ - ":freertos_headers", - "//libs/bsw/platform", - ], + deps = select({ + "//bazel/config/rtos:support_freertos": [ + ":freertos_headers", + "//libs/bsw/platform", + ], + "//conditions:default": [], + }), ) diff --git a/libs/3rdparty/threadx/BUILD.bazel b/libs/3rdparty/threadx/BUILD.bazel new file mode 100644 index 00000000000..d61b2ef30fe --- /dev/null +++ b/libs/3rdparty/threadx/BUILD.bazel @@ -0,0 +1,117 @@ +# ******************************************************************************* +# Copyright (c) 2026 Accenture +# +# This program and the accompanying materials are made available under the +# terms of the Apache License Version 2.0 which is available at +# https://www.apache.org/licenses/LICENSE-2.0 +# +# SPDX-License-Identifier: Apache-2.0 +# ******************************************************************************* + +load("@rules_cc//cc:cc_library.bzl", "cc_library") + +alias( + name = "threadx_port_default", + actual = select( + { + "//bazel/platform/constraints/soc:s32k148": "//platforms/s32k1xx/3rdparty/threadx:threadx_cortex_m4_port", + "@platforms//os:linux": "//platforms/posix/3rdparty/threadx:threadx_linux_port_headers", + }, + no_match_error = "No ThreadX port for this platform. Override --//libs/3rdparty/threadx:threadx_port with your own port target.", + ), +) + +# ThreadX port (tx_port.h). +# Default: select based on the target platform (S32K148, POSIX) +# Override: --//libs/3rdparty/threadx:threadx_port=//path/to:your_port +label_flag( + name = "threadx_port", + build_setting_default = ":threadx_port_default", + visibility = ["//visibility:public"], +) + +alias( + name = "threadx_port_impl_default", + actual = select( + { + "//bazel/platform/constraints/soc:s32k148": "//platforms/s32k1xx/3rdparty/threadx:threadx_cortex_m4", + "@platforms//os:linux": "//platforms/posix/3rdparty/threadx:threadx_linux", + }, + no_match_error = "No ThreadX port implementation for this platform. Override --//libs/3rdparty/threadx:threadx_port_impl with your own port target.", + ), +) + +# ThreadX port implementation +# Default: select based on the target platform (S32K148, POSIX) +# Override: --//libs/3rdparty/threadx:threadx_port_impl=//path/to:your_port_impl +label_flag( + name = "threadx_port_impl", + build_setting_default = ":threadx_port_impl_default", + visibility = ["//visibility:public"], +) + +alias( + name = "threadx_os_hooks_default", + actual = select( + { + "//bazel/platform/constraints/soc:s32k148": "//executables/referenceApp/platforms/s32k148evb/main:threadx_os_hooks", + "@platforms//os:linux": "//executables/referenceApp/platforms/posix/main:threadx_os_hooks", + }, + no_match_error = "No ThreadX OS hooks for this platform. Override --//libs/3rdparty/threadx:threadx_os_hooks with your own hooks target.", + ), +) + +# ThreadX OS hooks +# Default: select based on the target platform (S32K148, POSIX) +# Override: --//libs/3rdparty/threadx:threadx_os_hooks=//path/to:your_os_hooks +label_flag( + name = "threadx_os_hooks", + build_setting_default = ":threadx_os_hooks_default", + visibility = ["//visibility:public"], +) + +cc_library( + name = "threadx_headers", + hdrs = select({ + "//bazel/config/rtos:support_threadx": glob(["common/inc/**/*.h"]), + "//conditions:default": [], + }), + includes = select({ + "//bazel/config/rtos:support_threadx": ["common/inc"], + "//conditions:default": [], + }), + visibility = ["//visibility:public"], + deps = select({ + "//bazel/config/rtos:support_threadx": [ + ":threadx_port", + "//libs/bsw/asyncThreadX:threadx_configuration", + ], + "//conditions:default": [], + }), +) + +# Circular dependency present on the CMake side: threadX -> osHooks -> asyncThreadX -> threadX +# Split off threadx_headers to break the circular dependency for Bazel +cc_library( + name = "threadx", + srcs = select({ + "//bazel/config/rtos:support_threadx": glob(["common/src/*.c"]), + "//conditions:default": [], + }), + copts = ["-Wno-error=unused-parameter"], + implementation_deps = select({ + "//bazel/config/rtos:support_threadx": [ + ":threadx_os_hooks", + ":threadx_port_impl", + ], + "//conditions:default": [], + }), + visibility = ["//visibility:public"], + deps = select({ + "//bazel/config/rtos:support_threadx": [ + ":threadx_headers", + "//libs/bsw/platform", + ], + "//conditions:default": [], + }), +) diff --git a/libs/bsw/async/BUILD.bazel b/libs/bsw/async/BUILD.bazel index 1f1012fc5ac..558dfef5e81 100644 --- a/libs/bsw/async/BUILD.bazel +++ b/libs/bsw/async/BUILD.bazel @@ -10,14 +10,34 @@ load("@rules_cc//cc:cc_library.bzl", "cc_library") +alias( + name = "async_rtos_impl_default", + actual = select( + { + "//bazel/config/rtos:support_freertos": "//libs/bsw/asyncFreeRtos:async_freertos_impl", + "//bazel/config/rtos:support_threadx": "//libs/bsw/asyncThreadX:async_threadx_impl", + }, + no_match_error = "async_rtos_impl: build with --//bazel/config/rtos=freertos or --//bazel/config/rtos=threadx, or override --//libs/bsw/async:async_rtos_impl.", + ), +) + +# Async compiled RTOS implementation +# Default: select based on //bazel/config/rtos +# Override: --//libs/bsw/async:async_rtos_impl=//path/to:your_rtos_impl +label_flag( + name = "async_rtos_impl", + build_setting_default = ":async_rtos_impl_default", + visibility = ["//visibility:public"], +) + alias( name = "async_platform_default", actual = select( { "//bazel/config/rtos:support_freertos": "//libs/bsw/asyncFreeRtos:async_freertos", - # TODO: Add threadX support here once libs/3rdparty/threadx has been migrated + "//bazel/config/rtos:support_threadx": "//libs/bsw/asyncThreadX:async_threadx", }, - no_match_error = "async: only the FREERTOS asyncPlatform is migrated; build with --//bazel/config/rtos=freertos (ThreadX deferred), or override --//libs/bsw/async:async_platform.", + no_match_error = "async: build with --//bazel/config/rtos=freertos or --//bazel/config/rtos=threadx, or override --//libs/bsw/async:async_platform.", ), ) @@ -52,17 +72,29 @@ cc_library( ], strip_include_prefix = "include", visibility = ["//visibility:public"], - deps = [ - ":async_platform", - "//libs/3rdparty/etl", - ], + deps = select({ + "//bazel/config/rtos:support_freertos": [ + ":async_platform", + "//libs/3rdparty/etl", + ], + "//bazel/config/rtos:support_threadx": [ + ":async_platform", + "//libs/3rdparty/etl", + ], + }), ) cc_library( name = "async", visibility = ["//visibility:public"], - deps = [ - ":async_binding", - ":async_headers", - ], + deps = select({ + "//bazel/config/rtos:support_freertos": [ + ":async_binding", + ":async_headers", + ], + "//bazel/config/rtos:support_threadx": [ + ":async_binding", + ":async_headers", + ], + }), ) diff --git a/libs/bsw/asyncFreeRtos/BUILD.bazel b/libs/bsw/asyncFreeRtos/BUILD.bazel index 71c803ba841..6d15d45c398 100644 --- a/libs/bsw/asyncFreeRtos/BUILD.bazel +++ b/libs/bsw/asyncFreeRtos/BUILD.bazel @@ -57,31 +57,40 @@ cc_library( ], strip_include_prefix = "include", visibility = ["//visibility:public"], - deps = [ - "//libs/3rdparty/freeRtos:freertos", - "//libs/bsp/bspInterrupts:bsp_interrupts", - "//libs/bsw/asyncImpl:async_impl", - "//libs/bsw/bsp", - "//libs/bsw/common", - "//libs/bsw/timer", - ], + deps = select({ + "//bazel/config/rtos:support_freertos": [ + "//libs/3rdparty/freeRtos:freertos", + "//libs/bsp/bspInterrupts:bsp_interrupts", + "//libs/bsw/asyncImpl:async_impl", + "//libs/bsw/bsp", + "//libs/bsw/common", + "//libs/bsw/timer", + ], + "//conditions:default": [], + }), ) cc_library( name = "async_freertos_impl", - srcs = [ - "src/async/Async.cpp", - "src/async/FutureSupport.cpp", - "src/async/Hook.cpp", - "src/async/Types.cpp", - ], - implementation_deps = [ - ":async_core_configuration", - ":async_freertos", - "//libs/3rdparty/etl", - "//libs/bsw/async:async_binding", - "//libs/bsw/util", - ], + srcs = select({ + "//bazel/config/rtos:support_freertos": [ + "src/async/Async.cpp", + "src/async/FutureSupport.cpp", + "src/async/Hook.cpp", + "src/async/Types.cpp", + ], + "//conditions:default": [], + }), + implementation_deps = select({ + "//bazel/config/rtos:support_freertos": [ + ":async_core_configuration", + ":async_freertos", + "//libs/3rdparty/etl", + "//libs/bsw/async:async_binding", + "//libs/bsw/util", + ], + "//conditions:default": [], + }), visibility = ["//visibility:public"], ) @@ -94,9 +103,12 @@ cc_library( ], strip_include_prefix = "freeRtosConfiguration", visibility = ["//visibility:public"], - deps = [ - ":async_core_configuration", - ":freertos_core_configuration", - "//libs/bsw/platform", - ], + deps = select({ + "//bazel/config/rtos:support_freertos": [ + ":async_core_configuration", + ":freertos_core_configuration", + "//libs/bsw/platform", + ], + "//conditions:default": [], + }), ) diff --git a/libs/bsw/asyncThreadX/BUILD.bazel b/libs/bsw/asyncThreadX/BUILD.bazel new file mode 100644 index 00000000000..30e685b73be --- /dev/null +++ b/libs/bsw/asyncThreadX/BUILD.bazel @@ -0,0 +1,96 @@ +# ******************************************************************************* +# Copyright (c) 2026 Accenture +# +# This program and the accompanying materials are made available under the +# terms of the Apache License Version 2.0 which is available at +# https://www.apache.org/licenses/LICENSE-2.0 +# +# SPDX-License-Identifier: Apache-2.0 +# ******************************************************************************* + +load("@rules_cc//cc:cc_library.bzl", "cc_library") + +alias( + name = "threadx_core_configuration_default", + actual = select( + { + "//bazel/platform/constraints/soc:s32k148": "//executables/referenceApp/platforms/s32k148evb/threadXCoreConfiguration:threadx_core_configuration", + "@platforms//os:linux": "//executables/referenceApp/platforms/posix/threadXCoreConfiguration:threadx_core_configuration", + }, + no_match_error = "No ThreadX core configuration for this platform. Override --//libs/bsw/asyncThreadX:threadx_core_configuration with your own configuration target.", + ), +) + +# ThreadX core configuration (Hook.h, ThreadCConfig.h and platform wiring). +# Default: select based on the target platform (S32K148, POSIX) +# Override: --//libs/bsw/asyncThreadX:threadx_core_configuration=//path/to:your_config +label_flag( + name = "threadx_core_configuration", + build_setting_default = ":threadx_core_configuration_default", + visibility = ["//visibility:public"], +) + +cc_library( + name = "async_threadx", + hdrs = glob(["include/**/*.h"]), + strip_include_prefix = "include", + visibility = ["//visibility:public"], + deps = select({ + "//bazel/config/rtos:support_threadx": [ + "//libs/3rdparty/threadx", + "//libs/bsp/bspInterrupts:bsp_interrupts", + "//libs/bsw/asyncImpl:async_impl", + "//libs/bsw/bsp", + "//libs/bsw/common", + "//libs/bsw/timer", + ], + "//conditions:default": [ + # Only platform-agnostic deps in non-ThreadX builds + "//libs/bsw/asyncImpl:async_impl", + "//libs/bsw/common", + ], + }), +) + +cc_library( + name = "threadx_configuration", + hdrs = [ + "threadXConfiguration/ThreadXConfig.h", + "threadXConfiguration/async/Hook.h", + ], + strip_include_prefix = "threadXConfiguration", + visibility = ["//visibility:public"], + deps = select({ + "//bazel/config/rtos:support_threadx": [ + ":threadx_core_configuration", + "//libs/bsw/asyncFreeRtos:async_core_configuration", + "//libs/bsw/platform", + ], + "//conditions:default": [ + ":threadx_core_configuration", + "//libs/bsw/platform", + ], + }), +) + +cc_library( + name = "async_threadx_impl", + srcs = select({ + "//bazel/config/rtos:support_threadx": [ + "src/async/FutureSupport.cpp", + "src/async/Types.cpp", + ], + "//conditions:default": [], + }), + implementation_deps = select({ + "//bazel/config/rtos:support_threadx": [ + ":async_threadx", + ":threadx_configuration", + "//libs/3rdparty/etl", + "//libs/bsw/async:async_binding", + "//libs/bsw/util", + ], + "//conditions:default": [], + }), + visibility = ["//visibility:public"], +) diff --git a/libs/bsw/storage/BUILD.bazel b/libs/bsw/storage/BUILD.bazel index df2a6282351..da9fa3c174a 100644 --- a/libs/bsw/storage/BUILD.bazel +++ b/libs/bsw/storage/BUILD.bazel @@ -10,14 +10,14 @@ load("@rules_cc//cc:cc_library.bzl", "cc_library") -# TODO: Add asyncThreadXImpl branch once ThreadX has been migrated. alias( name = "storage_rtos_impl", actual = select( { "//bazel/config/rtos:support_freertos": "//libs/bsw/asyncFreeRtos:async_freertos_impl", + "//bazel/config/rtos:support_threadx": "//libs/bsw/asyncThreadX:async_threadx_impl", }, - no_match_error = "storage: asyncFreeRtosImpl only migrated for FreeRTOS; build with --//bazel/config/rtos=freertos (ThreadX deferred).", + no_match_error = "storage: build with --//bazel/config/rtos=freertos or --//bazel/config/rtos=threadx.", ), ) diff --git a/platforms/posix/3rdparty/freeRtosPosix/BUILD.bazel b/platforms/posix/3rdparty/freeRtosPosix/BUILD.bazel index d8333923244..ddc9064f884 100644 --- a/platforms/posix/3rdparty/freeRtosPosix/BUILD.bazel +++ b/platforms/posix/3rdparty/freeRtosPosix/BUILD.bazel @@ -1,3 +1,13 @@ +# ******************************************************************************* +# Copyright (c) 2026 Accenture +# +# This program and the accompanying materials are made available under the +# terms of the Apache License Version 2.0 which is available at +# https://www.apache.org/licenses/LICENSE-2.0 +# +# SPDX-License-Identifier: Apache-2.0 +# ******************************************************************************* + load("@rules_cc//cc:cc_library.bzl", "cc_library") cc_library( diff --git a/platforms/posix/3rdparty/threadx/BUILD.bazel b/platforms/posix/3rdparty/threadx/BUILD.bazel new file mode 100644 index 00000000000..0d4c0d829b3 --- /dev/null +++ b/platforms/posix/3rdparty/threadx/BUILD.bazel @@ -0,0 +1,69 @@ +# ******************************************************************************* +# Copyright (c) 2026 Accenture +# +# This program and the accompanying materials are made available under the +# terms of the Apache License Version 2.0 which is available at +# https://www.apache.org/licenses/LICENSE-2.0 +# +# SPDX-License-Identifier: Apache-2.0 +# ******************************************************************************* + +load("@rules_cc//cc:cc_library.bzl", "cc_library") + +cc_library( + name = "threadx_linux", + srcs = select({ + "//bazel/config/rtos:support_threadx": [ + "ports/linux/gnu/src/tx_initialize_low_level.c", + "ports/linux/gnu/src/tx_thread_context_restore.c", + "ports/linux/gnu/src/tx_thread_context_save.c", + "ports/linux/gnu/src/tx_thread_interrupt_control.c", + "ports/linux/gnu/src/tx_thread_schedule.c", + "ports/linux/gnu/src/tx_thread_stack_build.c", + "ports/linux/gnu/src/tx_thread_system_return.c", + "ports/linux/gnu/src/tx_timer_interrupt.c", + ], + "//conditions:default": [], + }), + copts = ["--warn-no-unused-result"], + linkopts = ["-lpthread"], + local_defines = ["TX_INCLUDE_USER_DEFINE_FILE"], + target_compatible_with = ["@platforms//os:linux"], + visibility = ["//visibility:public"], + deps = select({ + "//bazel/config/rtos:support_threadx": [ + "//libs/3rdparty/threadx:threadx_headers", + "//libs/bsp/bspInterrupts:bsp_interrupts", + "//libs/bsw/asyncThreadX:threadx_core_configuration", + ], + "//conditions:default": [], + }), +) + +cc_library( + name = "threadx_linux_port_headers", + hdrs = select({ + "//bazel/config/rtos:support_threadx": [ + "ports/linux/gnu/inc/tx_port.h", + ], + "//conditions:default": [], + }), + defines = select({ + "//bazel/config/rtos:support_threadx": [ + "TX_INCLUDE_USER_DEFINE_FILE", + "_GNU_SOURCE", + "TX_LINUX_DEBUG_ENABLE", + ], + "//conditions:default": [], + }), + linkopts = ["-lpthread"], + strip_include_prefix = "ports/linux/gnu/inc", + target_compatible_with = ["@platforms//os:linux"], + visibility = ["//visibility:public"], + deps = select({ + "//bazel/config/rtos:support_threadx": [ + "//libs/bsw/asyncThreadX:threadx_core_configuration", + ], + "//conditions:default": [], + }), +) diff --git a/platforms/posix/bsp/bspInterruptsImpl/BUILD.bazel b/platforms/posix/bsp/bspInterruptsImpl/BUILD.bazel index 6f49b66a851..ff0cde03007 100644 --- a/platforms/posix/bsp/bspInterruptsImpl/BUILD.bazel +++ b/platforms/posix/bsp/bspInterruptsImpl/BUILD.bazel @@ -11,13 +11,71 @@ load("@rules_cc//cc:cc_library.bzl", "cc_library") cc_library( - name = "bsp_interrupts_impl", - srcs = ["freertos/src/interrupts/suspendResumeAllInterrupts.cpp"], - hdrs = ["freertos/include/interrupts/suspendResumeAllInterrupts.h"], + name = "bsp_interrupts_impl_freertos", + srcs = select({ + "//bazel/config/rtos:support_freertos": [ + "freertos/src/interrupts/suspendResumeAllInterrupts.cpp", + ], + "//conditions:default": [], + }), + hdrs = select({ + "//bazel/config/rtos:support_freertos": [ + "freertos/include/interrupts/suspendResumeAllInterrupts.h", + ], + "//conditions:default": [], + }), + implementation_deps = select({ + "//bazel/config/rtos:support_freertos": [ + "//libs/3rdparty/freeRtos:freertos_headers", + ], + "//conditions:default": [], + }), strip_include_prefix = "freertos/include", + deps = select({ + "//bazel/config/rtos:support_freertos": [ + "//libs/bsw/platform", + ], + "//conditions:default": [], + }), +) + +cc_library( + name = "bsp_interrupts_impl_threadx", + srcs = select({ + "//bazel/config/rtos:support_threadx": [ + "threadx/src/interrupts/suspendResumeAllInterrupts.cpp", + ], + "//conditions:default": [], + }), + hdrs = select({ + "//bazel/config/rtos:support_threadx": [ + "threadx/include/interrupts/suspendResumeAllInterrupts.h", + ], + "//conditions:default": [], + }), + implementation_deps = select({ + "//bazel/config/rtos:support_threadx": [ + "//libs/3rdparty/threadx:threadx_headers", + ], + "//conditions:default": [], + }), + strip_include_prefix = "threadx/include", + deps = select({ + "//bazel/config/rtos:support_threadx": [ + "//libs/bsw/platform", + ], + "//conditions:default": [], + }), +) + +alias( + name = "bsp_interrupts_impl", + actual = select( + { + "//bazel/config/rtos:support_freertos": ":bsp_interrupts_impl_freertos", + "//bazel/config/rtos:support_threadx": ":bsp_interrupts_impl_threadx", + }, + no_match_error = "bsp_interrupts_impl: build with --//bazel/config/rtos=freertos or --//bazel/config/rtos=threadx.", + ), visibility = ["//visibility:public"], - deps = [ - "//libs/3rdparty/freeRtos:freertos_headers", - "//libs/bsw/platform", - ], ) diff --git a/platforms/s32k1xx/3rdparty/freertos_cm4_sysTick/BUILD.bazel b/platforms/s32k1xx/3rdparty/freertos_cm4_sysTick/BUILD.bazel index ec7312cfe74..70445f81b54 100644 --- a/platforms/s32k1xx/3rdparty/freertos_cm4_sysTick/BUILD.bazel +++ b/platforms/s32k1xx/3rdparty/freertos_cm4_sysTick/BUILD.bazel @@ -1,8 +1,23 @@ +# ******************************************************************************* +# Copyright (c) 2026 Accenture +# +# This program and the accompanying materials are made available under the +# terms of the Apache License Version 2.0 which is available at +# https://www.apache.org/licenses/LICENSE-2.0 +# +# SPDX-License-Identifier: Apache-2.0 +# ******************************************************************************* + load("@rules_cc//cc:cc_library.bzl", "cc_library") cc_library( name = "freertos_cm4_sys_tick_port_headers", - hdrs = ["include/portmacro.h"], + hdrs = select({ + "//bazel/config/rtos:support_freertos": [ + "include/portmacro.h", + ], + "//conditions:default": [], + }), strip_include_prefix = "include", target_compatible_with = ["//bazel/platform/constraints/soc:s32k148"], visibility = ["//visibility:public"], @@ -12,15 +27,23 @@ cc_library( # Split off freertos_headers to break the circular dependency for Bazel cc_library( name = "freertos_cm4_sys_tick", - srcs = ["src/port.c"], + srcs = select({ + "//bazel/config/rtos:support_freertos": [ + "src/port.c", + ], + "//conditions:default": [], + }), copts = ["-Wno-unused-but-set-variable"], implementation_deps = [ "//libs/bsp/bspInterrupts:bsp_interrupts", ], target_compatible_with = ["//bazel/platform/constraints/soc:s32k148"], visibility = ["//visibility:public"], - deps = [ - ":freertos_cm4_sys_tick_port_headers", - "//libs/3rdparty/freeRtos:freertos_headers", - ], + deps = select({ + "//bazel/config/rtos:support_freertos": [ + ":freertos_cm4_sys_tick_port_headers", + "//libs/3rdparty/freeRtos:freertos_headers", + ], + "//conditions:default": [], + }), ) diff --git a/platforms/s32k1xx/3rdparty/threadx/BUILD.bazel b/platforms/s32k1xx/3rdparty/threadx/BUILD.bazel new file mode 100644 index 00000000000..ec516d4bf0c --- /dev/null +++ b/platforms/s32k1xx/3rdparty/threadx/BUILD.bazel @@ -0,0 +1,64 @@ +# ******************************************************************************* +# Copyright (c) 2026 Accenture +# +# This program and the accompanying materials are made available under the +# terms of the Apache License Version 2.0 which is available at +# https://www.apache.org/licenses/LICENSE-2.0 +# +# SPDX-License-Identifier: Apache-2.0 +# ******************************************************************************* + +load("@rules_cc//cc:cc_library.bzl", "cc_library") + +cc_library( + name = "threadx_cortex_m4", + srcs = select({ + "//bazel/config/rtos:support_threadx": [ + "ports/cortex_m4/gnu/src/tx_thread_context_restore.S", + "ports/cortex_m4/gnu/src/tx_thread_context_save.S", + "ports/cortex_m4/gnu/src/tx_thread_interrupt_control.S", + "ports/cortex_m4/gnu/src/tx_thread_schedule.S", + "ports/cortex_m4/gnu/src/tx_thread_stack_build.S", + "ports/cortex_m4/gnu/src/tx_thread_system_return.S", + "ports/cortex_m4/gnu/src/tx_timer_interrupt.S", + ], + "//conditions:default": [], + }), + local_defines = select({ + "//bazel/config/rtos:support_threadx": ["TX_INCLUDE_USER_DEFINE_FILE"], + "//conditions:default": [], + }), + visibility = ["//visibility:public"], + deps = select({ + "//bazel/config/rtos:support_threadx": [ + "//libs/3rdparty/threadx:threadx_headers", + "//libs/bsp/bspInterrupts:bsp_interrupts", + "//libs/bsw/asyncThreadX:threadx_core_configuration", + "//platforms/s32k1xx/bsp/bspMcu:bsp_mcu", + ], + "//conditions:default": [], + }), +) + +cc_library( + name = "threadx_cortex_m4_port", + hdrs = select({ + "//bazel/config/rtos:support_threadx": [ + "ports/cortex_m4/gnu/inc/tx_port.h", + ], + "//conditions:default": [], + }), + defines = select({ + "//bazel/config/rtos:support_threadx": ["TX_INCLUDE_USER_DEFINE_FILE"], + "//conditions:default": [], + }), + strip_include_prefix = "ports/cortex_m4/gnu/inc", + target_compatible_with = ["//bazel/platform/constraints/soc:s32k148"], + visibility = ["//visibility:public"], + deps = select({ + "//bazel/config/rtos:support_threadx": [ + "//libs/bsw/asyncThreadX:threadx_core_configuration", + ], + "//conditions:default": [], + }), +) diff --git a/platforms/s32k1xx/bsp/bspInterruptsImpl/BUILD.bazel b/platforms/s32k1xx/bsp/bspInterruptsImpl/BUILD.bazel index 2fb84f00f4b..7c1b7c420dd 100644 --- a/platforms/s32k1xx/bsp/bspInterruptsImpl/BUILD.bazel +++ b/platforms/s32k1xx/bsp/bspInterruptsImpl/BUILD.bazel @@ -23,14 +23,22 @@ cc_library( target_compatible_with = ["//bazel/platform/constraints/soc:s32k148"], ) +cc_library( + name = "bsp_interrupts_impl_threadx_hdrs", + hdrs = ["threadx/include/interrupts/suspendResumeAllInterrupts.h"], + strip_include_prefix = "threadx/include", + target_compatible_with = ["//bazel/platform/constraints/soc:s32k148"], + deps = ["//libs/3rdparty/threadx:threadx_headers"], +) + alias( name = "bsp_interrupts_impl_rtos_hdrs", actual = select( { "//bazel/config/rtos:support_freertos": ":bsp_interrupts_impl_freertos_hdrs", - # TODO: add a "//bazel/config/rtos:support_threadx" branch once ThreadX is migrated. + "//bazel/config/rtos:support_threadx": ":bsp_interrupts_impl_threadx_hdrs", }, - no_match_error = "s32k1xx bsp_interrupts_impl supports only --//bazel/config/rtos=freertos; ThreadX is not yet migrated.", + no_match_error = "s32k1xx bsp_interrupts_impl supports only --//bazel/config/rtos=freertos or --//bazel/config/rtos=threadx.", ), )