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