#!/bin/sh

# Put which branch of Git to use here...
IPBUS_BRANCH="-b v1.6"
TLU_BRANCH="-b 1e000024"

echo "Creating working directory"
[ -d work ] && echo "Directory Exists" || mkdir work
cd work



IPBB_VERSION="0.5.2"
echo "Installing IPBB version ${IPBB_VERSION}"
[ -d ipbb-${IPBB_VERSION} ] && echo "ipbb-${IPBB_VERSION} already installed" || curl -L https://github.com/ipbus/ipbb/archive/v${IPBB_VERSION}.tar.gz | tar xvz
# ( or git clone git@github.com:ipbus/ipbb.git )
source ipbb-${IPBB_VERSION}/env.sh

ipbb init build

cd build
ipbb add git https://github.com/ipbus/ipbus-firmware.git ${IPBUS_BRANCH}
ipbb add git https://ohwr.org/project/fmc-mtlu-gw.git ${TLU_BRANCH}
# For read/write load a valid ssh key and use the repo below ....
# ipbb add git ssh://git@ohwr.org/fmc-projects/fmc-mtlu/fmc-mtlu-gw.git 




echo "Creating project"
ipbb proj create sim TLU_1e_sim fmc-mtlu-gw:AIDA_tlu/projects/sim -t top_sim.dep

cd proj/TLU_1e_sim

# source /software/CAD/setup_mentor2019.sh

echo "Generating address table VHDL from XML file"
ipbb sim gendecoders


ipbb sim setup-simlib ipcores fli

# First time or only if machine is rebooted
# Requires sudo rights
## ipbb sim virtualtap --ip 192.168.231.1

# Every time the sources
ipbb sim make-project

# Run the simulation
./vsim -c work.top -do ‘run -all’

# In a different window
## ping 192.168.231.128

deactivate
