1 /*
2  * Copyright (c) 2022 - 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 
34 #ifndef NRFX_INTERCONNECT_IPCT_HALTIUM_GLOBAL_H__
35 #define NRFX_INTERCONNECT_IPCT_HALTIUM_GLOBAL_H__
36 
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40 
41 /* Instance of the IPCT peripheral which belongs to the main APB bus. */
42 #define NRFX_INTERCONNECT_MAIN_IPCT_INSTANCE 130
43 
44 #ifndef NRFX_INTERCONNECT_IPCT_GLOBAL_DEFINE
45 /* Default IPCT static variables generation in case of bare-metal application. */
46 #ifndef NRFX_IPCTx_CHANNELS_SINGLE_VAR_NAME_BY_INST_NUM
47 #define NRFX_IPCTx_CHANNELS_SINGLE_VAR_NAME_BY_INST_NUM(inst_num) \
48         NRFX_CONCAT(m_ipct, inst_num, _channels)
49 #else
50 #error "Invalid set of configuration for IPCT."
51 #endif
52 
53 #ifndef NRFX_IPCTx_CONFIG_OWNED_CHANNELS_MASK_BY_INST_NUM
54 #define NRFX_IPCTx_CONFIG_OWNED_CHANNELS_MASK_BY_INST_NUM(inst_num) \
55         NRFX_CONCAT(NRFX_IPCT, inst_num, _CONFIG_OWNED_CHANNELS_MASK)
56 #else
57 #error Invalid set of configuration for IPCT.
58 #endif
59 
60 #ifndef NRFX_IPCTx_PUB_CONFIG_ALLOWED_CHANNELS_MASK_BY_INST_NUM
61 #define NRFX_IPCTx_PUB_CONFIG_ALLOWED_CHANNELS_MASK_BY_INST_NUM(inst_num) \
62         NRFX_CONCAT(NRFX_IPCT, inst_num, _PUB_CONFIG_ALLOWED_CHANNELS_MASK)
63 #else
64 #error "Invalid set of configuration for IPCT."
65 #endif
66 
67 #ifndef NRFX_IPCTx_SUB_CONFIG_ALLOWED_CHANNELS_MASK_BY_INST_NUM
68 #define NRFX_IPCTx_SUB_CONFIG_ALLOWED_CHANNELS_MASK_BY_INST_NUM(inst_num) \
69         NRFX_CONCAT(NRFX_IPCT, inst_num, _SUB_CONFIG_ALLOWED_CHANNELS_MASK)
70 #else
71 #error "Invalid set of configuration for IPCT."
72 #endif
73 
74 /* Macro checks if owned inst_num mask is not zero and then returns 1, else 0 */
75 #ifdef NRF_SECURE
76 #define NRFX_IPCT_OWNED_MASK(inst_num) 1
77 #else
78 #define NRFX_IPCT_OWNED_MASK(inst_num) \
79     NRFX_COND_CODE_0(NRFX_IPCTx_CONFIG_OWNED_CHANNELS_MASK_BY_INST_NUM(inst_num), (0), (1))
80 #endif
81 
82 #define NRFX_IPCT_CHANNELS_ENTRY(inst_num)                                               \
83     NRFX_COND_CODE_1(NRFX_IPCT_OWNED_MASK(inst_num), \
84             ( \
85               NRFX_CONCAT(static nrfx_atomic_t m_ipct, inst_num, _channels __attribute__((used)) = \
86                 NRFX_IPCTx_PUB_CONFIG_ALLOWED_CHANNELS_MASK_BY_INST_NUM(inst_num) |      \
87                 NRFX_IPCTx_SUB_CONFIG_ALLOWED_CHANNELS_MASK_BY_INST_NUM(inst_num)); \
88             ), ())
89 
90 /* Global entry discard case when instance has no inst_num (NRF_IPCT) which is a local
91  * instance.
92  */
93 #define _NRFX_IPCT_CHANNELS_ENTRY(periph_name, prefix, inst_num, _) \
94     NRFX_COND_CODE_1(NRFX_IS_EMPTY(inst_num), (), (NRFX_IPCT_CHANNELS_ENTRY(inst_num)))
95 
96 #define NRFX_INTERCONNECT_IPCT_GLOBAL_DEFINE \
97         NRFX_FOREACH_PRESENT(IPCT, _NRFX_IPCT_CHANNELS_ENTRY, (), (), _)
98 #else
99 #ifndef NRFX_IPCT_OWNED_MASK
100 #define NRFX_IPCT_OWNED_MASK NRFX_IPCT_PUB_OR_SUB_MASK
101 #endif
102 #endif // NRFX_INTERCONNECT_IPCT_GLOBAL_DEFINE
103 
104 #define _NRFX_IPCT_INSTANCE(inst_num) NRFX_CONCAT(NRF_, IPCT, inst_num)
105 
106 #define NRFX_INTERCONNECT_IPCT_PROP_ENTRY(inst_num)                                               \
107     NRFX_COND_CODE_1(NRFX_IPCT_OWNED_MASK(inst_num), \
108     ({                                                                                             \
109             .p_ipct                 = _NRFX_IPCT_INSTANCE(inst_num),                               \
110             .p_ipct_channels        = &NRFX_IPCTx_CHANNELS_SINGLE_VAR_NAME_BY_INST_NUM(inst_num),  \
111             .ipct_pub_channels_mask = \
112                 NRFX_IPCTx_PUB_CONFIG_ALLOWED_CHANNELS_MASK_BY_INST_NUM(inst_num), \
113             .ipct_sub_channels_mask = \
114                 NRFX_IPCTx_SUB_CONFIG_ALLOWED_CHANNELS_MASK_BY_INST_NUM(inst_num), \
115     },), ())
116 
117 /* Global entry discard case when instance has no inst_num (NRF_IPCT) which is a local
118  * instance.
119  */
120 #define _NRFX_INTERCONNECT_IPCT_GLOBAL_IPCT_PROP_ENTRY(periph_name, prefix, inst_num, _) \
121     NRFX_COND_CODE_1(NRFX_IS_EMPTY(inst_num), (), (NRFX_INTERCONNECT_IPCT_PROP_ENTRY(inst_num)))
122 
123 #define NRFX_INTERCONNECT_IPCT_GLOBAL_IPCT_PROP                                            \
124 {                                                                                          \
125         NRFX_FOREACH_PRESENT(IPCT, _NRFX_INTERCONNECT_IPCT_GLOBAL_IPCT_PROP_ENTRY, (), ()) \
126 }
127 
128 #ifdef __cplusplus
129 }
130 #endif
131 
132 #endif // NRFX_INTERCONNECT_IPCT_HALTIUM_GLOBAL_H__
133