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

Subversion Repositories s6soc

[/] [s6soc/] [trunk/] [bench/] [cpp/] [zip_sim.cpp] - Blame information for rev 2

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

Line No. Rev Author Line
1 2 dgisselq
//
2
//
3
// Filename:    busmaster_tb.cpp
4
//
5
// Project:     FPGA library development (S6 development board)
6
//
7
// Purpose:     
8
//
9
// Creator:     Dan Gisselquist
10
//              Gisselquist Tecnology, LLC
11
//
12
// Copyright:   2015
13
//
14
//
15
#include <stdio.h>
16
#include <sys/types.h>
17
#include <sys/stat.h>
18
#include <fcntl.h>
19
#include <signal.h>
20
#include <time.h>
21
#include <unistd.h>
22
 
23
#include "verilated.h"
24
#include "Vbusmaster.h"
25
 
26
#include "testb.h"
27
// #include "twoc.h"
28
#include "qspiflashsim.h"
29
#include "uartsim.h"
30
 
31
class   GPIOSIM {
32
public:
33
        unsigned operator()(const unsigned o_gpio) { return 0; }
34
};
35
 
36
class   KEYPADSIM {
37
public:
38
        unsigned operator()(const unsigned o_kpd) { return 0; }
39
};
40
 
41
// Add a reset line, since Vbusmaster doesn't have one
42
class   Vbusmasterr : public Vbusmaster {
43
public:
44
        int     i_rst;
45
};
46
 
47
// No particular "parameters" need definition or redefinition here.
48
class   ZIPSIM_TB : public TESTB<Vbusmasterr> {
49
public:
50
        QSPIFLASHSIM    m_flash;
51
        UARTSIM         m_uart;
52
        GPIOSIM         m_gpio;
53
        KEYPADSIM       m_keypad;
54
        unsigned        m_last_led;
55
        time_t          m_start_time;
56
 
57
        ZIPSIM_TB(void) : m_uart(0x2b6) {
58
                m_start_time = time(NULL);
59
        }
60
 
61
        void    reset(void) {
62
                m_flash.debug(false);
63
        }
64
 
65
        void    tick(void) {
66
                if ((m_tickcount & ((1<<28)-1))==0) {
67
                        double  ticks_per_second = m_tickcount;
68
                        time_t  nsecs = (time(NULL)-m_start_time);
69
                        if (nsecs > 0) {
70
                                ticks_per_second /= (double)nsecs;
71
                                printf(" ********   %.6f TICKS PER SECOND\n",
72
                                        ticks_per_second);
73
                        }
74
                }
75
 
76
                // Set up the bus before any clock tick
77
 
78
                // We've got the flash to deal with ...
79
                m_core->i_qspi_dat = m_flash(m_core->o_qspi_cs_n,
80
                                                m_core->o_qspi_sck,
81
                                                m_core->o_qspi_dat);
82
 
83
                // And the GPIO lines
84
                m_core->i_gpio = m_gpio(m_core->o_gpio);
85
 
86
                m_core->i_btn = 0; // 2'b0
87
                // o_led, o_pwm, o_pwm_aux
88
 
89
                // And the keypad
90
                m_core->i_kp_row = m_keypad(m_core->o_kp_col);
91
 
92
                // And the UART
93
                m_core->i_rx_stb  = m_uart.rx(m_core->i_rx_data);
94
                m_core->i_tx_busy = m_uart.tx(m_core->o_tx_stb, m_core->o_tx_data);
95
 
96
                TESTB<Vbusmasterr>::tick();
97
 
98
                if (m_core->o_led != m_last_led) {
99
                        printf("LED: %08x\n", m_core->o_led);
100
                }
101
 
102
                /*
103
 
104
                printf("PC: %08x:%08x [%08x:%08x:%08x:%08x:%08x],%08x,%08x,%d,%08x,%08x\n",
105
                        m_core->v__DOT__thecpu__DOT__thecpu__DOT__ipc,
106
                        m_core->v__DOT__thecpu__DOT__thecpu__DOT__upc,
107
                        m_core->v__DOT__thecpu__DOT__thecpu__DOT__regset[0],
108
                        m_core->v__DOT__thecpu__DOT__thecpu__DOT__regset[1],
109
                        m_core->v__DOT__thecpu__DOT__thecpu__DOT__regset[2],
110
                        m_core->v__DOT__thecpu__DOT__thecpu__DOT__regset[3],
111
                        m_core->v__DOT__thecpu__DOT__thecpu__DOT__regset[15],
112
                        m_core->v__DOT__thecpu__DOT__thecpu__DOT__instruction_decoder__DOT__r_I,
113
                        m_core->v__DOT__thecpu__DOT__thecpu__DOT__r_opB,
114
                        m_core->v__DOT__thecpu__DOT__thecpu__DOT__instruction_decoder__DOT__w_dcdR_pc,
115
                        m_core->v__DOT__thecpu__DOT__thecpu__DOT__r_opA,
116
                        m_core->v__DOT__thecpu__DOT__thecpu__DOT__wr_reg_vl);
117
                */
118
 
119
                /*
120
                if (m_core->v__DOT__thecpu__DOT__thecpu__DOT__pf_valid)
121
                        printf("PC: %08x - %08x, uart=%d,%d, pic = %d,%04x,%0d,%04x\n",
122
                                m_core->v__DOT__thecpu__DOT__thecpu__DOT__instruction_pc,
123
                                m_core->v__DOT__thecpu__DOT__thecpu__DOT__instruction,
124
                                m_core->i_rx_stb, m_core->i_tx_busy,
125
                                m_core->v__DOT__pic__DOT__r_gie,
126
                                m_core->v__DOT__pic__DOT__r_int_enable,
127
                                m_core->v__DOT__pic__DOT__r_any,
128
                                m_core->v__DOT__pic__DOT__r_int_state);
129
                */
130
        }
131
};
132
 
