forked from google/pigweed
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pw_interrupt: Adds a basic interrupt module
Adds a basic interrupt module which for now only gives you the ability to determine if you're executing in an interrupt context. In addition this also adds the first two backends of this module's context facade (pw_interrupt_cortex_m:context_{armv7m,armv8m}). Change-Id: If0056997f814b0ac33cb0209fc9b247c2599594e Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/24421 Commit-Queue: Ewout van Bekkum <[email protected]> Reviewed-by: Keir Mierle <[email protected]> Reviewed-by: Armando Montanez <[email protected]>
- Loading branch information
Ewout van Bekkum
authored and
CQ Bot Account
committed
Dec 1, 2020
1 parent
9618d8a
commit bd4906c
Showing
11 changed files
with
323 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# Copyright 2020 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( | ||
"//pw_build:pigweed.bzl", | ||
"pw_cc_library", | ||
) | ||
|
||
package(default_visibility = ["//visibility:public"]) | ||
|
||
licenses(["notice"]) # Apache License 2.0 | ||
|
||
# TODO(pwbug/101): Need to add support for facades/backends to Bazel. | ||
PW_INTERRUPT_CONTEXT_BACKEND = "//pw_interrupt_context_cortex_m:context_armv7m" | ||
|
||
pw_cc_library( | ||
name = "context_facade", | ||
hdrs = [ | ||
"public/pw_interrupt/context.h", | ||
], | ||
includes = ["public"], | ||
srcs = [ | ||
"context.cc" | ||
], | ||
deps = [ | ||
PW_INTERRUPT_CONTEXT_BACKEND + "_headers", | ||
], | ||
) | ||
|
||
pw_cc_library( | ||
name = "context", | ||
deps = [ | ||
":context_facade", | ||
PW_INTERRUPT_CONTEXT_BACKEND + "_headers", | ||
], | ||
) | ||
|
||
pw_cc_library( | ||
name = "context_backend", | ||
deps = [ | ||
PW_INTERRUPT_CONTEXT_BACKEND, | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Copyright 2020 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/facade.gni") | ||
import("$dir_pw_docgen/docs.gni") | ||
import("$dir_pw_unit_test/test.gni") | ||
|
||
declare_args() { | ||
# Backend for the pw_interrupt module. | ||
pw_interrupt_CONTEXT_BACKEND = "" | ||
} | ||
|
||
config("public_include_path") { | ||
include_dirs = [ "public" ] | ||
visibility = [ ":*" ] | ||
} | ||
|
||
pw_facade("context") { | ||
backend = pw_interrupt_CONTEXT_BACKEND | ||
public_configs = [ ":public_include_path" ] | ||
public = [ "public/pw_interrupt/context.h" ] | ||
} | ||
|
||
pw_doc_group("docs") { | ||
sources = [ "docs.rst" ] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
.. _module-pw_interrupt: | ||
|
||
------------ | ||
pw_interrupt | ||
------------ | ||
Pigweed's interrupt module provides a consistent interface for to determine | ||
whether one is currently executing in an interrupt context (IRQ or NMI) or not. | ||
|
||
.. c:function:: bool InInterruptContext() | ||
Returns true if currently executing within an interrupt service routine | ||
handling an IRQ or NMI.:w! | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Copyright 2020 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 "pw_interrupt_backend/context_backend.h" | ||
|
||
namespace pw::interrupt { | ||
|
||
// Returns true if currently executing within an interrupt service routine | ||
// handling an IRQ or NMI. | ||
bool InInterruptContext(); | ||
|
||
} // namespace pw::interrupt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# Copyright 2020 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( | ||
"//pw_build:pigweed.bzl", | ||
"pw_cc_library", | ||
) | ||
|
||
package(default_visibility = ["//visibility:public"]) | ||
|
||
licenses(["notice"]) # Apache License 2.0 | ||
|
||
pw_cc_library( | ||
name = "context_armv7m_headers", | ||
hdrs = [ | ||
"public/pw_interrupt_cortex_m/context.h", | ||
"public_overrides/pw_interrupt_backend/context_backend.h", | ||
], | ||
copts = [ "-DPW_INTERRUPT_CORTEX_M_ARMV7M=1" ], | ||
includes = [ | ||
"public", | ||
"public_overrides", | ||
], | ||
) | ||
|
||
pw_cc_library( | ||
name = "context_armv7m", | ||
copts = [ "-DPW_INTERRUPT_CORTEX_M_ARMV7M=1" ], | ||
deps = [ | ||
":context_armv7m_headers", | ||
"//pw_interrupt:context_facade", | ||
], | ||
) | ||
|
||
pw_cc_library( | ||
name = "context_armv8m_headers", | ||
hdrs = [ | ||
"public/pw_interrupt_cortex_m/context.h", | ||
"public_overrides/pw_interrupt_backend/context_backend.h", | ||
], | ||
copts = [ "-DPW_INTERRUPT_CORTEX_M_ARMV8M=1" ], | ||
includes = [ | ||
"public", | ||
"public_overrides", | ||
], | ||
) | ||
|
||
pw_cc_library( | ||
name = "context_armv8m", | ||
copts = [ "-DPW_INTERRUPT_CORTEX_M_ARMV8M=1" ], | ||
deps = [ | ||
":context_armv8m_headers", | ||
"//pw_interrupt:context_facade", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# Copyright 2020 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") | ||
|
||
config("public_include_path") { | ||
include_dirs = [ "public" ] | ||
visibility = [ ":*" ] | ||
} | ||
|
||
config("backend_config") { | ||
include_dirs = [ "public_overrides" ] | ||
visibility = [ ":*" ] | ||
} | ||
|
||
config("armv7m") { | ||
defines = [ "PW_INTERRUPT_CORTEX_M_ARMV7M=1" ] | ||
} | ||
|
||
config("armv8m") { | ||
defines = [ "PW_INTERRUPT_CORTEX_M_ARMV8M=1" ] | ||
} | ||
|
||
_context_common = { | ||
public_deps = [ "$dir_pw_interrupt:context.facade" ] | ||
public_configs = [ | ||
":public_include_path", | ||
":backend_config", | ||
] | ||
public = [ | ||
"public/pw_interrupt_cortex_m/context.h", | ||
"public_overrides/pw_interrupt_backend/context_backend.h", | ||
] | ||
} | ||
|
||
# This targets provides the ARMv7-M backend for pw_interrupt's context facade. | ||
pw_source_set("context_armv7m") { | ||
forward_variables_from(_context_common, "*") | ||
public_configs += [ ":armv7m" ] | ||
} | ||
|
||
# This targets provides the ARMv8-M backend for pw_interrupt's context facade. | ||
pw_source_set("context_armv8m") { | ||
forward_variables_from(_context_common, "*") | ||
public_configs += [ ":armv8m" ] | ||
} | ||
|
||
pw_doc_group("docs") { | ||
sources = [ "docs.rst" ] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
.. _module-pw_interrupt_cortex_m: | ||
|
||
--------------------- | ||
pw_interrupt_cortex_m | ||
--------------------- | ||
Pigweed's interrupt Cortex-M module provides a set of architecture specific | ||
backends for ``pw_interrupt``. |
34 changes: 34 additions & 0 deletions
34
pw_interrupt_cortex_m/public/pw_interrupt_cortex_m/context.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Copyright 2020 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 | ||
|
||
namespace pw::interrupt { | ||
|
||
#include <cstdint> | ||
|
||
#if defined(PW_INTERRUPT_CORTEX_M_ARMV7M) || \ | ||
defined(PW_INTERRUPT_CORTEX_M_ARMV8M) | ||
inline bool InInterruptContext() { | ||
// ARMv7M Reference manual section B1.4.2 describes how the Interrupt | ||
// Program Status Register (IPSR) is zero if there is no exception (interrupt) | ||
// being processed. | ||
uint32_t ipsr; | ||
asm volatile("MRS %0, ipsr" : "=r"(ipsr)); | ||
return ipsr != 0; | ||
} | ||
#else | ||
#error "Please select an architecture specific backend." | ||
#endif | ||
|
||
} // namespace pw::interrupt |
19 changes: 19 additions & 0 deletions
19
pw_interrupt_cortex_m/public_overrides/pw_interrupt_backend/context_backend.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Copyright 2020 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_m/context.h" |