OpenCores
URL https://opencores.org/ocsvn/dblclockfft/dblclockfft/trunk

Subversion Repositories dblclockfft

[/] [dblclockfft/] [trunk/] [bench/] [cpp/] [butterfly_tb.cpp] - Diff between revs 5 and 6

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 5 Rev 6
Line 1... Line 1...
 
////////////////////////////////////////////////////////////////////////////
 
//
 
// Filename:    butterfly_tb.cpp
 
//
 
// Project:     A Doubletime Pipelined FFT
 
//
 
// Purpose:     A test-bench for the butterfly.v subfile of the double
 
//              clocked FFT.  This file may be run autonomously.  If so,
 
//              the last line output will either read "SUCCESS" on success,
 
//              or some other failure message otherwise.
 
//
 
//              This file depends upon verilator to both compile, run, and
 
//              therefore test butterfly.v
 
//
 
// Creator:     Dan Gisselquist, Ph.D.
 
//              Gisselquist Tecnology, LLC
 
//
 
///////////////////////////////////////////////////////////////////////////
 
//
 
// Copyright (C) 2015, Gisselquist Technology, LLC
 
//
 
// This program is free software (firmware): you can redistribute it and/or
 
// modify it under the terms of  the GNU General Public License as published
 
// by the Free Software Foundation, either version 3 of the License, or (at
 
// your option) any later version.
 
//
 
// This program is distributed in the hope that it will be useful, but WITHOUT
 
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
 
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 
// for more details.
 
//
 
// You should have received a copy of the GNU General Public License along
 
// with this program.  (It's in the $(ROOT)/doc directory, run make with no
 
// target there if the PDF file isn't present.)  If not, see
 
// <http://www.gnu.org/licenses/> for a copy.
 
//
 
// License:     GPL, v3, as defined and found on www.gnu.org,
 
//              http://www.gnu.org/licenses/gpl.html
 
//
 
//
 
///////////////////////////////////////////////////////////////////////////
#include <stdio.h>
#include <stdio.h>
#include <stdint.h>
#include <stdint.h>
 
 
#include "Vbutterfly.h"
#include "Vbutterfly.h"
#include "verilated.h"
#include "verilated.h"
 
 
class   BFLY_TB {
class   BFLY_TB {
public:
public:
        Vbutterfly      *m_bfly;
        Vbutterfly      *m_bfly;
        unsigned long   m_left[64], m_right[64];
        unsigned long   m_left[64], m_right[64];
 
        bool            m_aux[64];
        int             m_addr, m_lastaux;
        int             m_addr, m_lastaux;
 
