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:
|
|
|
|
|
2022-09-04 16:14:45 -05:00
|
|
|
%.synth.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-09-04 16:14:45 -05:00
|
|
|
%.synth.v: %.synth.json %.v
|
2022-08-21 11:41:19 -05:00
|
|
|
( echo '`include "common.vh"'; grep timescale $*.v; \
|
2022-08-06 15:05:09 -05:00
|
|
|
$(SYNTH) -q -b verilog -f json $< ) | sed 's/endmodule/`DUMP(1)\n\0/g' > $@
|
|
|
|
|
2022-08-21 11:41:19 -05:00
|
|
|
# Don't warn about including the timescale from common.vh
|
|
|
|
IFLAGS := -g2012 -Wall -Wno-timescale
|
2022-08-06 15:05:09 -05:00
|
|
|
|
|
|
|
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)
|
|
|
|
|
2022-09-04 16:14:45 -05:00
|
|
|
%.synth.vvp: TOP = $(*F)
|
|
|
|
%.synth.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
|
|
|
|
%.synth.vvp: %.synth.v
|
2022-08-06 15:05:09 -05:00
|
|
|
$(run-icarus)
|
2022-05-15 21:52:26 -05:00
|
|
|
|
2022-09-04 16:14:45 -05:00
|
|
|
%.asc: %.synth.json
|
2022-05-15 21:52:26 -05:00
|
|
|
$(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)
|
|
|
|
|
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 =
|
|
|
|
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)
|
|
|
|
|
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-08-28 16:25:24 -05:00
|
|
|
MODULES := pcs pmd_io nrzi_encode nrzi_decode scramble descramble mdio mdio_io mii_io_rx mii_io_tx
|
2022-08-29 20:37:10 -05:00
|
|
|
MODULES += mdio_regs
|
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-05-15 21:52:26 -05:00
|
|
|
|
|
|
|
.PHONY: clean
|
|
|
|
clean:
|
|
|
|
rm *.fst
|
2022-09-04 16:14:45 -05:00
|
|
|
cd rtl && rm -f *.json *.asc *.pre *.vvp *.d *.synth.v
|