blob: cdf49b4ab7fb00ee29606bc3106258bdb1b9df4a [file] [log] [blame]
Austin Schuh41baf202022-01-01 14:33:40 -08001/*
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
42extern "C" {
43#endif
44
45/**
46 * @defgroup nrfx_glue nrfx_glue.h
47 * @{
48 * @ingroup nrfx
49 *
50 * @brief This file contains macros that should be implemented according to
51 * the needs of the host environment into which @em nrfx is integrated.
52 */
53
54// Uncomment this line to use the standard MDK way of binding IRQ handlers
55// at linking time.
56#include <soc/nrfx_irqs.h>
57
58//------------------------------------------------------------------------------
59
60/**
61 * @brief Macro for placing a runtime assertion.
62 *
63 * @param expression Expression to evaluate.
64 */
65#define NRFX_ASSERT(expression)
66
67/**
68 * @brief Macro for placing a compile time assertion.
69 *
70 * @param expression Expression to evaluate.
71 */
72#define NRFX_STATIC_ASSERT(expression)
73
74//------------------------------------------------------------------------------
75
76/**
77 * @brief Macro for setting the priority of a specific IRQ.
78 *
79 * @param irq_number IRQ number.
80 * @param priority Priority to set.
81 */
82#define NRFX_IRQ_PRIORITY_SET(irq_number, priority) _NRFX_IRQ_PRIORITY_SET(irq_number, priority)
83static inline void _NRFX_IRQ_PRIORITY_SET(IRQn_Type irq_number,
84 uint8_t priority)
85{
86 NRFX_ASSERT(INTERRUPT_PRIORITY_IS_VALID(priority));
87 NVIC_SetPriority(irq_number, priority);
88}
89
90/**
91 * @brief Macro for enabling a specific IRQ.
92 *
93 * @param irq_number IRQ number.
94 */
95#define NRFX_IRQ_ENABLE(irq_number) _NRFX_IRQ_ENABLE(irq_number)
96static inline void _NRFX_IRQ_ENABLE(IRQn_Type irq_number)
97{
98 NVIC_ClearPendingIRQ(irq_number);
99 NVIC_EnableIRQ(irq_number);
100}
101
102/**
103 * @brief Macro for checking if a specific IRQ is enabled.
104 *
105 * @param irq_number IRQ number.
106 *
107 * @retval true If the IRQ is enabled.
108 * @retval false Otherwise.
109 */
110#define NRFX_IRQ_IS_ENABLED(irq_number) _NRFX_IRQ_IS_ENABLED(irq_number)
111static inline bool _NRFX_IRQ_IS_ENABLED(IRQn_Type irq_number)
112{
113 return 0 != (NVIC->ISER[irq_number / 32] & (1UL << (irq_number % 32)));
114}
115
116/**
117 * @brief Macro for disabling a specific IRQ.
118 *
119 * @param irq_number IRQ number.
120 */
121#define NRFX_IRQ_DISABLE(irq_number) _NRFX_IRQ_DISABLE(irq_number)
122static inline void _NRFX_IRQ_DISABLE(IRQn_Type irq_number)
123{
124 NVIC_DisableIRQ(irq_number);
125}
126
127/**
128 * @brief Macro for setting a specific IRQ as pending.
129 *
130 * @param irq_number IRQ number.
131 */
132#define NRFX_IRQ_PENDING_SET(irq_number) _NRFX_IRQ_PENDING_SET(irq_number)
133static inline void _NRFX_IRQ_PENDING_SET(IRQn_Type irq_number)
134{
135 NVIC_SetPendingIRQ(irq_number);
136}
137
138/**
139 * @brief Macro for clearing the pending status of a specific IRQ.
140 *
141 * @param irq_number IRQ number.
142 */
143#define NRFX_IRQ_PENDING_CLEAR(irq_number) _NRFX_IRQ_PENDING_CLEAR(irq_number)
144static inline void _NRFX_IRQ_PENDING_CLEAR(IRQn_Type irq_number)
145{
146 NVIC_ClearPendingIRQ(irq_number);
147}
148
149/**
150 * @brief Macro for checking the pending status of a specific IRQ.
151 *
152 * @retval true If the IRQ is pending.
153 * @retval false Otherwise.
154 */
155#define NRFX_IRQ_IS_PENDING(irq_number) _NRFX_IRQ_IS_PENDING(irq_number)
156static inline bool _NRFX_IRQ_IS_PENDING(IRQn_Type irq_number)
157{
158 return (NVIC_GetPendingIRQ(irq_number) == 1);
159}
160
161/**
162 * @brief Macro for entering into a critical section.
163 */
164#define NRFX_CRITICAL_SECTION_ENTER()
165
166/**
167 * @brief Macro for exiting from a critical section.
168 */
169#define NRFX_CRITICAL_SECTION_EXIT()
170
171//------------------------------------------------------------------------------
172
173/**
174 * @brief When set to a non-zero value, this macro specifies that
175 * @ref nrfx_coredep_delay_us uses a precise DWT-based solution.
176 * A compilation error is generated if the DWT unit is not present
177 * in the SoC used.
178 */
179#define NRFX_DELAY_DWT_BASED 0
180
181/**
182 * @brief Macro for delaying the code execution for at least the specified time.
183 *
184 * @param us_time Number of microseconds to wait.
185 */
186#include <soc/nrfx_coredep.h>
187#define NRFX_DELAY_US(us_time) nrfx_coredep_delay_us(us_time)
188
189//------------------------------------------------------------------------------
190
191/**
192 * @brief When set to a non-zero value, this macro specifies that the
193 * @ref nrfx_error_codes and the @ref nrfx_err_t type itself are defined
194 * in a customized way and the default definitions from @c <nrfx_error.h>
195 * should not be used.
196 */
197#define NRFX_CUSTOM_ERROR_CODES 0
198
199//------------------------------------------------------------------------------
200
201/**
202 * @brief Bitmask defining PPI channels reserved to be used outside of nrfx.
203 */
204#define NRFX_PPI_CHANNELS_USED 0
205
206/**
207 * @brief Bitmask defining PPI groups reserved to be used outside of nrfx.
208 */
209#define NRFX_PPI_GROUPS_USED 0
210
211/**
212 * @brief Bitmask defining SWI instances reserved to be used outside of nrfx.
213 */
214#define NRFX_SWI_USED 0
215
216/**
217 * @brief Bitmask defining TIMER instances reserved to be used outside of nrfx.
218 */
219#define NRFX_TIMERS_USED 0
220
221/** @} */
222
223#ifdef __cplusplus
224}
225#endif
226
227#endif // NRFX_GLUE_H__