diff --git a/mibuild/sim/console_tb.cpp b/mibuild/sim/console_tb.cpp deleted file mode 100644 index 9468d24d4..000000000 --- a/mibuild/sim/console_tb.cpp +++ /dev/null @@ -1,168 +0,0 @@ -// This file is Copyright (c) 2015 Florent Kermarrec -// License: BSD - -#include - -#include "Vdut.h" -#include "verilated.h" -#include "verilated_vcd_c.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -int trace = 0; - -struct termios orig_termios; - -void reset_terminal_mode(void) -{ - tcsetattr(0, TCSANOW, &orig_termios); -} - -void set_conio_terminal_mode(void) -{ - struct termios new_termios; - - /* take two copies - one for now, one for later */ - tcgetattr(0, &orig_termios); - memcpy(&new_termios, &orig_termios, sizeof(new_termios)); - - /* register cleanup handler, and set the new terminal mode */ - atexit(reset_terminal_mode); - cfmakeraw(&new_termios); - tcsetattr(0, TCSANOW, &new_termios); -} - -int kbhit(void) -{ - struct timeval tv = { 0L, 0L }; - fd_set fds; - FD_ZERO(&fds); - FD_SET(0, &fds); - return select(1, &fds, NULL, NULL, &tv); -} - -int getch(void) -{ - int r; - unsigned char c; - if ((r = read(0, &c, sizeof(c))) < 0) { - return r; - } else { - return c; - } -} - -vluint64_t main_time = 0; -double sc_time_stamp() -{ - return main_time; -} - -Vdut* dut; -VerilatedVcdC* tfp; - -/* ios */ - -struct sim { - bool run; - - unsigned int tick; - clock_t start; - clock_t end; -}; - -int console_service(struct sim *s) -{ - /* fpga --> console */ - SERIAL_SOURCE_ACK = 1; - if(SERIAL_SOURCE_STB == 1) { - if (SERIAL_SOURCE_DATA == '\n') - putchar('\r'); - putchar(SERIAL_SOURCE_DATA); - fflush(stdout); - } - - /* console --> fpga */ - SERIAL_SINK_STB = 0; - if (s->tick%(1000) == 0) { - if(kbhit()) { - char c = getch(); - if (c == 27 && !kbhit()) { - printf("\r\n"); - return -1; - } else { - SERIAL_SINK_STB = 1; - SERIAL_SINK_DATA = c; - } - } - } - return 0; -} - -void sim_tick(struct sim *s) -{ - SYS_CLK = s->tick%2; - dut->eval(); - if (trace) - tfp->dump(s->tick); - s->tick++; -} - -void sim_init(struct sim *s) -{ - int i; - s->tick = 0; -#ifdef SYS_RST - SYS_RST = 1; - SYS_CLK = 0; - for (i=0; i<8; i++) - sim_tick(s); - SYS_RST = 0; -#endif - s->start = clock(); -} - -int main(int argc, char **argv, char **env) -{ - float speed; - - set_conio_terminal_mode(); - - Verilated::commandArgs(argc, argv); - dut = new Vdut; - - Verilated::traceEverOn(true); - tfp = new VerilatedVcdC; - dut->trace(tfp, 99); - tfp->open("dut.vcd"); - - struct sim s; - sim_init(&s); - - s.run = true; - while(s.run) { - sim_tick(&s); - if (SYS_CLK) { - if (console_service(&s) != 0) - s.run = false; - } - } - s.end = clock(); - - speed = (s.tick/2)/((s.end-s.start)/CLOCKS_PER_SEC); - - printf("average speed: %3.3f MHz\n\r", speed/1000000); - - tfp->close(); - - exit(0); -} diff --git a/mibuild/sim/ethernet_tb.cpp b/mibuild/sim/dut_tb.cpp similarity index 96% rename from mibuild/sim/ethernet_tb.cpp rename to mibuild/sim/dut_tb.cpp index 084cf1359..7aa9530de 100644 --- a/mibuild/sim/ethernet_tb.cpp +++ b/mibuild/sim/dut_tb.cpp @@ -79,7 +79,7 @@ int getch(void) mknod /dev/net/tap0 c 10 200 delete tap: openvpn --rmtun --dev tap0 */ - +#ifdef ETH_SOURCE_STB unsigned char eth_txbuffer[1532]; unsigned char eth_rxbuffer[1532]; int eth_txbuffer_len = 0; @@ -148,6 +148,7 @@ int eth_read_tap ( } return length; } +#endif Vdut* dut; VerilatedVcdC* tfp; @@ -259,6 +260,10 @@ void sim_init(struct sim *s) int main(int argc, char **argv, char **env) { + float speed; + + set_conio_terminal_mode(); + Verilated::commandArgs(argc, argv); dut = new Vdut; @@ -270,12 +275,14 @@ int main(int argc, char **argv, char **env) struct sim s; sim_init(&s); +#ifdef ETH_SOURCE_STB struct eth_device eth; char dev[] = "/dev/net/tap0"; char tap[] = "tap0"; eth.dev = dev; eth.tap = tap; eth_open(ð); +#endif s.run = true; while(s.run) { @@ -290,6 +297,11 @@ int main(int argc, char **argv, char **env) } s.end = clock(); + speed = (s.tick/2)/((s.end-s.start)/CLOCKS_PER_SEC); + + printf("average speed: %3.3f MHz\n\r", speed/1000000); + + tfp->close(); exit(0); diff --git a/mibuild/sim/verilator.py b/mibuild/sim/verilator.py index 84d4e5e6d..3c6bc8c82 100644 --- a/mibuild/sim/verilator.py +++ b/mibuild/sim/verilator.py @@ -109,7 +109,7 @@ def _run_sim(build_name): class VerilatorPlatform(GenericPlatform): # XXX fir sim_path def build(self, soc, build_dir="build", build_name="top", - sim_path="../migen/mibuild/sim/", dut="console_tb", + sim_path="../migen/mibuild/sim/", dut="dut_tb", run=True, verbose=False): tools.mkdir_noerror(build_dir) os.chdir(build_dir)