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