nrf_dppi.h 12 KB

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