URL
https://opencores.org/ocsvn/versatile_counter/versatile_counter/trunk
Subversion Repositories versatile_counter
Compare Revisions
- This comparison shows the changes necessary to convert path
/versatile_counter
- from Rev 19 to Rev 20
- ↔ Reverse comparison
Rev 19 → Rev 20
/trunk/bench/vc_tb.v
0,0 → 1,5
module vc_tb (); |
|
dut: vc ( |
. |
) |
/trunk/bench/versatile_counter_tb.v
51,7 → 51,7
.clear(clear), |
.cke(cke), |
.set(set), |
// .rew(rew), |
.rew(rew), |
.q(), |
// .q_next(), |
// .z(), |
/trunk/rtl/verilog/versatile_counter.v
1,17 → 1,20
`include "versatile_counter_defines.v" |
`define LFSR_LENGTH `CNT_LENGTH |
`define LFSR_LENGTH cnt_length |
`include "lfsr_polynom.v" |
`let CNT_INDEX=CNT_LENGTH-1 |
`ifndef CNT_MODULE_NAME |
`define CNT_MODULE_NAME vcnt |
`endif |
module `CNT_MODULE_NAME |
( |
`ifdef CNT_TYPE_GRAY |
output reg [`CNT_LENGTH:1] q, |
output reg [cnt_length:1] q, |
`ifdef CNT_Q_BIN |
output [`CNT_LENGTH:1] q_bin, |
output [cnt_length:1] q_bin, |
`endif |
`else |
`ifdef CNT_Q |
output [`CNT_LENGTH:1] q, |
output [cnt_length:1] q, |
`endif |
`endif |
`ifdef CNT_CLEAR |
27,7 → 30,7
input cke, |
`endif |
`ifdef CNT_QNEXT |
output [`CNT_LENGTH:1] q_next, |
output [cnt_length:1] q_next, |
`endif |
`ifdef CNT_Z |
output z, |
35,26 → 38,40
`ifdef CNT_ZQ |
output reg zq, |
`endif |
`ifdef CNT_LEVEL1 |
output reg level1, |
`endif |
`ifdef CNT_LEVEL2 |
output reg level2, |
`endif |
input clk, |
input rst |
); |
|
parameter cnt_length = `CNT_LENGTH; |
parameter cnt_reset_value = `CNT_RESET_VALUE; |
`ifdef CNT_SET |
parameter set_value = `CNT_SET_VALUE; |
parameter set_value = cnt_length'd`CNT_SET_VALUE; |
`endif |
`ifdef CNT_WRAP |
parameter wrap_value = `CNT_WRAP_VALUE; |
`endif |
parameter wrap_value = cnt_length'd`CNT_WRAP_VALUE; |
`endif |
`ifdef CNT_LEVEL1 |
parameter level1_value = cnt_length'd`CNT_LEVEL1_VALUE; |
`endif |
`ifdef CNT_LEVEL2 |
parameter level2_value = cnt_length'd`CNT_LEVEL2_VALUE; |
`endif |
|
// internal q reg |
reg [`CNT_LENGTH:1] qi; |
reg [cnt_length:1] qi; |
|
`ifndef CNT_QNEXT |
wire [`CNT_LENGTH:1] q_next; |
wire [cnt_length:1] q_next; |
`endif |
`ifdef CNT_REW |
wire [`CNT_LENGTH:1] q_next_fw; |
wire [`CNT_LENGTH:1] q_next_rew; |
wire [cnt_length:1] q_next_fw; |
wire [cnt_length:1] q_next_rew; |
`endif |
|
`ifndef CNT_REW |
63,35 → 80,35
assign q_next_fw = |
`endif |
`ifdef CNT_CLEAR |
clear ? `CNT_LENGTH'd0 : |
clear ? cnt_length'd0 : |
`endif |
`ifdef CNT_SET |
set ? set_value : |
`endif |
`ifdef CNT_WRAP |
(qi == wrap_value) ? `CNT_LENGTH'd0 : |
(qi == wrap_value) ? cnt_length'd0 : |
`endif |
`ifdef CNT_TYPE_LFSR |
{qi[`CNT_INDEX:1],~(`LFSR_FB)}; |
`else |
qi + `CNT_LENGTH'd1; |
qi + cnt_length'd1; |
`endif |
|
`ifdef CNT_REW |
assign q_next_rew = |
`ifdef CNT_CLEAR |
clear ? `CNT_LENGTH'd0 : |
clear ? cnt_length'd0 : |
`endif |
`ifdef CNT_SET |
set ? set_value : |
`endif |
`ifdef CNT_WRAP |
(qi == `CNT_LENGTH'd0) ? wrap_value : |
(qi == cnt_length'd0) ? wrap_value : |
`endif |
`ifdef CNT_TYPE_LFSR |
{~(`LFSR_FB_REW),qi[`CNT_LENGTH:2]}; |
{~(`LFSR_FB_REW),qi[cnt_length:2]}; |
`else |
qi - `CNT_LENGTH'd1; |
qi - cnt_length'd1; |
`endif |
`endif |
|
101,7 → 118,7
|
always @ (posedge clk or posedge rst) |
if (rst) |
qi <= `CNT_LENGTH'd0; |
qi <= cnt_length'd0; |
else |
`ifdef CNT_CE |
if (cke) |
127,7 → 144,7
`endif |
|
`ifdef CNT_Z |
assign z = (q == `CNT_LENGTH'd0); |
assign z = (q == cnt_length'd0); |
`endif |
|
`ifdef CNT_ZQ |
138,6 → 155,35
`ifdef CNT_CE |
if (cke) |
`endif |
zq <= q_next == `CNT_LENGTH'd0; |
zq <= q_next == cnt_length'd0; |
`endif |
|
`ifdef CNT_LEVEL1 |
always @ (posedge clk or posedge rst) |
if (rst) |
level1 <= 1'b0; |
else |
`ifdef CNT_CE |
if (cke) |
`endif |
if (q_next == level1_value) |
level1 <= 1'b1; |
else if (q == level1_value & rew) |
level1 <= 1'b0; |
`endif |
|
`ifdef CNT_LEVEL2 |
always @ (posedge clk or posedge rst) |
if (rst) |
level2 <= 1'b0; |
else |
`ifdef CNT_CE |
if (cke) |
`endif |
if (q_next == level2_value) |
level2 <= 1'b1; |
else if (q == level2_value & rew) |
level2 <= 1'b0; |
`endif |
|
endmodule |
/trunk/rtl/verilog/versatile_counter_generator.php
0,0 → 1,300
#!/usr/bin/php |
<?php |
|
function __autoload($className) { |
include "$className.class.php"; |
} |
|
if(!isset($argv[1])) { |
?> |
|
Usage: <?php echo basename($argv[0]); ?> <fileName> |
|
<?php |
die(1); |
} |
|
$csv = new CSV($argv[1]); |
|
$counter = $csv->getRow(); |
$csv->parseHeader(); |
$inputs = $csv->getRow(); |
$csv->parseHeader(); |
$outputs = $csv->getRow(); |
$csv->parseHeader(); |
$wrap = $csv->getRow(); |
$csv->parseHeader(); |
$parameters = $csv->getRow(); |
|
$length = $parameters['length']; |
|
# copyright |
echo "//////////////////////////////////////////////////////////////////////" . PHP_EOL; |
echo "//// ////" . PHP_EOL; |
echo "//// Versatile counter ////" . PHP_EOL; |
echo "//// ////" . PHP_EOL; |
echo "//// Description ////" . PHP_EOL; |
echo "//// Versatile counter, a reconfigurable binary, gray or LFSR ////" . PHP_EOL; |
echo "//// counter ////" . PHP_EOL; |
echo "//// ////" . PHP_EOL; |
echo "//// To Do: ////" . PHP_EOL; |
echo "//// - add LFSR with more taps ////" . PHP_EOL; |
echo "//// ////" . PHP_EOL; |
echo "//// Author(s): ////" . PHP_EOL; |
echo "//// - Michael Unneback, unneback@opencores.org ////" . PHP_EOL; |
echo "//// ORSoC AB ////" . PHP_EOL; |
echo "//// ////" . PHP_EOL; |
echo "//////////////////////////////////////////////////////////////////////" . PHP_EOL; |
echo "//// ////" . PHP_EOL; |
echo "//// Copyright (C) 2009 Authors and OPENCORES.ORG ////" . PHP_EOL; |
echo "//// ////" . PHP_EOL; |
echo "//// This source file may be used and distributed without ////" . PHP_EOL; |
echo "//// restriction provided that this copyright statement is not ////" . PHP_EOL; |
echo "//// removed from the file and that any derivative work contains ////" . PHP_EOL; |
echo "//// the original copyright notice and the associated disclaimer. ////" . PHP_EOL; |
echo "//// ////" . PHP_EOL; |
echo "//// This source file is free software; you can redistribute it ////" . PHP_EOL; |
echo "//// and/or modify it under the terms of the GNU Lesser General ////" . PHP_EOL; |
echo "//// Public License as published by the Free Software Foundation; ////" . PHP_EOL; |
echo "//// either version 2.1 of the License, or (at your option) any ////" . PHP_EOL; |
echo "//// later version. ////" . PHP_EOL; |
echo "//// ////" . PHP_EOL; |
echo "//// This source is distributed in the hope that it will be ////" . PHP_EOL; |
echo "//// useful, but WITHOUT ANY WARRANTY; without even the implied ////" . PHP_EOL; |
echo "//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ////" . PHP_EOL; |
echo "//// PURPOSE. See the GNU Lesser General Public License for more ////" . PHP_EOL; |
echo "//// details. ////" . PHP_EOL; |
echo "//// ////" . PHP_EOL; |
echo "//// You should have received a copy of the GNU Lesser General ////" . PHP_EOL; |
echo "//// Public License along with this source; if not, download it ////" . PHP_EOL; |
echo "//// from http://www.opencores.org/lgpl.shtml ////" . PHP_EOL; |
echo "//// ////" . PHP_EOL; |
echo "//////////////////////////////////////////////////////////////////////" . PHP_EOL; |
|
echo PHP_EOL . "// " . $counter['type'] . " counter" . PHP_EOL; |
echo "module " . $counter['Name']. " ("; |
|
if ($inputs['clear']=="1") { echo "clear,"; } |
if ($inputs['set']=="1") { echo " set,"; } |
if ($inputs['cke']=="1") { echo "cke, "; } |
if ($inputs['rew']=="1") { echo " rew,"; } |
|
if ($outputs['q']=="1") { echo " q,"; } |
if ($outputs['q_bin']=="1") { echo "q_bin,"; } |
if ($outputs['z']=="1") { echo " z,"; } |
if ($outputs['zq']=="1") { echo " zq,"; } |
if ($outputs['level1']=="1") { echo " level1,"; } |
if ($outputs['level2']=="1") { echo " level2,"; } |
|
echo " rst,"; |
echo " clk);" . PHP_EOL; |
echo PHP_EOL; |
|
echo " parameter length = " . $length . ";" . PHP_EOL; |
|
if ($inputs['clear']=="1") { echo " input " . "clear;" . PHP_EOL; } |
if ($inputs['set']=="1") { echo " input " . "set;" . PHP_EOL; } |
if ($inputs['cke']=="1") { echo " input " . "cke;" . PHP_EOL; } |
if ($inputs['rew']=="1") { echo " input " . "rew;" . PHP_EOL; } |
|
if ($outputs['q']=="1") { echo " output [length:1] q;" . PHP_EOL; } |
if ($outputs['q_bin']=="1") { echo " output [length:1] q_bin;" . PHP_EOL; } |
if ($outputs['z']=="1") { echo " output z;" . PHP_EOL; } |
if ($outputs['zq']=="1") { echo " output reg zq;" . PHP_EOL; } |
if ($outputs['level1']=="1") { echo " output reg level1;" . PHP_EOL; } |
if ($outputs['level2']=="1") { echo " output reg level2;" . PHP_EOL; } |
|
echo " input rst;" . PHP_EOL; |
echo " input clk;" . PHP_EOL; |
echo PHP_EOL; |
|
if ($parameters['clear_value']!="") { echo " parameter clear_value = " . $parameters['clear_value'] . ";" . PHP_EOL; } |
if ($parameters['set_value']!="") { echo " parameter set_value = " . $parameters['set_value'] . ";" . PHP_EOL; } |
if ($parameters['wrap_value']!="") { echo " parameter wrap_value = " . $parameters['wrap_value'] . ";" . PHP_EOL; } |
if ($parameters['level1']!="") { echo " parameter level1_value = " . $parameters['level1'] . ";" . PHP_EOL; } |
if ($parameters['level2']!="") { echo " parameter level2_value = " . $parameters['level2'] . ";" . PHP_EOL; } |
|
echo PHP_EOL . " reg [length:1] qi;" . PHP_EOL; |
if ($counter['type']=="LFSR") { echo " reg lfsr_fb";} |
if ($counter['type']=="LFSR" and $inputs['rew']==1) { echo ", lfsr_fb_rew;" . PHP_EOL; } else { echo ";" . PHP_EOL; } |
if ($inputs['rew']==1) { echo " wire [length:1] q_next, q_next_fw, q_next_rew;" . PHP_EOL; } |
else { echo " wire [length:1] q_next;" . PHP_EOL; } |
if ($counter['type']=="LFSR" and $inputs['rew']==1) { |
echo " reg [32:1] polynom_rew;" . PHP_EOL; |
echo " integer j;" . PHP_EOL; |
} |
|
if ($counter['type']=="LFSR") { |
echo " reg [32:1] polynom;" . PHP_EOL; |
echo " integer i;" . PHP_EOL . PHP_EOL; |
echo " always @ (qi)" . PHP_EOL; |
echo " begin |
case (length) |
2: polynom = 32'b11; // 0x3 |
3: polynom = 32'b110; // 0x6 |
4: polynom = 32'b1100; // 0xC |
5: polynom = 32'b10100; // 0x14 |
6: polynom = 32'b110000; // 0x30 |
7: polynom = 32'b1100000; // 0x60 |
8: polynom = 32'b10111000; // 0xb8 |
9: polynom = 32'b100010000; // 0x110 |
10: polynom = 32'b1001000000; // 0x240 |
11: polynom = 32'b10100000000; // 0x500 |
12: polynom = 32'b100000101001; // 0x829 |
13: polynom = 32'b1000000001100; // 0x100C |
14: polynom = 32'b10000000010101; // 0x2015 |
15: polynom = 32'b110000000000000; // 0x6000 |
16: polynom = 32'b1101000000001000; // 0xD008 |
17: polynom = 32'b10010000000000000; // 0x12000 |
18: polynom = 32'b100000010000000000; // 0x20400 |
19: polynom = 32'b1000000000000100011; // 0x40023 |
20: polynom = 32'b10000010000000000000; // 0x82000 |
21: polynom = 32'b101000000000000000000; // 0x140000 |
22: polynom = 32'b1100000000000000000000; // 0x300000 |
23: polynom = 32'b10000100000000000000000; // 0x420000 |
24: polynom = 32'b111000010000000000000000; // 0xE10000 |
25: polynom = 32'b1001000000000000000000000; // 0x1200000 |
26: polynom = 32'b10000000000000000000100011; // 0x2000023 |
27: polynom = 32'b100000000000000000000010011; // 0x4000013 |
28: polynom = 32'b1100100000000000000000000000; // 0xC800000 |
29: polynom = 32'b10100000000000000000000000000; // 0x14000000 |
30: polynom = 32'b100000000000000000000000101001; // 0x20000029 |
31: polynom = 32'b1001000000000000000000000000000; // 0x48000000 |
32: polynom = 32'b10000000001000000000000000000011; // 0x80200003 |
default: polynom = 32'b0; |
endcase |
lfsr_fb = qi[length]; |
for (i=length-1; i>=1; i=i-1) begin |
if (polynom[i]) |
lfsr_fb = lfsr_fb ~^ qi[i]; |
end |
end"; |
echo PHP_EOL; |
} |
|
if ($inputs['rew']!=1) { echo " assign q_next = "; } else { echo " assign q_next_fw = "; } |
if ($inputs['clear']==1) { echo " clear ? {length{1'b0}} :";} |
if ($inputs['set']==1) { echo " set ? set_value :";} |
if ($wrap['wrap']==1) { echo "(qi == wrap_value) ? {length{1'b0}} :";} |
if ($counter['type']=="LFSR") { echo "{qi[length-1:1],lfsr_fb};"; } else { echo "qi + length'd1;"; } |
echo PHP_EOL; |
|
if ($inputs['rew']) { |
if ($counter['type']=="LFSR") { |
echo " always @ (qi)" . PHP_EOL; |
echo " begin |
case (length) |
2: polynom_rew = 32'b11; |
3: polynom_rew = 32'b110; |
4: polynom_rew = 32'b1100; |
5: polynom_rew = 32'b10100; |
6: polynom_rew = 32'b110000; |
7: polynom_rew = 32'b1100000; |
8: polynom_rew = 32'b10111000; |
9: polynom_rew = 32'b100010000; |
10: polynom_rew = 32'b1001000000; |
11: polynom_rew = 32'b10100000000; |
12: polynom_rew = 32'b100000101001; |
13: polynom_rew = 32'b1000000001100; |
14: polynom_rew = 32'b10000000010101; |
15: polynom_rew = 32'b110000000000000; |
16: polynom_rew = 32'b1101000000001000; |
17: polynom_rew = 32'b10010000000000000; |
18: polynom_rew = 32'b100000010000000000; |
19: polynom_rew = 32'b1000000000000100011; |
20: polynom_rew = 32'b10000010000000000000; |
21: polynom_rew = 32'b101000000000000000000; |
22: polynom_rew = 32'b1100000000000000000000; |
23: polynom_rew = 32'b10000100000000000000000; |
24: polynom_rew = 32'b111000010000000000000000; |
25: polynom_rew = 32'b1001000000000000000000000; |
26: polynom_rew = 32'b10000000000000000000100011; |
27: polynom_rew = 32'b100000000000000000000010011; |
28: polynom_rew = 32'b1100100000000000000000000000; |
29: polynom_rew = 32'b10100000000000000000000000000; |
30: polynom_rew = 32'b100000000000000000000000101001; |
31: polynom_rew = 32'b1001000000000000000000000000000; |
32: polynom_rew = 32'b10000000001000000000000000000011; |
default: polynom_rew = 32'b0; |
endcase |
// rotate left |
polynom_rew[length:1] = { polynom_rew[length-2:1],polynom_rew[length] }; |
lfsr_fb_rew = qi[length]; |
for (i=length-1; i>=1; i=i-1) begin |
if (polynom_rew[i]) |
lfsr_fb_rew = lfsr_fb_rew ~^ qi[i]; |
end |
end"; |
echo PHP_EOL; |
|
} |
echo " assign q_next_rew = "; |
if ($inputs['clear']==1) { echo " clear ? clear_value :";} |
if ($inputs['set']==1) { echo " set ? set_value :";} |
if ($wrap['wrap']==1) { echo "(qi == wrap_value) ? {length{1'b0}} :";} |
if ($counter['type']=="LFSR") { echo "{lfsr_fb_rew,qi[length:2]};"; } else { echo "qi - length'd1;"; } |
echo PHP_EOL; |
echo " assign q_next = rew ? q_next_rew : q_next_fw;" . PHP_EOL; |
} |
|
echo " |
always @ (posedge clk or posedge rst) |
if (rst) |
qi <= {length{1'b0}}; |
else" . PHP_EOL; |
if ($inputs['cke']) { echo " if (cke)" . PHP_EOL;} |
echo " qi <= q_next;" . PHP_EOL; |
echo PHP_EOL; |
|
if ($outputs['q']) { |
if ($counter['type'] == "GRAY" or $counter['type'] == "gray") { |
echo "always @ (posedge clk or posedge rst) |
if (rst) |
q <= ; |
else"; |
if ($inputs['cke']) { echo " if (cke)" . PHP_EOL; } |
} else { |
echo " assign q = qi;" . PHP_EOL; |
} |
} |
echo PHP_EOL; |
|
if ($outputs['z']) { echo " assign z = (q == {length{1'b0}});" . PHP_EOL; } |
|
if ($outputs['zq']) { |
echo " |
always @ (posedge clk or posedge rst) |
if (rst) |
zq <= 1'b1; |
else" . PHP_EOL; |
if ($inputs['cke']) { echo " if (cke)" . PHP_EOL; } |
echo " zq <= q_next == {length{1'b0}};" . PHP_EOL; |
} |
|
if ($outputs['level1']) { |
echo " |
always @ (posedge clk or posedge rst) |
if (rst) |
level1 <= 1'b0; |
else" . PHP_EOL; |
if ($inputs['cke']) { echo " if (cke)" . PHP_EOL; } |
echo " if (q_next == level1_value) |
level1 <= 1'b1; |
else if (q == level1_value & rew) |
level1 <= 1'b0;" . PHP_EOL; |
} |
|
if ($outputs['level2']) { |
echo " |
always @ (posedge clk or posedge rst) |
if (rst) |
level2 <= 1'b0; |
else" . PHP_EOL; |
if ($inputs['cke']) { echo " if (cke)" . PHP_EOL; } |
echo " if (q_next == level2_value) |
level2 <= 1'b1; |
else if (q == level2_value & rew) |
level2 <= 1'b0;" . PHP_EOL; |
} |
|
echo "endmodule" . PHP_EOL; |
trunk/rtl/verilog/versatile_counter_generator.php
Property changes :
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: trunk/rtl/verilog/Makefile
===================================================================
--- trunk/rtl/verilog/Makefile (revision 19)
+++ trunk/rtl/verilog/Makefile (revision 20)
@@ -1,3 +1,3 @@
all:
- vpp versatile_counter.v > tmp1.v
- vppreproc --simple tmp1.v | cat copyright.v - > counter.v
+ excel2csv vc.xls -S ,
+ ./versatile_counter_generator.php Versatile_counter.csv > vc.v
Index: trunk/rtl/verilog/vc.xls
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Index: trunk/rtl/verilog/vc.xls
===================================================================
--- trunk/rtl/verilog/vc.xls (nonexistent)
+++ trunk/rtl/verilog/vc.xls (revision 20)
trunk/rtl/verilog/vc.xls
Property changes :
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: trunk/rtl/verilog/versatile_counter_defines.v
===================================================================
--- trunk/rtl/verilog/versatile_counter_defines.v (revision 19)
+++ trunk/rtl/verilog/versatile_counter_defines.v (revision 20)
@@ -18,7 +18,7 @@
`define CNT_LENGTH 4
// async reset value
-`define CNT_RESET_VALUE `CNT_LENGTH'h0
+`define CNT_RESET_VALUE 0
// clear
`define CNT_CLEAR
@@ -25,11 +25,11 @@
// set
`define CNT_SET
-`define CNT_SET_VALUE `CNT_LENGTH'h9
+`define CNT_SET_VALUE 9
// wrap around creates shorter cycle than maximum length
//`define CNT_WRAP
-`define CNT_WRAP_VALUE `CNT_LENGTH'h9
+`define CNT_WRAP_VALUE 9
// clock enable
`define CNT_CE
@@ -43,3 +43,10 @@
// q_next=0 as a registered output
//`define CNT_ZQ
+// level indicator 1
+`define CNT_LEVEL1
+`define CNT_LEVEL1_VALUE 1
+
+// level indicator 2
+`define CNT_LEVEL2
+`define CNT_LEVEL2_VALUE 2
/trunk/doc/versatile_counter.pdf
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
/trunk/doc/src/versatile_counter.odt
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
/trunk/doc/src/block.dia
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
/trunk/doc/src/block.png
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
/trunk/sim/rtl_sim/bin/wave.do
1,29 → 1,29
onerror {resume} |
quietly WaveActivateNextPane {} 0 |
add wave -noupdate -format Literal /lfsr_tb/DUT/set_value |
#add wave -noupdate -format Literal /lfsr_tb/DUT/wrap_value |
add wave -noupdate -format Literal /lfsr_tb/DUT/q |
add wave -noupdate -format Logic /lfsr_tb/DUT/clear |
add wave -noupdate -format Logic /lfsr_tb/DUT/set |
add wave -noupdate -format Logic /lfsr_tb/DUT/cke |
add wave -noupdate -format Logic /lfsr_tb/DUT/clk |
add wave -noupdate -format Logic /lfsr_tb/DUT/rst |
add wave -noupdate -format Literal /lfsr_tb/DUT/qi |
add wave -noupdate -format Literal /lfsr_tb/DUT/q_next |
TreeUpdate [SetDefaultTree] |
WaveRestoreCursors {{Cursor 1} {1895 ns} 0} {{Cursor 5} {7898 ns} 0} |
configure wave -namecolwidth 210 |
configure wave -valuecolwidth 140 |
configure wave -justifyvalue left |
configure wave -signalnamewidth 0 |
configure wave -snapdistance 10 |
configure wave -datasetprefix 0 |
configure wave -rowmargin 4 |
configure wave -childrowmargin 2 |
configure wave -gridoffset 0 |
configure wave -gridperiod 1 |
configure wave -griddelta 40 |
configure wave -timeline 0 |
configure wave -timelineunits ps |
update |
WaveRestoreZoom {0 ns} {10500 ns} |
onerror {resume} |
quietly WaveActivateNextPane {} 0 |
add wave -noupdate -format Logic /lfsr_tb/DUT/clear |
add wave -noupdate -format Logic /lfsr_tb/DUT/set |
add wave -noupdate -format Logic /lfsr_tb/DUT/cke |
add wave -noupdate -format Literal /lfsr_tb/DUT/q |
add wave -noupdate -format Logic /lfsr_tb/DUT/rst |
add wave -noupdate -format Logic /lfsr_tb/DUT/clk |
add wave -noupdate -format Literal /lfsr_tb/DUT/qi |
add wave -noupdate -format Logic /lfsr_tb/DUT/lfsr_fb |
add wave -noupdate -format Logic /lfsr_tb/DUT/q_next |
add wave -noupdate -format Logic /lfsr_tb/DUT/rew |
TreeUpdate [SetDefaultTree] |
WaveRestoreCursors {{Cursor 1} {1005 ns} 0} |
configure wave -namecolwidth 150 |
configure wave -valuecolwidth 100 |
configure wave -justifyvalue left |
configure wave -signalnamewidth 0 |
configure wave -snapdistance 10 |
configure wave -datasetprefix 0 |
configure wave -rowmargin 4 |
configure wave -childrowmargin 2 |
configure wave -gridoffset 0 |
configure wave -gridperiod 1 |
configure wave -griddelta 40 |
configure wave -timeline 0 |
configure wave -timelineunits ns |
update |
WaveRestoreZoom {862 ns} {1552 ns} |
/trunk/sw/VersatileCounter.php
0,0 → 1,16
#!/usr/bin/php |
<?php |
|
include (dirname(__FILE__) . '/VersatileCounter.class.php'); |
|
if(isset($argv[1]) and !isset(VersatileCounter::$masks[$argv[1]])) { |
echo "Error: Bitmask not found" . PHP_EOL; |
die(1); |
} |
|
$c = new VersatileCounter(isset($argv[1])?$argv[1]:8); |
$c->run(isset($argv[2])?$argv[2]:2,isset($argv[3])); |
|
if(!isset($argv[3])) { |
echo $c->state() . PHP_EOL; |
} |
trunk/sw/VersatileCounter.php
Property changes :
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: trunk/sw/VersatileCounter.class.php
===================================================================
--- trunk/sw/VersatileCounter.class.php (nonexistent)
+++ trunk/sw/VersatileCounter.class.php (revision 20)
@@ -0,0 +1,100 @@
+ 0x3,
+ 3 => 0x6,
+ 4 => 0xC,
+ 5 => 0x14,
+ 6 => 0x30,
+ 7 => 0x60,
+ 8 => 0xB8,
+ 9 => 0x110,
+ 10 => 0x240,
+ 11 => 0x500,
+ 12 => 0x829,
+ 13 => 0x100C,
+ 14 => 0x2015,
+ 15 => 0x6000,
+ 16 => 0xD008,
+ 17 => 0x12000,
+ 18 => 0x20400,
+ 19 => 0x40023,
+ 20 => 0x82000,
+ 21 => 0x140000,
+ 22 => 0x300000,
+ 23 => 0x420000,
+ 24 => 0xE10000,
+ 25 => 0x1200000,
+ 26 => 0x2000023,
+ 27 => 0x4000013,
+ 28 => 0xC800000,
+ 29 => 0x14000000,
+ 30 => 0x20000029,
+ 31 => 0x48000000,
+ 32 => 0x80200003
+
+ );
+
+ private $length, $mask;
+
+ private $state = 0;
+
+ function __construct($length = 8) {
+ $this->length = $length;
+ $this->mask = self::$masks[$length];
+ }
+
+ function state() {
+ return sprintf("%0" . $this->length . "b",$this->state);
+ }
+
+ function tick() {
+
+ $ns = ($this->state * 2) & (pow(2,$this->length) - 1);
+
+ $new = $this->state & pow(2,$this->length - 1);
+
+ for($i = $this->length - 2;$i >= 0;$i--) {
+
+ if($this->mask & pow(2,$i)) {
+ $new = (int) ($new xor ($this->state & pow(2,$i)));
+ }
+
+ }
+
+ if($new == 0) {
+ $ns++;
+ }
+
+ $this->state = $ns;
+
+ }
+
+ function run($ticks,$output = false) {
+
+ if($output) {
+ printf("%" . strlen($ticks) . "u: %0" . $this->length . "b\n",0,$this->state);
+ }
+
+ for($i=0;$i<$ticks;$i++) {
+ $this->tick();
+ if($output) {
+ printf("%" . strlen($ticks) . "u: %0" . $this->length . "b\n",$i+1,$this->state);
+ }
+ }
+
+ }
+
+ static function GetState($length,$ticks) {
+
+ $VC = new self($length);
+ $VC->run($ticks);
+
+ return $VC->state;
+
+ }
+
+}
Index: trunk/sw/VersatileCounter.kpf
===================================================================
--- trunk/sw/VersatileCounter.kpf (nonexistent)
+++ trunk/sw/VersatileCounter.kpf (revision 20)
@@ -0,0 +1,7 @@
+
+
+
+
+ 1
+
+