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
|
2023-03-01 18:14:59 -06:00
|
|
|
ADOC = asciidoctor
|
2022-05-15 21:52:26 -05:00
|
|
|
SYNTH = yosys
|
|
|
|
PNR = nextpnr-ice40
|
|
|
|
ICARUS = iverilog
|
2023-02-20 21:39:43 -06:00
|
|
|
ICEPACK = icepack
|
2022-05-15 21:52:26 -05:00
|
|
|
VVP = vvp
|
|
|
|
|
2022-10-16 17:00:02 -05:00
|
|
|
.DELETE_ON_ERROR:
|
|
|
|
|
2022-05-15 21:52:26 -05:00
|
|
|
.PHONY: all
|
2023-02-20 18:06:49 -06:00
|
|
|
all: examples/breakout_hub/top.bin
|
2022-05-15 21:52:26 -05:00
|
|
|
|
|
|
|
.PHONY: FORCE
|
|
|
|
FORCE:
|
|
|
|
|
2022-10-16 17:00:02 -05:00
|
|
|
log:
|
|
|
|
mkdir $@
|
|
|
|
|
2023-02-20 17:55:55 -06:00
|
|
|
INCDIRS := rtl
|
2023-01-09 19:59:27 -06:00
|
|
|
LIBDIRS := rtl lib/verilog-lfsr/rtl
|
2022-10-16 17:00:02 -05:00
|
|
|
%.synth.json: %.v | log
|
2023-02-18 20:20:53 -06:00
|
|
|
$(SYNTH) -q -E $@.d -b json -o $@ -l log/$(*F).synth \
|
2023-02-20 17:55:55 -06:00
|
|
|
-p "read_verilog $(addprefix -I ,$(INCDIRS)) -sv $<" \
|
2023-02-18 20:20:53 -06:00
|
|
|
-p "hierarchy $(addprefix -libdir ,$(LIBDIRS) $(<D))" \
|
|
|
|
-p "synth_ice40 -top $(*F)"
|
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
|
|
|
|
2023-02-20 22:03:57 -06:00
|
|
|
IFLAGS := -g2012 -gspecify -Wall
|
2022-08-21 11:41:19 -05:00
|
|
|
# Don't warn about including the timescale from common.vh
|
2023-02-20 22:03:57 -06:00
|
|
|
IFLAGS += -Wno-timescale
|
|
|
|
# Don't warn about mem2reg sensitivity
|
|
|
|
IFLAGS += -Wno-sensitivity-entire-array
|
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 =
|
2023-01-09 19:59:27 -06:00
|
|
|
$(ICARUS) $(IFLAGS) -I$(<D) $(addprefix -y,$(LIBDIRS) $(<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)
|
|
|
|
|
2023-01-22 15:26:35 -06:00
|
|
|
PNRARGS := --freq 125 --hx8k --package ct256 --pcf-allow-unconstrained --no-promote-globals
|
|
|
|
|
|
|
|
define run-pnr =
|
|
|
|
$(PNR) -q $(PNRARGS) --json $< --log log/$(*F).$(LOG_EXT)
|
|
|
|
endef
|
|
|
|
|
|
|
|
%.sdf %.place.json &: PNRARGS += --write $*.place.json --sdf $*.sdf
|
|
|
|
%.sdf %.place.json &: LOG_EXT := place
|
|
|
|
%.sdf %.place.json &: %.synth.json | log
|
|
|
|
$(run-pnr)
|
|
|
|
|
2023-02-18 21:46:45 -06:00
|
|
|
PNR_RETRIES := 10
|
|
|
|
|
2023-01-22 15:26:35 -06:00
|
|
|
%.asc: PNRARGS += --pcf $*.pcf --asc $@ -r
|
|
|
|
%.asc: LOG_EXT := asc
|
|
|
|
%.asc: %.synth.json %.pcf | log
|
2023-02-18 21:46:45 -06:00
|
|
|
for i in $$(seq $(PNR_RETRIES)); do \
|
|
|
|
if $(run-pnr); then \
|
|
|
|
exit 0; \
|
|
|
|
fi \
|
|
|
|
done; \
|
|
|
|
exit 1
|
2023-01-22 15:26:35 -06:00
|
|
|
|
2023-02-20 17:55:55 -06:00
|
|
|
%.bin: %.asc
|
2023-01-22 15:26:35 -06:00
|
|
|
$(ICEPACK) $< $@
|
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-30 16:57:31 -06:00
|
|
|
MODULES += axis_replay_buffer
|
2023-02-20 21:37:10 -06:00
|
|
|
MODULES += axis_mii_tx
|
2023-03-01 18:14:59 -06:00
|
|
|
MODULES += axis_wb_bridge
|
2022-11-30 16:57:31 -06:00
|
|
|
MODULES += descramble
|
2023-02-20 17:24:49 -06:00
|
|
|
MODULES += hub
|
2023-02-20 21:37:10 -06:00
|
|
|
MODULES += hub_core
|
2023-02-15 10:03:38 -06:00
|
|
|
MODULES += led_blinker
|
2022-11-30 16:57:31 -06:00
|
|
|
MODULES += mdio
|
|
|
|
MODULES += mdio_io
|
|
|
|
MODULES += mdio_regs
|
2023-02-12 18:53:44 -06:00
|
|
|
MODULES += mii_elastic_buffer
|
2022-11-30 16:57:31 -06:00
|
|
|
MODULES += mii_io_rx
|
|
|
|
MODULES += mii_io_tx
|
|
|
|
MODULES += nrzi_decode
|
|
|
|
MODULES += nrzi_encode
|
|
|
|
MODULES += pcs_rx
|
|
|
|
MODULES += pcs_tx
|
|
|
|
MODULES += phy_core
|
2022-11-30 17:05:30 -06:00
|
|
|
MODULES += pmd_dp83223
|
2022-11-30 16:57:31 -06:00
|
|
|
MODULES += pmd_dp83223_rx
|
|
|
|
MODULES += scramble
|
2023-02-27 22:20:56 -06:00
|
|
|
MODULES += uart_tx
|
2023-02-28 21:19:22 -06:00
|
|
|
MODULES += uart_rx
|
2023-02-18 21:32:12 -06:00
|
|
|
MODULES += wb_mux
|
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
|
|
|
|
2023-03-01 18:14:59 -06:00
|
|
|
doc/output:
|
|
|
|
mkdir -p $@
|
|
|
|
|
|
|
|
doc/output/%.html: doc/%.adoc doc/docinfo.html | doc/output
|
|
|
|
$(ADOC) -o $@ $<
|
|
|
|
|
|
|
|
DOCS += uart_wb_bridge
|
|
|
|
|
|
|
|
.PHONY: htmldocs
|
|
|
|
htmldocs: $(addprefix doc/output/,$(addsuffix .html,$(DOCS)))
|
|
|
|
|
2023-02-20 17:54:25 -06:00
|
|
|
CLEAN_EXT := .json .asc .pre .vvp .d .synth.v .place.v .sdf .bin
|
2023-02-20 17:52:31 -06:00
|
|
|
|
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
|
2023-02-20 17:52:31 -06:00
|
|
|
rm -f $(addprefix rtl/*,$(CLEAN_EXT))
|
2023-02-20 18:06:49 -06:00
|
|
|
rm -f $(addprefix examples/*/*,$(CLEAN_EXT))
|
2023-03-01 18:14:59 -06:00
|
|
|
rm -rf doc/output
|