-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_fpga_code.sh
executable file
·237 lines (166 loc) · 4.84 KB
/
generate_fpga_code.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
#!/bin/bash
dt=$(date)
#
# Emit prelude code
#
cat << ZZZ_PRELUDE_END
// ------------------------------------------------------------------------------
// Perseus Receiver FPGA code
//
// Copyright (c) 2010 Nicolangelo Palermo / IV3NWV
// This file is part of the Perseus SDR Library
//
// The Perseus SDR Library is free software; you can redistribute
// it and/or modify 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 (at your option) any later version.
// The Perseus SDR Library is distributed in the hope that it will
// be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// See the GNU Lesser General Public License for more details.
// You should have received a copy of the GNU Lesser General Public
// License along with the Perseus SDR Library;
// if not, see <http://www.gnu.org/licenses/>.
// Creation date: $dt
// Version: N/A
// Author: (Automatically generated)
// ------------------------------------------------------------------------------
//
// Automatically generated at $dt
// Please don't manually change this file !!!
//
#include <fpga_data.h>
ZZZ_PRELUDE_END
RBS=$1/'*.rbs'
N_FPGA=0
#
# generate the FPGA data arrays
#
for x in $RBS
do
# compute file length
file_size=$(stat -c%s "$x")
### -> # removes the shortest match from the beginning
### -> ## removes the longest match from the beginning
### -> % removes the shortest match from the end
### -> %% removes the longest match from the end
# file name without path
file=${x##*/}
speed=${file#perseus}
speed2=${speed%%v$RBS}
mega=${speed2%%m*}
kilo=${speed2%%k*}
tag=""
if [ -n "$( echo $mega | sed 's/^[+-]//;s/[0-9]//g;s/\.//;s/d//' )" ] ; then
if [ -n "$( echo $kilo | sed 's/^[+-]//;s/[0-9]//g;s/\.//' )" ] ; then
echo "FATAL: UNEXPECTED: $kilo"
exit 255
else
tag=$(expr $kilo \* 1000)
fi
else
### search for a 'd' embedded
if [ -n "$( echo $mega | sed 's/^[+-]//;s/[0-9]//g;s/\.//' )" ] ; then
dd=${mega#*d}
ii=${mega%d*}
tag=$(expr $ii \* 1000000 + $dd \* 100000 )
else
tag=$(expr $mega \* 1000000)
fi
fi
echo "////********** $file: s: $speed s2: $speed2 M: $mega K: $kilo $tag"
echo "//// [$x]"
echo "const unsigned char fpga_data_$tag[$file_size] = "
echo " { "
# produce the data in C format
cat "$x" | xxd -i
echo " };"
echo "//// end of $file"
N_FPGA=$(( $N_FPGA + 1 ))
done
#
# Generate the table (sorted by speed)
#
cat << YYY_END
FpgaImages fpgaImgTbl [] = {
YYY_END
echo -n "" > tmpfile
for x in $RBS
do
file_size=$(stat -c%s "$x")
file=${x##*/}
speed=${file#perseus}
speed2=${speed%%v$RBS}
mega=${speed2%%m*}
kilo=${speed2%%k*}
tag=""
if [ -n "$( echo $mega | sed 's/^[+-]//;s/[0-9]//g;s/\.//;s/d//' )" ] ; then
if [ -n "$( echo $kilo | sed 's/^[+-]//;s/[0-9]//g;s/\.//' )" ] ; then
echo "FATAL: UNEXPECTED: $kilo"
exit 255
else
tag=$(expr $kilo \* 1000)
fi
else
### search for a 'd' embedded
if [ -n "$( echo $mega | sed 's/^[+-]//;s/[0-9]//g;s/\.//' )" ] ; then
dd=${mega#*d}
ii=${mega%d*}
tag=$(expr $ii \* 1000000 + $dd \* 100000 )
else
tag=$(expr $mega \* 1000000)
fi
fi
##echo "********** $file: $speed: $speed2: M: $mega K: $kilo"
echo "$tag $file $file_size $x" >> tmpfile
done
#
# sort
#
cat tmpfile | sort -g > tmpfile2
while read SPEED FN SIZE FN2
do
echo "//// >>>>$SPEED<>$FN<>$SIZE<<<<<<"
obj_name=$( echo $FN | sed 's/[\.]/_/' )
echo "{"
echo " \"$FN\", "
echo " $SPEED, "
echo " $SIZE, "
echo " fpga_data_$SPEED,"
echo " sizeof( fpga_data_$SPEED )"
echo "}, "
echo "////"
done < tmpfile2
cat << XXXX_END
}; // end of table *******
XXXX_END
#emit table size
echo "int nFpgaImages = $N_FPGA;"
# emit trailers
cat << XXXXX_END
/*
* Compile and test with the following command:
*
* gcc -D__TEST_MODULE__ -I. fpga_data.c -o fpga_data_test && ./fpga_data_test
*/
#if defined __TEST_MODULE__
#include <stdio.h>
#include <assert.h>
#define ARRAYSIZE(a) (sizeof(a)/sizeof(a[0]))
int main (void)
{
int i;
assert(ARRAYSIZE(fpgaImgTbl)==nFpgaImages);
fprintf (stderr, "Cores available: %d\n\n", nFpgaImages);
for (i=0; i < ARRAYSIZE(fpgaImgTbl); ++i) {
fprintf (stderr, "name: %20.20s\tspeed: %10.d\tsize: %10.d\tsizeof: %10.d\n",
fpgaImgTbl [i].name, fpgaImgTbl [i].speed, fpgaImgTbl [i].size, fpgaImgTbl [i].osize
);
if (fpgaImgTbl [i].size != fpgaImgTbl[i].osize)
fprintf (stderr, "FATAL error: declared size %d != from real size: %d \n", fpgaImgTbl [i].size, fpgaImgTbl [i].osize );
}
return 0;
}
#endif
XXXXX_END
rm -f tmpfile tmpfile2