1 /*
2 * Copyright (c) 2019 Oticon A/S
3 * Copyright (c) 2023 Nordic Semiconductor ASA
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 *
7 */
8
9 #include "nrfx.h"
10 #include "bs_tracing.h"
11
12 #define PERIPHERAL_REG_BASE(per, nbr, post) \
13 (void*)NRF_##per##nbr##post##_BASE
14
15 #define IS_PERIPHERAL_REG(p, per, nbr, post) \
16 (p >= PERIPHERAL_REG_BASE(per, nbr, post)) && \
17 ((intptr_t)p < (intptr_t)PERIPHERAL_REG_BASE(per, nbr, post) + sizeof(NRF_##per##_Type))
18
nrfx_get_irq_number(void const * p_reg)19 IRQn_Type nrfx_get_irq_number(void const * p_reg){
20
21 #if defined(NRF52833_XXAA)
22 /*
23 * Peripheral numbers match interrupt numbers
24 * See https://infocenter.nordicsemi.com/index.jsp?topic=%2Fstruct_nrf52%2Fstruct%2Fnrf52833.html
25 */
26
27 if (IS_PERIPHERAL_REG(p_reg, POWER,,)) {
28 return POWER_CLOCK_IRQn;
29 } else if (IS_PERIPHERAL_REG(p_reg, CLOCK,,)) {
30 return POWER_CLOCK_IRQn;
31 } else if (IS_PERIPHERAL_REG(p_reg, RADIO,,)) {
32 return RADIO_IRQn;
33 } else if (IS_PERIPHERAL_REG(p_reg, UARTE, 0,)) {
34 return UARTE0_UART0_IRQn;
35 /*3-5*/
36 } else if (IS_PERIPHERAL_REG(p_reg, GPIOTE,,)) {
37 return GPIOTE_IRQn;
38 /*7 SAADC_IRQn */
39 } else if (IS_PERIPHERAL_REG(p_reg, TIMER, 0,)) {
40 return TIMER0_IRQn;
41 } else if (IS_PERIPHERAL_REG(p_reg, TIMER, 1,)) {
42 return TIMER1_IRQn;
43 } else if (IS_PERIPHERAL_REG(p_reg, TIMER, 2,)) {
44 return TIMER2_IRQn;
45 } else if (IS_PERIPHERAL_REG(p_reg, RTC, 0,)) {
46 return RTC0_IRQn;
47 } else if (IS_PERIPHERAL_REG(p_reg, TEMP,,)) {
48 return TEMP_IRQn;
49 } else if (IS_PERIPHERAL_REG(p_reg, RNG,,)) {
50 return RNG_IRQn;
51 } else if (IS_PERIPHERAL_REG(p_reg, ECB,,)) {
52 return ECB_IRQn;
53 } else if (IS_PERIPHERAL_REG(p_reg, AAR,,)) {
54 return CCM_AAR_IRQn;
55 } else if (IS_PERIPHERAL_REG(p_reg, CCM,,)) {
56 return CCM_AAR_IRQn;
57 /*16 WDT_IRQn*/
58 } else if (IS_PERIPHERAL_REG(p_reg, RTC, 1,)) {
59 return RTC1_IRQn;
60 /*18-19*/
61 } else if (IS_PERIPHERAL_REG(p_reg, EGU, 0,)) {
62 return SWI0_EGU0_IRQn;
63 } else if (IS_PERIPHERAL_REG(p_reg, EGU, 1,)) {
64 return SWI1_EGU1_IRQn;
65 } else if (IS_PERIPHERAL_REG(p_reg, EGU, 2,)) {
66 return SWI2_EGU2_IRQn;
67 } else if (IS_PERIPHERAL_REG(p_reg, EGU, 3,)) {
68 return SWI3_EGU3_IRQn;
69 } else if (IS_PERIPHERAL_REG(p_reg, EGU, 4,)) {
70 return SWI4_EGU4_IRQn;
71 } else if (IS_PERIPHERAL_REG(p_reg, EGU, 5,)) {
72 return SWI5_EGU5_IRQn;
73 } else if (IS_PERIPHERAL_REG(p_reg, TIMER, 3,)) {
74 return TIMER3_IRQn;
75 } else if (IS_PERIPHERAL_REG(p_reg, TIMER, 4,)) {
76 return TIMER4_IRQn;
77 /*28-29*/
78 } else if (IS_PERIPHERAL_REG(p_reg, NVMC,,)) {
79 return 30;
80 } else if (IS_PERIPHERAL_REG(p_reg, PPI,,)) {
81 return 0x1F;
82 /*32-35*/
83 } else if (IS_PERIPHERAL_REG(p_reg, RTC, 2,)) {
84 return RTC2_IRQn;
85 /*37-39*/
86 } else if (IS_PERIPHERAL_REG(p_reg, UARTE, 1,)) {
87 return UARTE1_IRQn;
88 /*40-47*/
89 } else {
90 bs_trace_error_time_line("Tried to get the peripheral number of an address unknown to these HW models\n");
91 return 0; /* unreachable */
92 }
93
94
95 #elif defined(NRF5340_XXAA_NETWORK)
96
97 if (IS_PERIPHERAL_REG(p_reg, POWER,, _NS)) {
98 return CLOCK_POWER_IRQn;
99 } else if (IS_PERIPHERAL_REG(p_reg, CLOCK,, _NS)) {
100 return CLOCK_POWER_IRQn;
101 } else if (IS_PERIPHERAL_REG(p_reg, RADIO,, _NS)) {
102 return RADIO_IRQn;
103 } else if (IS_PERIPHERAL_REG(p_reg, RNG,, _NS)) {
104 return RNG_IRQn;
105 } else if (IS_PERIPHERAL_REG(p_reg, GPIOTE,, _NS)) {
106 return GPIOTE_IRQn;
107 /* 11 WDT */
108 } else if (IS_PERIPHERAL_REG(p_reg, TIMER, 0, _NS)) {
109 return TIMER0_IRQn;
110 } else if (IS_PERIPHERAL_REG(p_reg, ECB,, _NS)) {
111 return ECB_IRQn;
112 } else if (IS_PERIPHERAL_REG(p_reg, AAR,, _NS)) {
113 return AAR_CCM_IRQn;
114 } else if (IS_PERIPHERAL_REG(p_reg, CCM,, _NS)) {
115 return AAR_CCM_IRQn;
116 } else if (IS_PERIPHERAL_REG(p_reg, TEMP,, _NS)) {
117 return TEMP_IRQn;
118 } else if (IS_PERIPHERAL_REG(p_reg, RTC, 0, _NS)) {
119 return RTC0_IRQn;
120 } else if (IS_PERIPHERAL_REG(p_reg, IPC,, _NS)) {
121 return IPC_IRQn;
122 } else if (IS_PERIPHERAL_REG(p_reg, UARTE, 0, _NS)) {
123 return SERIAL0_IRQn;
124 } else if (IS_PERIPHERAL_REG(p_reg, EGU, 0, _NS)) {
125 return EGU0_IRQn;
126 } else if (IS_PERIPHERAL_REG(p_reg, RTC, 1, _NS)) {
127 return RTC1_IRQn;
128 } else if (IS_PERIPHERAL_REG(p_reg, TIMER, 1, _NS)) {
129 return TIMER1_IRQn;
130 } else if (IS_PERIPHERAL_REG(p_reg, TIMER, 2, _NS)) {
131 return TIMER2_IRQn;
132 } else if (IS_PERIPHERAL_REG(p_reg, SWI, 0, _NS)) {
133 return SWI0_IRQn;
134 } else if (IS_PERIPHERAL_REG(p_reg, SWI, 1, _NS)) {
135 return SWI1_IRQn;
136 } else if (IS_PERIPHERAL_REG(p_reg, SWI, 2, _NS)) {
137 return SWI2_IRQn;
138 } else if (IS_PERIPHERAL_REG(p_reg, SWI, 3, _NS)) {
139 return SWI3_IRQn;
140 } else {
141 bs_trace_error_time_line("Tried to get the peripheral number of an address unknown to these HW models\n");
142 return 0; /* unreachable */
143 }
144 #elif defined(NRF5340_XXAA_APPLICATION)
145
146 /* 0 FPU */
147 /* 1 CACHE */
148 /* 3 SPU */
149 if (IS_PERIPHERAL_REG(p_reg, POWER,, _S)) {
150 return CLOCK_POWER_IRQn;
151 } else if (IS_PERIPHERAL_REG(p_reg, CLOCK,, _S)) {
152 return CLOCK_POWER_IRQn;
153 } else if (IS_PERIPHERAL_REG(p_reg, UARTE, 0, _S)) {
154 return SERIAL0_IRQn;
155 } else if (IS_PERIPHERAL_REG(p_reg, UARTE, 1, _S)) {
156 return SERIAL1_IRQn;
157 /* 10 SPIM4 */
158 } else if (IS_PERIPHERAL_REG(p_reg, UARTE, 2, _S)) {
159 return SERIAL2_IRQn;
160 } else if (IS_PERIPHERAL_REG(p_reg, UARTE, 3, _S)) {
161 return SERIAL3_IRQn;
162 } else if (IS_PERIPHERAL_REG(p_reg, GPIOTE, 0, _S)) {
163 return GPIOTE0_IRQn;
164 /* 14 SAADC */
165 } else if (IS_PERIPHERAL_REG(p_reg, TIMER, 0, _S)) {
166 return TIMER0_IRQn;
167 } else if (IS_PERIPHERAL_REG(p_reg, TIMER, 1, _S)) {
168 return TIMER1_IRQn;
169 } else if (IS_PERIPHERAL_REG(p_reg, TIMER, 2, _S)) {
170 return TIMER2_IRQn;
171 } else if (IS_PERIPHERAL_REG(p_reg, RTC, 0, _S)) {
172 return RTC0_IRQn;
173 } else if (IS_PERIPHERAL_REG(p_reg, RTC, 1, _S)) {
174 return RTC1_IRQn;
175 /* 24, 25 WDT0,1 */
176 /* 26 COMP */
177 } else if (IS_PERIPHERAL_REG(p_reg, EGU, 0, _S)) {
178 return EGU0_IRQn;
179 } else if (IS_PERIPHERAL_REG(p_reg, EGU, 1, _S)) {
180 return EGU1_IRQn;
181 } else if (IS_PERIPHERAL_REG(p_reg, EGU, 2, _S)) {
182 return EGU2_IRQn;
183 } else if (IS_PERIPHERAL_REG(p_reg, EGU, 3, _S)) {
184 return EGU3_IRQn;
185 } else if (IS_PERIPHERAL_REG(p_reg, EGU, 4, _S)) {
186 return EGU4_IRQn;
187 } else if (IS_PERIPHERAL_REG(p_reg, EGU, 5, _S)) {
188 return EGU5_IRQn;
189 /* 33-36 PWM0-3*/
190 /* 38 PDM0 */
191 /* 40 I2S */
192 } else if (IS_PERIPHERAL_REG(p_reg, IPC,, _S)) {
193 return IPC_IRQn;
194 /* 43 QPSI */
195 /* 45 NFCT */
196 } else if (IS_PERIPHERAL_REG(p_reg, GPIOTE, 1, _NS)) {
197 return GPIOTE1_IRQn;
198 /* 51,52 QDEC0,1*/
199 /* 54 USBD*/
200 /* 55 USBREGULATOR*/
201 /* 57 KMU */
202 /* 68 CRYPTOCELL */
203 } else {
204 bs_trace_error_time_line("Tried to get the peripheral number of an address unknown to these HW models\n");
205 return 0; /* unreachable */
206 }
207
208
209 #elif defined(NRF54L15_XXAA) && defined(NRF_APPLICATION)
210
211 /* 28..63 :not real */
212 if (IS_PERIPHERAL_REG(p_reg, SPU, 00, _S)) {
213 return SPU00_IRQn;
214 } else if (IS_PERIPHERAL_REG(p_reg, MPC, 00, _S)) {
215 return MPC00_IRQn;
216 } else if (IS_PERIPHERAL_REG(p_reg, AAR, 00, _S)) {
217 return AAR00_CCM00_IRQn;
218 } else if (IS_PERIPHERAL_REG(p_reg, CCM, 00, _S)) {
219 return AAR00_CCM00_IRQn;
220 } else if (IS_PERIPHERAL_REG(p_reg, ECB, 00, _S)) {
221 return ECB00_IRQn;
222 } else if (IS_PERIPHERAL_REG(p_reg, CRACEN, , _S)) {
223 return CRACEN_IRQn;
224 } else if (IS_PERIPHERAL_REG(p_reg, UARTE, 00, _S)) {
225 return SERIAL00_IRQn;
226 } else if (IS_PERIPHERAL_REG(p_reg, RRAMC, , _S)) {
227 return RRAMC_IRQn;
228 } else if (IS_PERIPHERAL_REG(p_reg, VPR, 00, _S)) {
229 return VPR00_IRQn;
230 /* CTRLAP */
231 /* CM33S */
232 } else if (IS_PERIPHERAL_REG(p_reg, TIMER, 00, _S)) {
233 return TIMER00_IRQn;
234 } else if (IS_PERIPHERAL_REG(p_reg, SPU, 10, _S)) {
235 return SPU10_IRQn;
236 } else if (IS_PERIPHERAL_REG(p_reg, TIMER, 10, _S)) {
237 return TIMER10_IRQn;
238 } else if (IS_PERIPHERAL_REG(p_reg, RTC, 10, _S)) {
239 return RTC10_IRQn;
240 } else if (IS_PERIPHERAL_REG(p_reg, EGU, 10, _S)) {
241 return EGU10_IRQn;
242 } else if (IS_PERIPHERAL_REG(p_reg, RADIO, , _S)) {
243 return RADIO_0_IRQn;
244 /* Note RADIO has 2 interrupts */
245 } else if (IS_PERIPHERAL_REG(p_reg, SPU, 20, _S)) {
246 return SPU20_IRQn;
247 } else if (IS_PERIPHERAL_REG(p_reg, UARTE, 20, _S)) {
248 return SERIAL20_IRQn;
249 } else if (IS_PERIPHERAL_REG(p_reg, UARTE, 21, _S)) {
250 return SERIAL21_IRQn;
251 } else if (IS_PERIPHERAL_REG(p_reg, UARTE, 22, _S)) {
252 return SERIAL22_IRQn;
253 } else if (IS_PERIPHERAL_REG(p_reg, EGU, 20, _S)) {
254 return EGU20_IRQn;
255 } else if (IS_PERIPHERAL_REG(p_reg, TIMER, 20, _S)) {
256 return TIMER20_IRQn;
257 } else if (IS_PERIPHERAL_REG(p_reg, TIMER, 21, _S)) {
258 return TIMER21_IRQn;
259 } else if (IS_PERIPHERAL_REG(p_reg, TIMER, 22, _S)) {
260 return TIMER22_IRQn;
261 } else if (IS_PERIPHERAL_REG(p_reg, TIMER, 23, _S)) {
262 return TIMER23_IRQn;
263 } else if (IS_PERIPHERAL_REG(p_reg, TIMER, 24, _S)) {
264 return TIMER24_IRQn;
265 } else if (IS_PERIPHERAL_REG(p_reg, PDM, 20, _S)) {
266 return PDM20_IRQn;
267 } else if (IS_PERIPHERAL_REG(p_reg, PDM, 21, _S)) {
268 return PDM21_IRQn;
269 } else if (IS_PERIPHERAL_REG(p_reg, PWM, 20, _S)) {
270 return PWM20_IRQn;
271 } else if (IS_PERIPHERAL_REG(p_reg, PWM, 21, _S)) {
272 return PWM21_IRQn;
273 } else if (IS_PERIPHERAL_REG(p_reg, PWM, 22, _S)) {
274 return PWM22_IRQn;
275 } else if (IS_PERIPHERAL_REG(p_reg, SAADC, , _S)) {
276 return SAADC_IRQn;
277 } else if (IS_PERIPHERAL_REG(p_reg, NFCT, , _S)) {
278 return NFCT_IRQn;
279 } else if (IS_PERIPHERAL_REG(p_reg, TEMP, , _S)) {
280 return TEMP_IRQn;
281 } else if (IS_PERIPHERAL_REG(p_reg, GPIOTE, 20, _S)) {
282 return GPIOTE20_0_IRQn;
283 /* Note GPIO20 has two interrupts */
284 } else if (IS_PERIPHERAL_REG(p_reg, TAMPC, , _S)) {
285 return TAMPC_IRQn;
286 } else if (IS_PERIPHERAL_REG(p_reg, I2S, 20, _S)) {
287 return I2S20_IRQn;
288 } else if (IS_PERIPHERAL_REG(p_reg, QDEC, 20, _S)) {
289 return QDEC20_IRQn;
290 } else if (IS_PERIPHERAL_REG(p_reg, QDEC, 21, _S)) {
291 return QDEC21_IRQn;
292 } else if (IS_PERIPHERAL_REG(p_reg, GRTC, , _S)) {
293 return GRTC_0_IRQn;
294 /* Note GRTC has 4 interrupts */
295 } else if (IS_PERIPHERAL_REG(p_reg, SPU, 30, _S)) {
296 return SPU30_IRQn;
297 } else if (IS_PERIPHERAL_REG(p_reg, UARTE, 30, _S)) {
298 return SERIAL30_IRQn;
299 } else if (IS_PERIPHERAL_REG(p_reg, RTC, 30, _S)) {
300 return RTC30_IRQn;
301 } else if (IS_PERIPHERAL_REG(p_reg, COMP, , _S)) {
302 return COMP_LPCOMP_IRQn;
303 } else if (IS_PERIPHERAL_REG(p_reg, WDT, 30, _S)) {
304 return WDT30_IRQn;
305 } else if (IS_PERIPHERAL_REG(p_reg, WDT, 31, _S)) {
306 return WDT31_IRQn;
307 } else if (IS_PERIPHERAL_REG(p_reg, GPIOTE, 30, _S)) {
308 return GPIOTE30_0_IRQn;
309 /* Note GPIO20 has two interrupts */
310 } else if (IS_PERIPHERAL_REG(p_reg, CLOCK, , _S)) {
311 return CLOCK_POWER_IRQn;
312 } else if (IS_PERIPHERAL_REG(p_reg, POWER, , _S)) {
313 return CLOCK_POWER_IRQn;
314 } else {
315 bs_trace_error_time_line("Tried to get the peripheral number of an address unknown to these HW models\n");
316 return 0; /* unreachable */
317 }
318
319 #else
320 #error "Unsuported SOC/cpu"
321 #endif
322
323 }
324