#----------------------------------------
#-- Establecer nombre del componente
#----------------------------------------
DEPSIM = cpu.v system.v uart.v
DEPSINT= cpu.v system.v uart.v pll.v

SOURCE= sieve
#-------------------------------------------------------
#-- Objetivo por defecto: hacer simulacion y sintesis
#-------------------------------------------------------
all: sim
	
#----------------------------------------------
#-- make sim
#----------------------------------------------
#-- Objetivo para hacer la simulacion del
#-- banco de pruebas
#----------------------------------------------
sim: tb.vcd
	#-- Ver visualmente la simulacion con gtkwave
	gtkwave tb.vcd tb.gtkw &
	
#-----------------------------------------------
#-  make sint
#-----------------------------------------------
#-  Objetivo para realizar la sintetis completa
#- y dejar el diseno listo para su grabacion en
#- la FPGA
#-----------------------------------------------
sint: main.bin
	../iceRAM/iceram $<

out.hex:	$(SOURCE).asm
	util/asmbn16s1 $<

#-------------------------------
#-- Compilacion y simulacion
#-------------------------------
tb.vcd: tb.v $(DEPSIM) out.hex
	
	#-- Compilar
	iverilog tb.v $(DEPSIM) -o tb.out
	
	#-- Simular
	./tb.out
	

#------------------------------
#-- Sintesis completa
#------------------------------
main.bin: pines.pcf main.v $(DEPSINT) out.hex Makefile
	
	#-- Sintesis
	yosys -p "synth_ice40 -blif main.blif" main.v $(DEPSINT) 
	
	#-- Place & route
	arachne-pnr -d 1k -p pines.pcf main.blif -o main.txt
	
	#-- Generar binario final, listo para descargar en fgpa
	icepack main.txt main.bin


#-- Limpiar todo
clean:
	rm -f *.bin *.txt *.blif *.out *.vcd *~

.PHONY: all clean

