1 /*!
2 \file gd32l23x_dma.c
3 \brief DMA driver
4
5 \version 2021-08-04, V1.0.0, firmware for GD32L23x
6 */
7
8 /*
9 Copyright (c) 2021, GigaDevice Semiconductor Inc.
10
11 Redistribution and use in source and binary forms, with or without modification,
12 are permitted provided that the following conditions are met:
13
14 1. Redistributions of source code must retain the above copyright notice, this
15 list of conditions and the following disclaimer.
16 2. Redistributions in binary form must reproduce the above copyright notice,
17 this list of conditions and the following disclaimer in the documentation
18 and/or other materials provided with the distribution.
19 3. Neither the name of the copyright holder nor the names of its contributors
20 may be used to endorse or promote products derived from this software without
21 specific prior written permission.
22
23 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
27 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
29 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
30 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
32 OF SUCH DAMAGE.
33 */
34
35 #include "gd32l23x_dma.h"
36 #include <stdlib.h>
37
38 #define DMA_WRONG_HANDLE while(1){}
39
40 /*!
41 \brief deinitialize DMA a channel registers
42 \param[in] channelx: specify which DMA channel is deinitialized
43 only one parameter can be selected which is shown as below:
44 \arg DMA_CHx(x=0..6)
45 \param[out] none
46 \retval none
47 */
dma_deinit(dma_channel_enum channelx)48 void dma_deinit(dma_channel_enum channelx)
49 {
50 /* disable DMA a channel */
51 DMA_CHCTL(channelx) &= ~DMA_CHXCTL_CHEN;
52 /* reset DMA channel registers */
53 DMA_CHCTL(channelx) = DMA_CHCTL_RESET_VALUE;
54 DMA_CHCNT(channelx) = DMA_CHCNT_RESET_VALUE;
55 DMA_CHPADDR(channelx) = DMA_CHPADDR_RESET_VALUE;
56 DMA_CHMADDR(channelx) = DMA_CHMADDR_RESET_VALUE;
57 DMA_INTC |= DMA_FLAG_ADD(DMA_CHINTF_RESET_VALUE, channelx);
58 }
59
60 /*!
61 \brief initialize the parameters of DMA struct with the default values
62 \param[in] init_struct: the initialization data needed to initialize DMA channel
63 \param[out] none
64 \retval none
65 */
dma_struct_para_init(dma_parameter_struct * init_struct)66 void dma_struct_para_init(dma_parameter_struct *init_struct)
67 {
68 if(NULL == init_struct) {
69 DMA_WRONG_HANDLE
70 }
71
72 /* set the DMA struct with the default values */
73 init_struct->periph_addr = 0U;
74 init_struct->periph_width = 0U;
75 init_struct->periph_inc = (uint8_t)DMA_PERIPH_INCREASE_DISABLE;
76 init_struct->memory_addr = 0U;
77 init_struct->memory_width = 0U;
78 init_struct->memory_inc = (uint8_t)DMA_MEMORY_INCREASE_DISABLE;
79 init_struct->number = 0U;
80 init_struct->direction = (uint8_t)DMA_PERIPHERAL_TO_MEMORY;
81 init_struct->priority = (uint32_t)DMA_PRIORITY_LOW;
82 init_struct->request = DMA_REQUEST_M2M;
83 }
84
85 /*!
86 \brief initialize DMA channel
87 \param[in] channelx: specify which DMA channel is initialized
88 only one parameter can be selected which is shown as below:
89 \arg DMA_CHx(x=0..6)
90 \param[in] init_struct: the data needed to initialize DMA channel
91 periph_addr: peripheral base address
92 periph_width: DMA_PERIPHERAL_WIDTH_8BIT, DMA_PERIPHERAL_WIDTH_16BIT, DMA_PERIPHERAL_WIDTH_32BIT
93 periph_inc: DMA_PERIPH_INCREASE_ENABLE, DMA_PERIPH_INCREASE_DISABLE
94 memory_addr: memory base address
95 memory_width: DMA_MEMORY_WIDTH_8BIT, DMA_MEMORY_WIDTH_16BIT, DMA_MEMORY_WIDTH_32BIT
96 memory_inc: DMA_MEMORY_INCREASE_ENABLE, DMA_MEMORY_INCREASE_DISABLE
97 direction: DMA_PERIPHERAL_TO_MEMORY, DMA_MEMORY_TO_PERIPHERAL
98 number: the number of remaining data to be transferred by the DMA
99 priority: DMA_PRIORITY_LOW, DMA_PRIORITY_MEDIUM, DMA_PRIORITY_HIGH, DMA_PRIORITY_ULTRA_HIGH
100 request: DMA_REQUEST_M2M, DMA_REQUEST_GENERATOR0, DMA_REQUEST_GENERATOR1, DMA_REQUEST_GENERATOR2,
101 DMA_REQUEST_GENERATOR3, DMA_REQUEST_ADC, DMA_REQUEST_DAC, DMA_REQUEST_I2C0_RX,
102 DMA_REQUEST_I2C0_TX, DMA_REQUEST_I2C1_RX, DMA_REQUEST_I2C1_TX, DMA_REQUEST_I2C2_RX,
103 DMA_REQUEST_I2C2_TX, DMA_REQUEST_SPI0_RX, DMA_REQUEST_SPI0_TX, DMA_REQUEST_SPI1_RX,
104 DMA_REQUEST_SPI1_TX, DMA_REQUEST_TIMER1_CH0, DMA_REQUEST_TIMER1_CH1, DMA_REQUEST_TIMER1_CH2,
105 DMA_REQUEST_TIMER1_CH3, DMA_REQUEST_TIMER1_UP, DMA_REQUEST_TIMER2_CH0, DMA_REQUEST_TIMER2_CH1,
106 DMA_REQUEST_TIMER2_CH2, DMA_REQUEST_TIMER2_CH3, DMA_REQUEST_TIMER2_TRIG, DMA_REQUEST_TIMER2_UP,
107 DMA_REQUEST_TIMER5_UP, DMA_REQUEST_TIMER6_UP, DMA_REQUEST_CAU_IN, DMA_REQUEST_CAU_OUT,
108 DMA_REQUEST_USART0_RX, DMA_REQUEST_USART0_TX, DMA_REQUEST_USART1_RX, DMA_REQUEST_USART1_TX,
109 DMA_REQUEST_UART3_RX, DMA_REQUEST_UART3_TX, DMA_REQUEST_UART4_RX, DMA_REQUEST_UART4_TX,
110 DMA_REQUEST_LPUART_RX, DMA_REQUEST_LPUART_TX
111 \param[out] none
112 \retval none
113 */
dma_init(dma_channel_enum channelx,dma_parameter_struct * init_struct)114 void dma_init(dma_channel_enum channelx, dma_parameter_struct *init_struct)
115 {
116 uint32_t ctl;
117
118 if(NULL == init_struct) {
119 DMA_WRONG_HANDLE
120 }
121
122 dma_channel_disable(channelx);
123
124 /* configure peripheral base address */
125 DMA_CHPADDR(channelx) = init_struct->periph_addr;
126
127 /* configure memory base address */
128 DMA_CHMADDR(channelx) = init_struct->memory_addr;
129
130 /* configure the number of remaining data to be transferred */
131 DMA_CHCNT(channelx) = (init_struct->number & DMA_CHANNEL_CNT_MASK);
132
133 /* configure peripheral transfer width, memory transfer width, channel priority */
134 ctl = DMA_CHCTL(channelx);
135 ctl &= ~(DMA_CHXCTL_PWIDTH | DMA_CHXCTL_MWIDTH | DMA_CHXCTL_PRIO);
136 ctl |= (init_struct->periph_width | init_struct->memory_width | init_struct->priority);
137 DMA_CHCTL(channelx) = ctl;
138
139 /* configure peripheral increasing mode */
140 if(DMA_PERIPH_INCREASE_ENABLE == init_struct->periph_inc) {
141 DMA_CHCTL(channelx) |= DMA_CHXCTL_PNAGA;
142 } else {
143 DMA_CHCTL(channelx) &= ~DMA_CHXCTL_PNAGA;
144 }
145
146 /* configure memory increasing mode */
147 if(DMA_MEMORY_INCREASE_ENABLE == init_struct->memory_inc) {
148 DMA_CHCTL(channelx) |= DMA_CHXCTL_MNAGA;
149 } else {
150 DMA_CHCTL(channelx) &= ~DMA_CHXCTL_MNAGA;
151 }
152
153 /* configure the direction of data transfer */
154 if(DMA_PERIPHERAL_TO_MEMORY == init_struct->direction) {
155 DMA_CHCTL(channelx) &= ~DMA_CHXCTL_DIR;
156 } else {
157 DMA_CHCTL(channelx) |= DMA_CHXCTL_DIR;
158 }
159
160 DMAMUX_RM_CHXCFG(channelx) &= ~DMAMUX_RM_CHXCFG_MUXID;
161 DMAMUX_RM_CHXCFG(channelx) |= init_struct->request;
162 }
163
164 /*!
165 \brief enable DMA circulation mode
166 \param[in] channelx: specify which DMA channel to set
167 only one parameter can be selected which is shown as below:
168 \arg DMA_CHx(x=0..6)
169 \param[out] none
170 \retval none
171 */
dma_circulation_enable(dma_channel_enum channelx)172 void dma_circulation_enable(dma_channel_enum channelx)
173 {
174 DMA_CHCTL(channelx) |= DMA_CHXCTL_CMEN;
175 }
176
177 /*!
178 \brief disable DMA circulation mode
179 \param[in] channelx: specify which DMA channel to set
180 only one parameter can be selected which is shown as below:
181 \arg DMA_CHx(x=0..6)
182 \param[out] none
183 \retval none
184 */
dma_circulation_disable(dma_channel_enum channelx)185 void dma_circulation_disable(dma_channel_enum channelx)
186 {
187 DMA_CHCTL(channelx) &= ~DMA_CHXCTL_CMEN;
188 }
189
190 /*!
191 \brief enable memory to memory mode
192 \param[in] channelx: specify which DMA channel to set
193 only one parameter can be selected which is shown as below:
194 \arg DMA_CHx(x=0..6)
195 \param[out] none
196 \retval none
197 */
dma_memory_to_memory_enable(dma_channel_enum channelx)198 void dma_memory_to_memory_enable(dma_channel_enum channelx)
199 {
200 DMA_CHCTL(channelx) |= DMA_CHXCTL_M2M;
201 }
202
203 /*!
204 \brief disable memory to memory mode
205 \param[in] channelx: specify which DMA channel to set
206 only one parameter can be selected which is shown as below:
207 \arg DMA_CHx(x=0..6)
208 \param[out] none
209 \retval none
210 */
dma_memory_to_memory_disable(dma_channel_enum channelx)211 void dma_memory_to_memory_disable(dma_channel_enum channelx)
212 {
213 DMA_CHCTL(channelx) &= ~DMA_CHXCTL_M2M;
214 }
215
216 /*!
217 \brief enable DMA channel
218 \param[in] channelx: specify which DMA channel to set
219 only one parameter can be selected which is shown as below:
220 \arg DMA_CHx(x=0..6)
221 \param[out] none
222 \retval none
223 */
dma_channel_enable(dma_channel_enum channelx)224 void dma_channel_enable(dma_channel_enum channelx)
225 {
226 DMA_CHCTL(channelx) |= DMA_CHXCTL_CHEN;
227 }
228
229 /*!
230 \brief disable DMA channel
231 \param[in] channelx: specify which DMA channel to set
232 only one parameter can be selected which is shown as below:
233 \arg DMA_CHx(x=0..6)
234 \param[out] none
235 \retval none
236 */
dma_channel_disable(dma_channel_enum channelx)237 void dma_channel_disable(dma_channel_enum channelx)
238 {
239 DMA_CHCTL(channelx) &= ~DMA_CHXCTL_CHEN;
240 }
241
242 /*!
243 \brief set DMA peripheral base address
244 \param[in] channelx: specify which DMA channel to set peripheral base address
245 only one parameter can be selected which is shown as below:
246 \arg DMA_CHx(x=0..6)
247 \param[in] address: peripheral base address
248 \param[out] none
249 \retval none
250 */
dma_periph_address_config(dma_channel_enum channelx,uint32_t address)251 void dma_periph_address_config(dma_channel_enum channelx, uint32_t address)
252 {
253 DMA_CHPADDR(channelx) = address;
254 }
255
256 /*!
257 \brief set DMA memory base address
258 \param[in] channelx: specify which DMA channel to set memory base address
259 only one parameter can be selected which is shown as below:
260 \arg DMA_CHx(x=0..6)
261 \param[in] address: memory base address
262 \param[out] none
263 \retval none
264 */
dma_memory_address_config(dma_channel_enum channelx,uint32_t address)265 void dma_memory_address_config(dma_channel_enum channelx, uint32_t address)
266 {
267 DMA_CHMADDR(channelx) = address;
268 }
269
270 /*!
271 \brief set the number of remaining data to be transferred by the DMA
272 \param[in] channelx: specify which DMA channel to set number
273 only one parameter can be selected which is shown as below:
274 \arg DMA_CHx(x=0..6)
275 \param[in] number: the number of remaining data to be transferred by the DMA
276 \arg 0x0 - 0xFFFF
277 \param[out] none
278 \retval none
279 */
dma_transfer_number_config(dma_channel_enum channelx,uint32_t number)280 void dma_transfer_number_config(dma_channel_enum channelx, uint32_t number)
281 {
282 DMA_CHCNT(channelx) = (number & DMA_CHANNEL_CNT_MASK);
283 }
284
285 /*!
286 \brief get the number of remaining data to be transferred by the DMA
287 \param[in] channelx: specify which DMA channel to set number
288 only one parameter can be selected which is shown as below:
289 \arg DMA_CHx(x=0..6)
290 \param[out] none
291 \retval the number of remaining data to be transferred by the DMA, 0x0 - 0xFFFF
292 */
dma_transfer_number_get(dma_channel_enum channelx)293 uint32_t dma_transfer_number_get(dma_channel_enum channelx)
294 {
295 return (uint32_t)DMA_CHCNT(channelx);
296 }
297
298 /*!
299 \brief configure priority level of DMA channel
300 \param[in] channelx: specify which DMA channel to set
301 only one parameter can be selected which is shown as below:
302 \arg DMA_CHx(x=0..6)
303 \param[in] priority: priority level of this channel
304 only one parameter can be selected which is shown as below:
305 \arg DMA_PRIORITY_LOW: low priority
306 \arg DMA_PRIORITY_MEDIUM: medium priority
307 \arg DMA_PRIORITY_HIGH: high priority
308 \arg DMA_PRIORITY_ULTRA_HIGH: ultra high priority
309 \param[out] none
310 \retval none
311 */
dma_priority_config(dma_channel_enum channelx,uint32_t priority)312 void dma_priority_config(dma_channel_enum channelx, uint32_t priority)
313 {
314 uint32_t ctl;
315
316 /* acquire DMA_CHxCTL register */
317 ctl = DMA_CHCTL(channelx);
318 /* assign regiser */
319 ctl &= ~DMA_CHXCTL_PRIO;
320 ctl |= priority;
321 DMA_CHCTL(channelx) = ctl;
322 }
323
324 /*!
325 \brief configure transfer data width of memory
326 \param[in] channelx: specify which DMA channel to set
327 only one parameter can be selected which is shown as below:
328 \arg DMA_CHx(x=0..6)
329 \param[in] mwidth: transfer data width of memory
330 only one parameter can be selected which is shown as below:
331 \arg DMA_MEMORY_WIDTH_8BIT: transfer data width of memory is 8-bit
332 \arg DMA_MEMORY_WIDTH_16BIT: transfer data width of memory is 16-bit
333 \arg DMA_MEMORY_WIDTH_32BIT: transfer data width of memory is 32-bit
334 \param[out] none
335 \retval none
336 */
dma_memory_width_config(dma_channel_enum channelx,uint32_t mwidth)337 void dma_memory_width_config(dma_channel_enum channelx, uint32_t mwidth)
338 {
339 uint32_t ctl;
340
341 /* acquire DMA_CHxCTL register */
342 ctl = DMA_CHCTL(channelx);
343 /* assign regiser */
344 ctl &= ~DMA_CHXCTL_MWIDTH;
345 ctl |= mwidth;
346 DMA_CHCTL(channelx) = ctl;
347 }
348
349 /*!
350 \brief configure transfer data width of peripheral
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[in] pwidth: transfer data width of peripheral
355 only one parameter can be selected which is shown as below:
356 \arg DMA_PERIPHERAL_WIDTH_8BIT: transfer data width of peripheral is 8-bit
357 \arg DMA_PERIPHERAL_WIDTH_16BIT: transfer data width of peripheral is 16-bit
358 \arg DMA_PERIPHERAL_WIDTH_32BIT: transfer data width of peripheral is 32-bit
359 \param[out] none
360 \retval none
361 */
dma_periph_width_config(dma_channel_enum channelx,uint32_t pwidth)362 void dma_periph_width_config(dma_channel_enum channelx, uint32_t pwidth)
363 {
364 uint32_t ctl;
365
366 /* acquire DMA_CHxCTL register */
367 ctl = DMA_CHCTL(channelx);
368 /* assign regiser */
369 ctl &= ~DMA_CHXCTL_PWIDTH;
370 ctl |= pwidth;
371 DMA_CHCTL(channelx) = ctl;
372 }
373
374 /*!
375 \brief enable next address increasement algorithm of memory
376 \param[in] channelx: specify which DMA channel to set
377 only one parameter can be selected which is shown as below:
378 \arg DMA_CHx(x=0..6)
379 \param[out] none
380 \retval none
381 */
dma_memory_increase_enable(dma_channel_enum channelx)382 void dma_memory_increase_enable(dma_channel_enum channelx)
383 {
384 DMA_CHCTL(channelx) |= DMA_CHXCTL_MNAGA;
385 }
386
387 /*!
388 \brief disable next address increasement algorithm of memory
389 \param[in] channelx: specify which DMA channel to set
390 only one parameter can be selected which is shown as below:
391 \arg DMA_CHx(x=0..6)
392 \param[out] none
393 \retval none
394 */
dma_memory_increase_disable(dma_channel_enum channelx)395 void dma_memory_increase_disable(dma_channel_enum channelx)
396 {
397 DMA_CHCTL(channelx) &= ~DMA_CHXCTL_MNAGA;
398 }
399
400 /*!
401 \brief enable next address increasement algorithm of peripheral
402 \param[in] channelx: specify which DMA channel to set
403 only one parameter can be selected which is shown as below:
404 \arg DMA_CHx(x=0..6)
405 \param[out] none
406 \retval none
407 */
dma_periph_increase_enable(dma_channel_enum channelx)408 void dma_periph_increase_enable(dma_channel_enum channelx)
409 {
410 DMA_CHCTL(channelx) |= DMA_CHXCTL_PNAGA;
411 }
412
413 /*!
414 \brief disable next address increasement algorithm of peripheral
415 \param[in] channelx: specify which DMA channel to set
416 only one parameter can be selected which is shown as below:
417 \arg DMA_CHx(x=0..6)
418 \param[out] none
419 \retval none
420 */
dma_periph_increase_disable(dma_channel_enum channelx)421 void dma_periph_increase_disable(dma_channel_enum channelx)
422 {
423 DMA_CHCTL(channelx) &= ~DMA_CHXCTL_PNAGA;
424 }
425
426 /*!
427 \brief configure the direction of data transfer on the channel
428 \param[in] channelx: specify which DMA channel to set
429 only one parameter can be selected which is shown as below:
430 \arg DMA_CHx(x=0..6)
431 \param[in] direction: specify the direction of data transfer
432 only one parameter can be selected which is shown as below:
433 \arg DMA_PERIPHERAL_TO_MEMORY: read from peripheral and write to memory
434 \arg DMA_MEMORY_TO_PERIPHERAL: read from memory and write to peripheral
435 \param[out] none
436 \retval none
437 */
dma_transfer_direction_config(dma_channel_enum channelx,uint32_t direction)438 void dma_transfer_direction_config(dma_channel_enum channelx, uint32_t direction)
439 {
440 if(DMA_PERIPHERAL_TO_MEMORY == direction) {
441 DMA_CHCTL(channelx) &= ~DMA_CHXCTL_DIR;
442 } else {
443 DMA_CHCTL(channelx) |= DMA_CHXCTL_DIR;
444 }
445 }
446
447 /*!
448 \brief check DMA flag is set or not
449 \param[in] channelx: specify which DMA channel to get flag
450 only one parameter can be selected which is shown as below:
451 \arg DMA_CHx(x=0..6)
452 \param[in] flag: specify get which flag
453 only one parameter can be selected which is shown as below:
454 \arg DMA_FLAG_G: global interrupt flag of channel
455 \arg DMA_FLAG_FTF: full transfer finish flag of channel
456 \arg DMA_FLAG_HTF: half transfer finish flag of channel
457 \arg DMA_FLAG_ERR: error flag of channel
458 \param[out] none
459 \retval FlagStatus: SET or RESET
460 */
dma_flag_get(dma_channel_enum channelx,uint32_t flag)461 FlagStatus dma_flag_get(dma_channel_enum channelx, uint32_t flag)
462 {
463 FlagStatus reval;
464
465 if(RESET != (DMA_INTF & DMA_FLAG_ADD(flag, channelx))) {
466 reval = SET;
467 } else {
468 reval = RESET;
469 }
470
471 return reval;
472 }
473
474 /*!
475 \brief clear a DMA channel flag
476 \param[in] channelx: specify which DMA channel to clear flag
477 only one parameter can be selected which is shown as below:
478 \arg DMA_CHx(x=0..6)
479 \param[in] flag: specify get which flag
480 only one parameter can be selected which is shown as below:
481 \arg DMA_FLAG_G: global interrupt flag of channel
482 \arg DMA_FLAG_FTF: full transfer finish flag of channel
483 \arg DMA_FLAG_HTF: half transfer finish flag of channel
484 \arg DMA_FLAG_ERR: error flag of channel
485 \param[out] none
486 \retval none
487 */
dma_flag_clear(dma_channel_enum channelx,uint32_t flag)488 void dma_flag_clear(dma_channel_enum channelx, uint32_t flag)
489 {
490 DMA_INTC |= DMA_FLAG_ADD(flag, channelx);
491 }
492
493 /*!
494 \brief check DMA flag and interrupt enable bit is set or not
495 \param[in] channelx: specify which DMA channel to get flag
496 only one parameter can be selected which is shown as below:
497 \arg DMA_CHx(x=0..6)
498 \param[in] flag: specify get which flag
499 only one parameter can be selected which is shown as below:
500 \arg DMA_INT_FLAG_FTF: transfer finish flag of channel
501 \arg DMA_INT_FLAG_HTF: half transfer finish flag of channel
502 \arg DMA_INT_FLAG_ERR: error flag of channel
503 \param[out] none
504 \retval FlagStatus: SET or RESET
505 */
dma_interrupt_flag_get(dma_channel_enum channelx,uint32_t int_flag)506 FlagStatus dma_interrupt_flag_get(dma_channel_enum channelx, uint32_t int_flag)
507 {
508 uint32_t interrupt_enable = 0U, interrupt_flag = 0U;
509
510 switch(int_flag) {
511 case DMA_INT_FLAG_FTF:
512 interrupt_flag = DMA_INTF & DMA_FLAG_ADD(int_flag, channelx);
513 interrupt_enable = DMA_CHCTL(channelx) & DMA_CHXCTL_FTFIE;
514 break;
515 case DMA_INT_FLAG_HTF:
516 interrupt_flag = DMA_INTF & DMA_FLAG_ADD(int_flag, channelx);
517 interrupt_enable = DMA_CHCTL(channelx) & DMA_CHXCTL_HTFIE;
518 break;
519 case DMA_INT_FLAG_ERR:
520 interrupt_flag = DMA_INTF & DMA_FLAG_ADD(int_flag, channelx);
521 interrupt_enable = DMA_CHCTL(channelx) & DMA_CHXCTL_ERRIE;
522 break;
523 default:
524 break;
525 }
526
527 if(interrupt_flag && interrupt_enable) {
528 return SET;
529 } else {
530 return RESET;
531 }
532 }
533
534 /*!
535 \brief clear a DMA channel interrupt flag
536 \param[in] channelx: specify which DMA channel to clear flag
537 only one parameter can be selected which is shown as below:
538 \arg DMA_CHx(x=0..6)
539 \param[in] flag: specify get which flag
540 only one parameter can be selected which is shown as below:
541 \arg DMA_INT_FLAG_G: global interrupt flag of channel
542 \arg DMA_INT_FLAG_FTF: transfer finish flag of channel
543 \arg DMA_INT_FLAG_HTF: half transfer finish flag of channel
544 \arg DMA_INT_FLAG_ERR: error flag of channel
545 \param[out] none
546 \retval none
547 */
dma_interrupt_flag_clear(dma_channel_enum channelx,uint32_t int_flag)548 void dma_interrupt_flag_clear(dma_channel_enum channelx, uint32_t int_flag)
549 {
550 DMA_INTC |= DMA_FLAG_ADD(int_flag, channelx);
551 }
552
553 /*!
554 \brief enable DMA interrupt
555 \param[in] channelx: specify which DMA channel to set
556 only one parameter can be selected which is shown as below:
557 \arg DMA_CHx(x=0..6)
558 \param[in] source: specify which interrupt to enable
559 only one parameter can be selected which is shown as below:
560 \arg DMA_INT_ERR: channel error interrupt
561 \arg DMA_INT_HTF: channel half transfer finish interrupt
562 \arg DMA_INT_FTF: channel full transfer finish interrupt
563 \param[out] none
564 \retval none
565 */
dma_interrupt_enable(dma_channel_enum channelx,uint32_t source)566 void dma_interrupt_enable(dma_channel_enum channelx, uint32_t source)
567 {
568 DMA_CHCTL(channelx) |= source;
569 }
570
571 /*!
572 \brief disable DMA interrupt
573 \param[in] channelx: specify which DMA channel to set
574 only one parameter can be selected which is shown as below:
575 \arg DMA_CHx(x=0..6)
576 \param[in] source: specify which interrupt to disable
577 only one parameter can be selected which is shown as below:
578 \arg DMA_INT_ERR: channel error interrupt
579 \arg DMA_INT_HTF: channel half transfer finish interrupt
580 \arg DMA_INT_FTF: channel full transfer finish interrupt
581 \param[out] none
582 \retval none
583 */
dma_interrupt_disable(dma_channel_enum channelx,uint32_t source)584 void dma_interrupt_disable(dma_channel_enum channelx, uint32_t source)
585 {
586 DMA_CHCTL(channelx) &= ~source;
587 }
588
589 /*!
590 \brief initialize the parameters of DMAMUX synchronization mode structure with the default values
591 \param[in] none
592 \param[out] init_struct: the initialization data needed to initialize DMAMUX request multiplexer channel synchronization mode
593 \retval none
594 */
dmamux_sync_struct_para_init(dmamux_sync_parameter_struct * init_struct)595 void dmamux_sync_struct_para_init(dmamux_sync_parameter_struct *init_struct)
596 {
597 if(NULL == init_struct) {
598 DMA_WRONG_HANDLE
599 }
600
601 /* set the DMAMUX synchronization struct with the default values */
602 init_struct->sync_id = DMAMUX_SYNC_EVT0_OUT;
603 init_struct->sync_polarity = DMAMUX_SYNC_RISING;
604 init_struct->request_number = 1U;
605 }
606
607 /*!
608 \brief initialize DMAMUX request multiplexer channel synchronization mode
609 \param[in] channelx: specify which DMAMUX request multiplexer channel is initialized
610 only one parameter can be selected which is shown as below:
611 \arg DMAMUX_MUXCHx(x=0..6)
612 \param[in] init_struct: the data needed to initialize DMAMUX request multiplexer channel
613 sync_id: DMAMUX_SYNC_EXTI0, DMAMUX_SYNC_EXTI1, DMAMUX_SYNC_EXTI2, DMAMUX_SYNC_EXTI3,
614 DMAMUX_SYNC_EXTI4, DMAMUX_SYNC_EXTI5, DMAMUX_SYNC_EXTI6, DMAMUX_SYNC_EXTI7,
615 DMAMUX_SYNC_EXTI8, DMAMUX_SYNC_EXTI9, DMAMUX_SYNC_EXTI10, DMAMUX_SYNC_EXTI11,
616 DMAMUX_SYNC_EXTI12, DMAMUX_SYNC_EXTI13, DMAMUX_SYNC_EXTI14, DMAMUX_SYNC_EXTI15,
617 DMAMUX_SYNC_EVT0_OUT, DMAMUX_SYNC_EVT1_OUT, DMAMUX_SYNC_EVT2_OUT, DMAMUX_SYNC_EVT3_OUT,
618 DMAMUX_SYNC_TIMER11_CH0_O
619 sync_polarity: DMAMUX_SYNC_NO_EVENT, DMAMUX_SYNC_RISING, DMAMUX_SYNC_FALLING, DMAMUX_SYNC_RISING_FALLING
620 request_number: the number of DMA request that will be authorized after a sync event, from 1 to 32
621 \param[out] none
622 \retval none
623 */
dmamux_synchronization_init(dmamux_multiplexer_channel_enum channelx,dmamux_sync_parameter_struct * init_struct)624 void dmamux_synchronization_init(dmamux_multiplexer_channel_enum channelx, dmamux_sync_parameter_struct *init_struct)
625 {
626 uint32_t cfg;
627
628 if(NULL == init_struct) {
629 DMA_WRONG_HANDLE
630 }
631
632 /* disable synchronization mode and event generation for DMA request forward number configuration */
633 DMAMUX_RM_CHXCFG(channelx) &= ~(DMAMUX_RM_CHXCFG_SYNCEN | DMAMUX_RM_CHXCFG_EVGEN);
634
635 /* configure synchronization input identification, synchronization input polarity, number of DMA requests to forward */
636 cfg = DMAMUX_RM_CHXCFG(channelx);
637 cfg &= ~(DMAMUX_RM_CHXCFG_SYNCID | DMAMUX_RM_CHXCFG_NBR | DMAMUX_RM_CHXCFG_SYNCP);
638 cfg |= (init_struct->sync_polarity | (init_struct->sync_id) | RM_CHXCFG_NBR(init_struct->request_number - 1U));
639 DMAMUX_RM_CHXCFG(channelx) = cfg;
640 }
641
642 /*!
643 \brief enable synchronization mode
644 \param[in] channelx: specify which DMAMUX request multiplexer channel is configured
645 only one parameter can be selected which is shown as below:
646 \arg DMAMUX_MUXCHx(x=0..6)
647 \param[out] none
648 \retval none
649 */
dmamux_synchronization_enable(dmamux_multiplexer_channel_enum channelx)650 void dmamux_synchronization_enable(dmamux_multiplexer_channel_enum channelx)
651 {
652 DMAMUX_RM_CHXCFG(channelx) |= DMAMUX_RM_CHXCFG_SYNCEN;
653 }
654
655 /*!
656 \brief disable synchronization mode
657 \param[in] channelx: specify which DMAMUX request multiplexer channel is configured
658 only one parameter can be selected which is shown as below:
659 \arg DMAMUX_MUXCHx(x=0..6)
660 \param[out] none
661 \retval none
662 */
dmamux_synchronization_disable(dmamux_multiplexer_channel_enum channelx)663 void dmamux_synchronization_disable(dmamux_multiplexer_channel_enum channelx)
664 {
665 DMAMUX_RM_CHXCFG(channelx) &= (~DMAMUX_RM_CHXCFG_SYNCEN);
666 }
667 /*!
668 \brief enable event generation
669 \param[in] channelx: specify which DMAMUX request multiplexer channel is configured
670 only one parameter can be selected which is shown as below:
671 \arg DMAMUX_MUXCHx(x=0..6)
672 \param[out] none
673 \retval none
674 */
dmamux_event_generation_enable(dmamux_multiplexer_channel_enum channelx)675 void dmamux_event_generation_enable(dmamux_multiplexer_channel_enum channelx)
676 {
677 DMAMUX_RM_CHXCFG(channelx) |= DMAMUX_RM_CHXCFG_EVGEN;
678 }
679
680 /*!
681 \brief disable event generation
682 \param[in] channelx: specify which DMAMUX request multiplexer channel is configured
683 only one parameter can be selected which is shown as below:
684 \arg DMAMUX_MUXCHx(x=0..6)
685 \param[out] none
686 \retval none
687 */
dmamux_event_generation_disable(dmamux_multiplexer_channel_enum channelx)688 void dmamux_event_generation_disable(dmamux_multiplexer_channel_enum channelx)
689 {
690 DMAMUX_RM_CHXCFG(channelx) &= (~DMAMUX_RM_CHXCFG_EVGEN);
691 }
692
693 /*!
694 \brief initialize the parameters of DMAMUX request generator structure with the default values
695 \param[in] init_struct: the initialization data needed to initialize DMAMUX request generator channel
696 \param[out] none
697 \retval none
698 */
dmamux_gen_struct_para_init(dmamux_gen_parameter_struct * init_struct)699 void dmamux_gen_struct_para_init(dmamux_gen_parameter_struct *init_struct)
700 {
701 if(NULL == init_struct) {
702 DMA_WRONG_HANDLE
703 }
704
705 /* set the DMAMUX request generator structure with the default values */
706 init_struct->trigger_id = DMAMUX_SYNC_EVT0_OUT;
707 init_struct->trigger_polarity = DMAMUX_SYNC_RISING;
708 init_struct->request_number = 1U;
709 }
710
711 /*!
712 \brief initialize DMAMUX request generator channel
713 \param[in] channelx: specify which DMAMUX request generator channel is initialized
714 only one parameter can be selected which is shown as below:
715 \arg DMAMUX_GENCHx(x=0..3)
716 \param[in] init_struct: the data needed to initialize DMAMUX request generator channel
717 trigger_id: DMAMUX_TRIGGER_EXTI0, DMAMUX_TRIGGER_EXTI1, DMAMUX_TRIGGER_EXTI2, DMAMUX_TRIGGER_EXTI3,
718 DMAMUX_TRIGGER_EXTI4, DMAMUX_TRIGGER_EXTI5, DMAMUX_TRIGGER_EXTI6, DMAMUX_TRIGGER_EXTI7,
719 DMAMUX_TRIGGER_EXTI8, DMAMUX_TRIGGER_EXTI9, DMAMUX_TRIGGER_EXTI10, DMAMUX_TRIGGER_EXTI11,
720 DMAMUX_TRIGGER_EXTI12, DMAMUX_TRIGGER_EXTI13, DMAMUX_TRIGGER_EXTI14, DMAMUX_TRIGGER_EXTI15,
721 DMAMUX_TRIGGER_EVT0_OUT, DMAMUX_TRIGGER_EVT1_OUT, DMAMUX_TRIGGER_EVT2_OUT, DMAMUX_TRIGGER_EVT3_OUT,
722 DMAMUX_TRIGGER_TIMER11_CH0_O
723 trigger_polarity: DMAMUX_GEN_NO_EVENT, DMAMUX_GEN_RISING, DMAMUX_GEN_FALLING, DMAMUX_GEN_RISING_FALLING
724 request_number: the number of DMA request that will be generated after a signal event, from 1 to 32
725 \param[out] none
726 \retval none
727 */
dmamux_request_generator_init(dmamux_generator_channel_enum channelx,dmamux_gen_parameter_struct * init_struct)728 void dmamux_request_generator_init(dmamux_generator_channel_enum channelx, dmamux_gen_parameter_struct *init_struct)
729 {
730 uint32_t cfg;
731
732 if(NULL == init_struct) {
733 DMA_WRONG_HANDLE
734 }
735
736 /* disable DMAMUX request generator channel for DMA request generation number configuration */
737 DMAMUX_RG_CHXCFG(channelx) &= ~(DMAMUX_RG_CHXCFG_RGEN);
738
739 /* configure trigger input identification, trigger polarity, number of DMA requests to be generated */
740 cfg = DMAMUX_RG_CHXCFG(channelx);
741 cfg &= ~(DMAMUX_RG_CHXCFG_TID | DMAMUX_RG_CHXCFG_NBRG | DMAMUX_RG_CHXCFG_RGTP);
742 cfg |= (RG_CHXCFG_NBRG(init_struct->request_number - 1U) | init_struct->trigger_id | init_struct->trigger_polarity);
743 DMAMUX_RG_CHXCFG(channelx) = cfg;
744 }
745
746 /*!
747 \brief enable DMAMUX request generator channel
748 \param[in] channelx: specify which DMAMUX request generator channel is configured
749 only one parameter can be selected which is shown as below:
750 \arg DMAMUX_GENCHx(x=0..3)
751 \param[out] none
752 \retval none
753 */
dmamux_request_generator_chennel_enable(dmamux_generator_channel_enum channelx)754 void dmamux_request_generator_chennel_enable(dmamux_generator_channel_enum channelx)
755 {
756 DMAMUX_RG_CHXCFG(channelx) |= DMAMUX_RG_CHXCFG_RGEN;
757 }
758
759 /*!
760 \brief disable DMAMUX request generator channel
761 \param[in] channelx: specify which DMAMUX request generator channel is configured
762 only one parameter can be selected which is shown as below:
763 \arg DMAMUX_GENCHx(x=0..3)
764 \param[out] none
765 \retval none
766 */
dmamux_request_generator_chennel_disable(dmamux_generator_channel_enum channelx)767 void dmamux_request_generator_chennel_disable(dmamux_generator_channel_enum channelx)
768 {
769 DMAMUX_RG_CHXCFG(channelx) &= (~DMAMUX_RG_CHXCFG_RGEN);
770 }
771
772 /*!
773 \brief configure synchronization input polarity
774 \param[in] channelx: specify which DMAMUX request multiplexer channel is configured
775 only one parameter can be selected which is shown as below:
776 \arg DMAMUX_MUXCHx(x=0..6)
777 \param[in] polarity: synchronization input polarity
778 only one parameter can be selected which is shown as below:
779 \arg DMAMUX_SYNC_NO_EVENT: no event detection
780 \arg DMAMUX_SYNC_RISING: rising edge
781 \arg DMAMUX_SYNC_FALLING: falling edge
782 \arg DMAMUX_SYNC_RISING_FALLING: rising and falling edges
783 \param[out] none
784 \retval none
785 */
dmamux_synchronization_polarity_config(dmamux_multiplexer_channel_enum channelx,uint32_t polarity)786 void dmamux_synchronization_polarity_config(dmamux_multiplexer_channel_enum channelx, uint32_t polarity)
787 {
788 DMAMUX_RM_CHXCFG(channelx) &= ~DMAMUX_RM_CHXCFG_SYNCP;
789 DMAMUX_RM_CHXCFG(channelx) |= polarity;
790 }
791
792 /*!
793 \brief configure number of DMA requests to forward
794 \param[in] channelx: specify which DMAMUX request multiplexer channel is configured
795 only one parameter can be selected which is shown as below:
796 \arg DMAMUX_MUXCHx(x=0..6)
797 \param[in] number: DMA requests number to forward
798 only one parameter can be selected which is shown as below:
799 \arg 1 - 32
800 \param[out] none
801 \retval none
802 */
dmamux_request_forward_number_config(dmamux_multiplexer_channel_enum channelx,uint32_t number)803 void dmamux_request_forward_number_config(dmamux_multiplexer_channel_enum channelx, uint32_t number)
804 {
805 DMAMUX_RM_CHXCFG(channelx) &= ~DMAMUX_RM_CHXCFG_NBR;
806 DMAMUX_RM_CHXCFG(channelx) |= (number - 1U);
807 }
808
809 /*!
810 \brief configure synchronization input identification
811 \param[in] channelx: specify which DMAMUX request multiplexer channel is configured
812 only one parameter can be selected which is shown as below:
813 \arg DMAMUX_MUXCHx(x=0..6)
814 \param[in] id: synchronization input identification
815 only one parameter can be selected which is shown as below:
816 \arg DMAMUX_SYNC_EXTI0: synchronization input is EXTI0
817 \arg DMAMUX_SYNC_EXTI1: synchronization input is EXTI1
818 \arg DMAMUX_SYNC_EXTI2: synchronization input is EXTI2
819 \arg DMAMUX_SYNC_EXTI3: synchronization input is EXTI3
820 \arg DMAMUX_SYNC_EXTI4: synchronization input is EXTI4
821 \arg DMAMUX_SYNC_EXTI5: synchronization input is EXTI5
822 \arg DMAMUX_SYNC_EXTI6: synchronization input is EXTI6
823 \arg DMAMUX_SYNC_EXTI7: synchronization input is EXTI7
824 \arg DMAMUX_SYNC_EXTI8: synchronization input is EXTI8
825 \arg DMAMUX_SYNC_EXTI9: synchronization input is EXTI9
826 \arg DMAMUX_SYNC_EXTI10: synchronization input is EXTI10
827 \arg DMAMUX_SYNC_EXTI11: synchronization input is EXTI11
828 \arg DMAMUX_SYNC_EXTI12: synchronization input is EXTI12
829 \arg DMAMUX_SYNC_EXTI13: synchronization input is EXTI13
830 \arg DMAMUX_SYNC_EXTI14: synchronization input is EXTI14
831 \arg DMAMUX_SYNC_EXTI15: synchronization input is EXTI15
832 \arg DMAMUX_SYNC_EVT0_OUT: synchronization input is Evt0_out
833 \arg DMAMUX_SYNC_EVT1_OUT: synchronization input is Evt1_out
834 \arg DMAMUX_SYNC_EVT2_OUT: synchronization input is Evt2_out
835 \arg DMAMUX_SYNC_EVT3_OUT: synchronization input is Evt3_out
836 \arg DMAMUX_SYNC_TIMER11_CH0_O: synchronization input is TIMER11_CH0_O
837 \param[out] none
838 \retval none
839 */
dmamux_sync_id_config(dmamux_multiplexer_channel_enum channelx,uint32_t id)840 void dmamux_sync_id_config(dmamux_multiplexer_channel_enum channelx, uint32_t id)
841 {
842 DMAMUX_RM_CHXCFG(channelx) &= ~DMAMUX_RM_CHXCFG_SYNCID;
843 DMAMUX_RM_CHXCFG(channelx) |= id;
844 }
845
846 /*!
847 \brief configure multiplexer input identification
848 \param[in] channelx: specify which DMAMUX request multiplexer channel is configured
849 only one parameter can be selected which is shown as below:
850 \arg DMAMUX_MUXCHx(x=0..6)
851 \param[in] id: input DMA request identification
852 only one parameter can be selected which is shown as below:
853 \arg DMA_REQUEST_M2M: memory to memory transfer
854 \arg DMA_REQUEST_GENERATOR0: DMAMUX request generator 0
855 \arg DMA_REQUEST_GENERATOR1: DMAMUX request generator 1
856 \arg DMA_REQUEST_GENERATOR2: DMAMUX request generator 2
857 \arg DMA_REQUEST_GENERATOR3: DMAMUX request generator 3
858 \arg DMA_REQUEST_ADC: DMAMUX ADC request
859 \arg DMA_REQUEST_DAC: DMAMUX DAC request
860 \arg DMA_REQUEST_I2C0_RX: DMAMUX I2C0 RX request
861 \arg DMA_REQUEST_I2C0_TX: DMAMUX I2C0 TX request
862 \arg DMA_REQUEST_I2C1_RX: DMAMUX I2C1 RX request
863 \arg DMA_REQUEST_I2C1_TX: DMAMUX I2C1 TX request
864 \arg DMA_REQUEST_I2C2_RX: DMAMUX I2C2 RX request
865 \arg DMA_REQUEST_I2C2_TX: DMAMUX I2C2 TX request
866 \arg DMA_REQUEST_SPI0_RX: DMAMUX SPI0 RX request
867 \arg DMA_REQUEST_SPI0_TX: DMAMUX SPI0 TX request
868 \arg DMA_REQUEST_SPI1_RX: DMAMUX SPI1 RX request
869 \arg DMA_REQUEST_SPI1_TX: DMAMUX SPI1 TX request
870 \arg DMA_REQUEST_TIMER1_CH0: DMAMUX TIMER1 CH0 request
871 \arg DMA_REQUEST_TIMER1_CH1: DMAMUX TIMER1 CH1 request
872 \arg DMA_REQUEST_TIMER1_CH2: DMAMUX TIMER1 CH2 request
873 \arg DMA_REQUEST_TIMER1_CH3: DMAMUX TIMER1 CH3 request
874 \arg DMA_REQUEST_TIMER1_UP: DMAMUX TIMER1 UP request
875 \arg DMA_REQUEST_TIMER2_CH0: DMAMUX TIMER2 CH0 request
876 \arg DMA_REQUEST_TIMER2_CH1: DMAMUX TIMER2 CH1 request
877 \arg DMA_REQUEST_TIMER2_CH2: DMAMUX TIMER2 CH2 request
878 \arg DMA_REQUEST_TIMER2_CH3: DMAMUX TIMER2 CH3 request
879 \arg DMA_REQUEST_TIMER2_TRIG: DMAMUX TIMER2 TRIG request
880 \arg DMA_REQUEST_TIMER2_UP: DMAMUX TIMER2 UP request
881 \arg DMA_REQUEST_TIMER5_UP: DMAMUX TIMER5 UP request
882 \arg DMA_REQUEST_TIMER6_UP: DMAMUX TIMER6 UP request
883 \arg DMA_REQUEST_CAU_IN: DMAMUX CAU IN request
884 \arg DMA_REQUEST_CAU_OUT: DMAMUX CAU OUT request
885 \arg DMA_REQUEST_USART0_RX: DMAMUX USART0 RX request
886 \arg DMA_REQUEST_USART0_TX: DMAMUX USART0 TX request
887 \arg DMA_REQUEST_USART1_RX: DMAMUX USART1 RX request
888 \arg DMA_REQUEST_USART1_TX: DMAMUX USART1 TX request
889 \arg DMA_REQUEST_UART3_RX: DMAMUX UART3 RX request
890 \arg DMA_REQUEST_UART3_TX: DMAMUX UART3 TX request
891 \arg DMA_REQUEST_UART4_RX: DMAMUX UART4 RX request
892 \arg DMA_REQUEST_UART4_TX: DMAMUX UART4 TX request
893 \arg DMA_REQUEST_LPUART_RX: DMAMUX LPUART RX request
894 \arg DMA_REQUEST_LPUART_TX: DMAMUX LPUART TX request
895 \param[out] none
896 \retval none
897 */
dmamux_request_id_config(dmamux_multiplexer_channel_enum channelx,uint32_t id)898 void dmamux_request_id_config(dmamux_multiplexer_channel_enum channelx, uint32_t id)
899 {
900 DMAMUX_RM_CHXCFG(channelx) &= ~DMAMUX_RM_CHXCFG_MUXID;
901 DMAMUX_RM_CHXCFG(channelx) |= id;
902 }
903
904 /*!
905 \brief configure trigger input polarity
906 \param[in] channelx: specify which DMAMUX request generator channel is configured
907 only one parameter can be selected which is shown as below:
908 \arg DMAMUX_GENCHx(x=0..3)
909 \param[in] polarity: trigger input polarity
910 only one parameter can be selected which is shown as below:
911 \arg DMAMUX_GEN_NO_EVENT: no event detection
912 \arg DMAMUX_GEN_RISING: rising edge
913 \arg DMAMUX_GEN_FALLING: falling edge
914 \arg DMAMUX_GEN_RISING_FALLING: rising and falling edges
915 \param[out] none
916 \retval none
917 */
dmamux_trigger_polarity_config(dmamux_generator_channel_enum channelx,uint32_t polarity)918 void dmamux_trigger_polarity_config(dmamux_generator_channel_enum channelx, uint32_t polarity)
919 {
920 DMAMUX_RG_CHXCFG(channelx) &= ~DMAMUX_RG_CHXCFG_RGTP;
921 DMAMUX_RG_CHXCFG(channelx) |= polarity;
922 }
923
924 /*!
925 \brief configure number of DMA requests to be generated
926 \param[in] channelx: specify which DMAMUX request generator channel is configured
927 only one parameter can be selected which is shown as below:
928 \arg DMAMUX_GENCHx(x=0..3)
929 \param[in] number: DMA requests number to be generated
930 only one parameter can be selected which is shown as below:
931 \arg 1 - 32
932 \param[out] none
933 \retval none
934 */
dmamux_request_generate_number_config(dmamux_generator_channel_enum channelx,uint32_t number)935 void dmamux_request_generate_number_config(dmamux_generator_channel_enum channelx, uint32_t number)
936 {
937 DMAMUX_RG_CHXCFG(channelx) &= ~DMAMUX_RG_CHXCFG_NBRG;
938 DMAMUX_RG_CHXCFG(channelx) |= (number - 1U);
939 }
940
941 /*!
942 \brief configure trigger input identification
943 \param[in] channelx: specify which DMAMUX request generator channel is configured
944 only one parameter can be selected which is shown as below:
945 \arg DMAMUX_GENCHx(x=0..3)
946 \param[in] id: trigger input identification
947 only one parameter can be selected which is shown as below:
948 \arg DMAMUX_TRIGGER_EXTI0: trigger input is EXTI0
949 \arg DMAMUX_TRIGGER_EXTI1: trigger input is EXTI1
950 \arg DMAMUX_TRIGGER_EXTI2: trigger input is EXTI2
951 \arg DMAMUX_TRIGGER_EXTI3: trigger input is EXTI3
952 \arg DMAMUX_TRIGGER_EXTI4: trigger input is EXTI4
953 \arg DMAMUX_TRIGGER_EXTI5: trigger input is EXTI5
954 \arg DMAMUX_TRIGGER_EXTI6: trigger input is EXTI6
955 \arg DMAMUX_TRIGGER_EXTI7: trigger input is EXTI7
956 \arg DMAMUX_TRIGGER_EXTI8: trigger input is EXTI8
957 \arg DMAMUX_TRIGGER_EXTI9: trigger input is EXTI9
958 \arg DMAMUX_TRIGGER_EXTI10: trigger input is EXTI10
959 \arg DMAMUX_TRIGGER_EXTI11: trigger input is EXTI11
960 \arg DMAMUX_TRIGGER_EXTI12: trigger input is EXTI12
961 \arg DMAMUX_TRIGGER_EXTI13: trigger input is EXTI13
962 \arg DMAMUX_TRIGGER_EXTI14: trigger input is EXTI14
963 \arg DMAMUX_TRIGGER_EXTI15: trigger input is EXTI15
964 \arg DMAMUX_TRIGGER_EVT0_OUT: trigger input is Evt0_out
965 \arg DMAMUX_TRIGGER_EVT1_OUT: trigger input is Evt1_out
966 \arg DMAMUX_TRIGGER_EVT2_OUT: trigger input is Evt2_out
967 \arg DMAMUX_TRIGGER_EVT3_OUT: trigger input is Evt3_out
968 \arg DMAMUX_TRIGGER_TIMER11_CH0_O: trigger input is TIMER11_CH0_O
969 \param[out] none
970 \retval none
971 */
dmamux_trigger_id_config(dmamux_generator_channel_enum channelx,uint32_t id)972 void dmamux_trigger_id_config(dmamux_generator_channel_enum channelx, uint32_t id)
973 {
974 DMAMUX_RG_CHXCFG(channelx) &= ~DMAMUX_RG_CHXCFG_TID;
975 DMAMUX_RG_CHXCFG(channelx) |= id;
976 }
977
978 /*!
979 \brief get DMAMUX flag
980 \param[in] flag: flag type
981 only one parameter can be selected which is shown as below:
982 \arg DMAMUX_FLAG_MUXCH0_SO: DMAMUX request multiplexer channel 0 synchronization overrun flag
983 \arg DMAMUX_FLAG_MUXCH1_SO: DMAMUX request multiplexer channel 1 synchronization overrun flag
984 \arg DMAMUX_FLAG_MUXCH2_SO: DMAMUX request multiplexer channel 2 synchronization overrun flag
985 \arg DMAMUX_FLAG_MUXCH3_SO: DMAMUX request multiplexer channel 3 synchronization overrun flag
986 \arg DMAMUX_FLAG_MUXCH4_SO: DMAMUX request multiplexer channel 4 synchronization overrun flag
987 \arg DMAMUX_FLAG_MUXCH5_SO: DMAMUX request multiplexer channel 5 synchronization overrun flag
988 \arg DMAMUX_FLAG_MUXCH6_SO: DMAMUX request multiplexer channel 6 synchronization overrun flag
989 \arg DMAMUX_FLAG_GENCH0_TO: DMAMUX request generator channel 0 trigger overrun flag
990 \arg DMAMUX_FLAG_GENCH1_TO: DMAMUX request generator channel 1 trigger overrun flag
991 \arg DMAMUX_FLAG_GENCH2_TO: DMAMUX request generator channel 2 trigger overrun flag
992 \arg DMAMUX_FLAG_GENCH3_TO: DMAMUX request generator channel 3 trigger overrun flag
993 \param[out] none
994 \retval FlagStatus: SET or RESET
995 */
dmamux_flag_get(dmamux_flag_enum flag)996 FlagStatus dmamux_flag_get(dmamux_flag_enum flag)
997 {
998 FlagStatus reval;
999
1000 if(RESET != (DMAMUX_REG_VAL(flag) & BIT(DMAMUX_BIT_POS(flag)))) {
1001 reval = SET;
1002 } else {
1003 reval = RESET;
1004 }
1005
1006 return reval;
1007 }
1008
1009 /*!
1010 \brief clear DMAMUX flag
1011 \param[in] flag: flag type
1012 only one parameter can be selected which is shown as below:
1013 \arg DMAMUX_FLAG_MUXCH0_SO: DMAMUX request multiplexer channel 0 synchronization overrun flag
1014 \arg DMAMUX_FLAG_MUXCH1_SO: DMAMUX request multiplexer channel 1 synchronization overrun flag
1015 \arg DMAMUX_FLAG_MUXCH2_SO: DMAMUX request multiplexer channel 2 synchronization overrun flag
1016 \arg DMAMUX_FLAG_MUXCH3_SO: DMAMUX request multiplexer channel 3 synchronization overrun flag
1017 \arg DMAMUX_FLAG_MUXCH4_SO: DMAMUX request multiplexer channel 4 synchronization overrun flag
1018 \arg DMAMUX_FLAG_MUXCH5_SO: DMAMUX request multiplexer channel 5 synchronization overrun flag
1019 \arg DMAMUX_FLAG_MUXCH6_SO: DMAMUX request multiplexer channel 6 synchronization overrun flag
1020 \arg DMAMUX_FLAG_GENCH0_TO: DMAMUX request generator channel 0 trigger overrun flag
1021 \arg DMAMUX_FLAG_GENCH1_TO: DMAMUX request generator channel 1 trigger overrun flag
1022 \arg DMAMUX_FLAG_GENCH2_TO: DMAMUX request generator channel 2 trigger overrun flag
1023 \arg DMAMUX_FLAG_GENCH3_TO: DMAMUX request generator channel 3 trigger overrun flag
1024 \param[out] none
1025 \retval none
1026 */
dmamux_flag_clear(dmamux_flag_enum flag)1027 void dmamux_flag_clear(dmamux_flag_enum flag)
1028 {
1029 DMAMUX_REG_VAL3(flag) = BIT(DMAMUX_BIT_POS(flag));
1030 }
1031
1032 /*!
1033 \brief get DMAMUX interrupt flag
1034 \param[in] int_flag: flag type
1035 only one parameter can be selected which is shown as below:
1036 \arg DMAMUX_INT_FLAG_MUXCH0_SO: DMAMUX request multiplexer channel 0 synchronization overrun interrupt flag
1037 \arg DMAMUX_INT_FLAG_MUXCH1_SO: DMAMUX request multiplexer channel 1 synchronization overrun interrupt flag
1038 \arg DMAMUX_INT_FLAG_MUXCH2_SO: DMAMUX request multiplexer channel 2 synchronization overrun interrupt flag
1039 \arg DMAMUX_INT_FLAG_MUXCH3_SO: DMAMUX request multiplexer channel 3 synchronization overrun interrupt flag
1040 \arg DMAMUX_INT_FLAG_MUXCH4_SO: DMAMUX request multiplexer channel 4 synchronization overrun interrupt flag
1041 \arg DMAMUX_INT_FLAG_MUXCH5_SO: DMAMUX request multiplexer channel 5 synchronization overrun interrupt flag
1042 \arg DMAMUX_INT_FLAG_MUXCH6_SO: DMAMUX request multiplexer channel 6 synchronization overrun interrupt flag
1043 \arg DMAMUX_INT_FLAG_GENCH0_TO: DMAMUX request generator channel 0 trigger overrun interrupt flag
1044 \arg DMAMUX_INT_FLAG_GENCH1_TO: DMAMUX request generator channel 1 trigger overrun interrupt flag
1045 \arg DMAMUX_INT_FLAG_GENCH2_TO: DMAMUX request generator channel 2 trigger overrun interrupt flag
1046 \arg DMAMUX_INT_FLAG_GENCH3_TO: DMAMUX request generator channel 3 trigger overrun interrupt flag
1047 \param[out] none
1048 \retval FlagStatus: SET or RESET
1049 */
dmamux_interrupt_flag_get(dmamux_interrupt_flag_enum int_flag)1050 FlagStatus dmamux_interrupt_flag_get(dmamux_interrupt_flag_enum int_flag)
1051 {
1052 FlagStatus reval;
1053 uint32_t intenable = 0U, flagstatus = 0U;
1054
1055 /* get the interrupt enable bit status */
1056 intenable = (DMAMUX_REG_VAL2(int_flag) & BIT(DMAMUX_BIT_POS2(int_flag)));
1057 /* get the corresponding flag bit status */
1058 flagstatus = (DMAMUX_REG_VAL(int_flag) & BIT(DMAMUX_BIT_POS(int_flag)));
1059
1060 if(flagstatus && intenable) {
1061 reval = SET;
1062 } else {
1063 reval = RESET;
1064 }
1065
1066 return reval;
1067 }
1068
1069 /*!
1070 \brief clear DMAMUX interrupt flag
1071 \param[in] int_flag: flag type
1072 only one parameter can be selected which is shown as below:
1073 \arg DMAMUX_INT_FLAG_MUXCH0_SO: DMAMUX request multiplexer channel 0 synchronization overrun interrupt flag
1074 \arg DMAMUX_INT_FLAG_MUXCH1_SO: DMAMUX request multiplexer channel 1 synchronization overrun interrupt flag
1075 \arg DMAMUX_INT_FLAG_MUXCH2_SO: DMAMUX request multiplexer channel 2 synchronization overrun interrupt flag
1076 \arg DMAMUX_INT_FLAG_MUXCH3_SO: DMAMUX request multiplexer channel 3 synchronization overrun interrupt flag
1077 \arg DMAMUX_INT_FLAG_MUXCH4_SO: DMAMUX request multiplexer channel 4 synchronization overrun interrupt flag
1078 \arg DMAMUX_INT_FLAG_MUXCH5_SO: DMAMUX request multiplexer channel 5 synchronization overrun interrupt flag
1079 \arg DMAMUX_INT_FLAG_MUXCH6_SO: DMAMUX request multiplexer channel 6 synchronization overrun interrupt flag
1080 \arg DMAMUX_INT_FLAG_GENCH0_TO: DMAMUX request generator channel 0 trigger overrun interrupt flag
1081 \arg DMAMUX_INT_FLAG_GENCH1_TO: DMAMUX request generator channel 1 trigger overrun interrupt flag
1082 \arg DMAMUX_INT_FLAG_GENCH2_TO: DMAMUX request generator channel 2 trigger overrun interrupt flag
1083 \arg DMAMUX_INT_FLAG_GENCH3_TO: DMAMUX request generator channel 3 trigger overrun interrupt flag
1084 \param[out] none
1085 \retval none
1086 */
dmamux_interrupt_flag_clear(dmamux_interrupt_flag_enum int_flag)1087 void dmamux_interrupt_flag_clear(dmamux_interrupt_flag_enum int_flag)
1088 {
1089 DMAMUX_REG_VAL3(int_flag) = BIT(DMAMUX_BIT_POS(int_flag));
1090 }
1091
1092 /*!
1093 \brief enable DMAMUX interrupt
1094 \param[in] interrupt: specify which interrupt to enable
1095 only one parameter can be selected which is shown as below:
1096 \arg DMAMUX_INT_MUXCH0_SO: DMAMUX request multiplexer channel 0 synchronization overrun interrupt
1097 \arg DMAMUX_INT_MUXCH1_SO: DMAMUX request multiplexer channel 1 synchronization overrun interrupt
1098 \arg DMAMUX_INT_MUXCH2_SO: DMAMUX request multiplexer channel 2 synchronization overrun interrupt
1099 \arg DMAMUX_INT_MUXCH3_SO: DMAMUX request multiplexer channel 3 synchronization overrun interrupt
1100 \arg DMAMUX_INT_MUXCH4_SO: DMAMUX request multiplexer channel 4 synchronization overrun interrupt
1101 \arg DMAMUX_INT_MUXCH5_SO: DMAMUX request multiplexer channel 5 synchronization overrun interrupt
1102 \arg DMAMUX_INT_MUXCH6_SO: DMAMUX request multiplexer channel 6 synchronization overrun interrupt
1103 \arg DMAMUX_INT_GENCH0_TO: DMAMUX request generator channel 0 trigger overrun interrupt
1104 \arg DMAMUX_INT_GENCH1_TO: DMAMUX request generator channel 1 trigger overrun interrupt
1105 \arg DMAMUX_INT_GENCH2_TO: DMAMUX request generator channel 2 trigger overrun interrupt
1106 \arg DMAMUX_INT_GENCH3_TO: DMAMUX request generator channel 3 trigger overrun interrupt
1107 \param[out] none
1108 \retval none
1109 */
dmamux_interrupt_enable(dmamux_interrupt_enum interrupt)1110 void dmamux_interrupt_enable(dmamux_interrupt_enum interrupt)
1111 {
1112 DMAMUX_REG_VAL(interrupt) |= BIT(DMAMUX_BIT_POS(interrupt));
1113 }
1114
1115 /*!
1116 \brief disable DMAMUX interrupt
1117 \param[in] interrupt: specify which interrupt to disable
1118 only one parameter can be selected which is shown as below:
1119 \arg DMAMUX_INT_MUXCH0_SO: DMAMUX request multiplexer channel 0 synchronization overrun interrupt
1120 \arg DMAMUX_INT_MUXCH1_SO: DMAMUX request multiplexer channel 1 synchronization overrun interrupt
1121 \arg DMAMUX_INT_MUXCH2_SO: DMAMUX request multiplexer channel 2 synchronization overrun interrupt
1122 \arg DMAMUX_INT_MUXCH3_SO: DMAMUX request multiplexer channel 3 synchronization overrun interrupt
1123 \arg DMAMUX_INT_MUXCH4_SO: DMAMUX request multiplexer channel 4 synchronization overrun interrupt
1124 \arg DMAMUX_INT_MUXCH5_SO: DMAMUX request multiplexer channel 5 synchronization overrun interrupt
1125 \arg DMAMUX_INT_MUXCH6_SO: DMAMUX request multiplexer channel 6 synchronization overrun interrupt
1126 \arg DMAMUX_INT_GENCH0_TO: DMAMUX request generator channel 0 trigger overrun interrupt
1127 \arg DMAMUX_INT_GENCH1_TO: DMAMUX request generator channel 1 trigger overrun interrupt
1128 \arg DMAMUX_INT_GENCH2_TO: DMAMUX request generator channel 2 trigger overrun interrupt
1129 \arg DMAMUX_INT_GENCH3_TO: DMAMUX request generator channel 3 trigger overrun interrupt
1130 \param[out] none
1131 \retval none
1132 */
dmamux_interrupt_disable(dmamux_interrupt_enum interrupt)1133 void dmamux_interrupt_disable(dmamux_interrupt_enum interrupt)
1134 {
1135 DMAMUX_REG_VAL(interrupt) &= ~BIT(DMAMUX_BIT_POS(interrupt));
1136 }
1137