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
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
|
/*****************************************************************************
* Copyright (C) 2020, Huada Semiconductor Co., Ltd. All rights reserved.
*
* This software component is licensed by HDSC under BSD 3-Clause license
* (the "License"); You may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
* opensource.org/licenses/BSD-3-Clause
*/
/******************************************************************************/
/** \file hc32f460_dmac.h
**
** A detailed description is available at
** @link DmacGroup DMAC description @endlink
**
** - 2018-11-18 CDT First version for Device Driver Library of DMAC.
**
******************************************************************************/
#ifndef __HC32F460_DMAC_H__
#define __HC32F460_DMAC_H__
/*******************************************************************************
* Include files
******************************************************************************/
#include "hc32_common.h"
/* C binding of definitions if building with C++ compiler */
#ifdef __cplusplus
extern "C"
{
#endif
/**
*******************************************************************************
** \defgroup DmacGroup Direct Memory Access Control(DMAC)
**
******************************************************************************/
//@{
/*******************************************************************************
* Global type definitions ('typedef')
******************************************************************************/
/**
*******************************************************************************
** \brief DMA Channel
**
******************************************************************************/
typedef enum en_dma_channel
{
DmaCh0 = 0u, ///< DMA channel 0
DmaCh1 = 1u, ///< DMA channel 1
DmaCh2 = 2u, ///< DMA channel 2
DmaCh3 = 3u, ///< DMA channel 3
DmaChMax = 4u ///< DMA channel max
}en_dma_channel_t;
/**
*******************************************************************************
** \brief DMA transfer data width
**
******************************************************************************/
typedef enum en_dma_transfer_width
{
Dma8Bit = 0u, ///< 8 bit transfer via DMA
Dma16Bit = 1u, ///< 16 bit transfer via DMA
Dma32Bit = 2u ///< 32 bit transfer via DMA
}en_dma_transfer_width_t;
/**
*******************************************************************************
** \brief DMA flag
**
******************************************************************************/
typedef enum en_dma_flag
{
DmaTransferComplete = 0u, ///< DMA transfer complete
DmaBlockComplete = 1u, ///< DMA block transfer complete
DmaTransferErr = 2u, ///< DMA transfer error
DmaReqErr = 3u, ///< DMA transfer request error
DmaFlagMax = 4u
}en_dma_flag_t;
/**
*******************************************************************************
** \brief DMA address mode
**
******************************************************************************/
typedef enum en_dma_address_mode
{
AddressFix = 0u, ///< Address fixed
AddressIncrease = 1u, ///< Address increased
AddressDecrease = 2u, ///< Address decreased
}en_dma_address_mode_t;
/**
*******************************************************************************
** \brief DMA link list pointer mode
**
******************************************************************************/
typedef enum en_dma_llp_mode
{
LlpWaitNextReq = 0u, ///< DMA trigger transfer after wait next request
LlpRunNow = 1u, ///< DMA trigger transfer now
}en_dma_llp_mode_t;
/**
*******************************************************************************
** \brief DMA interrupt selection
**
******************************************************************************/
typedef enum en_dma_irq_sel
{
TrnErrIrq = 0u, ///< Select DMA transfer error interrupt
TrnReqErrIrq = 1u, ///< Select DMA transfer req over error interrupt
TrnCpltIrq = 2u, ///< Select DMA transfer completion interrupt
BlkTrnCpltIrq = 3u, ///< Select DMA block completion interrupt
DmaIrqSelMax = 4u
}en_dma_irq_sel_t;
/**
*******************************************************************************
** \brief DMA re_config count mode
**
******************************************************************************/
typedef enum en_dma_recfg_cnt_mode
{
CntFix = 0u, ///< Fix
CntSrcAddr = 1u, ///< Source address mode
CntDesAddr = 2u, ///< Destination address mode
}en_dma_recfg_cnt_mode_t;
/**
*******************************************************************************
** \brief DMA re_config destination address mode
**
******************************************************************************/
typedef enum en_dma_recfg_daddr_mode
{
DaddrFix = 0u, ///< Fix
DaddrNseq = 1u, ///< No_sequence address
DaddrRep = 2u, ///< Repeat address
}en_dma_recfg_daddr_mode_t;
/**
*******************************************************************************
** \brief DMA re_config source address mode
**
******************************************************************************/
typedef enum en_dma_recfg_saddr_mode
{
SaddrFix = 0u, ///< Fix
SaddrNseq = 1u, ///< No_sequence address
SaddrRep = 2u, ///< Repeat address
}en_dma_recfg_saddr_mode_t;
/**
*******************************************************************************
** \brief DMA channel status
**
******************************************************************************/
typedef enum en_dma_ch_flag
{
DmaSta = 0u, ///< DMA status.
ReCfgSta = 1u, ///< DMA re_configuration status.
DmaCh0Sta = 2u, ///< DMA channel 0 status.
DmaCh1Sta = 3u, ///< DMA channel 1 status.
DmaCh2Sta = 4u, ///< DMA channel 2 status.
DmaCh3Sta = 5u, ///< DMA channel 3 status.
}en_dma_ch_flag_t;
/**
*******************************************************************************
** \brief DMA request status
**
******************************************************************************/
typedef enum en_dma_req_status
{
ReCfgReqSta = 0u, ///< DMA re_configuration request.
DmaCh0ReqSta = 1u, ///< DMA channel 0 transfer request status.
DmaCh1ReqSta = 2u, ///< DMA channel 1 transfer request status.
DmaCh2ReqSta = 3u, ///< DMA channel 2 transfer request status.
DmaCh3ReqSta = 4u, ///< DMA channel 3 transfer request status.
}en_dma_req_status_t;
/**
*******************************************************************************
** \brief DMA common trigger source select
**
******************************************************************************/
typedef enum en_dma_com_trigger
{
DmaComTrigger_1 = 0x1, ///< Select common trigger 1.
DmaComTrigger_2 = 0x2, ///< Select common trigger 2.
DmaComTrigger_1_2 = 0x3, ///< Select common trigger 1 and 2.
} en_dma_com_trigger_t;
/**
*******************************************************************************
** \brief DMA llp descriptor
**
******************************************************************************/
typedef struct stc_dma_llp_descriptor
{
uint32_t SARx; ///< DMA source address register
uint32_t DARx; ///< DMA destination address register
union
{
uint32_t DTCTLx;
stc_dma_dtctl_field_t DTCTLx_f; ///< DMA data control register
};
union
{
uint32_t RPTx;
stc_dma_rpt_field_t RPTx_f; ///< DMA repeat control register
};
union
{
uint32_t SNSEQCTLx;
stc_dma_snseqctl_field_t SNSEQCTLx_f; ///< DMA source no-sequence control register
};
union
{
__IO uint32_t DNSEQCTLx;
stc_dma_dnseqctl_field_t DNSEQCTLx_f; ///< DMA destination no-sequence control register
};
union
{
uint32_t LLPx;
stc_dma_llp_field_t LLPx_f; ///< DMA link-list-pointer register
};
union
{
uint32_t CHxCTL;
stc_dma_chctl_field_t CHxCTL_f; ///< DMA channel control register
};
}stc_dma_llp_descriptor_t;
/**
*******************************************************************************
** \brief DMA no-sequence function configuration
**
******************************************************************************/
typedef struct stc_dma_nseq_cfg
{
uint32_t u32Offset; ///< DMA no-sequence offset.
uint16_t u16Cnt; ///< DMA no-sequence count.
}stc_dma_nseq_cfg_t;
/**
*******************************************************************************
** \brief DMA no-sequence function configuration
**
******************************************************************************/
typedef struct stc_dma_nseqb_cfg
{
uint32_t u32NseqDist; ///< DMA no-sequence district interval.
uint16_t u16CntB; ///< DMA no-sequence count.
}stc_dma_nseqb_cfg_t;
/**
*******************************************************************************
** \brief DMA re_config configuration
**
******************************************************************************/
typedef struct stc_dma_recfg_ctl
{
uint16_t u16SrcRptBSize; ///< The source repeat size.
uint16_t u16DesRptBSize; ///< The destination repeat size.
en_dma_recfg_saddr_mode_t enSaddrMd; ///< DMA re_config source address mode.
en_dma_recfg_daddr_mode_t enDaddrMd; ///< DMA re_config destination address mode.
en_dma_recfg_cnt_mode_t enCntMd; ///< DMA re_config count mode.
stc_dma_nseq_cfg_t stcSrcNseqBCfg; ///< The source no_sequence re_config.
stc_dma_nseq_cfg_t stcDesNseqBCfg; ///< The destination no_sequence re_config.
}stc_dma_recfg_ctl_t;
/**
*******************************************************************************
** \brief DMA channel configuration
**
******************************************************************************/
typedef struct stc_dma_ch_cfg
{
en_dma_address_mode_t enSrcInc; ///< DMA source address update mode.
en_dma_address_mode_t enDesInc; ///< DMA destination address update mode.
en_functional_state_t enSrcRptEn; ///< Enable source repeat function or not.
en_functional_state_t enDesRptEn; ///< Enable destination repeat function or not.
en_functional_state_t enSrcNseqEn; ///< Enable source no_sequence function or not.
en_functional_state_t enDesNseqEn; ///< Enable destination no_sequence function or not.
en_dma_transfer_width_t enTrnWidth; ///< DMA transfer data width.
en_functional_state_t enLlpEn; ///< Enable linked list pointer function or not.
en_dma_llp_mode_t enLlpMd; ///< Dma linked list pointer mode.
en_functional_state_t enIntEn; ///< Enable interrupt function or not.
}stc_dma_ch_cfg_t;
/**
*******************************************************************************
** \brief DMA configuration
**
******************************************************************************/
typedef struct stc_dma_config
{
uint16_t u16BlockSize; ///< Transfer block size = 1024, when 0 is set.
uint16_t u16TransferCnt; ///< Transfer counter.
uint32_t u32SrcAddr; ///< The source address.
uint32_t u32DesAddr; ///< The destination address.
uint16_t u16SrcRptSize; ///< The source repeat size.
uint16_t u16DesRptSize; ///< The destination repeat size.
uint32_t u32DmaLlp; ///< The Dma linked list pointer address
stc_dma_nseq_cfg_t stcSrcNseqCfg; ///< The source no_sequence configuration.
stc_dma_nseq_cfg_t stcDesNseqCfg; ///< The destination no_sequence configuration.
stc_dma_ch_cfg_t stcDmaChCfg; ///< The Dma channel configuration.
}stc_dma_config_t;
/*******************************************************************************
* Global pre-processor symbols/macros ('#define')
******************************************************************************/
/*******************************************************************************
* Global variable definitions ('extern')
******************************************************************************/
/*******************************************************************************
* Global function prototypes (definition in C source)
******************************************************************************/
void DMA_Cmd(M4_DMA_TypeDef* pstcDmaReg, en_functional_state_t enNewState);
en_result_t DMA_EnableIrq(M4_DMA_TypeDef* pstcDmaReg, uint8_t u8Ch, en_dma_irq_sel_t enIrqSel);
en_result_t DMA_DisableIrq(M4_DMA_TypeDef* pstcDmaReg, uint8_t u8Ch, en_dma_irq_sel_t enIrqSel);
en_flag_status_t DMA_GetIrqFlag(M4_DMA_TypeDef* pstcDmaReg, uint8_t u8Ch, en_dma_irq_sel_t enIrqSel);
en_result_t DMA_ClearIrqFlag(M4_DMA_TypeDef* pstcDmaReg, uint8_t u8Ch, en_dma_irq_sel_t enIrqSel);
en_result_t DMA_ChannelCmd(M4_DMA_TypeDef* pstcDmaReg, uint8_t u8Ch, en_functional_state_t enNewState);
void DMA_InitReConfig(M4_DMA_TypeDef* pstcDmaReg, uint8_t u8Ch, const stc_dma_recfg_ctl_t* pstcDmaReCfg);
void DMA_ReCfgCmd(M4_DMA_TypeDef* pstcDmaReg,en_functional_state_t enNewState);
en_flag_status_t DMA_GetChFlag(M4_DMA_TypeDef* pstcDmaReg, en_dma_ch_flag_t enDmaChFlag);
en_flag_status_t DMA_GetReqStatus(M4_DMA_TypeDef* pstcDmaReg, en_dma_req_status_t enDmaReqStatus);
en_result_t DMA_SetSrcAddress(M4_DMA_TypeDef* pstcDmaReg, uint8_t u8Ch, uint32_t u32Address);
en_result_t DMA_SetDesAddress(M4_DMA_TypeDef* pstcDmaReg, uint8_t u8Ch, uint32_t u32Address);
en_result_t DMA_SetBlockSize(M4_DMA_TypeDef* pstcDmaReg, uint8_t u8Ch, uint16_t u16BlkSize);
en_result_t DMA_SetTransferCnt(M4_DMA_TypeDef* pstcDmaReg, uint8_t u8Ch, uint16_t u16TrnCnt);
en_result_t DMA_SetSrcRptSize(M4_DMA_TypeDef* pstcDmaReg, uint8_t u8Ch, uint16_t u16Size);
en_result_t DMA_SetDesRptSize(M4_DMA_TypeDef* pstcDmaReg, uint8_t u8Ch, uint16_t u16Size);
en_result_t DMA_SetSrcRptbSize(M4_DMA_TypeDef* pstcDmaReg, uint8_t u8Ch, uint16_t u16Size);
en_result_t DMA_SetDesRptbSize(M4_DMA_TypeDef* pstcDmaReg, uint8_t u8Ch, uint16_t u16Size);
en_result_t DMA_SetSrcNseqCfg(M4_DMA_TypeDef* pstcDmaReg, uint8_t u8Ch, const stc_dma_nseq_cfg_t* pstcSrcNseqCfg);
en_result_t DMA_SetSrcNseqBCfg(M4_DMA_TypeDef* pstcDmaReg, uint8_t u8Ch, const stc_dma_nseqb_cfg_t* pstcSrcNseqBCfg);
en_result_t DMA_SetDesNseqCfg(M4_DMA_TypeDef* pstcDmaReg, uint8_t u8Ch, const stc_dma_nseq_cfg_t* pstDesNseqCfg);
en_result_t DMA_SetDesNseqBCfg(M4_DMA_TypeDef* pstcDmaReg, uint8_t u8Ch, const stc_dma_nseqb_cfg_t* pstDesNseqBCfg);
en_result_t DMA_SetLLP(M4_DMA_TypeDef* pstcDmaReg, uint8_t u8Ch, uint32_t u32Pointer);
uint32_t DMA_GetSrcAddr(const M4_DMA_TypeDef* pstcDmaReg, uint8_t u8Ch);
uint32_t DMA_GetDesAddr(const M4_DMA_TypeDef* pstcDmaReg, uint8_t u8Ch);
uint32_t DMA_GetTransferCnt(const M4_DMA_TypeDef* pstcDmaReg, uint8_t u8Ch);
uint32_t DMA_GetBlockSize(const M4_DMA_TypeDef* pstcDmaReg, uint8_t u8Ch);
uint32_t DMA_GetSrcRptSize(const M4_DMA_TypeDef* pstcDmaReg, uint8_t u8Ch);
uint32_t DMA_GetDesRptSize(const M4_DMA_TypeDef* pstcDmaReg, uint8_t u8Ch);
uint32_t DMA_GetSrcNSeqCount(const M4_DMA_TypeDef* pstcDmaReg, uint8_t u8Ch);
uint32_t DMA_GetDesNSeqCount(const M4_DMA_TypeDef* pstcDmaReg, uint8_t u8Ch);
uint32_t DMA_GetSrcNSeqOffset(const M4_DMA_TypeDef* pstcDmaReg, uint8_t u8Ch);
uint32_t DMA_GetDesNSeqOffset(const M4_DMA_TypeDef* pstcDmaReg, uint8_t u8Ch);
void DMA_SetTriggerSrc(const M4_DMA_TypeDef* pstcDmaReg, uint8_t u8Ch, en_event_src_t enSrc);
void DMA_SetReConfigTriggerSrc(en_event_src_t enSrc);
void DMA_ComTriggerCmd(M4_DMA_TypeDef* pstcDmaReg, uint8_t u8Ch, en_dma_com_trigger_t enComTrigger, en_functional_state_t enNewState);
void DMA_ReConfigComTriggerCmd(en_dma_com_trigger_t enComTrigger, en_functional_state_t enNewState);
void DMA_ChannelCfg(M4_DMA_TypeDef* pstcDmaReg, uint8_t u8Ch, const stc_dma_ch_cfg_t* pstcChCfg);
void DMA_InitChannel(M4_DMA_TypeDef* pstcDmaReg, uint8_t u8Ch, const stc_dma_config_t* pstcDmaCfg);
void DMA_DeInit(M4_DMA_TypeDef* pstcDmaReg, uint8_t u8Ch);
//@} // DmacGroup
#ifdef __cplusplus
}
#endif
#endif /* __HC32F460_DMAC_H__*/
/*******************************************************************************
* EOF (not truncated)
******************************************************************************/
|