CC35xxDriverLibrary
dma.h
Go to the documentation of this file.
1 /******************************************************************************
2  * Filename: dma.h
3  *
4  * Description: Defines and prototypes for the DMA peripheral.
5  *
6  * Copyright (c) 2022-2025 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 __DMA_H__
37 #define __DMA_H__
38 
39 //*****************************************************************************
40 //
45 //
46 //*****************************************************************************
47 
48 #include "../inc/hw_types.h"
49 #include "../inc/hw_memmap.h"
50 #include "../inc/hw_host_dma.h"
51 #include "../inc/hw_soc_aaon.h"
52 #include "../inc/hw_soc_aon.h"
53 #include "debug.h"
54 
55 //*****************************************************************************
56 //
57 // If building with a C++ compiler, make all of the definitions in this header
58 // have a C binding.
59 //
60 //*****************************************************************************
61 #ifdef __cplusplus
62 extern "C" {
63 #endif
64 
66 #define DMA_NUM_CHANNELS 12
67 #define DMA_CH_OFFSET 0x1000
69 #define DMA_CHCTL_FIELD_WIDTH HOST_DMA_CHCTL0_CH0_W
71 #define DMA_CHCTRL_NUMBER_OF_FIELDS (32 / DMA_CHCTL_FIELD_WIDTH)
73 
74 //*****************************************************************************
75 //
76 // Configuration values that can be passed to DMAConfigureChannel() as the config parameter
77 //
78 //*****************************************************************************
81 #define DMA_CONFIG_SRC_PTR_WRAP HOST_DMA_CH0JCTL_BLKMODESRC
82 #define DMA_CONFIG_DST_PTR_WRAP HOST_DMA_CH0JCTL_BLKMODEDST
85 #define DMA_CONFIG_FORCE_REQ HOST_DMA_CH0JCTL_DMASIGBPS
88 #define DMA_CONFIG_SRC_PTR_FIFO HOST_DMA_CH0JCTL_FIFOMODS
90 #define DMA_CONFIG_DST_PTR_FIFO HOST_DMA_CH0JCTL_FIFOMODD
92 #define DMA_CONFIG_RX 0x00000000U
94 #define DMA_CONFIG_TX HOST_DMA_CH0JCTL_SRCDSTCFG
96 #define DMA_CONFIG_CLEAR_AT_JOB_START HOST_DMA_CH0JCTL_ENCLR
98 #define DMA_CONFIG_ALLOWED_MASK \
100  (DMA_CONFIG_SRC_PTR_WRAP | DMA_CONFIG_DST_PTR_WRAP | DMA_CONFIG_FORCE_REQ | DMA_CONFIG_SRC_PTR_FIFO | \
101  DMA_CONFIG_DST_PTR_FIFO | DMA_CONFIG_TX | DMA_CONFIG_CLEAR_AT_JOB_START)
102 
103 //*****************************************************************************
104 //
105 // Word size values that can be passed to DMAConfigureChannel() as the wordSize parameter
106 //
107 //*****************************************************************************
109 #define DMA_WORD_SIZE_1B 2
110 #define DMA_WORD_SIZE_2B 1
112 #define DMA_WORD_SIZE_4B 0
114 
115 //*****************************************************************************
116 //
117 // Enumerations
118 //
119 //*****************************************************************************
120 // DMA peripheral mapping (source:
121 // https://confluence.itg.ti.com/display/WNG/Host+DMA#HostDMA-HostDMAAppendix1-Channelsallocation)
123 typedef enum
124 {
139 } DMAPeripheral;
140 
141 // TODO: Update to use DOC release defines when available (LPRFXXWARE-747)
142 typedef enum
143 {
149 
150 typedef enum
151 {
155 } DMACommand;
156 
157 //*****************************************************************************
158 //
159 // Functions
160 //
161 //*****************************************************************************
162 //*****************************************************************************
163 //
172 //
173 //*****************************************************************************
174 extern void DMAInitChannel(uint32_t channel, DMAPeripheral peripheral);
175 
176 //*****************************************************************************
177 //
213 //
214 //*****************************************************************************
215 extern void DMAConfigureChannel(uint32_t channel, uint8_t blockSize, uint8_t wordSize, uint32_t config);
216 
217 //*****************************************************************************
218 //
244 //
245 //*****************************************************************************
246 extern void DMAStartTransaction(uint32_t channel,
247  const uint32_t *srcStartAddr,
248  uint32_t *dstStartAddr,
249  uint16_t transLenByte,
250  bool remainingBytesBurst);
251 
252 //*****************************************************************************
253 //
259 //
260 //*****************************************************************************
261 extern uint32_t DMAGetChannelStatus(uint32_t channel);
262 
263 //*****************************************************************************
264 //
270 //
271 //*****************************************************************************
272 extern uint32_t DMAGetChannelDirection(uint32_t channel);
273 
274 //*****************************************************************************
275 //
288 //
289 //*****************************************************************************
290 __STATIC_INLINE void DMAEnableInt(uint32_t channelMask)
291 {
292  // Enable the specified interrupts.
293  HWREG(SOC_AAON_BASE + SOC_AAON_O_DMASIMASK) |= channelMask;
294 }
295 
296 //*****************************************************************************
297 //
310 //
311 //*****************************************************************************
312 __STATIC_INLINE void DMADisableInt(uint32_t channelMask)
313 {
314  // Disable the specified interrupts.
315  HWREG(SOC_AAON_BASE + SOC_AAON_O_DMASIMASK) &= ~(channelMask);
316 }
317 
318 //*****************************************************************************
319 //
331 //
332 //*****************************************************************************
333 __STATIC_INLINE void DMAClearInt(uint32_t channelMask)
334 {
335  // Clear the requested interrupt sources
336  HWREG(SOC_AAON_BASE + SOC_AAON_O_DMASICLR) = channelMask;
337 }
338 
339 //*****************************************************************************
340 //
354 //
355 //*****************************************************************************
356 __STATIC_INLINE uint32_t DMAIntStatus(bool masked)
357 {
358  // Return either the masked interrupt status or the raw interrupt status as
359  // requested.
360  if (masked)
361  {
363  }
364  else
365  {
367  }
368 }
369 
370 //*****************************************************************************
371 //
401 //
402 //*****************************************************************************
403 __STATIC_INLINE void DMAConfigureChannelFlags(uint32_t channel, uint32_t config)
404 {
405  // Check arguments
406  ASSERT(channel < DMA_NUM_CHANNELS);
407  // Check allowed flags and not allowed flags
408  ASSERT((~(DMA_CONFIG_ALLOWED_MASK)&config) == 0);
409 
410  uint32_t regOffset = channel * DMA_CH_OFFSET;
411  uint32_t configReg = HWREG(HOST_DMA_TGT_BASE + HOST_DMA_O_CH0JCTL + regOffset);
412 
413  // Clear flags
414  configReg &= ~DMA_CONFIG_ALLOWED_MASK;
415 
416  // Incorporate flags to configuration value
417  configReg |= config;
418 
419  // Write configuration to hardware
420  HWREG(HOST_DMA_TGT_BASE + HOST_DMA_O_CH0JCTL + regOffset) = configReg;
421 }
422 
423 //*****************************************************************************
424 //
432 //
433 //*****************************************************************************
435 {
436  // Check arguments
437  ASSERT(channel < DMA_NUM_CHANNELS);
438 
439  uint32_t regOffset = channel * DMA_CH_OFFSET;
440 
442 }
443 
444 //*****************************************************************************
445 //
454 //
455 //*****************************************************************************
457 {
458  // Check arguments
459  ASSERT(channel < DMA_NUM_CHANNELS);
460 
461  uint32_t regOffset = channel * DMA_CH_OFFSET;
462 
464 }
465 
466 //*****************************************************************************
467 //
476 //
477 //*****************************************************************************
478 __STATIC_INLINE uint32_t DMAGetChannelPeripheral(uint32_t channel)
479 {
480  uint32_t regOffset;
481  uint32_t shiftValue;
482  uint32_t channelReg;
483  uint32_t peripheral;
484 
485  // Calculate register offset (0/4) based on the channel number
486  regOffset = (channel / DMA_CHCTRL_NUMBER_OF_FIELDS) * sizeof(uint32_t);
487 
488  // Read register containing channel configuration
489  channelReg = HWREG(HOST_DMA_TGT_BASE + HOST_DMA_O_CHCTL0 + regOffset);
490 
491  // Calculate bitfield position based on the channel number
492  shiftValue = (channel % DMA_CHCTRL_NUMBER_OF_FIELDS) * DMA_CHCTL_FIELD_WIDTH;
493 
494  // Extract the peripheral
495  peripheral = (channelReg & (HOST_DMA_CHCTL0_CH0_M << shiftValue)) >> shiftValue;
496 
497  return peripheral;
498 }
499 
500 //*****************************************************************************
501 //
502 // Mark the end of the C bindings section for C++ compilers.
503 //
504 //*****************************************************************************
505 #ifdef __cplusplus
506 }
507 #endif
508 
509 //*****************************************************************************
510 //
514 //
515 //*****************************************************************************
516 
517 #endif // __DMA_H__
SPI1.
Definition: dma.h:128
#define DMA_CHCTL_FIELD_WIDTH
DMA channel control field width, in number of bits (CHCTL register)
Definition: dma.h:70
DMAPeripheral
DMA peripheral ports enumerations for use with DMAInitChannel().
Definition: dma.h:123
__STATIC_INLINE void DMAEnableDestinationFifoMode(uint32_t channel)
Enable FIFO mode behavior for the destination pointer.
Definition: dma.h:434
Transaction aborted by SW.
Definition: dma.h:146
PDM.
Definition: dma.h:135
#define SOC_AAON_BASE
Definition: hw_memmap.h:77
#define HOST_DMA_O_CHCTL0
Definition: hw_host_dma.h:45
#define HOST_DMA_TGT_BASE
Definition: hw_memmap.h:84
Transaction done.
Definition: dma.h:145
#define HWREG(x)
Definition: hw_types.h:78
#define __STATIC_INLINE
Definition: hw_types.h:57
DMACommand
Definition: dma.h:150
ADC.
Definition: dma.h:134
SPI0.
Definition: dma.h:127
uint32_t DMAGetChannelDirection(uint32_t channel)
Returns the direction of the specified channel.
Definition: dma.c:173
#define HOST_DMA_O_CH0JCTL
Definition: hw_host_dma.h:72
void DMAStartTransaction(uint32_t channel, const uint32_t *srcStartAddr, uint32_t *dstStartAddr, uint16_t transLenByte, bool remainingBytesBurst)
Start job for the specified channel.
Definition: dma.c:108
#define DMA_NUM_CHANNELS
Number of available DMA channels.
Definition: dma.h:66
Definition: dma.h:153
void DMAConfigureChannel(uint32_t channel, uint8_t blockSize, uint8_t wordSize, uint32_t config)
Configure job for the specified channel.
Definition: dma.c:84
SDMMC.
Definition: dma.h:131
__STATIC_INLINE void DMAEnableInt(uint32_t channelMask)
Enables DMA interrupt sources.
Definition: dma.h:290
#define DMA_CH_OFFSET
DMA channel memory map offset, in bytes.
Definition: dma.h:68
Number of different DMA peripherals supported.
Definition: dma.h:138
uint32_t DMAGetChannelStatus(uint32_t channel)
Returns the status of the specified channel.
Definition: dma.c:155
I2C0.
Definition: dma.h:129
UARTLIN0.
Definition: dma.h:125
void DMAInitChannel(uint32_t channel, DMAPeripheral peripheral)
Initialize DMA channel by mapping it to a peripheral.
Definition: dma.c:50
MCAN.
Definition: dma.h:133
I2C1.
Definition: dma.h:130
UARTLIN2.
Definition: dma.h:137
SDIO.
Definition: dma.h:132
#define DMA_CONFIG_ALLOWED_MASK
Bitmask of allowed flags passed to DMAConfigureChannel() and DMAConfigureChannelFlags().
Definition: dma.h:99
UARTLIN1.
Definition: dma.h:126
Definition: dma.h:152
#define SOC_AAON_O_DMASMIS
Definition: hw_soc_aaon.h:63
__STATIC_INLINE void DMADisableDestinationFifoMode(uint32_t channel)
Disable FIFO mode behavior for the destination pointer.
Definition: dma.h:456
#define ASSERT(expr)
Definition: debug.h:81
__STATIC_INLINE uint32_t DMAGetChannelPeripheral(uint32_t channel)
Get channel linked peripheral.
Definition: dma.h:478
Definition: dma.h:154
__STATIC_INLINE void DMAConfigureChannelFlags(uint32_t channel, uint32_t config)
Clear all flags and set the specified channel flags.
Definition: dma.h:403
#define SOC_AAON_O_DMASICLR
Definition: hw_soc_aaon.h:51
HIF.
Definition: dma.h:136
No pending event // TODO: hw_ doc calls this "processing".
Definition: dma.h:144
__STATIC_INLINE uint32_t DMAIntStatus(bool masked)
Gets the current interrupt status.
Definition: dma.h:356
#define HOST_DMA_CH0JCTL_FIFOMODD
Definition: hw_host_dma.h:1700
DMAChannelStatus
Definition: dma.h:142
#define DMA_CHCTRL_NUMBER_OF_FIELDS
Number of fields in CHCTL register.
Definition: dma.h:72
#define SOC_AAON_O_DMASIMASK
Definition: hw_soc_aaon.h:45
__STATIC_INLINE void DMAClearInt(uint32_t channelMask)
Clears DMA interrupt sources.
Definition: dma.h:333
An error has occurred.
Definition: dma.h:147
__STATIC_INLINE void DMADisableInt(uint32_t channelMask)
Disables DMA channel interrupts.
Definition: dma.h:312