1 /*!
2     \file    gd32f3x0_dma.c
3     \brief   DMA driver
4 
5     \version 2017-06-06, V1.0.0, firmware for GD32F3x0
6     \version 2019-06-01, V2.0.0, firmware for GD32F3x0
7     \version 2020-09-30, V2.1.0, firmware for GD32F3x0
8 */
9 
10 /*
11     Copyright (c) 2020, GigaDevice Semiconductor Inc.
12 
13     Redistribution and use in source and binary forms, with or without modification,
14 are permitted provided that the following conditions are met:
15 
16     1. Redistributions of source code must retain the above copyright notice, this
17        list of conditions and the following disclaimer.
18     2. Redistributions in binary form must reproduce the above copyright notice,
19        this list of conditions and the following disclaimer in the documentation
20        and/or other materials provided with the distribution.
21     3. Neither the name of the copyright holder nor the names of its contributors
22        may be used to endorse or promote products derived from this software without
23        specific prior written permission.
24 
25     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
26 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
27 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
28 IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
29 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
30 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
31 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
32 WHETHER IN 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 POSSIBILITY
34 OF SUCH DAMAGE.
35 */
36 
37 #include "gd32f3x0_dma.h"
38 
39 /*!
40     \brief      deinitialize DMA a channel registers
41     \param[in]  channelx: specify which DMA channel is deinitialized
42                 only one parameter can be selected which is shown as below:
43       \arg        DMA_CHx(x=0..6)
44     \param[out] none
45     \retval     none
46 */
dma_deinit(dma_channel_enum channelx)47 void dma_deinit(dma_channel_enum channelx)
48 {
49     /* disable DMA a channel */
50     DMA_CHCTL(channelx) &= ~DMA_CHXCTL_CHEN;
51     /* reset DMA channel registers */
52     DMA_CHCTL(channelx) = DMA_CHCTL_RESET_VALUE;
53     DMA_CHCNT(channelx) = DMA_CHCNT_RESET_VALUE;
54     DMA_CHPADDR(channelx) = DMA_CHPADDR_RESET_VALUE;
55     DMA_CHMADDR(channelx) = DMA_CHMADDR_RESET_VALUE;
56     DMA_INTC |= DMA_FLAG_ADD(DMA_CHINTF_RESET_VALUE, channelx);
57 }
58 
59 /*!
60     \brief      initialize the parameters of DMA struct with the default values
61     \param[in]  init_struct: the initialization data needed to initialize DMA channel
62     \param[out] none
63     \retval     none
64 */
dma_struct_para_init(dma_parameter_struct * init_struct)65 void dma_struct_para_init(dma_parameter_struct* init_struct)
66 {
67     /* set the DMA struct with the default values */
68     init_struct->periph_addr  = 0U;
69     init_struct->periph_width = 0U;
70     init_struct->periph_inc   = (uint8_t)DMA_PERIPH_INCREASE_DISABLE;
71     init_struct->memory_addr  = 0U;
72     init_struct->memory_width = 0U;
73     init_struct->memory_inc   = (uint8_t)DMA_MEMORY_INCREASE_DISABLE;
74     init_struct->number       = 0U;
75     init_struct->direction    = (uint8_t)DMA_PERIPHERAL_TO_MEMORY;
76     init_struct->priority     = (uint32_t)DMA_PRIORITY_LOW;
77 }
78 
79 /*!
80     \brief      initialize DMA channel
81     \param[in]  channelx: specify which DMA channel is initialized
82                 only one parameter can be selected which is shown as below:
83       \arg        DMA_CHx(x=0..6)
84     \param[in]  init_struct: the data needed to initialize DMA channel
85                   periph_addr: peripheral base address
86                   periph_width: DMA_PERIPHERAL_WIDTH_8BIT,DMA_PERIPHERAL_WIDTH_16BIT,DMA_PERIPHERAL_WIDTH_32BIT
87                   periph_inc: DMA_PERIPH_INCREASE_ENABLE,DMA_PERIPH_INCREASE_DISABLE
88                   memory_addr: memory base address
89                   memory_width: DMA_MEMORY_WIDTH_8BIT,DMA_MEMORY_WIDTH_16BIT,DMA_MEMORY_WIDTH_32BIT
90                   memory_inc: DMA_MEMORY_INCREASE_ENABLE,DMA_MEMORY_INCREASE_DISABLE
91                   direction: DMA_PERIPHERAL_TO_MEMORY,DMA_MEMORY_TO_PERIPHERAL
92                   number: the number of remaining data to be transferred by the DMA
93                   priority: DMA_PRIORITY_LOW,DMA_PRIORITY_MEDIUM,DMA_PRIORITY_HIGH,DMA_PRIORITY_ULTRA_HIGH
94     \param[out] none
95     \retval     none
96 */
dma_init(dma_channel_enum channelx,dma_parameter_struct * init_struct)97 void dma_init(dma_channel_enum channelx, dma_parameter_struct* init_struct)
98 {
99     uint32_t ctl;
100 
101     dma_channel_disable(channelx);
102 
103     /* configure peripheral base address */
104     DMA_CHPADDR(channelx) = init_struct->periph_addr;
105 
106     /* configure memory base address */
107     DMA_CHMADDR(channelx) = init_struct->memory_addr;
108 
109     /* configure the number of remaining data to be transferred */
110     DMA_CHCNT(channelx) = (init_struct->number & DMA_CHANNEL_CNT_MASK);
111 
112     /* configure peripheral transfer width,memory transfer width,channel priotity */
113     ctl = DMA_CHCTL(channelx);
114     ctl &= ~(DMA_CHXCTL_PWIDTH | DMA_CHXCTL_MWIDTH | DMA_CHXCTL_PRIO);
115     ctl |= (init_struct->periph_width | init_struct->memory_width | init_struct->priority);
116     DMA_CHCTL(channelx) = ctl;
117 
118     /* configure peripheral increasing mode */
119     if(DMA_PERIPH_INCREASE_ENABLE == init_struct->periph_inc){
120         DMA_CHCTL(channelx) |= DMA_CHXCTL_PNAGA;
121     }else{
122         DMA_CHCTL(channelx) &= ~DMA_CHXCTL_PNAGA;
123     }
124 
125     /* configure memory increasing mode */
126     if(DMA_MEMORY_INCREASE_ENABLE == init_struct->memory_inc){
127         DMA_CHCTL(channelx) |= DMA_CHXCTL_MNAGA;
128     }else{
129         DMA_CHCTL(channelx) &= ~DMA_CHXCTL_MNAGA;
130     }
131 
132     /* configure the direction of  data transfer */
133     if(DMA_PERIPHERAL_TO_MEMORY == init_struct->direction){
134         DMA_CHCTL(channelx) &= ~DMA_CHXCTL_DIR;
135     }else{
136         DMA_CHCTL(channelx) |= DMA_CHXCTL_DIR;
137     }
138 }
139 
140 /*!
141     \brief      enable DMA circulation mode
142     \param[in]  channelx: specify which DMA channel to set
143                 only one parameter can be selected which is shown as below:
144       \arg        DMA_CHx(x=0..6)
145     \param[out] none
146     \retval     none
147 */
dma_circulation_enable(dma_channel_enum channelx)148 void dma_circulation_enable(dma_channel_enum channelx)
149 {
150     DMA_CHCTL(channelx) |= DMA_CHXCTL_CMEN;
151 }
152 
153 /*!
154     \brief      disable DMA circulation mode
155     \param[in]  channelx: specify which DMA channel to set
156                 only one parameter can be selected which is shown as below:
157       \arg        DMA_CHx(x=0..6)
158     \param[out] none
159     \retval     none
160 */
dma_circulation_disable(dma_channel_enum channelx)161 void dma_circulation_disable(dma_channel_enum channelx)
162 {
163     DMA_CHCTL(channelx) &= ~DMA_CHXCTL_CMEN;
164 }
165 
166 /*!
167     \brief      enable memory to memory mode
168     \param[in]  channelx: specify which DMA channel to set
169                 only one parameter can be selected which is shown as below:
170       \arg        DMA_CHx(x=0..6)
171     \param[out] none
172     \retval     none
173 */
dma_memory_to_memory_enable(dma_channel_enum channelx)174 void dma_memory_to_memory_enable(dma_channel_enum channelx)
175 {
176     DMA_CHCTL(channelx) |= DMA_CHXCTL_M2M;
177 }
178 
179 /*!
180     \brief      disable memory to memory mode
181     \param[in]  channelx: specify which DMA channel to set
182                 only one parameter can be selected which is shown as below:
183       \arg        DMA_CHx(x=0..6)
184     \param[out] none
185     \retval     none
186 */
dma_memory_to_memory_disable(dma_channel_enum channelx)187 void dma_memory_to_memory_disable(dma_channel_enum channelx)
188 {
189     DMA_CHCTL(channelx) &= ~DMA_CHXCTL_M2M;
190 }
191 
192 /*!
193     \brief      enable DMA channel
194     \param[in]  channelx: specify which DMA channel to set
195                 only one parameter can be selected which is shown as below:
196       \arg        DMA_CHx(x=0..6)
197     \param[out] none
198     \retval     none
199 */
dma_channel_enable(dma_channel_enum channelx)200 void dma_channel_enable(dma_channel_enum channelx)
201 {
202     DMA_CHCTL(channelx) |= DMA_CHXCTL_CHEN;
203 }
204 
205 /*!
206     \brief      disable DMA channel
207     \param[in]  channelx: specify which DMA channel to set
208                 only one parameter can be selected which is shown as below:
209       \arg        DMA_CHx(x=0..6)
210     \param[out] none
211     \retval     none
212 */
dma_channel_disable(dma_channel_enum channelx)213 void dma_channel_disable(dma_channel_enum channelx)
214 {
215     DMA_CHCTL(channelx) &= ~DMA_CHXCTL_CHEN;
216 }
217 
218 /*!
219     \brief      set DMA peripheral base address
220     \param[in]  channelx: specify which DMA channel to set peripheral base address
221                 only one parameter can be selected which is shown as below:
222       \arg        DMA_CHx(x=0..6)
223     \param[in]  address: peripheral base address
224     \param[out] none
225     \retval     none
226 */
dma_periph_address_config(dma_channel_enum channelx,uint32_t address)227 void dma_periph_address_config(dma_channel_enum channelx, uint32_t address)
228 {
229     DMA_CHPADDR(channelx) = address;
230 }
231 
232 /*!
233     \brief      set DMA memory base address
234     \param[in]  channelx: specify which DMA channel to set memory base address
235                 only one parameter can be selected which is shown as below:
236       \arg        DMA_CHx(x=0..6)
237     \param[in]  address: memory base address
238     \param[out] none
239     \retval     none
240 */
dma_memory_address_config(dma_channel_enum channelx,uint32_t address)241 void dma_memory_address_config(dma_channel_enum channelx, uint32_t address)
242 {
243     DMA_CHMADDR(channelx) = address;
244 }
245 
246 /*!
247     \brief      set the number of remaining data to be transferred by the DMA
248     \param[in]  channelx: specify which DMA channel to set number
249                 only one parameter can be selected which is shown as below:
250       \arg        DMA_CHx(x=0..6)
251     \param[in]  number: the number of remaining data to be transferred by the DMA
252     \param[out] none
253     \retval     none
254 */
dma_transfer_number_config(dma_channel_enum channelx,uint32_t number)255 void dma_transfer_number_config(dma_channel_enum channelx, uint32_t number)
256 {
257     DMA_CHCNT(channelx) = (number & DMA_CHANNEL_CNT_MASK);
258 }
259 
260 /*!
261     \brief      get the number of remaining data to be transferred by the DMA
262     \param[in]  channelx: specify which DMA channel to set number
263                 only one parameter can be selected which is shown as below:
264       \arg        DMA_CHx(x=0..6)
265     \param[out] none
266     \retval     the number of remaining data to be transferred by the DMA
267 */
dma_transfer_number_get(dma_channel_enum channelx)268 uint32_t dma_transfer_number_get(dma_channel_enum channelx)
269 {
270     return (uint32_t)DMA_CHCNT(channelx);
271 }
272 
273 /*!
274     \brief      configure priority level of DMA channel
275     \param[in]  channelx: specify which DMA channel to set
276                 only one parameter can be selected which is shown as below:
277       \arg        DMA_CHx(x=0..6)
278     \param[in]  priority: priority level of this channel
279                 only one parameter can be selected which is shown as below:
280       \arg        DMA_PRIORITY_LOW: low priority
281       \arg        DMA_PRIORITY_MEDIUM: medium priority
282       \arg        DMA_PRIORITY_HIGH: high priority
283       \arg        DMA_PRIORITY_ULTRA_HIGH: ultra high priority
284     \param[out] none
285     \retval     none
286 */
dma_priority_config(dma_channel_enum channelx,uint32_t priority)287 void dma_priority_config(dma_channel_enum channelx, uint32_t priority)
288 {
289     uint32_t ctl;
290 
291     /* acquire DMA_CHxCTL register */
292     ctl = DMA_CHCTL(channelx);
293     /* assign regiser */
294     ctl &= ~DMA_CHXCTL_PRIO;
295     ctl |= priority;
296     DMA_CHCTL(channelx) = ctl;
297 }
298 
299 /*!
300     \brief      configure transfer data width of memory
301     \param[in]  channelx: specify which DMA channel to set
302                 only one parameter can be selected which is shown as below:
303       \arg        DMA_CHx(x=0..6)
304     \param[in]  mwidth: transfer data width of memory
305                 only one parameter can be selected which is shown as below:
306       \arg        DMA_MEMORY_WIDTH_8BIT: transfer data width of memory is 8-bit
307       \arg        DMA_MEMORY_WIDTH_16BIT: transfer data width of memory is 16-bit
308       \arg        DMA_MEMORY_WIDTH_32BIT: transfer data width of memory is 32-bit
309     \param[out] none
310     \retval     none
311 */
dma_memory_width_config(dma_channel_enum channelx,uint32_t mwidth)312 void dma_memory_width_config(dma_channel_enum channelx, uint32_t mwidth)
313 {
314     uint32_t ctl;
315 
316     /* acquire DMA_CHxCTL register */
317     ctl = DMA_CHCTL(channelx);
318     /* assign regiser */
319     ctl &= ~DMA_CHXCTL_MWIDTH;
320     ctl |= mwidth;
321     DMA_CHCTL(channelx) = ctl;
322 }
323 
324 /*!
325     \brief      configure transfer data width of peripheral
326     \param[in]  channelx: specify which DMA channel
327                 only one parameter can be selected which is shown as below:
328       \arg        DMA_CHx(x=0..6)
329     \param[in]  pwidth: transfer data width of peripheral
330                 only one parameter can be selected which is shown as below:
331       \arg        DMA_PERIPHERAL_WIDTH_8BIT: transfer data width of peripheral is 8-bit
332       \arg        DMA_PERIPHERAL_WIDTH_16BIT: transfer data width of peripheral is 16-bit
333       \arg        DMA_PERIPHERAL_WIDTH_32BIT: transfer data width of peripheral is 32-bit
334     \param[out] none
335     \retval     none
336 */
dma_periph_width_config(dma_channel_enum channelx,uint32_t pwidth)337 void dma_periph_width_config(dma_channel_enum channelx, uint32_t pwidth)
338 {
339     uint32_t ctl;
340 
341     /* acquire DMA_CHxCTL register */
342     ctl = DMA_CHCTL(channelx);
343     /* assign regiser */
344     ctl &= ~DMA_CHXCTL_PWIDTH;
345     ctl |= pwidth;
346     DMA_CHCTL(channelx) = ctl;
347 }
348 
349 /*!
350     \brief      enable next address increasement algorithm of memory
351     \param[in]  channelx: specify which DMA channel to set
352                 only one parameter can be selected which is shown as below:
353       \arg        DMA_CHx(x=0..6)
354     \param[out] none
355     \retval     none
356 */
dma_memory_increase_enable(dma_channel_enum channelx)357 void dma_memory_increase_enable(dma_channel_enum channelx)
358 {
359     DMA_CHCTL(channelx) |= DMA_CHXCTL_MNAGA;
360 }
361 
362 /*!
363     \brief      disable next address increasement algorithm of memory
364     \param[in]  channelx: specify which DMA channel to set
365                 only one parameter can be selected which is shown as below:
366       \arg        DMA_CHx(x=0..6)
367     \param[out] none
368     \retval     none
369 */
dma_memory_increase_disable(dma_channel_enum channelx)370 void dma_memory_increase_disable(dma_channel_enum channelx)
371 {
372     DMA_CHCTL(channelx) &= ~DMA_CHXCTL_MNAGA;
373 }
374 
375 /*!
376     \brief      enable next address increasement algorithm of peripheral
377     \param[in]  channelx: specify which DMA channel to set
378                 only one parameter can be selected which is shown as below:
379       \arg        DMA_CHx(x=0..6)
380     \param[out] none
381     \retval     none
382 */
dma_periph_increase_enable(dma_channel_enum channelx)383 void dma_periph_increase_enable(dma_channel_enum channelx)
384 {
385     DMA_CHCTL(channelx) |= DMA_CHXCTL_PNAGA;
386 }
387 
388 /*!
389     \brief      disable next address increasement algorithm of peripheral
390     \param[in]  channelx: specify which DMA channel to set
391                 only one parameter can be selected which is shown as below:
392       \arg        DMA_CHx(x=0..6)
393     \param[out] none
394     \retval     none
395 */
dma_periph_increase_disable(dma_channel_enum channelx)396 void dma_periph_increase_disable(dma_channel_enum channelx)
397 {
398     DMA_CHCTL(channelx) &= ~DMA_CHXCTL_PNAGA;
399 }
400 
401 /*!
402     \brief      configure the direction of data transfer on the channel
403     \param[in]  channelx: specify which DMA channel to set
404                 only one parameter can be selected which is shown as below:
405       \arg        DMA_CHx(x=0..6)
406     \param[in]  direction: specify the direction of  data transfer
407                 only one parameter can be selected which is shown as below:
408       \arg        DMA_PERIPHERAL_TO_MEMORY: read from peripheral and write to memory
409       \arg        DMA_MEMORY_TO_PERIPHERAL: read from memory and write to peripheral
410     \param[out] none
411     \retval     none
412 */
dma_transfer_direction_config(dma_channel_enum channelx,uint32_t direction)413 void dma_transfer_direction_config(dma_channel_enum channelx, uint32_t direction)
414 {
415     if(DMA_PERIPHERAL_TO_MEMORY == direction){
416         DMA_CHCTL(channelx) &= ~DMA_CHXCTL_DIR;
417     } else {
418         DMA_CHCTL(channelx) |= DMA_CHXCTL_DIR;
419     }
420 }
421 
422 /*!
423     \brief      check DMA flag is set or not
424     \param[in]  channelx: specify which DMA channel to get flag
425                 only one parameter can be selected which is shown as below:
426       \arg        DMA_CHx(x=0..6)
427     \param[in]  flag: specify get which flag
428                 only one parameter can be selected which is shown as below:
429       \arg        DMA_FLAG_G: global interrupt flag of channel
430       \arg        DMA_FLAG_FTF: full transfer finish flag of channel
431       \arg        DMA_FLAG_HTF: half transfer finish flag of channel
432       \arg        DMA_FLAG_ERR: error flag of channel
433     \param[out] none
434     \retval     FlagStatus: SET or RESET
435 */
dma_flag_get(dma_channel_enum channelx,uint32_t flag)436 FlagStatus dma_flag_get(dma_channel_enum channelx, uint32_t flag)
437 {
438     FlagStatus reval;
439 
440     if(RESET != (DMA_INTF & DMA_FLAG_ADD(flag, channelx))){
441         reval = SET;
442     }else{
443         reval = RESET;
444     }
445 
446     return reval;
447 }
448 
449 /*!
450     \brief      clear DMA a channel flag
451     \param[in]  channelx: specify which DMA channel to clear flag
452                 only one parameter can be selected which is shown as below:
453       \arg        DMA_CHx(x=0..6)
454     \param[in]  flag: specify get which flag
455                 only one parameter can be selected which is shown as below:
456       \arg        DMA_FLAG_G: global interrupt flag of channel
457       \arg        DMA_FLAG_FTF: full transfer finish flag of channel
458       \arg        DMA_FLAG_HTF: half transfer finish flag of channel
459       \arg        DMA_FLAG_ERR: error flag of channel
460     \param[out] none
461     \retval     none
462 */
dma_flag_clear(dma_channel_enum channelx,uint32_t flag)463 void dma_flag_clear(dma_channel_enum channelx, uint32_t flag)
464 {
465     DMA_INTC |= DMA_FLAG_ADD(flag, channelx);
466 }
467 
468 /*!
469     \brief      check DMA flag and interrupt enable bit is set or not
470     \param[in]  channelx: specify which DMA channel to get flag
471                 only one parameter can be selected which is shown as below:
472       \arg        DMA_CHx(x=0..6)
473     \param[in]  flag: specify get which flag
474                 only one parameter can be selected which is shown as below:
475       \arg        DMA_INT_FLAG_FTF: transfer finish flag of channel
476       \arg        DMA_INT_FLAG_HTF: half transfer finish flag of channel
477       \arg        DMA_INT_FLAG_ERR: error flag of channel
478     \param[out] none
479     \retval     FlagStatus: SET or RESET
480 */
dma_interrupt_flag_get(dma_channel_enum channelx,uint32_t flag)481 FlagStatus dma_interrupt_flag_get(dma_channel_enum channelx, uint32_t flag)
482 {
483     uint32_t interrupt_enable = 0U, interrupt_flag = 0U;
484 
485     switch(flag){
486         case DMA_INT_FLAG_FTF:
487             interrupt_flag = DMA_INTF & DMA_FLAG_ADD(flag, channelx);
488             interrupt_enable = DMA_CHCTL(channelx) & DMA_CHXCTL_FTFIE;
489             break;
490         case DMA_INT_FLAG_HTF:
491             interrupt_flag = DMA_INTF & DMA_FLAG_ADD(flag, channelx);
492             interrupt_enable = DMA_CHCTL(channelx) & DMA_CHXCTL_HTFIE;
493             break;
494         case DMA_INT_FLAG_ERR:
495             interrupt_flag = DMA_INTF & DMA_FLAG_ADD(flag, channelx);
496             interrupt_enable = DMA_CHCTL(channelx) & DMA_CHXCTL_ERRIE;
497             break;
498         default:
499             break;
500         }
501 
502     if(interrupt_flag && interrupt_enable){
503         return SET;
504     }else{
505         return RESET;
506     }
507 }
508 
509 /*!
510     \brief      clear DMA a channel interrupt flag
511     \param[in]  channelx: specify which DMA channel to clear flag
512                 only one parameter can be selected which is shown as below:
513       \arg        DMA_CHx(x=0..6)
514     \param[in]  flag: specify get which flag
515                 only one parameter can be selected which is shown as below:
516       \arg        DMA_INT_FLAG_G: global interrupt flag of channel
517       \arg        DMA_INT_FLAG_FTF: transfer finish flag of channel
518       \arg        DMA_INT_FLAG_HTF: half transfer finish flag of channel
519       \arg        DMA_INT_FLAG_ERR: error flag of channel
520     \param[out] none
521     \retval     none
522 */
dma_interrupt_flag_clear(dma_channel_enum channelx,uint32_t flag)523 void dma_interrupt_flag_clear(dma_channel_enum channelx, uint32_t flag)
524 {
525     DMA_INTC |= DMA_FLAG_ADD(flag,channelx);
526 }
527 
528 /*!
529     \brief      enable DMA interrupt
530     \param[in]  channelx: specify which DMA channel to set
531                 only one parameter can be selected which is shown as below:
532       \arg        DMA_CHx(x=0..6)
533     \param[in]  source: specify which interrupt to enable
534                 only one parameter can be selected which is shown as below:
535       \arg        DMA_INT_ERR: channel error interrupt
536       \arg        DMA_INT_HTF: channel half transfer finish interrupt
537       \arg        DMA_INT_FTF: channel full transfer finish interrupt
538     \param[out] none
539     \retval     none
540 */
dma_interrupt_enable(dma_channel_enum channelx,uint32_t source)541 void dma_interrupt_enable(dma_channel_enum channelx, uint32_t source)
542 {
543     DMA_CHCTL(channelx) |= source;
544 }
545 
546 /*!
547     \brief      disable DMA interrupt
548     \param[in]  channelx: specify which DMA channel to set
549                 only one parameter can be selected which is shown as below:
550       \arg        DMA_CHx(x=0..6)
551     \param[in]  source: specify which interrupt to disable
552                 only one parameter can be selected which is shown as below:
553       \arg        DMA_INT_ERR: channel error interrupt
554       \arg        DMA_INT_HTF: channel half transfer finish interrupt
555       \arg        DMA_INT_FTF: channel full transfer finish interrupt
556     \param[out] none
557     \retval     none
558 */
dma_interrupt_disable(dma_channel_enum channelx,uint32_t source)559 void dma_interrupt_disable(dma_channel_enum channelx, uint32_t source)
560 {
561     DMA_CHCTL(channelx) &= ~source;
562 }
563