Skip to content

Instantly share code, notes, and snippets.

@paranlee
Last active August 10, 2021 07:17
Show Gist options
  • Select an option

  • Save paranlee/3167669a9fb3af8d7e4beea45de812f3 to your computer and use it in GitHub Desktop.

Select an option

Save paranlee/3167669a9fb3af8d7e4beea45de812f3 to your computer and use it in GitHub Desktop.
Setup from setup.sh. Build netlist svg file. $ bash netlist.sh dff
/**
* 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
/**
* 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
#!/bin/bash
yosys -q -p "prep -top $1; write_json $1.json" $1.v
netlistsvg $1.json -o $1.svg
#!/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