1 //*****************************************************************************
2 //
3 // udma.c - Driver for the micro-DMA controller.
4 //
5 // Copyright (c) 2007-2020 Texas Instruments Incorporated.  All rights reserved.
6 // Software License Agreement
7 //
8 //   Redistribution and use in source and binary forms, with or without
9 //   modification, are permitted provided that the following conditions
10 //   are met:
11 //
12 //   Redistributions of source code must retain the above copyright
13 //   notice, this list of conditions and the following disclaimer.
14 //
15 //   Redistributions in binary form must reproduce the above copyright
16 //   notice, this list of conditions and the following disclaimer in the
17 //   documentation and/or other materials provided with the
18 //   distribution.
19 //
20 //   Neither the name of Texas Instruments Incorporated nor the names of
21 //   its contributors may be used to endorse or promote products derived
22 //   from this software without specific prior written permission.
23 //
24 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
27 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
28 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
30 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
32 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
34 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 //
36 // This is part of revision 2.2.0.295 of the Tiva Peripheral Driver Library.
37 //
38 //*****************************************************************************
39 
40 //*****************************************************************************
41 //
42 //! \addtogroup udma_api
43 //! @{
44 //
45 //*****************************************************************************
46 
47 #include <stdbool.h>
48 #include <stdint.h>
49 #include "inc/hw_sysctl.h"
50 #include "inc/hw_types.h"
51 #include "inc/hw_udma.h"
52 #include "driverlib/debug.h"
53 #include "driverlib/interrupt.h"
54 #include "driverlib/udma.h"
55 
56 //*****************************************************************************
57 //
58 //! Enables the uDMA controller for use.
59 //!
60 //! This function enables the uDMA controller.  The uDMA controller must be
61 //! enabled before it can be configured and used.
62 //!
63 //! \return None.
64 //
65 //*****************************************************************************
66 void
uDMAEnable(void)67 uDMAEnable(void)
68 {
69     //
70     // Set the master enable bit in the config register.
71     //
72     HWREG(UDMA_CFG) = UDMA_CFG_MASTEN;
73 }
74 
75 //*****************************************************************************
76 //
77 //! Disables the uDMA controller for use.
78 //!
79 //! This function disables the uDMA controller.  Once disabled, the uDMA
80 //! controller cannot operate until re-enabled with uDMAEnable().
81 //!
82 //! \return None.
83 //
84 //*****************************************************************************
85 void
uDMADisable(void)86 uDMADisable(void)
87 {
88     //
89     // Clear the master enable bit in the config register.
90     //
91     HWREG(UDMA_CFG) = 0;
92 }
93 
94 //*****************************************************************************
95 //
96 //! Gets the uDMA error status.
97 //!
98 //! This function returns the uDMA error status.  It should be called from
99 //! within the uDMA error interrupt handler to determine if a uDMA error
100 //! occurred.
101 //!
102 //! \return Returns non-zero if a uDMA error is pending.
103 //
104 //*****************************************************************************
105 uint32_t
uDMAErrorStatusGet(void)106 uDMAErrorStatusGet(void)
107 {
108     //
109     // Return the uDMA error status.
110     //
111     return(HWREG(UDMA_ERRCLR));
112 }
113 
114 //*****************************************************************************
115 //
116 //! Clears the uDMA error interrupt.
117 //!
118 //! This function clears a pending uDMA error interrupt.  This function should
119 //! be called from within the uDMA error interrupt handler to clear the
120 //! interrupt.
121 //!
122 //! \return None.
123 //
124 //*****************************************************************************
125 void
uDMAErrorStatusClear(void)126 uDMAErrorStatusClear(void)
127 {
128     //
129     // Clear the uDMA error interrupt.
130     //
131     HWREG(UDMA_ERRCLR) = 1;
132 }
133 
134 //*****************************************************************************
135 //
136 //! Enables a uDMA channel for operation.
137 //!
138 //! \param ui32ChannelNum is the channel number to enable.
139 //!
140 //! This function enables a specific uDMA channel for use.  This function must
141 //! be used to enable a channel before it can be used to perform a uDMA
142 //! transfer.
143 //!
144 //! When a uDMA transfer is completed, the channel is automatically disabled by
145 //! the uDMA controller.  Therefore, this function should be called prior to
146 //! starting up any new transfer.
147 //!
148 //! \return None.
149 //
150 //*****************************************************************************
151 void
uDMAChannelEnable(uint32_t ui32ChannelNum)152 uDMAChannelEnable(uint32_t ui32ChannelNum)
153 {
154     //
155     // Check the arguments.
156     //
157     ASSERT((ui32ChannelNum & 0xffff) < 32);
158 
159     //
160     // Set the bit for this channel in the enable set register.
161     //
162     HWREG(UDMA_ENASET) = 1 << (ui32ChannelNum & 0x1f);
163 }
164 
165 //*****************************************************************************
166 //
167 //! Disables a uDMA channel for operation.
168 //!
169 //! \param ui32ChannelNum is the channel number to disable.
170 //!
171 //! This function disables a specific uDMA channel.  Once disabled, a channel
172 //! cannot respond to uDMA transfer requests until re-enabled via
173 //! uDMAChannelEnable().
174 //!
175 //! \return None.
176 //
177 //*****************************************************************************
178 void
uDMAChannelDisable(uint32_t ui32ChannelNum)179 uDMAChannelDisable(uint32_t ui32ChannelNum)
180 {
181     //
182     // Check the arguments.
183     //
184     ASSERT((ui32ChannelNum & 0xffff) < 32);
185 
186     //
187     // Set the bit for this channel in the enable clear register.
188     //
189     HWREG(UDMA_ENACLR) = 1 << (ui32ChannelNum & 0x1f);
190 }
191 
192 //*****************************************************************************
193 //
194 //! Checks if a uDMA channel is enabled for operation.
195 //!
196 //! \param ui32ChannelNum is the channel number to check.
197 //!
198 //! This function checks to see if a specific uDMA channel is enabled.  This
199 //! function can be used to check the status of a transfer, as the channel is
200 //! automatically disabled at the end of a transfer.
201 //!
202 //! \return Returns \b true if the channel is enabled, \b false if disabled.
203 //
204 //*****************************************************************************
205 bool
uDMAChannelIsEnabled(uint32_t ui32ChannelNum)206 uDMAChannelIsEnabled(uint32_t ui32ChannelNum)
207 {
208     //
209     // Check the arguments.
210     //
211     ASSERT((ui32ChannelNum & 0xffff) < 32);
212 
213     //
214     // AND the specified channel bit with the enable register and return the
215     // result.
216     //
217     return((HWREG(UDMA_ENASET) & (1 << (ui32ChannelNum & 0x1f))) ? true :
218            false);
219 }
220 
221 //*****************************************************************************
222 //
223 //! Sets the base address for the channel control table.
224 //!
225 //! \param psControlTable is a pointer to the 1024-byte-aligned base address
226 //! of the uDMA channel control table.
227 //!
228 //! This function configures the base address of the channel control table.
229 //! This table resides in system memory and holds control information for each
230 //! uDMA channel.  The table must be aligned on a 1024-byte boundary.  The base
231 //! address must be configured before any of the channel functions can be used.
232 //!
233 //! The size of the channel control table depends on the number of uDMA
234 //! channels and the transfer modes that are used.  Refer to the introductory
235 //! text and the microcontroller datasheet for more information about the
236 //! channel control table.
237 //!
238 //! \return None.
239 //
240 //*****************************************************************************
241 void
uDMAControlBaseSet(void * psControlTable)242 uDMAControlBaseSet(void *psControlTable)
243 {
244     //
245     // Check the arguments.
246     //
247     ASSERT(((uint32_t)psControlTable & ~0x3FF) ==
248            (uint32_t)psControlTable);
249     ASSERT((uint32_t)psControlTable >= 0x20000000);
250 
251     //
252     // Program the base address into the register.
253     //
254     HWREG(UDMA_CTLBASE) = (uint32_t)psControlTable;
255 }
256 
257 //*****************************************************************************
258 //
259 //! Gets the base address for the channel control table.
260 //!
261 //! This function gets the base address of the channel control table.  This
262 //! table resides in system memory and holds control information for each uDMA
263 //! channel.
264 //!
265 //! \return Returns a pointer to the base address of the channel control table.
266 //
267 //*****************************************************************************
268 void *
uDMAControlBaseGet(void)269 uDMAControlBaseGet(void)
270 {
271     //
272     // Read the current value of the control base register and return it to
273     // the caller.
274     //
275     return((void *)HWREG(UDMA_CTLBASE));
276 }
277 
278 //*****************************************************************************
279 //
280 //! Gets the base address for the channel control table alternate structures.
281 //!
282 //! This function gets the base address of the second half of the channel
283 //! control table that holds the alternate control structures for each channel.
284 //!
285 //! \return Returns a pointer to the base address of the second half of the
286 //! channel control table.
287 //
288 //*****************************************************************************
289 void *
uDMAControlAlternateBaseGet(void)290 uDMAControlAlternateBaseGet(void)
291 {
292     //
293     // Read the current value of the control base register and return it to
294     // the caller.
295     //
296     return((void *)HWREG(UDMA_ALTBASE));
297 }
298 
299 //*****************************************************************************
300 //
301 //! Requests a uDMA channel to start a transfer.
302 //!
303 //! \param ui32ChannelNum is the channel number on which to request a uDMA
304 //! transfer.
305 //!
306 //! This function allows software to request a uDMA channel to begin a
307 //! transfer.  This function could be used for performing a memory-to-memory
308 //! transfer, or if for some reason a transfer needs to be initiated by
309 //! software instead of the peripheral associated with that channel.
310 //!
311 //! \note If the channel is \b UDMA_CHANNEL_SW and interrupts are used, then
312 //! the completion is signaled on the uDMA dedicated interrupt.  If a
313 //! peripheral channel is used, then the completion is signaled on the
314 //! peripheral's interrupt.
315 //!
316 //! \return None.
317 //
318 //*****************************************************************************
319 void
uDMAChannelRequest(uint32_t ui32ChannelNum)320 uDMAChannelRequest(uint32_t ui32ChannelNum)
321 {
322     //
323     // Check the arguments.
324     //
325     ASSERT((ui32ChannelNum & 0xffff) < 32);
326 
327     //
328     // Set the bit for this channel in the software uDMA request register.
329     //
330     HWREG(UDMA_SWREQ) = 1 << (ui32ChannelNum & 0x1f);
331 }
332 
333 //*****************************************************************************
334 //
335 //! Enables attributes of a uDMA channel.
336 //!
337 //! \param ui32ChannelNum is the channel to configure.
338 //! \param ui32Attr is a combination of attributes for the channel.
339 //!
340 //! This function is used to enable attributes of a uDMA channel.
341 //!
342 //! The \e ui32Attr parameter is the logical OR of any of the following:
343 //!
344 //! - \b UDMA_ATTR_USEBURST is used to restrict transfers to use only burst
345 //!   mode.
346 //! - \b UDMA_ATTR_ALTSELECT is used to select the alternate control structure
347 //!   for this channel (it is very unlikely that this flag should be used).
348 //! - \b UDMA_ATTR_HIGH_PRIORITY is used to set this channel to high priority.
349 //! - \b UDMA_ATTR_REQMASK is used to mask the hardware request signal from the
350 //!   peripheral for this channel.
351 //!
352 //! \return None.
353 //
354 //*****************************************************************************
355 void
uDMAChannelAttributeEnable(uint32_t ui32ChannelNum,uint32_t ui32Attr)356 uDMAChannelAttributeEnable(uint32_t ui32ChannelNum, uint32_t ui32Attr)
357 {
358     //
359     // Check the arguments.
360     //
361     ASSERT((ui32ChannelNum & 0xffff) < 32);
362     ASSERT((ui32Attr & ~(UDMA_ATTR_USEBURST | UDMA_ATTR_ALTSELECT |
363                          UDMA_ATTR_HIGH_PRIORITY | UDMA_ATTR_REQMASK)) == 0);
364 
365     //
366     // In case a channel selector macro (like UDMA_CH0_USB0EP1RX) was
367     // passed as the ui32ChannelNum parameter, extract just the channel number
368     // from this parameter.
369     //
370     ui32ChannelNum &= 0x1f;
371 
372     //
373     // Set the useburst bit for this channel if set in ui32Config.
374     //
375     if(ui32Attr & UDMA_ATTR_USEBURST)
376     {
377         HWREG(UDMA_USEBURSTSET) = 1 << ui32ChannelNum;
378     }
379 
380     //
381     // Set the alternate control select bit for this channel,
382     // if set in ui32Config.
383     //
384     if(ui32Attr & UDMA_ATTR_ALTSELECT)
385     {
386         HWREG(UDMA_ALTSET) = 1 << ui32ChannelNum;
387     }
388 
389     //
390     // Set the high priority bit for this channel, if set in ui32Config.
391     //
392     if(ui32Attr & UDMA_ATTR_HIGH_PRIORITY)
393     {
394         HWREG(UDMA_PRIOSET) = 1 << ui32ChannelNum;
395     }
396 
397     //
398     // Set the request mask bit for this channel, if set in ui32Config.
399     //
400     if(ui32Attr & UDMA_ATTR_REQMASK)
401     {
402         HWREG(UDMA_REQMASKSET) = 1 << ui32ChannelNum;
403     }
404 }
405 
406 //*****************************************************************************
407 //
408 //! Disables attributes of a uDMA channel.
409 //!
410 //! \param ui32ChannelNum is the channel to configure.
411 //! \param ui32Attr is a combination of attributes for the channel.
412 //!
413 //! This function is used to disable attributes of a uDMA channel.
414 //!
415 //! The \e ui32Attr parameter is the logical OR of any of the following:
416 //!
417 //! - \b UDMA_ATTR_USEBURST is used to restrict transfers to use only burst
418 //!   mode.
419 //! - \b UDMA_ATTR_ALTSELECT is used to select the alternate control structure
420 //!   for this channel.
421 //! - \b UDMA_ATTR_HIGH_PRIORITY is used to set this channel to high priority.
422 //! - \b UDMA_ATTR_REQMASK is used to mask the hardware request signal from the
423 //!   peripheral for this channel.
424 //!
425 //! \return None.
426 //
427 //*****************************************************************************
428 void
uDMAChannelAttributeDisable(uint32_t ui32ChannelNum,uint32_t ui32Attr)429 uDMAChannelAttributeDisable(uint32_t ui32ChannelNum, uint32_t ui32Attr)
430 {
431     //
432     // Check the arguments.
433     //
434     ASSERT((ui32ChannelNum & 0xffff) < 32);
435     ASSERT((ui32Attr & ~(UDMA_ATTR_USEBURST | UDMA_ATTR_ALTSELECT |
436                          UDMA_ATTR_HIGH_PRIORITY | UDMA_ATTR_REQMASK)) == 0);
437 
438     //
439     // In case a channel selector macro (like UDMA_CH0_USB0EP1RX) was
440     // passed as the ui32ChannelNum parameter, extract just the channel number
441     // from this parameter.
442     //
443     ui32ChannelNum &= 0x1f;
444 
445     //
446     // Clear the useburst bit for this channel if set in ui32Config.
447     //
448     if(ui32Attr & UDMA_ATTR_USEBURST)
449     {
450         HWREG(UDMA_USEBURSTCLR) = 1 << ui32ChannelNum;
451     }
452 
453     //
454     // Clear the alternate control select bit for this channel, if set in
455     // ui32Config.
456     //
457     if(ui32Attr & UDMA_ATTR_ALTSELECT)
458     {
459         HWREG(UDMA_ALTCLR) = 1 << ui32ChannelNum;
460     }
461 
462     //
463     // Clear the high priority bit for this channel, if set in ui32Config.
464     //
465     if(ui32Attr & UDMA_ATTR_HIGH_PRIORITY)
466     {
467         HWREG(UDMA_PRIOCLR) = 1 << ui32ChannelNum;
468     }
469 
470     //
471     // Clear the request mask bit for this channel, if set in ui32Config.
472     //
473     if(ui32Attr & UDMA_ATTR_REQMASK)
474     {
475         HWREG(UDMA_REQMASKCLR) = 1 << ui32ChannelNum;
476     }
477 }
478 
479 //*****************************************************************************
480 //
481 //! Gets the enabled attributes of a uDMA channel.
482 //!
483 //! \param ui32ChannelNum is the channel to configure.
484 //!
485 //! This function returns a combination of flags representing the attributes of
486 //! the uDMA channel.
487 //!
488 //! \return Returns the logical OR of the attributes of the uDMA channel, which
489 //! can be any of the following:
490 //! - \b UDMA_ATTR_USEBURST is used to restrict transfers to use only burst
491 //!   mode.
492 //! - \b UDMA_ATTR_ALTSELECT is used to select the alternate control structure
493 //!   for this channel.
494 //! - \b UDMA_ATTR_HIGH_PRIORITY is used to set this channel to high priority.
495 //! - \b UDMA_ATTR_REQMASK is used to mask the hardware request signal from the
496 //!   peripheral for this channel.
497 //
498 //*****************************************************************************
499 uint32_t
uDMAChannelAttributeGet(uint32_t ui32ChannelNum)500 uDMAChannelAttributeGet(uint32_t ui32ChannelNum)
501 {
502     uint32_t ui32Attr = 0;
503 
504     //
505     // Check the arguments.
506     //
507     ASSERT((ui32ChannelNum & 0xffff) < 32);
508 
509     //
510     // In case a channel selector macro (like UDMA_CH0_USB0EP1RX) was
511     // passed as the ui32ChannelNum parameter, extract just the channel number
512     // from this parameter.
513     //
514     ui32ChannelNum &= 0x1f;
515 
516     //
517     // Check to see if useburst bit is set for this channel.
518     //
519     if(HWREG(UDMA_USEBURSTSET) & (1 << ui32ChannelNum))
520     {
521         ui32Attr |= UDMA_ATTR_USEBURST;
522     }
523 
524     //
525     // Check to see if the alternate control bit is set for this channel.
526     //
527     if(HWREG(UDMA_ALTSET) & (1 << ui32ChannelNum))
528     {
529         ui32Attr |= UDMA_ATTR_ALTSELECT;
530     }
531 
532     //
533     // Check to see if the high priority bit is set for this channel.
534     //
535     if(HWREG(UDMA_PRIOSET) & (1 << ui32ChannelNum))
536     {
537         ui32Attr |= UDMA_ATTR_HIGH_PRIORITY;
538     }
539 
540     //
541     // Check to see if the request mask bit is set for this channel.
542     //
543     if(HWREG(UDMA_REQMASKSET) & (1 << ui32ChannelNum))
544     {
545         ui32Attr |= UDMA_ATTR_REQMASK;
546     }
547 
548     //
549     // Return the configuration flags.
550     //
551     return(ui32Attr);
552 }
553 
554 //*****************************************************************************
555 //
556 //! Sets the control parameters for a uDMA channel control structure.
557 //!
558 //! \param ui32ChannelStructIndex is the logical OR of the uDMA channel number
559 //! with \b UDMA_PRI_SELECT or \b UDMA_ALT_SELECT.
560 //! \param ui32Control is logical OR of several control values to set the
561 //! control parameters for the channel.
562 //!
563 //! This function is used to set control parameters for a uDMA transfer.  These
564 //! parameters are typically not changed often.
565 //!
566 //! The \e ui32ChannelStructIndex parameter should be the logical OR of the
567 //! channel number with one of \b UDMA_PRI_SELECT or \b UDMA_ALT_SELECT to
568 //! choose whether the primary or alternate data structure is used.
569 //!
570 //! The \e ui32Control parameter is the logical OR of five values: the data
571 //! size, the source address increment, the destination address increment, the
572 //! arbitration size, and the use burst flag.  The choices available for each
573 //! of these values is described below.
574 //!
575 //! Choose the data size from one of \b UDMA_SIZE_8, \b UDMA_SIZE_16, or
576 //! \b UDMA_SIZE_32 to select a data size of 8, 16, or 32 bits.
577 //!
578 //! Choose the source address increment from one of \b UDMA_SRC_INC_8,
579 //! \b UDMA_SRC_INC_16, \b UDMA_SRC_INC_32, or \b UDMA_SRC_INC_NONE to select
580 //! an address increment of 8-bit bytes, 16-bit half-words, 32-bit words, or
581 //! to select non-incrementing.
582 //!
583 //! Choose the destination address increment from one of \b UDMA_DST_INC_8,
584 //! \b UDMA_DST_INC_16, \b UDMA_DST_INC_32, or \b UDMA_DST_INC_NONE to select
585 //! an address increment of 8-bit bytes, 16-bit half-words, 32-bit words, or
586 //! to select non-incrementing.
587 //!
588 //! The arbitration size determines how many items are transferred before
589 //! the uDMA controller re-arbitrates for the bus.  Choose the arbitration size
590 //! from one of \b UDMA_ARB_1, \b UDMA_ARB_2, \b UDMA_ARB_4, \b UDMA_ARB_8,
591 //! through \b UDMA_ARB_1024 to select the arbitration size from 1 to 1024
592 //! items, in powers of 2.
593 //!
594 //! The value \b UDMA_NEXT_USEBURST is used to force the channel to only
595 //! respond to burst requests at the tail end of a scatter-gather transfer.
596 //!
597 //! \note The address increment cannot be smaller than the data size.
598 //!
599 //! \return None.
600 //
601 //*****************************************************************************
602 void
uDMAChannelControlSet(uint32_t ui32ChannelStructIndex,uint32_t ui32Control)603 uDMAChannelControlSet(uint32_t ui32ChannelStructIndex, uint32_t ui32Control)
604 {
605     tDMAControlTable *psCtl;
606 
607     //
608     // Check the arguments.
609     //
610     ASSERT((ui32ChannelStructIndex & 0xffff) < 64);
611     ASSERT(HWREG(UDMA_CTLBASE) != 0);
612 
613     //
614     // In case a channel selector macro (like UDMA_CH0_USB0EP1RX) was
615     // passed as the ui32ChannelStructIndex parameter, extract just the channel
616     // index from this parameter.
617     //
618     ui32ChannelStructIndex &= 0x3f;
619 
620     //
621     // Get the base address of the control table.
622     //
623     psCtl = (tDMAControlTable *)HWREG(UDMA_CTLBASE);
624 
625     //
626     // Get the current control word value and mask off the fields to be
627     // changed, then OR in the new settings.
628     //
629     psCtl[ui32ChannelStructIndex].ui32Control =
630         ((psCtl[ui32ChannelStructIndex].ui32Control &
631           ~(UDMA_CHCTL_DSTINC_M |
632             UDMA_CHCTL_DSTSIZE_M |
633             UDMA_CHCTL_SRCINC_M |
634             UDMA_CHCTL_SRCSIZE_M |
635             UDMA_CHCTL_ARBSIZE_M |
636             UDMA_CHCTL_NXTUSEBURST)) |
637          ui32Control);
638 }
639 
640 //*****************************************************************************
641 //
642 //! Sets the transfer parameters for a uDMA channel control structure.
643 //!
644 //! \param ui32ChannelStructIndex is the logical OR of the uDMA channel number
645 //! with either \b UDMA_PRI_SELECT or \b UDMA_ALT_SELECT.
646 //! \param ui32Mode is the type of uDMA transfer.
647 //! \param pvSrcAddr is the source address for the transfer.
648 //! \param pvDstAddr is the destination address for the transfer.
649 //! \param ui32TransferSize is the number of data items to transfer.
650 //!
651 //! This function is used to configure the parameters for a uDMA transfer.
652 //! These parameters are not typically changed often.  The function
653 //! uDMAChannelControlSet() MUST be called at least once for this channel prior
654 //! to calling this function.
655 //!
656 //! The \e ui32ChannelStructIndex parameter should be the logical OR of the
657 //! channel number with one of \b UDMA_PRI_SELECT or \b UDMA_ALT_SELECT to
658 //! choose whether the primary or alternate data structure is used.
659 //!
660 //! The \e ui32Mode parameter should be one of the following values:
661 //!
662 //! - \b UDMA_MODE_STOP stops the uDMA transfer.  The controller sets the mode
663 //!   to this value at the end of a transfer.
664 //! - \b UDMA_MODE_BASIC to perform a basic transfer based on request.
665 //! - \b UDMA_MODE_AUTO to perform a transfer that always completes once
666 //!   started even if the request is removed.
667 //! - \b UDMA_MODE_PINGPONG to set up a transfer that switches between the
668 //!   primary and alternate control structures for the channel.  This mode
669 //!   allows use of ping-pong buffering for uDMA transfers.
670 //! - \b UDMA_MODE_MEM_SCATTER_GATHER to set up a memory scatter-gather
671 //!   transfer.
672 //! - \b UDMA_MODE_PER_SCATTER_GATHER to set up a peripheral scatter-gather
673 //!   transfer.
674 //!
675 //! The \e pvSrcAddr and \e pvDstAddr parameters are pointers to the first
676 //! location of the data to be transferred.  These addresses should be aligned
677 //! according to the item size.  The compiler takes care of this alignment if
678 //! the pointers are pointing to storage of the appropriate data type.
679 //!
680 //! The \e ui32TransferSize parameter is the number of data items, not the
681 //! number of bytes.
682 //!
683 //! The two scatter-gather modes, memory and peripheral, are actually different
684 //! depending on whether the primary or alternate control structure is
685 //! selected.  This function looks for the \b UDMA_PRI_SELECT and
686 //! \b UDMA_ALT_SELECT flag along with the channel number and sets the
687 //! scatter-gather mode as appropriate for the primary or alternate control
688 //! structure.
689 //!
690 //! The channel must also be enabled using uDMAChannelEnable() after calling
691 //! this function.  The transfer does not begin until the channel has been
692 //! configured and enabled.  Note that the channel is automatically disabled
693 //! after the transfer is completed, meaning that uDMAChannelEnable() must be
694 //! called again after setting up the next transfer.
695 //!
696 //! \note Great care must be taken to not modify a channel control structure
697 //! that is in use or else the results are unpredictable, including the
698 //! possibility of undesired data transfers to or from memory or peripherals.
699 //! For BASIC and AUTO modes, it is safe to make changes when the channel is
700 //! disabled, or the uDMAChannelModeGet() returns \b UDMA_MODE_STOP.  For
701 //! PINGPONG or one of the SCATTER_GATHER modes, it is safe to modify the
702 //! primary or alternate control structure only when the other is being used.
703 //! The uDMAChannelModeGet() function returns \b UDMA_MODE_STOP when a
704 //! channel control structure is inactive and safe to modify.
705 //!
706 //! \return None.
707 //
708 //*****************************************************************************
709 void
uDMAChannelTransferSet(uint32_t ui32ChannelStructIndex,uint32_t ui32Mode,void * pvSrcAddr,void * pvDstAddr,uint32_t ui32TransferSize)710 uDMAChannelTransferSet(uint32_t ui32ChannelStructIndex, uint32_t ui32Mode,
711                        void *pvSrcAddr, void *pvDstAddr,
712                        uint32_t ui32TransferSize)
713 {
714     tDMAControlTable *psControlTable;
715     uint32_t ui32Control;
716     uint32_t ui32Inc;
717     uint32_t ui32BufferBytes;
718 
719     //
720     // Check the arguments.
721     //
722     ASSERT((ui32ChannelStructIndex & 0xffff) < 64);
723     ASSERT(HWREG(UDMA_CTLBASE) != 0);
724     ASSERT(ui32Mode <= UDMA_MODE_PER_SCATTER_GATHER);
725     ASSERT((uint32_t)pvSrcAddr >= 0x20000000);
726     ASSERT((uint32_t)pvDstAddr >= 0x20000000);
727     ASSERT((ui32TransferSize != 0) && (ui32TransferSize <= 1024));
728 
729     //
730     // In case a channel selector macro (like UDMA_CH0_USB0EP1RX) was
731     // passed as the ui32ChannelStructIndex parameter, extract just the channel
732     // index from this parameter.
733     //
734     ui32ChannelStructIndex &= 0x3f;
735 
736     //
737     // Get the base address of the control table.
738     //
739     psControlTable = (tDMAControlTable *)HWREG(UDMA_CTLBASE);
740 
741     //
742     // Get the current control word value and mask off the mode and size
743     // fields.
744     //
745     ui32Control = (psControlTable[ui32ChannelStructIndex].ui32Control &
746                    ~(UDMA_CHCTL_XFERSIZE_M | UDMA_CHCTL_XFERMODE_M));
747 
748     //
749     // Adjust the mode if the alt control structure is selected.
750     //
751     if(ui32ChannelStructIndex & UDMA_ALT_SELECT)
752     {
753         if((ui32Mode == UDMA_MODE_MEM_SCATTER_GATHER) ||
754            (ui32Mode == UDMA_MODE_PER_SCATTER_GATHER))
755         {
756             ui32Mode |= UDMA_MODE_ALT_SELECT;
757         }
758     }
759 
760     //
761     // Set the transfer size and mode in the control word (but don't write the
762     // control word yet as it could kick off a transfer).
763     //
764     ui32Control |= ui32Mode | ((ui32TransferSize - 1) << 4);
765 
766     //
767     // Get the address increment value for the source, from the control word.
768     //
769     ui32Inc = (ui32Control & UDMA_CHCTL_SRCINC_M);
770 
771     //
772     // Compute the ending source address of the transfer.  If the source
773     // increment is set to none, then the ending address is the same as the
774     // beginning.
775     //
776     if(ui32Inc != UDMA_SRC_INC_NONE)
777     {
778         ui32Inc = ui32Inc >> 26;
779         ui32BufferBytes = ui32TransferSize << ui32Inc;
780         pvSrcAddr = (void *)((uint32_t)pvSrcAddr + ui32BufferBytes - 1);
781     }
782 
783     //
784     // Load the source ending address into the control block.
785     //
786     psControlTable[ui32ChannelStructIndex].pvSrcEndAddr = pvSrcAddr;
787 
788     //
789     // Get the address increment value for the destination, from the control
790     // word.
791     //
792     ui32Inc = ui32Control & UDMA_CHCTL_DSTINC_M;
793 
794     //
795     // Compute the ending destination address of the transfer.  If the
796     // destination increment is set to none, then the ending address is the
797     // same as the beginning.
798     //
799     if(ui32Inc != UDMA_DST_INC_NONE)
800     {
801         //
802         // There is a special case if this is setting up a scatter-gather
803         // transfer.  The destination pointer must point to the end of
804         // the alternate structure for this channel instead of calculating
805         // the end of the buffer in the normal way.
806         //
807         if((ui32Mode == UDMA_MODE_MEM_SCATTER_GATHER) ||
808            (ui32Mode == UDMA_MODE_PER_SCATTER_GATHER))
809         {
810             pvDstAddr =
811                 (void *)&psControlTable[ui32ChannelStructIndex |
812                                         UDMA_ALT_SELECT].ui32Spare;
813         }
814         //
815         // Not a scatter-gather transfer, calculate end pointer normally.
816         //
817         else
818         {
819             ui32Inc = ui32Inc >> 30;
820             ui32BufferBytes = ui32TransferSize << ui32Inc;
821             pvDstAddr = (void *)((uint32_t)pvDstAddr + ui32BufferBytes - 1);
822         }
823     }
824 
825     //
826     // Load the destination ending address into the control block.
827     //
828     psControlTable[ui32ChannelStructIndex].pvDstEndAddr = pvDstAddr;
829 
830     //
831     // Write the new control word value.
832     //
833     psControlTable[ui32ChannelStructIndex].ui32Control = ui32Control;
834 }
835 
836 //*****************************************************************************
837 //
838 //! Configures a uDMA channel for scatter-gather mode.
839 //!
840 //! \param ui32ChannelNum is the uDMA channel number.
841 //! \param ui32TaskCount is the number of scatter-gather tasks to execute.
842 //! \param pvTaskList is a pointer to the beginning of the scatter-gather
843 //! task list.
844 //! \param ui32IsPeriphSG is a flag to indicate it is a peripheral
845 //! scatter-gather transfer (else it is memory scatter-gather transfer)
846 //!
847 //! This function is used to configure a channel for scatter-gather mode.
848 //! The caller must have already set up a task list and must pass a pointer to
849 //! the start of the task list as the \e pvTaskList parameter.  The
850 //! \e ui32TaskCount parameter is the count of tasks in the task list, not the
851 //! size of the task list.  The flag \e bIsPeriphSG should be used to indicate
852 //! if scatter-gather should be configured for peripheral or memory
853 //! operation.
854 //!
855 //! \sa uDMATaskStructEntry
856 //!
857 //! \return None.
858 //
859 //*****************************************************************************
860 void
uDMAChannelScatterGatherSet(uint32_t ui32ChannelNum,uint32_t ui32TaskCount,void * pvTaskList,uint32_t ui32IsPeriphSG)861 uDMAChannelScatterGatherSet(uint32_t ui32ChannelNum, uint32_t ui32TaskCount,
862                             void *pvTaskList, uint32_t ui32IsPeriphSG)
863 {
864     tDMAControlTable *psControlTable;
865     tDMAControlTable *psTaskTable;
866 
867     //
868     // Check the parameters
869     //
870     ASSERT((ui32ChannelNum & 0xffff) < 32);
871     ASSERT(HWREG(UDMA_CTLBASE) != 0);
872     ASSERT(pvTaskList != 0);
873     ASSERT(ui32TaskCount <= 1024);
874     ASSERT(ui32TaskCount != 0);
875 
876     //
877     // In case a channel selector macro (like UDMA_CH0_USB0EP1RX) was
878     // passed as the ui32ChannelNum parameter, extract just the channel number
879     // from this parameter.
880     //
881     ui32ChannelNum &= 0x1f;
882 
883     //
884     // Get the base address of the control table.
885     //
886     psControlTable = (tDMAControlTable *)HWREG(UDMA_CTLBASE);
887 
888     //
889     // Get a handy pointer to the task list
890     //
891     psTaskTable = (tDMAControlTable *)pvTaskList;
892 
893     //
894     // Compute the ending address for the source pointer.  This address is the
895     // last element of the last task in the task table
896     //
897     psControlTable[ui32ChannelNum].pvSrcEndAddr =
898         &psTaskTable[ui32TaskCount - 1].ui32Spare;
899 
900     //
901     // Compute the ending address for the destination pointer.  This address
902     // is the end of the alternate structure for this channel.
903     //
904     psControlTable[ui32ChannelNum].pvDstEndAddr =
905         &psControlTable[ui32ChannelNum | UDMA_ALT_SELECT].ui32Spare;
906 
907     //
908     // Compute the control word.  Most configurable items are fixed for
909     // scatter-gather.  Item and increment sizes are all 32-bit and arb
910     // size must be 4.  The count is the number of items in the task list
911     // times 4 (4 words per task).
912     //
913     psControlTable[ui32ChannelNum].ui32Control =
914         (UDMA_CHCTL_DSTINC_32 | UDMA_CHCTL_DSTSIZE_32 |
915          UDMA_CHCTL_SRCINC_32 | UDMA_CHCTL_SRCSIZE_32 |
916          UDMA_CHCTL_ARBSIZE_4 |
917          (((ui32TaskCount * 4) - 1) << UDMA_CHCTL_XFERSIZE_S) |
918          (ui32IsPeriphSG ? UDMA_CHCTL_XFERMODE_PER_SG :
919           UDMA_CHCTL_XFERMODE_MEM_SG));
920 
921     //
922     // Scatter-gather operations can leave the alt bit set.  So if doing
923     // back to back scatter-gather transfers, the second attempt may not
924     // work correctly because the alt bit is set.  Therefore, clear the
925     // alt bit here to ensure that it is always cleared before a new SG
926     // transfer is started.
927     //
928     HWREG(UDMA_ALTCLR) = 1 << ui32ChannelNum;
929 }
930 
931 //*****************************************************************************
932 //
933 //! Gets the current transfer size for a uDMA channel control structure.
934 //!
935 //! \param ui32ChannelStructIndex is the logical OR of the uDMA channel number
936 //! with either \b UDMA_PRI_SELECT or \b UDMA_ALT_SELECT.
937 //!
938 //! This function is used to get the uDMA transfer size for a channel.  The
939 //! transfer size is the number of items to transfer, where the size of an item
940 //! might be 8, 16, or 32 bits.  If a partial transfer has already occurred,
941 //! then the number of remaining items is returned.  If the transfer is
942 //! complete, then 0 is returned.
943 //!
944 //! \return Returns the number of items remaining to transfer.
945 //
946 //*****************************************************************************
947 uint32_t
uDMAChannelSizeGet(uint32_t ui32ChannelStructIndex)948 uDMAChannelSizeGet(uint32_t ui32ChannelStructIndex)
949 {
950     tDMAControlTable *psControlTable;
951     uint32_t ui32Control;
952 
953     //
954     // Check the arguments.
955     //
956     ASSERT((ui32ChannelStructIndex & 0xffff) < 64);
957     ASSERT(HWREG(UDMA_CTLBASE) != 0);
958 
959     //
960     // In case a channel selector macro (like UDMA_CH0_USB0EP1RX) was
961     // passed as the ui32ChannelStructIndex parameter, extract just the channel
962     // index from this parameter.
963     //
964     ui32ChannelStructIndex &= 0x3f;
965 
966     //
967     // Get the base address of the control table.
968     //
969     psControlTable = (tDMAControlTable *)HWREG(UDMA_CTLBASE);
970 
971     //
972     // Get the current control word value and mask off all but the size field
973     // and the mode field.
974     //
975     ui32Control = (psControlTable[ui32ChannelStructIndex].ui32Control &
976                    (UDMA_CHCTL_XFERSIZE_M | UDMA_CHCTL_XFERMODE_M));
977 
978     //
979     // If the size field and mode field are 0 then the transfer is finished
980     // and there are no more items to transfer
981     //
982     if(ui32Control == 0)
983     {
984         return(0);
985     }
986 
987     //
988     // Otherwise, if either the size field or more field is non-zero, then
989     // not all the items have been transferred.
990     //
991     else
992     {
993         //
994         // Shift the size field and add one, then return to user.
995         //
996         return((ui32Control >> 4) + 1);
997     }
998 }
999 
1000 //*****************************************************************************
1001 //
1002 //! Gets the transfer mode for a uDMA channel control structure.
1003 //!
1004 //! \param ui32ChannelStructIndex is the logical OR of the uDMA channel number
1005 //! with either \b UDMA_PRI_SELECT or \b UDMA_ALT_SELECT.
1006 //!
1007 //! This function is used to get the transfer mode for the uDMA channel and
1008 //! to query the status of a transfer on a channel.  When the transfer is
1009 //! complete the mode is \b UDMA_MODE_STOP.
1010 //!
1011 //! \return Returns the transfer mode of the specified channel and control
1012 //! structure, which is one of the following values: \b UDMA_MODE_STOP,
1013 //! \b UDMA_MODE_BASIC, \b UDMA_MODE_AUTO, \b UDMA_MODE_PINGPONG,
1014 //! \b UDMA_MODE_MEM_SCATTER_GATHER, or \b UDMA_MODE_PER_SCATTER_GATHER.
1015 //
1016 //*****************************************************************************
1017 uint32_t
uDMAChannelModeGet(uint32_t ui32ChannelStructIndex)1018 uDMAChannelModeGet(uint32_t ui32ChannelStructIndex)
1019 {
1020     tDMAControlTable *psControlTable;
1021     uint32_t ui32Control;
1022 
1023     //
1024     // Check the arguments.
1025     //
1026     ASSERT((ui32ChannelStructIndex & 0xffff) < 64);
1027     ASSERT(HWREG(UDMA_CTLBASE) != 0);
1028 
1029     //
1030     // In case a channel selector macro (like UDMA_CH0_USB0EP1RX) was
1031     // passed as the ui32ChannelStructIndex parameter, extract just the channel
1032     // index from this parameter.
1033     //
1034     ui32ChannelStructIndex &= 0x3f;
1035 
1036     //
1037     // Get the base address of the control table.
1038     //
1039     psControlTable = (tDMAControlTable *)HWREG(UDMA_CTLBASE);
1040 
1041     //
1042     // Get the current control word value and mask off all but the mode field.
1043     //
1044     ui32Control = (psControlTable[ui32ChannelStructIndex].ui32Control &
1045                    UDMA_CHCTL_XFERMODE_M);
1046 
1047     //
1048     // Check if scatter/gather mode, and if so, mask off the alt bit.
1049     //
1050     if(((ui32Control & ~UDMA_MODE_ALT_SELECT) ==
1051         UDMA_MODE_MEM_SCATTER_GATHER) ||
1052        ((ui32Control & ~UDMA_MODE_ALT_SELECT) == UDMA_MODE_PER_SCATTER_GATHER))
1053     {
1054         ui32Control &= ~UDMA_MODE_ALT_SELECT;
1055     }
1056 
1057     //
1058     // Return the mode to the caller.
1059     //
1060     return(ui32Control);
1061 }
1062 
1063 //*****************************************************************************
1064 //
1065 //! Registers an interrupt handler for the uDMA controller.
1066 //!
1067 //! \param ui32IntChannel identifies which uDMA interrupt is to be registered.
1068 //! \param pfnHandler is a pointer to the function to be called when the
1069 //! interrupt is activated.
1070 //!
1071 //! This function registers and enables the handler to be called when the uDMA
1072 //! controller generates an interrupt.  The \e ui32IntChannel parameter should
1073 //! be one of the following:
1074 //!
1075 //! - \b INT_UDMA to register an interrupt handler to process interrupts
1076 //!   from the uDMA software channel (UDMA_CHANNEL_SW)
1077 //! - \b INT_UDMAERR to register an interrupt handler to process uDMA error
1078 //!   interrupts
1079 //!
1080 //! \sa IntRegister() for important information about registering interrupt
1081 //! handlers.
1082 //!
1083 //! \note The interrupt handler for the uDMA is for transfer completion when
1084 //! the channel UDMA_CHANNEL_SW is used and for error interrupts.  The
1085 //! interrupts for each peripheral channel are handled through the individual
1086 //! peripheral interrupt handlers.
1087 //!
1088 //! \return None.
1089 //
1090 //*****************************************************************************
1091 void
uDMAIntRegister(uint32_t ui32IntChannel,void (* pfnHandler)(void))1092 uDMAIntRegister(uint32_t ui32IntChannel, void (*pfnHandler)(void))
1093 {
1094     //
1095     // Check the arguments.
1096     //
1097     ASSERT(pfnHandler);
1098 
1099     //
1100     // Register the interrupt handler.
1101     //
1102     IntRegister(ui32IntChannel, pfnHandler);
1103 
1104     //
1105     // Enable the memory management fault.
1106     //
1107     IntEnable(ui32IntChannel);
1108 }
1109 
1110 //*****************************************************************************
1111 //
1112 //! Unregisters an interrupt handler for the uDMA controller.
1113 //!
1114 //! \param ui32IntChannel identifies which uDMA interrupt to unregister.
1115 //!
1116 //! This function disables and unregisters the handler to be called for the
1117 //! specified uDMA interrupt.  The \e ui32IntChannel parameter should be one of
1118 //! \b INT_UDMA or \b INT_UDMAERR as documented for the function
1119 //! uDMAIntRegister().
1120 //!
1121 //! \sa IntRegister() for important information about registering interrupt
1122 //! handlers.
1123 //!
1124 //! \return None.
1125 //
1126 //*****************************************************************************
1127 void
uDMAIntUnregister(uint32_t ui32IntChannel)1128 uDMAIntUnregister(uint32_t ui32IntChannel)
1129 {
1130     //
1131     // Disable the interrupt.
1132     //
1133     IntDisable(ui32IntChannel);
1134 
1135     //
1136     // Unregister the interrupt handler.
1137     //
1138     IntUnregister(ui32IntChannel);
1139 }
1140 
1141 //*****************************************************************************
1142 //
1143 //! Gets the uDMA controller channel interrupt status.
1144 //!
1145 //! This function is used to get the interrupt status of the uDMA controller.
1146 //! The returned value is a 32-bit bit mask that indicates which channels are
1147 //! requesting an interrupt.  This function can be used from within an
1148 //! interrupt handler to determine or confirm which uDMA channel has requested
1149 //! an interrupt.
1150 //!
1151 //! \note This function is only available on devices that have the DMA Channel
1152 //! Interrupt Status Register (DMACHIS).  Please consult the data sheet for
1153 //! your part.
1154 //!
1155 //! \return Returns a 32-bit mask which indicates requesting uDMA channels.
1156 //! There is a bit for each channel and a 1 indicates that the channel
1157 //! is requesting an interrupt.  Multiple bits can be set.
1158 //
1159 //*****************************************************************************
1160 uint32_t
uDMAIntStatus(void)1161 uDMAIntStatus(void)
1162 {
1163     //
1164     // Return the value of the uDMA interrupt status register
1165     //
1166     return(HWREG(UDMA_CHIS));
1167 }
1168 
1169 //*****************************************************************************
1170 //
1171 //! Clears uDMA interrupt status.
1172 //!
1173 //! \param ui32ChanMask is a 32-bit mask with one bit for each uDMA channel.
1174 //!
1175 //! This function clears bits in the uDMA interrupt status register according
1176 //! to which bits are set in \e ui32ChanMask.  There is one bit for each
1177 //! channel.  If a a bit is set in \e ui32ChanMask, then that corresponding
1178 //! channel's interrupt status is cleared (if it was set).
1179 //!
1180 //! \note This function is only available on devices that have the DMA Channel
1181 //! Interrupt Status Register (DMACHIS).  Please consult the data sheet for
1182 //! your part. Devices without the DMACHIS register have uDMA done status in
1183 //! the interrupt registers in the peripheral memory maps.
1184 //!
1185 //! \return None.
1186 //
1187 //*****************************************************************************
1188 void
uDMAIntClear(uint32_t ui32ChanMask)1189 uDMAIntClear(uint32_t ui32ChanMask)
1190 {
1191     //
1192     // Clear the requested bits in the uDMA interrupt status register
1193     //
1194     HWREG(UDMA_CHIS) = ui32ChanMask;
1195 }
1196 
1197 //*****************************************************************************
1198 //
1199 //! Assigns a peripheral mapping for a uDMA channel.
1200 //!
1201 //! \param ui32Mapping is a macro specifying the peripheral assignment for
1202 //! a channel.
1203 //!
1204 //! This function assigns a peripheral mapping to a uDMA channel.  It is
1205 //! used to select which peripheral is used for a uDMA channel.  The parameter
1206 //! \e ui32Mapping should be one of the macros named \b UDMA_CHn_tttt from the
1207 //! header file \e udma.h.  For example, to assign uDMA channel 0 to the
1208 //! UART2 RX channel, the parameter should be the macro \b UDMA_CH0_UART2RX.
1209 //!
1210 //! Please consult the Tiva data sheet for a table showing all the
1211 //! possible peripheral assignments for the uDMA channels for a particular
1212 //! device.
1213 //!
1214 //! \note This function is only available on devices that have the DMA Channel
1215 //! Map Select registers (DMACHMAP0-3).  Please consult the data sheet for
1216 //! your part.
1217 //!
1218 //! \return None.
1219 //
1220 //*****************************************************************************
1221 void
uDMAChannelAssign(uint32_t ui32Mapping)1222 uDMAChannelAssign(uint32_t ui32Mapping)
1223 {
1224     uint32_t ui32MapReg;
1225     uint_fast8_t ui8MapShift;
1226     uint_fast8_t ui8ChannelNum;
1227 
1228     //
1229     // Check the parameters
1230     //
1231     ASSERT((ui32Mapping & 0xffffff00) < 0x00090000);
1232 
1233     //
1234     // Extract the channel number and map encoding value from the parameter.
1235     //
1236     ui8ChannelNum = ui32Mapping & 0xff;
1237     ui32Mapping = ui32Mapping >> 16;
1238 
1239     //
1240     // Find the uDMA channel mapping register and shift value to use for this
1241     // channel
1242     //
1243     ui32MapReg = UDMA_CHMAP0 + (uint32_t)((ui8ChannelNum / 8) * 4);
1244     ui8MapShift = (ui8ChannelNum % 8) * 4;
1245 
1246     //
1247     // Set the channel map encoding for this channel
1248     //
1249     HWREG(ui32MapReg) = (HWREG(ui32MapReg) & ~(0xf << ui8MapShift)) |
1250                         ui32Mapping << ui8MapShift;
1251 }
1252 
1253 //*****************************************************************************
1254 //
1255 // The following functions are deprecated.  Use uDMAChannelAssign() instead
1256 // to accomplish the same end.
1257 //
1258 //*****************************************************************************
1259 #ifndef DEPRECATED
1260 //*****************************************************************************
1261 //
1262 //! Selects the secondary peripheral for a set of uDMA channels.
1263 //!
1264 //! \param ui32SecPeriphs is the logical OR of the uDMA channels for which to
1265 //! use the secondary peripheral, instead of the default peripheral.
1266 //!
1267 //! This function is used to select the secondary peripheral assignment for a
1268 //! set of uDMA channels.  By selecting the secondary peripheral assignment for
1269 //! a channel, the default peripheral assignment is no longer available for
1270 //! that channel.
1271 //!
1272 //! The parameter \e ui32SecPeriphs can be the logical OR of any of the
1273 //! following macros.  If one of the macros below is in the list passed to this
1274 //! function, then the secondary peripheral (marked as \b _SEC_) is selected.
1275 //!
1276 //! - \b UDMA_DEF_USBEP1RX_SEC_UART2RX
1277 //! - \b UDMA_DEF_USBEP1TX_SEC_UART2TX
1278 //! - \b UDMA_DEF_USBEP2RX_SEC_TMR3A
1279 //! - \b UDMA_DEF_USBEP2TX_SEC_TMR3B
1280 //! - \b UDMA_DEF_USBEP3RX_SEC_TMR2A
1281 //! - \b UDMA_DEF_USBEP3TX_SEC_TMR2B
1282 //! - \b UDMA_DEF_ETH0RX_SEC_TMR2A
1283 //! - \b UDMA_DEF_ETH0TX_SEC_TMR2B
1284 //! - \b UDMA_DEF_UART0RX_SEC_UART1RX
1285 //! - \b UDMA_DEF_UART0TX_SEC_UART1TX
1286 //! - \b UDMA_DEF_SSI0RX_SEC_SSI1RX
1287 //! - \b UDMA_DEF_SSI0TX_SEC_SSI1TX
1288 //! - \b UDMA_DEF_RESERVED_SEC_UART2RX
1289 //! - \b UDMA_DEF_RESERVED_SEC_UART2TX
1290 //! - \b UDMA_DEF_ADC00_SEC_TMR2A
1291 //! - \b UDMA_DEF_ADC01_SEC_TMR2B
1292 //! - \b UDMA_DEF_ADC02_SEC_RESERVED
1293 //! - \b UDMA_DEF_ADC03_SEC_RESERVED
1294 //! - \b UDMA_DEF_TMR0A_SEC_TMR1A
1295 //! - \b UDMA_DEF_TMR0B_SEC_TMR1B
1296 //! - \b UDMA_DEF_TMR1A_SEC_EPI0RX
1297 //! - \b UDMA_DEF_TMR1B_SEC_EPI0TX
1298 //! - \b UDMA_DEF_UART1RX_SEC_RESERVED
1299 //! - \b UDMA_DEF_UART1TX_SEC_RESERVED
1300 //! - \b UDMA_DEF_SSI1RX_SEC_ADC10
1301 //! - \b UDMA_DEF_SSI1TX_SEC_ADC11
1302 //! - \b UDMA_DEF_RESERVED_SEC_ADC12
1303 //! - \b UDMA_DEF_RESERVED_SEC_ADC13
1304 //! - \b UDMA_DEF_I2S0RX_SEC_RESERVED
1305 //! - \b UDMA_DEF_I2S0TX_SEC_RESERVED
1306 //!
1307 //! \return None.
1308 //
1309 //*****************************************************************************
1310 void
uDMAChannelSelectSecondary(uint32_t ui32SecPeriphs)1311 uDMAChannelSelectSecondary(uint32_t ui32SecPeriphs)
1312 {
1313     //
1314     // Select the secondary peripheral for the specified channels.
1315     //
1316     HWREG(UDMA_CHASGN) |= ui32SecPeriphs;
1317 }
1318 
1319 //*****************************************************************************
1320 //
1321 //! Selects the default peripheral for a set of uDMA channels.
1322 //!
1323 //! \param ui32DefPeriphs is the logical OR of the uDMA channels for which to
1324 //! use the default peripheral, instead of the secondary peripheral.
1325 //!
1326 //! This function is used to select the default peripheral assignment for a set
1327 //! of uDMA channels.
1328 //!
1329 //! The parameter \e ui32DefPeriphs can be the logical OR of any of the
1330 //! following macros.  If one of the macros below is in the list passed to this
1331 //! function, then the default peripheral (marked as \b _DEF_) is selected.
1332 //!
1333 //! - \b UDMA_DEF_USBEP1RX_SEC_UART2RX
1334 //! - \b UDMA_DEF_USBEP1TX_SEC_UART2TX
1335 //! - \b UDMA_DEF_USBEP2RX_SEC_TMR3A
1336 //! - \b UDMA_DEF_USBEP2TX_SEC_TMR3B
1337 //! - \b UDMA_DEF_USBEP3RX_SEC_TMR2A
1338 //! - \b UDMA_DEF_USBEP3TX_SEC_TMR2B
1339 //! - \b UDMA_DEF_ETH0RX_SEC_TMR2A
1340 //! - \b UDMA_DEF_ETH0TX_SEC_TMR2B
1341 //! - \b UDMA_DEF_UART0RX_SEC_UART1RX
1342 //! - \b UDMA_DEF_UART0TX_SEC_UART1TX
1343 //! - \b UDMA_DEF_SSI0RX_SEC_SSI1RX
1344 //! - \b UDMA_DEF_SSI0TX_SEC_SSI1TX
1345 //! - \b UDMA_DEF_RESERVED_SEC_UART2RX
1346 //! - \b UDMA_DEF_RESERVED_SEC_UART2TX
1347 //! - \b UDMA_DEF_ADC00_SEC_TMR2A
1348 //! - \b UDMA_DEF_ADC01_SEC_TMR2B
1349 //! - \b UDMA_DEF_ADC02_SEC_RESERVED
1350 //! - \b UDMA_DEF_ADC03_SEC_RESERVED
1351 //! - \b UDMA_DEF_TMR0A_SEC_TMR1A
1352 //! - \b UDMA_DEF_TMR0B_SEC_TMR1B
1353 //! - \b UDMA_DEF_TMR1A_SEC_EPI0RX
1354 //! - \b UDMA_DEF_TMR1B_SEC_EPI0TX
1355 //! - \b UDMA_DEF_UART1RX_SEC_RESERVED
1356 //! - \b UDMA_DEF_UART1TX_SEC_RESERVED
1357 //! - \b UDMA_DEF_SSI1RX_SEC_ADC10
1358 //! - \b UDMA_DEF_SSI1TX_SEC_ADC11
1359 //! - \b UDMA_DEF_RESERVED_SEC_ADC12
1360 //! - \b UDMA_DEF_RESERVED_SEC_ADC13
1361 //! - \b UDMA_DEF_I2S0RX_SEC_RESERVED
1362 //! - \b UDMA_DEF_I2S0TX_SEC_RESERVED
1363 //!
1364 //! \return None.
1365 //
1366 //*****************************************************************************
1367 void
uDMAChannelSelectDefault(uint32_t ui32DefPeriphs)1368 uDMAChannelSelectDefault(uint32_t ui32DefPeriphs)
1369 {
1370     //
1371     // Select the default peripheral for the specified channels.
1372     //
1373     HWREG(UDMA_CHASGN) &= ~ui32DefPeriphs;
1374 }
1375 #endif
1376 
1377 //*****************************************************************************
1378 //
1379 // Close the Doxygen group.
1380 //! @}
1381 //
1382 //*****************************************************************************
1383