1*150812a8SEvalZero /*
2*150812a8SEvalZero * Copyright (c) 2018, Nordic Semiconductor ASA
3*150812a8SEvalZero * All rights reserved.
4*150812a8SEvalZero *
5*150812a8SEvalZero * Redistribution and use in source and binary forms, with or without
6*150812a8SEvalZero * modification, are permitted provided that the following conditions are met:
7*150812a8SEvalZero *
8*150812a8SEvalZero * 1. Redistributions of source code must retain the above copyright notice, this
9*150812a8SEvalZero * list of conditions and the following disclaimer.
10*150812a8SEvalZero *
11*150812a8SEvalZero * 2. Redistributions in binary form must reproduce the above copyright
12*150812a8SEvalZero * notice, this list of conditions and the following disclaimer in the
13*150812a8SEvalZero * documentation and/or other materials provided with the distribution.
14*150812a8SEvalZero *
15*150812a8SEvalZero * 3. Neither the name of the copyright holder nor the names of its
16*150812a8SEvalZero * contributors may be used to endorse or promote products derived from this
17*150812a8SEvalZero * software without specific prior written permission.
18*150812a8SEvalZero *
19*150812a8SEvalZero * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20*150812a8SEvalZero * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21*150812a8SEvalZero * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22*150812a8SEvalZero * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23*150812a8SEvalZero * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24*150812a8SEvalZero * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25*150812a8SEvalZero * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26*150812a8SEvalZero * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27*150812a8SEvalZero * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28*150812a8SEvalZero * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29*150812a8SEvalZero * POSSIBILITY OF SUCH DAMAGE.
30*150812a8SEvalZero */
31*150812a8SEvalZero
32*150812a8SEvalZero #ifndef NRF_DPPI_H__
33*150812a8SEvalZero #define NRF_DPPI_H__
34*150812a8SEvalZero
35*150812a8SEvalZero #include <nrfx.h>
36*150812a8SEvalZero
37*150812a8SEvalZero #ifdef __cplusplus
38*150812a8SEvalZero extern "C" {
39*150812a8SEvalZero #endif
40*150812a8SEvalZero
41*150812a8SEvalZero /**
42*150812a8SEvalZero * @defgroup nrf_dppi_hal DPPI Controller HAL
43*150812a8SEvalZero * @{
44*150812a8SEvalZero * @ingroup nrf_dppi
45*150812a8SEvalZero * @brief Hardware access layer for managing the Distributed Programmable Peripheral
46*150812a8SEvalZero * Interconnect Controller (DPPIC).
47*150812a8SEvalZero */
48*150812a8SEvalZero
49*150812a8SEvalZero /** @brief DPPI channel groups. */
50*150812a8SEvalZero typedef enum
51*150812a8SEvalZero {
52*150812a8SEvalZero NRF_DPPI_CHANNEL_GROUP0 = 0, /**< Channel group 0. */
53*150812a8SEvalZero NRF_DPPI_CHANNEL_GROUP1 = 1, /**< Channel group 1. */
54*150812a8SEvalZero NRF_DPPI_CHANNEL_GROUP2 = 2, /**< Channel group 2. */
55*150812a8SEvalZero NRF_DPPI_CHANNEL_GROUP3 = 3, /**< Channel group 3. */
56*150812a8SEvalZero NRF_DPPI_CHANNEL_GROUP4 = 4, /**< Channel group 4. */
57*150812a8SEvalZero NRF_DPPI_CHANNEL_GROUP5 = 5 /**< Channel group 5. */
58*150812a8SEvalZero } nrf_dppi_channel_group_t;
59*150812a8SEvalZero
60*150812a8SEvalZero /** @brief DPPI tasks. */
61*150812a8SEvalZero typedef enum
62*150812a8SEvalZero {
63*150812a8SEvalZero NRF_DPPI_TASK_CHG0_EN = offsetof(NRF_DPPIC_Type, TASKS_CHG[0].EN), /**< Enable channel group 0. */
64*150812a8SEvalZero NRF_DPPI_TASK_CHG0_DIS = offsetof(NRF_DPPIC_Type, TASKS_CHG[0].DIS), /**< Disable channel group 0. */
65*150812a8SEvalZero NRF_DPPI_TASK_CHG1_EN = offsetof(NRF_DPPIC_Type, TASKS_CHG[1].EN), /**< Enable channel group 1. */
66*150812a8SEvalZero NRF_DPPI_TASK_CHG1_DIS = offsetof(NRF_DPPIC_Type, TASKS_CHG[1].DIS), /**< Disable channel group 1. */
67*150812a8SEvalZero NRF_DPPI_TASK_CHG2_EN = offsetof(NRF_DPPIC_Type, TASKS_CHG[2].EN), /**< Enable channel group 2. */
68*150812a8SEvalZero NRF_DPPI_TASK_CHG2_DIS = offsetof(NRF_DPPIC_Type, TASKS_CHG[2].DIS), /**< Disable channel group 2. */
69*150812a8SEvalZero NRF_DPPI_TASK_CHG3_EN = offsetof(NRF_DPPIC_Type, TASKS_CHG[3].EN), /**< Enable channel group 3. */
70*150812a8SEvalZero NRF_DPPI_TASK_CHG3_DIS = offsetof(NRF_DPPIC_Type, TASKS_CHG[3].DIS), /**< Disable channel group 3. */
71*150812a8SEvalZero NRF_DPPI_TASK_CHG4_EN = offsetof(NRF_DPPIC_Type, TASKS_CHG[4].EN), /**< Enable channel group 4. */
72*150812a8SEvalZero NRF_DPPI_TASK_CHG4_DIS = offsetof(NRF_DPPIC_Type, TASKS_CHG[4].DIS), /**< Disable channel group 4. */
73*150812a8SEvalZero NRF_DPPI_TASK_CHG5_EN = offsetof(NRF_DPPIC_Type, TASKS_CHG[5].EN), /**< Enable channel group 5. */
74*150812a8SEvalZero NRF_DPPI_TASK_CHG5_DIS = offsetof(NRF_DPPIC_Type, TASKS_CHG[5].DIS) /**< Disable channel group 5. */
75*150812a8SEvalZero } nrf_dppi_task_t;
76*150812a8SEvalZero
77*150812a8SEvalZero /**
78*150812a8SEvalZero * @brief Function for activating a DPPI task.
79*150812a8SEvalZero *
80*150812a8SEvalZero * @param[in] p_reg Pointer to the structure of registers of the peripheral.
81*150812a8SEvalZero * @param[in] dppi_task Task to activate.
82*150812a8SEvalZero */
83*150812a8SEvalZero __STATIC_INLINE void nrf_dppi_task_trigger(NRF_DPPIC_Type * p_reg, nrf_dppi_task_t dppi_task);
84*150812a8SEvalZero
85*150812a8SEvalZero /**
86*150812a8SEvalZero * @brief Function for checking the state of a specific DPPI channel.
87*150812a8SEvalZero *
88*150812a8SEvalZero * @param[in] p_reg Pointer to the structure of registers of the peripheral.
89*150812a8SEvalZero * @param[in] channel Channel to check.
90*150812a8SEvalZero *
91*150812a8SEvalZero * @retval true If the channel is enabled.
92*150812a8SEvalZero * @retval false If the channel is not enabled.
93*150812a8SEvalZero */
94*150812a8SEvalZero __STATIC_INLINE bool nrf_dppi_channel_check(NRF_DPPIC_Type const * p_reg, uint8_t channel);
95*150812a8SEvalZero
96*150812a8SEvalZero /**
97*150812a8SEvalZero * @brief Function for enabling multiple DPPI channels.
98*150812a8SEvalZero *
99*150812a8SEvalZero * The bits in @c mask value correspond to particular channels. It means that
100*150812a8SEvalZero * writing 1 to bit 0 enables channel 0, writing 1 to bit 1 enables channel 1 etc.
101*150812a8SEvalZero *
102*150812a8SEvalZero * @param[in] p_reg Pointer to the structure of registers of the peripheral.
103*150812a8SEvalZero * @param[in] mask Channel mask.
104*150812a8SEvalZero */
105*150812a8SEvalZero __STATIC_INLINE void nrf_dppi_channels_enable(NRF_DPPIC_Type * p_reg, uint32_t mask);
106*150812a8SEvalZero
107*150812a8SEvalZero /**
108*150812a8SEvalZero * @brief Function for disabling multiple DPPI channels.
109*150812a8SEvalZero *
110*150812a8SEvalZero * The bits in @c mask value correspond to particular channels. It means that
111*150812a8SEvalZero * writing 1 to bit 0 disables channel 0, writing 1 to bit 1 disables channel 1 etc.
112*150812a8SEvalZero *
113*150812a8SEvalZero * @param[in] p_reg Pointer to the structure of registers of the peripheral.
114*150812a8SEvalZero * @param[in] mask Channel mask.
115*150812a8SEvalZero */
116*150812a8SEvalZero __STATIC_INLINE void nrf_dppi_channels_disable(NRF_DPPIC_Type * p_reg, uint32_t mask);
117*150812a8SEvalZero
118*150812a8SEvalZero /**
119*150812a8SEvalZero * @brief Function for disabling all DPPI channels.
120*150812a8SEvalZero *
121*150812a8SEvalZero * @param[in] p_reg Pointer to the structure of registers of the peripheral.
122*150812a8SEvalZero */
123*150812a8SEvalZero __STATIC_INLINE void nrf_dppi_channels_disable_all(NRF_DPPIC_Type * p_reg);
124*150812a8SEvalZero
125*150812a8SEvalZero /**
126*150812a8SEvalZero * @brief Function for setting the subscribe configuration for a given
127*150812a8SEvalZero * DPPI task.
128*150812a8SEvalZero *
129*150812a8SEvalZero * @param[in] p_reg Pointer to the structure of registers of the peripheral.
130*150812a8SEvalZero * @param[in] task Task for which to set the configuration.
131*150812a8SEvalZero * @param[in] channel Channel through which to subscribe events.
132*150812a8SEvalZero */
133*150812a8SEvalZero __STATIC_INLINE void nrf_dppi_subscribe_set(NRF_DPPIC_Type * p_reg,
134*150812a8SEvalZero nrf_dppi_task_t task,
135*150812a8SEvalZero uint8_t channel);
136*150812a8SEvalZero
137*150812a8SEvalZero /**
138*150812a8SEvalZero * @brief Function for clearing the subscribe configuration for a given
139*150812a8SEvalZero * DPPI task.
140*150812a8SEvalZero *
141*150812a8SEvalZero * @param[in] p_reg Pointer to the structure of registers of the peripheral.
142*150812a8SEvalZero * @param[in] task Task for which to clear the configuration.
143*150812a8SEvalZero */
144*150812a8SEvalZero __STATIC_INLINE void nrf_dppi_subscribe_clear(NRF_DPPIC_Type * p_reg, nrf_dppi_task_t task);
145*150812a8SEvalZero
146*150812a8SEvalZero /**
147*150812a8SEvalZero * @brief Function for including multiple DPPI channels in a channel group.
148*150812a8SEvalZero *
149*150812a8SEvalZero * @details This function adds all specified channels to the group.
150*150812a8SEvalZero * The bits in @p channel_mask value correspond to particular channels. It means that
151*150812a8SEvalZero * writing 1 to bit 0 includes channel 0, writing 1 to bit 1 includes channel 1 etc.
152*150812a8SEvalZero *
153*150812a8SEvalZero * @param[in] p_reg Pointer to the structure of registers of the peripheral.
154*150812a8SEvalZero * @param[in] channel_mask Channels to be included in the group.
155*150812a8SEvalZero * @param[in] channel_group Channel group.
156*150812a8SEvalZero */
157*150812a8SEvalZero __STATIC_INLINE void nrf_dppi_channels_include_in_group(NRF_DPPIC_Type * p_reg,
158*150812a8SEvalZero uint32_t channel_mask,
159*150812a8SEvalZero nrf_dppi_channel_group_t channel_group);
160*150812a8SEvalZero
161*150812a8SEvalZero /**
162*150812a8SEvalZero * @brief Function for removing multiple DPPI channels from a channel group.
163*150812a8SEvalZero *
164*150812a8SEvalZero * @details This function removes all specified channels from the group.
165*150812a8SEvalZero * The bits in @c channel_mask value correspond to particular channels. It means that
166*150812a8SEvalZero * writing 1 to bit 0 removes channel 0, writing 1 to bit 1 removes channel 1 etc.
167*150812a8SEvalZero *
168*150812a8SEvalZero * @param[in] p_reg Pointer to the structure of registers of the peripheral.
169*150812a8SEvalZero * @param[in] channel_mask Channels to be removed from the group.
170*150812a8SEvalZero * @param[in] channel_group Channel group.
171*150812a8SEvalZero */
172*150812a8SEvalZero __STATIC_INLINE void nrf_dppi_channels_remove_from_group(NRF_DPPIC_Type * p_reg,
173*150812a8SEvalZero uint32_t channel_mask,
174*150812a8SEvalZero nrf_dppi_channel_group_t channel_group);
175*150812a8SEvalZero
176*150812a8SEvalZero /**
177*150812a8SEvalZero * @brief Function for removing all DPPI channels from a channel group.
178*150812a8SEvalZero *
179*150812a8SEvalZero * @param[in] p_reg Pointer to the structure of registers of the peripheral.
180*150812a8SEvalZero * @param[in] group Channel group.
181*150812a8SEvalZero */
182*150812a8SEvalZero __STATIC_INLINE void nrf_dppi_group_clear(NRF_DPPIC_Type * p_reg,
183*150812a8SEvalZero nrf_dppi_channel_group_t group);
184*150812a8SEvalZero
185*150812a8SEvalZero /**
186*150812a8SEvalZero * @brief Function for enabling a channel group.
187*150812a8SEvalZero *
188*150812a8SEvalZero * @param[in] p_reg Pointer to the structure of registers of the peripheral.
189*150812a8SEvalZero * @param[in] group Channel group.
190*150812a8SEvalZero */
191*150812a8SEvalZero __STATIC_INLINE void nrf_dppi_group_enable(NRF_DPPIC_Type * p_reg,
192*150812a8SEvalZero nrf_dppi_channel_group_t group);
193*150812a8SEvalZero
194*150812a8SEvalZero /**
195*150812a8SEvalZero * @brief Function for disabling a channel group.
196*150812a8SEvalZero *
197*150812a8SEvalZero * @param[in] p_reg Pointer to the structure of registers of the peripheral.
198*150812a8SEvalZero * @param[in] group Channel group.
199*150812a8SEvalZero */
200*150812a8SEvalZero __STATIC_INLINE void nrf_dppi_group_disable(NRF_DPPIC_Type * p_reg,
201*150812a8SEvalZero nrf_dppi_channel_group_t group);
202*150812a8SEvalZero
203*150812a8SEvalZero
204*150812a8SEvalZero #ifndef SUPPRESS_INLINE_IMPLEMENTATION
205*150812a8SEvalZero
nrf_dppi_task_trigger(NRF_DPPIC_Type * p_reg,nrf_dppi_task_t dppi_task)206*150812a8SEvalZero __STATIC_INLINE void nrf_dppi_task_trigger(NRF_DPPIC_Type * p_reg, nrf_dppi_task_t dppi_task)
207*150812a8SEvalZero {
208*150812a8SEvalZero *((volatile uint32_t *) ((uint8_t *) p_reg + (uint32_t) dppi_task)) = 1;
209*150812a8SEvalZero }
210*150812a8SEvalZero
nrf_dppi_channel_check(NRF_DPPIC_Type const * p_reg,uint8_t channel)211*150812a8SEvalZero __STATIC_INLINE bool nrf_dppi_channel_check(NRF_DPPIC_Type const * p_reg, uint8_t channel)
212*150812a8SEvalZero {
213*150812a8SEvalZero return ((p_reg->CHEN & (DPPIC_CHEN_CH0_Enabled << (DPPIC_CHEN_CH0_Pos + channel))) != 0);
214*150812a8SEvalZero }
215*150812a8SEvalZero
nrf_dppi_channels_disable_all(NRF_DPPIC_Type * p_reg)216*150812a8SEvalZero __STATIC_INLINE void nrf_dppi_channels_disable_all(NRF_DPPIC_Type * p_reg)
217*150812a8SEvalZero {
218*150812a8SEvalZero p_reg->CHENCLR = 0xFFFFFFFFuL;
219*150812a8SEvalZero }
220*150812a8SEvalZero
nrf_dppi_channels_enable(NRF_DPPIC_Type * p_reg,uint32_t mask)221*150812a8SEvalZero __STATIC_INLINE void nrf_dppi_channels_enable(NRF_DPPIC_Type * p_reg, uint32_t mask)
222*150812a8SEvalZero {
223*150812a8SEvalZero p_reg->CHENSET = mask;
224*150812a8SEvalZero }
225*150812a8SEvalZero
nrf_dppi_channels_disable(NRF_DPPIC_Type * p_reg,uint32_t mask)226*150812a8SEvalZero __STATIC_INLINE void nrf_dppi_channels_disable(NRF_DPPIC_Type * p_reg, uint32_t mask)
227*150812a8SEvalZero {
228*150812a8SEvalZero p_reg->CHENCLR = mask;
229*150812a8SEvalZero }
230*150812a8SEvalZero
nrf_dppi_subscribe_set(NRF_DPPIC_Type * p_reg,nrf_dppi_task_t task,uint8_t channel)231*150812a8SEvalZero __STATIC_INLINE void nrf_dppi_subscribe_set(NRF_DPPIC_Type * p_reg,
232*150812a8SEvalZero nrf_dppi_task_t task,
233*150812a8SEvalZero uint8_t channel)
234*150812a8SEvalZero {
235*150812a8SEvalZero *((volatile uint32_t *) ((uint8_t *) p_reg + (uint32_t) task + 0x80uL)) =
236*150812a8SEvalZero ((uint32_t)channel | DPPIC_SUBSCRIBE_CHG_EN_EN_Msk);
237*150812a8SEvalZero }
238*150812a8SEvalZero
nrf_dppi_subscribe_clear(NRF_DPPIC_Type * p_reg,nrf_dppi_task_t task)239*150812a8SEvalZero __STATIC_INLINE void nrf_dppi_subscribe_clear(NRF_DPPIC_Type * p_reg, nrf_dppi_task_t task)
240*150812a8SEvalZero {
241*150812a8SEvalZero *((volatile uint32_t *) ((uint8_t *) p_reg + (uint32_t) task + 0x80uL)) = 0;
242*150812a8SEvalZero }
243*150812a8SEvalZero
nrf_dppi_channels_include_in_group(NRF_DPPIC_Type * p_reg,uint32_t channel_mask,nrf_dppi_channel_group_t channel_group)244*150812a8SEvalZero __STATIC_INLINE void nrf_dppi_channels_include_in_group(NRF_DPPIC_Type * p_reg,
245*150812a8SEvalZero uint32_t channel_mask,
246*150812a8SEvalZero nrf_dppi_channel_group_t channel_group)
247*150812a8SEvalZero {
248*150812a8SEvalZero p_reg->CHG[(uint32_t) channel_group] =
249*150812a8SEvalZero p_reg->CHG[(uint32_t) channel_group] | (channel_mask);
250*150812a8SEvalZero }
251*150812a8SEvalZero
nrf_dppi_channels_remove_from_group(NRF_DPPIC_Type * p_reg,uint32_t channel_mask,nrf_dppi_channel_group_t channel_group)252*150812a8SEvalZero __STATIC_INLINE void nrf_dppi_channels_remove_from_group(NRF_DPPIC_Type * p_reg,
253*150812a8SEvalZero uint32_t channel_mask,
254*150812a8SEvalZero nrf_dppi_channel_group_t channel_group)
255*150812a8SEvalZero {
256*150812a8SEvalZero p_reg->CHG[(uint32_t) channel_group] =
257*150812a8SEvalZero p_reg->CHG[(uint32_t) channel_group] & ~(channel_mask);
258*150812a8SEvalZero }
259*150812a8SEvalZero
nrf_dppi_group_clear(NRF_DPPIC_Type * p_reg,nrf_dppi_channel_group_t group)260*150812a8SEvalZero __STATIC_INLINE void nrf_dppi_group_clear(NRF_DPPIC_Type * p_reg,
261*150812a8SEvalZero nrf_dppi_channel_group_t group)
262*150812a8SEvalZero {
263*150812a8SEvalZero p_reg->CHG[(uint32_t) group] = 0;
264*150812a8SEvalZero }
265*150812a8SEvalZero
nrf_dppi_group_enable(NRF_DPPIC_Type * p_reg,nrf_dppi_channel_group_t group)266*150812a8SEvalZero __STATIC_INLINE void nrf_dppi_group_enable(NRF_DPPIC_Type * p_reg, nrf_dppi_channel_group_t group)
267*150812a8SEvalZero {
268*150812a8SEvalZero p_reg->TASKS_CHG[(uint32_t) group].EN = 1;
269*150812a8SEvalZero }
270*150812a8SEvalZero
nrf_dppi_group_disable(NRF_DPPIC_Type * p_reg,nrf_dppi_channel_group_t group)271*150812a8SEvalZero __STATIC_INLINE void nrf_dppi_group_disable(NRF_DPPIC_Type * p_reg,
272*150812a8SEvalZero nrf_dppi_channel_group_t group)
273*150812a8SEvalZero {
274*150812a8SEvalZero p_reg->TASKS_CHG[(uint32_t) group].DIS = 1;
275*150812a8SEvalZero }
276*150812a8SEvalZero
277*150812a8SEvalZero #endif // SUPPRESS_INLINE_IMPLEMENTATION
278*150812a8SEvalZero
279*150812a8SEvalZero /** @} */
280*150812a8SEvalZero
281*150812a8SEvalZero #ifdef __cplusplus
282*150812a8SEvalZero }
283*150812a8SEvalZero #endif
284*150812a8SEvalZero
285*150812a8SEvalZero #endif // NRF_DPPIC_H__
286