1 |
73 |
olivier.gi |
#!/bin/bash
|
2 |
2 |
olivier.gi |
#------------------------------------------------------------------------------
|
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
|
27 |
|
|
#
|
28 |
17 |
olivier.gi |
# Author(s):
|
29 |
|
|
# - Olivier Girard, olgirard@gmail.com
|
30 |
|
|
#
|
31 |
2 |
olivier.gi |
#------------------------------------------------------------------------------
|
32 |
17 |
olivier.gi |
# $Rev: 73 $
|
33 |
|
|
# $LastChangedBy: olivier.girard $
|
34 |
|
|
# $LastChangedDate: 2010-08-03 21:26:39 +0200 (Tue, 03 Aug 2010) $
|
35 |
|
|
#------------------------------------------------------------------------------
|
36 |
2 |
olivier.gi |
|
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 "
|
44 |
|
|
echo "Example : msp430sim c-jump_jge"
|
45 |
|
|
exit 1
|
46 |
|
|
fi
|
47 |
|
|
|
48 |
|
|
|
49 |
|
|
###############################################################################
|
50 |
|
|
# Check if the required files exist #
|
51 |
|
|
###############################################################################
|
52 |
|
|
asmfile=../src/$1.s43;
|
53 |
|
|
verfile=../src/$1.v;
|
54 |
|
|
submitfile=../src/submit.f;
|
55 |
23 |
olivier.gi |
incfile=../../../rtl/verilog/openMSP430_defines.v;
|
56 |
2 |
olivier.gi |
deffile=../bin/template.def;
|
57 |
|
|
|
58 |
|
|
if [ ! -e $asmfile ]; then
|
59 |
|
|
echo "Assembler file $asmfile doesn't exist: $asmfile"
|
60 |
|
|
exit 1
|
61 |
|
|
fi
|
62 |
|
|
if [ ! -e $verfile ]; then
|
63 |
|
|
echo "Verilog stimulus file $verfile doesn't exist: $verfile"
|
64 |
|
|
exit 1
|
65 |
|
|
fi
|
66 |
|
|
if [ ! -e $submitfile ]; then
|
67 |
|
|
echo "Verilog submit file $submitfile doesn't exist: $submitfile"
|
68 |
|
|
exit 1
|
69 |
|
|
fi
|
70 |
|
|
if [ ! -e $deffile ]; then
|
71 |
|
|
echo "Linker definition file template doesn't exist: $deffile"
|
72 |
|
|
exit 1
|
73 |
|
|
fi
|
74 |
|
|
|
75 |
|
|
|
76 |
|
|
###############################################################################
|
77 |
|
|
# Cleanup #
|
78 |
|
|
###############################################################################
|
79 |
|
|
echo "Cleanup..."
|
80 |
65 |
olivier.gi |
rm -rf *.vcd
|
81 |
33 |
olivier.gi |
rm -rf pmem.*
|
82 |
2 |
olivier.gi |
rm -rf stimulus.v
|
83 |
|
|
|
84 |
|
|
|
85 |
|
|
###############################################################################
|
86 |
|
|
# Run simulation #
|
87 |
|
|
###############################################################################
|
88 |
|
|
echo " ======================================================="
|
89 |
|
|
echo "| Start simulation: $1"
|
90 |
|
|
echo " ======================================================="
|
91 |
|
|
|
92 |
|
|
# Create links
|
93 |
33 |
olivier.gi |
ln -s $asmfile pmem.s43
|
94 |
2 |
olivier.gi |
ln -s $verfile stimulus.v
|
95 |
|
|
|
96 |
|
|
# Make local copy of the openMSP403 configuration file and remove comments
|
97 |
33 |
olivier.gi |
cp $incfile ./pmem.inc
|
98 |
|
|
sed -i "/^\/\// s,.*,," pmem.inc
|
99 |
2 |
olivier.gi |
|
100 |
33 |
olivier.gi |
# Get Program Memory size
|
101 |
72 |
olivier.gi |
pmemunit=`grep PMEM_SIZE_ pmem.inc | grep -v ifdef | grep -v "//" | cut -d'_' -f4`
|
102 |
|
|
pmemsize=`grep PMEM_SIZE_ pmem.inc | grep -v ifdef | grep -v "//" | cut -d'_' -f3`
|
103 |
|
|
pmemsize=${pmemsize/p/.}
|
104 |
|
|
if [ $pmemunit == "KB" ]
|
105 |
|
|
then
|
106 |
|
|
pmemsize=`echo "pmemsize=$pmemsize * 1024; pmemsize /= 1; pmemsize" | bc`
|
107 |
|
|
fi
|
108 |
2 |
olivier.gi |
|
109 |
33 |
olivier.gi |
# Get Data Memory size
|
110 |
72 |
olivier.gi |
dmemunit=`grep DMEM_SIZE_ pmem.inc | grep -v ifdef | grep -v "//" | cut -d'_' -f4`
|
111 |
|
|
dmemsize=`grep DMEM_SIZE_ pmem.inc | grep -v ifdef | grep -v "//" | cut -d'_' -f3`
|
112 |
|
|
dmemsize=${dmemsize/p/.}
|
113 |
|
|
if [ $dmemunit == "KB" ]
|
114 |
|
|
then
|
115 |
|
|
dmemsize=`echo "dmemsize=$dmemsize * 1024; dmemsize /= 1; dmemsize" | bc`
|
116 |
|
|
fi
|
117 |
2 |
olivier.gi |
|
118 |
72 |
olivier.gi |
|
119 |
2 |
olivier.gi |
# Compile assembler code
|
120 |
33 |
olivier.gi |
echo "Compile, link & generate IHEX file (Program Memory: $pmemsize B, Data Memory: $dmemsize B)..."
|
121 |
|
|
../bin/asm2ihex.sh pmem pmem.s43 $deffile $pmemsize $dmemsize
|
122 |
2 |
olivier.gi |
|
123 |
33 |
olivier.gi |
# Generate Program memory file
|
124 |
2 |
olivier.gi |
echo "Convert IHEX file to Verilog MEMH format..."
|
125 |
33 |
olivier.gi |
../bin/ihex2mem.tcl -ihex pmem.ihex -out pmem.mem -mem_size $pmemsize
|
126 |
2 |
olivier.gi |
|
127 |
|
|
# Start verilog simulation
|
128 |
|
|
echo "Start Verilog simulation..."
|
129 |
33 |
olivier.gi |
../bin/rtlsim.sh stimulus.v pmem.mem $submitfile
|