⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 adi-bf533-dma-求FFT和DMA综合源码
💻 C
📖 第 1 页 / 共 2 页
字号:
/******************************************************************************/
//
// Name: 	BF533 EZ-KIT main function	DSP作业(求FFT和DMA综合)
//
/******************************************************************************

//	(C) Copyright 2006 - 王启源,指导教师:吴强   导师:阮晓钢	人工智能与机器人研究所,

//	File Name:	main.c

//	Date Modified:	5/21/07		$Revision: 		1.00 $

//	Software:       VisualDSP++4.5

//	Hardware:		ADSP-BF533 EZ-KIT Board

//	Special Connections:  None

//	Purpose:		The file is the main functian.

//	By:				 Lions Wang   BJUT    AI&Robots  Tuttor: Ruan Xiaogang. 			

//	See also: 		实验报告

//	explaination: 当然可以用直接写的方式将XYZ写入SDRAM但是那样损失了DSPcore的速度

//	ALL RIGHTS RESERVED.					

*********************************************************************************/
//需要改1:DMA0为描述子或者别的形式,以将Y打倒相应位置。2:将XYZ的位置修改正确
/**********************************************************************

Include files

*********************************************************************/

#include <cdefBF533.h>		//BF533 Register Pointer Definition
#include <stdio.h>
#include <sys\exception.h>		//Interrupt Handling Header
#include <services/services.h>		// system service includes
#include <drivers/adi_dev.h>		// device drivers includes
//#include "ezkitutilities.h"

#include<fract.h>
#include<complex.h>  
#include <math.h>
#include <filter.h>
#include <flt2fr.h>

/*********************************************************************

Enumerations and defines

*********************************************************************/

//定义变量的大小可以自己改之
#define PI 3.14159265   
#define XFFT_SIZE 1024   		//定义X的大小
#define YFFT_SIZE 256 		//定义Y的大小   
#define ZFFT_SIZE 2048 		//定义Z的大小

#define XADDR 0x00001000   	//定义X的地址
#define YADDR 0x00100000   	//定义Y的地址
#define ZADDR 0x00200000   	//定义Z的地址
//链式DMA用到的定义
#define BUFFERS					9			// number of descriptors in the chain (limited only by memory)
#define ELEMENTS				YFFT_SIZE	// number of words of data per descriptor ( the first 1)
#define BYTES_PER_ELEMENT		2			// number of bytes in each word (1, 2, or 4)

// Define some space in SDRAM for memory DMAs
#define SDRAM_DATA_START		XADDR		// I use SDRAM data starting at this address
#define SOURCE_DATA_START		SDRAM_DATA_START//暂时定义到这上面,用时就修改了
#define DESTINATION_DATA_START	(SDRAM_DATA_START + (BUFFERS * ELEMENTS * BYTES_PER_ELEMENT))//暂时定义到这上面,用时就修改了

/*********************************************************************

Static data

*********************************************************************/
static  fract16 X[XFFT_SIZE+1];//定义1.15格式的变量X   
static	fract16 Y[YFFT_SIZE+1];//定义1.15格式的变量Y
static	fract16 Z[ZFFT_SIZE+1];//定义1.15格式的变量Z
  	fract16 *x=XADDR;//定义1.15格式的变量X   
	fract16 *y=YADDR;//定义1.15格式的变量Y
	fract16 *z=ZADDR;//定义1.15格式的变量Z
float temp1[ZFFT_SIZE];//定义一个浮点变量用于看结果
	//sourse[]'s FFT

 
//  Descriptors contain information about what to copy.  In this work,
//  we chain multiple descriptors together so all of them are executed
//  by the Blackfin DMA engine.
static ADI_DMA_DESCRIPTOR_LARGE		DestinationBuffers[BUFFERS];// descriptors where data is written to
static ADI_DMA_DESCRIPTOR_LARGE		SourceBuffers[BUFFERS];		// descriptors where data is written from

// DMA Manager data (base memory + memory for 2 DMA channels, since memory DMA requires 2)
//下面的定义本利没用但是可以用于扩展应用
static u8 							DMAMgrData[ADI_DMA_BASE_MEMORY + (ADI_DMA_CHANNEL_MEMORY * 2)];
static ADI_DMA_MANAGER_HANDLE		DMAManagerHandle;					// handle for the whole DMA manager

ADI_DMA_CHANNEL_HANDLE				dma_s0_chan_handle;					// source DMA channel handle
ADI_DMA_CHANNEL_HANDLE				dma_d0_chan_handle;					// destination DMA channel handle


// Deferred Callback Manager data (memory for 1 service plus 1 posted callbacks)
static u8 							DCBMgrData[ADI_DCB_QUEUE_SIZE + ADI_DCB_ENTRY_SIZE];
static ADI_DCB_HANDLE				CallbackHandle;			// handle to the callback service
static u8							CallbackQueue[ADI_DCB_ENTRY_SIZE*10];// callback queue

// Sets up here all Prototype Functions 
void Init_EBIU(void);
void Init_Flash(void);
void Init_ADV(void);
void Init_Interrupts(void);
void Init_SDRAM(void);
void Init_MYMDMA0(fract16 *SorseADDR,fract16 *GoalADDR,u32 DMA_Count);
void Init_MYMDMA1(fract16 *SorseADDR,fract16 *GoalADDR,u32 DMA_Count);
void Init_PPI(void);
void Init_PLL(void);
//void myfftfunction(fract16 sourse[],u32 FFT_Count);
void buffer_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)
void DMA0FUN(void);
//void DMA1FUN(void);

