1 /*
2  * Copyright (c) 2022 - 2024, 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 #include <helpers/nrfx_gppi.h>
35 
36 #if NRFX_CHECK(NRFX_PPI_ENABLED)
37 #include <nrfx_ppi.h>
38 #endif
39 
40 #if defined(PPI_PRESENT)
41 
nrfx_gppi_channel_check(uint8_t channel)42 bool nrfx_gppi_channel_check(uint8_t channel)
43 {
44     return (nrf_ppi_channel_enable_get(NRF_PPI, (nrf_ppi_channel_t)channel) ==
45             NRF_PPI_CHANNEL_ENABLED);
46 }
47 
nrfx_gppi_channels_disable_all(void)48 void nrfx_gppi_channels_disable_all(void)
49 {
50     nrf_ppi_channels_disable_all(NRF_PPI);
51 }
52 
nrfx_gppi_channels_enable(uint32_t mask)53 void nrfx_gppi_channels_enable(uint32_t mask)
54 {
55     nrf_ppi_channels_enable(NRF_PPI, mask);
56 }
57 
nrfx_gppi_channels_disable(uint32_t mask)58 void nrfx_gppi_channels_disable(uint32_t mask)
59 {
60     nrf_ppi_channels_disable(NRF_PPI, mask);
61 }
62 
nrfx_gppi_event_endpoint_setup(uint8_t channel,uint32_t eep)63 void nrfx_gppi_event_endpoint_setup(uint8_t channel, uint32_t eep)
64 {
65     nrf_ppi_event_endpoint_setup(NRF_PPI, (nrf_ppi_channel_t)channel, eep);
66 }
67 
nrfx_gppi_task_endpoint_setup(uint8_t channel,uint32_t tep)68 void nrfx_gppi_task_endpoint_setup(uint8_t channel, uint32_t tep)
69 {
70     nrf_ppi_task_endpoint_setup(NRF_PPI, (nrf_ppi_channel_t)channel, tep);
71 }
72 
nrfx_gppi_channel_endpoints_setup(uint8_t channel,uint32_t eep,uint32_t tep)73 void nrfx_gppi_channel_endpoints_setup(uint8_t  channel, uint32_t eep, uint32_t tep)
74 {
75     nrf_ppi_channel_endpoint_setup(NRF_PPI, (nrf_ppi_channel_t)channel, eep, tep);
76 }
77 
nrfx_gppi_channel_endpoints_clear(uint8_t channel,uint32_t eep,uint32_t tep)78 void nrfx_gppi_channel_endpoints_clear(uint8_t channel, uint32_t eep, uint32_t tep)
79 {
80     nrfx_gppi_event_endpoint_clear(channel, eep);
81     nrfx_gppi_task_endpoint_clear(channel, tep);
82 }
83 
nrfx_gppi_event_endpoint_clear(uint8_t channel,uint32_t eep)84 void nrfx_gppi_event_endpoint_clear(uint8_t channel, uint32_t eep)
85 {
86     (void)eep;
87      nrf_ppi_event_endpoint_setup(NRF_PPI, (nrf_ppi_channel_t)channel, 0);
88 }
89 
nrfx_gppi_task_endpoint_clear(uint8_t channel,uint32_t tep)90 void nrfx_gppi_task_endpoint_clear(uint8_t channel, uint32_t tep)
91 {
92     (void)tep;
93     nrf_ppi_task_endpoint_setup(NRF_PPI, (nrf_ppi_channel_t)channel, 0);
94 }
95 
96 #if defined(PPI_FEATURE_FORKS_PRESENT)
nrfx_gppi_fork_endpoint_setup(uint8_t channel,uint32_t fork_tep)97 void nrfx_gppi_fork_endpoint_setup(uint8_t channel, uint32_t fork_tep)
98 {
99     nrf_ppi_fork_endpoint_setup(NRF_PPI, (nrf_ppi_channel_t)channel, fork_tep);
100 }
101 
nrfx_gppi_fork_endpoint_clear(uint8_t channel,uint32_t fork_tep)102 void nrfx_gppi_fork_endpoint_clear(uint8_t channel, uint32_t fork_tep)
103 {
104     (void)fork_tep;
105     nrf_ppi_fork_endpoint_setup(NRF_PPI, (nrf_ppi_channel_t)channel, 0);
106 }
107 #endif
108 
nrfx_gppi_channels_group_set(uint32_t channel_mask,nrfx_gppi_channel_group_t channel_group)109 void nrfx_gppi_channels_group_set(uint32_t                  channel_mask,
110                                   nrfx_gppi_channel_group_t channel_group)
111 {
112     nrf_ppi_channels_group_set(NRF_PPI,
113                                channel_mask,
114                                (nrf_ppi_channel_group_t)channel_group);
115 }
116 
nrfx_gppi_channels_include_in_group(uint32_t channel_mask,nrfx_gppi_channel_group_t channel_group)117 void nrfx_gppi_channels_include_in_group(uint32_t                  channel_mask,
118                                          nrfx_gppi_channel_group_t channel_group)
119 {
120     nrf_ppi_channels_include_in_group(NRF_PPI,
121                                       channel_mask,
122                                       (nrf_ppi_channel_group_t)channel_group);
123 }
124 
nrfx_gppi_channels_remove_from_group(uint32_t channel_mask,nrfx_gppi_channel_group_t channel_group)125 void nrfx_gppi_channels_remove_from_group(uint32_t                  channel_mask,
126                                           nrfx_gppi_channel_group_t channel_group)
127 {
128     nrf_ppi_channels_remove_from_group(NRF_PPI,
129                                        channel_mask,
130                                        (nrf_ppi_channel_group_t)channel_group);
131 }
132 
nrfx_gppi_group_clear(nrfx_gppi_channel_group_t channel_group)133 void nrfx_gppi_group_clear(nrfx_gppi_channel_group_t channel_group)
134 {
135     nrf_ppi_group_clear(NRF_PPI, (nrf_ppi_channel_group_t)channel_group);
136 }
137 
nrfx_gppi_group_enable(nrfx_gppi_channel_group_t channel_group)138 void nrfx_gppi_group_enable(nrfx_gppi_channel_group_t channel_group)
139 {
140     nrf_ppi_group_enable(NRF_PPI, (nrf_ppi_channel_group_t)channel_group);
141 }
142 
nrfx_gppi_group_disable(nrfx_gppi_channel_group_t channel_group)143 void nrfx_gppi_group_disable(nrfx_gppi_channel_group_t channel_group)
144 {
145     nrf_ppi_group_disable(NRF_PPI, (nrf_ppi_channel_group_t)channel_group);
146 }
147 
nrfx_gppi_task_trigger(nrfx_gppi_task_t task)148 void nrfx_gppi_task_trigger(nrfx_gppi_task_t task)
149 {
150     nrf_ppi_task_trigger(NRF_PPI, (nrf_ppi_task_t)task);
151 }
152 
nrfx_gppi_task_address_get(nrfx_gppi_task_t task)153 uint32_t nrfx_gppi_task_address_get(nrfx_gppi_task_t task)
154 {
155     return (uint32_t)nrf_ppi_task_address_get(NRF_PPI, (nrf_ppi_task_t)task);
156 }
157 
nrfx_gppi_group_disable_task_get(nrfx_gppi_channel_group_t group)158 nrfx_gppi_task_t nrfx_gppi_group_disable_task_get(nrfx_gppi_channel_group_t group)
159 {
160     return (nrfx_gppi_task_t)nrf_ppi_group_disable_task_get(NRF_PPI, (uint8_t)group);
161 }
162 
nrfx_gppi_group_enable_task_get(nrfx_gppi_channel_group_t group)163 nrfx_gppi_task_t nrfx_gppi_group_enable_task_get(nrfx_gppi_channel_group_t group)
164 {
165     return (nrfx_gppi_task_t)nrf_ppi_group_enable_task_get(NRF_PPI, (uint8_t)group);
166 }
167 
nrfx_gppi_channel_alloc(uint8_t * p_channel)168 nrfx_err_t nrfx_gppi_channel_alloc(uint8_t * p_channel)
169 {
170 #if NRFX_CHECK(NRFX_PPI_ENABLED)
171     return nrfx_ppi_channel_alloc((nrf_ppi_channel_t *)p_channel);
172 #else
173     (void)p_channel;
174     return NRFX_ERROR_NOT_SUPPORTED;
175 #endif
176 }
177 
nrfx_gppi_channel_free(uint8_t channel)178 nrfx_err_t nrfx_gppi_channel_free(uint8_t channel)
179 {
180 #if NRFX_CHECK(NRFX_PPI_ENABLED)
181     return nrfx_ppi_channel_free((nrf_ppi_channel_t)channel);
182 #else
183     (void)channel;
184     return NRFX_ERROR_NOT_SUPPORTED;
185 #endif
186 }
187 
nrfx_gppi_group_alloc(nrfx_gppi_channel_group_t * p_group)188 nrfx_err_t nrfx_gppi_group_alloc(nrfx_gppi_channel_group_t * p_group)
189 {
190 #if NRFX_CHECK(NRFX_PPI_ENABLED)
191     return nrfx_ppi_group_alloc((nrf_ppi_channel_group_t *)p_group);
192 #else
193     (void)p_group;
194     return NRFX_ERROR_NOT_SUPPORTED;
195 #endif
196 }
197 
nrfx_gppi_group_free(nrfx_gppi_channel_group_t group)198 nrfx_err_t nrfx_gppi_group_free(nrfx_gppi_channel_group_t group)
199 {
200 #if NRFX_CHECK(NRFX_PPI_ENABLED)
201     return nrfx_ppi_group_free((nrf_ppi_channel_group_t)group);
202 #else
203     (void)group;
204     return NRFX_ERROR_NOT_SUPPORTED;
205 #endif
206 }
207 #endif // defined(PPI_PRESENT)
208