1 /***********************************************************************************************//**
2  * \file cyabs_rtos_internal.h
3  *
4  * \brief
5  * Internal interface used for RTOS abstraction utilities.
6  ***************************************************************************************************
7  * \copyright
8  * Copyright 2018-2022 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 #if !defined (COMPONENT_CAT5)
34 #include <cmsis_compiler.h>
35 #endif
36 
37 /** Checks to see if code is currently executing within an interrupt context.
38  *
39  * @return Boolean indicating whether this was executed from an interrupt context.
40  */
is_in_isr(void)41 static inline bool is_in_isr(void)
42 {
43     #if defined(COMPONENT_CR4) // Can work for any Cortex-A & Cortex-R
44     uint32_t mode = __get_mode();
45     return (mode == 0x11U /*FIQ*/) || (mode == 0x12U /*IRQ*/) || (mode == 0x13U /*SVC*/) ||
46            (mode == 0x17U /*ABT*/) || (mode == 0x1BU /*UND*/);
47     #elif defined(COMPONENT_CAT5)
48     // This device does not allow calling from interrupt context.
49     return false;
50     #else // Cortex-M
51     return (__get_IPSR() != 0);
52     #endif
53 }
54 
55 
56 #if defined(__cplusplus)
57 }
58 #endif
59