G32R430 Device Driver Layer v1.0.4
G32R4xx Device Driver Layer API Reference
g32r4xx_ddl_dma.c
Go to the documentation of this file.
1
43#if defined(USE_FULL_DDL_DRIVER)
44
45/* Includes ------------------------------------------------------------------*/
46#include "g32r4xx_ddl_dma.h"
47#include "g32r4xx_ddl_rcm.h"
48#ifdef USE_FULL_ASSERT
49#include "g32_assert.h"
50#else
51#define ASSERT_PARAM(_PARAM_) ((void)0U)
52#endif
53
57
58#if defined (DMA1)
59
63
64/* Private types -------------------------------------------------------------*/
65/* Private variables ---------------------------------------------------------*/
66/* Private constants ---------------------------------------------------------*/
67/* Private macros ------------------------------------------------------------*/
71#define IS_DDL_DMA_DIRECTION(__VALUE__) (((__VALUE__) == DDL_DMA_DIRECTION_PERIPH_TO_MEMORY) || \
72 ((__VALUE__) == DDL_DMA_DIRECTION_MEMORY_TO_PERIPH) || \
73 ((__VALUE__) == DDL_DMA_DIRECTION_MEMORY_TO_MEMORY))
74
75#define IS_DDL_DMA_MODE(__VALUE__) (((__VALUE__) == DDL_DMA_MODE_NORMAL) || \
76 ((__VALUE__) == DDL_DMA_MODE_CIRCULAR) || \
77 ((__VALUE__) == DDL_DMA_MODE_PFCTRL))
78
79#define IS_DDL_DMA_PERIPHINCMODE(__VALUE__) (((__VALUE__) == DDL_DMA_PERIPH_INCREMENT) || \
80 ((__VALUE__) == DDL_DMA_PERIPH_NOINCREMENT))
81
82#define IS_DDL_DMA_MEMORYINCMODE(__VALUE__) (((__VALUE__) == DDL_DMA_MEMORY_INCREMENT) || \
83 ((__VALUE__) == DDL_DMA_MEMORY_NOINCREMENT))
84
85#define IS_DDL_DMA_PERIPHDATASIZE(__VALUE__) (((__VALUE__) == DDL_DMA_PDATAALIGN_BYTE) || \
86 ((__VALUE__) == DDL_DMA_PDATAALIGN_HALFWORD) || \
87 ((__VALUE__) == DDL_DMA_PDATAALIGN_WORD))
88
89#define IS_DDL_DMA_MEMORYDATASIZE(__VALUE__) (((__VALUE__) == DDL_DMA_MDATAALIGN_BYTE) || \
90 ((__VALUE__) == DDL_DMA_MDATAALIGN_HALFWORD) || \
91 ((__VALUE__) == DDL_DMA_MDATAALIGN_WORD))
92
93#define IS_DDL_DMA_NBDATA(__VALUE__) ((__VALUE__) <= 0x0000FFFFU)
94
95#define IS_DDL_DMA_CHANNEL(__VALUE__) (((__VALUE__) == DDL_DMA_CHANNEL_0) || \
96 ((__VALUE__) == DDL_DMA_CHANNEL_1) || \
97 ((__VALUE__) == DDL_DMA_CHANNEL_2) || \
98 ((__VALUE__) == DDL_DMA_CHANNEL_3) || \
99 ((__VALUE__) == DDL_DMA_CHANNEL_4) || \
100 ((__VALUE__) == DDL_DMA_CHANNEL_5) || \
101 ((__VALUE__) == DDL_DMA_CHANNEL_6) || \
102 ((__VALUE__) == DDL_DMA_CHANNEL_7))
103
104#define IS_DDL_DMA_PRIORITY(__VALUE__) (((__VALUE__) == DDL_DMA_PRIORITY_LOW) || \
105 ((__VALUE__) == DDL_DMA_PRIORITY_MEDIUM) || \
106 ((__VALUE__) == DDL_DMA_PRIORITY_HIGH) || \
107 ((__VALUE__) == DDL_DMA_PRIORITY_VERYHIGH))
108
109#define IS_DDL_DMA_ALL_STREAM_INSTANCE(INSTANCE, STREAM) ((((INSTANCE) == DMA1) && \
110 (((STREAM) == DDL_DMA_STREAM_0) || \
111 ((STREAM) == DDL_DMA_STREAM_1) || \
112 ((STREAM) == DDL_DMA_STREAM_2) || \
113 ((STREAM) == DDL_DMA_STREAM_3) || \
114 ((STREAM) == DDL_DMA_STREAM_4) || \
115 ((STREAM) == DDL_DMA_STREAM_5) || \
116 ((STREAM) == DDL_DMA_STREAM_6) || \
117 ((STREAM) == DDL_DMA_STREAM_7) || \
118 ((STREAM) == DDL_DMA_STREAM_ALL))))
119
120#define IS_DDL_DMA_FIFO_MODE_STATE(STATE) (((STATE) == DDL_DMA_FIFOMODE_DISABLE ) || \
121 ((STATE) == DDL_DMA_FIFOMODE_ENABLE))
122
123#define IS_DDL_DMA_FIFO_THRESHOLD(THRESHOLD) (((THRESHOLD) == DDL_DMA_FIFOTHRESHOLD_1_4) || \
124 ((THRESHOLD) == DDL_DMA_FIFOTHRESHOLD_1_2) || \
125 ((THRESHOLD) == DDL_DMA_FIFOTHRESHOLD_3_4) || \
126 ((THRESHOLD) == DDL_DMA_FIFOTHRESHOLD_FULL))
127
128#define IS_DDL_DMA_MEMORY_BURST(BURST) (((BURST) == DDL_DMA_MBURST_SINGLE) || \
129 ((BURST) == DDL_DMA_MBURST_INC4) || \
130 ((BURST) == DDL_DMA_MBURST_INC8) || \
131 ((BURST) == DDL_DMA_MBURST_INC16))
132
133#define IS_DDL_DMA_PERIPHERAL_BURST(BURST) (((BURST) == DDL_DMA_PBURST_SINGLE) || \
134 ((BURST) == DDL_DMA_PBURST_INC4) || \
135 ((BURST) == DDL_DMA_PBURST_INC8) || \
136 ((BURST) == DDL_DMA_PBURST_INC16))
137
141
142/* Private function prototypes -----------------------------------------------*/
143
144/* Exported functions --------------------------------------------------------*/
148
152
170uint32_t DDL_DMA_DeInit(DMA_TypeDef *DMAx, uint32_t Stream)
171{
172 DMA_Stream_TypeDef *tmp = (DMA_Stream_TypeDef *)DMA1_Stream0;
173 ErrorStatus status = SUCCESS;
174
175 /* Check the DMA Instance DMAx and Stream parameters*/
177
178 if (Stream == DDL_DMA_STREAM_ALL)
179 {
181
182 /* Force reset of DMA clock */
184 }
185 else
186 {
187 /* Disable the selected Stream */
188 DDL_DMA_DisableStream(DMAx,Stream);
189
190 /* Get the DMA Stream Instance */
191 tmp = (DMA_Stream_TypeDef *)(__DDL_DMA_GET_STREAM_INSTANCE(DMAx, Stream));
192
193 /* Reset DMAx_Streamy configuration register */
194 DDL_DMA_WriteReg(tmp, SCFG, 0U);
195
196 /* Reset DMAx_Streamy remaining bytes register */
197 DDL_DMA_WriteReg(tmp, NDATA, 0U);
198
199 /* Reset DMAx_Streamy peripheral address register */
200 DDL_DMA_WriteReg(tmp, PADDR, 0U);
201
202 /* Reset DMAx_Streamy memory address register */
203 DDL_DMA_WriteReg(tmp, M0ADDR, 0U);
204
205 /* Reset DMAx_Streamy memory address register */
206 DDL_DMA_WriteReg(tmp, M1ADDR, 0U);
207
208 /* Reset DMAx_Streamy FIFO control register */
209 DDL_DMA_WriteReg(tmp, FCTRL, 0x00000021U);
210
211 /* Reset Channel register field for DMAx Stream*/
213
214 if(Stream == DDL_DMA_STREAM_0)
215 {
216 /* Reset the Stream0 pending flags */
217 DMAx->LIFCLR = 0x0000003FU;
218 }
219 else if(Stream == DDL_DMA_STREAM_1)
220 {
221 /* Reset the Stream1 pending flags */
222 DMAx->LIFCLR = 0x00000F40U;
223 }
224 else if(Stream == DDL_DMA_STREAM_2)
225 {
226 /* Reset the Stream2 pending flags */
227 DMAx->LIFCLR = 0x003F0000U;
228 }
229 else if(Stream == DDL_DMA_STREAM_3)
230 {
231 /* Reset the Stream3 pending flags */
232 DMAx->LIFCLR = 0x0F400000U;
233 }
234 else if(Stream == DDL_DMA_STREAM_4)
235 {
236 /* Reset the Stream4 pending flags */
237 DMAx->HIFCLR = 0x0000003FU;
238 }
239 else if(Stream == DDL_DMA_STREAM_5)
240 {
241 /* Reset the Stream5 pending flags */
242 DMAx->HIFCLR = 0x00000F40U;
243 }
244 else if(Stream == DDL_DMA_STREAM_6)
245 {
246 /* Reset the Stream6 pending flags */
247 DMAx->HIFCLR = 0x003F0000U;
248 }
249 else if(Stream == DDL_DMA_STREAM_7)
250 {
251 /* Reset the Stream7 pending flags */
252 DMAx->HIFCLR = 0x0F400000U;
253 }
254 else
255 {
256 status = ERROR;
257 }
258 }
259
260 return status;
261}
262
283uint32_t DDL_DMA_Init(DMA_TypeDef *DMAx, uint32_t Stream, DDL_DMA_InitTypeDef *DMA_InitStruct)
284{
285 /* Check the DMA Instance DMAx and Stream parameters*/
287
288 /* Check the DMA parameters from DMA_InitStruct */
290 ASSERT_PARAM(IS_DDL_DMA_MODE(DMA_InitStruct->Mode));
295 ASSERT_PARAM(IS_DDL_DMA_NBDATA(DMA_InitStruct->NbData));
296 ASSERT_PARAM(IS_DDL_DMA_CHANNEL(DMA_InitStruct->Channel));
297 ASSERT_PARAM(IS_DDL_DMA_PRIORITY(DMA_InitStruct->Priority));
299 /* Check the memory burst, peripheral burst and FIFO threshold parameters only
300 when FIFO mode is enabled */
301 if(DMA_InitStruct->FIFOMode != DDL_DMA_FIFOMODE_DISABLE)
302 {
306 }
307
308 /*---------------------------- DMAx SCFGx Configuration ------------------------
309 * Configure DMAx_Streamy: data transfer direction, data transfer mode,
310 * peripheral and memory increment mode,
311 * data size alignment and priority level with parameters :
312 * - Direction: DMA_SCFG_DIRCFG[1:0] bits
313 * - Mode: DMA_SCFG_CIRCMEN bit
314 * - PeriphOrM2MSrcIncMode: DMA_SCFG_PERIM bit
315 * - MemoryOrM2MDstIncMode: DMA_SCFG_MEMIM bit
316 * - PeriphOrM2MSrcDataSize: DMA_SCFG_PERSIZECFG[1:0] bits
317 * - MemoryOrM2MDstDataSize: DMA_SCFG_MEMSIZECFG[1:0] bits
318 * - Priority: DMA_SCFG_PRILCFG[1:0] bits
319 */
320 DDL_DMA_ConfigTransfer(DMAx, Stream, DMA_InitStruct->Direction | \
321 DMA_InitStruct->Mode | \
322 DMA_InitStruct->PeriphOrM2MSrcIncMode | \
323 DMA_InitStruct->MemoryOrM2MDstIncMode | \
324 DMA_InitStruct->PeriphOrM2MSrcDataSize | \
325 DMA_InitStruct->MemoryOrM2MDstDataSize | \
326 DMA_InitStruct->Priority
327 );
328
329 if(DMA_InitStruct->FIFOMode != DDL_DMA_FIFOMODE_DISABLE)
330 {
331 /*---------------------------- DMAx FCTRLx Configuration ------------------------
332 * Configure DMAx_Streamy: fifo mode and fifo threshold with parameters :
333 * - FIFOMode: DMA_FCTRL_DMDEN bit
334 * - FIFOThreshold: DMA_FCTRL_FTHSEL[1:0] bits
335 */
336 DDL_DMA_ConfigFifo(DMAx, Stream, DMA_InitStruct->FIFOMode, DMA_InitStruct->FIFOThreshold);
337
338 /*---------------------------- DMAx SCFGx Configuration --------------------------
339 * Configure DMAx_Streamy: memory burst transfer with parameters :
340 * - MemBurst: DMA_SCFG_MBCFG[1:0] bits
341 */
342 DDL_DMA_SetMemoryBurstxfer(DMAx,Stream,DMA_InitStruct->MemBurst);
343
344 /*---------------------------- DMAx SCFGx Configuration --------------------------
345 * Configure DMAx_Streamy: peripheral burst transfer with parameters :
346 * - PeriphBurst: DMA_SCFG_PBCFG[1:0] bits
347 */
348 DDL_DMA_SetPeriphBurstxfer(DMAx,Stream,DMA_InitStruct->PeriphBurst);
349 }
350
351 /*-------------------------- DMAx M0ADDRx Configuration --------------------------
352 * Configure the memory or destination base address with parameter :
353 * - MemoryOrM2MDstAddress: DMA_M0ADDR_M0ADDR[31:0] bits
354 */
355 DDL_DMA_SetMemoryAddress(DMAx, Stream, DMA_InitStruct->MemoryOrM2MDstAddress);
356
357 /*-------------------------- DMAx PADDRx Configuration ---------------------------
358 * Configure the peripheral or source base address with parameter :
359 * - PeriphOrM2MSrcAddress: DMA_PADDR_PADDR[31:0] bits
360 */
361 DDL_DMA_SetPeriphAddress(DMAx, Stream, DMA_InitStruct->PeriphOrM2MSrcAddress);
362
363 /*--------------------------- DMAx SxNDTR Configuration -------------------------
364 * Configure the peripheral base address with parameter :
365 * - NbData: DMA_NDATA_NDATA[15:0] bits
366 */
367 DDL_DMA_SetDataLength(DMAx, Stream, DMA_InitStruct->NbData);
368
369 /*--------------------------- DMA SCFGx_CHSEL Configuration ----------------------
370 * Configure the peripheral base address with parameter :
371 * - PeriphRequest: DMA_SCFG_CHSEL[2:0] bits
372 */
373 DDL_DMA_SetChannelSelection(DMAx, Stream, DMA_InitStruct->Channel);
374
375 return SUCCESS;
376}
377
384{
385 /* Set DMA_InitStruct fields to default values */
386 DMA_InitStruct->PeriphOrM2MSrcAddress = 0x00000000U;
387 DMA_InitStruct->MemoryOrM2MDstAddress = 0x00000000U;
389 DMA_InitStruct->Mode = DDL_DMA_MODE_NORMAL;
394 DMA_InitStruct->NbData = 0x00000000U;
395 DMA_InitStruct->Channel = DDL_DMA_CHANNEL_0;
396 DMA_InitStruct->Priority = DDL_DMA_PRIORITY_LOW;
397 DMA_InitStruct->FIFOMode = DDL_DMA_FIFOMODE_DISABLE;
399 DMA_InitStruct->MemBurst = DDL_DMA_MBURST_SINGLE;
400 DMA_InitStruct->PeriphBurst = DDL_DMA_PBURST_SINGLE;
401}
402
406
410
414
415#endif /* DMA1 */
416
420
421#endif /* USE_FULL_DDL_DRIVER */
422
G32 assert template file. This file should be copied to the application folder and renamed to g32_ass...
#define ASSERT_PARAM(_PARAM_)
Definition g32_assert.h:58
Header file of DMA DDL module.
Header file of RCM DDL module.
#define DDL_DMA_CHANNEL_0
#define DDL_DMA_DIRECTION_PERIPH_TO_MEMORY
#define DDL_DMA_FIFOTHRESHOLD_1_4
#define DDL_DMA_MBURST_SINGLE
#define DDL_DMA_MDATAALIGN_BYTE
#define DDL_DMA_MEMORY_NOINCREMENT
#define DDL_DMA_MODE_NORMAL
#define DDL_DMA_PBURST_SINGLE
#define DDL_DMA_PDATAALIGN_BYTE
#define DDL_DMA_PERIPH_NOINCREMENT
#define DDL_DMA_PRIORITY_LOW
#define DDL_DMA_STREAM_2
#define DDL_DMA_STREAM_0
#define DDL_DMA_STREAM_6
#define DDL_DMA_STREAM_7
#define DDL_DMA_STREAM_5
#define DDL_DMA_STREAM_4
#define DDL_DMA_STREAM_3
#define DDL_DMA_STREAM_1
#define DDL_DMA_STREAM_ALL
__STATIC_INLINE void DDL_DMA_SetDataLength(DMA_TypeDef *DMAx, uint32_t Stream, uint32_t NbData)
Set Number of data to transfer.
__STATIC_INLINE void DDL_DMA_DisableStream(DMA_TypeDef *DMAx, uint32_t Stream)
Disable DMA stream.
__STATIC_INLINE void DDL_DMA_SetMemoryAddress(DMA_TypeDef *DMAx, uint32_t Stream, uint32_t MemoryAddress)
Set the Memory address.
__STATIC_INLINE void DDL_DMA_SetPeriphAddress(DMA_TypeDef *DMAx, uint32_t Stream, uint32_t PeriphAddress)
Set the Peripheral address.
__STATIC_INLINE void DDL_DMA_SetMemoryBurstxfer(DMA_TypeDef *DMAx, uint32_t Stream, uint32_t Mburst)
Set Memory burst transfer configuration.
__STATIC_INLINE void DDL_DMA_ConfigFifo(DMA_TypeDef *DMAx, uint32_t Stream, uint32_t FifoMode, uint32_t FifoThreshold)
Configure the FIFO .
__STATIC_INLINE void DDL_DMA_ConfigTransfer(DMA_TypeDef *DMAx, uint32_t Stream, uint32_t Configuration)
Configure all parameters linked to DMA transfer.
__STATIC_INLINE void DDL_DMA_SetPeriphBurstxfer(DMA_TypeDef *DMAx, uint32_t Stream, uint32_t Pburst)
Set Peripheral burst transfer configuration.
__STATIC_INLINE void DDL_DMA_SetChannelSelection(DMA_TypeDef *DMAx, uint32_t Stream, uint32_t Channel)
Select Channel number associated to the Stream.
uint32_t DDL_DMA_DeInit(DMA_TypeDef *DMAx, uint32_t Stream)
De-initialize the DMA registers to their default reset values.
void DDL_DMA_StructInit(DDL_DMA_InitTypeDef *DMA_InitStruct)
Set each DDL_DMA_InitTypeDef field to default value.
uint32_t DDL_DMA_Init(DMA_TypeDef *DMAx, uint32_t Stream, DDL_DMA_InitTypeDef *DMA_InitStruct)
Initialize the DMA registers according to the specified parameters in DMA_InitStruct.
#define __DDL_DMA_GET_STREAM_INSTANCE(__DMA_INSTANCE__, __STREAM__)
Convert DMA Instance DMAx and DDL_DMA_STREAM_y into DMAx_Streamy.
#define DDL_DMA_WriteReg(__INSTANCE__, __REG__, __VALUE__)
Write a value in DMA register.
#define DDL_DMA_FIFOMODE_DISABLE
#define IS_DDL_DMA_FIFO_MODE_STATE(STATE)
#define IS_DDL_DMA_MODE(__VALUE__)
#define IS_DDL_DMA_MEMORYDATASIZE(__VALUE__)
#define IS_DDL_DMA_NBDATA(__VALUE__)
#define IS_DDL_DMA_MEMORYINCMODE(__VALUE__)
#define IS_DDL_DMA_PERIPHINCMODE(__VALUE__)
#define IS_DDL_DMA_FIFO_THRESHOLD(THRESHOLD)
#define IS_DDL_DMA_PERIPHDATASIZE(__VALUE__)
#define IS_DDL_DMA_CHANNEL(__VALUE__)
#define IS_DDL_DMA_MEMORY_BURST(BURST)
#define IS_DDL_DMA_PRIORITY(__VALUE__)
#define IS_DDL_DMA_DIRECTION(__VALUE__)
#define IS_DDL_DMA_ALL_STREAM_INSTANCE(INSTANCE, STREAM)
#define IS_DDL_DMA_PERIPHERAL_BURST(BURST)
#define DDL_RCM_AHB_RESET_DMA
__STATIC_INLINE void DDL_RCM_Unlock(void)
Unlock the RCM register.
__STATIC_INLINE void DDL_RCM_EnableAHBReset(uint32_t Peripheral)
Enable the AHB peripheral reset.