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

Subversion Repositories xulalx25soc

[/] [xulalx25soc/] [trunk/] [bench/] [cpp/] [busmaster_tb.cpp] - Blame information for rev 112

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

Line No. Rev Author Line
1 75 dgisselq
////////////////////////////////////////////////////////////////////////////////
2 4 dgisselq
//
3
// Filename:    busmaster_tb.cpp
4
//
5
// Project:     FPGA library development (XuLA2 development board)
6
//
7
// Purpose:     This is piped version of the testbench for the busmaster
8
//              verilog code.  The busmaster code is designed to be a complete
9 75 dgisselq
//      code set implementing all of the functionality of the XESS XuLA2
10
//      development board.  If done well, the programs talking to this one
11
//      should be able to talk to the board and apply the same tests to the
12
//      board itself.
13 4 dgisselq
//
14 75 dgisselq
// Creator:     Dan Gisselquist, Ph.D.
15
//              Gisselquist Technology, LLC
16 4 dgisselq
//
17 75 dgisselq
////////////////////////////////////////////////////////////////////////////////
18 4 dgisselq
//
19 75 dgisselq
// Copyright (C) 2015-2016, Gisselquist Technology, LLC
20 4 dgisselq
//
21 75 dgisselq
// This program is free software (firmware): you can redistribute it and/or
22
// modify it under the terms of  the GNU General Public License as published
23
// by the Free Software Foundation, either version 3 of the License, or (at
24
// your option) any later version.
25
//
26
// This program is distributed in the hope that it will be useful, but WITHOUT
27
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
28
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
29
// for more details.
30
//
31
// You should have received a copy of the GNU General Public License along
32
// with this program.  (It's in the $(ROOT)/doc directory, run make with no
33
// target there if the PDF file isn't present.)  If not, see
34
// <http://www.gnu.org/licenses/> for a copy.
35
//
36
// License:     GPL, v3, as defined and found on www.gnu.org,
37
//              http://www.gnu.org/licenses/gpl.html
38
//
39
//
40
////////////////////////////////////////////////////////////////////////////////
41
//
42
//
43 4 dgisselq
#include <signal.h>
44
#include <time.h>
45 112 dgisselq
#include <ctype.h>
46 4 dgisselq
 
47
#include "verilated.h"
48
#include "Vbusmaster.h"
49
 
50
#include "testb.h"
51
// #include "twoc.h"
52
#include "pipecmdr.h"
53
#include "qspiflashsim.h"
54
#include "sdramsim.h"
55 75 dgisselq
#include "sdspisim.h"
56 112 dgisselq
#include "uartsim.h"
57 4 dgisselq
 
58
#include "port.h"
59
 
60
// Add a reset line, since Vbusmaster doesn't have one
61
class   Vbusmasterr : public Vbusmaster {
62
public:
63
        int     i_rst;
64
        virtual ~Vbusmasterr() {}
65
};
66
 
