主程序如下:<br /><br /><br /><br />/* ======================================================================== */<br />/* TEXAS INSTRUMENTS, INC. */<br />/* */<br />/* DSPLIB Application Note Example (DSP_fft32x32) */<br />/* */<br />/* Release: Version 1.0 */<br />/* */<br />/* This file contains proprietary intellectual property of Texas */<br />/* Instruments, Inc. Its source and binary codes are protected by */<br />/* various copyrights, and portions may also be protected by patents or */<br />/* other legal protections. */<br />/* */<br />/* ------------------------------------------------------------------------ */<br />/* Copyright (C) 2003 Texas Instruments, Incorporated. */<br />/* All Rights Reserved. */<br />/* ======================================================================== */<br /><br />#include <stdio.h><br />#include <stdlib.h><br />#include <csl.h><br />#include <csl_timer.h><br />#include <math.h><br /><br />/* ======================================================================== */<br />/* Include the DSPLIB header file */<br />/* ======================================================================== */<br />#include "dsp_fft32x32.h"<br /><br />/* ======================================================================== */<br />/* Macro definition */<br />/* ======================================================================== */<br />#define PI (3.141592654)<br />#define NN (1024)<br /><br />/* ======================================================================== */<br />/* Input and output arrays */<br />/* ======================================================================== */<br />#pragma DATA_ALIGN(x, 8) <br />#pragma DATA_ALIGN(xx, 8) <br />#pragma DATA_ALIGN(y, 8)<br />#pragma DATA_ALIGN(w, 8)<br />int x[2*NN]; <br />int w[2*NN]; <br />int xx[2*NN]; <br />int y[2*NN]; <br /><br />/* ======================================================================== */<br />/* D2I -- Truncate a 'double' to a 'int', with clamping. */<br />/* ======================================================================== */<br />static int d2i(double d)<br />{<br /> if (d >= 2147483647.0) return (int)0x7FFFFFFF;<br /> if (d <= -2147483648.0) return (int)0x80000000;<br /> return (int)d;<br />}<br /><br />/* ======================================================================== */<br />/* GEN_TWIDDLE -- Generate twiddle factors for fft32x32(). */<br />/* */<br />/* USAGE */<br />/* This routine is called as follows: */<br />/* */<br />/* int gen_twiddle_fft32x32(short *w, int n, double scale) */<br />/* */<br />/* int *w Pointer to twiddle-factor array */<br />/* int n Size of FFT */<br />/* double scale Scale factor to apply to values. */<br />/* */<br />/* The routine will generate the twiddle-factors directly into the */<br />/* array you specify. The array needs to be approximately 2*N */<br />/* elements long. (The actual size, which is slightly smaller, is */<br />/* returned by the function.) */<br />/* ======================================================================== */<br />int gen_twiddle_fft32x32(int *w, int n, double scale)<br />{<br /> int i, j, k, s=0, t;<br /><br /> for (j = 1, k = 0; j < n >> 2; j = j << 2, s++)<br /> {<br /> for (i = t=0; i < n >> 2; i += j, t++)<br /> {<br /> w[k + 5] = d2i(scale * cos(6.0 * PI * i / n));<br /> w[k + 4] = d2i(scale * sin(6.0 * PI * i / n));<br /><br /> w[k + 3] = d2i(scale * cos(4.0 * PI * i / n));<br /> w[k + 2] = d2i(scale * sin(4.0 * PI * i / n));<br /><br /> w[k + 1] = d2i(scale * cos(2.0 * PI * i / n));<br /> w[k + 0] = d2i(scale * sin(2.0 * PI * i / n));<br /><br /> k += 6;<br /> }<br /> }<br /><br /> return k;<br />}<br /><br />/* ======================================================================== */<br />/* NAME */<br />/* main */<br />/* */<br />/* RIVISION HISTORY */<br />/* 30-Jun-2002 Initial revision */<br />/* 31-Dec-2002 Improved benchmarking */<br />/* */<br />/* USAGE */<br />/* void main (); */<br />/* This program is to show how to use DSP_fft32x32() */<br />/* when data are in L2SRAM. */<br />/* */<br />/* DESCRIPTION */<br />/* First, function call overhead for timer functions is measured. */<br />/* Then, the execution cycles for the target function is measured. */<br />/* Finally, the timer function call overhead is excluded from the */<br />/* execution cycles measured. */<br />/* The cycle count measured will include L1P/D miss overhead as well as */<br />/* function call overhead. */<br />/* */<br />/* ASSUMPTIONS */<br />/* The benchmarking code assumes C64x, e.g., 1 count = 8 CPU cycles. */<br />/* */<br />/* ------------------------------------------------------------------------ */<br />/* Copyright (c) 2003 Texas Instruments, Incorporated. */<br />/* All Rights Reserved. */<br />/* ======================================================================== */<br /><br />void main(void)<br />{<br /> int i;<br /> int F1 = 10, F2 = 1140; /* Input frequencies */<br /> int start, stop, overhead, diff;<br /> TIMER_Handle hTimer;<br /><br /> /* ==================================================================== */<br /> /* Initialize Chip Support Library */<br /> /* ==================================================================== */<br /> CSL_init();<br /> <br /> /* ==================================================================== */<br /> /* Generate Q.31 input data */<br /> /* ==================================================================== */<br /> for(i=0; i<NN; i++) <br /> {<br /> x[2*i] = xx[2*i] = 2147483647./(2*NN) * ( sin(2*PI*F2*i/NN) <br /> + sin(2*PI*F1*i/NN) ); <br /> x[2*i+1] = xx[2*i+1] = 0; <br /> }<br /><br /> /* ==================================================================== */<br /> /* Generate twiddle factors */<br /> /* ==================================================================== */<br /> gen_twiddle_fft32x32(w, NN, 2147483647.);<br /><br /> /* ==================================================================== */<br /> /* Configure a timer. */<br /> /* ==================================================================== */<br /> hTimer = TIMER_open(TIMER_DEVANY,0); <br /> TIMER_configArgs(hTimer, 0x000002C0, 0xFFFFFFFF, 0x00000000);<br /> <br /> /* ==================================================================== */<br /> /* Compute the overhead of calling the timer. */<br /> /* ==================================================================== */<br /> start = TIMER_getCount(hTimer); /* called twice to avoid L1D miss. */<br /> start = TIMER_getCount(hTimer); <br /> stop = TIMER_getCount(hTimer); <br /> overhead = stop - start;<br /> <br /> /* ==================================================================== */<br /> /* Measure the time */<br /> /* ==================================================================== */<br /> start = TIMER_getCount(hTimer); <br /> DSP_fft32x32(w, NN, x, y); <br /> diff = TIMER_getCount(hTimer) - start - overhead; <br /><br /> /* ==================================================================== */<br /> /* Print the result */<br /> /* ==================================================================== */<br /> printf("Total cycles including L1P/D miss overhead = %d\n", diff*8);<br /> printf("Check the result with the Graph menu.\n"<br /> "* Input\n"<br /> "Start address: xx\n"<br /> "Acquisition buffer size: 512\n"<br /> "Index increment: 2\n"<br /> "Display data size: 512\n"<br /> "DSP data type: 32-bit signed integer\n"<br /> "* Output\n"<br /> "Start address: y\n"<br /> "Acquisition buffer size: 1024\n"<br /> "Index increment: 1\n"<br /> "Display data size: 1024\n"<br /> "DSP data type: 32-bit signed integer\n" );<br /><br /> TIMER_close(hTimer);<br /> while(1);<br />}<br /><br />/* ======================================================================== */<br />/* End of file: fft32x32_main.c */<br />/* ======================================================================== */ |
|