2022-05-15 21:52:26 -05:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-Only
|
|
|
|
# Copyright (C) 2022 Sean Anderson <seanga2@gmail.com>
|
|
|
|
|
|
|
|
Q = 1
|
|
|
|
SYNTH = yosys
|
|
|
|
PNR = nextpnr-ice40
|
|
|
|
ICARUS = iverilog
|
|
|
|
VVP = vvp
|
|
|
|
|
|
|
|
.PHONY: all
|
|
|
|
all: rtl/pcs.asc
|
|
|
|
|
|
|
|
.PHONY: FORCE
|
|
|
|
FORCE:
|
|
|
|
|
|
|
|
%.json: %.v
|
2022-08-06 15:05:09 -05:00
|
|
|
$(SYNTH) -q -E $@.d -p "synth_ice40 -top $(*F)" -b json -o $@ -f verilog $<
|
2022-05-15 21:52:26 -05:00
|
|
|
|
2022-08-06 15:05:09 -05:00
|
|
|
%.post.v: %.json %.v
|
|
|
|
( grep timescale $*.v && echo '`include "common.vh"' && \
|
|
|
|
$(SYNTH) -q -b verilog -f json $< ) | sed 's/endmodule/`DUMP(1)\n\0/g' > $@
|
|
|
|
|
|
|
|
IFLAGS := -g2012 -Wall
|
|
|
|
|
|
|
|
define run-icarus =
|
|
|
|
$(ICARUS) $(IFLAGS) -I$(<D) -M$@.pre -s $(TOP) -o $@ $< $(EXTRA_V) && \
|
|
|
|
( echo -n "$@: " && tr '\n' ' ' ) < $@.pre > $@.d; RET=$$?; rm -f $@.pre; exit $$RET
|
|
|
|
endef
|
|
|
|
|
|
|
|
%.vvp: TOP = $(*F)
|
2022-05-15 21:52:26 -05:00
|
|
|
%.vvp: %.v
|
2022-08-06 15:05:09 -05:00
|
|
|
$(run-icarus)
|
|
|
|
|
|
|
|
%.post.vvp: TOP = $(*F)
|
|
|
|
%.post.vvp: EXTRA_V := $(shell $(SYNTH)-config --datdir)/ice40/cells_sim.v
|
|
|
|
# Don't warn about unused SB_IO ports
|
|
|
|
%.post.vvp: IFLAGS += -Wno-portbind
|
|
|
|
%.post.vvp: %.post.v
|
|
|
|
$(run-icarus)
|
2022-05-15 21:52:26 -05:00
|
|
|
|
|
|
|
%.asc: %.json
|
|
|
|
$(PNR) --pcf-allow-unconstrained --freq 125 --hx8k --package ct256 --json $< --asc $@
|
|
|
|
|
|
|
|
-include $(wildcard rtl/*.d)
|
|
|
|
|
|
|
|
export LIBPYTHON_LOC := $(shell cocotb-config --libpython)
|
2022-08-06 15:05:09 -05:00
|
|
|
VVPFLAGS := -M $(shell cocotb-config --lib-dir)
|
|
|
|
VVPFLAGS += -m $(shell cocotb-config --lib-name vpi icarus)
|
|
|
|
|
|
|
|
define run-vvp =
|
|
|
|
MODULE=tb.$* $(VVP) $(VVPFLAGS) $< -fst +vcd=$@
|
|
|
|
endef
|
2022-05-15 21:52:26 -05:00
|
|
|
|
|
|
|
%.fst: rtl/%.vvp tb/%.py FORCE
|
2022-08-06 15:05:09 -05:00
|
|
|
$(run-vvp)
|
|
|
|
|
|
|
|
%.post.fst: rtl/%.post.vvp tb/%.py FORCE
|
|
|
|
$(run-vvp)
|
2022-05-15 21:52:26 -05:00
|
|
|
|
|
|
|
.PHONY: test
|
2022-08-06 15:05:09 -05:00
|
|
|
test: $(addsuffix .fst,pcs pmd) $(addsuffix .post.fst,pcs pmd)
|
2022-05-15 21:52:26 -05:00
|
|
|
|
|
|
|
.PHONY: clean
|
|
|
|
clean:
|
|
|
|
rm *.fst
|
2022-08-06 15:05:09 -05:00
|
|
|
cd rtl && rm -f *.json *.asc *.pre *.vvp *.d *.post.v
|