nrf_drv_ppi.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. /* Copyright (c) 2015 Nordic Semiconductor. All Rights Reserved.
  2. *
  3. * The information contained herein is property of Nordic Semiconductor ASA.
  4. * Terms and conditions of usage are described in detail in NORDIC
  5. * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
  6. *
  7. * Licensees are granted free, non-transferable use of the information. NO
  8. * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
  9. * the file.
  10. *
  11. */
  12. #ifndef NRF_DRV_PPI_H
  13. #define NRF_DRV_PPI_H
  14. /*lint ++flb "Enter library region" */
  15. #include "sdk_errors.h"
  16. #include "nrf_ppi.h"
  17. #include <stdbool.h>
  18. #include <stdint.h>
  19. /** @file
  20. *
  21. * @addtogroup nrf_ppi PPI HAL and driver
  22. * @ingroup nrf_drivers
  23. * @brief Programmable Peripheral Interconnect (PPI) APIs.
  24. *
  25. * @details The PPI HAL provides basic APIs for accessing the registers of the PPI.
  26. * The PPI driver provides APIs on a higher level.
  27. *
  28. * @defgroup lib_driver_ppi PPI driver
  29. * @{
  30. * @ingroup nrf_ppi
  31. *
  32. * @brief Programmable Peripheral Interconnect (PPI) driver.
  33. */
  34. #include "sdk_resources.h"
  35. #ifdef NRF52
  36. #define NRF_PPI_ALL_APP_CHANNELS_MASK ((uint32_t)0xFFFFFFFFuL & ~(NRF_PPI_CHANNELS_USED)) /**< All PPI channels available to the application. */
  37. #define NRF_PPI_PROG_APP_CHANNELS_MASK ((uint32_t)0x000FFFFFuL & ~(NRF_PPI_CHANNELS_USED)) /**< Programmable PPI channels available to the application. */
  38. #define NRF_PPI_ALL_APP_GROUPS_MASK ((uint32_t)0x0000003FuL & ~(NRF_PPI_GROUPS_USED)) /**< All PPI groups available to the application. */
  39. #else
  40. #define NRF_PPI_ALL_APP_CHANNELS_MASK ((uint32_t)0xFFF0FFFFuL & ~(NRF_PPI_CHANNELS_USED)) /**< All PPI channels available to the application. */
  41. #define NRF_PPI_PROG_APP_CHANNELS_MASK ((uint32_t)0x0000FFFFuL & ~(NRF_PPI_CHANNELS_USED)) /**< Programmable PPI channels available to the application. */
  42. #define NRF_PPI_ALL_APP_GROUPS_MASK ((uint32_t)0x0000000FuL & ~(NRF_PPI_GROUPS_USED)) /**< All PPI groups available to the application. */
  43. #endif
  44. /**@brief Function for initializing PPI module.
  45. *
  46. * @retval NRF_SUCCESS If the module was successfully initialized.
  47. * @retval MODULE_ALREADY_INITIALIZED If the module has already been initialized.
  48. */
  49. uint32_t nrf_drv_ppi_init(void);
  50. /**@brief Function for uninitializing the PPI module.
  51. *
  52. * This function also disables all channels and clears the channel groups.
  53. *
  54. * @retval NRF_SUCCESS If the module was successfully uninitialized.
  55. * @retval NRF_ERROR_INVALID_STATE If the module has not been initialized yet.
  56. * @retval NRF_ERROR_INTERNAL If the channels or groups could not be disabled.
  57. */
  58. uint32_t nrf_drv_ppi_uninit(void);
  59. /**@brief Function for allocating a PPI channel.
  60. * @details This function allocates the first unused PPI channel.
  61. *
  62. * @param[out] p_channel Pointer to the PPI channel that has been allocated.
  63. *
  64. * @retval NRF_SUCCESS If the channel was successfully allocated.
  65. * @retval NRF_ERROR_NO_MEM If there is no available channel to be used.
  66. */
  67. uint32_t nrf_drv_ppi_channel_alloc(nrf_ppi_channel_t * p_channel);
  68. /**@brief Function for freeing a PPI channel.
  69. * @details This function also disables the chosen channel.
  70. *
  71. * @param[in] channel PPI channel to be freed.
  72. *
  73. * @retval NRF_SUCCESS If the channel was successfully freed.
  74. * @retval NRF_ERROR_INVALID_PARAM If the channel is not user-configurable.
  75. */
  76. uint32_t nrf_drv_ppi_channel_free(nrf_ppi_channel_t channel);
  77. /**@brief Function for assigning task and event endpoints to the PPI channel.
  78. *
  79. * @param[in] channel PPI channel to be assigned endpoints.
  80. *
  81. * @param[in] eep Event endpoint address.
  82. *
  83. * @param[in] tep Task endpoint address.
  84. *
  85. * @retval NRF_SUCCESS If the channel was successfully assigned.
  86. * @retval NRF_ERROR_INVALID_STATE If the channel is not allocated for the user.
  87. * @retval NRF_ERROR_INVALID_PARAM If the channel is not user-configurable.
  88. */
  89. uint32_t nrf_drv_ppi_channel_assign(nrf_ppi_channel_t channel, uint32_t eep, uint32_t tep);
  90. /**@brief Function for assigning or clearing fork endpoint to the PPI channel.
  91. *
  92. * @param[in] channel PPI channel to be assigned endpoints.
  93. *
  94. * @param[in] fork_tep Fork task endpoint address or 0 to clear.
  95. *
  96. * @retval NRF_SUCCESS If the channel was successfully assigned.
  97. * @retval NRF_ERROR_INVALID_STATE If the channel is not allocated for the user.
  98. * @retval NRF_ERROR_INVALID_PARAM If the channel is not user-configurable.
  99. * @retval NRF_ERROR_NOT_SUPPORTED If function is not supported.
  100. */
  101. uint32_t nrf_drv_ppi_channel_fork_assign(nrf_ppi_channel_t channel, uint32_t fork_tep);
  102. /**@brief Function for enabling a PPI channel.
  103. *
  104. * @param[in] channel PPI channel to be enabled.
  105. *
  106. * @retval NRF_SUCCESS If the channel was successfully enabled.
  107. * @retval NRF_ERROR_INVALID_STATE If the user-configurable channel is not allocated.
  108. * @retval NRF_ERROR_INVALID_PARAM If the channel cannot be enabled by the user.
  109. */
  110. uint32_t nrf_drv_ppi_channel_enable(nrf_ppi_channel_t channel);
  111. /**@brief Function for disabling a PPI channel.
  112. *
  113. * @param[in] channel PPI channel to be disabled.
  114. *
  115. * @retval NRF_SUCCESS If the channel was successfully disabled.
  116. * @retval NRF_ERROR_INVALID_STATE If the user-configurable channel is not allocated.
  117. * @retval NRF_ERROR_INVALID_PARAM If the channel cannot be disabled by the user.
  118. */
  119. uint32_t nrf_drv_ppi_channel_disable(nrf_ppi_channel_t channel);
  120. /**@brief Function for allocating a PPI channel group.
  121. * @details This function allocates the first unused PPI group.
  122. *
  123. * @param[out] p_group Pointer to the PPI channel group that has been allocated.
  124. *
  125. * @retval NRF_SUCCESS If the channel group was successfully allocated.
  126. * @retval NRF_ERROR_NO_MEM If there is no available channel group to be used.
  127. */
  128. uint32_t nrf_drv_ppi_group_alloc(nrf_ppi_channel_group_t * p_group);
  129. /**@brief Function for freeing a PPI channel group.
  130. * @details This function also disables the chosen group.
  131. *
  132. * @param[in] group PPI channel group to be freed.
  133. *
  134. * @retval NRF_SUCCESS If the channel group was successfully freed.
  135. * @retval NRF_ERROR_INVALID_PARAM If the channel group is not user-configurable.
  136. */
  137. uint32_t nrf_drv_ppi_group_free(nrf_ppi_channel_group_t group);
  138. /**@brief Compute a channel mask for NRF_PPI registers.
  139. *
  140. * @param[in] channel Channel number to transform to a mask.
  141. *
  142. * @retval Channel mask.
  143. */
  144. __STATIC_INLINE uint32_t nrf_drv_ppi_channel_to_mask(nrf_ppi_channel_t channel)
  145. {
  146. return (1uL << (uint32_t) channel);
  147. }
  148. /**@brief Function for including multiple PPI channels in a channel group.
  149. *
  150. * @param[in] channel_mask PPI channels to be added.
  151. * @param[in] group Channel group in which to include the channels.
  152. *
  153. * @retval NRF_SUCCESS If the channels was successfully included.
  154. */
  155. uint32_t nrf_drv_ppi_channels_include_in_group(uint32_t channel_mask,
  156. nrf_ppi_channel_group_t group);
  157. /**@brief Function for including a PPI channel in a channel group.
  158. *
  159. * @param[in] channel PPI channel to be added.
  160. * @param[in] group Channel group in which to include the channel.
  161. *
  162. * @retval NRF_SUCCESS If the channel was successfully included.
  163. */
  164. __STATIC_INLINE uint32_t nrf_drv_ppi_channel_include_in_group(nrf_ppi_channel_t channel,
  165. nrf_ppi_channel_group_t group)
  166. {
  167. return nrf_drv_ppi_channels_include_in_group(nrf_drv_ppi_channel_to_mask(channel), group);
  168. }
  169. /**@brief Function for removing multiple PPI channels from a channel group.
  170. *
  171. * @param[in] channel_mask PPI channels to be removed.
  172. * @param[in] group Channel group from which to remove the channels.
  173. *
  174. * @retval NRF_SUCCESS If the channel was successfully removed.
  175. */
  176. uint32_t nrf_drv_ppi_channels_remove_from_group(uint32_t channel_mask,
  177. nrf_ppi_channel_group_t group);
  178. /**@brief Function for removing a PPI channel from a channel group.
  179. *
  180. * @param[in] channel PPI channel to be removed.
  181. * @param[in] group Channel group from which to remove the channel.
  182. *
  183. * @retval NRF_SUCCESS If the channel was successfully removed.
  184. */
  185. __STATIC_INLINE uint32_t nrf_drv_ppi_channel_remove_from_group(nrf_ppi_channel_t channel,
  186. nrf_ppi_channel_group_t group)
  187. {
  188. return nrf_drv_ppi_channels_remove_from_group(nrf_drv_ppi_channel_to_mask(channel), group);
  189. }
  190. /**@brief Function for clearing a PPI channel group.
  191. *
  192. * @param[in] group Channel group to be cleared.
  193. *
  194. * @retval NRF_SUCCESS If the group was successfully cleared.
  195. */
  196. __STATIC_INLINE uint32_t nrf_drv_ppi_group_clear(nrf_ppi_channel_group_t group)
  197. {
  198. return nrf_drv_ppi_channels_remove_from_group(NRF_PPI_ALL_APP_CHANNELS_MASK, group);
  199. }
  200. /**@brief Function for enabling a PPI channel group.
  201. *
  202. * @param[in] group Channel group to be enabled.
  203. *
  204. * @retval NRF_SUCCESS If the group was successfully enabled.
  205. */
  206. uint32_t nrf_drv_ppi_group_enable(nrf_ppi_channel_group_t group);
  207. /**@brief Function for disabling a PPI channel group.
  208. *
  209. * @param[in] group Channel group to be disabled.
  210. *
  211. * @retval NRF_SUCCESS If the group was successfully disabled.
  212. */
  213. uint32_t nrf_drv_ppi_group_disable(nrf_ppi_channel_group_t group);
  214. /**
  215. * @brief Function for getting the address of a PPI task.
  216. *
  217. * @param[in] task Task.
  218. *
  219. * @retval Task address.
  220. */
  221. __STATIC_INLINE uint32_t nrf_drv_ppi_task_addr_get(nrf_ppi_task_t task)
  222. {
  223. return (uint32_t) nrf_ppi_task_address_get(task);
  224. }
  225. /**
  226. * @brief Function for getting the address of a PPI group enable task.
  227. *
  228. * @param[in] group PPI channel group
  229. *
  230. * @retval Task address.
  231. */
  232. __STATIC_INLINE uint32_t nrf_drv_ppi_task_addr_group_enable_get(nrf_ppi_channel_group_t group)
  233. {
  234. return (uint32_t) nrf_ppi_task_group_enable_address_get(group);
  235. }
  236. /**
  237. * @brief Function for getting the address of a PPI group enable task.
  238. *
  239. * @param[in] group PPI channel group
  240. *
  241. * @retval Task address.
  242. */
  243. __STATIC_INLINE uint32_t nrf_drv_ppi_task_addr_group_disable_get(nrf_ppi_channel_group_t group)
  244. {
  245. return (uint32_t) nrf_ppi_task_group_disable_address_get(group);
  246. }
  247. /**
  248. *@}
  249. **/
  250. /*lint --flb "Leave library region" */
  251. #endif // NRF_DRV_PPI_H