@ECHO OFF
REM /////////////////////////////////////////////////////////////////////
REM >>>>>>>>>>>>>>>>>>>>>>>>>> COPYRIGHT NOTICE <<<<<<<<<<<<<<<<<<<<<<<<<
REM =====================================================================
REM  Copyright 2002 (c) Lattice Semiconductor Corporation
REM  ALL RIGHTS RESERVED
REM
REM  This confidential and proprietary software may be used only as
REM  authorised by a licensing agreement from Lattice Semiconductor
REM  Corporation.
REM  The entire notice above must be reproduced on all authorized
REM  copies and copies may only be made to the extent permitted
REM  by a licensing agreement from Lattice Semiconductor Corporation.
REM

REM =====================================================================
REM  Description        :
REM =====================================================================
REM  csh script to perfom compilation and simulation of ORSPII top-level
REM  for phase 1 testing.
REM
REM  Usage
REM  -----
REM  simany_ph1 <nn> <MTI | MTIGUI | NC | NCGUI>
REM
REM      nn   - Register & Memory configuration to use nn=01-16
REM  MTIGUI   - Use Modelsim GUI (default if not specified)
REM     MTI   - Use ModelSim in batch mode
REM   NCGUI   - Use NC GUI
REM      NC   - Use NC in batch mode
REM
REM =====================================================================

REM =====================================================================
REM  Revision History
REM =====================================================================
REM  $Log: simany_ph1.rca $
REM  
REM   Revision: 1.13 Wed Dec 18 12:46:05 2002 bkerr
REM   Added UNIT_DELAY and USE_DEL_DELAY compilation options
REM
REM   Revision: 1.12 Mon Oct  7 04:32:09 2002 bkerr
REM   Removed -y reference to maclog directory as these files are
REM   explicitly referenced in ../netlist/rtl.f
REM
REM   Revision: 1.11 Fri Sep 13 05:37:47 2002 bkerr
REM   Altered to compile orspii_asb top-level
REM   Deleted all PPC and MPIF commented out text
REM   Included AHB bmaster in ../test
REM
REM   Revision: 1.10 Fri Sep  6 03:57:33 2002 rproudlo
REM   Added Rx files - referenced ../s4/rtl.f compile file
REM
REM   Revision: 1.9 Wed Sep  4 07:51:11 2002 bkerr
REM   Removed fpga_bfm_rx from compilation as it was breaking the NC simulation
REM
REM   Revision: 1.8 Wed Sep  4 05:56:11 2002 bkerr
REM   Added spi4hsix.orspii file into compilation
REM
REM   Revision: 1.7 Fri Aug 23 08:12:23 2002 bkerr
REM   Commented out orspii_asb and PPC files as these are currently
REM   removed from the simulation
REM   Included all tx_path files
REM
REM   Revision: 1.6 Tue Aug 20 11:59:18 2002 bkerr
REM   Removed 3 stage NC compilation and replaced with call to ncverilog
REM   ncverilog uses the same -f file syntax as ModelSim, so building
REM   toptest.f file is easier
REM   Added orspii_asb and MPIF to compilation
REM   PowerPC interface is included, but commented out as this may not be required
REM
REM   Revision: 1.5 Tue Jul 30 12:49:38 2002 bkerr
REM   Altered usage to take 1 or 2 parameters
REM   Maintains sfnn and mnn association
REM   Added usage instructions
REM
REM   Revision: 1.4 Thu Jul 11 09:44:15 2002 bkerr
REM   Added NC-Verilog compilation and simulation
REM   Now builds a simulator specific toptest.f file
REM   Added GUI/Batch mode
REM
REM   Revision: 1.2 Wed Jul 10 11:49:22 2002 bkerr
REM   Changed path to SFnn and Mnn
REM
REM   Revision: 1.1 Tue Jul  9 12:14:35 2002 bkerr
REM   Initial creation for evaluation
REM   Path to SFnn and Mnn is still TBD
REM =====================================================================

echo Test number=%1  Simulator=%2

REM check for correct usage
REM if NOT EXIST %1 goto :usage
REM if NOT EXIST %2 goto :usage