133
ZIPSIM_TB       *tb;
134
 
135
bool    iself(const char *fname) {
136
        FILE    *fp;
137
        bool    ret = true;
138
        fp = fopen(fname, "rb");
139
 
140
        if (!fp)
141
                return false;
142
        if (0x7f != fgetc(fp))
143
                ret = false;
144
        if ('E' != fgetc(fp))
145
                ret = false;
146
        if ('L' != fgetc(fp))
147
                ret = false;
148
        if ('F' != fgetc(fp))
149
                ret = false;
150
 
151
        fclose(fp);
152
        return ret;
153
}
154
 
155
void    usage(void) {
156
        fprintf(stderr, "Usage: zip_sim flash_program\n");
157
}
158
 
159
int     main(int argc, char **argv) {
160
        Verilated::commandArgs(argc, argv);
161
        tb = new ZIPSIM_TB;
162
        const char      *codef = NULL;
163
 
164
        for(int argn=1; argn<argc; argn++) {
165
                if (argv[argn][0] == '-') {
166
                        usage();
167
                        exit(-1);
168
                } else
169
                        codef = argv[argn];
170
        }
171
 
172
        if ((!codef)||(!codef[0]))
173
                fprintf(stderr, "No executable code filename found!\n");
174
 
175
        if (access(codef, R_OK)!=0)
176
                fprintf(stderr, "Cannot read code filename, %s\n", codef);
177
 
178
        if (iself(codef)) {
179
                char    tmpbuf[TMP_MAX], cmdbuf[256];
180
                int     unused_fd;
181
                strcpy(tmpbuf, "/var/tmp/zipsimXXXX");
182
 
183
                // Make a temporary file
184
                unused_fd = mkostemp(tmpbuf, O_CREAT|O_TRUNC|O_RDWR);
185
                // Close it, though, since we don't want to write to it here
186
                close(unused_fd);
187
 
188
                // Now we right to it, as part of calling objcopy       
189
                sprintf(cmdbuf, "zip-objcopy -S -O binary --reverse-bytes=4 %s %s\n",
190
                        codef, tmpbuf);
191
                if (system(cmdbuf) != 0) {
192
                        unlink(tmpbuf);
193
                        fprintf(stderr, "ZIP_SIM::Could not convert ELF binary to a raw file\n");
194
                        exit(-2);
195
                }
196
 
197
                tb->m_flash.load(0x0400, tmpbuf);
198
                unlink(tmpbuf);
199
        } else {
200
                tb->m_flash.load(0x0400, codef);
201
        }
202
 
203
        tb->reset();
204
 
205
        while(1)
206
                tb->tick();
207
 
208
        printf("SUCCESS!\n");
209
        exit(0);
210
}
211
 

powered by: WebSVN 2.1.0

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