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

Subversion Repositories zipcpu

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

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
// 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
#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
        }
54
        virtual ~TESTB(void) {
55
                if (m_trace) m_trace->close();
56
                delete m_core;
57
                m_core = NULL;
58
        }
59
 
60
        virtual void    opentrace(const char *vcdname) {
61
                m_trace = new VerilatedVcdC;
62
                m_core->trace(m_trace, 99);
63
                m_trace->open(vcdname);
64
        }
65
 
66
        virtual void    closetrace(void) {
67
                if (m_trace) {
68
                        m_trace->close();
69
                        m_trace = NULL;
70
                }
71
        }
72
 
73
        virtual void    eval(void) {
74
                m_core->eval();
75
        }
76
 
77
        virtual void    tick(void) {
78
                m_tickcount++;
79
 
80
                //if((m_trace)&&(m_tickcount)) m_trace->dump(10*m_tickcount-4);
81
                eval();
82
                if ((m_trace)&&(m_tickcount)) m_trace->dump(10*m_tickcount-2);
83
                m_core->i_clk = 1;
84
                eval();
85
                if (m_trace) m_trace->dump(10*m_tickcount);
86
                m_core->i_clk = 0;
87
                eval();
88
                if (m_trace) m_trace->dump(10*m_tickcount+5);
89
 
90
        }
91
 
92
        virtual void    reset(void) {
93
                m_core->i_rst = 1;
94
                tick();
95
                m_core->i_rst = 0;
96
                // printf("RESET\n");
97
        }
98
};
99
 
100
#endif

powered by: WebSVN 2.1.0

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