-
Notifications
You must be signed in to change notification settings - Fork 6
/
Makefile
executable file
·197 lines (156 loc) · 6.05 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
# Makefile borrowed from https://github.com/cliffordwolf/icestorm/blob/master/examples/icestick/Makefile
#
# The following license is from the icestorm project and specifically applies to this file only:
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
# Do not use make's built-in rules
# (this improves performance and avoids hard-to-debug behaviour);
MAKEFLAGS += -r
# default board is rapbo
BOARD ?= rapbo
ifdef BOARD
include ./boards/${BOARD}/${BOARD}.mk
endif
# Default parameters for PLL, since they are always generated, even if not used
SPIFREQ ?= 64
PWMFREQ ?= 150
# Default flags
SYNTH_FLAGS ?= -abc9
PNR_FLAGS ?=
YOSYS_FLAGS ?= -DBOARD=$(BOARD)
YOSYS_READ_VERILOG ?= read_verilog -sv -noassert -noassume -norestrict -defer
PROJ = rapcore
TOP = ./src/rapcore.v
GENERATEDDIR = ./src/generated/
SRCDIR = ./src/
BUILDDIR = ./build/
BUILD = $(BUILDDIR)$(BOARD)
RAPCOREFILES := boards/$(BOARD)/$(BOARD).v \
$(addprefix src/, clock_divider.v \
edge_detector.v \
macro_params.v \
register_input.v \
space_vector_modulator.v \
spi_state_machine.v \
pwm.v \
quad_enc.v \
spi.v \
dda_fsm.v \
dual_hbridge.v \
dda_timer.v \
rapcore.v) \
$(wildcard src/microstepper/*.v)
# Some architectures or clock specs cannot have auto generated PLL.
# Define MANUALPLL=1 and instantiate PLL for include with a module like:
# module spi_pll(
# input clock_in,
# output clock_out,
# output locked
# );
ifndef MANUALPLL
PLLFILES := src/generated/spi_pll_$(ARCH)_$(SPIFREQ).v src/generated/pwm_pll_$(ARCH)_$(PWMFREQ).v
endif
ifdef MANUALPLL
PLLFILES := boards/$(BOARD)/spi_pll.v boards/$(BOARD)/pwm_pll.v
endif
SYNTHFILES = $(RAPCOREFILES)
SYNTHFILES += $(PLLFILES)
SIMFILES = $(RAPCOREFILES)
SIMFILES += ./src/sim/pwm_pll.v
all: $(BUILD).bit
$(BUILD).json: logs build $(SYNTHFILES)
yosys -ql ./logs/$(BOARD)_yosys.log $(YOSYS_FLAGS) -p '$(YOSYS_READ_VERILOG) $(SYNTHFILES); synth_$(ARCH) -top $(PROJ) $(SYNTH_FLAGS) -json $(BUILD).json'
$(BUILD).bit: $(BUILD).json ./boards/$(BOARD)/$(PIN_DEF)
ifeq ($(ARCH), ice40)
nextpnr-ice40 -ql ./logs/$(BOARD)_nextpnr.log $(PNR_FLAGS) --$(DEVICE) --freq $(FREQ) --package $(PACKAGE) --json $(BUILD).json --asc $(BUILD).asc --pcf ./boards/$(BOARD)/$(PIN_DEF)
icetime -d $(DEVICE) -c $(FREQ) -mtr $(BUILD).rpt $(BUILD).asc
icepack $(BUILD).asc $(BUILD).bit
endif
ifeq ($(ARCH), ecp5)
nextpnr-ecp5 -ql ./logs/$(BOARD)_nextpnr.log $(PNR_FLAGS) --$(DEVICE) --freq $(FREQ) --package $(PACKAGE) --textcfg $(BUILD)_out.config --json $(BUILD).json --lpf ./boards/$(BOARD)/$(PIN_DEF)
ecppack --svf $(BUILD).svf $(BUILD)_out.config $(BUILD).bit
endif
ifeq ($(ARCH), nexus)
nextpnr-nexus -ql ./logs/$(BOARD)_nextpnr.log $(PNR_FLAGS) --device $(DEVICE) --freq $(FREQ) --json $(BUILD).json --fasm $(BUILD).fasm --pdc ./boards/$(BOARD)/$(PIN_DEF)
prjoxide pack $(BUILD).fasm $(BUILD).bit
endif
ifeq ($(ARCH), gowin)
nextpnr-gowin -ql ./logs/$(BOARD)_nextpnr.log $(PNR_FLAGS) --device $(DEVICE) --freq $(FREQ) --json $(BUILD).json --cst ./boards/$(BOARD)/$(PIN_DEF)
gowin_pack $(PACK_FLAGS) -o $(BUILD).bit $(BUILD).json
endif
$(PLLFILES):
ifndef MANUALPLL
ifeq ($(ARCH), ice40)
icepll -i $(FREQ) -o $(SPIFREQ) -m -n spi_pll -f src/generated/spi_pll_$(ARCH)_$(SPIFREQ).v
icepll -i $(FREQ) -o $(PWMFREQ) -m -n pwm_pll -f src/generated/pwm_pll_$(ARCH)_$(PWMFREQ).v
endif
ifeq ($(ARCH), ecp5)
ecppll -i $(FREQ) -o $(SPIFREQ) --clkin_name clock_in --clkout0_name clock_out -n spi_pll -f src/generated/spi_pll_$(ARCH)_$(SPIFREQ).v
ecppll -i $(FREQ) -o $(PWMFREQ) --clkin_name clock_in --clkout0_name clock_out -n pwm_pll -f src/generated/pwm_pll_$(ARCH)_$(PWMFREQ).v
endif
endif
build-full: build logs formal iverilog-parse $(BUILD).bit
logs:
mkdir -p logs
build:
mkdir -p build
build/clocks_$(BOARD).py:
printf "ctx."
prog: $(BUILD).bit
$(PROGRAMMER) $<
clean:
rm -f $(BUILD).blif $(BUILD).asc $(BUILD).rpt $(BUILD).json $(BUILD).bin $(BUILD).bit ./src/generated/*.v
cleanall:
rm -rf build logs ./src/generated/*.v
formal:
cat symbiyosys/symbiyosys.sby boards/$(BOARD)/$(BOARD).v > symbiyosys/symbiyosys_$(BOARD).sby
sby -f symbiyosys/symbiyosys_$(BOARD).sby
iverilog-parse: $(SIMFILES)
iverilog -tnull -g2012 -E -Wall $(SIMFILES)
yosys-parse: $(SIMFILES)
yosys -qp 'read -sv $(SIMFILES)'
verilator-cdc: $(SIMFILES)
verilator --top-module rapcore --clk CLK --cdc $(SIMFILES)
triple-check: yosys-parse iverilog-parse verilator-cdc
svlint: $(SIMFILES)
svlint $(SIMFILES)
vvp: $(SIMFILES)
iverilog -tvvp -g2012 $(SIMFILES)
testbench/vcd:
mkdir -p testbench/vcd
yosys-%: testbench/vcd $(SIMFILES)
yosys -s testbench/yosys/$*.ys $(SIMFILES)
gtkwave testbench/vcd/$*.vcd
cxxrtl-%: testbench/vcd
yosys testbench/cxxrtl/$*.ys
clang++ -g -O3 -std=c++14 -I `yosys-config --datdir`/include testbench/cxxrtl/$*.cpp -o testbench/cxxrtl/$*.bin
./testbench/cxxrtl/$*.bin
gtkwave testbench/vcd/$*_cxxrtl.vcd
docs-%:
make -C docs teros-$*
make -C docs $*
stat:
yosys -s yosys/stats.ys $(SIMFILES) $(GENERATEDFILES)
ice40:
yosys -s yosys/ice40.ys $(SIMFILES) $(GENERATEDFILES)
#
# RAPcore-cli and librapcore recipes
#
CFLAGS += -O2 -Wall -g -D_GNU_SOURCE -I$(OUTPUT)include
rapcore-cli: librapcore/rapcore-cli.c librapcore/librapcore.h
$(CC) $(CFLAGS) $(LDFLAGS) $< -o $@
#
# Misc.
#
.SECONDARY:
.PHONY: all prog clean formal build-full