CC23x0R5DriverLibrary
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 CC23x0 each uDMA channel is multiplexed between one or 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 0x01
259 #define UDMA_CHANNEL_1_M 0x02
260 #define UDMA_CHANNEL_2_M 0x04
261 #define UDMA_CHANNEL_3_M 0x08
262 #define UDMA_CHANNEL_4_M 0x10
263 #define UDMA_CHANNEL_5_M 0x20
264 #define UDMA_CHANNEL_6_M 0x40
265 #define UDMA_CHANNEL_7_M 0x80
266 
267 //*****************************************************************************
268 //
269 // Flags to be OR'd with the channel ID to indicate if the primary or alternate
270 // control structure should be used.
271 //
272 //*****************************************************************************
273 #define UDMA_PRI_SELECT 0x00000000
274 #define UDMA_ALT_SELECT 0x00000008
275 
276 //*****************************************************************************
277 //
278 // API Functions and prototypes
279 //
280 //*****************************************************************************
281 
282 //*****************************************************************************
283 //
290 //
291 //*****************************************************************************
293 {
294  // Set the master enable bit in the config register.
295  HWREG(DMA_BASE + DMA_O_CFG) = DMA_CFG_MASTERENABLE;
296 }
297 
298 //*****************************************************************************
299 //
306 //
307 //*****************************************************************************
309 {
310  // Clear the master enable bit in the config register.
311  HWREG(DMA_BASE + DMA_O_CFG) = 0;
312 }
313 
314 //*****************************************************************************
315 //
323 //
324 //*****************************************************************************
326 {
327  // Return the uDMA error status.
328  return (HWREG(DMA_BASE + DMA_O_ERROR));
329 }
330 
331 //*****************************************************************************
332 //
339 //
340 //*****************************************************************************
342 {
343  // Clear the uDMA error interrupt.
344  HWREG(DMA_BASE + DMA_O_ERROR) = DMA_ERROR_STATUS;
345 }
346 
347 //*****************************************************************************
348 //
362 //
363 //*****************************************************************************
364 __STATIC_INLINE void uDMAEnableChannel(uint32_t channelBitMask)
365 {
366  HWREG(DMA_BASE + DMA_O_SETCHANNELEN) = channelBitMask;
367 }
368 
369 //*****************************************************************************
370 //
380 //
381 //*****************************************************************************
382 __STATIC_INLINE void uDMADisableChannel(uint32_t channelBitMask)
383 {
384  HWREG(DMA_BASE + DMA_O_CLEARCHANNELEN) = channelBitMask;
385 }
386 
387 //*****************************************************************************
388 //
402 //
403 //*****************************************************************************
404 __STATIC_INLINE bool uDMAIsChannelEnabled(uint32_t channelBitMask)
405 {
406  return ((HWREG(DMA_BASE + DMA_O_SETCHANNELEN) & (channelBitMask)) ? true : false);
407 }
408 
409 //*****************************************************************************
410 //
434 //
435 //*****************************************************************************
436 __STATIC_INLINE void uDMASetControlBase(void *pControlTable)
437 {
438  // Check the arguments.
439  ASSERT(((uint32_t)pControlTable & ~0x3FF) == (uint32_t)pControlTable);
440  ASSERT((uint32_t)pControlTable >= SRAM_BASE);
441 
442  // Program the base address into the register.
443  HWREG(DMA_BASE + DMA_O_CTRL) = (uint32_t)pControlTable;
444 }
445 
446 //*****************************************************************************
447 //
455 //
456 //*****************************************************************************
458 {
459  // Read the current value of the control base register, and return it to
460  // the caller.
461  return ((void *)HWREG(DMA_BASE + DMA_O_CTRL));
462 }
463 
464 //*****************************************************************************
465 //
473 //
474 //*****************************************************************************
476 {
477  // Read the current value of the control base register, and return it to
478  // the caller.
479  return ((void *)HWREG(DMA_BASE + DMA_O_ALTCTRL));
480 }
481 
482 //*****************************************************************************
483 //
500 //
501 //*****************************************************************************
502 __STATIC_INLINE void uDMARequestChannel(uint32_t channelBitMask)
503 {
504  // Set the bit for this channel in the software uDMA request register.
505  HWREG(DMA_BASE + DMA_O_SOFTREQ) = channelBitMask;
506 }
507 
508 //*****************************************************************************
509 //
525 //
526 //*****************************************************************************
527 extern void uDMAEnableChannelAttribute(uint32_t channelBitMask, uint32_t attr);
528 
529 //*****************************************************************************
530 //
546 //
547 //*****************************************************************************
548 extern void uDMADisableChannelAttribute(uint32_t channelBitMask, uint32_t attr);
549 
550 //*****************************************************************************
551 //
567 //
568 //*****************************************************************************
569 extern uint32_t uDMAGetChannelAttribute(uint32_t channelBitMask);
570 
571 //*****************************************************************************
572 //
609 //
610 //*****************************************************************************
611 extern void uDMASetChannelControl(volatile uDMAControlTableEntry *pChannelControlStruct, uint32_t control);
612 
613 //*****************************************************************************
614 //
668 //
669 //*****************************************************************************
670 extern void uDMASetChannelTransfer(volatile uDMAControlTableEntry *pChannelControlStruct,
671  uint32_t mode,
672  void *pSrcAddr,
673  void *pDstAddr,
674  uint32_t transferSize);
675 
676 //*****************************************************************************
677 //
690 //
691 //*****************************************************************************
692 extern uint32_t uDMAGetChannelSize(volatile uDMAControlTableEntry const *pChannelControlStruct);
693 
694 //*****************************************************************************
695 //
713 //
714 //*****************************************************************************
715 extern uint32_t uDMAGetChannelMode(volatile uDMAControlTableEntry const *pChannelControlStruct);
716 
717 //*****************************************************************************
718 //
740 //
741 //*****************************************************************************
742 __STATIC_INLINE void uDMARegisterInt(uint32_t intChannel, void (*pfnHandler)(void))
743 {
744  // Check the arguments.
745  ASSERT(pfnHandler);
746  ASSERT(intChannel == INT_DMA_DONE_COMB);
747 
748  // Register the interrupt handler.
749  IntRegister(intChannel, pfnHandler);
750 
751  // Enable the memory management fault.
752  IntEnable(intChannel);
753 }
754 
755 //*****************************************************************************
756 //
770 //
771 //*****************************************************************************
772 __STATIC_INLINE void uDMAUnregisterInt(uint32_t intChannel)
773 {
774  // Check the arguments.
775  ASSERT(intChannel == INT_DMA_DONE_COMB);
776 
777  // Disable the interrupt.
778  IntDisable(intChannel);
779 
780  // Unregister the interrupt handler.
781  IntUnregister(intChannel);
782 }
783 
784 //*****************************************************************************
785 //
796 //
797 //*****************************************************************************
798 __STATIC_INLINE void uDMAClearInt(uint32_t channelBitMask)
799 {
800  // Clear the requested bits in the uDMA interrupt status register.
801  HWREG(DMA_BASE + DMA_O_REQDONE) = channelBitMask;
802 }
803 
804 //*****************************************************************************
805 //
813 //
814 //*****************************************************************************
816 {
817  // Return the uDMA interrupt status register.
818  return (HWREG(DMA_BASE + DMA_O_REQDONE));
819 }
820 
821 //*****************************************************************************
822 //
836 //
837 //*****************************************************************************
838 __STATIC_INLINE void uDMAEnableSwEventInt(uint32_t intChannel)
839 {
840  // Check the arguments.
841  ASSERT(intChannel < UDMA_NUM_CHANNELS);
842 
843  // Enable the channel.
844  HWREG(DMA_BASE + DMA_O_DONEMASK) |= intChannel;
845 }
846 
847 //*****************************************************************************
848 //
860 //
861 //*****************************************************************************
862 __STATIC_INLINE void uDMADisableSwEventInt(uint32_t intChannel)
863 {
864  // Check the arguments.
865  ASSERT(intChannel < UDMA_NUM_CHANNELS);
866 
867  // Disable the SW channel.
868  HWREG(DMA_BASE + DMA_O_DONEMASK) &= ~intChannel;
869 }
870 
871 //*****************************************************************************
872 //
878 //
879 //*****************************************************************************
881 {
882  // Read and return the status register.
883  return HWREG(DMA_BASE + DMA_O_STATUS);
884 }
885 
886 //*****************************************************************************
887 //
896 //
897 //*****************************************************************************
898 __STATIC_INLINE void uDMASetChannelPriority(uint32_t channelBitMask)
899 {
900  // Set the channel priority to high.
901  HWREG(DMA_BASE + DMA_O_SETCHNLPRIORITY) = channelBitMask;
902 }
903 
904 //*****************************************************************************
905 //
913 //
914 //*****************************************************************************
915 __STATIC_INLINE bool uDMAGetChannelPriority(uint32_t channelBitMask)
916 {
917  // Return the channel priority.
918  return (HWREG(DMA_BASE + DMA_O_SETCHNLPRIORITY) & (channelBitMask) ? UDMA_PRIORITY_HIGH : UDMA_PRIORITY_LOW);
919 }
920 
921 //*****************************************************************************
922 //
931 //
932 //*****************************************************************************
933 __STATIC_INLINE void uDMAClearChannelPriority(uint32_t channelBitMask)
934 {
935  // Clear the channel priority.
936  HWREG(DMA_BASE + DMA_O_CLEARCHNLPRIORITY) = channelBitMask;
937 }
938 
939 //*****************************************************************************
940 //
941 // Mark the end of the C bindings section for C++ compilers.
942 //
943 //*****************************************************************************
944 #ifdef __cplusplus
945 }
946 #endif
947 
948 //*****************************************************************************
949 //
953 //
954 //*****************************************************************************
955 
956 #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:250
__STATIC_INLINE void uDMAEnable(void)
Enables the uDMA controller for use.
Definition: udma.h:292
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:341
__STATIC_INLINE uint32_t uDMAGetErrorStatus(void)
Gets the uDMA error status.
Definition: udma.h:325
#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:457
__STATIC_INLINE void uDMASetControlBase(void *pControlTable)
Sets the base address for the channel control table.
Definition: udma.h:436
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:308
__STATIC_INLINE void uDMAEnableChannel(uint32_t channelBitMask)
Enables a uDMA channel for operation.
Definition: udma.h:364
__STATIC_INLINE void uDMAClearChannelPriority(uint32_t channelBitMask)
Clear the priority of a uDMA channel.
Definition: udma.h:933
__STATIC_INLINE bool uDMAGetChannelPriority(uint32_t channelBitMask)
Get the priority of a uDMA channel.
Definition: udma.h:915
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:475
__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:742
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:772
__STATIC_INLINE void uDMADisableSwEventInt(uint32_t intChannel)
Disable interrupt on software event driven uDMA transfers.
Definition: udma.h:862
__STATIC_INLINE void uDMARequestChannel(uint32_t channelBitMask)
Requests a uDMA channel to start a transfer.
Definition: udma.h:502
__STATIC_INLINE void uDMAEnableSwEventInt(uint32_t intChannel)
Enable interrupt on software event driven uDMA transfers.
Definition: udma.h:838
#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:382
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:880
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:404
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:815
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:798
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:273
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:898