1 /***********************************************************************************************//**
2  * \file cyabs_rtos_internal.h
3  *
4  * \brief
5  * Internal interface used for RTOS abstraction utilities.
6  ***************************************************************************************************
7  * \copyright
8  * Copyright 2018-2021 Cypress Semiconductor Corporation (an Infineon company) or
9  * an affiliate of Cypress Semiconductor Corporation
10  *
11  * SPDX-License-Identifier: Apache-2.0
12  *
13  * Licensed under the Apache License, Version 2.0 (the "License");
14  * you may not use this file except in compliance with the License.
15  * You may obtain a copy of the License at
16  *
17  *     http://www.apache.org/licenses/LICENSE-2.0
18  *
19  * Unless required by applicable law or agreed to in writing, software
20  * distributed under the License is distributed on an "AS IS" BASIS,
21  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22  * See the License for the specific language governing permissions and
23  * limitations under the License.
24  **************************************************************************************************/
25 
26 #pragma once
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
32 #include <stdbool.h>
33 #include <cmsis_compiler.h>
34 
35 /** Checks to see if code is currently executing within an interrupt context.
36  *
37  * @return Boolean indicating whether this was executed from an interrupt context.
38  */
is_in_isr(void)39 static inline bool is_in_isr(void)
40 {
41     #if defined(COMPONENT_CR4) // Can work for any Cortex-A & Cortex-R
42     uint32_t mode = __get_mode();
43     return (mode == 0x11U /*FIQ*/) || (mode == 0x12U /*IRQ*/) || (mode == 0x13U /*SVC*/) ||
44            (mode == 0x17U /*ABT*/) || (mode == 0x1BU /*UND*/);
45     #else // Cortex-M
46     return (__get_IPSR() != 0);
47     #endif
48 }
49 
50 
51 #if defined(__cplusplus)
52 }
53 #endif
54