summaryrefslogtreecommitdiff
path: root/bsp/hc32l136/libraries/HC32L136_StdPeriph_Driver/inc/dmac.h
blob: 7e68f2547faa76c3c875e5eda49c7b2ef66ac784 (plain)
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
/*****************************************************************************
* Copyright (C) 2016, Huada Semiconductor Co.,Ltd All rights reserved.
*
* This software is owned and published by:
* Huada Semiconductor Co.,Ltd ("HDSC").
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with HDSC
* components. This software is licensed by HDSC to be adapted only
* for use in systems utilizing HDSC components. HDSC shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. HDSC is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* Disclaimer:
* HDSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
* WARRANTY OF NONINFRINGEMENT.
* HDSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
* SAVINGS OR PROFITS,
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
* FROM, THE SOFTWARE.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with each copy of this software, whether used in part or whole,
* at all times.
*/
/******************************************************************************/
/** \file dma.h
**
** A detailed description is available at
** @link DmacGroup Dmac description @endlink
**
**   - 2018-03-09  1.0  Hongjh First version for Device Driver Library of Dmac.
**
******************************************************************************/
#ifndef __DMAC_H__
#define __DMAC_H__

/*******************************************************************************
* Include files
******************************************************************************/
#include "ddl.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
    DmaChMax                        = 2U     ///< DMA channel max
  } en_dma_channel_t;
  /**
  *******************************************************************************
  ** \brief DMA priority
  **
  ******************************************************************************/
  typedef enum en_dma_priority
  {
    DmaPriorityFix                          = 0U,    ///< DMA channel priority fix (CH0>CH1)
    DmaPriorityLoop                         = 1U,    ///< DMA channel priority loop
  } en_dma_priority_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 transfer mode
  **
  ******************************************************************************/
  typedef enum en_dma_transfer_mode
  {
    DmaBlock                        = 0U,    ///< block transfer via DMA
    DmaBurst                        = 1U,    ///< burst transfer via DMA
  } en_dma_transfer_mode_t;
  
  /**
  *******************************************************************************
  ** \brief DMA flag
  **
  ******************************************************************************/
  typedef enum en_dma_stat
  {
    DEFAULT							            = 0U,    ///< Reserve
    DmaAddOverflow									= 1U,   ///< DMA address overflow
    DmaHALT                         = 2U,    ///< DMA HALT
    DmaAccSCRErr                    = 3U,    ///< DMA access source address error
    DmaAccDestErr                   = 4U,    ///< DMA access dest address error
    DmaTransferComplete             = 5U,    ///< DMA transfer complete
    DmaTransferPause                = 7U,    ///< DMA transfer pause      
  } en_dma_stat_t;
  
  /**
  *******************************************************************************
  ** \brief DMA address mode
  **
  ******************************************************************************/
  typedef enum en_address_mode
  {    
    AddressIncrease                 = 0U,    ///< Address increased
    AddressFix                      = 1U,    ///< Address fixed
  } en_address_mode_t;
  
  /**
  *******************************************************************************
  ** \brief DMA repeat tranfer
  **
  ******************************************************************************/
  typedef enum en_dma_msk
  {
    OneTranfer                      = 0U,    ///< One Tranfer
    ContinuousTranfer               = 1U,    ///< Continuous Tranfer 
  } en_dma_msk_t;
  /**
  *******************************************************************************
  ** \brief DMA trigger selection
  **
  ******************************************************************************/  
  typedef enum stc_dma_trig_sel
  {
    SWTrig                         = 0U,     ///< Select DMA software trig 
    SPI0RXTrig                     = 32U,    ///< Select DMA hardware trig 0
    SPI0TXTrig                     = 33U,    ///< Select DMA hardware trig 1
    SPI1RXTrig                     = 34U,    ///< Select DMA hardware trig 2
    SPI1TXTrig                     = 35U,    ///< Select DMA hardware trig 3
    ADCJQRTrig                     = 36U,    ///< Select DMA hardware trig 4
    ADCSQRTrig                     = 37U,    ///< Select DMA hardware trig 5
    LCDTxTrig                      = 38U,    ///< Select DMA hardware trig 6
    Uart0RxTrig                    = 40U,    ///< Select DMA hardware trig 8
    Uart0TxTrig                    = 41U,    ///< Select DMA hardware trig 9             
    Uart1RxTrig                    = 42U,    ///< Select DMA hardware trig 10
    Uart1TxTrig                    = 43U,    ///< Select DMA hardware trig 11
    LpUart0RxTrig                  = 44U,    ///< Select DMA hardware trig 12
    LpUart0TxTrig                  = 45U,    ///< Select DMA hardware trig 13
    LpUart1RxTrig                  = 46U,    ///< Select DMA hardware trig 14
    LpUart1TxTrig                  = 47U,    ///< Select DMA hardware trig 15
    TIM0ATrig                      = 50U,    ///< Select DMA hardware trig 18
    TIM0BTrig                      = 51U,    ///< Select DMA hardware trig 19
    TIM1ATrig                      = 52U,    ///< Select DMA hardware trig 20
    TIM1BTrig                      = 53U,    ///< Select DMA hardware trig 21
    TIM2ATrig                      = 54U,    ///< Select DMA hardware trig 22   
    TIM2BTrig                      = 55U,    ///< Select DMA hardware trig 23   
    TIM3ATrig                      = 56U,    ///< Select DMA hardware trig 24    
    TIM3BTrig                      = 57U,    ///< Select DMA hardware trig 25   
    TIM4ATrig                      = 58U,    ///< Select DMA hardware trig 26    
    TIM4BTrig                      = 59U,    ///< Select DMA hardware trig 27   
    TIM5ATrig                      = 60U,    ///< Select DMA hardware trig 28    
    TIM5BTrig                      = 61U,    ///< Select DMA hardware trig 29   
    TIM6ATrig                      = 62U,    ///< Select DMA hardware trig 30    
    TIM6BTrig                      = 63U,    ///< Select DMA hardware trig 31   
  }en_dma_trig_sel_t;  
  /**
  *******************************************************************************
  ** \brief DMA interrupt selection
  **
  ******************************************************************************/
