1 /* 2 * Copyright (c) 2017 - 2020, Nordic Semiconductor ASA 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright notice, this 9 * list of conditions and the following disclaimer. 10 * 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 15 * 3. Neither the name of the copyright holder nor the names of its 16 * contributors may be used to endorse or promote products derived from this 17 * software without specific prior written permission. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 23 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32 #ifndef NRFX_GLUE_H__ 33 #define NRFX_GLUE_H__ 34 35 /* Include the spm utilities for the SPM_ASSERT symbol */ 36 #include <assert.h> 37 38 #include <soc/nrfx_coredep.h> 39 40 #ifdef __cplusplus 41 extern "C" { 42 #endif 43 44 /** 45 * @defgroup nrfx_glue nrfx_glue.h 46 * @{ 47 * @ingroup nrfx 48 * 49 * @brief This file contains macros that should be implemented according to 50 * the needs of the host environment into which @em nrfx is integrated. 51 */ 52 53 //------------------------------------------------------------------------------ 54 55 /** 56 * @brief Macro for placing a runtime assertion. 57 * 58 * @param expression Expression to be evaluated. 59 */ 60 #if defined(NDEBUG) 61 #define NRFX_ASSERT(expression) if (0 && (expression)) {} 62 #else 63 #define NRFX_ASSERT(expression) assert(expression) 64 #endif 65 66 /** 67 * @brief Macro for placing a compile time assertion. 68 * 69 * @param expression Expression to be evaluated. 70 */ 71 #define NRFX_STATIC_ASSERT(expression) _Static_assert(expression, "") 72 73 //------------------------------------------------------------------------------ 74 75 /** 76 * @brief Macro for setting the priority of a specific IRQ. 77 * 78 * @param irq_number IRQ number. 79 * @param priority Priority to be set. 80 */ 81 #define NRFX_IRQ_PRIORITY_SET(irq_number, priority) \ 82 NVIC_SetPriority(irq_number, priority) 83 84 /** 85 * @brief Macro for enabling a specific IRQ. 86 * 87 * @param irq_number IRQ number. 88 */ 89 #define NRFX_IRQ_ENABLE(irq_number) NVIC_EnableIRQ(irq_number) 90 91 /** 92 * @brief Macro for checking if a specific IRQ is enabled. 93 * 94 * @param irq_number IRQ number. 95 * 96 * @retval true If the IRQ is enabled. 97 * @retval false Otherwise. 98 */ 99 #define NRFX_IRQ_IS_ENABLED(irq_number) NVIC_GetEnableIRQ(irq_number) 100 101 /** 102 * @brief Macro for disabling a specific IRQ. 103 * 104 * @param irq_number IRQ number. 105 */ 106 #define NRFX_IRQ_DISABLE(irq_number) NVIC_DisableIRQ(irq_number) 107 108 /** 109 * @brief Macro for setting a specific IRQ as pending. 110 * 111 * @param irq_number IRQ number. 112 */ 113 #define NRFX_IRQ_PENDING_SET(irq_number) NVIC_SetPendingIRQ(irq_number) 114 115 /** 116 * @brief Macro for clearing the pending status of a specific IRQ. 117 * 118 * @param irq_number IRQ number. 119 */ 120 #define NRFX_IRQ_PENDING_CLEAR(irq_number) NVIC_ClearPendingIRQ(irq_number) 121 122 /** 123 * @brief Macro for checking the pending status of a specific IRQ. 124 * 125 * @retval true If the IRQ is pending. 126 * @retval false Otherwise. 127 */ 128 #define NRFX_IRQ_IS_PENDING(irq_number) NVIC_GetPendingIRQ(irq_number) 129 130 /** @brief Macro for entering into a critical section. */ 131 #define NRFX_CRITICAL_SECTION_ENTER() nrfx_critical_section_enter() 132 void nrfx_critical_section_enter(void); 133 134 /** @brief Macro for exiting from a critical section. */ 135 #define NRFX_CRITICAL_SECTION_EXIT() nrfx_critical_section_exit() 136 void nrfx_critical_section_exit(void); 137 138 //------------------------------------------------------------------------------ 139 140 /** 141 * @brief When set to a non-zero value, this macro specifies that 142 * @ref nrfx_coredep_delay_us uses a precise DWT-based solution. 143 * A compilation error is generated if the DWT unit is not present 144 * in the SoC used. 145 */ 146 #define NRFX_DELAY_DWT_BASED 0 147 148 /** 149 * @brief Macro for delaying the code execution for at least the specified time. 150 * 151 * @param us_time Number of microseconds to wait. 152 */ 153 #define NRFX_DELAY_US(us_time) nrfx_coredep_delay_us(us_time) 154 155 //------------------------------------------------------------------------------ 156 157 /** @brief Atomic 32-bit unsigned type. */ 158 #define nrfx_atomic_t long 159 160 /** 161 * @brief Macro for storing a value to an atomic object and returning its previous value. 162 * 163 * @param[in] p_data Atomic memory pointer. 164 * @param[in] value Value to store. 165 * 166 * @return Previous value of the atomic object. 167 */ 168 #define NRFX_ATOMIC_FETCH_STORE(p_data, value) __atomic_exchange_n(p_data, value, __ATOMIC_SEQ_CST) 169 170 /** 171 * @brief Macro for running a bitwise OR operation on an atomic object and returning its previous value. 172 * 173 * @param[in] p_data Atomic memory pointer. 174 * @param[in] value Value of the second operand in the OR operation. 175 * 176 * @return Previous value of the atomic object. 177 */ 178 #define NRFX_ATOMIC_FETCH_OR(p_data, value) __atomic_fetch_or(p_data, value, __ATOMIC_SEQ_CST) 179 180 /** 181 * @brief Macro for running a bitwise AND operation on an atomic object 182 * and returning its previous value. 183 * 184 * @param[in] p_data Atomic memory pointer. 185 * @param[in] value Value of the second operand in the AND operation. 186 * 187 * @return Previous value of the atomic object. 188 */ 189 #define NRFX_ATOMIC_FETCH_AND(p_data, value) __atomic_fetch_and(p_data, value, __ATOMIC_SEQ_CST) 190 191 /** 192 * @brief Macro for running a bitwise XOR operation on an atomic object 193 * and returning its previous value. 194 * 195 * @param[in] p_data Atomic memory pointer. 196 * @param[in] value Value of the second operand in the XOR operation. 197 * 198 * @return Previous value of the atomic object. 199 */ 200 #define NRFX_ATOMIC_FETCH_XOR(p_data, value) __atomic_fetch_xor(p_data, value, __ATOMIC_SEQ_CST) 201 202 /** 203 * @brief Macro for running an addition operation on an atomic object 204 * and returning its previous value. 205 * 206 * @param[in] p_data Atomic memory pointer. 207 * @param[in] value Value of the second operand in the ADD operation. 208 * 209 * @return Previous value of the atomic object. 210 */ 211 #define NRFX_ATOMIC_FETCH_ADD(p_data, value) __atomic_fetch_add(p_data, value, __ATOMIC_SEQ_CST) 212 213 /** 214 * @brief Macro for running a subtraction operation on an atomic object 215 * and returning its previous value. 216 * 217 * @param[in] p_data Atomic memory pointer. 218 * @param[in] value Value of the second operand in the SUB operation. 219 * 220 * @return Previous value of the atomic object. 221 */ 222 #define NRFX_ATOMIC_FETCH_SUB(p_data, value) __atomic_fetch_sub(p_data, value, __ATOMIC_SEQ_CST) 223 224 //------------------------------------------------------------------------------ 225 226 /** 227 * @brief When set to a non-zero value, this macro specifies that the 228 * @ref nrfx_error_codes and the @ref nrfx_err_t type itself are defined 229 * in a customized way and the default definitions from @c <nrfx_error.h> 230 * should not be used. 231 */ 232 #define NRFX_CUSTOM_ERROR_CODES 0 233 234 //------------------------------------------------------------------------------ 235 236 /** 237 * @brief When set to a non-zero value, this macro specifies that inside HALs 238 * the event registers are read back after clearing, on devices that 239 * otherwise could defer the actual register modification. 240 */ 241 #define NRFX_EVENT_READBACK_ENABLED 1 242 243 //------------------------------------------------------------------------------ 244 245 /** 246 * @brief Macro for writing back cache lines associated with the specified buffer. 247 * 248 * @param[in] p_buffer Pointer to the buffer. 249 * @param[in] size Size of the buffer. 250 */ 251 #define NRFY_CACHE_WB(p_buffer, size) \ 252 do { \ 253 (void)p_buffer; \ 254 (void)size; \ 255 } while (0) 256 257 /** 258 * @brief Macro for invalidating cache lines associated with the specified buffer. 259 * 260 * @param[in] p_buffer Pointer to the buffer. 261 * @param[in] size Size of the buffer. 262 */ 263 #define NRFY_CACHE_INV(p_buffer, size) \ 264 do { \ 265 (void)p_buffer; \ 266 (void)size; \ 267 } while (0) 268 269 /** 270 * @brief Macro for writing back and invalidating cache lines associated with 271 * the specified buffer. 272 * 273 * @param[in] p_buffer Pointer to the buffer. 274 * @param[in] size Size of the buffer. 275 */ 276 #define NRFY_CACHE_WBINV(p_buffer, size) \ 277 do { \ 278 (void)p_buffer; \ 279 (void)size; \ 280 } while (0) 281 282 //------------------------------------------------------------------------------ 283 284 /** @brief Bitmask that defines DPPI channels that are reserved for use outside of the nrfx library. */ 285 #define NRFX_DPPI_CHANNELS_USED 0 286 287 /** @brief Bitmask that defines DPPI groups that are reserved for use outside of the nrfx library. */ 288 #define NRFX_DPPI_GROUPS_USED 0 289 290 /** @brief Bitmask that defines PPI channels that are reserved for use outside of the nrfx library. */ 291 #define NRFX_PPI_CHANNELS_USED 0 292 293 /** @brief Bitmask that defines PPI groups that are reserved for use outside of the nrfx library. */ 294 #define NRFX_PPI_GROUPS_USED 0 295 296 /** @brief Bitmask that defines GPIOTE channels that are reserved for use outside of the nrfx library. */ 297 #define NRFX_GPIOTE_CHANNELS_USED 0 298 299 /** @brief Bitmask that defines EGU instances that are reserved for use outside of the nrfx library. */ 300 #define NRFX_EGUS_USED 0 301 302 /** @brief Bitmask that defines TIMER instances that are reserved for use outside of the nrfx library. */ 303 #define NRFX_TIMERS_USED 0 304 305 /** @} */ 306 307 #ifdef __cplusplus 308 } 309 #endif 310 311 #endif // NRFX_GLUE_H__ 312