Forum Discussion
Altera_Forum
Honored Contributor
16 years agoFft In Sopc
Guyz please help , if u have an idea. Uptil now i made a 64 point FFT using megacore and added it to the sopc as a new component but there are a lot of signals and so it gives me an error when ...
Altera_Forum
Honored Contributor
15 years agohere is my code :
# include <stdio.h># include <unistd.h># include <stdlib.h># include <string.h># include <ctype.h> # include "includes.h"# include "priv/alt_file.h"# include "sys/alt_cache.h"# include "sys/alt_alarm.h"# include "system.h"# include "io.h"# include "alt_types.h" /*SGDMA Library*/# include <altera_avalon_sgdma.h># include <altera_avalon_sgdma_descriptor.h># include <altera_avalon_sgdma_regs.h> /////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////// alt_sgdma_dev * transmit_DMA; alt_sgdma_dev * receive_DMA; alt_u32 *tx_ptr; alt_u32 *rx_ptr; alt_sgdma_descriptor *desc = (alt_sgdma_descriptor*)INPUT_RAM_BASE ; alt_sgdma_descriptor *desc1 = (alt_sgdma_descriptor*)OUTPUT_RAM_BASE ; /////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////// void init_FFT_sgdma() { /* Open a SG-DMA for MM-->ST and ST-->MM (two SG-DMAs are present) */ transmit_DMA = alt_avalon_sgdma_open("/dev/sgdma_mm_to_st_fft"); receive_DMA = alt_avalon_sgdma_open("/dev/sgdma_st_to_mm_fft"); // Making sure the SG-DMAs were opened correctly if(transmit_DMA == NULL || receive_DMA == NULL) printf("Could not open the SG-DMA of FFT\n"); add pointer to the input and output memory. //tx_ptr pointer on memory where i will write input data tx_ptr = (alt_u32 *) (INPUT_RAM_BASE+ ALTERA_AVALON_SGDMA_DESCRIPTOR_SIZE); //rx_ptr pointer on memory where i can read output data rx_ptr = (alt_u32 *) (OUTPUT_RAM_BASE+ ALTERA_AVALON_SGDMA_DESCRIPTOR_SIZE); } /////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////// void Hardware_fourier_trans (N) { int i; alt_8 *s0= (alt_8*)tx_ptr; for(i = 0; i < N; i++) { tx_ptr = (alt_u32) (sig); //sig[1024] is array of input Signal //////////////////////////////////////////////// ///////* maybe you will face problem whith arrange bytes whish transmit by SGDMA so you should rearrange bytes when you read from memory */ //////////////////////////////////////////////// } // Construct descriptors in the same input and output memory. // here i use just one descriptorfor, if you want more than one replace "NULL" with name of next descriptor. alt_avalon_sgdma_construct_mem_to_stream_desc(desc,NULL,tx_ptr, (alt_u16)4096,0,1,1,0); alt_avalon_sgdma_construct_stream_to_mem_desc(desc1,NULL,rx_ptr,0,0); //start transfer data alt_avalon_sgdma_do_async_transfer(transmit_DMA, desc); //wait to finish while (IORD(SGDMA_MM_TO_ST_FFT_BASE,0)!=12) {}; //start receive data alt_avalon_sgdma_do_async_transfer(receive_DMA, desc1); while (IORD(SGDMA_ST_TO_MM_FFT_BASE,0)!=14) {}; //wait to finish short *s1= (alt_8*)rx_ptr; //calculate amplitude for (i=0;i<1024;i++) {sig[i]=-1*sqrt(pow(s1[2*i],2)+pow(s1[2*i+1],2));} } /////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////// int main(void) { init_FFT_sgdma(); return 0; } Good Luck