1 /*
2 * Copyright (c) 2023 - 2025, Nordic Semiconductor ASA
3 * All rights reserved.
4 *
5 * SPDX-License-Identifier: BSD-3-Clause
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are met:
9 *
10 * 1. Redistributions of source code must retain the above copyright notice, this
11 * list of conditions and the following disclaimer.
12 *
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 *
17 * 3. Neither the name of the copyright holder nor the names of its
18 * contributors may be used to endorse or promote products derived from this
19 * software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
25 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
32 */
33 #include <nrfx.h>
34
35 #if defined(HALTIUM_XXAA)
36
37 #include <soc/interconnect/apb/nrfx_interconnect_apb_haltium_global.h>
38 #include <soc/interconnect/apb/nrfx_interconnect_apb.h>
39
40 #if defined(NRF_RADIOCORE)
41 #include <soc/interconnect/apb/nrfx_interconnect_apb_haltium_radiocore.h>
42 #elif defined(NRF_APPLICATION)
43 #include <soc/interconnect/apb/nrfx_interconnect_apb_haltium_application.h>
44 #elif defined(NRF_PPR)
45 #include <soc/interconnect/apb/nrfx_interconnect_apb_haltium_ppr.h>
46 #elif defined(NRF_FLPR)
47 #include <soc/interconnect/apb/nrfx_interconnect_apb_haltium_flpr.h>
48 #else
49 #include <soc/interconnect/apb/nrfx_interconnect_apb_haltium_ext.h>
50 #endif
51
52 NRFX_INTERCONNECT_APB_GLOBAL_DPPI_DEFINE;
53 NRFX_INTERCONNECT_APB_LOCAL_DPPI_DEFINE;
54 static const nrfx_interconnect_apb_t m_local_apb_interconnect[] =
55 NRFX_INTERCONNECT_APB_LOCAL_BUSES_PROP;
56 static const nrfx_interconnect_apb_t m_global_apb_interconnect[] =
57 NRFX_INTERCONNECT_APB_GLOBAL_BUSES_PROP;
58
nrfx_interconnect_apb_domain_get(nrfx_interconnect_apb_t const * p_apb_prop)59 nrf_domain_t nrfx_interconnect_apb_domain_get(nrfx_interconnect_apb_t const * p_apb_prop)
60 {
61 return (nrf_domain_t)nrf_address_domain_get((uint32_t)p_apb_prop->p_dppi);
62 }
63
64 /* Set of macros to allow calculation of array index where given index is located.
65 * We create a structure with fields for each instance which has non-zero
66 * CHANNEL_MASK. Then offsetof is used to get the index of the given instance.
67 */
68 #define _APB_STRUCT_ELEM(periph_name, prefix, inst_num, _) \
69 NRFX_COND_CODE_0(prefix, (), \
70 (NRFX_COND_CODE_1(NRFX_DPPI_OWNED_MASK(inst_num), \
71 (uint8_t NRFX_CONCAT(dummy, inst_num);), ())))
72
73 #define APB_IDX_STRUCT() \
74 struct apb_idx_dummy_struct { \
75 NRFX_FOREACH_PRESENT(DPPIC, _APB_STRUCT_ELEM, (), (), _) \
76 }
77
78 #define APB_IDX(inst_num) \
79 NRFX_COND_CODE_1(NRFX_DPPI_OWNED_MASK(inst_num), \
80 (offsetof(struct apb_idx_dummy_struct, NRFX_CONCAT(dummy, inst_num))), \
81 (-1))
82
83 APB_IDX_STRUCT();
84
85 static const int apb_main_idx = APB_IDX(NRFX_INTERCONNECT_MAIN_DPPI_INSTANCE);
86
nrfx_interconnect_apb_main_get(void)87 nrfx_interconnect_apb_t const * nrfx_interconnect_apb_main_get(void)
88 {
89 return apb_main_idx >= 0 ? &m_global_apb_interconnect[apb_main_idx] : NULL;
90 }
91
nrfx_interconnect_apb_get(uint32_t addr)92 nrfx_interconnect_apb_t const * nrfx_interconnect_apb_get(uint32_t addr)
93 {
94 nrf_domain_t domain = (nrf_domain_t)nrf_address_domain_get(addr);
95 uint32_t num_of_entries;
96 nrfx_interconnect_apb_t const * apb_interconnect;
97 if (domain == NRF_DOMAIN_GLOBAL)
98 {
99 num_of_entries = NRFX_ARRAY_SIZE(m_global_apb_interconnect);
100 apb_interconnect = m_global_apb_interconnect;
101 }
102 else
103 {
104 num_of_entries = NRFX_ARRAY_SIZE(m_local_apb_interconnect);
105 apb_interconnect = m_local_apb_interconnect;
106 }
107
108 for (uint8_t i = 0; i < num_of_entries; i++)
109 {
110 nrfx_interconnect_apb_t const * p_apb = &apb_interconnect[i];
111 uint8_t bus_address_area = nrf_address_bus_get(addr, p_apb->size);
112
113 if (bus_address_area == nrf_address_bus_get((uint32_t)p_apb->p_dppi, p_apb->size))
114 {
115 return p_apb;
116 }
117 }
118 return NULL;
119 }
120
nrfx_interconnect_apb_global_num_of_get(void)121 size_t nrfx_interconnect_apb_global_num_of_get(void)
122 {
123 return NRFX_ARRAY_SIZE(m_global_apb_interconnect);
124 }
125
nrf_apb_interconnect_by_idx_global_get(uint8_t idx)126 nrfx_interconnect_apb_t const * nrf_apb_interconnect_by_idx_global_get(uint8_t idx)
127 {
128 return idx < NRFX_ARRAY_SIZE(m_global_apb_interconnect) ? &m_global_apb_interconnect[idx] : NULL;
129 }
130
131 #endif // defined(HALTIUM_XXAA)
132