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

Subversion Repositories qspiflash

[/] [qspiflash/] [trunk/] [bench/] [cpp/] [testb.h] - Blame information for rev 16

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 16 dgisselq
////////////////////////////////////////////////////////////////////////////////
2
//
3
// Filename:    testb.h
4
//
5
// Project:     Wishbone Controlled Quad SPI Flash Controller
6
//
7
// Purpose:     A wrapper for a common interface to a clocked FPGA core
8
//              begin exercised in Verilator.
9
//
10
// Creator:     Dan Gisselquist, Ph.D.
11
//              Gisselquist Technology, LLC
12
//
13
////////////////////////////////////////////////////////////////////////////////
14
//
15
// Copyright (C) 2015,2017, Gisselquist Technology, LLC
16
//
17
// This program is free software (firmware): you can redistribute it and/or
18
// modify it under the terms of  the GNU General Public License as published
19
// by the Free Software Foundation, either version 3 of the License, or (at
20
// your option) any later version.
21
//
22
// This program is distributed in the hope that it will be useful, but WITHOUT
23
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
24
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
25
// for more details.
26
//
27
// You should have received a copy of the GNU General Public License along
28
// with this program.  (It's in the $(ROOT)/doc directory.  Run make with no
29
// target there if the PDF file isn't present.)  If not, see
30
// <http://www.gnu.org/licenses/> for a copy.
31
//
32
// License:     GPL, v3, as defined and found on www.gnu.org,
33
//              http://www.gnu.org/licenses/gpl.html
34
//
35
//
36
////////////////////////////////////////////////////////////////////////////////
37
//
38
//
39
#ifndef TESTB_H
40
#define TESTB_H
41
 
42
#include <stdio.h>
43
#include <stdint.h>
44
#include <verilated_vcd_c.h>
45
 
46
#define TBASSERT(TB,A) do { if (!(A)) { (TB).closetrace(); } assert(A); } while(0);
47
 
48
template <class VA>     class TESTB {
49
public:
50
        VA      *m_core;
51
        VerilatedVcdC*  m_trace;
52
        unsigned long   m_tickcount;
53
 
54
        TESTB(void) : m_trace(NULL), m_tickcount(0l) {
55
                m_core = new VA;
56
                Verilated::traceEverOn(true);
57
                m_core->i_clk = 0;
58
                eval(); // Get our initial values set properly.
59
        }
60
        virtual ~TESTB(void) {
61
                if (m_trace) m_trace->close();
62
                delete m_core;
63
                m_core = NULL;
64
        }
65
 
66
        virtual void    opentrace(const char *vcdname) {
67
                if (!m_trace) {
68
                        m_trace = new VerilatedVcdC;
69
                        m_core->trace(m_trace, 99);
70
                        m_trace->open(vcdname);
71
                }
72
        }
73
 
74
        virtual void    closetrace(void) {
75
                if (m_trace) {
76
                        m_trace->close();
77
                        m_trace = NULL;
78
                }
79
        }
80
 
81
        virtual void    eval(void) {
82
                m_core->eval();
83
        }
84
 
85
        virtual void    tick(void) {
86
                m_tickcount++;
87
 
88
                // Make sure we have our evaluations straight before the top
89
                // of the clock.  This is necessary since some of the 
90
                // connection modules may have made changes, for which some
91
                // logic depends.  This forces that logic to be recalculated
92
                // before the top of the clock.
93
                eval();
94
                if (m_trace) m_trace->dump(10*m_tickcount-2);
95
                m_core->i_clk = 1;
96
                eval();
97
                if (m_trace) m_trace->dump(10*m_tickcount);
98
                m_core->i_clk = 0;
99
                eval();
100
                if (m_trace) {
101
                        m_trace->dump(10*m_tickcount+5);
102
                        m_trace->flush();
103
                }
104
        }
105
 
106
        virtual void    reset(void) {
107
        }
108
};
109
 
110
#endif

powered by: WebSVN 2.1.0

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