The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.
Dependents: hello SerialTestv11 SerialTestv12 Sierpinski ... more
mbed 2
This is the mbed 2 library. If you'd like to learn about Mbed OS please see the mbed-os docs.
TARGET_SDT51822B/TOOLCHAIN_IAR/nrf_nvic.h@171:3a7713b1edbc, 2018-11-08 (annotated)
- Committer:
- AnnaBridge
- Date:
- Thu Nov 08 11:45:42 2018 +0000
- Revision:
- 171:3a7713b1edbc
- Parent:
- TARGET_VBLUNO51/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF51/TARGET_MCU_NRF51822_UNIFIED/sdk/softdevice/s130/headers/nrf_nvic.h@169:a7c7b631e539
mbed library. Release version 164
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
AnnaBridge | 146:22da6e220af6 | 1 | /* |
AnnaBridge | 146:22da6e220af6 | 2 | * Copyright (c) 2000 Nordic Semiconductor ASA |
AnnaBridge | 146:22da6e220af6 | 3 | * All rights reserved. |
AnnaBridge | 146:22da6e220af6 | 4 | * |
AnnaBridge | 146:22da6e220af6 | 5 | * Redistribution and use in source and binary forms, with or without modification, |
AnnaBridge | 146:22da6e220af6 | 6 | * are permitted provided that the following conditions are met: |
AnnaBridge | 146:22da6e220af6 | 7 | * |
AnnaBridge | 146:22da6e220af6 | 8 | * 1. Redistributions of source code must retain the above copyright notice, this list |
AnnaBridge | 146:22da6e220af6 | 9 | * of conditions and the following disclaimer. |
AnnaBridge | 146:22da6e220af6 | 10 | * |
AnnaBridge | 146:22da6e220af6 | 11 | * 2. Redistributions in binary form, except as embedded into a Nordic Semiconductor ASA |
AnnaBridge | 146:22da6e220af6 | 12 | * integrated circuit in a product or a software update for such product, must reproduce |
AnnaBridge | 146:22da6e220af6 | 13 | * the above copyright notice, this list of conditions and the following disclaimer in |
AnnaBridge | 146:22da6e220af6 | 14 | * the documentation and/or other materials provided with the distribution. |
AnnaBridge | 146:22da6e220af6 | 15 | * |
AnnaBridge | 146:22da6e220af6 | 16 | * 3. Neither the name of Nordic Semiconductor ASA nor the names of its contributors may be |
AnnaBridge | 146:22da6e220af6 | 17 | * used to endorse or promote products derived from this software without specific prior |
AnnaBridge | 146:22da6e220af6 | 18 | * written permission. |
AnnaBridge | 146:22da6e220af6 | 19 | * |
AnnaBridge | 146:22da6e220af6 | 20 | * 4. This software, with or without modification, must only be used with a |
AnnaBridge | 146:22da6e220af6 | 21 | * Nordic Semiconductor ASA integrated circuit. |
AnnaBridge | 146:22da6e220af6 | 22 | * |
AnnaBridge | 146:22da6e220af6 | 23 | * 5. Any software provided in binary or object form under this license must not be reverse |
AnnaBridge | 146:22da6e220af6 | 24 | * engineered, decompiled, modified and/or disassembled. |
AnnaBridge | 146:22da6e220af6 | 25 | * |
AnnaBridge | 146:22da6e220af6 | 26 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
AnnaBridge | 146:22da6e220af6 | 27 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
AnnaBridge | 146:22da6e220af6 | 28 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
AnnaBridge | 146:22da6e220af6 | 29 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR |
AnnaBridge | 146:22da6e220af6 | 30 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
AnnaBridge | 146:22da6e220af6 | 31 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
AnnaBridge | 146:22da6e220af6 | 32 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON |
AnnaBridge | 146:22da6e220af6 | 33 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
AnnaBridge | 146:22da6e220af6 | 34 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
AnnaBridge | 146:22da6e220af6 | 35 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
AnnaBridge | 146:22da6e220af6 | 36 | * |
AnnaBridge | 146:22da6e220af6 | 37 | */ |
AnnaBridge | 146:22da6e220af6 | 38 | |
AnnaBridge | 146:22da6e220af6 | 39 | /** |
AnnaBridge | 146:22da6e220af6 | 40 | * @defgroup nrf_nvic_api SoftDevice NVIC API |
AnnaBridge | 146:22da6e220af6 | 41 | * @{ |
AnnaBridge | 146:22da6e220af6 | 42 | * |
AnnaBridge | 146:22da6e220af6 | 43 | * @note In order to use this module, the following code has to be added to a .c file: |
AnnaBridge | 146:22da6e220af6 | 44 | * \code |
AnnaBridge | 146:22da6e220af6 | 45 | * nrf_nvic_state_t nrf_nvic_state; |
AnnaBridge | 146:22da6e220af6 | 46 | * \endcode |
AnnaBridge | 146:22da6e220af6 | 47 | * |
AnnaBridge | 146:22da6e220af6 | 48 | * @note Definitions and declarations starting with __ (double underscore) in this header file are |
AnnaBridge | 146:22da6e220af6 | 49 | * not intended for direct use by the application. |
AnnaBridge | 146:22da6e220af6 | 50 | * |
AnnaBridge | 146:22da6e220af6 | 51 | * @brief APIs for the accessing NVIC when using a SoftDevice. |
AnnaBridge | 146:22da6e220af6 | 52 | * |
AnnaBridge | 146:22da6e220af6 | 53 | */ |
AnnaBridge | 146:22da6e220af6 | 54 | |
AnnaBridge | 146:22da6e220af6 | 55 | #ifndef NRF_NVIC_H__ |
AnnaBridge | 146:22da6e220af6 | 56 | #define NRF_NVIC_H__ |
AnnaBridge | 146:22da6e220af6 | 57 | |
AnnaBridge | 146:22da6e220af6 | 58 | #include <stdint.h> |
AnnaBridge | 146:22da6e220af6 | 59 | #include "nrf.h" |
AnnaBridge | 146:22da6e220af6 | 60 | |
AnnaBridge | 146:22da6e220af6 | 61 | #include "nrf_error_soc.h" |
AnnaBridge | 146:22da6e220af6 | 62 | |
AnnaBridge | 146:22da6e220af6 | 63 | #ifdef __cplusplus |
AnnaBridge | 146:22da6e220af6 | 64 | extern "C" { |
AnnaBridge | 146:22da6e220af6 | 65 | #endif |
AnnaBridge | 146:22da6e220af6 | 66 | |
AnnaBridge | 146:22da6e220af6 | 67 | /**@addtogroup NRF_NVIC_DEFINES Defines |
AnnaBridge | 146:22da6e220af6 | 68 | * @{ */ |
AnnaBridge | 146:22da6e220af6 | 69 | |
AnnaBridge | 146:22da6e220af6 | 70 | /**@defgroup NRF_NVIC_ISER_DEFINES SoftDevice NVIC internal definitions |
AnnaBridge | 146:22da6e220af6 | 71 | * @{ */ |
AnnaBridge | 146:22da6e220af6 | 72 | |
AnnaBridge | 146:22da6e220af6 | 73 | #define __NRF_NVIC_NVMC_IRQn (30) /**< The peripheral ID of the NVMC. IRQ numbers are used to identify peripherals, but the NVMC doesn't have an IRQ number in the MDK. */ |
AnnaBridge | 146:22da6e220af6 | 74 | |
AnnaBridge | 146:22da6e220af6 | 75 | #ifdef NRF51 |
AnnaBridge | 146:22da6e220af6 | 76 | #define __NRF_NVIC_ISER_COUNT (1) /**< The number of ISER/ICER registers in the NVIC that are used. */ |
AnnaBridge | 146:22da6e220af6 | 77 | |
AnnaBridge | 146:22da6e220af6 | 78 | /**@brief Interrupts used by the SoftDevice. */ |
AnnaBridge | 146:22da6e220af6 | 79 | #define __NRF_NVIC_SD_IRQS_0 ((uint32_t)( \ |
AnnaBridge | 146:22da6e220af6 | 80 | (1U << POWER_CLOCK_IRQn) \ |
AnnaBridge | 146:22da6e220af6 | 81 | | (1U << RADIO_IRQn) \ |
AnnaBridge | 146:22da6e220af6 | 82 | | (1U << RTC0_IRQn) \ |
AnnaBridge | 146:22da6e220af6 | 83 | | (1U << TIMER0_IRQn) \ |
AnnaBridge | 146:22da6e220af6 | 84 | | (1U << RNG_IRQn) \ |
AnnaBridge | 146:22da6e220af6 | 85 | | (1U << ECB_IRQn) \ |
AnnaBridge | 146:22da6e220af6 | 86 | | (1U << CCM_AAR_IRQn) \ |
AnnaBridge | 146:22da6e220af6 | 87 | | (1U << TEMP_IRQn) \ |
AnnaBridge | 146:22da6e220af6 | 88 | | (1U << __NRF_NVIC_NVMC_IRQn) \ |
AnnaBridge | 146:22da6e220af6 | 89 | | (1U << (uint32_t)SWI4_IRQn) \ |
AnnaBridge | 146:22da6e220af6 | 90 | | (1U << (uint32_t)SWI5_IRQn) \ |
AnnaBridge | 146:22da6e220af6 | 91 | )) |
AnnaBridge | 146:22da6e220af6 | 92 | |
AnnaBridge | 146:22da6e220af6 | 93 | /**@brief Interrupts available for to application. */ |
AnnaBridge | 146:22da6e220af6 | 94 | #define __NRF_NVIC_APP_IRQS_0 (~__NRF_NVIC_SD_IRQS_0) |
AnnaBridge | 146:22da6e220af6 | 95 | #endif |
AnnaBridge | 146:22da6e220af6 | 96 | |
AnnaBridge | 146:22da6e220af6 | 97 | #ifdef NRF52 |
AnnaBridge | 146:22da6e220af6 | 98 | #define __NRF_NVIC_ISER_COUNT (2) /**< The number of ISER/ICER registers in the NVIC that are used. */ |
AnnaBridge | 146:22da6e220af6 | 99 | |
AnnaBridge | 146:22da6e220af6 | 100 | /**@brief Interrupts used by the SoftDevice. */ |
AnnaBridge | 146:22da6e220af6 | 101 | #define __NRF_NVIC_SD_IRQS_0 ((uint32_t)( \ |
AnnaBridge | 146:22da6e220af6 | 102 | (1U << POWER_CLOCK_IRQn) \ |
AnnaBridge | 146:22da6e220af6 | 103 | | (1U << RADIO_IRQn) \ |
AnnaBridge | 146:22da6e220af6 | 104 | | (1U << RTC0_IRQn) \ |
AnnaBridge | 146:22da6e220af6 | 105 | | (1U << TIMER0_IRQn) \ |
AnnaBridge | 146:22da6e220af6 | 106 | | (1U << RNG_IRQn) \ |
AnnaBridge | 146:22da6e220af6 | 107 | | (1U << ECB_IRQn) \ |
AnnaBridge | 146:22da6e220af6 | 108 | | (1U << CCM_AAR_IRQn) \ |
AnnaBridge | 146:22da6e220af6 | 109 | | (1U << TEMP_IRQn) \ |
AnnaBridge | 146:22da6e220af6 | 110 | | (1U << __NRF_NVIC_NVMC_IRQn) \ |
AnnaBridge | 146:22da6e220af6 | 111 | | (1U << (uint32_t)SWI4_EGU4_IRQn) \ |
AnnaBridge | 146:22da6e220af6 | 112 | | (1U << (uint32_t)SWI5_EGU5_IRQn) \ |
AnnaBridge | 146:22da6e220af6 | 113 | )) |
AnnaBridge | 146:22da6e220af6 | 114 | #define __NRF_NVIC_SD_IRQS_1 ((uint32_t)0) |
AnnaBridge | 146:22da6e220af6 | 115 | |
AnnaBridge | 146:22da6e220af6 | 116 | /**@brief Interrupts available for to application. */ |
AnnaBridge | 146:22da6e220af6 | 117 | #define __NRF_NVIC_APP_IRQS_0 (~__NRF_NVIC_SD_IRQS_0) |
AnnaBridge | 146:22da6e220af6 | 118 | #define __NRF_NVIC_APP_IRQS_1 (~__NRF_NVIC_SD_IRQS_1) |
AnnaBridge | 146:22da6e220af6 | 119 | #endif |
AnnaBridge | 146:22da6e220af6 | 120 | /**@} */ |
AnnaBridge | 146:22da6e220af6 | 121 | |
AnnaBridge | 146:22da6e220af6 | 122 | /**@} */ |
AnnaBridge | 146:22da6e220af6 | 123 | |
AnnaBridge | 146:22da6e220af6 | 124 | /**@addtogroup NRF_NVIC_VARIABLES Variables |
AnnaBridge | 146:22da6e220af6 | 125 | * @{ */ |
AnnaBridge | 146:22da6e220af6 | 126 | |
AnnaBridge | 146:22da6e220af6 | 127 | /**@brief Type representing the state struct for the SoftDevice NVIC module. */ |
AnnaBridge | 146:22da6e220af6 | 128 | typedef struct |
AnnaBridge | 146:22da6e220af6 | 129 | { |
AnnaBridge | 146:22da6e220af6 | 130 | uint32_t volatile __irq_masks[__NRF_NVIC_ISER_COUNT]; /**< IRQs enabled by the application in the NVIC. */ |
AnnaBridge | 146:22da6e220af6 | 131 | uint32_t volatile __cr_flag; /**< Non-zero if already in a critical region */ |
AnnaBridge | 146:22da6e220af6 | 132 | } nrf_nvic_state_t; |
AnnaBridge | 146:22da6e220af6 | 133 | |
AnnaBridge | 146:22da6e220af6 | 134 | /**@brief Variable keeping the state for the SoftDevice NVIC module. This must be declared in an |
AnnaBridge | 146:22da6e220af6 | 135 | * application source file. */ |
AnnaBridge | 146:22da6e220af6 | 136 | extern nrf_nvic_state_t nrf_nvic_state; |
AnnaBridge | 146:22da6e220af6 | 137 | |
AnnaBridge | 146:22da6e220af6 | 138 | /**@} */ |
AnnaBridge | 146:22da6e220af6 | 139 | |
AnnaBridge | 146:22da6e220af6 | 140 | /**@addtogroup NRF_NVIC_INTERNAL_FUNCTIONS SoftDevice NVIC internal functions |
AnnaBridge | 146:22da6e220af6 | 141 | * @{ */ |
AnnaBridge | 146:22da6e220af6 | 142 | |
AnnaBridge | 146:22da6e220af6 | 143 | /**@brief Disables IRQ interrupts globally, including the SoftDevice's interrupts. |
AnnaBridge | 146:22da6e220af6 | 144 | * |
AnnaBridge | 146:22da6e220af6 | 145 | * @retval The value of PRIMASK prior to disabling the interrupts. |
AnnaBridge | 146:22da6e220af6 | 146 | */ |
AnnaBridge | 146:22da6e220af6 | 147 | static inline int __sd_nvic_irq_disable(void) |
AnnaBridge | 146:22da6e220af6 | 148 | { |
AnnaBridge | 146:22da6e220af6 | 149 | int pm = __get_PRIMASK(); |
AnnaBridge | 146:22da6e220af6 | 150 | __disable_irq(); |
AnnaBridge | 146:22da6e220af6 | 151 | return pm; |
AnnaBridge | 146:22da6e220af6 | 152 | } |
AnnaBridge | 146:22da6e220af6 | 153 | |
AnnaBridge | 146:22da6e220af6 | 154 | /**@brief Enables IRQ interrupts globally, including the SoftDevice's interrupts. |
AnnaBridge | 146:22da6e220af6 | 155 | */ |
AnnaBridge | 146:22da6e220af6 | 156 | static inline void __sd_nvic_irq_enable(void) |
AnnaBridge | 146:22da6e220af6 | 157 | { |
AnnaBridge | 146:22da6e220af6 | 158 | __enable_irq(); |
AnnaBridge | 146:22da6e220af6 | 159 | } |
AnnaBridge | 146:22da6e220af6 | 160 | |
AnnaBridge | 146:22da6e220af6 | 161 | /**@brief Checks if IRQn is available to application |
AnnaBridge | 146:22da6e220af6 | 162 | * @param[in] IRQn irq to check |
AnnaBridge | 146:22da6e220af6 | 163 | * |
AnnaBridge | 146:22da6e220af6 | 164 | * @retval 1 (true) if the irq to check is available to the application |
AnnaBridge | 146:22da6e220af6 | 165 | */ |
AnnaBridge | 146:22da6e220af6 | 166 | static inline uint32_t __sd_nvic_app_accessible_irq(IRQn_Type IRQn) |
AnnaBridge | 146:22da6e220af6 | 167 | { |
AnnaBridge | 146:22da6e220af6 | 168 | if (IRQn < 32) |
AnnaBridge | 146:22da6e220af6 | 169 | { |
AnnaBridge | 146:22da6e220af6 | 170 | return ((1UL<<IRQn) & __NRF_NVIC_APP_IRQS_0) != 0; |
AnnaBridge | 146:22da6e220af6 | 171 | } |
AnnaBridge | 146:22da6e220af6 | 172 | #ifdef NRF52 |
AnnaBridge | 146:22da6e220af6 | 173 | else if (IRQn < 64) |
AnnaBridge | 146:22da6e220af6 | 174 | { |
AnnaBridge | 146:22da6e220af6 | 175 | return ((1UL<<(IRQn-32)) & __NRF_NVIC_APP_IRQS_1) != 0; |
AnnaBridge | 146:22da6e220af6 | 176 | } |
AnnaBridge | 146:22da6e220af6 | 177 | #endif |
AnnaBridge | 146:22da6e220af6 | 178 | else |
AnnaBridge | 146:22da6e220af6 | 179 | { |
AnnaBridge | 146:22da6e220af6 | 180 | return 1; |
AnnaBridge | 146:22da6e220af6 | 181 | } |
AnnaBridge | 146:22da6e220af6 | 182 | } |
AnnaBridge | 146:22da6e220af6 | 183 | |
AnnaBridge | 146:22da6e220af6 | 184 | /**@brief Checks if IRQn is available to application |
AnnaBridge | 146:22da6e220af6 | 185 | * @param[in] priority priority to check |
AnnaBridge | 146:22da6e220af6 | 186 | * |
AnnaBridge | 146:22da6e220af6 | 187 | * @retval 1 (true) if the priority to check is available to the application |
AnnaBridge | 146:22da6e220af6 | 188 | */ |
AnnaBridge | 146:22da6e220af6 | 189 | static inline uint32_t __sd_nvic_is_app_accessible_priority(uint32_t priority) |
AnnaBridge | 146:22da6e220af6 | 190 | { |
AnnaBridge | 146:22da6e220af6 | 191 | if(priority >= (1 << __NVIC_PRIO_BITS)) |
AnnaBridge | 146:22da6e220af6 | 192 | { |
AnnaBridge | 146:22da6e220af6 | 193 | return 0; |
AnnaBridge | 146:22da6e220af6 | 194 | } |
AnnaBridge | 146:22da6e220af6 | 195 | #ifdef NRF51 |
AnnaBridge | 146:22da6e220af6 | 196 | if( priority == 0 |
AnnaBridge | 146:22da6e220af6 | 197 | || priority == 2 |
AnnaBridge | 146:22da6e220af6 | 198 | ) |
AnnaBridge | 146:22da6e220af6 | 199 | { |
AnnaBridge | 146:22da6e220af6 | 200 | return 0; |
AnnaBridge | 146:22da6e220af6 | 201 | } |
AnnaBridge | 146:22da6e220af6 | 202 | #endif |
AnnaBridge | 146:22da6e220af6 | 203 | #ifdef NRF52 |
AnnaBridge | 146:22da6e220af6 | 204 | if( priority == 0 |
AnnaBridge | 146:22da6e220af6 | 205 | || priority == 1 |
AnnaBridge | 146:22da6e220af6 | 206 | || priority == 4 |
AnnaBridge | 146:22da6e220af6 | 207 | || priority == 5 |
AnnaBridge | 146:22da6e220af6 | 208 | ) |
AnnaBridge | 146:22da6e220af6 | 209 | { |
AnnaBridge | 146:22da6e220af6 | 210 | return 0; |
AnnaBridge | 146:22da6e220af6 | 211 | } |
AnnaBridge | 146:22da6e220af6 | 212 | #endif |
AnnaBridge | 146:22da6e220af6 | 213 | return 1; |
AnnaBridge | 146:22da6e220af6 | 214 | } |
AnnaBridge | 146:22da6e220af6 | 215 | |
AnnaBridge | 146:22da6e220af6 | 216 | /**@} */ |
AnnaBridge | 146:22da6e220af6 | 217 | |
AnnaBridge | 146:22da6e220af6 | 218 | /**@addtogroup NRF_NVIC_FUNCTIONS SoftDevice NVIC public functions |
AnnaBridge | 146:22da6e220af6 | 219 | * @{ */ |
AnnaBridge | 146:22da6e220af6 | 220 | |
AnnaBridge | 146:22da6e220af6 | 221 | /**@brief Enable External Interrupt. |
AnnaBridge | 146:22da6e220af6 | 222 | * @note Corresponds to NVIC_EnableIRQ in CMSIS. |
AnnaBridge | 146:22da6e220af6 | 223 | * |
AnnaBridge | 146:22da6e220af6 | 224 | * @pre IRQn is valid and not reserved by the stack. |
AnnaBridge | 146:22da6e220af6 | 225 | * |
AnnaBridge | 146:22da6e220af6 | 226 | * @param[in] IRQn See the NVIC_EnableIRQ documentation in CMSIS. |
AnnaBridge | 146:22da6e220af6 | 227 | * |
AnnaBridge | 146:22da6e220af6 | 228 | * @retval ::NRF_SUCCESS The interrupt was enabled. |
AnnaBridge | 146:22da6e220af6 | 229 | * @retval ::NRF_ERROR_SOC_NVIC_INTERRUPT_NOT_AVAILABLE The interrupt is not available for the application. |
AnnaBridge | 146:22da6e220af6 | 230 | * @retval ::NRF_ERROR_SOC_NVIC_INTERRUPT_PRIORITY_NOT_ALLOWED The interrupt has a priority not available for the application. |
AnnaBridge | 146:22da6e220af6 | 231 | */ |
AnnaBridge | 146:22da6e220af6 | 232 | static inline uint32_t sd_nvic_EnableIRQ(IRQn_Type IRQn) |
AnnaBridge | 146:22da6e220af6 | 233 | { |
AnnaBridge | 146:22da6e220af6 | 234 | if (!__sd_nvic_app_accessible_irq(IRQn)) |
AnnaBridge | 146:22da6e220af6 | 235 | { |
AnnaBridge | 146:22da6e220af6 | 236 | return NRF_ERROR_SOC_NVIC_INTERRUPT_NOT_AVAILABLE; |
AnnaBridge | 146:22da6e220af6 | 237 | } |
AnnaBridge | 146:22da6e220af6 | 238 | if (!__sd_nvic_is_app_accessible_priority(NVIC_GetPriority(IRQn))) |
AnnaBridge | 146:22da6e220af6 | 239 | { |
AnnaBridge | 146:22da6e220af6 | 240 | return NRF_ERROR_SOC_NVIC_INTERRUPT_PRIORITY_NOT_ALLOWED; |
AnnaBridge | 146:22da6e220af6 | 241 | } |
AnnaBridge | 146:22da6e220af6 | 242 | |
AnnaBridge | 146:22da6e220af6 | 243 | if (nrf_nvic_state.__cr_flag) |
AnnaBridge | 146:22da6e220af6 | 244 | { |
AnnaBridge | 146:22da6e220af6 | 245 | nrf_nvic_state.__irq_masks[(uint32_t)((int32_t)IRQn) >> 5] |= (uint32_t)(1 << ((uint32_t)((int32_t)IRQn) & (uint32_t)0x1F)); |
AnnaBridge | 146:22da6e220af6 | 246 | } |
AnnaBridge | 146:22da6e220af6 | 247 | else |
AnnaBridge | 146:22da6e220af6 | 248 | { |
AnnaBridge | 146:22da6e220af6 | 249 | NVIC_EnableIRQ(IRQn); |
AnnaBridge | 146:22da6e220af6 | 250 | } |
AnnaBridge | 146:22da6e220af6 | 251 | return NRF_SUCCESS; |
AnnaBridge | 146:22da6e220af6 | 252 | } |
AnnaBridge | 146:22da6e220af6 | 253 | |
AnnaBridge | 146:22da6e220af6 | 254 | /**@brief Disable External Interrupt. |
AnnaBridge | 146:22da6e220af6 | 255 | * @note Corresponds to NVIC_DisableIRQ in CMSIS. |
AnnaBridge | 146:22da6e220af6 | 256 | * |
AnnaBridge | 146:22da6e220af6 | 257 | * @pre IRQn is valid and not reserved by the stack. |
AnnaBridge | 146:22da6e220af6 | 258 | * |
AnnaBridge | 146:22da6e220af6 | 259 | * @param[in] IRQn See the NVIC_DisableIRQ documentation in CMSIS. |
AnnaBridge | 146:22da6e220af6 | 260 | * |
AnnaBridge | 146:22da6e220af6 | 261 | * @retval ::NRF_SUCCESS The interrupt was disabled. |
AnnaBridge | 146:22da6e220af6 | 262 | * @retval ::NRF_ERROR_SOC_NVIC_INTERRUPT_NOT_AVAILABLE The interrupt is not available for the application. |
AnnaBridge | 146:22da6e220af6 | 263 | */ |
AnnaBridge | 146:22da6e220af6 | 264 | static inline uint32_t sd_nvic_DisableIRQ(IRQn_Type IRQn) |
AnnaBridge | 146:22da6e220af6 | 265 | { |
AnnaBridge | 146:22da6e220af6 | 266 | if (!__sd_nvic_app_accessible_irq(IRQn)) |
AnnaBridge | 146:22da6e220af6 | 267 | { |
AnnaBridge | 146:22da6e220af6 | 268 | return NRF_ERROR_SOC_NVIC_INTERRUPT_NOT_AVAILABLE; |
AnnaBridge | 146:22da6e220af6 | 269 | } |
AnnaBridge | 146:22da6e220af6 | 270 | |
AnnaBridge | 146:22da6e220af6 | 271 | if (nrf_nvic_state.__cr_flag) |
AnnaBridge | 146:22da6e220af6 | 272 | { |
AnnaBridge | 146:22da6e220af6 | 273 | nrf_nvic_state.__irq_masks[(uint32_t)((int32_t)IRQn) >> 5] &= ~(1UL << ((uint32_t)(IRQn) & 0x1F)); |
AnnaBridge | 146:22da6e220af6 | 274 | } |
AnnaBridge | 146:22da6e220af6 | 275 | else |
AnnaBridge | 146:22da6e220af6 | 276 | { |
AnnaBridge | 146:22da6e220af6 | 277 | NVIC_DisableIRQ(IRQn); |
AnnaBridge | 146:22da6e220af6 | 278 | } |
AnnaBridge | 146:22da6e220af6 | 279 | |
AnnaBridge | 146:22da6e220af6 | 280 | return NRF_SUCCESS; |
AnnaBridge | 146:22da6e220af6 | 281 | } |
AnnaBridge | 146:22da6e220af6 | 282 | |
AnnaBridge | 146:22da6e220af6 | 283 | /**@brief Get Pending Interrupt. |
AnnaBridge | 146:22da6e220af6 | 284 | * @note Corresponds to NVIC_GetPendingIRQ in CMSIS. |
AnnaBridge | 146:22da6e220af6 | 285 | * |
AnnaBridge | 146:22da6e220af6 | 286 | * @pre IRQn is valid and not reserved by the stack. |
AnnaBridge | 146:22da6e220af6 | 287 | * |
AnnaBridge | 146:22da6e220af6 | 288 | * @param[in] IRQn See the NVIC_GetPendingIRQ documentation in CMSIS. |
AnnaBridge | 146:22da6e220af6 | 289 | * @param[out] p_pending_irq Return value from NVIC_GetPendingIRQ. |
AnnaBridge | 146:22da6e220af6 | 290 | * |
AnnaBridge | 146:22da6e220af6 | 291 | * @retval ::NRF_SUCCESS The interrupt is available for the application. |
AnnaBridge | 146:22da6e220af6 | 292 | * @retval ::NRF_ERROR_SOC_NVIC_INTERRUPT_NOT_AVAILABLE IRQn is not available for the application. |
AnnaBridge | 146:22da6e220af6 | 293 | */ |
AnnaBridge | 146:22da6e220af6 | 294 | static inline uint32_t sd_nvic_GetPendingIRQ(IRQn_Type IRQn, uint32_t * p_pending_irq) |
AnnaBridge | 146:22da6e220af6 | 295 | { |
AnnaBridge | 146:22da6e220af6 | 296 | if (__sd_nvic_app_accessible_irq(IRQn)) |
AnnaBridge | 146:22da6e220af6 | 297 | { |
AnnaBridge | 146:22da6e220af6 | 298 | *p_pending_irq = NVIC_GetPendingIRQ(IRQn); |
AnnaBridge | 146:22da6e220af6 | 299 | return NRF_SUCCESS; |
AnnaBridge | 146:22da6e220af6 | 300 | } |
AnnaBridge | 146:22da6e220af6 | 301 | else |
AnnaBridge | 146:22da6e220af6 | 302 | { |
AnnaBridge | 146:22da6e220af6 | 303 | return NRF_ERROR_SOC_NVIC_INTERRUPT_NOT_AVAILABLE; |
AnnaBridge | 146:22da6e220af6 | 304 | } |
AnnaBridge | 146:22da6e220af6 | 305 | } |
AnnaBridge | 146:22da6e220af6 | 306 | |
AnnaBridge | 146:22da6e220af6 | 307 | /**@brief Set Pending Interrupt. |
AnnaBridge | 146:22da6e220af6 | 308 | * @note Corresponds to NVIC_SetPendingIRQ in CMSIS. |
AnnaBridge | 146:22da6e220af6 | 309 | * |
AnnaBridge | 146:22da6e220af6 | 310 | * @pre IRQn is valid and not reserved by the stack. |
AnnaBridge | 146:22da6e220af6 | 311 | * |
AnnaBridge | 146:22da6e220af6 | 312 | * @param[in] IRQn See the NVIC_SetPendingIRQ documentation in CMSIS. |
AnnaBridge | 146:22da6e220af6 | 313 | * |
AnnaBridge | 146:22da6e220af6 | 314 | * @retval ::NRF_SUCCESS The interrupt is set pending. |
AnnaBridge | 146:22da6e220af6 | 315 | * @retval ::NRF_ERROR_SOC_NVIC_INTERRUPT_NOT_AVAILABLE IRQn is not available for the application. |
AnnaBridge | 146:22da6e220af6 | 316 | */ |
AnnaBridge | 146:22da6e220af6 | 317 | static inline uint32_t sd_nvic_SetPendingIRQ(IRQn_Type IRQn) |
AnnaBridge | 146:22da6e220af6 | 318 | { |
AnnaBridge | 146:22da6e220af6 | 319 | if (__sd_nvic_app_accessible_irq(IRQn)) |
AnnaBridge | 146:22da6e220af6 | 320 | { |
AnnaBridge | 146:22da6e220af6 | 321 | NVIC_SetPendingIRQ(IRQn); |
AnnaBridge | 146:22da6e220af6 | 322 | return NRF_SUCCESS; |
AnnaBridge | 146:22da6e220af6 | 323 | } |
AnnaBridge | 146:22da6e220af6 | 324 | else |
AnnaBridge | 146:22da6e220af6 | 325 | { |
AnnaBridge | 146:22da6e220af6 | 326 | return NRF_ERROR_SOC_NVIC_INTERRUPT_NOT_AVAILABLE; |
AnnaBridge | 146:22da6e220af6 | 327 | } |
AnnaBridge | 146:22da6e220af6 | 328 | } |
AnnaBridge | 146:22da6e220af6 | 329 | |
AnnaBridge | 146:22da6e220af6 | 330 | /**@brief Clear Pending Interrupt. |
AnnaBridge | 146:22da6e220af6 | 331 | * @note Corresponds to NVIC_ClearPendingIRQ in CMSIS. |
AnnaBridge | 146:22da6e220af6 | 332 | * |
AnnaBridge | 146:22da6e220af6 | 333 | * @pre IRQn is valid and not reserved by the stack. |
AnnaBridge | 146:22da6e220af6 | 334 | * |
AnnaBridge | 146:22da6e220af6 | 335 | * @param[in] IRQn See the NVIC_ClearPendingIRQ documentation in CMSIS. |
AnnaBridge | 146:22da6e220af6 | 336 | * |
AnnaBridge | 146:22da6e220af6 | 337 | * @retval ::NRF_SUCCESS The interrupt pending flag is cleared. |
AnnaBridge | 146:22da6e220af6 | 338 | * @retval ::NRF_ERROR_SOC_NVIC_INTERRUPT_NOT_AVAILABLE IRQn is not available for the application. |
AnnaBridge | 146:22da6e220af6 | 339 | */ |
AnnaBridge | 146:22da6e220af6 | 340 | static inline uint32_t sd_nvic_ClearPendingIRQ(IRQn_Type IRQn) |
AnnaBridge | 146:22da6e220af6 | 341 | { |
AnnaBridge | 146:22da6e220af6 | 342 | if (__sd_nvic_app_accessible_irq(IRQn)) |
AnnaBridge | 146:22da6e220af6 | 343 | { |
AnnaBridge | 146:22da6e220af6 | 344 | NVIC_ClearPendingIRQ(IRQn); |
AnnaBridge | 146:22da6e220af6 | 345 | return NRF_SUCCESS; |
AnnaBridge | 146:22da6e220af6 | 346 | } |
AnnaBridge | 146:22da6e220af6 | 347 | else |
AnnaBridge | 146:22da6e220af6 | 348 | { |
AnnaBridge | 146:22da6e220af6 | 349 | return NRF_ERROR_SOC_NVIC_INTERRUPT_NOT_AVAILABLE; |
AnnaBridge | 146:22da6e220af6 | 350 | } |
AnnaBridge | 146:22da6e220af6 | 351 | } |
AnnaBridge | 146:22da6e220af6 | 352 | |
AnnaBridge | 146:22da6e220af6 | 353 | /**@brief Set Interrupt Priority. |
AnnaBridge | 146:22da6e220af6 | 354 | * @note Corresponds to NVIC_SetPriority in CMSIS. |
AnnaBridge | 146:22da6e220af6 | 355 | * |
AnnaBridge | 146:22da6e220af6 | 356 | * @pre IRQn is valid and not reserved by the stack. |
AnnaBridge | 146:22da6e220af6 | 357 | * @pre Priority is valid and not reserved by the stack. |
AnnaBridge | 146:22da6e220af6 | 358 | * |
AnnaBridge | 146:22da6e220af6 | 359 | * @param[in] IRQn See the NVIC_SetPriority documentation in CMSIS. |
AnnaBridge | 146:22da6e220af6 | 360 | * @param[in] priority A valid IRQ priority for use by the application. |
AnnaBridge | 146:22da6e220af6 | 361 | * |
AnnaBridge | 146:22da6e220af6 | 362 | * @retval ::NRF_SUCCESS The interrupt and priority level is available for the application. |
AnnaBridge | 146:22da6e220af6 | 363 | * @retval ::NRF_ERROR_SOC_NVIC_INTERRUPT_NOT_AVAILABLE IRQn is not available for the application. |
AnnaBridge | 146:22da6e220af6 | 364 | * @retval ::NRF_ERROR_SOC_NVIC_INTERRUPT_PRIORITY_NOT_ALLOWED The interrupt priority is not available for the application. |
AnnaBridge | 146:22da6e220af6 | 365 | */ |
AnnaBridge | 146:22da6e220af6 | 366 | static inline uint32_t sd_nvic_SetPriority(IRQn_Type IRQn, uint32_t priority) |
AnnaBridge | 146:22da6e220af6 | 367 | { |
AnnaBridge | 146:22da6e220af6 | 368 | if (!__sd_nvic_app_accessible_irq(IRQn)) |
AnnaBridge | 146:22da6e220af6 | 369 | { |
AnnaBridge | 146:22da6e220af6 | 370 | return NRF_ERROR_SOC_NVIC_INTERRUPT_NOT_AVAILABLE; |
AnnaBridge | 146:22da6e220af6 | 371 | } |
AnnaBridge | 146:22da6e220af6 | 372 | |
AnnaBridge | 146:22da6e220af6 | 373 | if (!__sd_nvic_is_app_accessible_priority(priority)) |
AnnaBridge | 146:22da6e220af6 | 374 | { |
AnnaBridge | 146:22da6e220af6 | 375 | return NRF_ERROR_SOC_NVIC_INTERRUPT_PRIORITY_NOT_ALLOWED; |
AnnaBridge | 146:22da6e220af6 | 376 | } |
AnnaBridge | 146:22da6e220af6 | 377 | |
AnnaBridge | 146:22da6e220af6 | 378 | NVIC_SetPriority(IRQn, (uint32_t)priority); |
AnnaBridge | 146:22da6e220af6 | 379 | return NRF_SUCCESS; |
AnnaBridge | 146:22da6e220af6 | 380 | } |
AnnaBridge | 146:22da6e220af6 | 381 | |
AnnaBridge | 146:22da6e220af6 | 382 | /**@brief Get Interrupt Priority. |
AnnaBridge | 146:22da6e220af6 | 383 | * @note Corresponds to NVIC_GetPriority in CMSIS. |
AnnaBridge | 146:22da6e220af6 | 384 | * |
AnnaBridge | 146:22da6e220af6 | 385 | * @pre IRQn is valid and not reserved by the stack. |
AnnaBridge | 146:22da6e220af6 | 386 | * |
AnnaBridge | 146:22da6e220af6 | 387 | * @param[in] IRQn See the NVIC_GetPriority documentation in CMSIS. |
AnnaBridge | 146:22da6e220af6 | 388 | * @param[out] p_priority Return value from NVIC_GetPriority. |
AnnaBridge | 146:22da6e220af6 | 389 | * |
AnnaBridge | 146:22da6e220af6 | 390 | * @retval ::NRF_SUCCESS The interrupt priority is returned in p_priority. |
AnnaBridge | 146:22da6e220af6 | 391 | * @retval ::NRF_ERROR_SOC_NVIC_INTERRUPT_NOT_AVAILABLE - IRQn is not available for the application. |
AnnaBridge | 146:22da6e220af6 | 392 | */ |
AnnaBridge | 146:22da6e220af6 | 393 | static inline uint32_t sd_nvic_GetPriority(IRQn_Type IRQn, uint32_t * p_priority) |
AnnaBridge | 146:22da6e220af6 | 394 | { |
AnnaBridge | 146:22da6e220af6 | 395 | if (__sd_nvic_app_accessible_irq(IRQn)) |
AnnaBridge | 146:22da6e220af6 | 396 | { |
AnnaBridge | 146:22da6e220af6 | 397 | *p_priority = (NVIC_GetPriority(IRQn) & 0xFF); |
AnnaBridge | 146:22da6e220af6 | 398 | return NRF_SUCCESS; |
AnnaBridge | 146:22da6e220af6 | 399 | } |
AnnaBridge | 146:22da6e220af6 | 400 | else |
AnnaBridge | 146:22da6e220af6 | 401 | { |
AnnaBridge | 146:22da6e220af6 | 402 | return NRF_ERROR_SOC_NVIC_INTERRUPT_NOT_AVAILABLE; |
AnnaBridge | 146:22da6e220af6 | 403 | } |
AnnaBridge | 146:22da6e220af6 | 404 | } |
AnnaBridge | 146:22da6e220af6 | 405 | |
AnnaBridge | 146:22da6e220af6 | 406 | /**@brief System Reset. |
AnnaBridge | 146:22da6e220af6 | 407 | * @note Corresponds to NVIC_SystemReset in CMSIS. |
AnnaBridge | 146:22da6e220af6 | 408 | * |
AnnaBridge | 146:22da6e220af6 | 409 | * @retval ::NRF_ERROR_SOC_NVIC_SHOULD_NOT_RETURN |
AnnaBridge | 146:22da6e220af6 | 410 | */ |
AnnaBridge | 146:22da6e220af6 | 411 | static inline uint32_t sd_nvic_SystemReset(void) |
AnnaBridge | 146:22da6e220af6 | 412 | { |
AnnaBridge | 146:22da6e220af6 | 413 | NVIC_SystemReset(); |
AnnaBridge | 146:22da6e220af6 | 414 | return NRF_ERROR_SOC_NVIC_SHOULD_NOT_RETURN; |
AnnaBridge | 146:22da6e220af6 | 415 | } |
AnnaBridge | 146:22da6e220af6 | 416 | |
AnnaBridge | 146:22da6e220af6 | 417 | /**@brief Enters critical region. |
AnnaBridge | 146:22da6e220af6 | 418 | * |
AnnaBridge | 146:22da6e220af6 | 419 | * @post Application interrupts will be disabled. |
AnnaBridge | 146:22da6e220af6 | 420 | * @note sd_nvic_critical_region_enter() and ::sd_nvic_critical_region_exit() must be called in matching pairs inside each |
AnnaBridge | 146:22da6e220af6 | 421 | * execution context |
AnnaBridge | 146:22da6e220af6 | 422 | * @sa sd_nvic_critical_region_exit |
AnnaBridge | 146:22da6e220af6 | 423 | * |
AnnaBridge | 146:22da6e220af6 | 424 | * @retval ::NRF_SUCCESS |
AnnaBridge | 146:22da6e220af6 | 425 | */ |
AnnaBridge | 146:22da6e220af6 | 426 | static inline uint32_t sd_nvic_critical_region_enter(uint8_t * p_is_nested_critical_region) |
AnnaBridge | 146:22da6e220af6 | 427 | { |
AnnaBridge | 146:22da6e220af6 | 428 | int was_masked = __sd_nvic_irq_disable(); |
AnnaBridge | 146:22da6e220af6 | 429 | if (!nrf_nvic_state.__cr_flag) |
AnnaBridge | 146:22da6e220af6 | 430 | { |
AnnaBridge | 146:22da6e220af6 | 431 | nrf_nvic_state.__cr_flag = 1; |
AnnaBridge | 146:22da6e220af6 | 432 | nrf_nvic_state.__irq_masks[0] = ( NVIC->ICER[0] & __NRF_NVIC_APP_IRQS_0 ); |
AnnaBridge | 146:22da6e220af6 | 433 | NVIC->ICER[0] = __NRF_NVIC_APP_IRQS_0; |
AnnaBridge | 146:22da6e220af6 | 434 | #ifdef NRF52 |
AnnaBridge | 146:22da6e220af6 | 435 | nrf_nvic_state.__irq_masks[1] = ( NVIC->ICER[1] & __NRF_NVIC_APP_IRQS_1 ); |
AnnaBridge | 146:22da6e220af6 | 436 | NVIC->ICER[1] = __NRF_NVIC_APP_IRQS_1; |
AnnaBridge | 146:22da6e220af6 | 437 | #endif |
AnnaBridge | 146:22da6e220af6 | 438 | *p_is_nested_critical_region = 0; |
AnnaBridge | 146:22da6e220af6 | 439 | } |
AnnaBridge | 146:22da6e220af6 | 440 | else |
AnnaBridge | 146:22da6e220af6 | 441 | { |
AnnaBridge | 146:22da6e220af6 | 442 | *p_is_nested_critical_region = 1; |
AnnaBridge | 146:22da6e220af6 | 443 | } |
AnnaBridge | 146:22da6e220af6 | 444 | if (!was_masked) |
AnnaBridge | 146:22da6e220af6 | 445 | { |
AnnaBridge | 146:22da6e220af6 | 446 | __sd_nvic_irq_enable(); |
AnnaBridge | 146:22da6e220af6 | 447 | } |
AnnaBridge | 146:22da6e220af6 | 448 | return NRF_SUCCESS; |
AnnaBridge | 146:22da6e220af6 | 449 | } |
AnnaBridge | 146:22da6e220af6 | 450 | |
AnnaBridge | 146:22da6e220af6 | 451 | /**@brief Exit critical region. |
AnnaBridge | 146:22da6e220af6 | 452 | * |
AnnaBridge | 146:22da6e220af6 | 453 | * @pre Application has entered a critical region using ::sd_nvic_critical_region_enter. |
AnnaBridge | 146:22da6e220af6 | 454 | * @post If not in a nested critical region, the application interrupts will restored to the state before ::sd_nvic_critical_region_enter was called. |
AnnaBridge | 146:22da6e220af6 | 455 | * |
AnnaBridge | 146:22da6e220af6 | 456 | * @param[in] is_nested_critical_region If this is set to 1, the critical region won't be exited. @sa sd_nvic_critical_region_enter. |
AnnaBridge | 146:22da6e220af6 | 457 | * |
AnnaBridge | 146:22da6e220af6 | 458 | * @retval ::NRF_SUCCESS |
AnnaBridge | 146:22da6e220af6 | 459 | */ |
AnnaBridge | 146:22da6e220af6 | 460 | static inline uint32_t sd_nvic_critical_region_exit(uint8_t is_nested_critical_region) |
AnnaBridge | 146:22da6e220af6 | 461 | { |
AnnaBridge | 146:22da6e220af6 | 462 | if (nrf_nvic_state.__cr_flag && (is_nested_critical_region == 0)) |
AnnaBridge | 146:22da6e220af6 | 463 | { |
AnnaBridge | 146:22da6e220af6 | 464 | int was_masked = __sd_nvic_irq_disable(); |
AnnaBridge | 146:22da6e220af6 | 465 | NVIC->ISER[0] = nrf_nvic_state.__irq_masks[0]; |
AnnaBridge | 146:22da6e220af6 | 466 | #ifdef NRF52 |
AnnaBridge | 146:22da6e220af6 | 467 | NVIC->ISER[1] = nrf_nvic_state.__irq_masks[1]; |
AnnaBridge | 146:22da6e220af6 | 468 | #endif |
AnnaBridge | 146:22da6e220af6 | 469 | nrf_nvic_state.__cr_flag = 0; |
AnnaBridge | 146:22da6e220af6 | 470 | if (!was_masked) |
AnnaBridge | 146:22da6e220af6 | 471 | { |
AnnaBridge | 146:22da6e220af6 | 472 | __sd_nvic_irq_enable(); |
AnnaBridge | 146:22da6e220af6 | 473 | } |
AnnaBridge | 146:22da6e220af6 | 474 | } |
AnnaBridge | 146:22da6e220af6 | 475 | |
AnnaBridge | 146:22da6e220af6 | 476 | return NRF_SUCCESS; |
AnnaBridge | 146:22da6e220af6 | 477 | } |
AnnaBridge | 146:22da6e220af6 | 478 | /**@} */ |
AnnaBridge | 146:22da6e220af6 | 479 | |
AnnaBridge | 146:22da6e220af6 | 480 | #ifdef __cplusplus |
AnnaBridge | 146:22da6e220af6 | 481 | } |
AnnaBridge | 146:22da6e220af6 | 482 | #endif |
AnnaBridge | 146:22da6e220af6 | 483 | |
AnnaBridge | 146:22da6e220af6 | 484 | #endif // NRF_NVIC_H__ |
AnnaBridge | 146:22da6e220af6 | 485 | |
AnnaBridge | 146:22da6e220af6 | 486 | /**@} */ |