]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_M4F_MSP432_LaunchPad_IAR_CCS_Keil/driverlib/dma.c
Final V8.2.1 release ready for tagging:
[freertos] / FreeRTOS / Demo / CORTEX_M4F_MSP432_LaunchPad_IAR_CCS_Keil / driverlib / dma.c
1 /*
2  * -------------------------------------------
3  *    MSP432 DriverLib - v01_04_00_18 
4  * -------------------------------------------
5  *
6  * --COPYRIGHT--,BSD,BSD
7  * Copyright (c) 2015, Texas Instruments Incorporated
8  * All rights reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  *
14  * *  Redistributions of source code must retain the above copyright
15  *    notice, this list of conditions and the following disclaimer.
16  *
17  * *  Redistributions in binary form must reproduce the above copyright
18  *    notice, this list of conditions and the following disclaimer in the
19  *    documentation and/or other materials provided with the distribution.
20  *
21  * *  Neither the name of Texas Instruments Incorporated nor the names of
22  *    its contributors may be used to endorse or promote products derived
23  *    from this software without 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,
27  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
29  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
32  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
33  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
34  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
35  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36  * --/COPYRIGHT--*/
37 #include <stdint.h>
38
39 #include <debug.h>
40 #include <interrupt.h>
41 #include <dma.h>
42
43 void DMA_enableModule(void)
44 {
45     //
46     // Set the master enable bit in the config register.
47     //
48     DMA->rCFG.r = DMA_CFG_;
49 }
50
51 void DMA_disableModule(void)
52 {
53     //
54     // Clear the master enable bit in the config register.
55     //
56     DMA->rCFG.r = 0;
57 }
58
59 uint32_t DMA_getErrorStatus(void)
60 {
61     //
62     // Return the DMA error status.
63     //
64     return DMA->rERRCLR.r;
65 }
66
67 void DMA_clearErrorStatus(void)
68 {
69     //
70     // Clear the DMA error interrupt.
71     //
72     DMA->rERRCLR.r = 1;
73 }
74
75 void DMA_enableChannel(uint32_t channelNum)
76 {
77     //
78     // Check the arguments.
79     //
80     ASSERT((channelNum & 0xffff) < 8);
81
82     //
83     // Set the bit for this channel in the enable set register.
84     //
85     DMA->rENASET = 1 << (channelNum & 0x0F);
86 }
87
88 void DMA_disableChannel(uint32_t channelNum)
89 {
90     //
91     // Check the arguments.
92     //
93     ASSERT((channelNum & 0xffff) < 8);
94
95     //
96     // Set the bit for this channel in the enable clear register.
97     //
98     DMA->rENACLR = 1 << (channelNum & 0x0F);
99 }
100
101 bool DMA_isChannelEnabled(uint32_t channelNum)
102 {
103     //
104     // Check the arguments.
105     //
106     ASSERT((channelNum & 0xffff) < 8);
107
108     //
109     // AND the specified channel bit with the enable register and return the
110     // result.
111     //
112     return ((DMA->rENASET & (1 << (channelNum & 0x0F))) ? true : false);
113 }
114
115 void DMA_setControlBase(void *controlTable)
116 {
117     //
118     // Check the arguments.
119     //
120     ASSERT(((uint32_t) controlTable & ~0x3FF) == (uint32_t) controlTable);
121     ASSERT((uint32_t) controlTable >= 0x20000000);
122
123     //
124     // Program the base address into the register.
125     //
126     DMA->rCTLBASE.r = (uint32_t) controlTable;
127 }
128
129 void* DMA_getControlBase(void)
130 {
131     //
132     // Read the current value of the control base register and return it to
133     // the caller.
134     //
135     return ((void *) DMA->rCTLBASE.r);
136 }
137
138 void* DMA_getControlAlternateBase(void)
139 {
140     //
141     // Read the current value of the control base register and return it to
142     // the caller.
143     //
144     return ((void *) DMA->rATLBASE);
145 }
146
147 void DMA_requestChannel(uint32_t channelNum)
148 {
149     //
150     // Check the arguments.
151     //
152     ASSERT((channelNum & 0xffff) < 8);
153
154     //
155     // Set the bit for this channel in the software DMA request register.
156     //
157     DMA->rSWREQ = 1 << (channelNum & 0x0F);
158 }
159
160 void DMA_enableChannelAttribute(uint32_t channelNum, uint32_t attr)
161 {
162     //
163     // Check the arguments.
164     //
165     ASSERT((channelNum & 0xffff) < 8);
166     ASSERT(
167             (attr
168                     & ~(UDMA_ATTR_USEBURST | UDMA_ATTR_ALTSELECT
169                             | UDMA_ATTR_HIGH_PRIORITY | UDMA_ATTR_REQMASK))
170             == 0);
171
172     //
173     // In case a channel selector macro (like UDMA_CH0_USB0EP1RX) was
174     // passed as the channelNum parameter, extract just the channel number
175     // from this parameter.
176     //
177     channelNum &= 0x0F;
178
179     //
180     // Set the useburst bit for this channel if set in config.
181     //
182     if (attr & UDMA_ATTR_USEBURST)
183     {
184         DMA->rUSEBURSTSET = 1 << channelNum;
185     }
186
187     //
188     // Set the alternate control select bit for this channel,
189     // if set in config.
190     //
191     if (attr & UDMA_ATTR_ALTSELECT)
192     {
193         DMA->rALTSET = 1 << channelNum;
194     }
195
196     //
197     // Set the high priority bit for this channel, if set in config.
198     //
199     if (attr & UDMA_ATTR_HIGH_PRIORITY)
200     {
201         DMA->rPRIOSET = 1 << channelNum;
202     }
203
204     //
205     // Set the request mask bit for this channel, if set in config.
206     //
207     if (attr & UDMA_ATTR_REQMASK)
208     {
209         DMA->rREQMASKSET = 1 << channelNum;
210     }
211 }
212
213 void DMA_disableChannelAttribute(uint32_t channelNum, uint32_t attr)
214 {
215     //
216     // Check the arguments.
217     //
218     ASSERT((channelNum & 0xffff) < 8);
219     ASSERT(
220             (attr
221                     & ~(UDMA_ATTR_USEBURST | UDMA_ATTR_ALTSELECT
222                             | UDMA_ATTR_HIGH_PRIORITY | UDMA_ATTR_REQMASK))
223             == 0);
224
225     //
226     // In case a channel selector macro (like UDMA_CH0_USB0EP1RX) was
227     // passed as the channelNum parameter, extract just the channel number
228     // from this parameter.
229     //
230     channelNum &= 0x0F;
231
232     //
233     // Clear the useburst bit for this channel if set in config.
234     //
235     if (attr & UDMA_ATTR_USEBURST)
236     {
237         DMA->rUSEBURSTCLR = 1 << channelNum;
238     }
239
240     //
241     // Clear the alternate control select bit for this channel, if set in
242     // config.
243     //
244     if (attr & UDMA_ATTR_ALTSELECT)
245     {
246         DMA->rALTCLR = 1 << channelNum;
247     }
248
249     //
250     // Clear the high priority bit for this channel, if set in config.
251     //
252     if (attr & UDMA_ATTR_HIGH_PRIORITY)
253     {
254         DMA->rPRIOCLR = 1 << channelNum;
255     }
256
257     //
258     // Clear the request mask bit for this channel, if set in config.
259     //
260     if (attr & UDMA_ATTR_REQMASK)
261     {
262         DMA->rREQMASKCLR = 1 << channelNum;
263     }
264 }
265
266 uint32_t DMA_getChannelAttribute(uint32_t channelNum)
267 {
268     uint32_t attr = 0;
269
270     //
271     // Check the arguments.
272     //
273     ASSERT((channelNum & 0xffff) < 8);
274
275     //
276     // In case a channel selector macro (like UDMA_CH0_USB0EP1RX) was
277     // passed as the channelNum parameter, extract just the channel number
278     // from this parameter.
279     //
280     channelNum &= 0x0F;
281
282     //
283     // Check to see if useburst bit is set for this channel.
284     //
285     if (DMA->rUSEBURSTSET & (1 << channelNum))
286     {
287         attr |= UDMA_ATTR_USEBURST;
288     }
289
290     //
291     // Check to see if the alternate control bit is set for this channel.
292     //
293     if (DMA->rALTSET & (1 << channelNum))
294     {
295         attr |= UDMA_ATTR_ALTSELECT;
296     }
297
298     //
299     // Check to see if the high priority bit is set for this channel.
300     //
301     if (DMA->rPRIOSET & (1 << channelNum))
302     {
303         attr |= UDMA_ATTR_HIGH_PRIORITY;
304     }
305
306     //
307     // Check to see if the request mask bit is set for this channel.
308     //
309     if (DMA->rREQMASKSET & (1 << channelNum))
310     {
311         attr |= UDMA_ATTR_REQMASK;
312     }
313
314     //
315     // Return the configuration flags.
316     //
317     return (attr);
318 }
319
320 void DMA_setChannelControl(uint32_t channelStructIndex, uint32_t control)
321 {
322     DMA_ControlTable *pCtl;
323
324     //
325     // Check the arguments.
326     //
327     ASSERT((channelStructIndex & 0xffff) < 64);
328     ASSERT(DMA->rCTLBASE != 0);
329
330     //
331     // In case a channel selector macro (like UDMA_CH0_USB0EP1RX) was
332     // passed as the channelStructIndex parameter, extract just the channel
333     // index from this parameter.
334     //
335     channelStructIndex &= 0x3f;
336
337     //
338     // Get the base address of the control table.
339     //
340     pCtl = (DMA_ControlTable *) DMA->rCTLBASE.r;
341
342     //
343     // Get the current control word value and mask off the fields to be
344     // changed, then OR in the new settings.
345     //
346     pCtl[channelStructIndex].control = ((pCtl[channelStructIndex].control
347             & ~(UDMA_CHCTL_DSTINC_M | UDMA_CHCTL_DSTSIZE_M | UDMA_CHCTL_SRCINC_M
348                     | UDMA_CHCTL_SRCSIZE_M | UDMA_CHCTL_ARBSIZE_M
349                     | UDMA_CHCTL_NXTUSEBURST)) | control);
350 }
351
352 void DMA_setChannelTransfer(uint32_t channelStructIndex, uint32_t mode,
353         void *srcAddr, void *dstAddr, uint32_t transferSize)
354 {
355     DMA_ControlTable *controlTable;
356     uint32_t control;
357     uint32_t increment;
358     uint32_t bufferBytes;
359
360     //
361     // Check the arguments.
362     //
363     ASSERT((channelStructIndex & 0xffff) < 64);
364     ASSERT(DMA->rCTLBASE != 0);
365     ASSERT(mode <= UDMA_MODE_PER_SCATTER_GATHER);
366     ASSERT((transferSize != 0) && (transferSize <= 1024));
367
368     //
369     // In case a channel selector macro (like UDMA_CH0_USB0EP1RX) was
370     // passed as the channelStructIndex parameter, extract just the channel
371     // index from this parameter.
372     //
373     channelStructIndex &= 0x3f;
374
375     //
376     // Get the base address of the control table.
377     //
378     controlTable = (DMA_ControlTable *) DMA->rCTLBASE.r;
379
380     //
381     // Get the current control word value and mask off the mode and size
382     // fields.
383     //
384     control = (controlTable[channelStructIndex].control
385             & ~(UDMA_CHCTL_XFERSIZE_M | UDMA_CHCTL_XFERMODE_M));
386
387     //
388     // Adjust the mode if the alt control structure is selected.
389     //
390     if (channelStructIndex & UDMA_ALT_SELECT)
391     {
392         if ((mode == UDMA_MODE_MEM_SCATTER_GATHER)
393                 || (mode == UDMA_MODE_PER_SCATTER_GATHER))
394         {
395             mode |= UDMA_MODE_ALT_SELECT;
396         }
397     }
398
399     //
400     // Set the transfer size and mode in the control word (but don't write the
401     // control word yet as it could kick off a transfer).
402     //
403     control |= mode | ((transferSize - 1) << 4);
404
405     //
406     // Get the address increment value for the source, from the control word.
407     //
408     increment = (control & UDMA_CHCTL_SRCINC_M);
409
410     //
411     // Compute the ending source address of the transfer.  If the source
412     // increment is set to none, then the ending address is the same as the
413     // beginning.
414     //
415     if (increment != UDMA_SRC_INC_NONE)
416     {
417         increment = increment >> 26;
418         bufferBytes = transferSize << increment;
419         srcAddr = (void *) ((uint32_t) srcAddr + bufferBytes - 1);
420     }
421
422     //
423     // Load the source ending address into the control block.
424     //
425     controlTable[channelStructIndex].srcEndAddr = srcAddr;
426
427     //
428     // Get the address increment value for the destination, from the control
429     // word.
430     //
431     increment = control & UDMA_CHCTL_DSTINC_M;
432
433     //
434     // Compute the ending destination address of the transfer.  If the
435     // destination increment is set to none, then the ending address is the
436     // same as the beginning.
437     //
438     if (increment != UDMA_DST_INC_NONE)
439     {
440         //
441         // There is a special case if this is setting up a scatter-gather
442         // transfer.  The destination pointer must point to the end of
443         // the alternate structure for this channel instead of calculating
444         // the end of the buffer in the normal way.
445         //
446         if ((mode == UDMA_MODE_MEM_SCATTER_GATHER)
447                 || (mode == UDMA_MODE_PER_SCATTER_GATHER))
448         {
449             dstAddr = (void *) &controlTable[channelStructIndex
450                     | UDMA_ALT_SELECT].spare;
451         }
452         //
453         // Not a scatter-gather transfer, calculate end pointer normally.
454         //
455         else
456         {
457             increment = increment >> 30;
458             bufferBytes = transferSize << increment;
459             dstAddr = (void *) ((uint32_t) dstAddr + bufferBytes - 1);
460         }
461     }
462
463     //
464     // Load the destination ending address into the control block.
465     //
466     controlTable[channelStructIndex].dstEndAddr = dstAddr;
467
468     //
469     // Write the new control word value.
470     //
471     controlTable[channelStructIndex].control = control;
472 }
473
474 void DMA_setChannelScatterGather(uint32_t channelNum, uint32_t taskCount,
475         void *taskList, uint32_t isPeriphSG)
476 {
477     DMA_ControlTable *controlTable;
478     DMA_ControlTable *pTaskTable;
479
480     //
481     // Check the parameters
482     //
483     ASSERT((channelNum & 0xffff) < 8);
484     ASSERT(DMA->rCTLBASE != 0);
485     ASSERT(taskList != 0);
486     ASSERT(taskCount <= 1024);
487     ASSERT(taskCount != 0);
488
489     //
490     // In case a channel selector macro (like UDMA_CH0_USB0EP1RX) was
491     // passed as the channelNum parameter, extract just the channel number
492     // from this parameter.
493     //
494     channelNum &= 0x0F;
495
496     //
497     // Get the base address of the control table.
498     //
499     controlTable = (DMA_ControlTable *) DMA->rCTLBASE.r;
500
501     //
502     // Get a handy pointer to the task list
503     //
504     pTaskTable = (DMA_ControlTable *) taskList;
505
506     //
507     // Compute the ending address for the source pointer.  This address is the
508     // last element of the last task in the task table
509     //
510     controlTable[channelNum].srcEndAddr = &pTaskTable[taskCount - 1].spare;
511
512     //
513     // Compute the ending address for the destination pointer.  This address
514     // is the end of the alternate structure for this channel.
515     //
516     controlTable[channelNum].dstEndAddr = &controlTable[channelNum
517             | UDMA_ALT_SELECT].spare;
518
519     //
520     // Compute the control word.  Most configurable items are fixed for
521     // scatter-gather.  Item and increment sizes are all 32-bit and arb
522     // size must be 4.  The count is the number of items in the task list
523     // times 4 (4 words per task).
524     //
525     controlTable[channelNum].control = (UDMA_CHCTL_DSTINC_32
526             | UDMA_CHCTL_DSTSIZE_32 | UDMA_CHCTL_SRCINC_32
527             | UDMA_CHCTL_SRCSIZE_32 | UDMA_CHCTL_ARBSIZE_4
528             | (((taskCount * 4) - 1) << UDMA_CHCTL_XFERSIZE_S)
529             | (isPeriphSG ?
530             UDMA_CHCTL_XFERMODE_PER_SG :
531                             UDMA_CHCTL_XFERMODE_MEM_SG));
532
533     //
534     // Scatter-gather operations can leave the alt bit set.  So if doing
535     // back to back scatter-gather transfers, the second attempt may not
536     // work correctly because the alt bit is set.  Therefore, clear the
537     // alt bit here to ensure that it is always cleared before a new SG
538     // transfer is started.
539     //
540     DMA->rALTCLR = 1 << channelNum;
541 }
542
543 uint32_t DMA_getChannelSize(uint32_t channelStructIndex)
544 {
545     DMA_ControlTable *controlTable;
546     uint32_t control;
547
548     //
549     // Check the arguments.
550     //
551     ASSERT((channelStructIndex & 0xffff) < 16);
552     ASSERT(DMA->rCTLBASE != 0);
553
554     //
555     // In case a channel selector macro (like UDMA_CH0_USB0EP1RX) was
556     // passed as the channelStructIndex parameter, extract just the channel
557     // index from this parameter.
558     //
559     channelStructIndex &= 0x3f;
560
561     //
562     // Get the base address of the control table.
563     //
564     controlTable = (DMA_ControlTable *) DMA->rCTLBASE.r;
565
566     //
567     // Get the current control word value and mask off all but the size field
568     // and the mode field.
569     //
570     control = (controlTable[channelStructIndex].control
571             & (UDMA_CHCTL_XFERSIZE_M | UDMA_CHCTL_XFERMODE_M));
572
573     //
574     // If the size field and mode field are 0 then the transfer is finished
575     // and there are no more items to transfer
576     //
577     if (control == 0)
578     {
579         return (0);
580     }
581
582     //
583     // Otherwise, if either the size field or more field is non-zero, then
584     // not all the items have been transferred.
585     //
586     else
587     {
588         //
589         // Shift the size field and add one, then return to user.
590         //
591         return ((control >> 4) + 1);
592     }
593 }
594
595 uint32_t DMA_getChannelMode(uint32_t channelStructIndex)
596 {
597     DMA_ControlTable *controlTable;
598     uint32_t control;
599
600     //
601     // Check the arguments.
602     //
603     ASSERT((channelStructIndex & 0xffff) < 64);
604     ASSERT(DMA->rCTLBASE != 0);
605
606     //
607     // In case a channel selector macro (like UDMA_CH0_USB0EP1RX) was
608     // passed as the channelStructIndex parameter, extract just the channel
609     // index from this parameter.
610     //
611     channelStructIndex &= 0x3f;
612
613     //
614     // Get the base address of the control table.
615     //
616     controlTable = (DMA_ControlTable *) DMA->rCTLBASE.r;
617
618     //
619     // Get the current control word value and mask off all but the mode field.
620     //
621     control =
622             (controlTable[channelStructIndex].control & UDMA_CHCTL_XFERMODE_M);
623
624     //
625     // Check if scatter/gather mode, and if so, mask off the alt bit.
626     //
627     if (((control & ~UDMA_MODE_ALT_SELECT) == UDMA_MODE_MEM_SCATTER_GATHER)
628             || ((control & ~UDMA_MODE_ALT_SELECT)
629                     == UDMA_MODE_PER_SCATTER_GATHER))
630     {
631         control &= ~UDMA_MODE_ALT_SELECT;
632     }
633
634     //
635     // Return the mode to the caller.
636     //
637     return (control);
638 }
639
640 void DMA_assignChannel(uint32_t mapping)
641 {
642     switch (mapping)
643     {
644     case DMA_CH0_RESERVED0:
645     case DMA_CH0_EUSCIA0TX:
646     case DMA_CH0_EUSCIB0TX0:
647     case DMA_CH0_EUSCIB3TX1:
648     case DMA_CH0_EUSCIB2TX2:
649     case DMA_CH0_EUSCIB1TX3:
650     case DMA_CH0_TIMERA0CCR0:
651     case DMA_CH0_AESTRIGGER0:
652         DMA->rCH0_SRCCFG.r = (mapping >> 24) & 0x1F;
653         break;
654     case DMA_CH1_RESERVED0:
655     case DMA_CH1_EUSCIA0RX:
656     case DMA_CH1_EUSCIB0RX0:
657     case DMA_CH1_EUSCIB3RX1:
658     case DMA_CH1_EUSCIB2RX2:
659     case DMA_CH1_EUSCIB1RX3:
660     case DMA_CH1_TIMERA0CCR2:
661     case DMA_CH1_AESTRIGGER1:
662         DMA->rCH1_SRCCFG.r = (mapping >> 24) & 0x1F;
663         break;
664     case DMA_CH2_RESERVED0:
665     case DMA_CH2_EUSCIA1TX:
666     case DMA_CH2_EUSCIB1TX0:
667     case DMA_CH2_EUSCIB0TX1:
668     case DMA_CH2_EUSCIB3TX2:
669     case DMA_CH2_EUSCIB2TX3:
670     case DMA_CH2_TIMERA1CCR0:
671     case DMA_CH2_AESTRIGGER2:
672         DMA->rCH2_SRCCFG.r = (mapping >> 24) & 0x1F;
673         break;
674     case DMA_CH3_RESERVED0:
675     case DMA_CH3_EUSCIA1RX:
676     case DMA_CH3_EUSCIB1RX0:
677     case DMA_CH3_EUSCIB0RX1:
678     case DMA_CH3_EUSCIB3RX2:
679     case DMA_CH3_EUSCIB2RX3:
680     case DMA_CH3_TIMERA1CCR2:
681     case DMA_CH3_RESERVED1:
682         DMA->rCH3_SRCCFG.r = (mapping >> 24) & 0x1F;
683         break;
684     case DMA_CH4_RESERVED0:
685     case DMA_CH4_EUSCIA2TX:
686     case DMA_CH4_EUSCIB2TX0:
687     case DMA_CH4_EUSCIB1TX1:
688     case DMA_CH4_EUSCIB0TX2:
689     case DMA_CH4_EUSCIB3TX3:
690     case DMA_CH4_TIMERA2CCR0:
691     case DMA_CH4_RESERVED1:
692         DMA->rCH4_SRCCFG.r = (mapping >> 24) & 0x1F;
693         break;
694     case DMA_CH5_RESERVED0:
695     case DMA_CH5_EUSCIA2RX:
696     case DMA_CH5_EUSCIB2RX0:
697     case DMA_CH5_EUSCIB1RX1:
698     case DMA_CH5_EUSCIB0RX2:
699     case DMA_CH5_EUSCIB3RX3:
700     case DMA_CH5_TIMERA2CCR2:
701     case DMA_CH5_RESERVED1:
702         DMA->rCH5_SRCCFG.r = (mapping >> 24) & 0x1F;
703         break;
704     case DMA_CH6_RESERVED0:
705     case DMA_CH6_EUSCIA3TX:
706     case DMA_CH6_EUSCIB3TX0:
707     case DMA_CH6_EUSCIB2TX1:
708     case DMA_CH6_EUSCIB1TX2:
709     case DMA_CH6_EUSCIB0TX3:
710     case DMA_CH6_TIMERA3CCR0:
711     case DMA_CH6_EXTERNALPIN:
712         DMA->rCH6_SRCCFG.r = (mapping >> 24) & 0x1F;
713         break;
714     case DMA_CH7_RESERVED0:
715     case DMA_CH7_EUSCIA3RX:
716     case DMA_CH7_EUSCIB3RX0:
717     case DMA_CH7_EUSCIB2RX1:
718     case DMA_CH7_EUSCIB1RX2:
719     case DMA_CH7_EUSCIB0RX3:
720     case DMA_CH7_TIMERA3CCR2:
721     case DMA_CH7_ADC12C:
722         DMA->rCH7_SRCCFG.r = (mapping >> 24) & 0x1F;
723         break;
724     default:
725         ASSERT(false);
726     }
727
728 }
729
730 void DMA_assignInterrupt(uint32_t interruptNumber, uint32_t channel)
731 {
732     ASSERT(
733             interruptNumber == DMA_INT1 || interruptNumber == DMA_INT2
734             || interruptNumber == DMA_INT3);
735
736     if (interruptNumber == DMA_INT1)
737     {
738         DMA->rINT1_SRCCFG.r = (DMA->rINT1_SRCCFG.r & ~DMA_INT1_SRCCFG_INT_SRC_M)
739                 | channel;
740     } else if (interruptNumber == DMA_INT2)
741     {
742         DMA->rINT2_SRCCFG.r = (DMA->rINT2_SRCCFG.r & ~DMA_INT1_SRCCFG_INT_SRC_M)
743                 | channel;
744     } else if (interruptNumber == DMA_INT3)
745     {
746         DMA->rINT3_SRCCFG.r = (DMA->rINT3_SRCCFG.r & ~DMA_INT1_SRCCFG_INT_SRC_M)
747                 | channel;
748     }
749
750     /* Enabling the assigned interrupt */
751     DMA_enableInterrupt(interruptNumber);
752 }
753
754 void DMA_requestSoftwareTransfer(uint32_t channel)
755 {
756     DMA->rSW_CHTRIG.r |= (1 << channel);
757 }
758
759 uint32_t DMA_getInterruptStatus(void)
760 {
761     return DMA->rINT0_SRCFLG.r;
762 }
763
764 void DMA_clearInterruptFlag(uint32_t channel)
765 {
766     DMA->rINT0_CLRFLG.r |= (1 << channel);
767 }
768
769 void DMA_enableInterrupt(uint32_t interruptNumber)
770 {
771     ASSERT(
772             (interruptNumber == DMA_INT0) || (interruptNumber == DMA_INT1)
773             || (interruptNumber == DMA_INT2)
774             || (interruptNumber == DMA_INT3));
775
776     if (interruptNumber == DMA_INT1)
777     {
778         DMA->rINT1_SRCCFG.r |= DMA_INT1_SRCCFG_EN;
779     } else if (interruptNumber == DMA_INT2)
780     {
781         DMA->rINT2_SRCCFG.r |= DMA_INT2_SRCCFG_EN;
782     } else if (interruptNumber == DMA_INT3)
783     {
784         DMA->rINT3_SRCCFG.r |= DMA_INT3_SRCCFG_EN;
785     }
786
787 }
788
789 void DMA_disableInterrupt(uint32_t interruptNumber)
790 {
791     ASSERT(
792             (interruptNumber == DMA_INT0) || (interruptNumber == DMA_INT1)
793             || (interruptNumber == DMA_INT2)
794             || (interruptNumber == DMA_INT3));
795
796     if (interruptNumber == DMA_INT1)
797     {
798         DMA->rINT1_SRCCFG.r &= ~DMA_INT1_SRCCFG_EN;
799     } else if (interruptNumber == DMA_INT2)
800     {
801         DMA->rINT2_SRCCFG.r &= ~DMA_INT2_SRCCFG_EN;
802     } else if (interruptNumber == DMA_INT3)
803     {
804         DMA->rINT3_SRCCFG.r &= ~DMA_INT3_SRCCFG_EN;
805     }
806 }
807
808 void DMA_registerInterrupt(uint32_t interruptNumber, void (*intHandler)(void))
809 {
810     //
811     // Check the arguments.
812     //
813     ASSERT(intHandler);
814     ASSERT(
815             (interruptNumber == DMA_INT0) || (interruptNumber == DMA_INT1)
816             || (interruptNumber == DMA_INT2)
817             || (interruptNumber == DMA_INT3)
818             || (interruptNumber == DMA_INTERR));
819
820     //
821     // Register the interrupt handler.
822     //
823     Interrupt_registerInterrupt(interruptNumber, intHandler);
824
825     //
826     // Enable the memory management fault.
827     //
828     Interrupt_enableInterrupt(interruptNumber);
829
830 }
831
832 void DMA_unregisterInterrupt(uint32_t interruptNumber)
833 {
834     ASSERT(
835             (interruptNumber == DMA_INT0) || (interruptNumber == DMA_INT1)
836             || (interruptNumber == DMA_INT2)
837             || (interruptNumber == DMA_INT3)
838             || (interruptNumber == DMA_INTERR));
839
840     //
841     // Disable the interrupt.
842     //
843     Interrupt_disableInterrupt(interruptNumber);
844
845     //
846     // Unregister the interrupt handler.
847     //
848     Interrupt_unregisterInterrupt(interruptNumber);
849 }
850