#!/bin/bash
|
#!/bin/bash
|
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
# Copyright (C) 2001 Authors
|
# Copyright (C) 2001 Authors
|
#
|
#
|
# This source file may be used and distributed without restriction provided
|
# This source file may be used and distributed without restriction provided
|
# that this copyright statement is not removed from the file and that any
|
# that this copyright statement is not removed from the file and that any
|
# derivative work contains the original copyright notice and the associated
|
# derivative work contains the original copyright notice and the associated
|
# disclaimer.
|
# disclaimer.
|
#
|
#
|
# This source file is free software; you can redistribute it and/or modify
|
# This source file is free software; you can redistribute it and/or modify
|
# it under the terms of the GNU Lesser General Public License as published
|
# it under the terms of the GNU Lesser General Public License as published
|
# by the Free Software Foundation; either version 2.1 of the License, or
|
# by the Free Software Foundation; either version 2.1 of the License, or
|
# (at your option) any later version.
|
# (at your option) any later version.
|
#
|
#
|
# This source is distributed in the hope that it will be useful, but WITHOUT
|
# This source is distributed in the hope that it will be useful, but WITHOUT
|
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
# License for more details.
|
# License for more details.
|
#
|
#
|
# You should have received a copy of the GNU Lesser General Public License
|
# You should have received a copy of the GNU Lesser General Public License
|
# along with this source; if not, write to the Free Software Foundation,
|
# along with this source; if not, write to the Free Software Foundation,
|
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
#
|
#
|
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
#
|
#
|
# File Name: msp430sim
|
# File Name: msp430sim
|
#
|
#
|
# Author(s):
|
# Author(s):
|
# - Olivier Girard, olgirard@gmail.com
|
# - Olivier Girard, olgirard@gmail.com
|
#
|
#
|
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
# $Rev: 151 $
|
# $Rev: 192 $
|
# $LastChangedBy: olivier.girard $
|
# $LastChangedBy: olivier.girard $
|
# $LastChangedDate: 2012-07-23 00:24:11 +0200 (Mon, 23 Jul 2012) $
|
# $LastChangedDate: 2013-12-17 21:15:28 +0100 (Tue, 17 Dec 2013) $
|
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
|
|
###############################################################################
|
###############################################################################
|
# Parameter Check #
|
# Parameter Check #
|
###############################################################################
|
###############################################################################
|
EXPECTED_ARGS=1
|
EXPECTED_ARGS=1
|
if [ $# -ne $EXPECTED_ARGS ]; then
|
if [ $# -ne $EXPECTED_ARGS ]; then
|
echo "ERROR : wrong number of arguments"
|
echo "ERROR : wrong number of arguments"
|
echo "USAGE : msp430sim "
|
echo "USAGE : msp430sim "
|
echo "Example : msp430sim c-jump_jge"
|
echo "Example : msp430sim c-jump_jge"
|
echo ""
|
echo ""
|
echo "In order to switch the verilog simulator, the OMSP_SIMULATOR environment"
|
echo "In order to switch the verilog simulator, the OMSP_SIMULATOR environment"
|
echo "variable can be set to the following values:"
|
echo "variable can be set to the following values:"
|
echo ""
|
echo ""
|
echo " - iverilog : Icarus Verilog (default)"
|
echo " - iverilog : Icarus Verilog (default)"
|
echo " - cver : CVer"
|
echo " - cver : CVer"
|
echo " - verilog : Verilog-XL"
|
echo " - verilog : Verilog-XL"
|
echo " - ncverilog : NC-Verilog"
|
echo " - ncverilog : NC-Verilog"
|
echo " - vcs : VCS"
|
echo " - vcs : VCS"
|
echo " - vsim : Modelsim"
|
echo " - vsim : Modelsim"
|
echo " - isim : Xilinx simulator"
|
echo " - isim : Xilinx simulator"
|
echo ""
|
echo ""
|
exit 1
|
exit 1
|
fi
|
fi
|
|
|
|
|
###############################################################################
|
###############################################################################
|
# Check if the required files exist #
|
# Check if the required files exist #
|
###############################################################################
|
###############################################################################
|
asmfile=../src/$1.s43;
|
asmfile=../src/$1.s43;
|
verfile=../src/$1.v;
|
verfile=../src/$1.v;
|
incfile=../../../rtl/verilog/openMSP430_defines.v;
|
incfile=../../../rtl/verilog/openMSP430_defines.v;
|
linkfile=../bin/template.x;
|
linkfile=../bin/template.x;
|
headfile=../bin/template_defs.asm;
|
headfile=../bin/template_defs.asm;
|
submitfile=../src/submit.f;
|
submitfile=../src/submit.f;
|
if [ $OMSP_SIMULATOR == "isim" ]; then
|
if [ $OMSP_SIMULATOR == "isim" ]; then
|
submitfile=../src/submit.prj;
|
submitfile=../src/submit.prj;
|
fi
|
fi
|
|
|
if [ ! -e $asmfile ]; then
|
if [ ! -e $asmfile ]; then
|
echo "Assembler file $asmfile doesn't exist: $asmfile"
|
echo "Assembler file $asmfile doesn't exist: $asmfile"
|
exit 1
|
exit 1
|
fi
|
fi
|
if [ ! -e $verfile ]; then
|
if [ ! -e $verfile ]; then
|
echo "Verilog stimulus file $verfile doesn't exist: $verfile"
|
echo "Verilog stimulus file $verfile doesn't exist: $verfile"
|
exit 1
|
exit 1
|
fi
|
fi
|
if [ ! -e $submitfile ]; then
|
if [ ! -e $submitfile ]; then
|
echo "Verilog submit file $submitfile doesn't exist: $submitfile"
|
echo "Verilog submit file $submitfile doesn't exist: $submitfile"
|
exit 1
|
exit 1
|
fi
|
fi
|
if [ ! -e $linkfile ]; then
|
if [ ! -e $linkfile ]; then
|
echo "Linker definition file template doesn't exist: $linkfile"
|
echo "Linker definition file template doesn't exist: $linkfile"
|
exit 1
|
exit 1
|
fi
|
fi
|
if [ ! -e $headfile ]; then
|
if [ ! -e $headfile ]; then
|
echo "Assembler definition file template doesn't exist: $headfile"
|
echo "Assembler definition file template doesn't exist: $headfile"
|
exit 1
|
exit 1
|
fi
|
fi
|
|
|
|
|
###############################################################################
|
###############################################################################
|
# Cleanup #
|
# Cleanup #
|
###############################################################################
|
###############################################################################
|
echo "Cleanup..."
|
echo "Cleanup..."
|
rm -rf *.vcd
|
rm -rf *.vcd
|
rm -rf *.vpd
|
rm -rf *.vpd
|
rm -rf *.trn
|
rm -rf *.trn
|
rm -rf *.dsn
|
rm -rf *.dsn
|
rm -rf pmem*
|
rm -rf pmem*
|
rm -rf stimulus.v
|
rm -rf stimulus.v
|
|
|
|
|
###############################################################################
|
###############################################################################
|
# Run simulation #
|
# Run simulation #
|
###############################################################################
|
###############################################################################
|
echo " ======================================================="
|
echo " ======================================================="
|
echo "| Start simulation: $1"
|
echo "| Start simulation: $1"
|
echo " ======================================================="
|
echo " ======================================================="
|
|
|
# Create links
|
# Create links
|
if [ `uname -o` = "Cygwin" ]
|
if [ `uname -o` = "Cygwin" ]
|
then
|
then
|
cp $asmfile pmem.s43
|
cp $asmfile pmem.s43
|
cp $verfile stimulus.v
|
cp $verfile stimulus.v
|
else
|
else
|
ln -s $asmfile pmem.s43
|
ln -s $asmfile pmem.s43
|
ln -s $verfile stimulus.v
|
ln -s $verfile stimulus.v
|
fi
|
fi
|
|
|
# Make local copy of the openMSP403 configuration file
|
# Make local copy of the openMSP403 configuration file
|
# and prepare it for MSPGCC preprocessing
|
# and prepare it for MSPGCC preprocessing
|
cp $incfile ./pmem.h
|
cp $incfile ./pmem.h
|
sed -i 's/`ifdef/#ifdef/g' ./pmem.h
|
sed -i 's/`ifdef/#ifdef/g' ./pmem.h
|
sed -i 's/`else/#else/g' ./pmem.h
|
sed -i 's/`else/#else/g' ./pmem.h
|
sed -i 's/`endif/#endif/g' ./pmem.h
|
sed -i 's/`endif/#endif/g' ./pmem.h
|
sed -i 's/`define/#define/g' ./pmem.h
|
sed -i 's/`define/#define/g' ./pmem.h
|
|
sed -i 's/`include/\/\/#include/g' ./pmem.h
|
sed -i 's/`//g' ./pmem.h
|
sed -i 's/`//g' ./pmem.h
|
sed -i "s/'//g" ./pmem.h
|
sed -i "s/'//g" ./pmem.h
|
|
|
# Use MSPGCC preprocessor to extract the Program, Data
|
# Use MSPGCC preprocessor to extract the Program, Data
|
# and Peripheral memory sizes
|
# and Peripheral memory sizes
|
msp430-gcc -E -P -x c ../bin/omsp_config.sh > pmem.sh
|
msp430-gcc -E -P -x c ../bin/omsp_config.sh > pmem.sh
|
|
|
# Source the extracted configuration file
|
# Source the extracted configuration file
|
source pmem.sh
|
source pmem.sh
|
|
|
# Compile assembler code
|
# Compile assembler code
|
echo "Compile, link & generate IHEX file (Program Memory: $pmemsize B, Data Memory: $dmemsize B, Peripheral Space: $persize B)..."
|
echo "Compile, link & generate IHEX file (Program Memory: $pmemsize B, Data Memory: $dmemsize B, Peripheral Space: $persize B)..."
|
../bin/asm2ihex.sh pmem pmem.s43 $linkfile $headfile $pmemsize $dmemsize $persize
|
../bin/asm2ihex.sh pmem pmem.s43 $linkfile $headfile $pmemsize $dmemsize $persize
|
|
|
# Generate Program memory file
|
# Generate Program memory file
|
echo "Convert IHEX file to Verilog MEMH format..."
|
echo "Convert IHEX file to Verilog MEMH format..."
|
../bin/ihex2mem.tcl -ihex pmem.ihex -out pmem.mem -mem_size $pmemsize
|
../bin/ihex2mem.tcl -ihex pmem.ihex -out pmem.mem -mem_size $pmemsize
|
|
|
# Start verilog simulation
|
# Start verilog simulation
|
echo "Start Verilog simulation..."
|
echo "Start Verilog simulation..."
|
../bin/rtlsim.sh stimulus.v pmem.mem $submitfile
|
../bin/rtlsim.sh stimulus.v pmem.mem $submitfile
|
|
|