blob: 8d25f14d4f8af751c14d8b9acae94f5cca92b5ed [file] [log] [blame]
// 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
// 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>
#include "pw_preprocessor/arch.h"
namespace pw::interrupt {
#error You can only build this for ARM Cortex-M architectures. If you are \
trying to do this and are still seeing this error, see \
#endif // !_PW_ARCH_ARM_CORTEX_M
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;
#error "Your selected ARM Cortex-M arch is not yet supported by this module."
} // namespace pw::interrupt