REM variables
REM filenames of the sf and m files to use
set SF        = sf%1
set M         = m%1
REM uncomment to use local disk
REM set WORKDIR    = .

REM variables to be inserted into %TESTBENCH_PC%\toptest.v as `defines
set BUILDDATE= %DATE%
set SF_DEFINE= sf%1
set M_DEFINE= m%1
set SF_DEFINE_FILE= sf%1.v
set M_DEFINE_FILE= m%1.v
set LOG_FILE= %1.log
set TESTBENCH=../testbench
set TESTBENCH_PC=..\testbench
set MODELS_PC=..\lib\modelsim
set MODELS=../lib/modelsim
set SOURCE_PC=..\source
set SOURCE=../source
set MODEL_TECH=C:\Modeltech_5.7c\win32

echo BUILDDATE= %BUILDDATE%
echo SF_DEFINE= %SF_DEFINE%
echo M_DEFINE= %M_DEFINE%
echo SF_DEFINE_FILE= %SF_DEFINE_FILE%
echo M_DEFINE_FILE= %M_DEFINE_FILE%
echo LOG_FILE= %LOG_FILE%

REM GUI switch
if %2==mti set GUI=-c -do ..\pc_scripts\run.do
if %2==mtigui set GUI=

echo GUI= %GUI%

REM check for valid SF
if NOT EXIST  %TESTBENCH_PC%\parameters\sf%1.v echo sf%1.v not present
if EXIST  %TESTBENCH_PC%\parameters\sf%1.v echo sf%1.v present


REM    echo "Valid SFs are:"
REM if ( ! -f %TESTBENCH_PC%\parameters\$SF.v ) then
REM    echo $SF "not present"
REM    echo "Valid SFs are:"
REM    dir %TESTBENCH_PC%\paramaters\sf*.v > temp_sf
REM    type temp_sf
REM    del temp_sf
REM endif

REM check for valid M
if NOT EXIST  %TESTBENCH_PC%\parameters\m%1.v echo m%1.v not present
if EXIST  %TESTBENCH_PC%\parameters\m%1.v echo m%1.v present



REM delete the %TESTBENCH_PC%\top\toptest.v file
if NOT EXIST .\%TESTBENCH_PC%\top\toptest.v echo %TESTBENCH_PC%\top\toptest.v does not exist, Making %TESTBENCH_PC%\top\toptest.v
if EXIST .\%TESTBENCH_PC%\top\toptest.v echo %TESTBENCH_PC%\top\toptest.v exists, Deleting %TESTBENCH_PC%\top\toptest.v
if EXIST .\%TESTBENCH_PC%\top\toptest.v del %TESTBENCH_PC%\top\toptest.v

REM build the %TESTBENCH_PC%\top\toptest.v file
echo // *** THIS FILE IS AUTOMATICALLY GENERATED *** > %TESTBENCH_PC%\top\toptest.v
echo // *** DO NOT EDIT AS CHANGES WILL BE LOST! *** >> %TESTBENCH_PC%\top\toptest.v
echo `define BUILDDATE "%BUILDDATE%" >> %TESTBENCH_PC%\top\toptest.v
echo `define BUILDWHO "user@latticesemi.com" >> %TESTBENCH_PC%\top\toptest.v
echo `define SF "%SF_DEFINE%" >> %TESTBENCH_PC%\top\toptest.v
echo `define M "%M_DEFINE%" >> %TESTBENCH_PC%\top\toptest.v
type %TESTBENCH_PC%\top\header_rtl.v >> %TESTBENCH_PC%\top\toptest.v
REM type %TESTBENCH_PC%\parameters\%SF_DEFINE_FILE% >> %TESTBENCH_PC%\top\toptest.v
type %TESTBENCH_PC%\parameters\sf03.v >> %TESTBENCH_PC%\top\toptest.v
REM type %TESTBENCH_PC%\parameters\%M_DEFINE_FILE% >> %TESTBENCH_PC%\top\toptest.v
type %TESTBENCH_PC%\parameters\m03.v >> %TESTBENCH_PC%\top\toptest.v
type %TESTBENCH_PC%\top\body.v >> %TESTBENCH_PC%\top\toptest.v
type %TESTBENCH_PC%\top\footer.v >> %TESTBENCH_PC%\top\toptest.v


REM delete the toptest.f file
if NOT EXIST .\toptest.f echo toptest.f does not exist, Making toptest.f
if EXIST .\toptest.f echo toptest.f exists, Deleting toptest.f
if EXIST .\toptest.f del toptest.f


REM ORSPI_QSPI3
echo %TESTBENCH%/top/rfclk_pll.v            >> toptest.f

echo %SOURCE%/sim/rfclk_pll_ph_bo.v         >> toptest.f
echo %SOURCE%/sim/rfclk_hpll_ph_bo.v        >> toptest.f
echo %SOURCE%/sim/sysbus_fpsc.v          >> toptest.f
echo %SOURCE%/sim/mycore_sim.v           >> toptest.f

echo %SOURCE%/top/orspi.v                 >> toptest.f
echo %TESTBENCH%/spi4/latspi4.v                >> toptest.f
echo %TESTBENCH%/spi4/latspi4_tx.v             >> toptest.f
echo %TESTBENCH%/spi4/latspi4_rx.v             >> toptest.f
echo %TESTBENCH%/spi4/latspi4_df.v             >> toptest.f
echo %TESTBENCH%/spi3/loop.v                   >> toptest.f
echo %TESTBENCH%/spi3/spi3mon.v                >> toptest.f


REM AHB bus master
echo %TESTBENCH%/sysbus/bmaster.v              >> toptest.f
echo %TESTBENCH%/top/tbclk.v                   >> toptest.f

REM Top level
REM echo +incdir+%TESTBENCH%/sysbus            >> toptest.f
REM echo +incdir+%TESTBENCH%/parameters        >> toptest.f
echo %TESTBENCH%/top/toptest.v                                 >> toptest.f


REM #-----------------------------------------------------------------------
REM # Search path to all the files to be used
REM #-----------------------------------------------------------------------

   set SYSBUS_WORK=%MODELS_PC%\sysbus_work
   set ORCA4_WORK=%MODELS_PC%\orca4_work
   set ORSPI4_WORK=%MODELS_PC%\orspi4_work
   set IP_WORK=%MODELS_PC%\spi_324p_o4_1_001

REM #-----------------------------------------------------------------------
REM # Refresh all libraries
REM #-----------------------------------------------------------------------

REM  %MODEL_TECH%\vlog -refresh  -work %SYSBUS_WORK%
REM   %MODEL_TECH%\vlog -refresh  -work %ORCA4_WORK%
REM   %MODEL_TECH%\vlog -refresh  -work %ORSPI4_WORK%
REM   %MODEL_TECH%\vlog -refresh  -work %IP_WORK%


set INC_DIR=+incdir+%TESTBENCH_PC%\spi4 +incdir+%SOURCE_PC%\top  +incdir+%TESTBENCH_PC%\sysbus +incdir+%TESTBENCH_PC%\parameters 

REM ModelSim compilation and simulation (default)



   REM create ModelSim work library
   if NOT EXIST work      %MODEL_TECH%\vlib work

   REM delete the compilation log file
   if EXIST %LOG_FILE%      del %LOG_FILE%


   REM compile the top level design
   %MODEL_TECH%\vlog -work work -incr %INC_DIR% +define+UNIT_DELAY +define+USE_DEL_DELAY -f toptest.f 

   REM check to see if compilation was successful
   REM if ( `egrep -c 'ERROR|Error|error' vlog.log` > 0 ) then
   REM    echo "Verilog compilation failed"
   REM    exit(1)
   REM else
   REM    echo "Verilog compilation successful - starting simulator"
   REM endif

   REM start the simulator
   REM add option to run in gui\batch mode (use vsim -c switch)
   REM vsim -t 10ps \





   %MODEL_TECH%\vsim -t ps -L %SYSBUS_WORK% -L %ORCA4_WORK% -L %ORSPI4_WORK% -L %IP_WORK% -wlf vsim.wlf -do scripts\run.do -l %LOG_FILE% work.toptest

:end
