打印

『原创』DIY的DM642EVM调试代码(1)--测试片内部件的FFT程序

[复制链接]
3682|10
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
DSP探路者|  楼主 | 2007-2-9 23:37 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
主程序如下:



/* ======================================================================== */
/*  TEXAS INSTRUMENTS, INC.                                                 */
/*                                                                          */
/*  DSPLIB Application Note Example (DSP_fft32x32)                          */
/*                                                                          */
/*      Release:        Version 1.0                                         */
/*                                                                          */
/*  This file contains proprietary intellectual property of Texas           */
/*  Instruments, Inc.  Its source and binary codes are protected by         */
/*  various copyrights, and portions may also be protected by patents or    */
/*  other legal protections.                                                */
/*                                                                          */
/* ------------------------------------------------------------------------ */
/*          Copyright (C) 2003 Texas Instruments, Incorporated.             */
/*                          All Rights Reserved.                            */
/* ======================================================================== */

#include <stdio.h>
#include <stdlib.h>
#include <csl.h>
#include <csl_timer.h>
#include <math.h>

/* ======================================================================== */
/* Include the DSPLIB header file                                           */
/* ======================================================================== */
#include "dsp_fft32x32.h"

/* ======================================================================== */
/* Macro definition                                                         */
/* ======================================================================== */
#define PI  (3.141592654)
#define NN  (1024)

/* ======================================================================== */
/* Input and output arrays                                                  */
/* ======================================================================== */
#pragma DATA_ALIGN(x, 8)       
#pragma DATA_ALIGN(xx, 8)       
#pragma DATA_ALIGN(y, 8)
#pragma DATA_ALIGN(w, 8)
int x[2*NN];              
int w[2*NN];              
int xx[2*NN];             
int y[2*NN];              

/* ======================================================================== */
/*  D2I -- Truncate a 'double' to a 'int',   with clamping.                 */
/* ======================================================================== */
static int d2i(double d)
{
    if (d >=  2147483647.0) return (int)0x7FFFFFFF;
    if (d <= -2147483648.0) return (int)0x80000000;
    return (int)d;
}

/* ======================================================================== */
/*  GEN_TWIDDLE -- Generate twiddle factors for fft32x32().                 */
/*                                                                          */
/*  USAGE                                                                   */
/*      This routine is called as follows:                                  */
/*                                                                          */
/*          int gen_twiddle_fft32x32(short *w, int n, double scale)         */
/*                                                                          */
/*          int    *w     Pointer to twiddle-factor array                   */
/*          int    n      Size of FFT                                       */
/*          double scale  Scale factor to apply to values.                  */
/*                                                                          */
/*      The routine will generate the twiddle-factors directly into the     */
/*      array you specify.  The array needs to be approximately 2*N         */
/*      elements long.  (The actual size, which is slightly smaller, is     */
/*      returned by the function.)                                          */
/* ======================================================================== */
int gen_twiddle_fft32x32(int *w, int n, double scale)
{
    int i, j, k, s=0, t;

    for (j = 1, k = 0; j < n >> 2; j = j << 2, s++)
    {
        for (i = t=0; i < n >> 2; i += j, t++)
        {
            w[k +  5] = d2i(scale * cos(6.0 * PI * i / n));
            w[k +  4] = d2i(scale * sin(6.0 * PI * i / n));

            w[k +  3] = d2i(scale * cos(4.0 * PI * i / n));
            w[k +  2] = d2i(scale * sin(4.0 * PI * i / n));

            w[k +  1] = d2i(scale * cos(2.0 * PI * i / n));
            w[k +  0] = d2i(scale * sin(2.0 * PI * i / n));

            k += 6;
        }
    }

    return k;
}

/* ======================================================================== */
/*  NAME                                                                    */
/*     main                                                                 */
/*                                                                          */
/*  RIVISION HISTORY                                                        */
/*     30-Jun-2002 Initial revision                                         */
/*     31-Dec-2002 Improved benchmarking                                    */
/*                                                                          */
/*  USAGE                                                                   */
/*     void main ();                                                        */
/*     This program is to show how to use DSP_fft32x32()                    */
/*     when data are in L2SRAM.                                             */
/*                                                                          */
/*  DESCRIPTION                                                             */
/*     First, function call overhead for timer functions is measured.       */
/*     Then, the execution cycles for the target function is measured.      */
/*     Finally, the timer function call overhead is excluded from the       */
/*     execution cycles measured.                                           */
/*     The cycle count measured will include L1P/D miss overhead as well as */
/*     function call overhead.                                              */
/*                                                                          */
/*  ASSUMPTIONS                                                             */
/*     The benchmarking code assumes C64x, e.g., 1 count = 8 CPU cycles.    */
/*                                                                          */
/* ------------------------------------------------------------------------ */
/*            Copyright (c) 2003 Texas Instruments, Incorporated.           */
/*                           All Rights Reserved.                           */
/* ======================================================================== */

