From e61919ca93f922bc67fc6bd2f005c00f858cdcbd Mon Sep 17 00:00:00 2001 From: Randy Zhang Date: Tue, 21 Jan 2025 12:21:43 -0800 Subject: [PATCH] pw_interrupt_cortex_a: Add pw_interrupt backend for A-profile processors MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I53b570aab788eb0cde8e14c2342a31b9218938e3 Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/261396 Lint: Lint 🤖 Reviewed-by: Dave Roth Commit-Queue: Randy Zhang --- CMakeLists.txt | 1 + PIGWEED_MODULES | 1 + docs/module_metadata.json | 4 ++ pw_build/generated_pigweed_modules_lists.gni | 5 ++ pw_interrupt/backends.rst | 1 + pw_interrupt_cortex_a/BUILD.bazel | 56 +++++++++++++++++++ pw_interrupt_cortex_a/BUILD.gn | 48 ++++++++++++++++ pw_interrupt_cortex_a/CMakeLists.txt | 24 ++++++++ pw_interrupt_cortex_a/OWNERS | 2 + pw_interrupt_cortex_a/docs.rst | 11 ++++ .../pw_interrupt_cortex_a/context_inline.h | 42 ++++++++++++++ .../pw_interrupt_backend/context_inline.h | 19 +++++++ 12 files changed, 214 insertions(+) create mode 100644 pw_interrupt_cortex_a/BUILD.bazel create mode 100644 pw_interrupt_cortex_a/BUILD.gn create mode 100644 pw_interrupt_cortex_a/CMakeLists.txt create mode 100644 pw_interrupt_cortex_a/OWNERS create mode 100644 pw_interrupt_cortex_a/docs.rst create mode 100644 pw_interrupt_cortex_a/public/pw_interrupt_cortex_a/context_inline.h create mode 100644 pw_interrupt_cortex_a/public_overrides/pw_interrupt_backend/context_inline.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 234f9ab8b..396103873 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -109,6 +109,7 @@ add_subdirectory(pw_hex_dump EXCLUDE_FROM_ALL) add_subdirectory(pw_hdlc EXCLUDE_FROM_ALL) add_subdirectory(pw_i2c EXCLUDE_FROM_ALL) add_subdirectory(pw_interrupt EXCLUDE_FROM_ALL) +add_subdirectory(pw_interrupt_cortex_a EXCLUDE_FROM_ALL) add_subdirectory(pw_interrupt_cortex_m EXCLUDE_FROM_ALL) add_subdirectory(pw_interrupt_zephyr EXCLUDE_FROM_ALL) add_subdirectory(pw_intrusive_ptr EXCLUDE_FROM_ALL) diff --git a/PIGWEED_MODULES b/PIGWEED_MODULES index 6478d2e7a..0dc1ecd5a 100644 --- a/PIGWEED_MODULES +++ b/PIGWEED_MODULES @@ -80,6 +80,7 @@ pw_i2c_mcuxpresso pw_i2c_rp2040 pw_ide pw_interrupt +pw_interrupt_cortex_a pw_interrupt_cortex_m pw_interrupt_xtensa pw_interrupt_zephyr diff --git a/docs/module_metadata.json b/docs/module_metadata.json index b69dd5d33..a3a479db3 100644 --- a/docs/module_metadata.json +++ b/docs/module_metadata.json @@ -483,6 +483,10 @@ "pw_interrupt": { "status": "unstable" }, + "pw_interrupt_cortex_a": { + "status": "experimental", + "languages": [] + }, "pw_interrupt_cortex_m": { "status": "unstable" }, diff --git a/pw_build/generated_pigweed_modules_lists.gni b/pw_build/generated_pigweed_modules_lists.gni index 343e69066..cb20d1922 100644 --- a/pw_build/generated_pigweed_modules_lists.gni +++ b/pw_build/generated_pigweed_modules_lists.gni @@ -116,6 +116,8 @@ declare_args() { dir_pw_i2c_rp2040 = get_path_info("../pw_i2c_rp2040", "abspath") dir_pw_ide = get_path_info("../pw_ide", "abspath") dir_pw_interrupt = get_path_info("../pw_interrupt", "abspath") + dir_pw_interrupt_cortex_a = + get_path_info("../pw_interrupt_cortex_a", "abspath") dir_pw_interrupt_cortex_m = get_path_info("../pw_interrupt_cortex_m", "abspath") dir_pw_interrupt_xtensa = get_path_info("../pw_interrupt_xtensa", "abspath") @@ -315,6 +317,7 @@ declare_args() { dir_pw_i2c_rp2040, dir_pw_ide, dir_pw_interrupt, + dir_pw_interrupt_cortex_a, dir_pw_interrupt_cortex_m, dir_pw_interrupt_xtensa, dir_pw_interrupt_zephyr, @@ -502,6 +505,7 @@ declare_args() { "$dir_pw_i2c_rp2040:tests", "$dir_pw_ide:tests", "$dir_pw_interrupt:tests", + "$dir_pw_interrupt_cortex_a:tests", "$dir_pw_interrupt_cortex_m:tests", "$dir_pw_interrupt_xtensa:tests", "$dir_pw_interrupt_zephyr:tests", @@ -689,6 +693,7 @@ declare_args() { "$dir_pw_i2c_rp2040:docs", "$dir_pw_ide:docs", "$dir_pw_interrupt:docs", + "$dir_pw_interrupt_cortex_a:docs", "$dir_pw_interrupt_cortex_m:docs", "$dir_pw_interrupt_xtensa:docs", "$dir_pw_interrupt_zephyr:docs", diff --git a/pw_interrupt/backends.rst b/pw_interrupt/backends.rst index cd9c0dbed..77f9ad864 100644 --- a/pw_interrupt/backends.rst +++ b/pw_interrupt/backends.rst @@ -8,6 +8,7 @@ Backends .. toctree:: :maxdepth: 1 + Cortex-A <../pw_interrupt_cortex_a/docs> Cortex-M <../pw_interrupt_cortex_m/docs> Xtensa <../pw_interrupt_xtensa/docs> Zephyr <../pw_interrupt_zephyr/docs> diff --git a/pw_interrupt_cortex_a/BUILD.bazel b/pw_interrupt_cortex_a/BUILD.bazel new file mode 100644 index 000000000..189ea60ba --- /dev/null +++ b/pw_interrupt_cortex_a/BUILD.bazel @@ -0,0 +1,56 @@ +# Copyright 2025 The Pigweed Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may not +# use this file except in compliance with the License. You may obtain a copy of +# the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations under +# the License. + +load("@rules_python//sphinxdocs:sphinx_docs_library.bzl", "sphinx_docs_library") +load("//pw_build:compatibility.bzl", "incompatible_with_mcu") + +package(default_visibility = ["//visibility:public"]) + +licenses(["notice"]) + +constraint_value( + name = "backend", + constraint_setting = "//pw_interrupt:backend_constraint_setting", +) + +cc_library( + name = "context", + hdrs = [ + "public_overrides/pw_interrupt_backend/context_inline.h", + ], + strip_include_prefix = "public_overrides", + target_compatible_with = [":backend"], + deps = [ + ":context_implementation", + "//pw_interrupt:context.facade", + ], +) + +cc_library( + name = "context_implementation", + hdrs = [ + "public/pw_interrupt_cortex_a/context_inline.h", + ], + strip_include_prefix = "public", + visibility = ["//visibility:private"], +) + +sphinx_docs_library( + name = "docs", + srcs = [ + "docs.rst", + ], + prefix = "pw_interrupt_cortex_a/", + target_compatible_with = incompatible_with_mcu(), +) diff --git a/pw_interrupt_cortex_a/BUILD.gn b/pw_interrupt_cortex_a/BUILD.gn new file mode 100644 index 000000000..fcfa814bc --- /dev/null +++ b/pw_interrupt_cortex_a/BUILD.gn @@ -0,0 +1,48 @@ +# Copyright 2025 The Pigweed Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may not +# use this file except in compliance with the License. You may obtain a copy of +# the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations under +# the License. + +import("//build_overrides/pigweed.gni") + +import("$dir_pw_build/target_types.gni") +import("$dir_pw_docgen/docs.gni") +import("$dir_pw_unit_test/test.gni") + +config("public_include_path") { + include_dirs = [ "public" ] + visibility = [ ":*" ] +} + +config("backend_config") { + include_dirs = [ "public_overrides" ] + visibility = [ ":*" ] +} + +pw_source_set("context") { + public_deps = [ "$dir_pw_interrupt:context.facade" ] + public_configs = [ + ":public_include_path", + ":backend_config", + ] + public = [ + "public/pw_interrupt_cortex_a/context_inline.h", + "public_overrides/pw_interrupt_backend/context_inline.h", + ] +} + +pw_doc_group("docs") { + sources = [ "docs.rst" ] +} + +pw_test_group("tests") { +} diff --git a/pw_interrupt_cortex_a/CMakeLists.txt b/pw_interrupt_cortex_a/CMakeLists.txt new file mode 100644 index 000000000..522f2bd54 --- /dev/null +++ b/pw_interrupt_cortex_a/CMakeLists.txt @@ -0,0 +1,24 @@ +# Copyright 2025 The Pigweed Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may not +# use this file except in compliance with the License. You may obtain a copy of +# the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations under +# the License. + +include($ENV{PW_ROOT}/pw_build/pigweed.cmake) + +pw_add_library(pw_interrupt_cortex_a.context INTERFACE + HEADERS + public/pw_interrupt_cortex_a/context_inline.h + public_overrides/pw_interrupt_backend/context_inline.h + PUBLIC_INCLUDES + public + public_overrides +) diff --git a/pw_interrupt_cortex_a/OWNERS b/pw_interrupt_cortex_a/OWNERS new file mode 100644 index 000000000..b266347a4 --- /dev/null +++ b/pw_interrupt_cortex_a/OWNERS @@ -0,0 +1,2 @@ +davidroth@google.com +randyzhg@google.com diff --git a/pw_interrupt_cortex_a/docs.rst b/pw_interrupt_cortex_a/docs.rst new file mode 100644 index 000000000..82a330fa9 --- /dev/null +++ b/pw_interrupt_cortex_a/docs.rst @@ -0,0 +1,11 @@ +.. _module-pw_interrupt_cortex_a: + +--------------------- +pw_interrupt_cortex_a +--------------------- +.. pigweed-module:: + :name: pw_interrupt_cortex_a + +Pigweed's interrupt Cortex-A module provides a set of architecture specific +backends for ``pw_interrupt``. Currently this module only supports processors +that implement the Aarch64 execution state. diff --git a/pw_interrupt_cortex_a/public/pw_interrupt_cortex_a/context_inline.h b/pw_interrupt_cortex_a/public/pw_interrupt_cortex_a/context_inline.h new file mode 100644 index 000000000..6abd1ed02 --- /dev/null +++ b/pw_interrupt_cortex_a/public/pw_interrupt_cortex_a/context_inline.h @@ -0,0 +1,42 @@ +// Copyright 2025 The Pigweed Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may not +// use this file except in compliance with the License. You may obtain a copy of +// the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +// License for the specific language governing permissions and limitations under +// the License. +#pragma once + +#include + +namespace pw::interrupt { + +// This module is not preprocessor protected like pw_interrupt_cortex_m because +// pw_preprocessor/arch.h does not have macros for Arm A-profile architectures. +// And it is not straightforward to add them because of the "cortex_m" +// cc_library. A more ground up refactor of pw_preprocessor is needed. For now, +// leave the responsibility to the user this backend only for Arm A-profile +// architectures. + +#if ((__ARM_ARCH_PROFILE == 'A') && (__ARM_ARCH == 8) && \ + (__ARM_ARCH_ISA_A64 == 1)) +inline bool InInterruptContext() { + // Arm A-profile Architecture Registers describes if the Interrupt Status + // Register (ISR_EL1) is zero if there is no exception (interrupt) being + // processed. + uint32_t isr_el1; + asm volatile("MRS %0, ISR_EL1" : "=r"(isr_el1)); + return isr_el1 != 0; +} +#else +#error "This module is only intended for 64-bit ARMv8-A processors." +#endif // ((__ARM_ARCH_PROFILE == 'A') && (__ARM_ARCH == 8) && + // (__ARM_ARCH_ISA_A64 == 1)) + +} // namespace pw::interrupt diff --git a/pw_interrupt_cortex_a/public_overrides/pw_interrupt_backend/context_inline.h b/pw_interrupt_cortex_a/public_overrides/pw_interrupt_backend/context_inline.h new file mode 100644 index 000000000..a40cfd6cf --- /dev/null +++ b/pw_interrupt_cortex_a/public_overrides/pw_interrupt_backend/context_inline.h @@ -0,0 +1,19 @@ +// Copyright 2025 The Pigweed Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may not +// use this file except in compliance with the License. You may obtain a copy of +// the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +// License for the specific language governing permissions and limitations under +// the License. + +// This override header includes the main tokenized logging header and defines +// the PW_LOG macro as the tokenized logging macro. +#pragma once + +#include "pw_interrupt_cortex_a/context_inline.h"