cyhal_dma.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459
  1. /***************************************************************************//**
  2. * \file cyhal_dma.h
  3. *
  4. * \brief
  5. * Provides a high level interface for interacting with the Infineon DMA.
  6. * This interface abstracts out the chip specific details. If any chip specific
  7. * functionality is necessary, or performance is critical the low level functions
  8. * can be used directly.
  9. *
  10. ********************************************************************************
  11. * \copyright
  12. * Copyright 2018-2022 Cypress Semiconductor Corporation (an Infineon company) or
  13. * an affiliate of Cypress Semiconductor Corporation
  14. *
  15. * SPDX-License-Identifier: Apache-2.0
  16. *
  17. * Licensed under the Apache License, Version 2.0 (the "License");
  18. * you may not use this file except in compliance with the License.
  19. * You may obtain a copy of the License at
  20. *
  21. * http://www.apache.org/licenses/LICENSE-2.0
  22. *
  23. * Unless required by applicable law or agreed to in writing, software
  24. * distributed under the License is distributed on an "AS IS" BASIS,
  25. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  26. * See the License for the specific language governing permissions and
  27. * limitations under the License.
  28. *******************************************************************************/
  29. /**
  30. * \addtogroup group_hal_dma DMA (Direct Memory Access)
  31. * \ingroup group_hal
  32. * \{
  33. * High level interface for interacting with the direct memory access (DMA). The DMA driver allows
  34. * for initializing and configuring a DMA channel in order to trigger data transfers to and from
  35. * memory and peripherals. The transfers occur independently of the CPU and can be triggered by
  36. * software or hardware. Multiple channels can be active at the same time each with their own
  37. * user-selectable priority and transfer characteristics.
  38. *
  39. * \section section_dma_features Features
  40. * * CPU independent memory access
  41. * * Access to memory and peripherals
  42. * * Multiple independent channels
  43. * * Configurable transer sizes and bursts
  44. * * Configurable priorities
  45. * * Event completion notification
  46. *
  47. * \section Usage Flow
  48. * The operational flow of the driver is listed below. This shows the basic order in which each of
  49. * the functions would generally be called. While Initialize must always be first and Release always
  50. * last, with care, the other functions can be reordered based on the implementation needs.
  51. * -# Initialize: \ref cyhal_dma_init or \ref cyhal_dma_init_adv or \ref cyhal_dma_init_cfg
  52. * -# Configure: \ref cyhal_dma_configure
  53. * -# Setup: \ref cyhal_dma_register_callback, \ref cyhal_dma_enable_event, \ref cyhal_dma_connect_digital, or \ref cyhal_dma_enable_output
  54. * -# Enable: \ref cyhal_dma_enable
  55. * -# Trigger: \ref cyhal_dma_start_transfer or via a hardware signal
  56. * -# Status/ReEnable (optional): \ref cyhal_dma_is_busy, \ref cyhal_dma_enable
  57. * -# Cleanup (optional): \ref cyhal_dma_disable, \ref cyhal_dma_enable_event, \ref cyhal_dma_disconnect_digital, or \ref cyhal_dma_disable_output
  58. * -# Release (optional): \ref cyhal_dma_free
  59. *
  60. * \section section_dma_quickstart Quick Start
  61. *
  62. * See \ref subsection_dma_snippet_1 for a code snippet that sets up a DMA
  63. * transfer to move memory from one location to another.
  64. *
  65. * \section section_dma_snippets Code snippets
  66. * \note Error handling code has been intentionally left out of snippets to highlight API usage.
  67. *
  68. * \subsection subsection_dma_snippet_1 Snippet 1: Simple DMA initialization and transfer
  69. * The following snippet initializes a DMA channel and uses it to transfer a a single block of memory.
  70. * The DMA channel is reserved by calling \ref cyhal_dma_init. It then needs to be configured with
  71. * \ref cyhal_dma_configure and then the transfer is started with \ref cyhal_dma_start_transfer.<br>
  72. * If the DMA channel is not needed anymore, it can be released by calling \ref cyhal_dma_free
  73. *
  74. * \snippet hal_dma.c snippet_cyhal_dma_simple_init
  75. *
  76. *
  77. * \subsection subsection_dma_snippet_2 Snippet 2: Configuring the DMA channel based on memory requirements
  78. * \ref cyhal_dma_configure can be used after DMA initialization to handle a variety of memory layouts.
  79. *
  80. * \snippet hal_dma.c snippet_cyhal_dma_configure
  81. *
  82. *
  83. * \subsection subsection_dma_snippet_3 Snippet 3: Interrupts and retriggering DMA transfers
  84. * DMA events like transfer complete or error events can be used to trigger a callback function. <br>
  85. * This snippet uses \ref cyhal_dma_configure to break the full transfer into multiple bursts. This
  86. * allows higher priority items access to the memory bus if necessary while the DMA operation is still
  87. * in progress. It then uses \ref cyhal_dma_enable_event() to enable the transfer complete event to
  88. * trigger the callback function registered by \ref cyhal_dma_register_callback().
  89. *
  90. * \snippet hal_dma.c snippet_cyhal_dma_events
  91. *
  92. *
  93. * \subsection subsection_dma_snippet_4 Snippet 4: Using hardware signals with DMA
  94. * DMA operations can be initiated by a hardware signal, or initiate a hardware signal on completion.
  95. * <br>This snippet shows how either can be done with a timer object.
  96. * \note Not all devices have the same internal connections. As a result, it may not be possible to
  97. * setup connections exactly as shown in the snippet on your device.
  98. *
  99. * In the first case, the DMA output signal (\ref cyhal_dma_enable_output) is used so that when the
  100. * DMA operation complets it in turn causes the timer to run.
  101. * <br>NOTE: The \ref cyhal_dma_init_adv can also be used insted of \ref cyhal_dma_enable_output to
  102. * enable the output. The advantage of using init_adv is it makes sure the DMA instance that is
  103. * allocated is able to connected to the specified signal.
  104. *
  105. * \snippet hal_dma.c snippet_cyhal_dma_triggers_output
  106. *
  107. * The second snippet shows how a timer overflow can be used to trigger a DMA operation. It uses
  108. * \ref cyhal_dma_init_adv to setup the connection, but \ref cyhal_dma_connect_digital could be used
  109. * instead; with the same note as above about ensuring a connection between instances.
  110. *
  111. * \snippet hal_dma.c snippet_cyhal_dma_triggers_input
  112. */
  113. #pragma once
  114. #include <stdbool.h>
  115. #include <stdint.h>
  116. #include "cy_result.h"
  117. #include "cyhal_hw_types.h"
  118. #if defined(__cplusplus)
  119. extern "C" {
  120. #endif
  121. /** \addtogroup group_hal_results_dma DMA HAL Results
  122. * DMA specific return codes
  123. * \ingroup group_hal_results
  124. * \{ *//**
  125. */
  126. /** Invalid transfer width parameter error */
  127. #define CYHAL_DMA_RSLT_ERR_INVALID_TRANSFER_WIDTH \
  128. (CY_RSLT_CREATE_EX(CY_RSLT_TYPE_ERROR, CY_RSLT_MODULE_ABSTRACTION_HAL, CYHAL_RSLT_MODULE_DMA, 0))
  129. /** Invalid parameter error */
  130. #define CYHAL_DMA_RSLT_ERR_INVALID_PARAMETER \
  131. (CY_RSLT_CREATE_EX(CY_RSLT_TYPE_ERROR, CY_RSLT_MODULE_ABSTRACTION_HAL, CYHAL_RSLT_MODULE_DMA, 1))
  132. /** Invalid priority parameter error */
  133. #define CYHAL_DMA_RSLT_ERR_INVALID_PRIORITY \
  134. (CY_RSLT_CREATE_EX(CY_RSLT_TYPE_ERROR, CY_RSLT_MODULE_ABSTRACTION_HAL, CYHAL_RSLT_MODULE_DMA, 2))
  135. /** Invalid src or dst addr alignment error */
  136. #define CYHAL_DMA_RSLT_ERR_INVALID_ALIGNMENT \
  137. (CY_RSLT_CREATE_EX(CY_RSLT_TYPE_ERROR, CY_RSLT_MODULE_ABSTRACTION_HAL, CYHAL_RSLT_MODULE_DMA, 3))
  138. /** Invalid burst_size paramenter error */
  139. #define CYHAL_DMA_RSLT_ERR_INVALID_BURST_SIZE \
  140. (CY_RSLT_CREATE_EX(CY_RSLT_TYPE_ERROR, CY_RSLT_MODULE_ABSTRACTION_HAL, CYHAL_RSLT_MODULE_DMA, 4))
  141. /** Channel busy error */
  142. #define CYHAL_DMA_RSLT_ERR_CHANNEL_BUSY \
  143. (CY_RSLT_CREATE_EX(CY_RSLT_TYPE_ERROR, CY_RSLT_MODULE_ABSTRACTION_HAL, CYHAL_RSLT_MODULE_DMA, 5))
  144. /** Transfer has already been started warning */
  145. #define CYHAL_DMA_RSLT_WARN_TRANSFER_ALREADY_STARTED \
  146. (CY_RSLT_CREATE_EX(CY_RSLT_TYPE_WARNING, CY_RSLT_MODULE_ABSTRACTION_HAL, CYHAL_RSLT_MODULE_DMA, 6))
  147. /** Unsupported hardware error */
  148. #define CYHAL_DMA_RSLT_FATAL_UNSUPPORTED_HARDWARE \
  149. (CY_RSLT_CREATE_EX(CY_RSLT_TYPE_FATAL, CY_RSLT_MODULE_ABSTRACTION_HAL, CYHAL_RSLT_MODULE_DMA, 7))
  150. /** Requested transfer size is not supported */
  151. #define CYHAL_DMA_RSLT_ERR_INVALID_TRANSFER_SIZE \
  152. (CY_RSLT_CREATE_EX(CY_RSLT_TYPE_FATAL, CY_RSLT_MODULE_ABSTRACTION_HAL, CYHAL_RSLT_MODULE_DMA, 8))
  153. /**
  154. * \}
  155. */
  156. /** Direction for DMA transfers. */
  157. typedef enum
  158. {
  159. CYHAL_DMA_DIRECTION_MEM2MEM, //!< Memory to memory
  160. CYHAL_DMA_DIRECTION_MEM2PERIPH, //!< Memory to peripheral
  161. CYHAL_DMA_DIRECTION_PERIPH2MEM, //!< Peripheral to memory
  162. CYHAL_DMA_DIRECTION_PERIPH2PERIPH, //!< Peripheral to peripheral
  163. } cyhal_dma_direction_t;
  164. /** Flags enum of DMA events. Multiple events can be enabled via \ref cyhal_dma_enable_event and
  165. * the callback from \ref cyhal_dma_register_callback will be run to notify. */
  166. typedef enum
  167. {
  168. CYHAL_DMA_NO_INTR = 0, //!< No interrupt
  169. CYHAL_DMA_TRANSFER_COMPLETE = 1 << 0, /**< Indicates that an individual transfer (burst or
  170. full) has completed based on the specified \ref
  171. cyhal_dma_transfer_action_t */
  172. CYHAL_DMA_DESCRIPTOR_COMPLETE = 1 << 1, //!< Indicates that the full transfer has completed
  173. CYHAL_DMA_SRC_BUS_ERROR = 1 << 2, //!< Indicates that there is a source bus error
  174. CYHAL_DMA_DST_BUS_ERROR = 1 << 3, //!< Indicates that there is a destination bus error
  175. CYHAL_DMA_SRC_MISAL = 1 << 4, //!< Indicates that the source address is not aligned
  176. CYHAL_DMA_DST_MISAL = 1 << 5, //!< Indicates that the destination address is not aligned
  177. CYHAL_DMA_CURR_PTR_NULL = 1 << 6, //!< Indicates that the current descriptor pointer is null
  178. CYHAL_DMA_ACTIVE_CH_DISABLED = 1 << 7, //!< Indicates that the active channel is disabled
  179. CYHAL_DMA_DESCR_BUS_ERROR = 1 << 8, //!< Indicates that there has been a descriptor bus error
  180. } cyhal_dma_event_t;
  181. /** Specifies the transfer type to trigger when an input signal is received. */
  182. typedef enum
  183. {
  184. CYHAL_DMA_INPUT_TRIGGER_SINGLE_ELEMENT, //!< Transfer a single element when an input signal is received
  185. CYHAL_DMA_INPUT_TRIGGER_SINGLE_BURST, //!< Transfer a single burst when an input signal is received
  186. CYHAL_DMA_INPUT_TRIGGER_ALL_ELEMENTS, //!< Transfer all elements when an input signal is received
  187. } cyhal_dma_input_t;
  188. /** Specifies the transfer completion event that triggers a signal output. */
  189. typedef enum
  190. {
  191. CYHAL_DMA_OUTPUT_TRIGGER_SINGLE_ELEMENT, //!< Trigger an output when a single element is transferred
  192. CYHAL_DMA_OUTPUT_TRIGGER_SINGLE_BURST, //!< Trigger an output when a single burst is transferred
  193. CYHAL_DMA_OUTPUT_TRIGGER_ALL_ELEMENTS, //!< Trigger an output when all elements are transferred
  194. } cyhal_dma_output_t;
  195. /** This defines the behavior of the the channel when transfers are initiated. It can specify both
  196. * how the transfer is broken up and what happens at the end of the transfer.
  197. * If burst_size from \ref cyhal_dma_cfg_t is used, this specifies the granularity of operations
  198. * that occur. Using \ref CYHAL_DMA_TRANSFER_BURST or \ref CYHAL_DMA_TRANSFER_BURST_DISABLE means
  199. * a single trigger will transfer a single burst (of burst_size) and raise the \ref
  200. * CYHAL_DMA_TRANSFER_COMPLETE interrupt. Using \ref CYHAL_DMA_TRANSFER_FULL means a single trigger
  201. * will transfer all bursts (total size length) and raise the \ref CYHAL_DMA_TRANSFER_COMPLETE
  202. * interrupt. If burst_size is not used, this has no impact and a single trigger will perform a
  203. * complete transfer and raise a single interrupt at the end.
  204. * When the transfer is complete, the channel can be left enabled, or automatically disabled. When
  205. * left enabled (\ref CYHAL_DMA_TRANSFER_BURST or \ref CYHAL_DMA_TRANSFER_FULL) subsequent triggers
  206. * will re-start the transfers. If the channel is diabled on completion (\ref
  207. * CYHAL_DMA_TRANSFER_BURST_DISABLE or \ref CYHAL_DMA_TRANSFER_FULL_DISABLE), \ref
  208. * cyhal_dma_configure must be called to reconfigure the channel for future transfers.
  209. *
  210. * \note When using \ref cyhal_dma_connect_digital for a hardware input trigger, the
  211. * \ref cyhal_dma_input_t argument defines how much of the transfer is initiated at a time. This
  212. * enum will still define when interrupts are raised. */
  213. typedef enum
  214. {
  215. /** A single burst is triggered and a \ref CYHAL_DMA_TRANSFER_COMPLETE will occur after
  216. * each burst. The channel will be left enabled and can continue to be triggered. */
  217. CYHAL_DMA_TRANSFER_BURST,
  218. /** All bursts are triggered and a single \ref CYHAL_DMA_TRANSFER_COMPLETE will occur at
  219. * the end. The channel will be left enabled and can continue to be triggered. */
  220. CYHAL_DMA_TRANSFER_FULL,
  221. /** A single burst is triggered and a \ref CYHAL_DMA_TRANSFER_COMPLETE will occur after
  222. * each burst. When all bursts are complete, the channel will be disabled. */
  223. CYHAL_DMA_TRANSFER_BURST_DISABLE,
  224. /** All bursts are triggered and a single \ref CYHAL_DMA_TRANSFER_COMPLETE will occur at
  225. * the end. When complete, the channel will be disabled. */
  226. CYHAL_DMA_TRANSFER_FULL_DISABLE,
  227. } cyhal_dma_transfer_action_t;
  228. /** \brief Configuration of a DMA channel. When configuring address,
  229. * increments, and transfer width keep in mind your hardware may have more
  230. * stringent address and data alignment requirements. */
  231. typedef struct
  232. {
  233. uint32_t src_addr; //!< Source address. Some devices can apply special requirements for user data arrays. Please refer to implementation-specific documentation to see whether any limitations exist for used device.
  234. int16_t src_increment; //!< Source address auto increment amount in multiples of transfer_width
  235. uint32_t dst_addr; //!< Destination address. Some devices can apply special requirements for user data arrays. Please refer to implementation-specific documentation to see whether any limitations exist for used device.
  236. int16_t dst_increment; //!< Destination address auto increment amount in multiples of transfer_width
  237. uint8_t transfer_width; //!< Transfer width in bits. Valid values are: 8, 16, or 32
  238. uint32_t length; //!< Number of elements to be transferred in total
  239. uint32_t burst_size; //!< Number of elements to be transferred per trigger. If set to 0 every element is transferred, otherwise burst_size must evenly divide length.
  240. cyhal_dma_transfer_action_t action; //!< Sets the behavior of the channel when triggered (using start_transfer). Ignored if burst_size is not configured.
  241. } cyhal_dma_cfg_t;
  242. /** Event handler for DMA interrupts */
  243. typedef void (*cyhal_dma_event_callback_t)(void *callback_arg, cyhal_dma_event_t event);
  244. /** DMA input connection information to setup while initializing the driver. */
  245. typedef struct
  246. {
  247. cyhal_source_t source; //!< Source of signal to DMA; obtained from another driver's cyhal_<PERIPH>_enable_output
  248. cyhal_dma_input_t input; //!< DMA input signal to be driven
  249. } cyhal_dma_src_t;
  250. /** DMA output connection information to setup while initializing the driver. */
  251. typedef struct
  252. {
  253. cyhal_dma_output_t output; //!< Output signal of DMA
  254. cyhal_dest_t dest; //!< Destination of DMA signal
  255. } cyhal_dma_dest_t;
  256. /** Initialize the DMA peripheral.
  257. *
  258. * If a source signal is provided for \p src, this will connect the provided signal to the DMA
  259. * just as would be done by calling \ref cyhal_dma_connect_digital. Similarly, if a destination
  260. * target is provided for \p dest this will enable the specified output just as would be done
  261. * by calling \ref cyhal_dma_enable_output.
  262. * @param[out] obj Pointer to a DMA object. The caller must allocate the memory
  263. * for this object but the init function will initialize its contents.
  264. * @param[in] src An optional source signal to connect to the DMA
  265. * @param[in] dest An optional destination signal to drive from the DMA
  266. * @param[out] dest_source An optional pointer to user-allocated source signal object which
  267. * will be initialized by enable_output. If \p dest is non-null, this must also be non-null.
  268. * \p dest_source should be passed to (dis)connect_digital functions to (dis)connect the
  269. * associated endpoints.
  270. * @param[in] priority The priority of this DMA operation relative to others. The number of
  271. * priority levels which are supported is hardware dependent. All implementations define a
  272. * #CYHAL_DMA_PRIORITY_DEFAULT constant which is always valid. If supported, implementations will
  273. * also define #CYHAL_DMA_PRIORITY_HIGH, #CYHAL_DMA_PRIORITY_MEDIUM, and #CYHAL_DMA_PRIORITY_LOW.
  274. * The behavior of any other value is implementation defined. See the implementation-specific DMA
  275. * documentation for more details.
  276. * @param[in] direction The direction memory is copied
  277. * @return The status of the init request
  278. */
  279. cy_rslt_t cyhal_dma_init_adv(cyhal_dma_t *obj, cyhal_dma_src_t *src, cyhal_dma_dest_t *dest, cyhal_source_t *dest_source, uint8_t priority, cyhal_dma_direction_t direction);
  280. /** Initialize the DMA peripheral.
  281. *
  282. * @param[out] obj Pointer to a DMA object. The caller must allocate the memory for this
  283. * object but the init function will initialize its contents.
  284. * @param[in] priority The priority of this DMA operation relative to others. The number of
  285. * priority levels which are supported is hardware dependent. All implementations define a
  286. * #CYHAL_DMA_PRIORITY_DEFAULT constant which is always valid. If supported, implementations will
  287. * also define #CYHAL_DMA_PRIORITY_HIGH, #CYHAL_DMA_PRIORITY_MEDIUM, and #CYHAL_DMA_PRIORITY_LOW.
  288. * The behavior of any other value is implementation defined. See the implementation-specific DMA
  289. * documentation for more details.
  290. * @param[in] direction The direction memory is copied
  291. * @return The status of the init request
  292. */
  293. #define cyhal_dma_init(obj, priority, direction) (cyhal_dma_init_adv(obj, NULL, NULL, NULL, priority, direction))
  294. /** Initialize the DMA peripheral using data provided by the configurator.
  295. *
  296. * \note Depending on what the configurator allows filling it, it is likely that at least the source
  297. * and destination addresses of the transfer(s) still need to be setup.
  298. *
  299. * @param[out] obj Pointer to a DMA object. The caller must allocate the memory for this
  300. * object but the init function will initialize its contents.
  301. * @param[in] cfg Configuration structure generated by a configurator.
  302. * @return The status of the init request
  303. */
  304. cy_rslt_t cyhal_dma_init_cfg(cyhal_dma_t *obj, const cyhal_dma_configurator_t *cfg);
  305. /** Free the DMA object. Freeing a DMA object while a transfer is in progress
  306. * (\ref cyhal_dma_is_busy) is invalid.
  307. *
  308. * @param[in,out] obj The DMA object
  309. */
  310. void cyhal_dma_free(cyhal_dma_t *obj);
  311. /** Setup the DMA channel behavior. This will also enable the channel to allow it to be triggered.
  312. * The transfer can be software triggered by calling \ref cyhal_dma_start_transfer or by hardware.
  313. * A hardware input signal is setup by \ref cyhal_dma_connect_digital or \ref cyhal_dma_init_adv.
  314. * \note If hardware triggers are used, any necessary event callback setup (\ref
  315. * cyhal_dma_register_callback and \ref cyhal_dma_enable_event) should be done before calling
  316. * this function to ensure the handlers are in place before the transfer can happen.
  317. * \note The automatic enablement of the channel as part of this function is expected to change
  318. * in a future update. This would only happen on a new major release (eg: 1.0 -> 2.0).
  319. * \note If the DMA was setup using \ref cyhal_dma_init_cfg, this function should not be used.
  320. *
  321. * @param[in] obj The DMA object
  322. * @param[in] cfg Configuration parameters for the transfer
  323. * @return The status of the configure request
  324. */
  325. cy_rslt_t cyhal_dma_configure(cyhal_dma_t *obj, const cyhal_dma_cfg_t *cfg);
  326. /** Enable the DMA transfer so that it can start transferring data when triggered. A trigger is
  327. * caused either by calling \ref cyhal_dma_start_transfer or by hardware as a result of a connection
  328. * made in either \ref cyhal_dma_connect_digital or \ref cyhal_dma_init_adv. The DMA can be disabled
  329. * by calling \ref cyhal_dma_disable or by setting the \ref cyhal_dma_cfg_t action to \ref
  330. * CYHAL_DMA_TRANSFER_BURST_DISABLE, or \ref CYHAL_DMA_TRANSFER_FULL_DISABLE.
  331. *
  332. * @param[in] obj The DMA object
  333. * @return The status of the enable request
  334. */
  335. cy_rslt_t cyhal_dma_enable(cyhal_dma_t *obj);
  336. /** Disable the DMA transfer so that it does not continue to trigger. It can be reenabled by calling
  337. * \ref cyhal_dma_enable or \ref cyhal_dma_configure.
  338. *
  339. * @param[in] obj The DMA object
  340. * @return The status of the enable request
  341. */
  342. cy_rslt_t cyhal_dma_disable(cyhal_dma_t *obj);
  343. /** Initiates DMA channel transfer for specified DMA object. This should only be done after the
  344. * channel has been configured (\ref cyhal_dma_configure) and any necessary event callbacks setup
  345. * (\ref cyhal_dma_register_callback \ref cyhal_dma_enable_event)
  346. *
  347. * @param[in] obj The DMA object
  348. * @return The status of the start_transfer request
  349. */
  350. cy_rslt_t cyhal_dma_start_transfer(cyhal_dma_t *obj);
  351. /** Checks if the transfer has been triggered, but not yet complete (eg: is pending, blocked or running)
  352. *
  353. * @param[in] obj The DMA object
  354. * @return True if DMA channel is busy
  355. */
  356. bool cyhal_dma_is_busy(cyhal_dma_t *obj);
  357. /** Register a DMA callback handler.
  358. *
  359. * This function will be called when one of the events enabled by \ref cyhal_dma_enable_event occurs.
  360. *
  361. * @param[in] obj The DMA object
  362. * @param[in] callback The callback handler which will be invoked when an event triggers
  363. * @param[in] callback_arg Generic argument that will be provided to the callback when called
  364. */
  365. void cyhal_dma_register_callback(cyhal_dma_t *obj, cyhal_dma_event_callback_t callback, void *callback_arg);
  366. /** Configure DMA event enablement.
  367. *
  368. * When an enabled event occurs, the function specified by \ref cyhal_dma_register_callback will be called.
  369. *
  370. * @param[in] obj The DMA object
  371. * @param[in] event The DMA event type
  372. * @param[in] intr_priority The priority for NVIC interrupt events. The priority from the most
  373. * recent call will take precedence, i.e all events will have the same priority.
  374. * @param[in] enable True to turn on interrupts, False to turn off
  375. */
  376. void cyhal_dma_enable_event(cyhal_dma_t *obj, cyhal_dma_event_t event, uint8_t intr_priority, bool enable);
  377. /** Connects a source signal and enables the specified input to the DMA channel. This connection
  378. * can also be setup automatically on initialization via \ref cyhal_dma_init_adv. If the signal
  379. * needs to be disconnected later, \ref cyhal_dma_disconnect_digital can be used.
  380. *
  381. * @param[in] obj The DMA object
  382. * @param[in] source Source signal obtained from another driver's cyhal_<PERIPH>_enable_output
  383. * @param[in] input Which input to enable
  384. * @return The status of the connection
  385. */
  386. cy_rslt_t cyhal_dma_connect_digital(cyhal_dma_t *obj, cyhal_source_t source, cyhal_dma_input_t input);
  387. /** Enables the specified output signal from a DMA channel that is triggered when a transfer is
  388. * completed. This can also be setup automatically on initialization via \ref cyhal_dma_init_adv.
  389. * If the output is not needed in the future, \ref cyhal_dma_disable_output can be used.
  390. *
  391. * @param[in] obj The DMA object
  392. * @param[in] output Which event triggers the output
  393. * @param[out] source Pointer to user-allocated source signal object which
  394. * will be initialized by enable_output. \p source should be passed to
  395. * (dis)connect_digital functions to (dis)connect the associated endpoints.
  396. * @return The status of the output enable
  397. */
  398. cy_rslt_t cyhal_dma_enable_output(cyhal_dma_t *obj, cyhal_dma_output_t output, cyhal_source_t *source);
  399. /** Disconnects a source signal and disables the specified input to the DMA channel. This removes
  400. * the connection that was established by either \ref cyhal_dma_init_adv or \ref
  401. * cyhal_dma_connect_digital.
  402. *
  403. * @param[in] obj The DMA object
  404. * @param[in] source Source signal from cyhal_<PERIPH>_enable_output to disable
  405. * @param[in] input Which input to disable
  406. * @return The status of the disconnect
  407. */
  408. cy_rslt_t cyhal_dma_disconnect_digital(cyhal_dma_t *obj, cyhal_source_t source, cyhal_dma_input_t input);
  409. /** Disables the specified output signal from a DMA channel. This turns off the signal that was
  410. * enabled by either \ref cyhal_dma_init_adv or \ref cyhal_dma_enable_output. It is recommended
  411. * that the signal is disconnected (cyhal_<PERIPH>_disconnect_digital) from anything it might be
  412. * driving before being disabled.
  413. *
  414. * @param[in] obj The DMA object
  415. * @param[in] output Which output to disable
  416. * @return The status of the disablement
  417. * */
  418. cy_rslt_t cyhal_dma_disable_output(cyhal_dma_t *obj, cyhal_dma_output_t output);
  419. #if defined(__cplusplus)
  420. }
  421. #endif
  422. #ifdef CYHAL_DMA_IMPL_HEADER
  423. #include CYHAL_DMA_IMPL_HEADER
  424. #endif /* CYHAL_DMA_IMPL_HEADER */
  425. /** \} group_hal_dma */