void main(void)
{
    int i;
    int F1 = 10, F2 = 1140;              /* Input frequencies                 */
    int start, stop, overhead, diff;
    TIMER_Handle hTimer;

    /* ==================================================================== */
    /* Initialize Chip Support Library                                      */
    /* ==================================================================== */
    CSL_init();
    
    /* ==================================================================== */
    /* Generate Q.31 input data                                             */
    /* ==================================================================== */
    for(i=0; i<NN; i++) 
    {
        x[2*i] = xx[2*i] = 2147483647./(2*NN) * ( sin(2*PI*F2*i/NN) 
                         + sin(2*PI*F1*i/NN) ); 
        x[2*i+1] = xx[2*i+1] = 0; 
    }

    /* ==================================================================== */
    /* Generate twiddle factors                                             */
    /* ==================================================================== */
        gen_twiddle_fft32x32(w, NN, 2147483647.);

    /* ==================================================================== */
    /* Configure a timer.                                                   */
    /* ==================================================================== */
    hTimer = TIMER_open(TIMER_DEVANY,0);   
    TIMER_configArgs(hTimer, 0x000002C0, 0xFFFFFFFF, 0x00000000);
  
    /* ==================================================================== */
    /*  Compute the overhead of calling the timer.                          */
    /* ==================================================================== */
    start = TIMER_getCount(hTimer); /* called twice to avoid L1D miss.      */
    start = TIMER_getCount(hTimer);        
    stop  = TIMER_getCount(hTimer);        
    overhead = stop - start;
    
    /* ==================================================================== */
    /* Measure the time                                                     */
    /* ==================================================================== */
    start = TIMER_getCount(hTimer);        
    DSP_fft32x32(w, NN, x, y);                 
    diff = TIMER_getCount(hTimer) - start - overhead; 

    /* ==================================================================== */
    /* Print the result                                                     */
    /* ==================================================================== */
    printf("Total cycles including L1P/D miss overhead = %d\n", diff*8);
    printf("Check the result with the Graph menu.\n"
           "* Input\n"
           "Start address: xx\n"
                   "Acquisition buffer size: 512\n"
           "Index increment: 2\n"
           "Display data size: 512\n"
           "DSP data type: 32-bit signed integer\n"
           "* Output\n"
           "Start address: y\n"
           "Acquisition buffer size: 1024\n"
           "Index increment: 1\n"
           "Display data size: 1024\n"
           "DSP data type: 32-bit signed integer\n" );

    TIMER_close(hTimer);
        while(1);
}

/* ======================================================================== */
/*  End of file: fft32x32_main.c                                            */
/* ======================================================================== */

相关帖子

沙发
DSP探路者|  楼主 | 2007-2-9 23:37 | 只看该作者

CMD文件

/***********************************************************************/
/*  Copyright (c) 2003  Texas Instruments Incorporated                 */
/***********************************************************************/


MEMORY 
{
   IRAM     : o= 0x00000000 l= 0x00100000 
}

SECTIONS
{
    .text       >       IRAM
    .stack      >       IRAM
    .bss        >       IRAM
    .cinit      >       IRAM
    .cio        >       IRAM
    .const      >       IRAM
    .data       >       IRAM
    .switch     >       IRAM
    .sysmem     >       IRAM
    .far        >       IRAM
}

使用特权

评论回复
板凳
DSP探路者|  楼主 | 2007-2-9 23:39 | 只看该作者

FFT结果对比

2各个正弦信号的时域和频域对比

使用特权

评论回复
地板
DSP探路者|  楼主 | 2007-2-9 23:40 | 只看该作者

工程源码打包下载

工程源码打包下载

使用特权

评论回复
5
DSP探路者|  楼主 | 2007-2-9 23:43 | 只看该作者

说明

这是一个基础测试程序。

FFT程序可以测试片内的存储器是否工作正常、片内的指令是否执行正常,可以用装载存储器、查看存储器等方式寻址映射到片内所有的部件是否工作正常。

如果这个程序执行正常,意味着DM642的供电、复位、内部存储器工作正常,如果利用仿真器装载程序正常,即证明JTAG口工作正常。

还可以测试32×32电的FFT的执行时间(us数量级)。

使用特权

评论回复
6
mybao| | 2007-2-10 09:45 | 只看该作者

DIY的DM642EVM调试代码(1)--测试片内部件的FFT程序

使用特权

评论回复
7
cetclyb| | 2007-2-13 13:11 | 只看该作者

编译不通过,说少dsp_fft32x32.h

使用特权

评论回复
8
DSP探路者|  楼主 | 2007-2-24 00:43 | 只看该作者

dsp_fft32x32.h是FFT库的头文件

在安装目录->C6400->DSPLIB目录中找

使用特权

评论回复
9
黑哥哥| | 2007-2-26 17:26 | 只看该作者

编译通不过,3个错误

编译通不过,3个错误
"D:/ccs3.1/C6000/csl/include/csl.h", line 66: error: identifier "_IRQ_Dispatch" is undefined
"D:/ccs3.1/C6000/csl/include/csl.h", line 71: error: identifier "TIMER_Handle" is undefined
"FFT.c", line 27: fatal error: could not open source file "dsp_fft32x32.h"
楼主帮帮我,谢谢

使用特权

评论回复
10
黑哥哥| | 2007-2-27 12:15 | 只看该作者

期待中

楼主帮帮忙

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

10

主题

84

帖子

0

粉丝