1 /*
2  * Arm SCP/MCP Software
3  * Copyright (c) 2021-2023, Arm Limited and Contributors. All rights reserved.
4  *
5  * SPDX-License-Identifier: BSD-3-Clause
6  */
7 
8 #ifndef ARCH_HELPERS_H
9 #define ARCH_HELPERS_H
10 
11 #include <fmw_cmsis.h>
12 
13 /*
14  * This variable is used to ensure spurious nested calls won't
15  * enable interrupts. This is been defined in arch_main.c
16  */
17 extern unsigned int critical_section_nest_level;
18 
19 /*!
20  * \brief Enables global CPU interrupts.
21  *
22  * \note inline is necessary as this call can be used in performance sensitive
23  *     path
24  */
arch_interrupts_enable(unsigned int not_used)25 inline static void arch_interrupts_enable(unsigned int not_used)
26 {
27     /* Decrement critical_section_nest_level only if in critical section */
28     if (critical_section_nest_level > 0) {
29         critical_section_nest_level--;
30     }
31 
32     /* Enable interrupts globally if now outside critical section */
33     if (critical_section_nest_level == 0) {
34         __enable_irq();
35     }
36 }
37 
38 /*!
39  * \brief Disables global CPU interrupts.
40 
41  * \note inline is necessary as this call can be used in performance sensitive
42  *     path
43  */
arch_interrupts_disable(void)44 inline static unsigned int arch_interrupts_disable(void)
45 {
46     __disable_irq();
47     critical_section_nest_level++;
48 
49     return 0;
50 }
51 
52 /*!
53  * \brief Suspend execution of current CPU.
54 
55  * \note CPU will be woken up by receiving interrupts.
56  *
57  */
arch_suspend(void)58 inline static void arch_suspend(void)
59 {
60     __asm volatile("wfe");
61 }
62 
63 #endif /* ARCH_HELPERS_H */
64