1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
|
# FDDMA 驱动程序
## 1. 概述
DDMA(Device Direct Memory Access)是E2000提供的一个通用DMA控制模块,支持典型的DMA操作,提供多个DMA通道,多个通道可以同时工作,独立配置给不同外设使用
## 2. 功能
FDDMA 驱动程序主要完成 DDMA 模块的初始化,DDMA通道的分配与释放,
相关源文件为:
```
fddma
.
├── fddma.c
├── fddma.h
├── fddma_g.c
├── fddma_hw.c
├── fddma_hw.h
├── fddma_intr.c
├── fddma_selftest.c
└── fddma_sinit.c
```
## 3. 配置方法
以下部分将指导您完成 FDDMA 驱动的软件配置:
- 初始化 DDMA 控制器
- 配置 DDMA 通道,与外设完成绑定
- 启动 DDMA 通道
## 4 应用示例
### [通过DDMA搬运SPI数据完成回环测试](../../../baremetal/example/peripheral/dma/fddma_spi)
## 5. API参考
### 5.1. 用户数据结构
#### FDdmaConfig
- DDMA 实例配置
```c
typedef struct
{
u32 id; /* DDMA ctrl id */
uintptr base_addr; /* DDMA ctrl base address */
u32 irq_num; /* DDMA ctrl interrupt id */
u32 irq_prority; /* DDMA ctrl interrupt priority */
} FDdmaConfig; /* DDMA instance configuration */
```
#### FDdmaChanConfig
- DDMA 通道配置
```c
typedef struct
{
FDdmaChanIndex id; /* DMA channel index */
u32 slave_id; /* Perpherial slave id for DDMA */
FDdmaChanRequst req_mode; /* DMA transfer direction */
uintptr ddr_addr; /* DMA channel DDR address, could be source or destination */
u32 dev_addr; /* DMA channel Perpherial, could be source or destination */
u32 trans_len; /* DMA channel transfer length */
#define FDDMA_MAX_TRANSFER_LEN 64 /* max bytes in transfer */
#define FDDMA_MIN_TRANSFER_LEN 4 /* min bytes in transfer */
u32 timeout; /* timeout = 0 means no use DMA timeout */
} FDdmaChanConfig; /* DDMA channel instance */
```
#### FDdmaChan
- DDMA 通道实例
```c
typedef struct FDdmaChan_
{
FDdmaChanConfig config; /* DDMA channel configuration */
boolean is_used; /* TRUE means channel is in use */
FDdma *dma; /* DMA instance of this channel */
FDdmaChanEvtHandler evt_handler[FDDMA_NUM_OF_CHAN_EVT]; /* interrupt evt */
void *evt_handler_args[FDDMA_NUM_OF_CHAN_EVT]; /* interrupt evt args */
} FDdmaChan; /* DDMA channel instance */
```
#### FDdma
- DDMA 控制器实例
```c
typedef struct FDdma_
{
FDdmaConfig config; /* DDMA instance configuration */
FDdmaChan *chan[FDDMA_NUM_OF_CHAN]; /* DDMA channel instance, NULL means channel not yet allocate */
u32 is_ready; /* TRUE means DDMA init ok */
u32 bind_status; /* channel bind status, BIT(n) = 1 means channel n is allocated */
} FDdma; /* DDMA instance */
```
### 5.2 错误码定义
- FDDMA_SUCCESS : 成功
- FDDMA_ERR_NOT_INIT :驱动未初始化
- FDDMA_ERR_CHAN_BINDED :通道已经绑定无法分配
- FDDMA_ERR_CHAN_RUNNING : 通道正在工作无法分配
- FDDMA_ERR_INVALID_TRANS_SIZE : DMA传输字节数不合法
- FDDMA_ERR_WAIT_TIMEOUT : DMA等待超时
- FDDMA_ERR_INVALID_DDR_ADDR : DMA传输地址不合法
### 5.3. 用户API接口
#### FDdmaLookupConfig
```c
const FDdmaConfig *FDdmaLookupConfig(u32 instance_id);
```
Note:
- 获取DDMA实例默认配置
Input:
- {u32} instance_id, DDMA实例号
Return:
- {const FDdmaConfig *} DDMA控制器默认配置
#### FDdmaCfgInitialization
```c
FError FDdmaCfgInitialization(FDdma *const instance, const FDdmaConfig *input_config);
```
Note:
- 初始化DDMA控制器
Input:
- {FDdma} *instance, DDMA控制器实例
- {FDdmaConfig} *input_config, DDMA控制器配置
Return:
- {FError} FDDMA_SUCCESS表示初始化成功,其它返回值表示初始化失败
#### FDdmaDeInitialization
```c
void FDdmaDeInitialization(FDdma *const instance);
```
Note:
- 去初始化DDMA控制器
Input:
- {FDdma} *instance, DDMA控制器实例
Return:
- 无
#### FDdmaAllocateChan
```c
FError FDdmaAllocateChan(FDdma *const instance, FDdmaChan *const dma_chan, const FDdmaChanConfig *dma_chan_config);
```
Note:
- 按照配置分配并使能DDMA通道
Input:
- {FDdma} *instance, DDMA控制器实例
- {FDdmaChan} *dma_chan, DDMA通道实例
- {FDdmaChanConfig} *dma_chan_config, DDMA通道配置
Return:
- {FError} FDDMA_SUCCESS表示分配成功,其它返回值表示分配失败
#### FDdmaDellocateChan
```c
FError FDdmaDellocateChan(FDdmaChan *const dma_chan);
```
Note:
- 释放之前分配的DDMA通道
Input:
- {FDdmaChan} *dma_chan, DDMA控制器实例
Return:
- {FError} FDDMA_SUCCESS表示释放成功,其它返回值表示释放失败
#### FDdmaStart
```c
FError FDdmaStart(FDdma *const instance);
```
Note:
- 启动DDMA控制器,开始传输
Input:
- {FDdma} *instance, DDMA控制器实例
Return:
- {FError} FDDMA_SUCCESS表示启动成功,其它返回值表示启动失败
#### FDdmaStop
```c
FError FDdmaStop(FDdma *const instance);
```
Note:
- 停止DDMA控制器
Input:
- {FDdma} *instance, DDMA控制器实例
Return:
- {FError} FDDMA_SUCCESS表示停止成功,其它返回值表示停止失败
#### FDdmaIrqHandler
```c
void FDdmaIrqHandler(s32 vector, void *args)
```
Note:
- DDMA中断处理函数
Input:
- {s32} vector
- {void} *param, 输入参数
Return:
- 无
#### FDdmaRegisterChanEvtHandler
```c
void FDdmaRegisterChanEvtHandler(FDdmaChan *const dma_chan,
FDdmaChanEvt evt,
FDdmaChanEvtHandler handler,
void *handler_arg);
```
Note:
- 注册DDMA通道中断响应事件函数
Input:
- {FDdmaChan} *dma_chan, DDMA通道
- {FDdmaChanEvt} evt, 中断事件
- {FDdmaChanEvtHandler} handler, 中断响应事件函数
- {void} *handler_arg, 中断响应事件函数输入参数
Return:
- 无
|