nrf_dppi.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  1. /**
  2. * Copyright (c) 2018 - 2020, 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 be activated.
  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 getting the address of the specified DPPI task register.
  88. *
  89. * @param[in] p_reg Pointer to the structure of registers of the peripheral.
  90. * @param[in] task Requested task.
  91. *
  92. * @return Address of the specified task register.
  93. */
  94. __STATIC_INLINE uint32_t nrf_dppi_task_address_get(NRF_DPPIC_Type const * p_reg,
  95. nrf_dppi_task_t task);
  96. /**
  97. * @brief Function for checking the state of a specific DPPI channel.
  98. *
  99. * @param[in] p_reg Pointer to the structure of registers of the peripheral.
  100. * @param[in] channel Channel to be checked.
  101. *
  102. * @retval true The channel is enabled.
  103. * @retval false The channel is not enabled.
  104. */
  105. __STATIC_INLINE bool nrf_dppi_channel_check(NRF_DPPIC_Type const * p_reg, uint8_t channel);
  106. /**
  107. * @brief Function for enabling multiple DPPI channels.
  108. *
  109. * The bits in @c mask value correspond to particular channels. It means that
  110. * writing 1 to bit 0 enables channel 0, writing 1 to bit 1 enables 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_enable(NRF_DPPIC_Type * p_reg, uint32_t mask);
  116. /**
  117. * @brief Function for disabling multiple DPPI channels.
  118. *
  119. * The bits in @c mask value correspond to particular channels. It means that
  120. * writing 1 to bit 0 disables channel 0, writing 1 to bit 1 disables channel 1 etc.
  121. *
  122. * @param[in] p_reg Pointer to the structure of registers of the peripheral.
  123. * @param[in] mask Channel mask.
  124. */
  125. __STATIC_INLINE void nrf_dppi_channels_disable(NRF_DPPIC_Type * p_reg, uint32_t mask);
  126. /**
  127. * @brief Function for disabling all DPPI channels.
  128. *
  129. * @param[in] p_reg Pointer to the structure of registers of the peripheral.
  130. */
  131. __STATIC_INLINE void nrf_dppi_channels_disable_all(NRF_DPPIC_Type * p_reg);
  132. /**
  133. * @brief Function for setting the subscribe configuration for a given
  134. * DPPI task.
  135. *
  136. * @param[in] p_reg Pointer to the structure of registers of the peripheral.
  137. * @param[in] task Task for which to set the configuration.
  138. * @param[in] channel Channel through which to subscribe events.
  139. */
  140. __STATIC_INLINE void nrf_dppi_subscribe_set(NRF_DPPIC_Type * p_reg,
  141. nrf_dppi_task_t task,
  142. uint8_t channel);
  143. /**
  144. * @brief Function for clearing the subscribe configuration for a given
  145. * DPPI task.
  146. *
  147. * @param[in] p_reg Pointer to the structure of registers of the peripheral.
  148. * @param[in] task Task for which to clear the configuration.
  149. */
  150. __STATIC_INLINE void nrf_dppi_subscribe_clear(NRF_DPPIC_Type * p_reg, nrf_dppi_task_t task);
  151. /**
  152. * @brief Function for including multiple DPPI channels in a channel group.
  153. *
  154. * @details This function adds all specified channels to the group.
  155. * The bits in @p channel_mask value correspond to particular channels. It means that
  156. * writing 1 to bit 0 includes channel 0, writing 1 to bit 1 includes channel 1 etc.
  157. *
  158. * @param[in] p_reg Pointer to the structure of registers of the peripheral.
  159. * @param[in] channel_mask Channels to be included in the group.
  160. * @param[in] channel_group Channel group.
  161. */
  162. __STATIC_INLINE void nrf_dppi_channels_include_in_group(NRF_DPPIC_Type * p_reg,
  163. uint32_t channel_mask,
  164. nrf_dppi_channel_group_t channel_group);
  165. /**
  166. * @brief Function for removing multiple DPPI channels from a channel group.
  167. *
  168. * @details This function removes all specified channels from the group.
  169. * The bits in @c channel_mask value correspond to particular channels. It means that
  170. * writing 1 to bit 0 removes channel 0, writing 1 to bit 1 removes channel 1 etc.
  171. *
  172. * @param[in] p_reg Pointer to the structure of registers of the peripheral.
  173. * @param[in] channel_mask Channels to be removed from the group.
  174. * @param[in] channel_group Channel group.
  175. */
  176. __STATIC_INLINE void nrf_dppi_channels_remove_from_group(NRF_DPPIC_Type * p_reg,
  177. uint32_t channel_mask,
  178. nrf_dppi_channel_group_t channel_group);
  179. /**
  180. * @brief Function for removing all DPPI channels from a channel group.
  181. *
  182. * @param[in] p_reg Pointer to the structure of registers of the peripheral.
  183. * @param[in] group Channel group.
  184. */
  185. __STATIC_INLINE void nrf_dppi_group_clear(NRF_DPPIC_Type * p_reg,
  186. nrf_dppi_channel_group_t group);
  187. /**
  188. * @brief Function for enabling a channel group.
  189. *
  190. * @param[in] p_reg Pointer to the structure of registers of the peripheral.
  191. * @param[in] group Channel group.
  192. */
  193. __STATIC_INLINE void nrf_dppi_group_enable(NRF_DPPIC_Type * p_reg,
  194. nrf_dppi_channel_group_t group);
  195. /**
  196. * @brief Function for disabling a channel group.
  197. *
  198. * @param[in] p_reg Pointer to the structure of registers of the peripheral.
  199. * @param[in] group Channel group.
  200. */
  201. __STATIC_INLINE void nrf_dppi_group_disable(NRF_DPPIC_Type * p_reg,
  202. nrf_dppi_channel_group_t group);
  203. /**
  204. * @brief Function for getting the ENABLE task associated with the specified channel group.
  205. *
  206. * @param[in] index Channel group index.
  207. *
  208. * @return Requested ENABLE task.
  209. */
  210. __STATIC_INLINE nrf_dppi_task_t nrf_dppi_group_enable_task_get(uint8_t index);
  211. /**
  212. * @brief Function for getting the DISABLE task associated with the specified channel group.
  213. *
  214. * @param[in] index Channel group index.
  215. *
  216. * @return Requested DISABLE task.
  217. */
  218. __STATIC_INLINE nrf_dppi_task_t nrf_dppi_group_disable_task_get(uint8_t index);
  219. #ifndef SUPPRESS_INLINE_IMPLEMENTATION
  220. __STATIC_INLINE void nrf_dppi_task_trigger(NRF_DPPIC_Type * p_reg, nrf_dppi_task_t dppi_task)
  221. {
  222. *((volatile uint32_t *) ((uint8_t *) p_reg + (uint32_t) dppi_task)) = 1;
  223. }
  224. __STATIC_INLINE uint32_t nrf_dppi_task_address_get(NRF_DPPIC_Type const * p_reg,
  225. nrf_dppi_task_t task)
  226. {
  227. return (uint32_t) ((uint8_t *) p_reg + (uint32_t ) task);
  228. }
  229. __STATIC_INLINE bool nrf_dppi_channel_check(NRF_DPPIC_Type const * p_reg, uint8_t channel)
  230. {
  231. return ((p_reg->CHEN & (DPPIC_CHEN_CH0_Enabled << (DPPIC_CHEN_CH0_Pos + channel))) != 0);
  232. }
  233. __STATIC_INLINE void nrf_dppi_channels_disable_all(NRF_DPPIC_Type * p_reg)
  234. {
  235. p_reg->CHENCLR = 0xFFFFFFFFuL;
  236. }
  237. __STATIC_INLINE void nrf_dppi_channels_enable(NRF_DPPIC_Type * p_reg, uint32_t mask)
  238. {
  239. p_reg->CHENSET = mask;
  240. }
  241. __STATIC_INLINE void nrf_dppi_channels_disable(NRF_DPPIC_Type * p_reg, uint32_t mask)
  242. {
  243. p_reg->CHENCLR = mask;
  244. }
  245. __STATIC_INLINE void nrf_dppi_subscribe_set(NRF_DPPIC_Type * p_reg,
  246. nrf_dppi_task_t task,
  247. uint8_t channel)
  248. {
  249. *((volatile uint32_t *) ((uint8_t *) p_reg + (uint32_t) task + 0x80uL)) =
  250. ((uint32_t)channel | DPPIC_SUBSCRIBE_CHG_EN_EN_Msk);
  251. }
  252. __STATIC_INLINE void nrf_dppi_subscribe_clear(NRF_DPPIC_Type * p_reg, nrf_dppi_task_t task)
  253. {
  254. *((volatile uint32_t *) ((uint8_t *) p_reg + (uint32_t) task + 0x80uL)) = 0;
  255. }
  256. __STATIC_INLINE void nrf_dppi_channels_include_in_group(NRF_DPPIC_Type * p_reg,
  257. uint32_t channel_mask,
  258. nrf_dppi_channel_group_t channel_group)
  259. {
  260. p_reg->CHG[(uint32_t) channel_group] =
  261. p_reg->CHG[(uint32_t) channel_group] | (channel_mask);
  262. }
  263. __STATIC_INLINE void nrf_dppi_channels_remove_from_group(NRF_DPPIC_Type * p_reg,
  264. uint32_t channel_mask,
  265. nrf_dppi_channel_group_t channel_group)
  266. {
  267. p_reg->CHG[(uint32_t) channel_group] =
  268. p_reg->CHG[(uint32_t) channel_group] & ~(channel_mask);
  269. }
  270. __STATIC_INLINE void nrf_dppi_group_clear(NRF_DPPIC_Type * p_reg,
  271. nrf_dppi_channel_group_t group)
  272. {
  273. p_reg->CHG[(uint32_t) group] = 0;
  274. }
  275. __STATIC_INLINE void nrf_dppi_group_enable(NRF_DPPIC_Type * p_reg, nrf_dppi_channel_group_t group)
  276. {
  277. p_reg->TASKS_CHG[(uint32_t) group].EN = 1;
  278. }
  279. __STATIC_INLINE void nrf_dppi_group_disable(NRF_DPPIC_Type * p_reg,
  280. nrf_dppi_channel_group_t group)
  281. {
  282. p_reg->TASKS_CHG[(uint32_t) group].DIS = 1;
  283. }
  284. __STATIC_INLINE nrf_dppi_task_t nrf_dppi_group_enable_task_get(uint8_t index)
  285. {
  286. NRFX_ASSERT(index < NRFX_ARRAY_SIZE(NRF_DPPIC->TASKS_CHG));
  287. return (nrf_dppi_task_t)NRFX_OFFSETOF(NRF_DPPIC_Type, TASKS_CHG[index].EN);
  288. }
  289. __STATIC_INLINE nrf_dppi_task_t nrf_dppi_group_disable_task_get(uint8_t index)
  290. {
  291. NRFX_ASSERT(index < NRFX_ARRAY_SIZE(NRF_DPPIC->TASKS_CHG));
  292. return (nrf_dppi_task_t)NRFX_OFFSETOF(NRF_DPPIC_Type, TASKS_CHG[index].DIS);
  293. }
  294. #endif // SUPPRESS_INLINE_IMPLEMENTATION
  295. /** @} */
  296. #ifdef __cplusplus
  297. }
  298. #endif
  299. #endif // NRF_DPPIC_H__