Last active
August 10, 2021 07:17
-
-
Save paranlee/3167669a9fb3af8d7e4beea45de812f3 to your computer and use it in GitHub Desktop.
Setup from setup.sh. Build netlist svg file. $ bash netlist.sh dff
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * D flip-flop: | |
| * https://github.com/edaplayground/eda-playground/blob/master/docs/code-examples/d-flip-flop.rst | |
| */ | |
| module dff (clk, reset, | |
| d, q, qb); | |
| input clk; | |
| input reset; | |
| input d; | |
| output q; | |
| output qb; | |
| reg q; | |
| assign qb = ~q; | |
| always @(posedge clk or posedge reset) | |
| begin | |
| if (reset) begin | |
| // Asynchronous reset when reset goes high | |
| q <= 1'b0; | |
| end else begin | |
| // Assign D to Q on positive clock edge | |
| q <= d; | |
| end | |
| end | |
| endmodule |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * D flip-flop Testbench: | |
| * https://github.com/edaplayground/eda-playground/blob/master/docs/code-examples/d-flip-flop.rst | |
| */ | |
| module test; | |
| reg clk; | |
| reg reset; | |
| reg d; | |
| wire q; | |
| wire qb; | |
| // Instantiate design under test | |
| dff DFF(.clk(clk), .reset(reset), | |
| .d(d), .q(q), .qb(qb)); | |
| initial begin | |
| // Dump waves | |
| $dumpfile("dump.vcd"); | |
| $dumpvars(1); | |
| $display("Reset flop."); | |
| clk = 0; | |
| reset = 1; | |
| d = 1'bx; | |
| display; | |
| $display("Release reset."); | |
| d = 1; | |
| reset = 0; | |
| display; | |
| $display("Toggle clk."); | |
| clk = 1; | |
| display; | |
| end | |
| task display; | |
| #1 $display("d:%0h, q:%0h, qb:%0h", | |
| d, q, qb); | |
| endtask | |
| endmodule |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| yosys -q -p "prep -top $1; write_json $1.json" $1.v | |
| netlistsvg $1.json -o $1.svg |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # verilog | |
| sudo apt -y install iverilog gtkwave yosys yosys-doc | |
| # node.js | |
| curl -fsSL https://deb.nodesource.com/setup_current.x | sudo -E bash - | |
| sudo apt -y install nodejs | |
| sudo npm install -g netlistsvg |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment