
# Put here the name of the Device Under Test
DUT=TSPCFF

### Modules names are forged from the Device Under Test name
# The board module
BD=board
# The testbench module
TB=testbench
# The name of the control file
CTR=amsIrunControl

# Where is the gpdk045 design kit ?
KITDIR=/comelec/softs/opt/opus_kits/CADENCE_PDKS
# Where are COMELEC goodies
GOODIES=${KITDIR}/COMELEC

# Define here simulation parameters
supply_voltage ?= 1.1

##### File names are forged from module names
# The original Spectre file
SCS_FILE=../${DUT}.scs

# The translated Verilog-ams file
DUT_FILE=../${DUT}.vams
# The the board file
BD_FILE=board.vams
# The testbench file
TB_FILE=testbench.sv
# The control file
CTR_FILE=${CTR}.scs

all:
	@echo "simu : batch simulation"
	@echo "show_waves : examine simulation waveforms"
	@echo "show_results : examine simulation results"
	@echo "clean: cleaning of the simulation work directory"

simu:IRUN_OPT= -access +r -disable_sem2009 -input probes.tcl
simu:real_simu

simu_gui:IRUN_OPT= -access +r -disable_sem2009  -gui -input probes.tcl
simu_gui:real_simu

real_simu: ${DUT_FILE} ${CTR_FILE} | results
	-/comelec/softs/bin/irun ${IRUN_OPT} \
	-defparam ${TB}.supply_voltage=${supply_voltage} \
	-reflib /comelec/softs/opt/opus_kits/CADENCE_PDKS/COMELEC/lib_scs/gsclib045_basicCells \
	${CTR_FILE} \
    -top ${TB} \
    ${TB_FILE} \
    ${BD_FILE} \
	${DUT_FILE} 

results:
	    mkdir -p results


show_waves:
	viva -datadir  psf &

show_results:
	cat results/test_dut_1.1V.dat

clean:
	@rm -rf INCA_libs
	@rm -rf irun.history
	@rm -rf irun.log
	@rm -rf ${CTR}.raw
	@rm -rf ${CTR}.shm
	@rm -rf INCA_LIBS
	@rm -rf psf
	@rm -rf .simvision
	@rm -f irun.key
	@rm -f CDS*
	@rm -rf .cadence



ultraclean: clean
	@rm -rf results

### Specific part for Verilog-ams DUT file generation
# Convert a spice netlist to a verilog-ams netlist
${DUT_FILE}: ${SCS_FILE}
	sed -e 's/(//g' -e 's/)//g' $< | awk 'BEGIN {line=""} /\\$$/ {line=(line substr($$0,0,length($$0)-1)) ; next} {if(line !="") { printf("%s\n",line $$0); line =""} else  printf("%s\n",$$0)} END {printf("%s\n",line)}' > tmp.scs
	awk -f ${GOODIES}/scs2va_irun.awk tmp.scs > $@
	@rm -f tmp.scs
	
cleandut:
	@rm -rf ${DUT_FILE}
