gr55xx_hal_dma.h
Go to the documentation of this file.
1 /**
2 ****************************************************************************************
3 *
4 * @file gr55xx_hal_dma.h
5 * @author BLE Driver Team
6 * @brief Header file containing functions prototypes of DMA HAL library.
7 *
8 ****************************************************************************************
9 * @attention
10 #####Copyright (c) 2019 GOODIX
11 All rights reserved.
12
13 Redistribution and use in source and binary forms, with or without
14 modification, are permitted provided that the following conditions are met:
15 * Redistributions of source code must retain the above copyright
16 notice, this list of conditions and the following disclaimer.
17 * Redistributions in binary form must reproduce the above copyright
18 notice, this list of conditions and the following disclaimer in the
19 documentation and/or other materials provided with the distribution.
20 * Neither the name of GOODIX nor the names of its contributors may be used
21 to endorse or promote products derived from this software without
22 specific prior written permission.
23
24 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
28 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 POSSIBILITY OF SUCH DAMAGE.
35 ****************************************************************************************
36 */
37
38 /** @addtogroup PERIPHERAL Peripheral Driver
39 * @{
40 */
41
42 /** @addtogroup HAL_DRIVER HAL Driver
43 * @{
44 */
45
46 /** @defgroup HAL_DMA DMA
47 * @brief DMA HAL module driver.
48 * @{
49 */
50
51 /* Define to prevent recursive inclusion -------------------------------------*/
52 #ifndef __GR55xx_HAL_DMA_H__
53 #define __GR55xx_HAL_DMA_H__
54
55 #ifdef __cplusplus
56 extern "C" {
57 #endif
58
59 /* Includes ------------------------------------------------------------------*/
60 #include "gr55xx_ll_dma.h"
61 #include "gr55xx_hal_def.h"
62
63 /* Exported types ------------------------------------------------------------*/
64 /** @addtogroup HAL_DMA_ENUMERATIONS Enumerations
65 * @{
66 */
67
68 /** @defgroup HAL_DMA_state HAL DMA state
69 * @{
70 */
71
72 /**
73 * @brief HAL DMA State Enumerations definition
74 */
75 typedef enum
76 {
77 HAL_DMA_STATE_RESET = 0x00U, /**< DMA not yet initialized or disabled */
78 HAL_DMA_STATE_READY = 0x01U, /**< DMA process success and ready for use */
79 HAL_DMA_STATE_BUSY = 0x02U, /**< DMA process is ongoing */
80 HAL_DMA_STATE_TIMEOUT = 0x03U, /**< DMA timeout state */
81 HAL_DMA_STATE_ERROR = 0x04U, /**< DMA error state */
82 } hal_dma_state_t;
83 /** @} */
84
85 /** @defgroup HAL_DMA_channel HAL DMA channel
86 * @{
87 */
88
89 /**
90 * @brief HAL DMA Channel Enumerations definition
91 */
92 typedef enum
93 {
94 DMA_Channel0 = 0U, /**< Channel 0 */
95 DMA_Channel1 = 1U, /**< Channel 1 */
96 DMA_Channel2 = 2U, /**< Channel 2 */
97 DMA_Channel3 = 3U, /**< Channel 3 */
98 DMA_Channel4 = 4U, /**< Channel 4 */
99 DMA_Channel5 = 5U, /**< Channel 5 */
100 DMA_Channel6 = 6U, /**< Channel 6 */
101 DMA_Channel7 = 7U, /**< Channel 7 */
102 } dma_channel_t;
103 /** @} */
104
105 /** @defgroup HAL_DMA_callback_ID HAL DMA callback ID
106 * @{
107 */
108
109 /**
110 * @brief HAL DMA Callback ID Enumerations definition
111 */
112 typedef enum
113 {
114 HAL_DMA_XFER_TFR_CB_ID = 0x00, /**< Full transfer */
115 HAL_DMA_XFER_BLK_CB_ID = 0x01, /**< Block transfer */
116 HAL_DMA_XFER_ERROR_CB_ID = 0x02, /**< Error */
117 HAL_DMA_XFER_ABORT_CB_ID = 0x03, /**< Abort */
118 HAL_DMA_XFER_ALL_CB_ID = 0x04 /**< All */
119 } hal_dma_callback_id_t;
120 /** @} */
121
122 /** @} */
123
124
125 /** @addtogroup HAL_DMA_STRUCTURES Structures
126 * @{
127 */
128
129 /** @defgroup DMA_Configuration DMA Configuration
130 * @{
131 */
132
133 /**
134 * @brief DMA Configuration Structure definition
135 */
136 typedef struct _dma_init
137 {
138 uint32_t src_request; /**< Specifies the source request selected for the specified channel.
139 This parameter can be a value of @ref DMA_request */
140
141 uint32_t dst_request; /**< Specifies the destination request selected for the specified channel.
142 This parameter can be a value of @ref DMA_request */
143
144 uint32_t direction; /**< Specifies if the data will be transferred from memory to peripheral,
145 from memory to memory or from peripheral to memory.
146 This parameter can be a value of @ref DMA_Data_transfer_direction */
147
148 uint32_t src_increment; /**< Specifies whether the srouce address register should be incremented or decrement or not.
149 This parameter can be a value of @ref DMA_Source_incremented_mode */
150
151 uint32_t dst_increment; /**< Specifies whether the destination address register should be incremented or decrement or not.
152 This parameter can be a value of @ref DMA_Destination_incremented_mode */
153
154 uint32_t src_data_alignment; /**< Specifies the source data width.
155 This parameter can be a value of @ref DMA_Source_data_size */
156
157 uint32_t dst_data_alignment; /**< Specifies the destination data width.
158 This parameter can be a value of @ref DMA_Destination_data_size */
159
160 uint32_t mode; /**< Specifies the operation mode of the DMA Channel(Normal or Circular).
161 This parameter can be a value of @ref DMA_mode
162 @note The circular buffer mode cannot be used if the memory-to-memory
163 data transfer is configured on the selected Channel */
164
165 uint32_t priority; /**< Specifies the software priority for the DMA Channel.
166 This parameter can be a value of @ref DMA_Priority_level */
167 } dma_init_t;
168
169 /** @} */
170
171 /** @defgroup DMA_handle DMA handle
172 * @{
173 */
174
175 /**
176 * @brief DMA handle Structure definition
177 */
178 typedef struct _dma_handle
179 {
180 dma_channel_t channel; /**< DMA Channel Number */
181
182 dma_init_t init; /**< DMA communication parameters */
183
184 hal_lock_t lock; /**< DMA locking object */
185
186 __IO hal_dma_state_t state; /**< DMA transfer state */
187
188 void *p_parent; /**< Parent object state */
189
190 void (* xfer_tfr_callback)(struct _dma_handle *p_dma); /**< DMA transfer complete callback */
191
192 void (* xfer_blk_callback)(struct _dma_handle *p_dma); /**< DMA block complete callback */
193
194 void (* xfer_error_callback)(struct _dma_handle *p_dma); /**< DMA transfer error callback */
195
196 void (* xfer_abort_callback)(struct _dma_handle *p_dma); /**< DMA transfer abort callback */
197
198 __IO uint32_t error_code; /**< DMA Error code */
199
200 uint32_t retention[5]; /**< DMA important register information. */
201 } dma_handle_t;
202
203 /** @} */
204
205 /** @} */
206
207
208 /**
209 * @defgroup HAL_DMA_MACRO Defines
210 * @{
211 */
212
213 /* Exported constants --------------------------------------------------------*/
214 /** @defgroup DMA_Exported_Constants DMA Exported Constants
215 * @{
216 */
217
218 /** @defgroup DMA_Error_Code DMA Error Code
219 * @{
220 */
221 #define HAL_DMA_ERROR_NONE ((uint32_t)0x00000000U) /**< No error */
222 #define HAL_DMA_ERROR_TE ((uint32_t)0x00000001U) /**< Transfer error */
223 #define HAL_DMA_ERROR_NO_XFER ((uint32_t)0x00000004U) /**< no ongoing transfer */
224 #define HAL_DMA_ERROR_TIMEOUT ((uint32_t)0x00000020U) /**< Timeout error */
225 /** @} */
226
227 /** @defgroup DMA_request DMA request definitions
228 * @{
229 */
230 #define DMA_REQUEST_SPIM_TX LL_DMA_PERIPH_SPIM_TX /**< DMA SPIM transmit request */
231 #define DMA_REQUEST_SPIM_RX LL_DMA_PERIPH_SPIM_RX /**< DMA SPIM receive request */
232 #define DMA_REQUEST_SPIS_TX LL_DMA_PERIPH_SPIS_TX /**< DMA SPIS transmit request */
233 #define DMA_REQUEST_SPIS_RX LL_DMA_PERIPH_SPIS_RX /**< DMA SPIS receive request */
234 #define DMA_REQUEST_QSPI0_TX LL_DMA_PERIPH_QSPI0_TX /**< DMA QSPI0 transmit request */
235 #define DMA_REQUEST_QSPI0_RX LL_DMA_PERIPH_QSPI0_RX /**< DMA QSPI0 receive request */
236 #define DMA_REQUEST_I2C0_TX LL_DMA_PERIPH_I2C0_TX /**< DMA I2C0 transmit request */
237 #define DMA_REQUEST_I2C0_RX LL_DMA_PERIPH_I2C0_RX /**< DMA I2C0 receive request */
238 #define DMA_REQUEST_I2C1_TX LL_DMA_PERIPH_I2C1_TX /**< DMA I2C1 transmit request */
239 #define DMA_REQUEST_I2C1_RX LL_DMA_PERIPH_I2C1_RX /**< DMA I2C1 receive request */
240 #define DMA_REQUEST_I2S_S_TX LL_DMA_PERIPH_I2S_S_TX /**< DMA I2S_S transmit request */
241 #define DMA_REQUEST_I2S_S_RX LL_DMA_PERIPH_I2S_S_RX /**< DMA I2S_S receive request */
242 #define DMA_REQUEST_UART0_TX LL_DMA_PERIPH_UART0_TX /**< DMA UART0 transmit request */
243 #define DMA_REQUEST_UART0_RX LL_DMA_PERIPH_UART0_RX /**< DMA UART0 receive request */
244 #define DMA_REQUEST_QSPI1_TX LL_DMA_PERIPH_QSPI1_TX /**< DMA QSPI1 transmit request */
245 #define DMA_REQUEST_QSPI1_RX LL_DMA_PERIPH_QSPI1_RX /**< DMA QSPI1 receive request */
246 #define DMA_REQUEST_I2S_M_TX LL_DMA_PERIPH_I2S_M_TX /**< DMA I2S_M transmit request */
247 #define DMA_REQUEST_I2S_M_RX LL_DMA_PERIPH_I2S_M_RX /**< DMA I2S_M receive request */
248 #define DMA_REQUEST_SNSADC LL_DMA_PERIPH_SNSADC /**< DMA SenseADC request */
249 #define DMA_REQUEST_MEM LL_DMA_PERIPH_MEM /**< DMA Memory request */
250 /** @} */
251
252 /** @defgroup DMA_Data_transfer_direction DMA Data Transfer directions
253 * @{
254 */
255 #define DMA_MEMORY_TO_MEMORY LL_DMA_DIRECTION_MEMORY_TO_MEMORY /**< Memory to memory direction */
256 #define DMA_MEMORY_TO_PERIPH LL_DMA_DIRECTION_MEMORY_TO_PERIPH /**< Memory to peripheral direction */
257 #define DMA_PERIPH_TO_MEMORY LL_DMA_DIRECTION_PERIPH_TO_MEMORY /**< Peripheral to memory direction */
258 #define DMA_PERIPH_TO_PERIPH LL_DMA_DIRECTION_PERIPH_TO_PERIPH /**< Peripheral to Peripheral direction */
259 /** @} */
260
261 /** @defgroup DMA_Source_incremented_mode DMA Source Incremented Mode
262 * @{
263 */
264 #define DMA_SRC_INCREMENT LL_DMA_SRC_INCREMENT /**< Source increment mode */
265 #define DMA_SRC_DECREMENT LL_DMA_SRC_DECREMENT /**< Source decrement mode */
266 #define DMA_SRC_NO_CHANGE LL_DMA_SRC_NO_CHANGE /**< Source no change mode */
267 /** @} */
268
269 /** @defgroup DMA_Destination_incremented_mode DMA Destination Incremented Mode
270 * @{
271 */
272 #define DMA_DST_INCREMENT LL_DMA_DST_INCREMENT /**< Destination increment mode */
273 #define DMA_DST_DECREMENT LL_DMA_DST_DECREMENT /**< Destination decrement mode */
274 #define DMA_DST_NO_CHANGE LL_DMA_DST_NO_CHANGE /**< Destination no change mode */
275 /** @} */
276
277 /** @defgroup DMA_Source_data_size DMA Source Data Size Alignment
278 * @{
279 */
280 #define DMA_SDATAALIGN_BYTE LL_DMA_SDATAALIGN_BYTE /**< Source data alignment : Byte */
281 #define DMA_SDATAALIGN_HALFWORD LL_DMA_SDATAALIGN_HALFWORD /**< Source data alignment : HalfWord */
282 #define DMA_SDATAALIGN_WORD LL_DMA_SDATAALIGN_WORD /**< Source data alignment : Word */
283 /** @} */
284
285 /** @defgroup DMA_Destination_data_size DMA Destination Data Size Alignment
286 * @{
287 */
288 #define DMA_DDATAALIGN_BYTE LL_DMA_DDATAALIGN_BYTE /**< Destination data alignment : Byte */
289 #define DMA_DDATAALIGN_HALFWORD LL_DMA_DDATAALIGN_HALFWORD /**< Destination data alignment : HalfWord */
290 #define DMA_DDATAALIGN_WORD LL_DMA_DDATAALIGN_WORD /**< Destination data alignment : Word */
291 /** @} */
292
293 /** @defgroup DMA_mode DMA Mode
294 * @{
295 */
296 #define DMA_NORMAL LL_DMA_MODE_SINGLE_BLOCK /**< Normal Mode */
297 #define DMA_CIRCULAR LL_DMA_MODE_MULTI_BLOCK_ALL_RELOAD /**< Circular Mode */
298
299 /** @} */
300
301 /** @defgroup DMA_Priority_level DMA Priority Level
302 * @{
303 */
304 #define DMA_PRIORITY_LOW LL_DMA_PRIORITY_0 /**< Priority level : Low */
305 #define DMA_PRIORITY_MEDIUM LL_DMA_PRIORITY_2 /**< Priority level : Medium */
306 #define DMA_PRIORITY_HIGH LL_DMA_PRIORITY_5 /**< Priority level : High */
307 #define DMA_PRIORITY_VERY_HIGH LL_DMA_PRIORITY_7 /**< Priority level : Very High */
308 /** @} */
309
310 /** @} */
311
312 /* Private macros ------------------------------------------------------------*/
313 /** @defgroup DMA_Private_Macro DMA Private Macros
314 * @{
315 */
316
317 /** @brief Check if DMA channel instance is valid.
318 * @param __instance__ DMA channel instance.
319 * @retval SET (__instance__ is valid) or RESET (__instance__ is invalid)
320 */
321 #define IS_DMA_ALL_INSTANCE(__instance__) (((__instance__) == DMA_Channel0) || \
322 ((__instance__) == DMA_Channel1) || \
323 ((__instance__) == DMA_Channel2) || \
324 ((__instance__) == DMA_Channel3) || \
325 ((__instance__) == DMA_Channel4) || \
326 ((__instance__) == DMA_Channel5) || \
327 ((__instance__) == DMA_Channel6) || \
328 ((__instance__) == DMA_Channel7))
329
330 /** @brief Check if DMA request is valid.
331 * @param __REQUEST__ DMA request.
332 * @retval SET (__REQUEST__ is valid) or RESET (__REQUEST__ is invalid)
333 */
334 #define IS_DMA_ALL_REQUEST(__REQUEST__) (((__REQUEST__) == DMA_REQUEST_SPIM_TX) || \
335 ((__REQUEST__) == DMA_REQUEST_SPIM_RX) || \
336 ((__REQUEST__) == DMA_REQUEST_SPIS_TX) || \
337 ((__REQUEST__) == DMA_REQUEST_SPIS_RX) || \
338 ((__REQUEST__) == DMA_REQUEST_QSPI0_TX) || \
339 ((__REQUEST__) == DMA_REQUEST_QSPI0_RX) || \
340 ((__REQUEST__) == DMA_REQUEST_I2C0_TX) || \
341 ((__REQUEST__) == DMA_REQUEST_I2C0_RX) || \
342 ((__REQUEST__) == DMA_REQUEST_I2C1_TX) || \
343 ((__REQUEST__) == DMA_REQUEST_I2C1_RX) || \
344 ((__REQUEST__) == DMA_REQUEST_I2S_S_TX) || \
345 ((__REQUEST__) == DMA_REQUEST_I2S_S_RX) || \
346 ((__REQUEST__) == DMA_REQUEST_UART0_TX) || \
347 ((__REQUEST__) == DMA_REQUEST_UART0_RX) || \
348 ((__REQUEST__) == DMA_REQUEST_QSPI1_TX) || \
349 ((__REQUEST__) == DMA_REQUEST_QSPI1_RX) || \
350 ((__REQUEST__) == DMA_REQUEST_I2S_M_TX) || \
351 ((__REQUEST__) == DMA_REQUEST_I2S_M_RX) || \
352 ((__REQUEST__) == DMA_REQUEST_SNSADC) || \
353 ((__REQUEST__) == DMA_REQUEST_MEM))
354
355 /** @brief Check if DMA direction is valid.
356 * @param __DIRECTION__ DMA direction.
357 * @retval SET (__DIRECTION__ is valid) or RESET (__DIRECTION__ is invalid)
358 */
359 #define IS_DMA_DIRECTION(__DIRECTION__) (((__DIRECTION__) == DMA_MEMORY_TO_MEMORY) || \
360 ((__DIRECTION__) == DMA_MEMORY_TO_PERIPH) || \
361 ((__DIRECTION__) == DMA_PERIPH_TO_MEMORY) || \
362 ((__DIRECTION__) == DMA_PERIPH_TO_PERIPH))
363
364 /** @brief Check if DMA buffer size is valid.
365 * @param __SIZE__ DMA buffer size.
366 * @retval SET (__SIZE__ is valid) or RESET (__SIZE__ is invalid)
367 */
368 #define IS_DMA_BUFFER_SIZE(__SIZE__) (((__SIZE__) >= 0x1) && ((__SIZE__) < 0xFFF))
369
370 /** @brief Check if DMA source address increment state is valid.
371 * @param __STATE__ DMA source address increment state.
372 * @retval SET (__STATE__ is valid) or RESET (__STATE__ is invalid)
373 */
374 #define IS_DMA_SOURCE_INC_STATE(__STATE__) (((__STATE__) == DMA_SRC_INCREMENT) || \
375 ((__STATE__) == DMA_SRC_DECREMENT) || \
376 ((__STATE__) == DMA_SRC_NO_CHANGE))
377
378 /** @brief Check if DMA destination address increment state is valid.
379 * @param __STATE__ DMA destination address increment state.
380 * @retval SET (__STATE__ is valid) or RESET (__STATE__ is invalid)
381 */
382 #define IS_DMA_DESTINATION_INC_STATE(__STATE__) (((__STATE__) == DMA_DST_INCREMENT) || \
383 ((__STATE__) == DMA_DST_DECREMENT) || \
384 ((__STATE__) == DMA_DST_NO_CHANGE))
385
386 /** @brief Check if DMA source data size is valid.
387 * @param __SIZE__ DMA source data size.
388 * @retval SET (__SIZE__ is valid) or RESET (__SIZE__ is invalid)
389 */
390 #define IS_DMA_SOURCE_DATA_SIZE(__SIZE__) (((__SIZE__) == DMA_SDATAALIGN_BYTE) || \
391 ((__SIZE__) == DMA_SDATAALIGN_HALFWORD) || \
392 ((__SIZE__) == DMA_SDATAALIGN_WORD))
393
394 /** @brief Check if DMA destination data size is valid.
395 * @param __SIZE__ DMA destination data size.
396 * @retval SET (__SIZE__ is valid) or RESET (__SIZE__ is invalid)
397 */
398 #define IS_DMA_DESTINATION_DATA_SIZE(__SIZE__) (((__SIZE__) == DMA_DDATAALIGN_BYTE) || \
399 ((__SIZE__) == DMA_DDATAALIGN_HALFWORD) || \
400 ((__SIZE__) == DMA_DDATAALIGN_WORD ))
401
402 /** @brief Check if DMA mode is valid.
403 * @param __MODE__ DMA mode.
404 * @retval SET (__MODE__ is valid) or RESET (__MODE__ is invalid)
405 */
406 #define IS_DMA_MODE(__MODE__) (((__MODE__) == DMA_NORMAL ) || \
407 ((__MODE__) == DMA_CIRCULAR))
408
409 /** @brief Check if DMA priority is valid.
410 * @param __PRIORITY__ DMA priority.
411 * @retval SET (__PRIORITY__ is valid) or RESET (__PRIORITY__ is invalid)
412 */
413 #define IS_DMA_PRIORITY(__PRIORITY__) (((__PRIORITY__) == DMA_PRIORITY_LOW ) || \
414 ((__PRIORITY__) == DMA_PRIORITY_MEDIUM) || \
415 ((__PRIORITY__) == DMA_PRIORITY_HIGH) || \
416 ((__PRIORITY__) == DMA_PRIORITY_VERY_HIGH))
417 /** @} */
418
419 /** @} */
420
421
422 /* Exported functions --------------------------------------------------------*/
423 /** @addtogroup HAL_DMA_DRIVER_FUNCTIONS Functions
424 * @{
425 */
426
427 /** @defgroup DMA_Exported_Functions_Group1 Initialization and de-initialization functions
428 * @brief Initialization and de-initialization functions
429 *
430 @verbatim
431 ===============================================================================
432 ##### Initialization and de-initialization functions #####
433 ===============================================================================
434 [..]
435 This section provides functions allowing to initialize the DMA Channel source
436 and destination addresses, incrementation and data sizes, transfer direction,
437 circular/normal mode selection, memory-to-memory mode selection and Channel priority value.
438 [..]
439 The hal_dma_init() function follows the DMA configuration procedures as described in
440 reference manual.
441
442 @endverbatim
443 * @{
444 */
445
446 /**
447 ****************************************************************************************
448 * @brief Initialize the DMA according to the specified
449 * parameters in the dma_init_t and initialize the associated handle.
450 *
451 * @param[in] p_dma: Pointer to a DMA handle which contains the configuration information for the specified DMA Channel.
452 *
453 * @retval ::HAL_OK: Operation is OK.
454 * @retval ::HAL_ERROR: Parameter error or operation not supported.
455 * @retval ::HAL_BUSY: Driver is busy.
456 * @retval ::HAL_TIMEOUT: Timeout occurred.
457 ****************************************************************************************
458 */
459 hal_status_t hal_dma_init(dma_handle_t *p_dma);
460
461 /**
462 ****************************************************************************************
463 * @brief De-initialize the DMA peripheral.
464 *
465 * @param[in] p_dma: Pointer to a DMA handle which contains the configuration information for the specified DMA Channel.
466 *
467 * @retval ::HAL_OK: Operation is OK.
468 * @retval ::HAL_ERROR: Parameter error or operation not supported.
469 * @retval ::HAL_BUSY: Driver is busy.
470 * @retval ::HAL_TIMEOUT: Timeout occurred.
471 ****************************************************************************************
472 */
473 hal_status_t hal_dma_deinit (dma_handle_t *p_dma);
474
475 /** @} */
476
477
478 /** @defgroup DMA_Exported_Functions_Group2 Input and Output operation functions
479 * @brief Input and Output operation functions
480 *
481 @verbatim
482 ===============================================================================
483 ##### IO operation functions #####
484 ===============================================================================
485 [..] This section provides functions allowing to:
486 (+) Configure the source, destination address and data length and Start DMA transfer
487 (+) Configure the source, destination address and data length and
488 Start DMA transfer with interrupt
489 (+) Abort DMA transfer
490 (+) Poll for transfer complete
491 (+) Handle DMA interrupt request
492
493 @endverbatim
494 * @{
495 */
496
497 /**
498 ****************************************************************************************
499 * @brief Start the DMA Transfer.
500 *
501 * @param[in] p_dma: Pointer to a DMA handle which contains the configuration information for the specified DMA Channel.
502 * @param[in] src_address: The source memory Buffer address
503 * @param[in] dst_address: The destination memory Buffer address
504 * @param[in] data_length: The length of data to be transferred from source to destination, ranging between 0 and 4095.
505 *
506 * @retval ::HAL_OK: Operation is OK.
507 * @retval ::HAL_ERROR: Parameter error or operation not supported.
508 * @retval ::HAL_BUSY: Driver is busy.
509 * @retval ::HAL_TIMEOUT: Timeout occurred.
510 ****************************************************************************************
511 */
512 hal_status_t hal_dma_start (dma_handle_t *p_dma, uint32_t src_address, uint32_t dst_address, uint32_t data_length);
513
514 /**
515 ****************************************************************************************
516 * @brief Start the DMA Transfer with interrupt enabled.
517 *
518 * @param[in] p_dma: Pointer to a DMA handle which contains the configuration information for the specified DMA Channel.
519 * @param[in] src_address: The source memory Buffer address
520 * @param[in] dst_address: The destination memory Buffer address
521 * @param[in] data_length: The length of data to be transferred from source to destination, ranging between 0 and 4095.
522 *
523 * @retval ::HAL_OK: Operation is OK.
524 * @retval ::HAL_ERROR: Parameter error or operation not supported.
525 * @retval ::HAL_BUSY: Driver is busy.
526 * @retval ::HAL_TIMEOUT: Timeout occurred.
527 ****************************************************************************************
528 */
529 hal_status_t hal_dma_start_it(dma_handle_t *p_dma, uint32_t src_address, uint32_t dst_address, uint32_t data_length);
530
531 /**
532 ****************************************************************************************
533 * @brief Abort the DMA Transfer.
534 *
535 * @param[in] p_dma: Pointer to a DMA handle which contains the configuration information for the specified DMA Channel.
536 *
537 * @retval ::HAL_OK: Operation is OK.
538 * @retval ::HAL_ERROR: Parameter error or operation not supported.
539 * @retval ::HAL_BUSY: Driver is busy.
540 * @retval ::HAL_TIMEOUT: Timeout occurred.
541 ****************************************************************************************
542 */
543 hal_status_t hal_dma_abort(dma_handle_t *p_dma);
544
545 /**
546 ****************************************************************************************
547 * @brief Aborts the DMA Transfer in Interrupt mode.
548 *
549 * @param[in] p_dma: Pointer to a DMA handle which contains the configuration information for the specified DMA Channel.
550 *
551 * @retval ::HAL_OK: Operation is OK.
552 * @retval ::HAL_ERROR: Parameter error or operation not supported.
553 * @retval ::HAL_BUSY: Driver is busy.
554 * @retval ::HAL_TIMEOUT: Timeout occurred.
555 ****************************************************************************************
556 */
557 hal_status_t hal_dma_abort_it(dma_handle_t *p_dma);
558
559 /**
560 ****************************************************************************************
561 * @brief Polling for transfer complete.
562 *
563 * @param[in] p_dma: Pointer to a DMA handle which contains the configuration information for the specified DMA Channel.
564 * @param[in] timeout: Timeout duration.
565 *
566 * @retval ::HAL_OK: Operation is OK.
567 * @retval ::HAL_ERROR: Parameter error or operation not supported.
568 * @retval ::HAL_BUSY: Driver is busy.
569 * @retval ::HAL_TIMEOUT: Timeout occurred.
570 ****************************************************************************************
571 */
572 hal_status_t hal_dma_poll_for_transfer(dma_handle_t *p_dma, uint32_t timeout);
573
574 /** @} */
575
576 /** @addtogroup DMA_IRQ_Handler_and_Callbacks IRQ Handler and Callbacks
577 * @brief IRQ Handler and Callbacks functions
578 * @{
579 */
580
581 /**
582 ****************************************************************************************
583 * @brief Handle DMA interrupt request.
584 *
585 * @param[in] p_dma: Pointer to a DMA handle which contains the configuration information for the specified DMA Channel.
586 ****************************************************************************************
587 */
588 void hal_dma_irq_handler(dma_handle_t *p_dma);
589
590 /**
591 ****************************************************************************************
592 * @brief Register callbacks
593 *
594 * @param[in] p_dma: Pointer to a DMA handle which contains the configuration information for the specified DMA Channel.
595 * @param[in] id: User Callback identifer. This parameter can be one of the following values:
596 * @arg @ref HAL_DMA_XFER_TFR_CB_ID
597 * @arg @ref HAL_DMA_XFER_BLK_CB_ID
598 * @arg @ref HAL_DMA_XFER_ERROR_CB_ID
599 * @arg @ref HAL_DMA_XFER_ABORT_CB_ID
600 * @param[in] callback: Pointer to private callbacsk function which has pointer to a dma_handle_t structure as parameter.
601 *
602 * @retval ::HAL_OK: Operation is OK.
603 * @retval ::HAL_ERROR: Parameter error or operation not supported.
604 * @retval ::HAL_BUSY: Driver is busy.
605 * @retval ::HAL_TIMEOUT: Timeout occurred.
606 ****************************************************************************************
607 */
608 hal_status_t hal_dma_register_callback(dma_handle_t *p_dma, hal_dma_callback_id_t id, void (* callback)( dma_handle_t * p_dma));
609
610 /**
611 ****************************************************************************************
612 * @brief UnRegister callbacks
613 *
614 * @param[in] p_dma: Pointer to a DMA handle which contains the configuration information for the specified DMA Channel.
615 * @param[in] id: User Callback identifer. This parameter can be a combiantion of the following values:
616 * @arg @ref HAL_DMA_XFER_TFR_CB_ID
617 * @arg @ref HAL_DMA_XFER_BLK_CB_ID
618 * @arg @ref HAL_DMA_XFER_ERROR_CB_ID
619 * @arg @ref HAL_DMA_XFER_ABORT_CB_ID
620 * @arg @ref HAL_DMA_XFER_ALL_CB_ID
621 *
622 * @retval ::HAL_OK: Operation is OK.
623 * @retval ::HAL_ERROR: Parameter error or operation not supported.
624 * @retval ::HAL_BUSY: Driver is busy.
625 * @retval ::HAL_TIMEOUT: Timeout occurred.
626 ****************************************************************************************
627 */
628 hal_status_t hal_dma_unregister_callback(dma_handle_t *p_dma, hal_dma_callback_id_t id);
629
630 /** @} */
631
632 /** @defgroup DMA_Exported_Functions_Group3 Peripheral State and Errors functions
633 * @brief Peripheral State and Errors functions
634 *
635 @verbatim
636 ===============================================================================
637 ##### Peripheral State and Errors functions #####
638 ===============================================================================
639 [..]
640 This subsection provides functions allowing to
641 (+) Check the DMA state
642 (+) Get error code
643
644 @endverbatim
645 * @{
646 */
647
648 /**
649 ****************************************************************************************
650 * @brief Return the DMA hande state.
651 *
652 * @param[in] p_dma: Pointer to a DMA handle which contains the configuration information for the specified DMA Channel.
653 *
654 * @retval ::HAL_DMA_STATE_RESET: DMA not yet initialized or disabled.
655 * @retval ::HAL_DMA_STATE_READY: DMA process succeeded and ready for use.
656 * @retval ::HAL_DMA_STATE_BUSY: DMA process is ongoing.
657 * @retval ::HAL_DMA_STATE_TIMEOUT: DMA timeout state.
658 * @retval ::HAL_DMA_STATE_ERROR: DMA error state.
659 ****************************************************************************************
660 */
661 hal_dma_state_t hal_dma_get_state(dma_handle_t *p_dma);
662
663 /**
664 ****************************************************************************************
665 * @brief Return the DMA error code.
666 *
667 * @param[in] p_dma: Pointer to a DMA handle which contains the configuration information for the specified DMA Channel.
668 *
669 * @return DMA Error Code
670 ****************************************************************************************
671 */
672 uint32_t hal_dma_get_error(dma_handle_t *p_dma);
673
674 /**
675 ****************************************************************************************
676 * @brief Suspend some registers related to DMA configuration before sleep.
677 * @param[in] p_dma: Pointer to a DMA handle which contains the configuration
678 * information for the specified DMA module.
679 * @retval ::HAL_OK: Operation is OK.
680 * @retval ::HAL_ERROR: Parameter error or operation not supported.
681 * @retval ::HAL_BUSY: Driver is busy.
682 * @retval ::HAL_TIMEOUT: Timeout occurred.
683 ****************************************************************************************
684 */
685 hal_status_t hal_dma_suspend_reg(dma_handle_t *p_dma);
686
687 /**
688 ****************************************************************************************
689 * @brief Restore some registers related to DMA configuration after sleep.
690 * This function must be used in conjunction with the hal_dma_resume_reg().
691 * @param[in] p_dma: Pointer to a DMA handle which contains the configuration
692 * information for the specified DMA module.
693 * @retval ::HAL_OK: Operation is OK.
694 * @retval ::HAL_ERROR: Parameter error or operation not supported.
695 * @retval ::HAL_BUSY: Driver is busy.
696 * @retval ::HAL_TIMEOUT: Timeout occurred.
697 ****************************************************************************************
698 */
699 hal_status_t hal_dma_resume_reg(dma_handle_t *p_dma);
700
701 /** @} */
702
703 /** @} */
704
705 #ifdef __cplusplus
706 }
707 #endif
708
709 #endif /* __GR55xx_HAL_DMA_H__*/
710
711 /** @} */
712
713 /** @} */
714
715 /** @} */
DMA_Channel4
@ DMA_Channel4
Channel 4
Definition: gr55xx_hal_dma.h:98
HAL_DMA_XFER_TFR_CB_ID
@ HAL_DMA_XFER_TFR_CB_ID
Full transfer
Definition: gr55xx_hal_dma.h:114
hal_lock_t
hal_lock_t
HAL Lock structures definition.
Definition: gr55xx_hal_def.h:81
hal_dma_get_error
uint32_t hal_dma_get_error(dma_handle_t *p_dma)
Return the DMA error code.
DMA_Channel1
@ DMA_Channel1
Channel 1
Definition: gr55xx_hal_dma.h:95
HAL_DMA_STATE_TIMEOUT
@ HAL_DMA_STATE_TIMEOUT
DMA timeout state
Definition: gr55xx_hal_dma.h:80
_dma_init
DMA Configuration Structure definition.
Definition: gr55xx_hal_dma.h:137
_dma_handle::error_code
__IO uint32_t error_code
DMA Error code
Definition: gr55xx_hal_dma.h:198
DMA_Channel0
@ DMA_Channel0
Channel 0
Definition: gr55xx_hal_dma.h:94
dma_handle_t
struct _dma_handle dma_handle_t
DMA handle Structure definition.
hal_dma_state_t
hal_dma_state_t
HAL DMA State Enumerations definition.
Definition: gr55xx_hal_dma.h:76
hal_dma_start_it
hal_status_t hal_dma_start_it(dma_handle_t *p_dma, uint32_t src_address, uint32_t dst_address, uint32_t data_length)
Start the DMA Transfer with interrupt enabled.
hal_dma_abort_it
hal_status_t hal_dma_abort_it(dma_handle_t *p_dma)
Aborts the DMA Transfer in Interrupt mode.
HAL_DMA_STATE_READY
@ HAL_DMA_STATE_READY
DMA process success and ready for use
Definition: gr55xx_hal_dma.h:78
_dma_init::dst_increment
uint32_t dst_increment
Specifies whether the destination address register should be incremented or decrement or not.
Definition: gr55xx_hal_dma.h:151
DMA_Channel5
@ DMA_Channel5
Channel 5
Definition: gr55xx_hal_dma.h:99
_dma_handle::init
dma_init_t init
DMA communication parameters
Definition: gr55xx_hal_dma.h:182
DMA_Channel2
@ DMA_Channel2
Channel 2
Definition: gr55xx_hal_dma.h:96
hal_dma_irq_handler
void hal_dma_irq_handler(dma_handle_t *p_dma)
Handle DMA interrupt request.
_dma_handle::xfer_blk_callback
void(* xfer_blk_callback)(struct _dma_handle *p_dma)
DMA block complete callback
Definition: gr55xx_hal_dma.h:192
hal_dma_suspend_reg
hal_status_t hal_dma_suspend_reg(dma_handle_t *p_dma)
Suspend some registers related to DMA configuration before sleep.
_dma_handle::retention
uint32_t retention[5]
DMA important register information.
Definition: gr55xx_hal_dma.h:200
gr55xx_ll_dma.h
Header file containing functions prototypes of DMA LL library.
_dma_init::priority
uint32_t priority
Specifies the software priority for the DMA Channel.
Definition: gr55xx_hal_dma.h:165
HAL_DMA_XFER_ABORT_CB_ID
@ HAL_DMA_XFER_ABORT_CB_ID
Abort
Definition: gr55xx_hal_dma.h:117
hal_dma_register_callback
hal_status_t hal_dma_register_callback(dma_handle_t *p_dma, hal_dma_callback_id_t id, void(*callback)(dma_handle_t *p_dma))
Register callbacks.
HAL_DMA_XFER_ALL_CB_ID
@ HAL_DMA_XFER_ALL_CB_ID
All
Definition: gr55xx_hal_dma.h:118
_dma_init::dst_request
uint32_t dst_request
Specifies the destination request selected for the specified channel.
Definition: gr55xx_hal_dma.h:141
hal_dma_poll_for_transfer
hal_status_t hal_dma_poll_for_transfer(dma_handle_t *p_dma, uint32_t timeout)
Polling for transfer complete.
DMA_Channel6
@ DMA_Channel6
Channel 6
Definition: gr55xx_hal_dma.h:100
hal_dma_start
hal_status_t hal_dma_start(dma_handle_t *p_dma, uint32_t src_address, uint32_t dst_address, uint32_t data_length)
Start the DMA Transfer.
hal_dma_resume_reg
hal_status_t hal_dma_resume_reg(dma_handle_t *p_dma)
Restore some registers related to DMA configuration after sleep.
_dma_handle::state
__IO hal_dma_state_t state
DMA transfer state
Definition: gr55xx_hal_dma.h:186
hal_dma_init
hal_status_t hal_dma_init(dma_handle_t *p_dma)
Initialize the DMA according to the specified parameters in the dma_init_t and initialize the associa...
_dma_handle::xfer_error_callback
void(* xfer_error_callback)(struct _dma_handle *p_dma)
DMA transfer error callback
Definition: gr55xx_hal_dma.h:194
HAL_DMA_XFER_BLK_CB_ID
@ HAL_DMA_XFER_BLK_CB_ID
Block transfer
Definition: gr55xx_hal_dma.h:115
hal_dma_callback_id_t
hal_dma_callback_id_t
HAL DMA Callback ID Enumerations definition.
Definition: gr55xx_hal_dma.h:113
DMA_Channel3
@ DMA_Channel3
Channel 3
Definition: gr55xx_hal_dma.h:97
HAL_DMA_STATE_ERROR
@ HAL_DMA_STATE_ERROR
DMA error state
Definition: gr55xx_hal_dma.h:81
_dma_handle::xfer_tfr_callback
void(* xfer_tfr_callback)(struct _dma_handle *p_dma)
DMA transfer complete callback
Definition: gr55xx_hal_dma.h:190
HAL_DMA_STATE_BUSY
@ HAL_DMA_STATE_BUSY
DMA process is ongoing
Definition: gr55xx_hal_dma.h:79
_dma_handle::xfer_abort_callback
void(* xfer_abort_callback)(struct _dma_handle *p_dma)
DMA transfer abort callback
Definition: gr55xx_hal_dma.h:196
dma_init_t
struct _dma_init dma_init_t
DMA Configuration Structure definition.
hal_status_t
hal_status_t
HAL Status structures definition.
Definition: gr55xx_hal_def.h:70
_dma_init::direction
uint32_t direction
Specifies if the data will be transferred from memory to peripheral, from memory to memory or from pe...
Definition: gr55xx_hal_dma.h:144
hal_dma_get_state
hal_dma_state_t hal_dma_get_state(dma_handle_t *p_dma)
Return the DMA hande state.
_dma_init::mode
uint32_t mode
Specifies the operation mode of the DMA Channel(Normal or Circular).
Definition: gr55xx_hal_dma.h:160
DMA_Channel7
@ DMA_Channel7
Channel 7
Definition: gr55xx_hal_dma.h:101
hal_dma_unregister_callback
hal_status_t hal_dma_unregister_callback(dma_handle_t *p_dma, hal_dma_callback_id_t id)
UnRegister callbacks.
_dma_handle::channel
dma_channel_t channel
DMA Channel Number
Definition: gr55xx_hal_dma.h:180
_dma_init::dst_data_alignment
uint32_t dst_data_alignment
Specifies the destination data width.
Definition: gr55xx_hal_dma.h:157
_dma_handle::lock
hal_lock_t lock
DMA locking object
Definition: gr55xx_hal_dma.h:184
_dma_handle::p_parent
void * p_parent
Parent object state
Definition: gr55xx_hal_dma.h:188
hal_dma_abort
hal_status_t hal_dma_abort(dma_handle_t *p_dma)
Abort the DMA Transfer.
HAL_DMA_XFER_ERROR_CB_ID
@ HAL_DMA_XFER_ERROR_CB_ID
Error
Definition: gr55xx_hal_dma.h:116
HAL_DMA_STATE_RESET
@ HAL_DMA_STATE_RESET
DMA not yet initialized or disabled.
Definition: gr55xx_hal_dma.h:77
_dma_init::src_request
uint32_t src_request
Specifies the source request selected for the specified channel.
Definition: gr55xx_hal_dma.h:138
_dma_init::src_data_alignment
uint32_t src_data_alignment
Specifies the source data width.
Definition: gr55xx_hal_dma.h:154
_dma_handle
DMA handle Structure definition.
Definition: gr55xx_hal_dma.h:179
gr55xx_hal_def.h
This file contains HAL common definitions, enumeration, macros and structures definitions.
hal_dma_deinit
hal_status_t hal_dma_deinit(dma_handle_t *p_dma)
De-initialize the DMA peripheral.
dma_channel_t
dma_channel_t
HAL DMA Channel Enumerations definition.
Definition: gr55xx_hal_dma.h:93
_dma_init::src_increment
uint32_t src_increment
Specifies whether the srouce address register should be incremented or decrement or not.
Definition: gr55xx_hal_dma.h:148