Skip to content

Commit

Permalink
pw_interrupt_cortex_a: Add pw_interrupt backend for A-profile processors
Browse files Browse the repository at this point in the history
Change-Id: I53b570aab788eb0cde8e14c2342a31b9218938e3
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/261396
Lint: Lint 🤖 <android-build-ayeaye@system.gserviceaccount.com>
Reviewed-by: Dave Roth <davidroth@google.com>
Commit-Queue: Randy Zhang <randyzhg@google.com>
  • Loading branch information
Randy Zhang authored and CQ Bot Account committed Jan 21, 2025
1 parent eb1926a commit e61919c
Show file tree
Hide file tree
Showing 12 changed files with 214 additions and 0 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions PIGWEED_MODULES
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions docs/module_metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,10 @@
"pw_interrupt": {
"status": "unstable"
},
"pw_interrupt_cortex_a": {
"status": "experimental",
"languages": []
},
"pw_interrupt_cortex_m": {
"status": "unstable"
},
Expand Down
5 changes: 5 additions & 0 deletions pw_build/generated_pigweed_modules_lists.gni
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions pw_interrupt/backends.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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>
56 changes: 56 additions & 0 deletions pw_interrupt_cortex_a/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -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(),
)
48 changes: 48 additions & 0 deletions pw_interrupt_cortex_a/BUILD.gn
Original file line number Diff line number Diff line change
@@ -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") {
}
24 changes: 24 additions & 0 deletions pw_interrupt_cortex_a/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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
)
2 changes: 2 additions & 0 deletions pw_interrupt_cortex_a/OWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
davidroth@google.com
randyzhg@google.com
11 changes: 11 additions & 0 deletions pw_interrupt_cortex_a/docs.rst
Original file line number Diff line number Diff line change
@@ -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.
Original file line number Diff line number Diff line change
@@ -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 <cstdint>

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
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit e61919c

Please sign in to comment.