67
// No particular "parameters" need definition or redefinition here.
68
class   BUSMASTER_TB : public PIPECMDR<Vbusmasterr> {
69
public:
70
        unsigned long   m_tx_busy_count;
71
        QSPIFLASHSIM    m_flash;
72 75 dgisselq
        SDSPISIM        m_sdcard;
73 4 dgisselq
        SDRAMSIM        m_sdram;
74
        unsigned        m_last_led;
75
        time_t          m_start_time;
76 75 dgisselq
        bool            m_last_writeout;
77 112 dgisselq
        UARTSIM         m_uart;
78 4 dgisselq
 
79 112 dgisselq
        BUSMASTER_TB(void) : PIPECMDR(FPGAPORT), m_uart(FPGAPORT+1) {
80 4 dgisselq
                m_start_time = time(NULL);
81
        }
82
 
83
        void    reset(void) {
84
                m_core->i_clk = 1;
85
                m_core->eval();
86
        }
87
 
88 75 dgisselq
        void    setsdcard(const char *fn) {
89
                m_sdcard.load(fn);
90 96 dgisselq
 
91
                printf("LOADING SDCARD FROM: \'%s\'\n", fn);
92 75 dgisselq
        }
93
 
94 4 dgisselq
        void    tick(void) {
95 75 dgisselq
                int     flash_miso, sdcard_miso;
96
 
97 4 dgisselq
                if ((m_tickcount & ((1<<28)-1))==0) {
98
                        double  ticks_per_second = m_tickcount;
99 47 dgisselq
                        time_t  seconds_passed = time(NULL)-m_start_time;
100
                        if (seconds_passed != 0) {
101 4 dgisselq
                        ticks_per_second /= (double)(time(NULL) - m_start_time);
102
                        printf(" ********   %.6f TICKS PER SECOND\n",
103
                                ticks_per_second);
104 47 dgisselq
                        }
105 4 dgisselq
                }
106
 
107
                // Set up the bus before any clock tick
108
                m_core->i_clk = 1;
109 75 dgisselq
                flash_miso = (m_flash(m_core->o_sf_cs_n,
110
                                        m_core->o_spi_sck,
111
                                        m_core->o_spi_mosi)&0x02)?1:0;
112
                sdcard_miso = m_sdcard(m_core->o_sd_cs_n, m_core->o_spi_sck,
113
                                        m_core->o_spi_mosi);
114
 
115
                if ((m_core->o_sf_cs_n)&&(m_core->o_sd_cs_n))
116
                        m_core->i_spi_miso = 1;
117
                else if ((!m_core->o_sf_cs_n)&&(m_core->o_sd_cs_n))
118
                        m_core->i_spi_miso = flash_miso;
119
                else if ((m_core->o_sf_cs_n)&&(!m_core->o_sd_cs_n))
120
                        m_core->i_spi_miso = sdcard_miso;
121
                else
122
                        assert((m_core->o_sf_cs_n)||(m_core->o_sd_cs_n));
123
 
124 4 dgisselq
                m_core->i_ram_data = m_sdram(1,
125
                                m_core->o_ram_cke, m_core->o_ram_cs_n,
126
                                m_core->o_ram_ras_n, m_core->o_ram_cas_n,
127
                                m_core->o_ram_we_n, m_core->o_ram_bs,
128
                                m_core->o_ram_addr, m_core->o_ram_drive_data,
129
                                m_core->o_ram_data);
130 112 dgisselq
 
131
                m_core->i_rx_uart = m_uart(m_core->o_tx_uart,
132
                                m_core->v__DOT__serialport__DOT__r_setup);
133 4 dgisselq
                PIPECMDR::tick();
134
 
135
                bool    writeout = false;
136 75 dgisselq
 
137
                if ((writeout)||(m_last_writeout)) {
138 4 dgisselq
                        printf("%08lx:", m_tickcount);
139
 
140 75 dgisselq
                        printf("\n"); fflush(stdout);
141
                } m_last_writeout = writeout;
142 4 dgisselq
        }
143
 
144
};
145
 
146
BUSMASTER_TB    *tb;
147
 
148
void    busmaster_kill(int v) {
149
        tb->kill();
150 75 dgisselq
        fprintf(stderr, "KILLED!!\n");
151 4 dgisselq
        exit(0);
152
}
153
 
154
int     main(int argc, char **argv) {
155
        Verilated::commandArgs(argc, argv);
156
        tb = new BUSMASTER_TB;
157
 
158
        // signal(SIGINT,  busmaster_kill);
159
 
160
        tb->reset();
161 96 dgisselq
        if (argc > 1)
162
                tb->setsdcard(argv[1]);
163
        else
164
                tb->setsdcard("/dev/zero");
165 4 dgisselq
 
166
        while(1)
167
                tb->tick();
168
 
169
        exit(0);
170
}
171
 

powered by: WebSVN 2.1.0

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