        bool            m_syncd;
 
 
        BFLY_TB(void) {
        BFLY_TB(void) {
                m_bfly = new Vbutterfly;
                m_bfly = new Vbutterfly;
                m_addr = 0;
                m_addr = 0;
 
                m_syncd = 0;
        }
        }
 
 
        void    tick(void) {
        void    tick(void) {
                m_lastaux = m_bfly->o_aux;
                m_lastaux = m_bfly->o_aux;
                m_bfly->i_clk = 0;
                m_bfly->i_clk = 0;
                m_bfly->eval();
                m_bfly->eval();
                m_bfly->i_clk = 1;
                m_bfly->i_clk = 1;
                m_bfly->eval();
                m_bfly->eval();
 
 
 
                m_syncd = (m_syncd) || (m_bfly->o_aux);
        }
        }
 
 
        void    reset(void) {
        void    reset(void) {
                m_bfly->i_ce    = 0;
                m_bfly->i_ce    = 0;
                m_bfly->i_aux   = 1;
                m_bfly->i_rst   = 1;
                m_bfly->i_coef  = 0l;
                m_bfly->i_coef  = 0l;
                m_bfly->i_left  = 0;
                m_bfly->i_left  = 0;
                m_bfly->i_right = 0;
                m_bfly->i_right = 0;
                tick();
                tick();
 
                m_bfly->i_rst = 0;
 
                m_bfly->i_ce  = 1;
 
                //
 
                // Let's run a RESET test here, forcing the whole butterfly
 
                // to be filled with aux=1.  If the reset works right,
 
                // we'll never get an aux=1 output.
 
                //
 
                m_bfly->i_rst = 1;
                m_bfly->i_ce  = 1;
                m_bfly->i_ce  = 1;
                m_bfly->i_aux = 1;
                m_bfly->i_aux = 1;
 
                for(int i=0; i<200; i++)
                for(int i=0; i<40; i++)
 
                        tick();
                        tick();
                m_bfly->i_aux = 0;
 
 
                // Now here's the RESET line, so let's see what the test does
 
                m_bfly->i_rst = 1;
 
                m_bfly->i_ce  = 1;
 
                m_bfly->i_aux = 1;
                tick();
                tick();
 
                m_bfly->i_rst = 0;
 
                m_syncd = 0;
        }
        }
 
 
        void    test(const int n, const int k, const unsigned long cof,
        void    test(const int n, const int k, const unsigned long cof,
                        const unsigned lft, const unsigned rht, const int aux) {
                        const unsigned lft, const unsigned rht, const int aux) {
 
 
Line 82... Line 141...
                        m_bfly->v__DOT__mpy_r & (~(-1l<<40)),
                        m_bfly->v__DOT__mpy_r & (~(-1l<<40)),
                        m_bfly->v__DOT__mpy_i & (~(-1l<<40)));
                        m_bfly->v__DOT__mpy_i & (~(-1l<<40)));
                printf("\n");
                printf("\n");
                */
                */
 
 
                if (m_left[(m_addr-23)&(64-1)] != m_bfly->o_left) {
                if ((m_syncd)&&(m_left[(m_addr-23)&(64-1)] != m_bfly->o_left)) {
                        fprintf(stderr, "WRONG O_LEFT!\n");
                        fprintf(stderr, "WRONG O_LEFT!\n");
                        exit(-1);
                        exit(-1);
                }
                }
 
 
                if (m_right[(m_addr-23)&(64-1)] != m_bfly->o_right) {
                if ((m_syncd)&&(m_right[(m_addr-23)&(64-1)] != m_bfly->o_right)) {
                        fprintf(stderr, "WRONG O_RIGHT!\n");
                        fprintf(stderr, "WRONG O_RIGHT!\n");
                        exit(-1);
                        exit(-1);
                }
                }
 
 
 
                if ((m_syncd)&&(m_aux[(m_addr-23)&(64-1)] != m_bfly->o_aux)) {
 
                        fprintf(stderr, "FAILED AUX CHANNEL TEST (i.e. the SYNC)\n");
 
                        exit(-1);
 
                }
 
 
 
                if ((m_addr > 22)&&(!m_syncd)) {
 
                        fprintf(stderr, "NO SYNC PULSE!\n");
 
                        exit(-1);
 
                }
 
 
                // Now, let's calculate an "expected" result ...
                // Now, let's calculate an "expected" result ...
                long    rlft, ilft;
                long    rlft, ilft;
 
 
                // Extract left and right values ...
                // Extract left and right values ...
                rlft = (m_bfly->i_left >> 16) & 0x0ffff;
                rlft = (m_bfly->i_left >> 16) & 0x0ffff;
Line 171... Line 240...
                printf("oR_i = %lx\n", o_right_i);
                printf("oR_i = %lx\n", o_right_i);
        */
        */
 
 
                m_left[ m_addr&(64-1)] = o_left;
                m_left[ m_addr&(64-1)] = o_left;
                m_right[m_addr&(64-1)] = o_right;
                m_right[m_addr&(64-1)] = o_right;
 
                m_aux[  m_addr&(64-1)] = aux;
 
 
                m_addr++;
                m_addr++;
        }
        }
};
};
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.