typedef struct stc_dma_irq
  {
    boolean_t TrnErrIrq;                        ///< Select DMA transfer error interrupt
    boolean_t TrnCpltIrq;                      ///< Select DMA transfer completion interrupt
  }stc_dma_irq_sel_t;
  
 
  
  /**
  *******************************************************************************
  ** \brief DMA configuration
  **
  ******************************************************************************/
  typedef struct stc_dma_config
  {
    en_dma_transfer_mode_t enMode;
    
    uint16_t u16BlockSize;                      ///< Transfer Block counter
    uint16_t u16TransferCnt;                    ///< Transfer counter
    en_dma_transfer_width_t enTransferWidth;    ///< DMA transfer width (see #en_dma_transfer_width_t for details)
    
    en_address_mode_t enSrcAddrMode;            ///< Source address mode(see #en_source_address_mode_t for details)
    en_address_mode_t enDstAddrMode;            ///< Destination address mode(see #en_dest_address_mode_t for details)  
    
    boolean_t bSrcAddrReloadCtl;  ///< Source address reload(TRUE: reload;FALSE: reload forbidden)
    boolean_t bDestAddrReloadCtl;  ///< Dest address reload(TRUE: reload;FALSE: reload forbidden)
    boolean_t bSrcBcTcReloadCtl;  ///< Bc/Tc address reload(TRUE: reload;FALSE: reload forbidden)
    uint32_t u32SrcAddress;           ///< Source address>
    uint32_t u32DstAddress;           ///< Dest address>
    boolean_t bMsk;                   ///0: clear the bit (CONFA:ENS) after tarnfer;1: remain the bit (CONFA:ENS) after tarnfer
    
    en_dma_trig_sel_t enRequestNum;     ///< DMA trigger request number
  } stc_dma_config_t;
  /**
 ******************************************************************************
 ** \brief  DMA中断回调函数
 *****************************************************************************/
