1 /* SPDX-License-Identifier: BSD-3-Clause */
2 /*
3 * Copyright (c) 2020-2021 Rockchip Electronics Co., Ltd.
4 */
5
6 /** @addtogroup RK_HAL_Driver
7 * @{
8 */
9
10 /** @addtogroup DMA
11 * @{
12 */
13
14 #ifndef _HAL_DMA_H
15 #define _HAL_DMA_H
16
17 #include "hal_def.h"
18
19 /***************************** MACRO Definition ******************************/
20 /** @defgroup DMA_Exported_Definition_Group1 Basic Definition
21 * @{
22 */
23
24 /***************************** Structure Definition **************************/
25 /**
26 * enum DMA_TRANSFER_DIRECTION - dma transfer mode and direction indicator
27 */
28 typedef enum {
29 DMA_MEM_TO_MEM, /**< Async/Memcpy mode */
30 DMA_MEM_TO_DEV, /**< Slave mode & From Memory to Device */
31 DMA_DEV_TO_MEM, /**< Slave mode & From Device to Memory */
32 DMA_DEV_TO_DEV, /**< Slave mode & From Device to Device */
33 DMA_TRANS_NONE,
34 } eDMA_TRANSFER_DIRECTION;
35
36 /**
37 * enum DMA_SLAVE_BUSWIDTH - defines bus width of the DMA slave
38 * device, source or target buses
39 */
40 typedef enum {
41 DMA_SLAVE_BUSWIDTH_UNDEFINED = 0,
42 DMA_SLAVE_BUSWIDTH_1_BYTE = 1,
43 DMA_SLAVE_BUSWIDTH_2_BYTES = 2,
44 DMA_SLAVE_BUSWIDTH_3_BYTES = 3,
45 DMA_SLAVE_BUSWIDTH_4_BYTES = 4,
46 DMA_SLAVE_BUSWIDTH_8_BYTES = 8,
47 DMA_SLAVE_BUSWIDTH_16_BYTES = 16,
48 DMA_SLAVE_BUSWIDTH_32_BYTES = 32,
49 DMA_SLAVE_BUSWIDTH_64_BYTES = 64,
50 } eDMA_SLAVE_BUSWIDTH;
51
52 /**
53 * struct DMA_SLAVE_CONFIG - dma slave channel runtime config
54 */
55 struct DMA_SLAVE_CONFIG {
56 eDMA_TRANSFER_DIRECTION direction; /**< Transfer direction. */
57 eDMA_SLAVE_BUSWIDTH srcAddrWidth; /**< The width in bytes of the source,
58 * Legal values: 1, 2, 4, 8.
59 */
60 eDMA_SLAVE_BUSWIDTH dstAddrWidth; /**< The same as srcAddrWidth. */
61 uint32_t srcAddr; /**< The source physical address. */
62 uint32_t dstAddr; /**< The destination physical address. */
63 uint16_t srcMaxBurst; /**< The maximum number of words (note: words, as in
64 * units of the srcAddrWidth member, not bytes) that
65 * can be sent in one burst to the device, Typically
66 * something like half the FIFO depth on I/O peri so
67 * you don't overflow it.
68 */
69 uint16_t dstMaxBurst; /**< The same as srcMaxBurst for destination. */
70 uint16_t srcInterlaceSize; /**< The interlace size for src mem increase */
71 uint16_t dstInterlaceSize; /**< The interlace size for dst mem increase */
72 };
73
74 /**
75 * dma complete callback.
76 */
77 typedef void (*DMA_Callback)(void *cparam);
78
79 /** @} */
80
81 /********************* Public Function Definition ****************************/
82 /** @defgroup DMA_Exported_Functions_Group5 Other Functions
83 * @{
84 */
85
HAL_DMA_IsSlaveDirection(eDMA_TRANSFER_DIRECTION direction)86 __STATIC_INLINE bool HAL_DMA_IsSlaveDirection(eDMA_TRANSFER_DIRECTION direction)
87 {
88 return (direction == DMA_MEM_TO_DEV) || (direction == DMA_DEV_TO_MEM);
89 }
90
91 /** @} */
92
93 #endif
94
95 /** @} */
96
97 /** @} */
98