#!/usr/bin/env bash

export FPGA_PROJ=1

#Directory structure

#Root direcotry
export PROJ=/projekty/mbist/dads.lite

#Sub directories
export HDL=$PROJ/hdl
export RTL=$HDL/rtl
export IP=$HD/ip
export TB=$HDL/model
export TC=$HDL/testcase
export INCLUDE=$HDL/support
export UTILS=$PROJ/utils
export SCRIPTS=$PROJ/scripts.altera
export SCRATCH=$PROJ/scratch
export LOGS=$PROJ/logs
export CONFIG=$PROJ/config

#Altera tools
export ALTERAHOME=/opt/altera/16.0 #14.1
export QUARTUS_SH=$ALTERAHOME/quartus/bin/quartus_sh
export QUARTUS_CPF=$ALTERAHOME/quartus/bin/quartus_cpf
export URJTAG=jtag
#export COREGEN=coregen
#export XAW2VHDL=xaw2vhdl
#export XST=xst
#export NGDBUILD=ngdbuild
#export MAP=map
#export PAR=par
#export TRCE=trce

#Modelsim
export MODELSIMHOME=$ALTERAHOME/modelsim_ase
export VLIB=$MODELSIMHOME/linux/vlib
export VMAP=$MODELSIMHOME/linux/vmap
export VCOM=$MODELSIMHOME/linux/vcom
export VLOG=$MODELSIMHOME/linux/vlog
export VMAKE=$MODELSIMHOME/linux/vmake
export VSIM=$MODELSIMHOME/linux/vsim

#Parameters
export TOP=MBIST_TOP
#export CHIP=ep4ce6e22c8
#export JTAG_VOLTAGE=3.3
#export JTAG_SPEED=12Mhz

#Functions

#Check result of command
# Use: check $? "name of step"
check () {
  if [ $1 -ne 0 ]
  then
    echo "Error while $2"
    exit 1
  fi
}

scratch_init () {
  cd $PROJ
  rm -rf $SCRATCH
  mkdir $SCRATCH
  check $? "create scratch dir"

  echo "Scratch directory $SCRATCH"
}
