summaryrefslogtreecommitdiffstats
path: root/Makefile
blob: d442655ee883b200054309fb5b99a5006acb0f60 (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
IMAGE  = fpga-tools
PODMAN = podman run --rm --cpus=$(shell nproc) -v $(CURDIR):/workspace $(IMAGE)

BUILD  = build

# Which C program to build.  Override: make PROG=test_uart
PROG ?= blink
override PROG := $(basename $(PROG))

$(BUILD):
	mkdir -p $@

# -- Host-side C compilation (sdcc on host) --------------------------------------------

$(BUILD)/%.hex: fw/%.c | $(BUILD)
	cd $(BUILD) && sdcc --use-non-free -mpic14 -p16f84a \
		-Wl-s -Wl$(CURDIR)/fw/fpga_pic.lkr \
		$(CURDIR)/fw/$*.c

# program.hex is what the testbench loads at runtime
$(BUILD)/program.hex: $(BUILD)/$(PROG).hex
	cp $< $@

# prog_rom.vhd embeds the program for synthesis
hdl/prog_rom.vhd: $(BUILD)/program.hex
	python3 hex2rom.py $< > $@

# Regenerate ROM from an arbitrary hex file: make rom HEX=foo.hex
rom:
	python3 hex2rom.py $(HEX) > hdl/prog_rom.vhd

# -- Container targets ----------------------------------------------------------------------------

all: hdl/prog_rom.vhd
	$(PODMAN) make -f Makefile.inner

sim: $(BUILD)/program.hex
	$(PODMAN) make -f Makefile.inner sim

flash: $(BUILD)/pic_top.fs
	openFPGALoader -b tangprimer25k $<

show-top:
	$(PODMAN) make -f Makefile.inner $(BUILD)/pic_top.dot
	xdot $(BUILD)/pic_top.dot

show-uart:
	$(PODMAN) make -f Makefile.inner $(BUILD)/uart.dot
	xdot $(BUILD)/uart.dot

# -- Clean ----------------------------------------------------------------------------

clean:
	$(PODMAN) make -f Makefile.inner clean
	rm -rf $(BUILD)
	rm -f hdl/prog_rom.vhd

.PHONY: all sim clean flash show-top show-uart rom