typedef struct stc_dma_irq_calbakfn_pt
{
    /*! Dma传输完成中断回调函数指针*/
    func_ptr_t  pfnDma0TranferCompleteIrq;
     /*! Dma传输完成中断回调函数指针*/
    func_ptr_t  pfnDma1TranferCompleteIrq;
    /*! Dma传输错误中断回调函数指针*/
    func_ptr_t  pfnDma0TranferErrIrq;
    /*! Dma传输错误中断回调函数指针*/
    func_ptr_t  pfnDma1TranferErrIrq;
}stc_dma_irq_calbakfn_pt_t;
  /*******************************************************************************
  * Global pre-processor symbols/macros ('#define')
  ******************************************************************************/
  
  /*******************************************************************************
  * Global variable definitions ('extern')
  ******************************************************************************/
  
  /*******************************************************************************
  * Global function prototypes (definition in C source)
  ******************************************************************************/
  en_result_t Dma_InitChannel(en_dma_channel_t enCh, stc_dma_config_t* pstcConfig);
  
  void Dma_SwTrigger(en_dma_channel_t enCh);
  
  void Dma_Enable(void);
  void Dma_Disable(void);
  
  void Dma_Start(en_dma_channel_t enCh);
  void Dma_Stop(en_dma_channel_t enCh);
  
  en_result_t Dma_EnableChannel(en_dma_channel_t enCh);
  en_result_t Dma_DisableChannel(en_dma_channel_t enCh);
  
  en_result_t Dma_SetTriggerSel(en_dma_channel_t enCh, en_dma_trig_sel_t enTrgSel);
  
  en_result_t Dma_SetSourceAddress(en_dma_channel_t enCh, uint32_t u32Address);
  en_result_t Dma_SetDestinationAddress(en_dma_channel_t enCh, uint32_t u32Address);
  
  en_result_t Dma_SetBlockSize(en_dma_channel_t enCh, uint16_t u16BlkSize);
  en_result_t Dma_SetTransferCnt(en_dma_channel_t enCh, uint16_t u16TrnCnt);
  
  
  en_result_t Dma_SetSourceIncMode(en_dma_channel_t enCh, en_address_mode_t enMode);
  en_result_t Dma_SetDestinationIncMode(en_dma_channel_t enCh, en_address_mode_t enMode);
  
  en_result_t Dma_EnableSourceRload(en_dma_channel_t enCh);
  en_result_t Dma_DisableSourceRload(en_dma_channel_t enCh);
  
  en_result_t Dma_EnableDestinationRload(en_dma_channel_t enCh);
  en_result_t Dma_DisableDestinationRload(en_dma_channel_t enCh);
  
  en_result_t Dma_EnableContinusTranfer(en_dma_channel_t enCh);
  en_result_t Dma_DisableContinusTranfer(en_dma_channel_t enCh);
  
  en_result_t Dma_EnableBcTcReload(en_dma_channel_t enCh);
  en_result_t Dma_DisableBcTcReload(en_dma_channel_t enCh);
  
  void Dma_HaltTranfer(void);
  void Dma_RecoverTranfer(void);
  en_result_t Dma_PauseChannelTranfer(en_dma_channel_t enCh);
  en_result_t Dma_RecoverChannelTranfer(en_dma_channel_t enCh);

  en_result_t Dma_SetTransferWidth(en_dma_channel_t enCh, en_dma_transfer_width_t enWidth);
  
  en_result_t Dma_SetChPriority(en_dma_priority_t enPrio);
  
  en_result_t Dma_EnableChannelIrq(en_dma_channel_t enCh);
  en_result_t Dma_DisableChannelIrq(en_dma_channel_t enCh);
  
  en_result_t Dma_EnableChannelErrIrq(en_dma_channel_t enCh);
  en_result_t Dma_DisableChannelErrIrq(en_dma_channel_t enCh);
  
  en_result_t Dma_ConfigIrq(en_dma_channel_t enCh,stc_dma_irq_sel_t* stcDmaIrqCfg,stc_dma_irq_calbakfn_pt_t* pstcDmaIrqCalbaks);

  
  en_dma_stat_t Dma_GetStat(en_dma_channel_t enCh);
  
  void Dma_ClrStat(en_dma_channel_t enCh);
  //@} // DmacGroup
  
#ifdef __cplusplus
}
#endif

#endif /* __DMAC_H__ */

/*******************************************************************************
* EOF (not truncated)
******************************************************************************/