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 <assert.h> 36 #include <nrfx_atomic.h> 37 #include <arch/arm/cm.h> 38 39 // THIS WAS CREATED FROM THE TEMPLATE FILE INCLUDED WITH THE MDK. 40 // This is the clue that binds macros used in the MDK with LK specific implementations 41 // If the MDK is upgraded in the future, this will need to be carried over. 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 // Instead of using this in LK, each LK driver using nrfx should define the irq 59 // handler which should handle the irq entry, calling into the nrfx handler, then 60 // handling the irq exit (i.e. - arm_cm_irq_entry and arm_cm_irq_exit) 61 //#include <soc/nrfx_irqs.h> 62 63 //------------------------------------------------------------------------------ 64 65 /** 66 * @brief Macro for placing a runtime assertion. 67 * 68 * @param expression Expression to be evaluated. 69 */ 70 // Instead of using lk ASSERT, defining the code here since the conditionals 71 // in the lk ASSERT cause some warnings with the nrfx library (fall through errors) 72 #define NRFX_ASSERT(expression) ASSERT(expression) 73 74 /** 75 * @brief Macro for placing a compile time assertion. 76 * 77 * @param expression Expression to be evaluated. 78 */ 79 #define NRFX_STATIC_ASSERT(expression) STATIC_ASSERT(expression) 80 81 //------------------------------------------------------------------------------ 82 83 /** 84 * @brief Macro for setting the priority of a specific IRQ. 85 * 86 * @param irq_number IRQ number. 87 * @param priority Priority to be set. 88 */ 89 #define NRFX_IRQ_PRIORITY_SET(irq_number, priority) NVIC_SetPriority(irq_number, priority) 90 91 /** 92 * @brief Macro for enabling a specific IRQ. 93 * 94 * @param irq_number IRQ number. 95 */ 96 #define NRFX_IRQ_ENABLE(irq_number) NVIC_EnableIRQ(irq_number) 97 98 /** 99 * @brief Macro for checking if a specific IRQ is enabled. 100 * 101 * @param irq_number IRQ number. 102 * 103 * @retval true If the IRQ is enabled. 104 * @retval false Otherwise. 105 */ 106 #define NRFX_IRQ_IS_ENABLED(irq_number) NVIC_GetEnableIRQ(irq_number) 107 108 /** 109 * @brief Macro for disabling a specific IRQ. 110 * 111 * @param irq_number IRQ number. 112 */ 113 #define NRFX_IRQ_DISABLE(irq_number) NVIC_DisableIRQ(irq_number) 114 115 /** 116 * @brief Macro for setting a specific IRQ as pending. 117 * 118 * @param irq_number IRQ number. 119 */ 120 #define NRFX_IRQ_PENDING_SET(irq_number) NVIC_SetPendingIRQ(irq_number) 121 122 /** 123 * @brief Macro for clearing the pending status of a specific IRQ. 124 * 125 * @param irq_number IRQ number. 126 */ 127 #define NRFX_IRQ_PENDING_CLEAR(irq_number) NVIC_ClearPendingIRQ(irq_number) 128 129 /** 130 * @brief Macro for checking the pending status of a specific IRQ. 131 * 132 * @retval true If the IRQ is pending. 133 * @retval false Otherwise. 134 */ 135 #define NRFX_IRQ_IS_PENDING(irq_number) NVIC_GetPendingIRQ(irq_number) 136 137 /** @brief Macro for entering into a critical section. */ 138 #define NRFX_CRITICAL_SECTION_ENTER() 139 140 /** @brief Macro for exiting from a critical section. */ 141 #define NRFX_CRITICAL_SECTION_EXIT() 142 143 //------------------------------------------------------------------------------ 144 145 /** 146 * @brief When set to a non-zero value, this macro specifies that 147 * @ref nrfx_coredep_delay_us uses a precise DWT-based solution. 148 * A compilation error is generated if the DWT unit is not present 149 * in the SoC used. 150 */ 151 #define NRFX_DELAY_DWT_BASED 0 152 153 /** 154 * @brief Macro for delaying the code execution for at least the specified time. 155 * 156 * @param us_time Number of microseconds to wait. 157 */ 158 #define NRFX_DELAY_US(us_time) 159 //------------------------------------------------------------------------------ 160 161 /** @brief Atomic 32-bit unsigned type. */ 162 #define nrfx_atomic_t nrfx_atomic_u32_t 163 164 /** 165 * @brief Macro for storing a value to an atomic object and returning its previous value. 166 * 167 * @param[in] p_data Atomic memory pointer. 168 * @param[in] value Value to store. 169 * 170 * @return Previous value of the atomic object. 171 */ 172 #define NRFX_ATOMIC_FETCH_STORE(p_data, value) nrfx_atomic_u32_fetch_store(p_data, value) 173 174 /** 175 * @brief Macro for running a bitwise OR operation on an atomic object and returning its previous value. 176 * 177 * @param[in] p_data Atomic memory pointer. 178 * @param[in] value Value of the second operand in the OR operation. 179 * 180 * @return Previous value of the atomic object. 181 */ 182 #define NRFX_ATOMIC_FETCH_OR(p_data, value) nrfx_atomic_u32_fetch_or(p_data, value) 183 184 /** 185 * @brief Macro for running a bitwise AND operation on an atomic object 186 * and returning its previous value. 187 * 188 * @param[in] p_data Atomic memory pointer. 189 * @param[in] value Value of the second operand in the AND operation. 190 * 191 * @return Previous value of the atomic object. 192 */ 193 #define NRFX_ATOMIC_FETCH_AND(p_data, value) nrfx_atomic_u32_fetch_and(p_data, value) 194 /** 195 * @brief Macro for running a bitwise XOR operation on an atomic object 196 * and returning its previous value. 197 * 198 * @param[in] p_data Atomic memory pointer. 199 * @param[in] value Value of the second operand in the XOR operation. 200 * 201 * @return Previous value of the atomic object. 202 */ 203 #define NRFX_ATOMIC_FETCH_XOR(p_data, value) nrfx_atomic_u32_fetch_xor(p_data, value) 204 205 /** 206 * @brief Macro for running an addition operation on an atomic object 207 * and returning its previous value. 208 * 209 * @param[in] p_data Atomic memory pointer. 210 * @param[in] value Value of the second operand in the ADD operation. 211 * 212 * @return Previous value of the atomic object. 213 */ 214 #define NRFX_ATOMIC_FETCH_ADD(p_data, value) nrfx_atomic_u32_fetch_add(p_data, value) 215 216 /** 217 * @brief Macro for running a subtraction operation on an atomic object 218 * and returning its previous value. 219 * 220 * @param[in] p_data Atomic memory pointer. 221 * @param[in] value Value of the second operand in the SUB operation. 222 * 223 * @return Previous value of the atomic object. 224 */ 225 #define NRFX_ATOMIC_FETCH_SUB(p_data, value) nrfx_atomic_u32_fetch_sub(p_data, value) 226 227 //------------------------------------------------------------------------------ 228 229 /** 230 * @brief When set to a non-zero value, this macro specifies that the 231 * @ref nrfx_error_codes and the @ref nrfx_err_t type itself are defined 232 * in a customized way and the default definitions from @c <nrfx_error.h> 233 * should not be used. 234 */ 235 #define NRFX_CUSTOM_ERROR_CODES 0 236 237 //------------------------------------------------------------------------------ 238 239 /** 240 * @brief When set to a non-zero value, this macro specifies that inside HALs 241 * the event registers are read back after clearing, on devices that 242 * otherwise could defer the actual register modification. 243 */ 244 #define NRFX_EVENT_READBACK_ENABLED 1 245 246 //------------------------------------------------------------------------------ 247 248 /** @brief Bitmask that defines DPPI channels that are reserved for use outside of the nrfx library. */ 249 #define NRFX_DPPI_CHANNELS_USED 0 250 251 /** @brief Bitmask that defines DPPI groups that are reserved for use outside of the nrfx library. */ 252 #define NRFX_DPPI_GROUPS_USED 0 253 254 /** @brief Bitmask that defines PPI channels that are reserved for use outside of the nrfx library. */ 255 #define NRFX_PPI_CHANNELS_USED 0 256 257 /** @brief Bitmask that defines PPI groups that are reserved for use outside of the nrfx library. */ 258 #define NRFX_PPI_GROUPS_USED 0 259 260 /** @brief Bitmask that defines EGU instances that are reserved for use outside of the nrfx library. */ 261 #define NRFX_EGUS_USED 0 262 263 /** @brief Bitmask that defines TIMER instances that are reserved for use outside of the nrfx library. */ 264 #define NRFX_TIMERS_USED 0 265 266 /** @} */ 267 268 #ifdef __cplusplus 269 } 270 #endif 271 272 #endif // NRFX_GLUE_H__ 273