1 |
40 |
unneback |
#!/usr/bin/php
|
2 |
|
|
<?php
|
3 |
|
|
|
4 |
|
|
function __autoload($className) {
|
5 |
|
|
include "$className.class.php";
|
6 |
|
|
}
|
7 |
|
|
|
8 |
|
|
if(!isset($argv[1])) {
|
9 |
|
|
?>
|
10 |
|
|
|
11 |
|
|
Usage: <?php echo basename($argv[0]); ?> <fileName>
|
12 |
|
|
|
13 |
|
|
<?php
|
14 |
|
|
die(1);
|
15 |
|
|
}
|
16 |
|
|
|
17 |
|
|
$csv = new CSV($argv[1]);
|
18 |
|
|
|
19 |
|
|
$counter = $csv->getRow();
|
20 |
|
|
$csv->parseHeader();
|
21 |
|
|
$inputs = $csv->getRow();
|
22 |
|
|
$csv->parseHeader();
|
23 |
|
|
$outputs = $csv->getRow();
|
24 |
|
|
$csv->parseHeader();
|
25 |
|
|
$wrap = $csv->getRow();
|
26 |
|
|
$csv->parseHeader();
|
27 |
|
|
$parameters = $csv->getRow();
|
28 |
|
|
|
29 |
|
|
$length = $parameters['length'];
|
30 |
|
|
|
31 |
|
|
# copyright
|
32 |
|
|
echo "`ifdef " . strtoupper($counter['Name']) . PHP_EOL;
|
33 |
|
|
echo "//////////////////////////////////////////////////////////////////////" . PHP_EOL;
|
34 |
|
|
echo "//// ////" . PHP_EOL;
|
35 |
|
|
echo "//// Versatile counter ////" . PHP_EOL;
|
36 |
|
|
echo "//// ////" . PHP_EOL;
|
37 |
|
|
echo "//// Description ////" . PHP_EOL;
|
38 |
|
|
echo "//// Versatile counter, a reconfigurable binary, gray or LFSR ////" . PHP_EOL;
|
39 |
|
|
echo "//// counter ////" . PHP_EOL;
|
40 |
|
|
echo "//// ////" . PHP_EOL;
|
41 |
|
|
echo "//// To Do: ////" . PHP_EOL;
|
42 |
|
|
echo "//// - add LFSR with more taps ////" . PHP_EOL;
|
43 |
|
|
echo "//// ////" . PHP_EOL;
|
44 |
|
|
echo "//// Author(s): ////" . PHP_EOL;
|
45 |
|
|
echo "//// - Michael Unneback, unneback@opencores.org ////" . PHP_EOL;
|
46 |
|
|
echo "//// ORSoC AB ////" . PHP_EOL;
|
47 |
|
|
echo "//// ////" . PHP_EOL;
|
48 |
|
|
echo "//////////////////////////////////////////////////////////////////////" . PHP_EOL;
|
49 |
|
|
echo "//// ////" . PHP_EOL;
|
50 |
|
|
echo "//// Copyright (C) 2009 Authors and OPENCORES.ORG ////" . PHP_EOL;
|
51 |
|
|
echo "//// ////" . PHP_EOL;
|
52 |
|
|
echo "//// This source file may be used and distributed without ////" . PHP_EOL;
|
53 |
|
|
echo "//// restriction provided that this copyright statement is not ////" . PHP_EOL;
|
54 |
|
|
echo "//// removed from the file and that any derivative work contains ////" . PHP_EOL;
|
55 |
|
|
echo "//// the original copyright notice and the associated disclaimer. ////" . PHP_EOL;
|
56 |
|
|
echo "//// ////" . PHP_EOL;
|
57 |
|
|
echo "//// This source file is free software; you can redistribute it ////" . PHP_EOL;
|
58 |
|
|
echo "//// and/or modify it under the terms of the GNU Lesser General ////" . PHP_EOL;
|
59 |
|
|
echo "//// Public License as published by the Free Software Foundation; ////" . PHP_EOL;
|
60 |
|
|
echo "//// either version 2.1 of the License, or (at your option) any ////" . PHP_EOL;
|
61 |
|
|
echo "//// later version. ////" . PHP_EOL;
|
62 |
|
|
echo "//// ////" . PHP_EOL;
|
63 |
|
|
echo "//// This source is distributed in the hope that it will be ////" . PHP_EOL;
|
64 |
|
|
echo "//// useful, but WITHOUT ANY WARRANTY; without even the implied ////" . PHP_EOL;
|
65 |
|
|
echo "//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ////" . PHP_EOL;
|
66 |
|
|
echo "//// PURPOSE. See the GNU Lesser General Public License for more ////" . PHP_EOL;
|
67 |
|
|
echo "//// details. ////" . PHP_EOL;
|
68 |
|
|
echo "//// ////" . PHP_EOL;
|
69 |
|
|
echo "//// You should have received a copy of the GNU Lesser General ////" . PHP_EOL;
|
70 |
|
|
echo "//// Public License along with this source; if not, download it ////" . PHP_EOL;
|
71 |
|
|
echo "//// from http://www.opencores.org/lgpl.shtml ////" . PHP_EOL;
|
72 |
|
|
echo "//// ////" . PHP_EOL;
|
73 |
|
|
echo "//////////////////////////////////////////////////////////////////////" . PHP_EOL;
|
74 |
|
|
|
75 |
|
|
echo PHP_EOL . "// " . $counter['type'] . " counter" . PHP_EOL;
|
76 |
|
|
echo PHP_EOL . "`define MODULE " . $counter['Name'] . PHP_EOL;
|
77 |
|
|
echo "module " . "`BASE`MODULE" . " (" . PHP_EOL;
|
78 |
|
|
echo "`undef MODULE" . PHP_EOL;
|
79 |
|
|
|
80 |
|
|
if ($inputs['clear']=="1") { echo " clear,"; }
|
81 |
|
|
if ($inputs['set']=="1") { echo " set,"; }
|
82 |
|
|
if ($inputs['cke']=="1") { echo " cke,"; }
|
83 |
|
|
if ($inputs['rew']=="1") { echo " rew,"; }
|
84 |
|
|
|
85 |
|
|
if ($outputs['q']=="1") { echo " q,"; }
|
86 |
|
|
if ($outputs['q_bin']=="1" and $counter['type']=="GRAY") { echo " q_bin,"; }
|
87 |
|
|
if ($outputs['z']=="1") { echo " z,"; }
|
88 |
|
|
if ($outputs['zq']=="1") { echo " zq,"; }
|
89 |
|
|
if ($outputs['level1']=="1") { echo " level1,"; }
|
90 |
|
|
if ($outputs['level2']=="1") { echo " level2,"; }
|
91 |
|
|
|
92 |
|
|
echo " rst,";
|
93 |
|
|
echo " clk);" . PHP_EOL;
|
94 |
|
|
echo PHP_EOL;
|
95 |
|
|
|
96 |
|
|
echo " parameter length = " . $length . ";" . PHP_EOL;
|
97 |
|
|
|
98 |
|
|
if ($inputs['clear']=="1") { echo " input " . "clear;" . PHP_EOL; }
|
99 |
|
|
if ($inputs['set']=="1") { echo " input " . "set;" . PHP_EOL; }
|
100 |
|
|
if ($inputs['cke']=="1") { echo " input " . "cke;" . PHP_EOL; }
|
101 |
|
|
if ($inputs['rew']=="1") { echo " input " . "rew;" . PHP_EOL; }
|
102 |
|
|
|
103 |
|
|
if ($counter['type']=="GRAY") {
|
104 |
|
|
if ($outputs['q']=="1") { echo " output reg [length:1] q;" . PHP_EOL; }
|
105 |
|
|
} else {
|
106 |
|
|
if ($outputs['q']=="1") { echo " output [length:1] q;" . PHP_EOL; }
|
107 |
|
|
}
|
108 |
|
|
if ($outputs['q_bin']=="1" and $counter['type']=="GRAY") { echo " output [length:1] q_bin;" . PHP_EOL; }
|
109 |
|
|
if ($outputs['z']=="1") { echo " output z;" . PHP_EOL; }
|
110 |
|
|
if ($outputs['zq']=="1") { echo " output reg zq;" . PHP_EOL; }
|
111 |
|
|
if ($outputs['level1']=="1") { echo " output reg level1;" . PHP_EOL; }
|
112 |
|
|
if ($outputs['level2']=="1") { echo " output reg level2;" . PHP_EOL; }
|
113 |
|
|
|
114 |
|
|
echo " input rst;" . PHP_EOL;
|
115 |
|
|
echo " input clk;" . PHP_EOL;
|
116 |
|
|
echo PHP_EOL;
|
117 |
|
|
|
118 |
|
|
if ($parameters['clear_value']!="") { echo " parameter clear_value = " . $parameters['clear_value'] . ";" . PHP_EOL; }
|
119 |
|
|
if ($parameters['set_value']!="") { echo " parameter set_value = " . $parameters['set_value'] . ";" . PHP_EOL; }
|
120 |
|
|
if ($parameters['wrap_value']!="") { echo " parameter wrap_value = " . $parameters['wrap_value'] . ";" . PHP_EOL; }
|
121 |
|
|
if ($parameters['level1']!="") { echo " parameter level1_value = " . $parameters['level1'] . ";" . PHP_EOL; }
|
122 |
|
|
if ($parameters['level2']!="") { echo " parameter level2_value = " . $parameters['level2'] . ";" . PHP_EOL; }
|
123 |
|
|
|
124 |
|
|
echo PHP_EOL;
|
125 |
|
|
if ($outputs['level1']=="1" and $inputs['clear']=="0") { echo " wire clear;" . PHP_EOL . " assign clear = 1'b0;" . PHP_EOL; }
|
126 |
|
|
if ($outputs['level1']=="1" and $inputs['rew']=="0") { echo " wire rew;" . PHP_EOL . " assign rew = 1'b0;" . PHP_EOL; }
|
127 |
|
|
|
128 |
|
|
echo " reg [length:1] qi;" . PHP_EOL;
|
129 |
|
|
if ($counter['type']=="LFSR") { echo " reg lfsr_fb";}
|
130 |
|
|
if ($counter['type']=="LFSR" and $inputs['rew']==1) { echo ", lfsr_fb_rew;" . PHP_EOL; } else { if ($counter['type']=="LFSR") echo ";" . PHP_EOL; }
|
131 |
|
|
if ($inputs['rew']==1) { echo " wire [length:1] q_next, q_next_fw, q_next_rew;" . PHP_EOL; }
|
132 |
|
|
else { echo " wire [length:1] q_next;" . PHP_EOL; }
|
133 |
|
|
if ($counter['type']=="LFSR" and $inputs['rew']==1) {
|
134 |
|
|
echo " reg [32:1] polynom_rew;" . PHP_EOL;
|
135 |
|
|
echo " integer j;" . PHP_EOL;
|
136 |
|
|
}
|
137 |
|
|
|
138 |
|
|
if ($counter['type']=="LFSR") {
|
139 |
|
|
echo " reg [32:1] polynom;" . PHP_EOL;
|
140 |
|
|
echo " integer i;" . PHP_EOL . PHP_EOL;
|
141 |
|
|
echo " always @ (qi)" . PHP_EOL;
|
142 |
|
|
echo " begin
|
143 |
|
|
case (length)
|
144 |
|
|
2: polynom = 32'b11; // 0x3
|
145 |
|
|
3: polynom = 32'b110; // 0x6
|
146 |
|
|
4: polynom = 32'b1100; // 0xC
|
147 |
|
|
5: polynom = 32'b10100; // 0x14
|
148 |
|
|
6: polynom = 32'b110000; // 0x30
|
149 |
|
|
7: polynom = 32'b1100000; // 0x60
|
150 |
|
|
8: polynom = 32'b10111000; // 0xb8
|
151 |
|
|
9: polynom = 32'b100010000; // 0x110
|
152 |
|
|
10: polynom = 32'b1001000000; // 0x240
|
153 |
|
|
11: polynom = 32'b10100000000; // 0x500
|
154 |
|
|
12: polynom = 32'b100000101001; // 0x829
|
155 |
|
|
13: polynom = 32'b1000000001100; // 0x100C
|
156 |
|
|
14: polynom = 32'b10000000010101; // 0x2015
|
157 |
|
|
15: polynom = 32'b110000000000000; // 0x6000
|
158 |
|
|
16: polynom = 32'b1101000000001000; // 0xD008
|
159 |
|
|
17: polynom = 32'b10010000000000000; // 0x12000
|
160 |
|
|
18: polynom = 32'b100000010000000000; // 0x20400
|
161 |
|
|
19: polynom = 32'b1000000000000100011; // 0x40023
|
162 |
|
|
20: polynom = 32'b10010000000000000000; // 0x90000
|
163 |
|
|
21: polynom = 32'b101000000000000000000; // 0x140000
|
164 |
|
|
22: polynom = 32'b1100000000000000000000; // 0x300000
|
165 |
|
|
23: polynom = 32'b10000100000000000000000; // 0x420000
|
166 |
|
|
24: polynom = 32'b111000010000000000000000; // 0xE10000
|
167 |
|
|
25: polynom = 32'b1001000000000000000000000; // 0x1200000
|
168 |
|
|
26: polynom = 32'b10000000000000000000100011; // 0x2000023
|
169 |
|
|
27: polynom = 32'b100000000000000000000010011; // 0x4000013
|
170 |
|
|
28: polynom = 32'b1100100000000000000000000000; // 0xC800000
|
171 |
|
|
29: polynom = 32'b10100000000000000000000000000; // 0x14000000
|
172 |
|
|
30: polynom = 32'b100000000000000000000000101001; // 0x20000029
|
173 |
|
|
31: polynom = 32'b1001000000000000000000000000000; // 0x48000000
|
174 |
|
|
32: polynom = 32'b10000000001000000000000000000011; // 0x80200003
|
175 |
|
|
default: polynom = 32'b0;
|
176 |
|
|
endcase
|
177 |
|
|
lfsr_fb = qi[length];
|
178 |
|
|
for (i=length-1; i>=1; i=i-1) begin
|
179 |
|
|
if (polynom[i])
|
180 |
|
|
lfsr_fb = lfsr_fb ~^ qi[i];
|
181 |
|
|
end
|
182 |
|
|
end";
|
183 |
|
|
echo PHP_EOL;
|
184 |
|
|
}
|
185 |
|
|
|
186 |
|
|
if ($inputs['rew']!=1) { echo " assign q_next = "; } else { echo " assign q_next_fw = "; }
|
187 |
|
|
if ($inputs['clear']==1) { echo " clear ? {length{1'b0}} :";}
|
188 |
|
|
if ($inputs['set']==1) { echo " set ? set_value :";}
|
189 |
|
|
if ($wrap['wrap']==1) { echo "(qi == wrap_value) ? {length{1'b0}} :";}
|
190 |
|
|
if ($counter['type']=="LFSR") { echo "{qi[length-1:1],lfsr_fb};"; } else { echo "qi + {{length-1{1'b0}},1'b1};"; }
|
191 |
|
|
echo PHP_EOL;
|
192 |
|
|
|
193 |
|
|
if ($inputs['rew']) {
|
194 |
|
|
if ($counter['type']=="LFSR") {
|
195 |
|
|
echo " always @ (qi)" . PHP_EOL;
|
196 |
|
|
echo " begin
|
197 |
|
|
case (length)
|
198 |
|
|
2: polynom_rew = 32'b11;
|
199 |
|
|
3: polynom_rew = 32'b110;
|
200 |
|
|
4: polynom_rew = 32'b1100;
|
201 |
|
|
5: polynom_rew = 32'b10100;
|
202 |
|
|
6: polynom_rew = 32'b110000;
|
203 |
|
|
7: polynom_rew = 32'b1100000;
|
204 |
|
|
8: polynom_rew = 32'b10111000;
|
205 |
|
|
9: polynom_rew = 32'b100010000;
|
206 |
|
|
10: polynom_rew = 32'b1001000000;
|
207 |
|
|
11: polynom_rew = 32'b10100000000;
|
208 |
|
|
12: polynom_rew = 32'b100000101001;
|
209 |
|
|
13: polynom_rew = 32'b1000000001100;
|
210 |
|
|
14: polynom_rew = 32'b10000000010101;
|
211 |
|
|
15: polynom_rew = 32'b110000000000000;
|
212 |
|
|
16: polynom_rew = 32'b1101000000001000;
|
213 |
|
|
17: polynom_rew = 32'b10010000000000000;
|
214 |
|
|
18: polynom_rew = 32'b100000010000000000;
|
215 |
|
|
19: polynom_rew = 32'b1000000000000100011;
|
216 |
|
|
20: polynom_rew = 32'b10000010000000000000;
|
217 |
|
|
21: polynom_rew = 32'b101000000000000000000;
|
218 |
|
|
22: polynom_rew = 32'b1100000000000000000000;
|
219 |
|
|
23: polynom_rew = 32'b10000100000000000000000;
|
220 |
|
|
24: polynom_rew = 32'b111000010000000000000000;
|
221 |
|
|
25: polynom_rew = 32'b1001000000000000000000000;
|
222 |
|
|
26: polynom_rew = 32'b10000000000000000000100011;
|
223 |
|
|
27: polynom_rew = 32'b100000000000000000000010011;
|
224 |
|
|
28: polynom_rew = 32'b1100100000000000000000000000;
|
225 |
|
|
29: polynom_rew = 32'b10100000000000000000000000000;
|
226 |
|
|
30: polynom_rew = 32'b100000000000000000000000101001;
|
227 |
|
|
31: polynom_rew = 32'b1001000000000000000000000000000;
|
228 |
|
|
32: polynom_rew = 32'b10000000001000000000000000000011;
|
229 |
|
|
default: polynom_rew = 32'b0;
|
230 |
|
|
endcase
|
231 |
|
|
// rotate left
|
232 |
|
|
polynom_rew[length:1] = { polynom_rew[length-2:1],polynom_rew[length] };
|
233 |
|
|
lfsr_fb_rew = qi[length];
|
234 |
|
|
for (i=length-1; i>=1; i=i-1) begin
|
235 |
|
|
if (polynom_rew[i])
|
236 |
|
|
lfsr_fb_rew = lfsr_fb_rew ~^ qi[i];
|
237 |
|
|
end
|
238 |
|
|
end";
|
239 |
|
|
echo PHP_EOL;
|
240 |
|
|
|
241 |
|
|
}
|
242 |
|
|
echo " assign q_next_rew = ";
|
243 |
|
|
if ($inputs['clear']==1) { echo " clear ? clear_value :";}
|
244 |
|
|
if ($inputs['set']==1) { echo " set ? set_value :";}
|
245 |
|
|
if ($wrap['wrap']==1) { echo "(qi == wrap_value) ? {length{1'b0}} :";}
|
246 |
|
|
if ($counter['type']=="LFSR") { echo "{lfsr_fb_rew,qi[length:2]};"; } else { echo "qi - {{length-1{1'b0}},1'b1};"; }
|
247 |
|
|
echo PHP_EOL;
|
248 |
|
|
echo " assign q_next = rew ? q_next_rew : q_next_fw;" . PHP_EOL;
|
249 |
|
|
}
|
250 |
|
|
|
251 |
|
|
echo "
|
252 |
|
|
always @ (posedge clk or posedge rst)
|
253 |
|
|
if (rst)
|
254 |
|
|
qi <= {length{1'b0}};
|
255 |
|
|
else" . PHP_EOL;
|
256 |
|
|
if ($inputs['cke']) { echo " if (cke)" . PHP_EOL;}
|
257 |
|
|
echo " qi <= q_next;" . PHP_EOL;
|
258 |
|
|
echo PHP_EOL;
|
259 |
|
|
|
260 |
|
|
if ($outputs['q']) {
|
261 |
|
|
if ($counter['type'] == "GRAY" or $counter['type'] == "gray") {
|
262 |
|
|
echo " always @ (posedge clk or posedge rst)
|
263 |
|
|
if (rst)
|
264 |
|
|
q <= {length{1'b0}};
|
265 |
|
|
else" . PHP_EOL;
|
266 |
|
|
if ($inputs['cke']) { echo " if (cke)" . PHP_EOL; }
|
267 |
|
|
echo " q <= (q_next>>1) ^ q_next;" . PHP_EOL;
|
268 |
|
|
if ($outputs['q_bin']) { echo PHP_EOL . " assign q_bin = qi;" . PHP_EOL; }
|
269 |
|
|
} else {
|
270 |
|
|
echo " assign q = qi;" . PHP_EOL;
|
271 |
|
|
}
|
272 |
|
|
}
|
273 |
|
|
echo PHP_EOL;
|
274 |
|
|
|
275 |
|
|
if ($outputs['z']) { echo " assign z = (q == {length{1'b0}});" . PHP_EOL; }
|
276 |
|
|
|
277 |
|
|
if ($outputs['zq']) {
|
278 |
|
|
echo "
|
279 |
|
|
always @ (posedge clk or posedge rst)
|
280 |
|
|
if (rst)
|
281 |
|
|
zq <= 1'b1;
|
282 |
|
|
else" . PHP_EOL;
|
283 |
|
|
if ($inputs['cke']) { echo " if (cke)" . PHP_EOL; }
|
284 |
|
|
echo " zq <= q_next == {length{1'b0}};" . PHP_EOL;
|
285 |
|
|
}
|
286 |
|
|
|
287 |
|
|
if ($outputs['level1']) {
|
288 |
|
|
echo "
|
289 |
|
|
always @ (posedge clk or posedge rst)
|
290 |
|
|
if (rst)
|
291 |
|
|
level1 <= 1'b0;
|
292 |
|
|
else" . PHP_EOL;
|
293 |
|
|
if ($inputs['cke']) { echo " if (cke)" . PHP_EOL; }
|
294 |
|
|
echo " if (clear)
|
295 |
|
|
level1 <= 1'b0;
|
296 |
|
|
else if (q_next == level1_value)
|
297 |
|
|
level1 <= 1'b1;
|
298 |
|
|
else if (qi == level1_value & rew)
|
299 |
|
|
level1 <= 1'b0;" . PHP_EOL;
|
300 |
|
|
}
|
301 |
|
|
|
302 |
|
|
if ($outputs['level2']) {
|
303 |
|
|
echo "
|
304 |
|
|
always @ (posedge clk or posedge rst)
|
305 |
|
|
if (rst)
|
306 |
|
|
level2 <= 1'b0;
|
307 |
|
|
else" . PHP_EOL;
|
308 |
|
|
if ($inputs['cke']) { echo " if (cke)" . PHP_EOL; }
|
309 |
|
|
echo " if (clear)
|
310 |
|
|
level2 <= 1'b0;
|
311 |
|
|
else if (q_next == level2_value)
|
312 |
|
|
level2 <= 1'b1;
|
313 |
|
|
else if (qi == level2_value & rew)
|
314 |
|
|
level2 <= 1'b0;" . PHP_EOL;
|
315 |
|
|
}
|
316 |
|
|
|
317 |
|
|
echo "endmodule" . PHP_EOL;
|
318 |
|
|
echo "`endif" . PHP_EOL;
|