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
|
|
|
|
|
2022-10-16 17:00:02 -05:00
|
|
|
.DELETE_ON_ERROR:
|
|
|
|
|
2022-05-15 21:52:26 -05:00
|
|
|
.PHONY: all
|
|
|
|
all: rtl/pcs.asc
|
|
|
|
|
|
|
|
.PHONY: FORCE
|
|
|
|
FORCE:
|
|
|
|
|
2022-10-16 17:00:02 -05:00
|
|
|
log:
|
|
|
|
mkdir $@
|
|
|
|
|
|
|
|
%.synth.json: %.v | log
|
|
|
|
$(SYNTH) -q -E $@.d -p "synth_ice40 -top $(*F)" -b json -o $@ -f verilog $< -l log/$(*F).synth
|
2022-05-15 21:52:26 -05:00
|
|
|
|
2022-10-16 16:52:27 -05:00
|
|
|
define run-jsontov =
|
2022-10-28 17:28:28 -05:00
|
|
|
( grep timescale $*.v; $(SYNTH) -q -p "write_verilog -defparam -noattr" -f json $< ) > $@
|
2022-10-16 16:52:27 -05:00
|
|
|
endef
|
|
|
|
|
|
|
|
%.synth.v: %.synth.json %.v
|
|
|
|
$(run-jsontov)
|
|
|
|
|
|
|
|
%.place.v: %.place.json %.v
|
|
|
|
$(run-jsontov)
|
2022-08-06 15:05:09 -05:00
|
|
|
|
2022-08-21 11:41:19 -05:00
|
|
|
# Don't warn about including the timescale from common.vh
|
2022-10-16 16:52:27 -05:00
|
|
|
IFLAGS := -g2012 -gspecify -Wall -Wno-timescale
|
2022-10-28 17:28:28 -05:00
|
|
|
EXTRA_V := rtl/iverilog_dump.v
|
2022-08-06 15:05:09 -05:00
|
|
|
|
|
|
|
define run-icarus =
|
2022-11-05 11:11:00 -05:00
|
|
|
$(ICARUS) $(IFLAGS) -I$(<D) -y$(<D) -M$@.pre -DTOP=$(TOP) -s $(TOP) -s iverilog_dump -o $@ $< $(EXTRA_V) && \
|
2022-08-06 15:05:09 -05:00
|
|
|
( echo -n "$@: " && tr '\n' ' ' ) < $@.pre > $@.d; RET=$$?; rm -f $@.pre; exit $$RET
|
|
|
|
endef
|
|
|
|
|
|
|
|
%.vvp: TOP = $(*F)
|
2022-10-28 17:28:28 -05:00
|
|
|
%.vvp: %.v rtl/iverilog_dump.v
|
2022-08-06 15:05:09 -05:00
|
|
|
$(run-icarus)
|
|
|
|
|
2022-09-04 16:14:45 -05:00
|
|
|
%.synth.vvp: TOP = $(*F)
|
2022-10-28 17:28:28 -05:00
|
|
|
%.synth.vvp %.place.vvp: EXTRA_V += $(shell $(SYNTH)-config --datdir)/ice40/cells_sim.v
|
2022-08-06 15:05:09 -05:00
|
|
|
# Don't warn about unused SB_IO ports
|
2022-09-04 16:14:45 -05:00
|
|
|
%.synth.vvp: IFLAGS += -Wno-portbind
|
2022-10-28 17:28:28 -05:00
|
|
|
%.synth.vvp: %.synth.v rtl/iverilog_dump.v
|
2022-08-06 15:05:09 -05:00
|
|
|
$(run-icarus)
|
2022-05-15 21:52:26 -05:00
|
|
|
|
2022-10-16 16:52:27 -05:00
|
|
|
%.place.vvp: TOP = top
|
|
|
|
# Don't warn about unused SB_IO ports
|
|
|
|
%.place.vvp: IFLAGS += -Wno-portbind
|
|
|
|
%.place.vvp: IFLAGS += -DTIMING -Ttyp
|
2022-10-28 17:28:28 -05:00
|
|
|
%.place.vvp: %.place.v rtl/iverilog_dump.v
|
2022-10-16 16:52:27 -05:00
|
|
|
$(run-icarus)
|
|
|
|
|
|
|
|
%.asc %.sdf %.place.json &: %.synth.json | log
|
|
|
|
$(PNR) -q --pcf-allow-unconstrained --freq 125 --hx8k --package ct256 --json $< \
|
|
|
|
--write $*.place.json --sdf $*.sdf --asc $*.asc --log log/$(*F).place
|
2022-05-15 21:52:26 -05:00
|
|
|
|
|
|
|
-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)
|
2022-10-16 16:52:27 -05:00
|
|
|
PLUSARGS = -fst +vcd=$@
|
2022-08-06 15:05:09 -05:00
|
|
|
|
2022-08-24 11:07:25 -05:00
|
|
|
# Always use color output if we have a tty. This allows for easy use of -O
|
|
|
|
ifeq ($(shell test -c /dev/stdin && echo 1),1)
|
|
|
|
export COCOTB_ANSI_OUTPUT=1
|
|
|
|
endif
|
|
|
|
|
2022-08-06 15:05:09 -05:00
|
|
|
define run-vvp =
|
2022-10-16 16:52:27 -05:00
|
|
|
MODULE=tb.$* $(VVP) $(VVPFLAGS) $< $(PLUSARGS)
|
2022-08-06 15:05:09 -05:00
|
|
|
endef
|
2022-05-15 21:52:26 -05:00
|
|
|
|
2022-10-28 17:28:28 -05:00
|
|
|
%.fst: PLUSARGS += +levels=0
|
2022-05-15 21:52:26 -05:00
|
|
|
%.fst: rtl/%.vvp tb/%.py FORCE
|
2022-08-06 15:05:09 -05:00
|
|
|
$(run-vvp)
|
|
|
|
|
2022-10-28 17:28:28 -05:00
|
|
|
%.synth.fst: PLUSARGS += +levels=1
|
2022-09-04 16:14:45 -05:00
|
|
|
%.synth.fst: rtl/%.synth.vvp tb/%.py FORCE
|
2022-08-06 15:05:09 -05:00
|
|
|
$(run-vvp)
|
2022-05-15 21:52:26 -05:00
|
|
|
|
2022-10-28 17:28:28 -05:00
|
|
|
%.place.fst: PLUSARGS += +levels=1 +sdf=rtl/$*.sdf
|
2022-10-16 16:52:27 -05:00
|
|
|
%.place.fst: rtl/%.place.vvp rtl/%.sdf tb/%.py FORCE
|
|
|
|
$(run-vvp)
|
|
|
|
|
2022-11-05 11:04:00 -05:00
|
|
|
MODULES := pcs_rx pcs_tx pmd_dp83223_rx nrzi_encode nrzi_decode scramble descramble mdio mdio_io
|
2022-11-30 14:23:59 -06:00
|
|
|
MODULES += mii_io_rx mii_io_tx mdio_regs phy_core axis_replay_buffer
|
2022-08-24 11:10:07 -05:00
|
|
|
|
2022-05-15 21:52:26 -05:00
|
|
|
.PHONY: test
|
2022-09-04 16:14:45 -05:00
|
|
|
test: $(addsuffix .fst,$(MODULES)) $(addsuffix .synth.fst,$(MODULES))
|
2022-10-16 16:52:27 -05:00
|
|
|
#test: $(addsuffix .place.fst,$(MODULES))
|
|
|
|
|
|
|
|
.PHONY: asc
|
|
|
|
asc: $(addprefix rtl/,$(addsuffix .asc,$(MODULES)))
|
2022-05-15 21:52:26 -05:00
|
|
|
|
|
|
|
.PHONY: clean
|
|
|
|
clean:
|
2022-10-16 16:52:27 -05:00
|
|
|
rm -f *.fst
|
2022-11-05 11:06:01 -05:00
|
|
|
rm -rf log
|
2022-10-16 16:52:27 -05:00
|
|
|
cd rtl && rm -f *.json *.asc *.pre *.vvp *.d *.synth.v *.place.v
|