/*********************************************************************
 *	FFT和DMA主函数
 *	DSP作业(求FFT和DMA综合)----王启源,指导教师:吴强   导师:阮晓钢	人工智能与机器人研究所,
 *  See also: 实验报告
 *  Lions Wang   BJUT    AI&Robots  Tuttor: Ruan Xiaogang.
 *  $Revision: 1.00 $
*********************************************************************/
void main()
{
	int i,j;   ;//定义的循环变量
		
//setup;
	Init_PLL();
	Init_EBIU();		//Async Memory Interface Setup,本题没用
	Init_Flash();		//Flash Setup to config the flash GPIOs,本题没用
//	Init_ADV();			//Link the ADV7183 clock to the PPI and ADV7183 reset,本题没用,可以以后扩展ADC

	Init_Interrupts();	//Enter an interrupt subroutine after DMA has been finished,定义DMAA的中断用于以后扩展
	Init_SDRAM();		//SDRAM Setup to store the video image,初始化SDRAM
	
//	initfun();//初始化函数,初始化X,Y,Z     

 for(i=1;i<=XFFT_SIZE;i++)

    {
        X[i]=float_to_fract16(sin(PI/i));  	//初始化向量X         
    }    
 
	Init_MYMDMA1(X,XADDR,XFFT_SIZE);
//DMA Setup "L1data RAM->DMA->SDRAM" Its configured in Stop Mode
//用了链式DMA方式和STOP MODE DMA 方式
	printf("\n DMA--X Setup completed successfully!\n"); //将X用DMA的方式打到SDRAM上

//求X的FFT
    complex_fract16  tempsourseX[XFFT_SIZE];
    complex_fract16  outputsourseX[XFFT_SIZE];			//fft的输出
    complex_fract16  twiddle_tablesourseX[XFFT_SIZE/2];	//反转向量,位反序
   	twidfftrad2_fr16(twiddle_tablesourseX,XFFT_SIZE);
    rfft_fr16(X,tempsourseX,outputsourseX,twiddle_tablesourseX,1,XFFT_SIZE,1/XFFT_SIZE,1/XFFT_SIZE);//调用系统函数求fft,调用之前先反转
 //end myfftfunction
	printf("\n X FFT completed successfully!\n"); 		//FFT完成
    
    for(i=1;i<=YFFT_SIZE;i++)
    {
        temp1[i]=cos(3*PI/i);				//此句话可以去掉,
        Y[i]=float_to_fract16(temp1[i]);	//初始化向量Y
    }  
    for(i=1;i<=ZFFT_SIZE/YFFT_SIZE;i++)    
    {
        for(j=1;j<=YFFT_SIZE;j++)
        {
           Z[(i-1)*YFFT_SIZE+j]=Y[j];	//初始化向量Z
        }
    }
    	
	DMA0FUN();			//DMA Setup "L1data RAM->DMA->SDRAM" Its configured in Stop Mode
//用了链式DMA方式
	printf("\n DMA --Y Setup completed successfully!\n"); //将Y用DMA的方式打到SDRAM上				

//求Y的FFT
	//sourse[]'s FFT
    complex_fract16  tempsourseY[YFFT_SIZE];
    complex_fract16  outputsourseY[YFFT_SIZE];			//fft的输出
    complex_fract16  twiddle_tablesourseY[YFFT_SIZE/2];	//反转向量,位反序
    twidfftrad2_fr16(twiddle_tablesourseY,YFFT_SIZE);
    rfft_fr16(Y,tempsourseY,outputsourseY,twiddle_tablesourseY,1,YFFT_SIZE,1/YFFT_SIZE,1/YFFT_SIZE);//调用系统函数求fft,调用之前先反转
 //end myfftfunction
	printf("\n Y FFT completed successfully!\n"); 		 //FFT完成	
	printf("\n DMA--Z Setup completed successfully!\n"); //将Y用DMA的方式打到SDRAM上    

//求Z的FFT
		//sourse[]'s FFT
    complex_fract16  tempsourseZ[ZFFT_SIZE];
    complex_fract16  outputsourseZ[ZFFT_SIZE];			//fft的输出
    complex_fract16  twiddle_tablesourseZ[ZFFT_SIZE/2];	//反转向量,位反序
    twidfftrad2_fr16(twiddle_tablesourseZ,ZFFT_SIZE);
    rfft_fr16(Z,tempsourseZ,outputsourseZ,twiddle_tablesourseZ,1,ZFFT_SIZE,1/ZFFT_SIZE,1/ZFFT_SIZE);//调用系统函数求fft,调用之前先反转
 //end myfftfunction
	printf("\n Z  FFT completed successfully!\n"); 		//FFT完成

//	Init_PPI();			//PPI Setup,本题没用可以用于以后扩展视频输入,当然是DMA方式。	
	while (1)
	{
		i = 1;
	}//程序的死循环
}//end main
/*********************************************************************
 *	FFT函数myfftfunctio
 *	DSP作业(求FFT和DMA综合)----王启源,指导教师:吴强   导师:阮晓钢	人工智能与机器人研究所,
 *  See also: 实验报告
 *  Lions Wang   BJUT    AI&Robots  Tuttor: Ruan Xiaogang.
 *  $Revision: 1.00 $
*********************************************************************/

                   /*    void rfft_fr16(
                                  const fract16  *in,       // Input array
                                  complex_fract16 *t,       // Temporary buffer
                                  complex_fract16 *out,     // Output array

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -