1 |
157 |
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 |
212 |
olivier.gi |
#
|
26 |
157 |
olivier.gi |
# File Name: msp430sim
|
27 |
212 |
olivier.gi |
#
|
28 |
157 |
olivier.gi |
# Author(s):
|
29 |
|
|
# - Olivier Girard, olgirard@gmail.com
|
30 |
|
|
#
|
31 |
|
|
#------------------------------------------------------------------------------
|
32 |
212 |
olivier.gi |
# $Rev: 73 $
|
33 |
157 |
olivier.gi |
# $LastChangedBy: olivier.girard $
|
34 |
212 |
olivier.gi |
# $LastChangedDate: 2010-08-03 21:26:39 +0200 (Tue, 03 Aug 2010) $
|
35 |
157 |
olivier.gi |
#------------------------------------------------------------------------------
|
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 "
|
44 |
|
|
echo "Example : msp430sim leds"
|
45 |
|
|
echo ""
|
46 |
|
|
echo "In order to switch the verilog simulator, the OMSP_SIMULATOR 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 " - isim : Xilinx simulator"
|
56 |
|
|
echo ""
|
57 |
|
|
exit 1
|
58 |
|
|
fi
|
59 |
|
|
|
60 |
|
|
|
61 |
|
|
###############################################################################
|
62 |
|
|
# Check if the required files exist #
|
63 |
|
|
###############################################################################
|
64 |
|
|
softdir=../../../software/$1;
|
65 |
|
|
elffile=../../../software/$1/$1.elf;
|
66 |
|
|
verfile=../src/$1.v;
|
67 |
|
|
submitfile=../src/submit.f;
|
68 |
|
|
if [ $OMSP_SIMULATOR == "isim" ]; then
|
69 |
|
|
submitfile=../src/submit.prj;
|
70 |
|
|
fi
|
71 |
|
|
incfile=../../../rtl/verilog/openmsp430/openMSP430_defines.v;
|
72 |
|
|
|
73 |
|
|
if [ ! -e $softdir ]; then
|
74 |
|
|
echo "Software directory doesn't exist: $softdir"
|
75 |
|
|
exit 1
|
76 |
|
|
fi
|
77 |
|
|
if [ ! -e $verfile ]; then
|
78 |
|
|
echo "Verilog stimulus file $verfile doesn't exist: $verfile"
|
79 |
|
|
exit 1
|
80 |
|
|
fi
|
81 |
|
|
if [ ! -e $submitfile ]; then
|
82 |
|
|
echo "Verilog submit file $submitfile doesn't exist: $submitfile"
|
83 |
|
|
exit 1
|
84 |
|
|
fi
|
85 |
|
|
|
86 |
|
|
|
87 |
|
|
###############################################################################
|
88 |
|
|
# Cleanup #
|
89 |
|
|
###############################################################################
|
90 |
|
|
echo "Cleanup..."
|
91 |
|
|
rm -rf *.vcd
|
92 |
|
|
rm -rf *.vpd
|
93 |
|
|
rm -rf *.trn
|
94 |
|
|
rm -rf *.dsn
|
95 |
|
|
rm -rf pmem.*
|
96 |
|
|
rm -rf stimulus.v
|
97 |
|
|
|
98 |
|
|
|
99 |
|
|
###############################################################################
|
100 |
|
|
# Run simulation #
|
101 |
|
|
###############################################################################
|
102 |
|
|
echo " ======================================================="
|
103 |
|
|
echo "| Start simulation: $1"
|
104 |
|
|
echo " ======================================================="
|
105 |
|
|
|
106 |
212 |
olivier.gi |
# Make local copy of the openMSP403 configuration file
|
107 |
|
|
# and prepare it for MSPGCC preprocessing
|
108 |
|
|
cp $incfile ./pmem.h
|
109 |
|
|
sed -ie 's/`ifdef/#ifdef/g' ./pmem.h
|
110 |
|
|
sed -ie 's/`else/#else/g' ./pmem.h
|
111 |
|
|
sed -ie 's/`endif/#endif/g' ./pmem.h
|
112 |
|
|
sed -ie 's/`define/#define/g' ./pmem.h
|
113 |
|
|
sed -ie 's/`include/\/\/#include/g' ./pmem.h
|
114 |
|
|
sed -ie 's/`//g' ./pmem.h
|
115 |
|
|
sed -ie "s/'//g" ./pmem.h
|
116 |
|
|
|
117 |
|
|
# Use MSPGCC preprocessor to extract the Program, Data
|
118 |
|
|
# and Peripheral memory sizes
|
119 |
|
|
if command -v msp430-elf-gcc >/dev/null; then
|
120 |
|
|
msp430-elf-gcc -E -P -x c ../bin/omsp_config.sh > pmem.sh
|
121 |
|
|
else
|
122 |
|
|
msp430-gcc -E -P -x c ../bin/omsp_config.sh > pmem.sh
|
123 |
|
|
fi
|
124 |
|
|
|
125 |
|
|
# Source the extracted configuration file
|
126 |
|
|
if [[ $(uname -s) == CYGWIN* ]];
|
127 |
|
|
then
|
128 |
|
|
dos2unix pmem.sh
|
129 |
|
|
fi
|
130 |
|
|
source pmem.sh
|
131 |
|
|
|
132 |
157 |
olivier.gi |
# Make C program
|
133 |
|
|
cd $softdir
|
134 |
|
|
make clean
|
135 |
|
|
make
|
136 |
|
|
cd ../../sim/rtl_sim/run/
|
137 |
|
|
|
138 |
|
|
# Create links
|
139 |
212 |
olivier.gi |
if [[ $(uname -s) == CYGWIN* ]];
|
140 |
157 |
olivier.gi |
then
|
141 |
|
|
cp $elffile pmem.elf
|
142 |
|
|
cp $verfile stimulus.v
|
143 |
|
|
else
|
144 |
|
|
ln -s $elffile pmem.elf
|
145 |
|
|
ln -s $verfile stimulus.v
|
146 |
|
|
fi
|
147 |
|
|
|
148 |
|
|
# Create IHEX file from ELF
|
149 |
|
|
echo "Convert ELF file to IHEX format..."
|
150 |
212 |
olivier.gi |
if command -v msp430-elf-objcopy >/dev/null; then
|
151 |
|
|
msp430-elf-objcopy -O ihex pmem.elf pmem.ihex
|
152 |
|
|
else
|
153 |
|
|
msp430-objcopy -O ihex pmem.elf pmem.ihex
|
154 |
|
|
fi
|
155 |
157 |
olivier.gi |
|
156 |
|
|
# Generate Program memory file
|
157 |
|
|
echo "Convert IHEX file to Verilog MEMH format..."
|
158 |
|
|
../bin/ihex2mem.tcl -ihex pmem.ihex -out pmem.mem -mem_size $pmemsize
|
159 |
|
|
|
160 |
|
|
# Start verilog simulation
|
161 |
|
|
echo "Start Verilog simulation..."
|
162 |
|
|
../bin/rtlsim.sh stimulus.v pmem.mem $submitfile
|