CC27xxDriverLibrary
udma.h
Go to the documentation of this file.
1 /******************************************************************************
2  * Filename: udma.h
3  *
4  * Description: Defines and prototypes for the uDMA controller.
5  *
6  * Copyright (c) 2022-2024 Texas Instruments Incorporated
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions are met:
10  *
11  * 1) Redistributions of source code must retain the above copyright notice,
12  * this list of conditions and the following disclaimer.
13  *
14  * 2) Redistributions in binary form must reproduce the above copyright notice,
15  * this list of conditions and the following disclaimer in the documentation
16  * and/or other materials provided with the distribution.
17  *
18  * 3) Neither the name of the copyright holder nor the names of its
19  * contributors may be used to endorse or promote products derived from this
20  * software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
26  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *
34  ******************************************************************************/
35 
36 #ifndef __UDMA_H__
37 #define __UDMA_H__
38 
39 //*****************************************************************************
40 //
45 //
46 //*****************************************************************************
47 
48 //*****************************************************************************
49 //
50 // If building with a C++ compiler, make all of the definitions in this header
51 // have a C binding.
52 //
53 //*****************************************************************************
54 #ifdef __cplusplus
55 extern "C" {
56 #endif
57 
58 #include <stdbool.h>
59 #include <stdint.h>
60 #include "../inc/hw_types.h"
61 #include "../inc/hw_ints.h"
62 #include "../inc/hw_memmap.h"
63 #include "../inc/hw_dma.h"
64 #include "debug.h"
65 #include "interrupt.h"
66 
67 //*****************************************************************************
68 //
73 //
74 //*****************************************************************************
75 typedef struct
76 {
77  volatile void *pSrcEndAddr;
78  volatile void *pDstEndAddr;
79  volatile uint32_t control;
80  volatile uint32_t spare;
82 
83 //*****************************************************************************
84 //
98 
110 //
150 //*****************************************************************************
151 #define uDMATaskStructEntry(transferCount, itemSize, srcIncrement, pSrcAddr, dstIncrement, pDstAddr, arbSize, mode) \
152  { \
153  (((srcIncrement) == UDMA_SRC_INC_NONE) \
154  ? (pSrcAddr) \
155  : ((void *)(&((uint8_t *)(pSrcAddr))[((transferCount) << ((srcIncrement) >> 26)) - 1]))), \
156  (((dstIncrement) == UDMA_DST_INC_NONE) \
157  ? (pDstAddr) \
158  : ((void *)(&((uint8_t *)(pDstAddr))[((transferCount) << ((dstIncrement) >> 30)) - 1]))), \
159  (srcIncrement) | (dstIncrement) | (itemSize) | (arbSize) | (((transferCount)-1) << 4) | \
160  ((((mode) == UDMA_MODE_MEM_SCATTER_GATHER) || ((mode) == UDMA_MODE_PER_SCATTER_GATHER)) \
161  ? (mode) | UDMA_MODE_ALT_SELECT \
162  : (mode)), \
163  0 \
164  }
165 
166 //*****************************************************************************
167 //
168 // The hardware configured number of uDMA channels.
169 //
170 //*****************************************************************************
171 #define UDMA_NUM_CHANNELS 8
172 
173 //*****************************************************************************
174 //
175 // The level of priority for the uDMA channels
176 //
177 //*****************************************************************************
178 #define UDMA_PRIORITY_LOW 0x00000000
179 #define UDMA_PRIORITY_HIGH 0x00000001
180 
181 //*****************************************************************************
182 //
183 // Flags that can be passed to uDMAEnableChannelAttribute(),
184 // uDMADisableChannelAttribute(), and returned from uDMAGetChannelAttribute().
185 //
186 //*****************************************************************************
187 #define UDMA_ATTR_USEBURST 0x00000001
188 #define UDMA_ATTR_ALTSELECT 0x00000002
189 #define UDMA_ATTR_HIGH_PRIORITY 0x00000004
190 #define UDMA_ATTR_REQMASK 0x00000008
191 #define UDMA_ATTR_ALL 0x0000000F
192 
193 //*****************************************************************************
194 //
195 // DMA control modes that can be passed to uDMASetChannelTransfer() and returned
196 // from uDMAGetChannelMode().
197 //
198 //*****************************************************************************
199 #define UDMA_MODE_STOP 0x00000000
200 #define UDMA_MODE_BASIC 0x00000001
201 #define UDMA_MODE_AUTO 0x00000002
202 #define UDMA_MODE_PINGPONG 0x00000003
203 #define UDMA_MODE_MEM_SCATTER_GATHER 0x00000004
204 #define UDMA_MODE_PER_SCATTER_GATHER 0x00000006
205 #define UDMA_MODE_M 0x00000007 // uDMA Transfer Mode
206 #define UDMA_MODE_ALT_SELECT 0x00000001
207 
208 //*****************************************************************************
209 //
210 // Channel configuration values that can be passed to uDMASetChannelControl().
211 //
212 //*****************************************************************************
213 #define UDMA_DST_INC_8 0x00000000
214 #define UDMA_DST_INC_16 0x40000000
215 #define UDMA_DST_INC_32 0x80000000
216 #define UDMA_DST_INC_NONE 0xC0000000
217 #define UDMA_DST_INC_M 0xC0000000 // Destination Address Increment
218 #define UDMA_DST_INC_S 30
219 #define UDMA_SRC_INC_8 0x00000000
220 #define UDMA_SRC_INC_16 0x04000000
221 #define UDMA_SRC_INC_32 0x08000000
222 #define UDMA_SRC_INC_NONE 0x0c000000
223 #define UDMA_SRC_INC_M 0x0C000000 // Source Address Increment
224 #define UDMA_SRC_INC_S 26
225 #define UDMA_SIZE_8 0x00000000
226 #define UDMA_SIZE_16 0x11000000
227 #define UDMA_SIZE_32 0x22000000
228 #define UDMA_SIZE_M 0x33000000 // Data Size
229 #define UDMA_SIZE_S 24
230 #define UDMA_ARB_1 0x00000000
231 #define UDMA_ARB_2 0x00004000
232 #define UDMA_ARB_4 0x00008000
233 #define UDMA_ARB_8 0x0000c000
234 #define UDMA_ARB_16 0x00010000
235 #define UDMA_ARB_32 0x00014000
236 #define UDMA_ARB_64 0x00018000
237 #define UDMA_ARB_128 0x0001c000
238 #define UDMA_ARB_256 0x00020000
239 #define UDMA_ARB_512 0x00024000
240 #define UDMA_ARB_1024 0x00028000
241 #define UDMA_ARB_M 0x0003C000 // Arbitration Size
242 #define UDMA_ARB_S 14
243 #define UDMA_NEXT_USEBURST 0x00000008
244 #define UDMA_XFER_SIZE_MAX 1024
245 #define UDMA_XFER_SIZE_M 0x00003FF0 // Transfer size
246 #define UDMA_XFER_SIZE_S 4
247 
248 //*****************************************************************************
249 //
250 // Channel numbers to be passed to API functions that require a channel number
251 // ID. On CC27xx each uDMA channel is multiplexed between two different
252 // peripherals. The 1-to-1 mapping between UDMA channel and peripheral must be
253 // decided by the user and set in the event fabric registers EVTSVT.DMACH[x]SEL.
254 // The two valid peripherals for each channel are listed next to each channel's
255 // mask definition.
256 //
257 //*****************************************************************************
258 #define UDMA_CHANNEL_0_M 0x001
259 #define UDMA_CHANNEL_1_M 0x002
260 #define UDMA_CHANNEL_2_M 0x004
261 #define UDMA_CHANNEL_3_M 0x008
262 #define UDMA_CHANNEL_4_M 0x010
263 #define UDMA_CHANNEL_5_M 0x020
264 #define UDMA_CHANNEL_6_M 0x040
265 #define UDMA_CHANNEL_7_M 0x080
266 #define UDMA_CHANNEL_8_M 0x100
267 #define UDMA_CHANNEL_9_M 0x200
268 #define UDMA_CHANNEL_10_M 0x400
269 #define UDMA_CHANNEL_11_M 0x800
270 
271 //*****************************************************************************
272 //
273 // Flags to be OR'd with the channel ID to indicate if the primary or alternate
274 // control structure should be used.
275 //
276 //*****************************************************************************
277 #define UDMA_PRI_SELECT 0x00000000
278 #define UDMA_ALT_SELECT 0x00000010
279 
280 //*****************************************************************************
281 //
282 // API Functions and prototypes
283 //
284 //*****************************************************************************
285 
286 //*****************************************************************************
287 //
294 //
295 //*****************************************************************************
297 {
298  // Set the master enable bit in the config register.
299  HWREG(DMA_BASE + DMA_O_CFG) = DMA_CFG_MASTERENABLE;
300 }
301 
302 //*****************************************************************************
303 //
310 //
311 //*****************************************************************************
313 {
314  // Clear the master enable bit in the config register.
315  HWREG(DMA_BASE + DMA_O_CFG) = 0;
316 }
317 
318 //*****************************************************************************
319 //
327 //
328 //*****************************************************************************
330 {
331  // Return the uDMA error status.
332  return (HWREG(DMA_BASE + DMA_O_ERROR));
333 }
334 
335 //*****************************************************************************
336 //
343 //
344 //*****************************************************************************
346 {
347  // Clear the uDMA error interrupt.
348  HWREG(DMA_BASE + DMA_O_ERROR) = DMA_ERROR_STATUS;
349 }
350 
351 //*****************************************************************************
352 //
366 //
367 //*****************************************************************************
368 __STATIC_INLINE void uDMAEnableChannel(uint32_t channelBitMask)
369 {
370  HWREG(DMA_BASE + DMA_O_SETCHANNELEN) = channelBitMask;
371 }
372 
373 //*****************************************************************************
374 //
384 //
385 //*****************************************************************************
386 __STATIC_INLINE void uDMADisableChannel(uint32_t channelBitMask)
387 {
388  HWREG(DMA_BASE + DMA_O_CLEARCHANNELEN) = channelBitMask;
389 }
390 
391 //*****************************************************************************
392 //
406 //
407 //*****************************************************************************
408 __STATIC_INLINE bool uDMAIsChannelEnabled(uint32_t channelBitMask)
409 {
410  return ((HWREG(DMA_BASE + DMA_O_SETCHANNELEN) & (channelBitMask)) ? true : false);
411 }
412 
413 //*****************************************************************************
414 //
438 //
439 //*****************************************************************************
440 __STATIC_INLINE void uDMASetControlBase(void *pControlTable)
441 {
442  // Check the arguments.
443  ASSERT(((uint32_t)pControlTable & ~0x3FF) == (uint32_t)pControlTable);
444  ASSERT((uint32_t)pControlTable >= SRAM_BASE);
445 
446  // Program the base address into the register.
447  HWREG(DMA_BASE + DMA_O_CTRL) = (uint32_t)pControlTable;
448 }
449 
450 //*****************************************************************************
451 //
459 //
460 //*****************************************************************************
462 {
463  // Read the current value of the control base register, and return it to
464  // the caller.
465  return ((void *)HWREG(DMA_BASE + DMA_O_CTRL));
466 }
467 
468 //*****************************************************************************
469 //
477 //
478 //*****************************************************************************
480 {
481  // Read the current value of the control base register, and return it to
482  // the caller.
483  return ((void *)HWREG(DMA_BASE + DMA_O_ALTCTRL));
484 }
485 
486 //*****************************************************************************
487 //
504 //
505 //*****************************************************************************
506 __STATIC_INLINE void uDMARequestChannel(uint32_t channelBitMask)
507 {
508  // Set the bit for this channel in the software uDMA request register.
509  HWREG(DMA_BASE + DMA_O_SOFTREQ) = channelBitMask;
510 }
511 
512 //*****************************************************************************
513 //
529 //
530 //*****************************************************************************
531 extern void uDMAEnableChannelAttribute(uint32_t channelBitMask, uint32_t attr);
532 
533 //*****************************************************************************
534 //
550 //
551 //*****************************************************************************
552 extern void uDMADisableChannelAttribute(uint32_t channelBitMask, uint32_t attr);
553 
554 //*****************************************************************************
555 //
571 //
572 //*****************************************************************************
573 extern uint32_t uDMAGetChannelAttribute(uint32_t channelBitMask);
574 
575 //*****************************************************************************
576 //
613 //
614 //*****************************************************************************
615 extern void uDMASetChannelControl(volatile uDMAControlTableEntry *pChannelControlStruct, uint32_t control);
616 
617 //*****************************************************************************
618 //
672 //
673 //*****************************************************************************
674 extern void uDMASetChannelTransfer(volatile uDMAControlTableEntry *pChannelControlStruct,
675  uint32_t mode,
676  void *pSrcAddr,
677  void *pDstAddr,
678  uint32_t transferSize);
679 
680 //*****************************************************************************
681 //
694 //
695 //*****************************************************************************
696 extern uint32_t uDMAGetChannelSize(volatile uDMAControlTableEntry const *pChannelControlStruct);
697 
698 //*****************************************************************************
699 //
717 //
718 //*****************************************************************************
719 extern uint32_t uDMAGetChannelMode(volatile uDMAControlTableEntry const *pChannelControlStruct);
720 
721 //*****************************************************************************
722 //
744 //
745 //*****************************************************************************
746 __STATIC_INLINE void uDMARegisterInt(uint32_t intChannel, void (*pfnHandler)(void))
747 {
748  // Check the arguments.
749  ASSERT(pfnHandler);
750  ASSERT(intChannel == INT_DMA_DONE_COMB);
751 
752  // Register the interrupt handler.
753  IntRegister(intChannel, pfnHandler);
754 
755  // Enable the memory management fault.
756  IntEnable(intChannel);
757 }
758 
759 //*****************************************************************************
760 //
774 //
775 //*****************************************************************************
776 __STATIC_INLINE void uDMAUnregisterInt(uint32_t intChannel)
777 {
778  // Check the arguments.
779  ASSERT(intChannel == INT_DMA_DONE_COMB);
780 
781  // Disable the interrupt.
782  IntDisable(intChannel);
783 
784  // Unregister the interrupt handler.
785  IntUnregister(intChannel);
786 }
787 
788 //*****************************************************************************
789 //
800 //
801 //*****************************************************************************
802 __STATIC_INLINE void uDMAClearInt(uint32_t channelBitMask)
803 {
804  // Clear the requested bits in the uDMA interrupt status register.
805  HWREG(DMA_BASE + DMA_O_REQDONE) = channelBitMask;
806 }
807 
808 //*****************************************************************************
809 //
817 //
818 //*****************************************************************************
820 {
821  // Return the uDMA interrupt status register.
822  return (HWREG(DMA_BASE + DMA_O_REQDONE));
823 }
824 
825 //*****************************************************************************
826 //
840 //
841 //*****************************************************************************
842 __STATIC_INLINE void uDMAEnableSwEventInt(uint32_t intChannel)
843 {
844  // Check the arguments.
845  ASSERT(intChannel < UDMA_NUM_CHANNELS);
846 
847  // Enable the channel.
848  HWREG(DMA_BASE + DMA_O_DONEMASK) |= intChannel;
849 }
850 
851 //*****************************************************************************
852 //
864 //
865 //*****************************************************************************
866 __STATIC_INLINE void uDMADisableSwEventInt(uint32_t intChannel)
867 {
868  // Check the arguments.
869  ASSERT(intChannel < UDMA_NUM_CHANNELS);
870 
871  // Disable the SW channel.
872  HWREG(DMA_BASE + DMA_O_DONEMASK) &= ~intChannel;
873 }
874 
875 //*****************************************************************************
876 //
882 //
883 //*****************************************************************************
885 {
886  // Read and return the status register.
887  return HWREG(DMA_BASE + DMA_O_STATUS);
888 }
889 
890 //*****************************************************************************
891 //
900 //
901 //*****************************************************************************
902 __STATIC_INLINE void uDMASetChannelPriority(uint32_t channelBitMask)
903 {
904  // Set the channel priority to high.
905  HWREG(DMA_BASE + DMA_O_SETCHNLPRIORITY) = channelBitMask;
906 }
907 
908 //*****************************************************************************
909 //
917 //
918 //*****************************************************************************
919 __STATIC_INLINE bool uDMAGetChannelPriority(uint32_t channelBitMask)
920 {
921  // Return the channel priority.
922  return (HWREG(DMA_BASE + DMA_O_SETCHNLPRIORITY) & (channelBitMask) ? UDMA_PRIORITY_HIGH : UDMA_PRIORITY_LOW);
923 }
924 
925 //*****************************************************************************
926 //
935 //
936 //*****************************************************************************
937 __STATIC_INLINE void uDMAClearChannelPriority(uint32_t channelBitMask)
938 {
939  // Clear the channel priority.
940  HWREG(DMA_BASE + DMA_O_CLEARCHNLPRIORITY) = channelBitMask;
941 }
942 
943 //*****************************************************************************
944 //
945 // Mark the end of the C bindings section for C++ compilers.
946 //
947 //*****************************************************************************
948 #ifdef __cplusplus
949 }
950 #endif
951 
952 //*****************************************************************************
953 //
957 //
958 //*****************************************************************************
959 
960 #endif // __UDMA_H__
void uDMASetChannelControl(volatile uDMAControlTableEntry *pChannelControlStruct, uint32_t control)
Sets the control parameters for a uDMA channel control structure.
Definition: udma.c:152
#define UDMA_NUM_CHANNELS
Definition: udma.h:171
void IntEnable(uint32_t intNum)
Enables an interrupt or system exception.
Definition: interrupt.c:223
__STATIC_INLINE void uDMAEnable(void)
Enables the uDMA controller for use.
Definition: udma.h:296
volatile uint32_t control
The channel control mode.
Definition: udma.h:79
__STATIC_INLINE void uDMAClearErrorStatus(void)
Clears the uDMA error interrupt.
Definition: udma.h:345
__STATIC_INLINE uint32_t uDMAGetErrorStatus(void)
Gets the uDMA error status.
Definition: udma.h:329
#define UDMA_PRIORITY_LOW
Definition: udma.h:178
__STATIC_INLINE void * uDMAGetControlBase(void)
Gets the base address for the channel control table.
Definition: udma.h:461
__STATIC_INLINE void uDMASetControlBase(void *pControlTable)
Sets the base address for the channel control table.
Definition: udma.h:440
volatile void * pDstEndAddr
The ending destination address of the data transfer.
Definition: udma.h:78
__STATIC_INLINE void uDMADisable(void)
Disables the uDMA controller for use.
Definition: udma.h:312
__STATIC_INLINE void uDMAEnableChannel(uint32_t channelBitMask)
Enables a uDMA channel for operation.
Definition: udma.h:368
__STATIC_INLINE void uDMAClearChannelPriority(uint32_t channelBitMask)
Clear the priority of a uDMA channel.
Definition: udma.h:937
__STATIC_INLINE bool uDMAGetChannelPriority(uint32_t channelBitMask)
Get the priority of a uDMA channel.
Definition: udma.h:919
volatile uint32_t spare
An unused location.
Definition: udma.h:80
__STATIC_INLINE void * uDMAGetControlAlternateBase(void)
Gets the base address for the channel control table alternate structures.
Definition: udma.h:479
__STATIC_INLINE void uDMARegisterInt(uint32_t intChannel, void(*pfnHandler)(void))
Registers an interrupt handler for the uDMA controller in the dynamic interrupt table.
Definition: udma.h:746
uint32_t uDMAGetChannelSize(volatile uDMAControlTableEntry const *pChannelControlStruct)
Gets the current transfer size for a uDMA channel control structure.
Definition: udma.c:275
__STATIC_INLINE void uDMAUnregisterInt(uint32_t intChannel)
Unregisters an interrupt handler for the uDMA controller in the dynamic interrupt table...
Definition: udma.h:776
__STATIC_INLINE void uDMADisableSwEventInt(uint32_t intChannel)
Disable interrupt on software event driven uDMA transfers.
Definition: udma.h:866
__STATIC_INLINE void uDMARequestChannel(uint32_t channelBitMask)
Requests a uDMA channel to start a transfer.
Definition: udma.h:506
__STATIC_INLINE void uDMAEnableSwEventInt(uint32_t intChannel)
Enable interrupt on software event driven uDMA transfers.
Definition: udma.h:842
#define ASSERT(expr)
Definition: debug.h:71
void uDMADisableChannelAttribute(uint32_t channelBitMask, uint32_t attr)
Disables attributes of an uDMA channel.
Definition: udma.c:79
__STATIC_INLINE void uDMADisableChannel(uint32_t channelBitMask)
Disables a uDMA channel for operation.
Definition: udma.h:386
uint32_t uDMAGetChannelMode(volatile uDMAControlTableEntry const *pChannelControlStruct)
Gets the transfer mode for a uDMA channel control structure.
Definition: udma.c:307
A structure that defines an entry in the channel control table.
Definition: udma.h:75
__STATIC_INLINE uint32_t uDMAGetStatus(void)
Return the status of the uDMA module.
Definition: udma.h:884
void IntUnregister(uint32_t intNum)
Unregisters an interrupt handler in the dynamic vector table.
Definition: interrupt.c:124
__STATIC_INLINE bool uDMAIsChannelEnabled(uint32_t channelBitMask)
Checks if a uDMA channel is enabled for operation.
Definition: udma.h:408
void IntRegister(uint32_t intNum, void(*handler)(void))
Registers a function as an interrupt handler in the dynamic vector table.
__STATIC_INLINE uint32_t uDMAIntStatus(void)
Get the uDMA interrupt status.
Definition: udma.h:819
void uDMASetChannelTransfer(volatile uDMAControlTableEntry *pChannelControlStruct, uint32_t mode, void *pSrcAddr, void *pDstAddr, uint32_t transferSize)
Sets the transfer parameters for a uDMA channel control structure.
Definition: udma.c:170
__STATIC_INLINE void uDMAClearInt(uint32_t channelBitMask)
Clears uDMA interrupt done status.
Definition: udma.h:802
uint32_t uDMAGetChannelAttribute(uint32_t channelBitMask)
Gets the enabled attributes of a uDMA channel.
Definition: udma.c:115
#define __STATIC_INLINE
Definition: cmsis_gcc.h:47
volatile void * pSrcEndAddr
The ending source address of the data transfer.
Definition: udma.h:77
void IntDisable(uint32_t intNum)
Disables an interrupt or system exception.
Definition: interrupt.c:249
void uDMAEnableChannelAttribute(uint32_t channelBitMask, uint32_t attr)
Enables attributes of a uDMA channel.
Definition: udma.c:43
#define UDMA_PRIORITY_HIGH
Definition: udma.h:179
__STATIC_INLINE void uDMASetChannelPriority(uint32_t channelBitMask)
Set the priority of a uDMA channel.
Definition: udma.h:902