xref: /nrf52832-nimble/nordic/nrfx/drivers/include/nrfx_dppi.h (revision 150812a83cab50279bd772ef6db1bfaf255f2c5b)
1 /*
2  * Copyright (c) 2018, Nordic Semiconductor ASA
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice, this
9  *    list of conditions and the following disclaimer.
10  *
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * 3. Neither the name of the copyright holder nor the names of its
16  *    contributors may be used to endorse or promote products derived from this
17  *    software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #ifndef NRFX_DPPI_H__
33 #define NRFX_DPPI_H__
34 
35 #include <nrfx.h>
36 #include <hal/nrf_dppi.h>
37 
38 /**
39  * @defgroup nrfx_dppi DPPI allocator
40  * @{
41  * @ingroup nrf_dppi
42  * @brief   Distributed Programmable Peripheral Interconnect (DPPI) allocator.
43  */
44 
45 #ifdef __cplusplus
46 extern "C" {
47 #endif
48 
49 /** @brief Function for freeing all allocated channels and groups. */
50 void nrfx_dppi_free(void);
51 
52 /**
53  * @brief Function for allocating a DPPI channel.
54  * @details This function allocates the first unused DPPI channel.
55  *
56  * @param[out] p_channel Pointer to the DPPI channel number that has been allocated.
57  *
58  * @retval NRFX_SUCCESS      If the channel was successfully allocated.
59  * @retval NRFX_ERROR_NO_MEM If there is no available channel to be used.
60  */
61 nrfx_err_t nrfx_dppi_channel_alloc(uint8_t * p_channel);
62 
63 /**
64  * @brief Function for freeing a DPPI channel.
65  * @details This function also disables the chosen channel.
66  *
67  * @param[in] channel DPPI channel to be freed.
68  *
69  * @retval NRFX_SUCCESS             If the channel was successfully freed.
70  * @retval NRFX_ERROR_INVALID_PARAM If the specified channel is not allocated.
71  */
72 nrfx_err_t nrfx_dppi_channel_free(uint8_t channel);
73 
74 /**
75  * @brief Function for enabling a DPPI channel.
76  *
77  * @param[in] channel DPPI channel to be enabled.
78  *
79  * @retval NRFX_SUCCESS             If the channel was successfully enabled.
80  * @retval NRFX_ERROR_INVALID_PARAM If the specified channel is not allocated.
81  */
82 nrfx_err_t nrfx_dppi_channel_enable(uint8_t channel);
83 
84 /**
85  * @brief Function for disabling a DPPI channel.
86  *
87  * @param[in] channel DPPI channel to be disabled.
88  *
89  * @retval NRFX_SUCCESS             If the channel was successfully disabled.
90  * @retval NRFX_ERROR_INVALID_PARAM If the specified channel is not allocated.
91  */
92 nrfx_err_t nrfx_dppi_channel_disable(uint8_t channel);
93 
94 /**
95  * @brief Function for allocating a DPPI channel group.
96  * @details This function allocates the first unused DPPI group.
97  *
98  * @param[out] p_group Pointer to the DPPI channel group that has been allocated.
99  *
100  * @retval NRFX_SUCCESS      If the channel group was successfully allocated.
101  * @retval NRFX_ERROR_NO_MEM If there is no available channel group to be used.
102  */
103 nrfx_err_t nrfx_dppi_group_alloc(nrf_dppi_channel_group_t * p_group);
104 
105 /**
106  * @brief Function for freeing a DPPI channel group.
107  * @details This function also disables the chosen group.
108  *
109  * @param[in] group DPPI channel group to be freed.
110  *
111  * @retval NRFX_SUCCESS             If the channel group was successfully freed.
112  * @retval NRFX_ERROR_INVALID_PARAM If the specified group is not allocated.
113  */
114 nrfx_err_t nrfx_dppi_group_free(nrf_dppi_channel_group_t group);
115 
116 /**
117  * @brief Function for including a DPPI channel in a channel group.
118  *
119  * @param[in] channel DPPI channel to be added.
120  * @param[in] group   Channel group in which to include the channel.
121  *
122  * @retval NRFX_SUCCESS             If the channel was successfully included.
123  * @retval NRFX_ERROR_INVALID_PARAM If the specified group or channel is not allocated.
124  */
125 nrfx_err_t nrfx_dppi_channel_include_in_group(uint8_t                  channel,
126                                               nrf_dppi_channel_group_t group);
127 
128 /**
129  * @brief Function for removing a DPPI channel from a channel group.
130  *
131  * @param[in] channel DPPI channel to be removed.
132  * @param[in] group   Channel group from which to remove the channel.
133  *
134  * @retval NRFX_SUCCESS             If the channel was successfully removed.
135  * @retval NRFX_ERROR_INVALID_PARAM If the specified group or channel is not allocated.
136  */
137 nrfx_err_t nrfx_dppi_channel_remove_from_group(uint8_t                  channel,
138                                                nrf_dppi_channel_group_t group);
139 
140 /**
141  * @brief Function for clearing a DPPI channel group.
142  *
143  * @param[in] group Channel group to be cleared.
144  *
145  * @retval NRFX_SUCCESS             If the group was successfully cleared.
146  * @retval NRFX_ERROR_INVALID_PARAM If the specified group is not allocated.
147  */
148 nrfx_err_t nrfx_dppi_group_clear(nrf_dppi_channel_group_t group);
149 
150 /**
151  * @brief Function for enabling a DPPI channel group.
152  *
153  * @param[in] group Channel group to be enabled.
154  *
155  * @retval NRFX_SUCCESS             If the group was successfully enabled.
156  * @retval NRFX_ERROR_INVALID_PARAM If the specified group is not allocated.
157  */
158 nrfx_err_t nrfx_dppi_group_enable(nrf_dppi_channel_group_t group);
159 
160 /**
161  * @brief Function for disabling a DPPI channel group.
162  *
163  * @param[in] group Channel group to be disabled.
164  *
165  * @retval NRFX_SUCCESS             If the group was successfully disabled.
166  * @retval NRFX_ERROR_INVALID_PARAM If the specified group is not allocated.
167  */
168 nrfx_err_t nrfx_dppi_group_disable(nrf_dppi_channel_group_t group);
169 
170 /** @} */
171 
172 #ifdef __cplusplus
173 }
174 #endif
175 
176 #endif // NRFX_DPPI_H__
177