#!/bin/bash
################################################################################
##   ____  ____
##  /   /\/   /
## /___/  \  /    Vendor: Xilinx
## \   \   \/     Version : 1.05
##  \   \         Application : ILA v1.05_a Core
##  /   /         Filename : ise_implement.sh
## /___/   /\     
## \   \  /  \
##  \___\/\___\
##
##
## ise_implement.sh script 
## Generated by Xilinx ILA v1.05_a Core
##
#-----------------------------------------------------------------------------
# Script to synthesize and implement the RTL provided for the ILA core
#-----------------------------------------------------------------------------
#Exit on Error enabled.
set -o errexit

#Create results directory
rm -rf results
mkdir results

echo 'Running Coregen on ICON required for example design'
coregen -b chipscope_icon.xco -p coregen.cgp
# Check Results
if [ $? -gt 0 ] ; then 
echo An error occurred running Coregen on ICON
echo FAIL
exit
fi

cp ../../chipscope_ila.ngc .

##-------------------------------Run Xst on Example design----------------------------
echo 'Running Xst on example design'
xst -ifn example_chipscope_ila.xst -ofn example_core.log -intstyle silent
# Check Results
if [ $? -gt 0 ] ; then 
echo An error occurred running XST on example_chipscope_ila
echo FAIL
exit
fi

cp chipscope_icon.ngc ./results

cp ../../chipscope_ila.ngc        ./results
cp example_chipscope_ila.ngc        ./results
cp chipscope_icon.ncf ./results
cp ../../chipscope_ila.ncf        ./results
cd ./results
##-------------------------------Run ngdbuild---------------------------------------
echo 'Running ngdbuild'
ngdbuild -uc ../../example_design/example_chipscope_ila.ucf -p xc6slx45t-fgg484-3 -sd . example_chipscope_ila.ngc example_chipscope_ila.ngd
if [ $? -gt 0 ] ; then 
echo An error occurred running NGDBUILD on example_chipscope_ila 
echo FAIL
exit
fi
#end run ngdbuild section
##-------------------------------Run map-------------------------------------------
echo 'Running map'
map -w -p xc6slx45t-fgg484-3 -o example_chipscope_ila.map.ncd example_chipscope_ila.ngd
if [ $? -gt 0 ] ; then 
echo An error occurred running MAP on example_chipscope_ila 
echo FAIL
exit
fi
##-------------------------------Run par-------------------------------------------
echo 'Running par'
par -w -ol high example_chipscope_ila.map.ncd example_chipscope_ila.ncd 
if [ $? -gt 0 ] ; then 
echo An error occurred running PAR on example_chipscope_ila 
echo FAIL
exit
fi
##---------------------------Report par results-------------------------------------
echo 'Running design through bitgen'
bitgen -d -g GWE_cycle:Done -g GTS_cycle:Done -g DriveDone:Yes -g StartupClk:Cclk -w example_chipscope_ila.ncd
if [ $? -gt 0 ] ; then 
echo An error occurred running BITGEN on example_chipscope_ila 
echo FAIL
exit
else
echo PASS
exit
fi
