export DISPLAY=$(grep -m 1 nameserver /etc/resolv.conf | awk '{print $2}'):0.0
to the file "~/.bashrc"
.
shell:startup
.
sudo apt install python3
brew install python3
sudo apt install python3-pip
brew install python3-pip
pip3 install --upgrade --user fusesoc
"~/.local/bin"
"iverilog"
folder to "~/Utils/iverilog"
. (Open \\wsl$
in Explorer.)"~/Utils/iverilog/bin"
to path. (Add export PATH=$PATH:~/Utils/iverilog/bin
to the file "~/.bashrc"
.)chmod +x ~/Utils/iverilog/bin/* ~/Utils/iverilog/lib/ivl/*
to make iverilog runnable.brew install icarus-verilog
iverilog -v
sudo apt install gtkwave
brew tap homebrew/cask
brew install gtkwave --cask
sudo cpan install Switch
perl -V:'installsitelib'
"/usr/local/Cellar/perl/..."
, then Switch must be coppied to the correct location in "/Library/Perl/5.*/"
with sudo cp /usr/local/Cellar/perl/5.*/lib/perl5/site_perl/5.*/Switch.pm /Library/Perl/5.*/
/Applications/gtkwave.app/Contents/Resources/bin/gtkwave
"/Applications/gtkwave.app/Contents/Resources/bin/"
to path.
Download this Verilog project template, and run make view
to ensure everything was installed correctly. It should simulate the Verilog and open the waves in GTKWave.
Verilog is a hardware description language (HDL). Just as markup languages such as HTML and Markdown are not programming languages, HDLs are not programming languages. HDLs describe register-transfer level (RTL) circuits that can be either simulated or synthesized. In this class, we will be writing RTL in Verilog; we will be simulating the design in Icarus Verilog and synthesizing the design with Yosys.
There are lots of “good” Verilog resources already available. Skim this if you have any questions on syntax: Verilog In One Day. If you want to see the circuit that will be generated by Verilog, use DigitalJS Online.
Note, we will actually be using SystemVerilog for this project. SystemVerilog gives you extra functionality that Verilog does not. (SystemVerilog is to Verilog as C++ is to C.) You can still refer to vanilla Verilog guides because everything will carry to SystemVerilog. However, not all tools support all SystemVerilog features, so make sure a feature is supported before using it. To use SystemVerilog, make sure your filename extensions are “.sv”.
To implement combinational logic in Verilog, you must use assign
or always_comb
.
Notice that you can use C-like functionality such as integer arithmetic, for loops, if-else statements, and more.
However, Icarus Verilog will often mistakenly simulate unsynthesizable Verilog. This class will try to only cover best practices for writing Verilog, but Icarus is so forgiving that you may accidentally write something that works in simulation, but not in synthesis. For example, every modified value in an always_comb
block must have a default value; if it does not, Yosys will infer a latch, which is unsupported. If you are ever unsure about what you wrote, test it with DigitalJS Online.
To implement flip flops in Verilog, you must use always_ff @ (posedge clk)
or always_ff @ (negedge clk)
. For best practice, you should add a reset to every register. Non-blocking assignment <=
must be used to signify that all assignments happen as soon as a clock pulse occurs. There should be no combinational logic inside an always_ff
block, otherwise synthesis tools will have trouble deciphering what logic should be treated as a clock or reset.
To test a design, you need to simulate a test for it. You do this by creating a testbench. A testbench should have:
$finish;
at the end.$dumpfile("dump.fst"); $dumpvars;
#1
.For example, in the following code, the resulting outputs of the full adder are verified for all 8 possible inputs.
You can also open the dump file in GTKWave, which will display all the nets at every point in time. To run this on the Verilog template, do make view
.