Verilog templating

This commit is contained in:
Andrew Kay
2020-02-04 22:11:14 -06:00
parent e24ba22a1f
commit ad7ba12d2c
9 changed files with 129 additions and 0 deletions

13
interface2/Makefile Normal file
View File

@@ -0,0 +1,13 @@
SUBDIRS = tests rtl
all: $(SUBDIRS)
$(SUBDIRS):
$(MAKE) -C $@
clean:
for dir in $(SUBDIRS); do \
$(MAKE) -C $$dir clean; \
done
.PHONY: all $(SUBDIRS) clean

3
interface2/rtl/.gitignore vendored Normal file
View File

@@ -0,0 +1,3 @@
*.json
*.asc
*.bin

25
interface2/rtl/Makefile Normal file
View File

@@ -0,0 +1,25 @@
YOSYS ?= yosys
NEXTPNR ?= nextpnr-ice40
ICEPACK ?= icepack
TINYPROG ?= tinyprog
all: top.bin
top.json: top.v coax_tx.v
prog: top.bin
$(TINYPROG) -p top.bin
clean:
rm -f *.json *.asc *.bin
%.json:
$(YOSYS) -p 'synth_ice40 -top top -json $@' $^
%.asc: %.json pins.pcf
$(NEXTPNR) --lp8k --package cm81 --json $< --pcf pins.pcf --asc $@
%.bin: %.asc
$(ICEPACK) $< $@
.PHONY: all prog clean

15
interface2/rtl/coax_tx.v Normal file
View File

@@ -0,0 +1,15 @@
`default_nettype none
module coax_tx (
input clk,
output tx
);
reg state = 0;
always @(posedge clk)
begin
state <= ~state;
end
assign tx = state;
endmodule

6
interface2/rtl/pins.pcf Normal file
View File

@@ -0,0 +1,6 @@
set_io --warn-no-port tx B8
# 16MHz clock
set_io --warn-no-port clk B2
set_io --warn-no-port usb_pu A3

14
interface2/rtl/top.v Normal file
View File

@@ -0,0 +1,14 @@
`default_nettype none
module top (
input clk,
output tx,
output usb_pu
);
coax_tx coax_tx (
.clk(clk),
.tx(tx)
);
assign usb_pu = 0;
endmodule

2
interface2/tests/.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
*_tb
*.vcd

19
interface2/tests/Makefile Normal file
View File

@@ -0,0 +1,19 @@
IVERILOG ?= iverilog
VVP ?= vvp
RTL = ../rtl
all: coax_tx_tb.vcd
coax_tx_tb: coax_tx_tb.v $(RTL)/coax_tx.v
clean:
rm -f *_tb *.vcd
%_tb:
$(IVERILOG) -o $@ $^
%_tb.vcd: %_tb
$(VVP) -N $< -lxt2
.PHONY: all, clean

View File

@@ -0,0 +1,32 @@
`default_nettype none
module coax_tx_tb();
reg clk = 0;
initial
begin
clk <= 1'h0;
forever
begin
#1 clk <= ~clk;
end
end
wire tx;
coax_tx dut (
.clk(clk),
.tx(tx)
);
initial
begin
$dumpfile("coax_tx_tb.vcd");
$dumpvars(0, coax_tx_tb);
repeat(100) @(posedge clk);
$finish;
end
endmodule