1 /* 2 * Copyright (c) 2017 - 2018, 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 // THIS IS A TEMPLATE FILE. 36 // It should be copied to a suitable location within the host environment into 37 // which nrfx is integrated, and the following macros should be provided with 38 // appropriate implementations. 39 // And this comment should be removed from the customized file. 40 41 #ifdef __cplusplus 42 extern "C" { 43 #endif 44 45 int NVIC_IRQ_IS_ENABLED(unsigned int irq); 46 unsigned int nrfx_enter_critical(void); 47 void nrfx_exit_critical(unsigned int ctx); 48 49 /** 50 * @defgroup nrfx_glue nrfx_glue.h 51 * @{ 52 * @ingroup nrfx 53 * 54 * @brief This file contains macros that should be implemented according to 55 * the needs of the host environment into which @em nrfx is integrated. 56 */ 57 58 // Uncomment this line to use the standard MDK way of binding IRQ handlers 59 // at linking time. 60 //#include <soc/nrfx_irqs.h> 61 62 //------------------------------------------------------------------------------ 63 64 /** 65 * @brief Macro for placing a runtime assertion. 66 * 67 * @param expression Expression to evaluate. 68 */ 69 #define NRFX_ASSERT(expression) 70 71 /** 72 * @brief Macro for placing a compile time assertion. 73 * 74 * @param expression Expression to evaluate. 75 */ 76 #define NRFX_STATIC_ASSERT(expression) 77 78 //------------------------------------------------------------------------------ 79 80 /** 81 * @brief Macro for setting the priority of a specific IRQ. 82 * 83 * @param irq_number IRQ number. 84 * @param priority Priority to set. 85 */ 86 #define NRFX_IRQ_PRIORITY_SET(irq_number, priority) NVIC_SetPriority(irq_number, priority) 87 88 /** 89 * @brief Macro for enabling a specific IRQ. 90 * 91 * @param irq_number IRQ number. 92 */ 93 #define NRFX_IRQ_ENABLE(irq_number) NVIC_EnableIRQ(irq_number) 94 95 /** 96 * @brief Macro for checking if a specific IRQ is enabled. 97 * 98 * @param irq_number IRQ number. 99 * 100 * @retval true If the IRQ is enabled. 101 * @retval false Otherwise. 102 */ 103 #define NRFX_IRQ_IS_ENABLED(irq_number) NVIC_IRQ_IS_ENABLED(irq_number) 104 105 /** 106 * @brief Macro for disabling a specific IRQ. 107 * 108 * @param irq_number IRQ number. 109 */ 110 #define NRFX_IRQ_DISABLE(irq_number) NVIC_DisableIRQ(irq_number) 111 112 /** 113 * @brief Macro for setting a specific IRQ as pending. 114 * 115 * @param irq_number IRQ number. 116 */ 117 #define NRFX_IRQ_PENDING_SET(irq_number) NVIC_SetPendingIRQ(irq_number) 118 119 /** 120 * @brief Macro for clearing the pending status of a specific IRQ. 121 * 122 * @param irq_number IRQ number. 123 */ 124 #define NRFX_IRQ_PENDING_CLEAR(irq_number) NVIC_ClearPendingIRQ(irq_number) 125 126 /** 127 * @brief Macro for checking the pending status of a specific IRQ. 128 * 129 * @retval true If the IRQ is pending. 130 * @retval false Otherwise. 131 */ 132 #define NRFX_IRQ_IS_PENDING(irq_number) NVIC_GetPendingIRQ(irq_number) 133 134 /** 135 * @brief Macro for entering into a critical section. 136 */ 137 #define NRFX_CRITICAL_SECTION_ENTER() {unsigned int ctx; ctx = nrfx_enter_critical(); 138 139 /** 140 * @brief Macro for exiting from a critical section. 141 */ 142 #define NRFX_CRITICAL_SECTION_EXIT() nrfx_exit_critical(ctx);} 143 144 //------------------------------------------------------------------------------ 145 146 /** 147 * @brief When set to a non-zero value, this macro specifies that 148 * @ref nrfx_coredep_delay_us uses a precise DWT-based solution. 149 * A compilation error is generated if the DWT unit is not present 150 * in the SoC used. 151 */ 152 #define NRFX_DELAY_DWT_BASED 0 153 154 /** 155 * @brief Macro for delaying the code execution for at least the specified time. 156 * 157 * @param us_time Number of microseconds to wait. 158 */ 159 #define NRFX_DELAY_US(us_time) 160 161 //------------------------------------------------------------------------------ 162 163 /** 164 * @brief Atomic 32-bit unsigned type. 165 */ 166 #define nrfx_atomic_t 167 168 /** 169 * @brief Macro for storing a value to an atomic object and returning its previous value. 170 * 171 * @param[in] p_data Atomic memory pointer. 172 * @param[in] value Value to store. 173 * 174 * @return Previous value of the atomic object. 175 */ 176 #define NRFX_ATOMIC_FETCH_STORE(p_data, value) 177 178 /** 179 * @brief Macro for running a bitwise OR operation on an atomic object and returning its previous value. 180 * 181 * @param[in] p_data Atomic memory pointer. 182 * @param[in] value Value of the second operand in the OR operation. 183 * 184 * @return Previous value of the atomic object. 185 */ 186 #define NRFX_ATOMIC_FETCH_OR(p_data, value) 187 188 /** 189 * @brief Macro for running a bitwise AND operation on an atomic object 190 * and returning its previous value. 191 * 192 * @param[in] p_data Atomic memory pointer. 193 * @param[in] value Value of the second operand in the AND operation. 194 * 195 * @return Previous value of the atomic object. 196 */ 197 #define NRFX_ATOMIC_FETCH_AND(p_data, value) 198 199 /** 200 * @brief Macro for running a bitwise XOR operation on an atomic object 201 * and returning its previous value. 202 * 203 * @param[in] p_data Atomic memory pointer. 204 * @param[in] value Value of the second operand in the XOR operation. 205 * 206 * @return Previous value of the atomic object. 207 */ 208 #define NRFX_ATOMIC_FETCH_XOR(p_data, value) 209 210 /** 211 * @brief Macro for running an addition operation on an atomic object 212 * and returning its previous value. 213 * 214 * @param[in] p_data Atomic memory pointer. 215 * @param[in] value Value of the second operand in the ADD operation. 216 * 217 * @return Previous value of the atomic object. 218 */ 219 #define NRFX_ATOMIC_FETCH_ADD(p_data, value) 220 221 /** 222 * @brief Macro for running a subtraction operation on an atomic object 223 * and returning its previous value. 224 * 225 * @param[in] p_data Atomic memory pointer. 226 * @param[in] value Value of the second operand in the SUB operation. 227 * 228 * @return Previous value of the atomic object. 229 */ 230 #define NRFX_ATOMIC_FETCH_SUB(p_data, value) 231 232 //------------------------------------------------------------------------------ 233 234 /** 235 * @brief When set to a non-zero value, this macro specifies that the 236 * @ref nrfx_error_codes and the @ref nrfx_err_t type itself are defined 237 * in a customized way and the default definitions from @c <nrfx_error.h> 238 * should not be used. 239 */ 240 #define NRFX_CUSTOM_ERROR_CODES 0 241 242 //------------------------------------------------------------------------------ 243 244 /** 245 * @brief Bitmask defining DPPI channels reserved to be used outside of nrfx. 246 */ 247 #define NRFX_DPPI_CHANNELS_USED 0 248 249 /** 250 * @brief Bitmask defining DPPI groups reserved to be used outside of nrfx. 251 */ 252 #define NRFX_DPPI_GROUPS_USED 0 253 254 /** 255 * @brief Bitmask defining PPI channels reserved to be used outside of nrfx. 256 */ 257 #define NRFX_PPI_CHANNELS_USED 0 258 259 /** 260 * @brief Bitmask defining PPI groups reserved to be used outside of nrfx. 261 */ 262 #define NRFX_PPI_GROUPS_USED 0 263 264 /** 265 * @brief Bitmask defining SWI instances reserved to be used outside of nrfx. 266 */ 267 #define NRFX_SWI_USED 0 268 269 /** 270 * @brief Bitmask defining TIMER instances reserved to be used outside of nrfx. 271 */ 272 #define NRFX_TIMERS_USED 0 273 274 /** @} */ 275 276 #ifdef __cplusplus 277 } 278 #endif 279 280 #endif // NRFX_GLUE_H__ 281