URL
https://opencores.org/ocsvn/s6soc/s6soc/trunk
Subversion Repositories s6soc
[/] [s6soc/] [trunk/] [bench/] [cpp/] [zip_sim.cpp] - Rev 2
Go to most recent revision | Compare with Previous | Blame | View Log
// // // Filename: busmaster_tb.cpp // // Project: FPGA library development (S6 development board) // // Purpose: // // Creator: Dan Gisselquist // Gisselquist Tecnology, LLC // // Copyright: 2015 // // #include <stdio.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <signal.h> #include <time.h> #include <unistd.h> #include "verilated.h" #include "Vbusmaster.h" #include "testb.h" // #include "twoc.h" #include "qspiflashsim.h" #include "uartsim.h" class GPIOSIM { public: unsigned operator()(const unsigned o_gpio) { return 0; } }; class KEYPADSIM { public: unsigned operator()(const unsigned o_kpd) { return 0; } }; // Add a reset line, since Vbusmaster doesn't have one class Vbusmasterr : public Vbusmaster { public: int i_rst; }; // No particular "parameters" need definition or redefinition here. class ZIPSIM_TB : public TESTB<Vbusmasterr> { public: QSPIFLASHSIM m_flash; UARTSIM m_uart; GPIOSIM m_gpio; KEYPADSIM m_keypad; unsigned m_last_led; time_t m_start_time; ZIPSIM_TB(void) : m_uart(0x2b6) { m_start_time = time(NULL); } void reset(void) { m_flash.debug(false); } void tick(void) { if ((m_tickcount & ((1<<28)-1))==0) { double ticks_per_second = m_tickcount; time_t nsecs = (time(NULL)-m_start_time); if (nsecs > 0) { ticks_per_second /= (double)nsecs; printf(" ******** %.6f TICKS PER SECOND\n", ticks_per_second); } } // Set up the bus before any clock tick // We've got the flash to deal with ... m_core->i_qspi_dat = m_flash(m_core->o_qspi_cs_n, m_core->o_qspi_sck, m_core->o_qspi_dat); // And the GPIO lines m_core->i_gpio = m_gpio(m_core->o_gpio); m_core->i_btn = 0; // 2'b0 // o_led, o_pwm, o_pwm_aux // And the keypad m_core->i_kp_row = m_keypad(m_core->o_kp_col); // And the UART m_core->i_rx_stb = m_uart.rx(m_core->i_rx_data); m_core->i_tx_busy = m_uart.tx(m_core->o_tx_stb, m_core->o_tx_data); TESTB<Vbusmasterr>::tick(); if (m_core->o_led != m_last_led) { printf("LED: %08x\n", m_core->o_led); } /* printf("PC: %08x:%08x [%08x:%08x:%08x:%08x:%08x],%08x,%08x,%d,%08x,%08x\n", m_core->v__DOT__thecpu__DOT__thecpu__DOT__ipc, m_core->v__DOT__thecpu__DOT__thecpu__DOT__upc, m_core->v__DOT__thecpu__DOT__thecpu__DOT__regset[0], m_core->v__DOT__thecpu__DOT__thecpu__DOT__regset[1], m_core->v__DOT__thecpu__DOT__thecpu__DOT__regset[2], m_core->v__DOT__thecpu__DOT__thecpu__DOT__regset[3], m_core->v__DOT__thecpu__DOT__thecpu__DOT__regset[15], m_core->v__DOT__thecpu__DOT__thecpu__DOT__instruction_decoder__DOT__r_I, m_core->v__DOT__thecpu__DOT__thecpu__DOT__r_opB, m_core->v__DOT__thecpu__DOT__thecpu__DOT__instruction_decoder__DOT__w_dcdR_pc, m_core->v__DOT__thecpu__DOT__thecpu__DOT__r_opA, m_core->v__DOT__thecpu__DOT__thecpu__DOT__wr_reg_vl); */ /* if (m_core->v__DOT__thecpu__DOT__thecpu__DOT__pf_valid) printf("PC: %08x - %08x, uart=%d,%d, pic = %d,%04x,%0d,%04x\n", m_core->v__DOT__thecpu__DOT__thecpu__DOT__instruction_pc, m_core->v__DOT__thecpu__DOT__thecpu__DOT__instruction, m_core->i_rx_stb, m_core->i_tx_busy, m_core->v__DOT__pic__DOT__r_gie, m_core->v__DOT__pic__DOT__r_int_enable, m_core->v__DOT__pic__DOT__r_any, m_core->v__DOT__pic__DOT__r_int_state); */ } }; ZIPSIM_TB *tb; bool iself(const char *fname) { FILE *fp; bool ret = true; fp = fopen(fname, "rb"); if (!fp) return false; if (0x7f != fgetc(fp)) ret = false; if ('E' != fgetc(fp)) ret = false; if ('L' != fgetc(fp)) ret = false; if ('F' != fgetc(fp)) ret = false; fclose(fp); return ret; } void usage(void) { fprintf(stderr, "Usage: zip_sim flash_program\n"); } int main(int argc, char **argv) { Verilated::commandArgs(argc, argv); tb = new ZIPSIM_TB; const char *codef = NULL; for(int argn=1; argn<argc; argn++) { if (argv[argn][0] == '-') { usage(); exit(-1); } else codef = argv[argn]; } if ((!codef)||(!codef[0])) fprintf(stderr, "No executable code filename found!\n"); if (access(codef, R_OK)!=0) fprintf(stderr, "Cannot read code filename, %s\n", codef); if (iself(codef)) { char tmpbuf[TMP_MAX], cmdbuf[256]; int unused_fd; strcpy(tmpbuf, "/var/tmp/zipsimXXXX"); // Make a temporary file unused_fd = mkostemp(tmpbuf, O_CREAT|O_TRUNC|O_RDWR); // Close it, though, since we don't want to write to it here close(unused_fd); // Now we right to it, as part of calling objcopy sprintf(cmdbuf, "zip-objcopy -S -O binary --reverse-bytes=4 %s %s\n", codef, tmpbuf); if (system(cmdbuf) != 0) { unlink(tmpbuf); fprintf(stderr, "ZIP_SIM::Could not convert ELF binary to a raw file\n"); exit(-2); } tb->m_flash.load(0x0400, tmpbuf); unlink(tmpbuf); } else { tb->m_flash.load(0x0400, codef); } tb->reset(); while(1) tb->tick(); printf("SUCCESS!\n"); exit(0); }
Go to most recent revision | Compare with Previous | Blame | View Log