📄 main.c
字号:
const complex_fract16 *w, // Twiddle table
int wst, // Twiddle stride
int n, // Size FFT
int block_exponent, // Not used
int scale_method); // Not used
*/
//void myfftfunction(fract16 sourse[],u32 FFT_Count)
/*********************************************************************
* 链式DMA设置函数 buffer_setup
* DSP作业(求FFT和DMA综合)----王启源,指导教师:吴强 导师:阮晓钢 人工智能与机器人研究所,
* See also: 实验报告
* Lions Wang BJUT AI&Robots Tuttor: Ruan Xiaogang.
* $Revision: 1.00 $
*********************************************************************/
void buffer0_setup(
int buffs, // number of buffers (descriptors) to use in each direction
int elements, // number of elements in each buffer (descriptor)
int bytes_per_element) // number of bytes in each element (1, 2, or 4)
{
ADI_DMA_CONFIG_REG config;
int i, j, k;
int data_index;
u8 *pTemp;
void *debug;
// Set up the configuration register for DMA. Some of the bits
// are set up by the DMA manager which will over-write anything
// you place in them, so watch out for that.
//
// config.b_DMA_EN set by DMA manager
if(bytes_per_element == 1) { // careful not to confuse 0,1,2 values with 1, 2, and 4 bytes
config.b_WDSIZE = 0; // 0=8bits (1 byte)
} else if(bytes_per_element == 2) {
config.b_WDSIZE = 1; // 1=16bits (2 bytes)
} else if(bytes_per_element == 4) {
config.b_WDSIZE = 2; // 2=32bits (4 bytes)
} else {
// ezErrorCheck(1);
}
config.b_DMA2D = 0; // 0 = 1-dimensional DMA, 1 = 2-dimensional DMA
// config.b_RESTART set by DMA manager
// config.b_DI_SEL set by DMA manager
// config.b_DI_EN set below (for both source and destination)
// config.b_NDSIZE set by DMA manager
// config.b_FLOW set by DMA manager
config.b_WNR = 1; // 0 = memory read, 1 = memory write
for (i = 0; i < buffs; i++)
{ // set up all the buffers (descriptors) for writing TO memory
DestinationBuffers[i].StartAddress = (void *)( i * ELEMENTS * BYTES_PER_ELEMENT+ZADDR);// SDRAM // SDRAM
DestinationBuffers[i].Config = config; // the config register we set up earlier
DestinationBuffers[i].XCount = elements;
DestinationBuffers[i].XModify = bytes_per_element;
DestinationBuffers[i].YCount = 1; // this is for 2-dimensional DMA only
DestinationBuffers[i].YModify = 1; // this is for 2-dimensional DMA only
if (i == (buffs-1))
{
DestinationBuffers[i].Config.b_DI_EN = 1; // interrupt on the last descriptor only
DestinationBuffers[i].pNext = NULL; // the last descriptor always points to zero!
DestinationBuffers[i].StartAddress = (void *)YADDR; // SDRAM
}
else
{
DestinationBuffers[i].Config.b_DI_EN = 0; // don't interrupt on intermediate descriptors
DestinationBuffers[i].pNext = &DestinationBuffers[i+1]; // point to the next buffer in the chain
}
}
// The source uses slightly different config register settings
config.b_WNR = 0; // 0=memory read, 1=memory write
config.b_DI_EN = 0; // don't interrupt on outbound data
for (i = 0; i < buffs; i++)
{ // set up all the buffers (descriptors) for writing FROM memory
SourceBuffers[i].StartAddress = (void *)Y+2; //SDRAM
SourceBuffers[i].Config = config; // the config register we set up earlier
SourceBuffers[i].XCount = elements;
SourceBuffers[i].XModify = bytes_per_element;
SourceBuffers[i].YCount = 1; // this is for 2-dimensional DMA only
SourceBuffers[i].YModify = 1; // this is for 2-dimensional DMA only
if (i == (buffs-1)) // Notice we only use interrupts in the destination DMA
{
SourceBuffers[i].pNext = NULL; // the last descriptor always points to zero!!
}
else
{
SourceBuffers[i].pNext = &SourceBuffers[i+1]; // point to the next buffer in the chain
}
}
}
/*********************************************************************
* 链式DMA函数回调函数 Callback
* DSP作业(求FFT和DMA综合)----王启源,指导教师:吴强 导师:阮晓钢 人工智能与机器人研究所,
* See also: 实验报告
* Lions Wang BJUT AI&Robots Tuttor: Ruan Xiaogang.
* $Revision: 1.00 $
*********************************************************************/
static void Callback( // callback function called by DCB
void *AppHandle,
u32 Event,
void *pArg)
{
u8 *pSource;
u8 *pDestination;
int i, j;
volatile u32 delay;
switch(Event) {
case ADI_DMA_EVENT_DESCRIPTOR_PROCESSED: // Done with the DMA transfer
// shut off the source DMA channel
adi_dma_Control( dma_s0_chan_handle, ADI_DMA_CMD_SET_DATAFLOW, (void *)FALSE);
// shut off the destination DMA channel
adi_dma_Control( dma_d0_chan_handle, ADI_DMA_CMD_SET_DATAFLOW, (void *)FALSE);
// close the destination DMA channel
adi_dma_Close( dma_d0_chan_handle, TRUE);
// close the source DMA channel
adi_dma_Close( dma_s0_chan_handle, TRUE);
case ADI_DMA_EVENT_INNER_LOOP_PROCESSED: // this is only used with 2-D DMA
// ezErrorCheck(1);
break;
case ADI_DMA_EVENT_OUTER_LOOP_PROCESSED: // we're not using this feature of DMA
// ezErrorCheck(1);
break;
case ADI_DMA_EVENT_ERROR_INTERRUPT: // this is a common error when debugging DMA applications
// ezErrorCheck(1); // <--- you might want to set a breakpoint here
break;
default: // unexpected events
// ezErrorCheck(1);
break;
}
}
/*********************************************************************
* 链式DMA函数DMAFUN
* DSP作业(求FFT和DMA综合)----王启源,指导教师:吴强 导师:阮晓钢 人工智能与机器人研究所,
* See also: 实验报告
* Lions Wang BJUT AI&Robots Tuttor: Ruan Xiaogang.
* $Revision: 1.00 $
*********************************************************************/
void DMA0FUN(void) {
ADI_DEV_CMD_VALUE_PAIR *pCommandPair;
unsigned int Result;
unsigned int i, j, k;
unsigned int iElements, iBuffers, iBytesPerWord;
u32 divider;
u32 ResponseCount;
u32 SecondaryCount;
ADI_DEV_1D_BUFFER *pOutboundBuffer;
ADI_DEV_1D_BUFFER *pFirstBuffer;
unsigned int Flag;
char* TmpPtr;
// initialize interrupt manager
adi_int_Init(NULL, 0, &ResponseCount, NULL);
// we're not bothering to check ResponseCount
//Initialize the flag service, memory is not passed because callbacks are not being used
adi_flag_Init(NULL, 0, &ResponseCount, NULL);
// initialize the DMA manager
adi_dma_Init(DMAMgrData, sizeof(DMAMgrData), &ResponseCount, &DMAManagerHandle, NULL); // we're not bothering to check ResponseCount
// setup the descriptors and data
buffer0_setup(BUFFERS, ELEMENTS, BYTES_PER_ELEMENT);
#if defined(__ADSPBF561__)
// open the source DMA channel
adi_dma_Open(DMAManagerHandle, ADI_DMA_MDMA1_S0, (void *)0, &dma_s0_chan_handle, ADI_DMA_MODE_DESCRIPTOR_LARGE, CallbackHandle, Callback);
// open the destination DMA channel
adi_dma_Open(DMAManagerHandle, ADI_DMA_MDMA1_D0, (void *)0, &dma_d0_chan_handle, ADI_DMA_MODE_DESCRIPTOR_LARGE, CallbackHandle, Callback);
#else // The other processors use the same names for the DMA channels
// open the source DMA channel
adi_dma_Open(DMAManagerHandle, ADI_DMA_MDMA_S0, (void *)0, &dma_s0_chan_handle, ADI_DMA_MODE_DESCRIPTOR_LARGE, CallbackHandle, Callback);
// open the destination DMA channel
adi_dma_Open(DMAManagerHandle, ADI_DMA_MDMA_D0, (void *)0, &dma_d0_chan_handle, ADI_DMA_MODE_DESCRIPTOR_LARGE, CallbackHandle, Callback);
#endif
// queue the source descriptors first (normal DMA operations only use 1 channel)
adi_dma_Queue( dma_s0_chan_handle, (ADI_DMA_DESCRIPTOR_HANDLE)&SourceBuffers[0]);
// queue the destination descriptors
adi_dma_Queue( dma_d0_chan_handle, (ADI_DMA_DESCRIPTOR_HANDLE)&DestinationBuffers[0]);
// start the DMA transfer at the source side first (normal DMA operations only use 1 channel)
adi_dma_Control( dma_s0_chan_handle, ADI_DMA_CMD_SET_DATAFLOW, (void *)TRUE);
// start the DMA transfer at the destination side
adi_dma_Control( dma_d0_chan_handle, ADI_DMA_CMD_SET_DATAFLOW, (void *)TRUE);
// The DMA will go independently and cause a callback above.
// a normal application would return to whatever it was doing and allow the DMA to finish on its own.
}
// Exception handler to catch exceptions which can occur when you do something wrong
static ADI_INT_HANDLER(ExceptionHandler)
{
// ezErrorCheck(1);
return(ADI_INT_RESULT_PROCESSED);
}
// Hardware error handler to catch problems with the hardware.
static ADI_INT_HANDLER(HWErrorHandler)
{
// ezErrorCheck(1);
return(ADI_INT_RESULT_PROCESSED);
}
//程序结束,Bye!
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -