#include "dsk5510_dual3006cfg.h" #include "dsk5510.h" #include "swi_process.h" #include "dsplib.h" #define N 1024 #include "window.h" /* comment the next line to use DSPLIB fft */ //#define C_FFT #ifdef C_FFT /* Use C FFT */ /* function defined in lab4fft.c */ void fft(void); /* FFT data buffers */ int real[N]; /* Real part of data */ int imag[N]; /* Imaginary part of data */ #include "lab4fft.c" #else /* Use DSPLIB FFT */ /* Function defined by lab4asm.asm */ void bit_rev(void); /* FFT data buffers (declared in lab4asm.asm) */ extern int bit_rev_data[N*2]; /* Data input for bit-reverse function */ extern int fft_data[N*2]; /* In-place FFT & Output array */ #endif /* C_FFT */ // all data processing should be done in SWI_ProcessBuffer void SWI_ProcessBuffer() { static unsigned int mbox_value = 0; short *psrc, *pdest; unsigned int i; mbox_value |= SWI_getmbox(); // buffers are only processed when both transmit and receive are ready if((mbox_value & DMA_RECEIVE_DONE) && (mbox_value & DMA_TRANSMIT_DONE)) { mbox_value = 0; // get buffer pointers psrc = receive_buffer[receive_buffer_to_process_index]; pdest = transmit_buffer[transmit_buffer_to_fill_index]; // samples are interleaved in input buffer 3-4-1-2-3-4-1-2 // output buffer is organized 1-2-3-4-1-2-3-4 // pdest[4*i] = psrc[4*i+2] would copy input from channel 1 // to output channel 1. #ifdef C_FFT /* Use C FFT */ /* I n s e r t c o d e t o f i l l */ /* C F F T b u f f e r s */ #else /* Use DSPLIB FFT */ /* I n s e r t c o d e t o f i l l */ /* a s s e m b l y F F T b u f f e r s */ #endif /* C_FFT */ #ifdef C_FFT /* Use C FFT */ /* Multiply the input signal by the Hamming window. */ /* . . . i n s e r t C / a s m code . . . */ /* Bit-reverse and compute FFT in C */ fft(); /* Now, take absolute value squared of FFT */ /* . . . i n s e r t C / a s m code . . . */ /* Last, set the DC coefficient to -1 for a trigger pulse */ /* . . . i n s e r t C / a s m code . . . */ /* done, wait for next time around! */ #else /* Use DSPLIB FFT */ /* Multiply the input signal by the Hamming window. */ /* . . . i n s e r t C / a s m code . . . */ /* Compute FFT using DSPLIB function */ cfft((DATA *)bit_rev_data,N, SCALE); /* Bit reverse using assembly function */ bit_rev(); /* Now, take absolute value squared of FFT */ /* . . . i n s e r t C / a s m code . . . */ /* Last, set the DC coefficient to -1 for a trigger pulse */ /* . . . i n s e r t C / a s m code . . . */ /* done, wait for next time around! */ #endif /* C_FFT */ receive_buffer_processed = 1; // flag receive buffer as processed transmit_buffer_filled = 1; // flag output buffer as full } }