Contiki-NG
Loading...
Searching...
No Matches
nrfx_glue.h
Go to the documentation of this file.
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 "sys/cc.h"
36
37#ifdef __cplusplus
38extern "C" {
39#endif
40
41/**
42 * \addtogroup nrf
43 * @{
44 *
45 * \file
46 * Header with nrfx stub defines
47 * \author
48 * Yago Fontoura do Rosario <yago.rosario@hotmail.com.br>
49 */
50
51#include <nrf.h>
52
53/*
54 * nRF54L15 GRTC IRQ workaround:
55 * The MDK defines GRTC_IRQn as GRTC_0_IRQn, but the nrfx GRTC HAL will try to
56 * redefine it to GRTC_2_IRQn for NRF_APPLICATION && !NRF_TRUSTZONE_NONSECURE.
57 * Undefine the MDK's definition here to allow the HAL's redefinition to proceed
58 * without error. Individual files using GRTC_0 can explicitly use GRTC_0_IRQn.
59 */
60#if defined(NRF54L15_XXAA) && defined(GRTC_IRQn)
61#undef GRTC_IRQn
62#undef GRTC_IRQHandler
63#endif
64
65#include <soc/nrfx_irqs.h>
66#include <soc/nrfx_atomic.h>
67#include <soc/nrfx_coredep.h>
68
69/*------------------------------------------------------------------------------ */
70
71/**
72 * @brief Macro for placing a runtime assertion.
73 *
74 * @param expression Expression to evaluate.
75 */
76#define NRFX_ASSERT(expression)
77
78/**
79 * @brief Macro for placing a compile time assertion.
80 *
81 * @param expression Expression to evaluate.
82 */
83#define NRFX_STATIC_ASSERT(expression)
84
85/*------------------------------------------------------------------------------ */
86
87/**
88 * @brief Macro for setting the priority of a specific IRQ.
89 *
90 * @param irq_number IRQ number.
91 * @param priority Priority to be set.
92 */
93#define NRFX_IRQ_PRIORITY_SET(irq_number, priority) \
94 _NRFX_IRQ_PRIORITY_SET(irq_number, priority)
95static inline void
96_NRFX_IRQ_PRIORITY_SET(IRQn_Type irq_number,
97 uint8_t priority)
98{
99 NVIC_SetPriority(irq_number, priority);
100}
101/**
102 * @brief Macro for enabling a specific IRQ.
103 *
104 * @param irq_number IRQ number.
105 */
106#define NRFX_IRQ_ENABLE(irq_number) _NRFX_IRQ_ENABLE(irq_number)
107static inline void
108_NRFX_IRQ_ENABLE(IRQn_Type irq_number)
109{
110 NVIC_EnableIRQ(irq_number);
111}
112/**
113 * @brief Macro for checking if a specific IRQ is enabled.
114 *
115 * @param irq_number IRQ number.
116 *
117 * @retval true If the IRQ is enabled.
118 * @retval false Otherwise.
119 */
120#define NRFX_IRQ_IS_ENABLED(irq_number) _NRFX_IRQ_IS_ENABLED(irq_number)
121static inline bool
122_NRFX_IRQ_IS_ENABLED(IRQn_Type irq_number)
123{
124 return 0 != (NVIC->ISER[irq_number / 32] & (1UL << (irq_number % 32)));
125}
126/**
127 * @brief Macro for disabling a specific IRQ.
128 *
129 * @param irq_number IRQ number.
130 */
131#define NRFX_IRQ_DISABLE(irq_number) _NRFX_IRQ_DISABLE(irq_number)
132static inline void
133_NRFX_IRQ_DISABLE(IRQn_Type irq_number)
134{
135 NVIC_DisableIRQ(irq_number);
136}
137/**
138 * @brief Macro for clearing the pending status of a specific IRQ.
139 *
140 * @param irq_number IRQ number.
141 */
142#define NRFX_IRQ_PENDING_CLEAR(irq_number) _NVIC_ClearPendingIRQ(irq_number)
143static inline void
144_NVIC_ClearPendingIRQ(IRQn_Type irq_number)
145{
146 NVIC_ClearPendingIRQ(irq_number);
147}
148/**
149 * @brief Macro for setting the pending status of a specific IRQ.
150 *
151 * @param irq_number IRQ number.
152 */
153#define NRFX_IRQ_PENDING_SET(irq_number) _NVIC_SetPendingIRQ(irq_number)
154static inline void
155_NVIC_SetPendingIRQ(IRQn_Type irq_number)
156{
157 NVIC_SetPendingIRQ(irq_number);
158}
159/**
160 * @brief Macro for entering into a critical section.
161 *
162 * Uses PRIMASK save/restore to support proper nesting. The original
163 * __disable_irq()/__enable_irq() pair was non-nesting: EXIT would
164 * unconditionally re-enable interrupts even if the caller had already
165 * disabled them, breaking e.g. the nrf_802154 radio driver's own
166 * critical sections.
167 */
168#define NRFX_CRITICAL_SECTION_ENTER() { uint32_t _nrfx_pm = __get_PRIMASK(); __disable_irq()
169
170/**
171 * @brief Macro for exiting from a critical section.
172 */
173#define NRFX_CRITICAL_SECTION_EXIT() __set_PRIMASK(_nrfx_pm); }
174
175/*------------------------------------------------------------------------------ */
176
177/**
178 * @brief Macro for counting trailing zeros.
179 *
180 * @param[in] value A word value.
181 *
182 * @return Number of trailing 0-bits in @p value, starting at the least significant bit position.
183 * If x is 0, the result is undefined.
184 */
185#define NRFX_CTZ(value) __builtin_ctz(value)
186
187/*------------------------------------------------------------------------------ */
188
189#define NRFX_DELAY_US(us_time) nrfx_coredep_delay_us(us_time)
190
191/*------------------------------------------------------------------------------ */
192
193/** @brief Atomic 32-bit unsigned type. */
194#define nrfx_atomic_t uint32_t
195
196/**
197 * @brief Macro for running a bitwise AND operation on an atomic object
198 * and returning its previous value.
199 *
200 * @param[in] p_data Atomic memory pointer.
201 * @param[in] value Value of the second operand in the AND operation.
202 *
203 * @return Previous value of the atomic object.
204 */
205#define NRFX_ATOMIC_FETCH_AND(p_data, value) nrfx_atomic_u32_fetch_and(p_data, value)
206#define NRFX_ATOMIC_FETCH_OR(p_data, value) nrfx_atomic_u32_fetch_or(p_data, value)
207
208/*------------------------------------------------------------------------------ */
209
210/** @} */
211
212#ifdef __cplusplus
213}
214#endif
215
216#endif // NRFX_GLUE_H__
Default definitions of C compiler quirk work-arounds.