1 /* 2 * Copyright (c) 2017 - 2023, Nordic Semiconductor ASA 3 * All rights reserved. 4 * 5 * SPDX-License-Identifier: BSD-3-Clause 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions are met: 9 * 10 * 1. Redistributions of source code must retain the above copyright notice, this 11 * list of conditions and the following disclaimer. 12 * 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 17 * 3. Neither the name of the copyright holder nor the names of its 18 * contributors may be used to endorse or promote products derived from this 19 * software without specific prior written permission. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 25 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 * POSSIBILITY OF SUCH DAMAGE. 32 */ 33 34 #ifndef NRFX_GLUE_H__ 35 #define NRFX_GLUE_H__ 36 37 // THIS IS A TEMPLATE FILE. 38 // It should be copied to a suitable location within the host environment into 39 // which nrfx is integrated, and the following macros should be provided with 40 // appropriate implementations. 41 // And this comment should be removed from the customized file. 42 43 #ifdef __cplusplus 44 extern "C" { 45 #endif 46 47 /** 48 * @defgroup nrfx_glue nrfx_glue.h 49 * @{ 50 * @ingroup nrfx 51 * 52 * @brief This file contains macros that should be implemented according to 53 * the needs of the host environment into which @em nrfx is integrated. 54 */ 55 56 // Uncomment this line to use the standard MDK way of binding IRQ handlers 57 // at linking time. 58 //#include <soc/nrfx_irqs.h> 59 60 //------------------------------------------------------------------------------ 61 62 /** 63 * @brief Macro for placing a runtime assertion. 64 * 65 * @param expression Expression to be evaluated. 66 */ 67 #define NRFX_ASSERT(expression) 68 69 /** 70 * @brief Macro for placing a compile time assertion. 71 * 72 * @param expression Expression to be evaluated. 73 */ 74 #define NRFX_STATIC_ASSERT(expression) 75 76 //------------------------------------------------------------------------------ 77 78 /** 79 * @brief Macro for setting the priority of a specific IRQ. 80 * 81 * @param irq_number IRQ number. 82 * @param priority Priority to be set. 83 */ 84 #define NRFX_IRQ_PRIORITY_SET(irq_number, priority) 85 86 /** 87 * @brief Macro for enabling a specific IRQ. 88 * 89 * @param irq_number IRQ number. 90 */ 91 #define NRFX_IRQ_ENABLE(irq_number) 92 93 /** 94 * @brief Macro for checking if a specific IRQ is enabled. 95 * 96 * @param irq_number IRQ number. 97 * 98 * @retval true If the IRQ is enabled. 99 * @retval false Otherwise. 100 */ 101 #define NRFX_IRQ_IS_ENABLED(irq_number) 102 103 /** 104 * @brief Macro for disabling a specific IRQ. 105 * 106 * @param irq_number IRQ number. 107 */ 108 #define NRFX_IRQ_DISABLE(irq_number) 109 110 /** 111 * @brief Macro for setting a specific IRQ as pending. 112 * 113 * @param irq_number IRQ number. 114 */ 115 #define NRFX_IRQ_PENDING_SET(irq_number) 116 117 /** 118 * @brief Macro for clearing the pending status of a specific IRQ. 119 * 120 * @param irq_number IRQ number. 121 */ 122 #define NRFX_IRQ_PENDING_CLEAR(irq_number) 123 124 /** 125 * @brief Macro for checking the pending status of a specific IRQ. 126 * 127 * @retval true If the IRQ is pending. 128 * @retval false Otherwise. 129 */ 130 #define NRFX_IRQ_IS_PENDING(irq_number) 131 132 /** @brief Macro for entering into a critical section. */ 133 #define NRFX_CRITICAL_SECTION_ENTER() 134 135 /** @brief Macro for exiting from a critical section. */ 136 #define NRFX_CRITICAL_SECTION_EXIT() 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) 154 155 //------------------------------------------------------------------------------ 156 157 /** @brief Atomic 32-bit unsigned type. */ 158 #define nrfx_atomic_t 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) 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) 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) 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) 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) 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) 223 224 /** 225 * @brief Macro for running compare and swap on an atomic object. 226 * 227 * Value is updated to the new value only if it previously equaled old value. 228 * 229 * @param[in,out] p_data Atomic memory pointer. 230 * @param[in] old_value Expected old value. 231 * @param[in] new_value New value. 232 * 233 * @retval true If value was updated. 234 * @retval false If value was not updated because location was not equal to @p old_value. 235 */ 236 #define NRFX_ATOMIC_CAS(p_data, old_value, new_value) 237 238 /** 239 * @brief Macro for counting leading zeros. 240 * 241 * @param[in] value A word value. 242 * 243 * @return Number of leading 0-bits in @p value, starting at the most significant bit position. 244 * If x is 0, the result is undefined. 245 */ 246 #define NRFX_CLZ(value) 247 248 /** 249 * @brief Macro for counting trailing zeros. 250 * 251 * @param[in] value A word value. 252 * 253 * @return Number of trailing 0-bits in @p value, starting at the least significant bit position. 254 * If x is 0, the result is undefined. 255 */ 256 #define NRFX_CTZ(value) 257 258 //------------------------------------------------------------------------------ 259 260 /** 261 * @brief When set to a non-zero value, this macro specifies that the 262 * @ref nrfx_error_codes and the @ref nrfx_err_t type itself are defined 263 * in a customized way and the default definitions from @c <nrfx_error.h> 264 * should not be used. 265 */ 266 #define NRFX_CUSTOM_ERROR_CODES 0 267 268 //------------------------------------------------------------------------------ 269 270 /** 271 * @brief When set to a non-zero value, this macro specifies that inside HALs 272 * the event registers are read back after clearing, on devices that 273 * otherwise could defer the actual register modification. 274 */ 275 #define NRFX_EVENT_READBACK_ENABLED 1 276 277 //------------------------------------------------------------------------------ 278 279 /** 280 * @brief Macro for writing back cache lines associated with the specified buffer. 281 * 282 * @note Macro should be empty if data cache is disabled or not present. 283 * 284 * @param[in] p_buffer Pointer to the buffer. 285 * @param[in] size Size of the buffer. 286 */ 287 #define NRFY_CACHE_WB(p_buffer, size) 288 289 /** 290 * @brief Macro for invalidating cache lines associated with the specified buffer. 291 * 292 * @note Macro should be empty if data cache is disabled or not present. 293 * 294 * @param[in] p_buffer Pointer to the buffer. 295 * @param[in] size Size of the buffer. 296 */ 297 #define NRFY_CACHE_INV(p_buffer, size) 298 299 /** 300 * @brief Macro for writing back and invalidating cache lines associated with 301 * the specified buffer. 302 * 303 * @note Macro should be empty if data cache is disabled or not present. 304 * 305 * @param[in] p_buffer Pointer to the buffer. 306 * @param[in] size Size of the buffer. 307 */ 308 #define NRFY_CACHE_WBINV(p_buffer, size) 309 310 //------------------------------------------------------------------------------ 311 312 /** @brief Bitmask that defines DPPI channels that are reserved for use outside of the nrfx library. */ 313 #define NRFX_DPPI_CHANNELS_USED 0 314 315 /** @brief Bitmask that defines DPPI groups that are reserved for use outside of the nrfx library. */ 316 #define NRFX_DPPI_GROUPS_USED 0 317 318 /** @brief Bitmask that defines PPI channels that are reserved for use outside of the nrfx library. */ 319 #define NRFX_PPI_CHANNELS_USED 0 320 321 /** @brief Bitmask that defines PPI groups that are reserved for use outside of the nrfx library. */ 322 #define NRFX_PPI_GROUPS_USED 0 323 324 /** @brief Bitmask that defines GPIOTE channels that are reserved for use outside of the nrfx library. */ 325 #define NRFX_GPIOTE_CHANNELS_USED 0 326 327 /** @brief Bitmask that defines EGU instances that are reserved for use outside of the nrfx library. */ 328 #define NRFX_EGUS_USED 0 329 330 /** @brief Bitmask that defines TIMER instances that are reserved for use outside of the nrfx library. */ 331 #define NRFX_TIMERS_USED 0 332 333 /** @} */ 334 335 #ifdef __cplusplus 336 } 337 #endif 338 339 #endif // NRFX_GLUE_H__ 340