aboutsummaryrefslogtreecommitdiffstats
path: root/Makefile
blob: f8d94ef89e3b9c40d1beae8db1bddf9e1d8b1263 (plain) (blame)
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
# Makefile for TurboSwap FPGA (iCE40UP3K)
# Uses Yosys/IceStorm toolchain

# FPGA device
DEVICE = iCE40UP3K-SG48

# Verilog source files
HDL_SRC = hdl/turbo_top.v \
          hdl/sdio_to_spi.v \
          hdl/spi_controller.v \
          hdl/clock_divider.v \
          hdl/fifo_buffer.v

# Simulation files
SIM_SRC = sim/tb_turbo_top.v \
          $(HDL_SRC)

# Build directories
BUILD_DIR = build
SYNTH_DIR = $(BUILD_DIR)/synthesis
PNR_DIR = $(BUILD_DIR)/pnr
BIN_DIR = $(BUILD_DIR)/bin

# Toolchain executables (adjust paths as needed)
YOSYS = yosys
NEXTPNR = nextpnr-ice40
ICEPACK = icepack
ICEPROG = iceprog
IVERILOG = iverilog
VVP = vvp

# Synthesis options
YOSYS_OPTS = -p "synth_ice40 -top turbo_top -json $(SYNTH_DIR)/turbo_top.json"
NEXTPNR_OPTS = --$(DEVICE) --package SG48 --pcf constraints/turbo.pcf --json $(SYNTH_DIR)/turbo_top.json --asc $(PNR_DIR)/turbo_top.asc --freq 25
ICEPACK_OPTS = 

# Default target
all: $(BIN_DIR)/turbo_top.bin

# Create directories
dirs:
	mkdir -p $(BUILD_DIR) $(SYNTH_DIR) $(PNR_DIR) $(BIN_DIR)

# Synthesis flow
$(SYNTH_DIR)/turbo_top.json: $(HDL_SRC) | dirs
	$(YOSYS) $(YOSYS_OPTS) $(HDL_SRC)

$(PNR_DIR)/turbo_top.asc: $(SYNTH_DIR)/turbo_top.json constraints/turbo.pcf
	$(NEXTPNR) $(NEXTPNR_OPTS)

$(BIN_DIR)/turbo_top.bin: $(PNR_DIR)/turbo_top.asc
	$(ICEPACK) $(ICEPACK_OPTS) $< $@

# Programming
program: $(BIN_DIR)/turbo_top.bin
	$(ICEPROG) $<

# Simulation
sim: $(BUILD_DIR)/tb_turbo_top.vvp
	$(VVP) $<

$(BUILD_DIR)/tb_turbo_top.vvp: $(SIM_SRC)
	$(IVERILOG) -o $@ $(SIM_SRC)

# Clean
clean:
	rm -rf $(BUILD_DIR)

distclean: clean
	rm -rf *.vcd

# Help
help:
	@echo "TurboSwap FPGA Build System"
	@echo "Targets:"
	@echo "  all        - Build bitstream (default)"
	@echo "  program    - Program FPGA"
	@echo "  sim        - Run simulation"
	@echo "  clean      - Clean build artifacts"
	@echo "  distclean  - Clean everything"
	@echo "  help       - Show this help"

.PHONY: all dirs program sim clean distclean help