Makefile 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. # Configuration
  2. PROCESSOR ?= RISC8 # Also supported OISC8
  3. PROCESSOR_LOW = $(strip $(shell echo $(PROCESSOR) | tr A-Z a-z))
  4. QUARTUS_DIR = /opt/altera/18.1/quartus
  5. MODELSIM_DIR = /opt/altera/18.1/modelsim_ase
  6. PROJECT_NAME = UCL_project_y3
  7. MODELSIM_GUI = ${QUARTUS_DIR}/bin/quartus_sh -t "${QUARTUS_DIR}/common/tcl/internal/nativelink/qnativesim.tcl" --rtl_sim "${PROJECT_NAME}" "${PROJECT_NAME}"
  8. MODELSIM_BIN = ${MODELSIM_DIR}/bin/vsim
  9. QUARTUS_MACROS = --set VERILOG_MACRO="SYNTHESIS=1"
  10. # OUTPUT FILES
  11. OUTPUTP = output_files/$(PROJECT_NAME)
  12. OUT_ASM = $(OUTPUTP).sof
  13. # Program & Monitor
  14. JTAG ?= 1
  15. TTY ?= /dev/ttyUSB0
  16. BAUD ?= 9600
  17. GENTABLE_BIN = python3 tools/gen_sv.py
  18. ASMC = python3 tools/$(PROCESSOR_LOW)asm.py
  19. MEMSIZE ?= 4096
  20. RAMSIZE ?= -1
  21. MEMDEP := $(shell find memory -name '*${PROCESSOR_LOW}.asm')
  22. MEMSLICES = 0 1 2 3
  23. ifeq "${PROCESSOR_LOW}" "risc8"
  24. MEMRES = $(foreach i,$(MEMSLICES),$(MEMDEP:.asm=.text_$(i).mem)) \
  25. $(foreach i,$(MEMSLICES),$(MEMDEP:.asm=.text_$(i).mif)) \
  26. $(foreach i,$(MEMSLICES),$(MEMDEP:.asm=.text_$(i).uhex)) \
  27. $(MEMDEP:.asm=.data.mem) \
  28. $(MEMDEP:.asm=.data.uhex) \
  29. $(MEMDEP:.asm=.data.mif)
  30. else ifeq "${PROCESSOR_LOW}" "oisc8"
  31. MEMRES = $(MEMDEP:.asm=.text.mem) \
  32. $(MEMDEP:.asm=.text.uhex) \
  33. $(MEMDEP:.asm=.text.mif) \
  34. $(MEMDEP:.asm=.data.mem) \
  35. $(MEMDEP:.asm=.data.uhex) \
  36. $(MEMDEP:.asm=.data.mif)
  37. else
  38. $(error "Processor not supported: ${PROCESSOR_LOW}")
  39. endif
  40. VERILOG ?= $(wildcard src/*/*.sv)
  41. # Genreate sv case table from csv
  42. CSVS = src/risc/controller.csv
  43. define execute-gentable
  44. $(GENTABLE_BIN) $(1) $(1:.csv=.sv)
  45. endef
  46. analysis: compile
  47. ${QUARTUS_DIR}/bin/quartus_map --read_settings_files=on --write_settings_files=off ${QUARTUS_MACROS} ${PROJECT_NAME} -c ${PROJECT_NAME} --analysis_and_elaboration
  48. $(OUT_ASM): $(MEMDEP)
  49. ${QUARTUS_DIR}/bin/quartus_map --read_settings_files=on --write_settings_files=off ${QUARTUS_MACROS} ${PROJECT_NAME} -c ${PROJECT_NAME}
  50. ${QUARTUS_DIR}/bin/quartus_fit --read_settings_files=off --write_settings_files=off ${QUARTUS_MACROS} ${PROJECT_NAME} -c ${PROJECT_NAME}
  51. ${QUARTUS_DIR}/bin/quartus_asm --read_settings_files=off --write_settings_files=off ${QUARTUS_MACROS} ${PROJECT_NAME} -c ${PROJECT_NAME}
  52. $(OUT_STA): $(OUT_ASM)
  53. ${QUARTUS_DIR}/bin/quartus_sta ${PROJECT_NAME} -c ${PROJECT_NAME}
  54. eda: $(OUT_STA)
  55. ${QUARTUS_DIR}/bin/quartus_eda --read_settings_files=off --write_settings_files=off ${QUARTUS_MACROS} ${PROJECT_NAME} -c ${PROJECT_NAME}
  56. program: $(OUT_ASM)
  57. ${QUARTUS_DIR}/bin/quartus_pgm -z -c $(JTAG) -m jtag -o "p;$(OUT_ASM)@1"
  58. listdev:
  59. ${QUARTUS_DIR}/bin/quartus_pgm -l
  60. monitor:
  61. hash cu && echo "Escape with ~." && cu -l $(TTY) -s $(BAUD)
  62. #hash minicom && minicom -D $(TTY) -b $(BAUD)
  63. modelsim_cli:
  64. ${MODELSIM_BIN} -c
  65. modelsim_gui:
  66. ${MODELSIM_GUI}
  67. compile_all:
  68. ${MODELSIM_BIN} -c -do simulation/modelsim/${PROJECT_NAME}_run_msim_rtl_verilog.do -do exit
  69. %.sv: %.csv $(CSVS)
  70. $(GENTABLE_BIN) $< $(@:.csv=.sv)
  71. gentable:
  72. $(foreach x,$(CSVS),$(call execute-gentable,./$(x)))
  73. simulate: $(VERILOG)
  74. @echo ${MODELSIM_BIN} -c -do "vlog -sv -work work +incdir+$(abspath $(dir $<)) $(abspath $<)" -do exit
  75. .PHONY: compile
  76. testbench: compile
  77. ${MODELSIM_BIN} -c -do "vsim work.$(basename $(notdir $(VERILOG)))_tb" -do "run -all" -do exit
  78. compile: $(MEMRES)
  79. %.text_0.mem %.text_1.mem %.text_2.mem %.text_3.mem: %.asm
  80. $(ASMC) -t mem -f $< -S $(words $(MEMSLICES)) .text
  81. %.text_0.mif %.text_1.mif %.text_2.mif %.text_3.mif: %.asm
  82. $(ASMC) -t mif -f $< -S $(words $(MEMSLICES)) .text
  83. %.text_0.uhex %.text_1.uhex %.text_2.uhex %.text_3.uhex: %.asm
  84. $(ASMC) -t uhex -f $< -S $(words $(MEMSLICES)) .text
  85. %.data.mem: %.asm
  86. $(ASMC) -t mem -f $< .data
  87. %.data.mif: %.asm
  88. $(ASMC) -t mif -f $< .data
  89. %.data.uhex: %.asm
  90. $(ASMC) -t uhex -f $< .data
  91. %.text.mem: %.asm
  92. $(ASMC) -t mem -f $< .text
  93. %.text.mif: %.asm
  94. $(ASMC) -t mif -f $< .text
  95. %.text.uhex: %.asm
  96. $(ASMC) -t uhex -f $< .text
  97. flash: $(MEMRES)
  98. $(QUARTUS_DIR)/bin/quartus_stp -t ./scripts/update_$(PROCESSOR_LOW).tcl
  99. clean:
  100. rm -f $(MEMRES)
  101. rm -f $(OUT_ASM)
  102. #.PHONY: clean