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

Subversion Repositories zipcpu

[/] [zipcpu/] [trunk/] [sim/] [verilator/] [testb.h] - Blame information for rev 208

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

Line No. Rev Author Line
1 204 dgisselq
////////////////////////////////////////////////////////////////////////////////
2
//
3
// Filename:    testb.h
4
//
5
// Project:     Zip CPU -- a small, lightweight, RISC CPU core
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 208 dgisselq
// with this program.  (It's in the $(ROOT)/doc directory.  Run make with no
29 204 dgisselq
// 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
#ifndef TESTB_H
38
#define TESTB_H
39
 
40
#include <stdio.h>
41
#include <stdint.h>
42
#include <verilated_vcd_c.h>
43
 
44
template <class VA>     class TESTB {
45
public:
46
        VA      *m_core;
47
        VerilatedVcdC*  m_trace;
48
        unsigned long   m_tickcount;
49
 
50
        TESTB(void) : m_trace(NULL), m_tickcount(0l) {
51
                m_core = new VA;
52
                Verilated::traceEverOn(true);
53 208 dgisselq
                m_core->i_clk = 0;
54
                eval(); // Get our initial values set properly.
55 204 dgisselq
        }
56
        virtual ~TESTB(void) {
57
                if (m_trace) m_trace->close();
58
                delete m_core;
59
                m_core = NULL;
60
        }
61
 
62
        virtual void    opentrace(const char *vcdname) {
63 208 dgisselq
                if (!m_trace) {
64
                        m_trace = new VerilatedVcdC;
65
                        m_core->trace(m_trace, 99);
66
                        m_trace->open(vcdname);
67
                }
68 204 dgisselq
        }
69
 
70
        virtual void    closetrace(void) {
71
                if (m_trace) {
72
                        m_trace->close();
73
                        m_trace = NULL;
74
                }
75
        }
76
 
77
        virtual void    eval(void) {
78
                m_core->eval();
79
        }
80
 
81
        virtual void    tick(void) {
82
                m_tickcount++;
83
 
84 208 dgisselq
                // Make sure we have our evaluations straight before the top
85
                // of the clock.  This is necessary since some of the 
86
                // connection modules may have made changes, for which some
87
                // logic depends.  This forces that logic to be recalculated
88
                // before the top of the clock.
89 204 dgisselq
                eval();
90 208 dgisselq
                if (m_trace) m_trace->dump(10*m_tickcount-2);
91 204 dgisselq
                m_core->i_clk = 1;
92
                eval();
93
                if (m_trace) m_trace->dump(10*m_tickcount);
94
                m_core->i_clk = 0;
95
                eval();
96
                if (m_trace) m_trace->dump(10*m_tickcount+5);
97
 
98
        }
99
 
100
        virtual void    reset(void) {
101
                m_core->i_rst = 1;
102
                tick();
103
                m_core->i_rst = 0;
104
                // printf("RESET\n");
105
        }
106
};
107
 
108
#endif

powered by: WebSVN 2.1.0

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