Add step 19 and run simulation in verilator.

This commit is contained in:
Bastian Löher
2023-02-28 01:36:36 +01:00
parent a7545ad8d4
commit af50b7df23
3 changed files with 54 additions and 0 deletions

27
19_verilator/run_verilator.sh Executable file
View File

@@ -0,0 +1,27 @@
#!/bin/bash
set -e
echo "Make sure:"
echo " - you've compiled a design previously, so build/top.v exists"
echo " - you've added the snippet.v to the 'top' module in build/top.v"
echo ""
read -n 1 -s -r -p "Press any key to continue or Ctrl-C to stop."
cd 19_verilator/.. || cd ../19_verilator/..
# generate C++ sources in 'obj_dir'
verilator \
-DBENCH \
-DBOARD_FREQ=12 \
-Wno-fatal \
--top-module soc \
-cc -exe \
19_verilator/sim_main.cpp \
build/top.v
# compile C++ sources
make -C obj_dir -j8 -f Vsoc.mk
# run the simulation
./obj_dir/Vsoc

15
19_verilator/sim_main.cpp Normal file
View File

@@ -0,0 +1,15 @@
#include "Vsoc.h"
#include "verilated.h"
#include <iostream>
int
main(int argc, char **argv, char **env)
{
Vsoc top;
top.clk = 0;
while (!Verilated::gotFinish()) {
top.clk = !top.clk;
top.eval();
}
return 0;
}

12
19_verilator/snippet.v Normal file
View File

@@ -0,0 +1,12 @@
// add this to the end of the 'top' module in build/top.v
`ifdef BENCH
always @(posedge clk)
begin
if(uart_valid)
begin
$write("%c", memory_mem_wdata[7:0] );
$fflush(32'h8000_0001);
end
end
`endif