| 1 |
76 |
olivier.gi |
#!/bin/bash
|
| 2 |
|
|
#------------------------------------------------------------------------------
|
| 3 |
|
|
# Copyright (C) 2001 Authors
|
| 4 |
|
|
#
|
| 5 |
|
|
# This source file may be used and distributed without restriction provided
|
| 6 |
|
|
# that this copyright statement is not removed from the file and that any
|
| 7 |
|
|
# derivative work contains the original copyright notice and the associated
|
| 8 |
|
|
# disclaimer.
|
| 9 |
|
|
#
|
| 10 |
|
|
# This source file is free software; you can redistribute it and/or modify
|
| 11 |
|
|
# it under the terms of the GNU Lesser General Public License as published
|
| 12 |
|
|
# by the Free Software Foundation; either version 2.1 of the License, or
|
| 13 |
|
|
# (at your option) any later version.
|
| 14 |
|
|
#
|
| 15 |
|
|
# This source is distributed in the hope that it will be useful, but WITHOUT
|
| 16 |
|
|
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
| 17 |
|
|
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
| 18 |
|
|
# License for more details.
|
| 19 |
|
|
#
|
| 20 |
|
|
# You should have received a copy of the GNU Lesser General Public License
|
| 21 |
|
|
# along with this source; if not, write to the Free Software Foundation,
|
| 22 |
|
|
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
| 23 |
|
|
#
|
| 24 |
|
|
#------------------------------------------------------------------------------
|
| 25 |
|
|
#
|
| 26 |
|
|
# File Name: msp430sim_c
|
| 27 |
|
|
#
|
| 28 |
|
|
# Author(s):
|
| 29 |
|
|
# - Olivier Girard, olgirard@gmail.com
|
| 30 |
|
|
#
|
| 31 |
|
|
#------------------------------------------------------------------------------
|
| 32 |
|
|
# $Rev: 73 $
|
| 33 |
|
|
# $LastChangedBy: olivier.girard $
|
| 34 |
|
|
# $LastChangedDate: 2010-08-03 21:26:39 +0200 (Tue, 03 Aug 2010) $
|
| 35 |
|
|
#------------------------------------------------------------------------------
|
| 36 |
|
|
|
| 37 |
|
|
###############################################################################
|
| 38 |
|
|
# Parameter Check #
|
| 39 |
|
|
###############################################################################
|
| 40 |
|
|
EXPECTED_ARGS=1
|
| 41 |
|
|
if [ $# -ne $EXPECTED_ARGS ]; then
|
| 42 |
|
|
echo "ERROR : wrong number of arguments"
|
| 43 |
|
|
echo "USAGE : msp430sim_c "
|
| 44 |
|
|
echo "Example : msp430sim_c sandbox"
|
| 45 |
98 |
olivier.gi |
echo ""
|
| 46 |
|
|
echo "In order to switch the verilog simulator, the MYVLOG environment"
|
| 47 |
|
|
echo "variable can be set to the following values:"
|
| 48 |
|
|
echo ""
|
| 49 |
|
|
echo " - iverilog : Icarus Verilog (default)"
|
| 50 |
|
|
echo " - cver : CVer"
|
| 51 |
|
|
echo " - verilog : Verilog-XL"
|
| 52 |
|
|
echo " - ncverilog : NC-Verilog"
|
| 53 |
|
|
echo " - vcs : VCS"
|
| 54 |
|
|
echo " - vsim : Modelsim"
|
| 55 |
|
|
echo ""
|
| 56 |
76 |
olivier.gi |
exit 1
|
| 57 |
|
|
fi
|
| 58 |
|
|
|
| 59 |
|
|
|
| 60 |
|
|
###############################################################################
|
| 61 |
|
|
# Check if the required files exist #
|
| 62 |
|
|
###############################################################################
|
| 63 |
|
|
softdir=../src-c/$1;
|
| 64 |
|
|
elffile=../src-c/$1/$1.elf;
|
| 65 |
|
|
verfile=../src-c/$1/$1.v;
|
| 66 |
|
|
submitfile=../src/submit.f;
|
| 67 |
|
|
incfile=../../../rtl/verilog/openMSP430_defines.v;
|
| 68 |
|
|
|
| 69 |
|
|
if [ ! -e $softdir ]; then
|
| 70 |
|
|
echo "Software directory doesn't exist: $softdir"
|
| 71 |
|
|
exit 1
|
| 72 |
|
|
fi
|
| 73 |
|
|
if [ ! -e $verfile ]; then
|
| 74 |
|
|
echo "Verilog stimulus file $verfile doesn't exist: $verfile"
|
| 75 |
|
|
exit 1
|
| 76 |
|
|
fi
|
| 77 |
|
|
if [ ! -e $submitfile ]; then
|
| 78 |
|
|
echo "Verilog submit file $submitfile doesn't exist: $submitfile"
|
| 79 |
|
|
exit 1
|
| 80 |
|
|
fi
|
| 81 |
|
|
|
| 82 |
|
|
|
| 83 |
|
|
###############################################################################
|
| 84 |
|
|
# Cleanup #
|
| 85 |
|
|
###############################################################################
|
| 86 |
|
|
echo "Cleanup..."
|
| 87 |
98 |
olivier.gi |
rm -rf *.vcd
|
| 88 |
|
|
rm -rf *.vpd
|
| 89 |
|
|
rm -rf *.trn
|
| 90 |
|
|
rm -rf *.dsn
|
| 91 |
76 |
olivier.gi |
rm -rf pmem.*
|
| 92 |
|
|
rm -rf stimulus.v
|
| 93 |
|
|
|
| 94 |
|
|
|
| 95 |
|
|
###############################################################################
|
| 96 |
|
|
# Run simulation #
|
| 97 |
|
|
###############################################################################
|
| 98 |
|
|
echo " ======================================================="
|
| 99 |
|
|
echo "| Start simulation: $1"
|
| 100 |
|
|
echo " ======================================================="
|
| 101 |
|
|
|
| 102 |
|
|
# Make local copy of the openMSP403 configuration file and remove comments
|
| 103 |
|
|
cp $incfile ./pmem.inc
|
| 104 |
|
|
sed -i "/^\/\// s,.*,," pmem.inc
|
| 105 |
|
|
|
| 106 |
|
|
# Get Program memory size
|
| 107 |
|
|
pmemunit=`grep PMEM_SIZE_ pmem.inc | grep -v ifdef | grep -v "//" | cut -d'_' -f4`
|
| 108 |
|
|
pmemsize=`grep PMEM_SIZE_ pmem.inc | grep -v ifdef | grep -v "//" | cut -d'_' -f3`
|
| 109 |
|
|
pmemsize=${pmemsize/p/.}
|
| 110 |
|
|
if [ $pmemunit == "KB" ]
|
| 111 |
|
|
then
|
| 112 |
|
|
pmemsize=`echo "pmemsize=$pmemsize * 1024; pmemsize /= 1; pmemsize" | bc`
|
| 113 |
|
|
fi
|
| 114 |
|
|
|
| 115 |
|
|
# Get Data Memory size
|
| 116 |
|
|
dmemunit=`grep DMEM_SIZE_ pmem.inc | grep -v ifdef | grep -v "//" | cut -d'_' -f4`
|
| 117 |
|
|
dmemsize=`grep DMEM_SIZE_ pmem.inc | grep -v ifdef | grep -v "//" | cut -d'_' -f3`
|
| 118 |
|
|
dmemsize=${dmemsize/p/.}
|
| 119 |
|
|
if [ $dmemunit == "KB" ]
|
| 120 |
|
|
then
|
| 121 |
|
|
dmemsize=`echo "dmemsize=$dmemsize * 1024; dmemsize /= 1; dmemsize" | bc`
|
| 122 |
|
|
fi
|
| 123 |
|
|
|
| 124 |
|
|
# Make C program
|
| 125 |
|
|
echo "Compile, link & generate IHEX file (Program Memory: $pmemsize B, Data Memory: $dmemsize B)..."
|
| 126 |
|
|
cd $softdir
|
| 127 |
|
|
make clean
|
| 128 |
|
|
make
|
| 129 |
|
|
cd ../../run/
|
| 130 |
|
|
|
| 131 |
|
|
# Create links
|
| 132 |
|
|
ln -s $elffile pmem.elf
|
| 133 |
|
|
ln -s $verfile stimulus.v
|
| 134 |
|
|
|
| 135 |
|
|
# Create IHEX file from ELF
|
| 136 |
|
|
echo "Convert ELF file to IHEX format..."
|
| 137 |
|
|
msp430-objcopy -O ihex pmem.elf pmem.ihex
|
| 138 |
|
|
|
| 139 |
|
|
# Generate Program memory file
|
| 140 |
|
|
echo "Convert IHEX file to Verilog MEMH format..."
|
| 141 |
|
|
../bin/ihex2mem.tcl -ihex pmem.ihex -out pmem.mem -mem_size $pmemsize
|
| 142 |
|
|
|
| 143 |
|
|
# Start verilog simulation
|
| 144 |
|
|
echo "Start Verilog simulation..."
|
| 145 |
|
|
../bin/rtlsim.sh stimulus.v pmem.mem $submitfile
|