📄 simplememdma.c
字号:
/************************************************************************
Copyright(c) 2005 Analog Devices, Inc. All Rights Reserved.
This software is proprietary and confidential. By using this software
you agree to the terms of the associated Analog Devices License Agreement.
*************************************************************************
Please refer to the "readme" file for a description of this example.
************************************************************************
Include files
***********************************************************************/
#include <services/services.h>
#include "ezkitutilities.h"
/***********************************************************************
Defines
***********************************************************************/
#if defined(__ADSP_TETON__)
#define SourcePeripheralID ADI_DMA_MDMA2_S0
#define DestPeripheralID ADI_DMA_MDMA2_D0
#else
#define SourcePeripheralID ADI_DMA_MDMA_S0
#define DestPeripheralID ADI_DMA_MDMA_D0
#endif
/***********************************************************************
Static data
***********************************************************************/
// storage for interrupt manager data
static u8 IntMgrData[2*(ADI_INT_SECONDARY_MEMORY)];
// DMA Manager data (base memory + memory for 2 DMA channel)
static u8 DMAMgrData[ADI_DMA_BASE_MEMORY + (ADI_DMA_CHANNEL_MEMORY * 2)];
/************************************************************************
Destination Buffer for DMA transfer
*************************************************************************/
u32 DestBuffer[100];
/***********************************************************************
*
* Function: main
*
***********************************************************************/
void main(void) {
u32 ResponseCount;
u16 Count;
u32 SourceValue;
u32 *DestinationAddress;
u32 i; //loop variable
ADI_DMA_CONFIG_REG SourceConfigReg;
ADI_DMA_CONFIG_REG DestConfigReg;
ADI_DMA_MANAGER_HANDLE DMAHandle;
ADI_DMA_CHANNEL_HANDLE ChanHandleSource;
ADI_DMA_CHANNEL_HANDLE ChanHandleDest;
// initialize the interrupt manager
ezErrorCheck(adi_int_Init(IntMgrData, sizeof(IntMgrData), &ResponseCount, NULL));
// initialize EZ-Kit; power and EBIU services
ezInit(1);
// Initialization of DMA Manager.
ezErrorCheck(adi_dma_Init(DMAMgrData, sizeof(DMAMgrData), &ResponseCount, &DMAHandle, NULL));
// Register the DMA Channel for use by the DMA manager, obtaining a unique handle for each DMA
// channel configuration, source and destination, setting ChanHandleSource equal to the address of
// MDMA2_S0_CONFIG register and setting ChanHandleDest equal to the address of MDMA2_D0_CONFIG register.
ezErrorCheck(adi_dma_Open(DMAHandle, SourcePeripheralID, NULL, &ChanHandleSource, ADI_DMA_MODE_SINGLE, NULL, NULL));
ezErrorCheck(adi_dma_Open(DMAHandle, DestPeripheralID, NULL, &ChanHandleDest, ADI_DMA_MODE_SINGLE, NULL, NULL));
// Fill the memory with the 32 bit value 12345678
SourceValue = 0x78563412;
//Initialize the flag service, memory is not passed because callbacks are not being used
ezErrorCheck(adi_flag_Init(NULL, 0, &ResponseCount, NULL));
//Initialize all LEDS
for (i = EZ_FIRST_LED; i < EZ_NUM_LEDS; i++){
ezInitLED(i);
}
/********************************************************************************
NOTE: To clear the memory, uncomment this line, setting the source value to zero
********************************************************************************/
// SourceValue = 0x0;
// Set number of iterations
Count = 100;
// This should be assigned by "ifdef" to be a processor specific address in SRAM
DestinationAddress = DestBuffer;
// Set the config registers for 1 dimensional 32 bit transfers into common SRAM
SourceConfigReg.b_WNR = 0; // 1 Direction
SourceConfigReg.b_WDSIZE = 2; // 2:3 Transfer word size
SourceConfigReg.b_DMA2D = 0; // 4 DMA mode
SourceConfigReg.b_NDSIZE = 0; // 8:11 Flex descriptor size
DestConfigReg.b_WNR = 1; // 1 Direction
DestConfigReg.b_WDSIZE = 2; // 2:3 Transfer word size
DestConfigReg.b_DMA2D = 0; // 4 DMA mode
DestConfigReg.b_NDSIZE = 0; // 8:11 Flex descriptor size
// Assigning a data buffer to the source Channel, and copy from the address that the source value compiled to.
ezErrorCheck(adi_dma_Buffer(ChanHandleSource, &SourceValue, SourceConfigReg, Count, 0, 0, 0 ));
// Assigning a data buffer to the destination Channel, and copy to "DestinationAddress".
ezErrorCheck(adi_dma_Buffer (ChanHandleDest, DestinationAddress, DestConfigReg, Count, 4, 0, 0 ));
// Initiate the transfer
ezErrorCheck(adi_dma_Control(ChanHandleSource, ADI_DMA_CMD_SET_DATAFLOW, (void *)TRUE));
ezErrorCheck(adi_dma_Control(ChanHandleDest, ADI_DMA_CMD_SET_DATAFLOW, (void *)TRUE));
while (1)
{
i=i;
// Stop here and see the value 12345678 repeated 100 times, at DestinationAddress
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -