1 |
2 |
rud_dp |
///*************************************************************///
|
2 |
|
|
/// ///
|
3 |
|
|
/// Reed-Solomon Decoder (31,19,6) ///
|
4 |
|
|
/// ///
|
5 |
|
|
/// ///
|
6 |
|
|
/// Author : Rudy Dwi Putra ///
|
7 |
|
|
/// rudy.dp@gmail.com ///
|
8 |
|
|
/// ///
|
9 |
|
|
///*************************************************************///
|
10 |
|
|
/// ///
|
11 |
|
|
/// Copyright (C) 2006 Rudy Dwi Putra ///
|
12 |
|
|
/// rudy.dp@gmail.com ///
|
13 |
|
|
/// ///
|
14 |
|
|
/// This source file may be used and distributed without ///
|
15 |
|
|
/// restriction provided that this copyright statement is not ///
|
16 |
|
|
/// removed from the file and that any derivative work contains ///
|
17 |
|
|
/// the original copyright notice and the associated disclaimer.///
|
18 |
|
|
/// ///
|
19 |
|
|
/// THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY ///
|
20 |
|
|
/// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED ///
|
21 |
|
|
/// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS ///
|
22 |
|
|
/// FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL THE AUTHOR ///
|
23 |
|
|
/// OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, ///
|
24 |
|
|
/// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES ///
|
25 |
|
|
/// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE ///
|
26 |
|
|
/// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR ///
|
27 |
|
|
/// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF ///
|
28 |
|
|
/// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT ///
|
29 |
|
|
/// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT ///
|
30 |
|
|
/// OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE ///
|
31 |
|
|
/// POSSIBILITY OF SUCH DAMAGE. ///
|
32 |
|
|
/// ///
|
33 |
|
|
///*************************************************************///
|
34 |
|
|
|
35 |
|
|
//***************************************//
|
36 |
|
|
// Testbench for RS Decoder (31, 19, 6) //
|
37 |
|
|
//***************************************//
|
38 |
|
|
|
39 |
|
|
module testbench_rsdecoder;
|
40 |
|
|
|
41 |
|
|
reg [4:0] recword;
|
42 |
|
|
reg clock1, clock2;
|
43 |
|
|
reg start, reset;
|
44 |
|
|
|
45 |
|
|
//******************************************************//
|
46 |
|
|
// ready = if set to 1, decoder is ready to input or it //
|
47 |
|
|
// is inputting new data //
|
48 |
|
|
// dataoutstart = flag the first symbol of outputted //
|
49 |
|
|
// received word. //
|
50 |
|
|
// dataoutend = flag the last symbol of outputted //
|
51 |
|
|
// received word. //
|
52 |
|
|
// errfound = set to 1, if one of syndrome values //
|
53 |
|
|
// is not zero. //
|
54 |
|
|
// decode_fail = set to 1, if decoder fails to correct //
|
55 |
|
|
// the received word. //
|
56 |
|
|
//******************************************************//
|
57 |
|
|
wire ready, decode_fail, errfound, dataoutstart, dataoutend;
|
58 |
|
|
wire [4:0] corr_recword;
|
59 |
|
|
|
60 |
|
|
parameter [5:0] clk_period = 50;
|
61 |
|
|
|
62 |
|
|
initial
|
63 |
|
|
begin
|
64 |
|
|
recword = 5'b0;
|
65 |
|
|
start = 0;
|
66 |
|
|
reset = 0;
|
67 |
|
|
end
|
68 |
|
|
|
69 |
|
|
//**********//
|
70 |
|
|
// clock1 //
|
71 |
|
|
//**********//
|
72 |
|
|
initial
|
73 |
|
|
begin
|
74 |
|
|
clock1 = 0;
|
75 |
|
|
forever #(clk_period/2) clock1 = ~clock1;
|
76 |
|
|
end
|
77 |
|
|
|
78 |
|
|
//**********//
|
79 |
|
|
// clock2 //
|
80 |
|
|
//**********//
|
81 |
|
|
initial
|
82 |
|
|
begin
|
83 |
|
|
clock2 = 1;
|
84 |
|
|
forever #(clk_period/2) clock2 = ~clock2;
|
85 |
|
|
end
|
86 |
|
|
|
87 |
|
|
//***********************************************//
|
88 |
|
|
// This section defines feeding of received word //
|
89 |
|
|
// and start signal. Start signal is active 1 //
|
90 |
|
|
// clock cycle before first symbol of received //
|
91 |
|
|
// word. All input and output synchronize with //
|
92 |
|
|
// clock2. First received word contains no error //
|
93 |
|
|
// symbol. Thus, all syndrome values will be zero//
|
94 |
|
|
// and decoder will pass the received word. //
|
95 |
|
|
// Second received word contains 6 error symbol. //
|
96 |
|
|
// Decoder will determine its error locator //
|
97 |
|
|
// and error evaluator polynomial in KES block. //
|
98 |
|
|
// Then, it calculates error values in CSEE //
|
99 |
|
|
// block. Third received word contains 8 error //
|
100 |
|
|
// symbol. Decoder can't correct the error and //
|
101 |
|
|
// at the end of outputted received word, it will//
|
102 |
|
|
// set decode_fail to 1. //
|
103 |
|
|
//***********************************************//
|
104 |
|
|
initial
|
105 |
|
|
begin
|
106 |
|
|
#(clk_period) reset = 1;
|
107 |
|
|
|
108 |
|
|
//start has to be active 1 clock cycle before first recword,
|
109 |
|
|
//otherwise decoder will output wrong recword.
|
110 |
|
|
#(clk_period) start = 1;
|
111 |
|
|
#(clk_period) start = 0;
|
112 |
|
|
|
113 |
|
|
//First received word contains no error symbol.
|
114 |
|
|
//The decoder should give errfound = 0 at the end
|
115 |
|
|
//of syndrome calculation stage.
|
116 |
|
|
recword = 5'b10100;
|
117 |
|
|
#(clk_period) recword = 5'b00100;
|
118 |
|
|
#(clk_period) recword = 5'b00101;
|
119 |
|
|
#(clk_period) recword = 5'b10001;
|
120 |
|
|
#(clk_period) recword = 5'b10110;
|
121 |
|
|
#(clk_period) recword = 5'b00001;
|
122 |
|
|
#(clk_period) recword = 5'b00010;
|
123 |
|
|
#(clk_period) recword = 5'b11100;
|
124 |
|
|
#(clk_period) recword = 5'b00011;
|
125 |
|
|
#(clk_period) recword = 5'b10001;
|
126 |
|
|
#(clk_period) recword = 5'b00110;
|
127 |
|
|
#(clk_period) recword = 5'b00111;
|
128 |
|
|
#(clk_period) recword = 5'b01010;
|
129 |
|
|
#(clk_period) recword = 5'b11111;
|
130 |
|
|
#(clk_period) recword = 5'b01011;
|
131 |
|
|
#(clk_period) recword = 5'b10100;
|
132 |
|
|
#(clk_period) recword = 5'b00100;
|
133 |
|
|
#(clk_period) recword = 5'b00101;
|
134 |
|
|
#(clk_period) recword = 5'b00001;
|
135 |
|
|
#(clk_period) recword = 5'b10111;
|
136 |
|
|
#(clk_period) recword = 5'b10100;
|
137 |
|
|
#(clk_period) recword = 5'b00010;
|
138 |
|
|
#(clk_period) recword = 5'b10110;
|
139 |
|
|
#(clk_period) recword = 5'b00100;
|
140 |
|
|
#(clk_period) recword = 5'b01011;
|
141 |
|
|
#(clk_period) recword = 5'b00110;
|
142 |
|
|
#(clk_period) recword = 5'b11110;
|
143 |
|
|
#(clk_period) recword = 5'b10100;
|
144 |
|
|
#(clk_period) recword = 5'b11111;
|
145 |
|
|
#(clk_period) recword = 5'b01010;
|
146 |
|
|
#(clk_period) recword = 5'b11110;
|
147 |
|
|
#(clk_period) recword = 5'b0;
|
148 |
|
|
|
149 |
|
|
|
150 |
|
|
#(18*clk_period) start = 1;
|
151 |
|
|
#(clk_period) start = 0;
|
152 |
|
|
|
153 |
|
|
//Second received word contains 6 error symbols.
|
154 |
|
|
//The decoder sets errfound = 1, and activates
|
155 |
|
|
//KES block and then CSEE block. Because the
|
156 |
|
|
//number of errors is equal to correction capability
|
157 |
|
|
//of the decoder, decoder can correct the received
|
158 |
|
|
//word.
|
159 |
|
|
recword = 5'b01100; //it should be 5'b10100
|
160 |
|
|
#(clk_period) recword = 5'b00100;
|
161 |
|
|
#(clk_period) recword = 5'b00101;
|
162 |
|
|
#(clk_period) recword = 5'b10001;
|
163 |
|
|
#(clk_period) recword = 5'b10110;
|
164 |
|
|
#(clk_period) recword = 5'b00001;
|
165 |
|
|
#(clk_period) recword = 5'b00110; //it should be 5'b00010
|
166 |
|
|
#(clk_period) recword = 5'b11100;
|
167 |
|
|
#(clk_period) recword = 5'b00011;
|
168 |
|
|
#(clk_period) recword = 5'b10001;
|
169 |
|
|
#(clk_period) recword = 5'b00110;
|
170 |
|
|
#(clk_period) recword = 5'b00101; //it should be 5'b00111
|
171 |
|
|
#(clk_period) recword = 5'b01010;
|
172 |
|
|
#(clk_period) recword = 5'b11111;
|
173 |
|
|
#(clk_period) recword = 5'b11111; //it should be 5'b01011
|
174 |
|
|
#(clk_period) recword = 5'b10100;
|
175 |
|
|
#(clk_period) recword = 5'b00100;
|
176 |
|
|
#(clk_period) recword = 5'b00101;
|
177 |
|
|
#(clk_period) recword = 5'b00001;
|
178 |
|
|
#(clk_period) recword = 5'b10111;
|
179 |
|
|
#(clk_period) recword = 5'b01101; //it should be 5'b10100
|
180 |
|
|
#(clk_period) recword = 5'b00010;
|
181 |
|
|
#(clk_period) recword = 5'b10110;
|
182 |
|
|
#(clk_period) recword = 5'b00100;
|
183 |
|
|
#(clk_period) recword = 5'b01011;
|
184 |
|
|
#(clk_period) recword = 5'b00110;
|
185 |
|
|
#(clk_period) recword = 5'b11110;
|
186 |
|
|
#(clk_period) recword = 5'b10100;
|
187 |
|
|
#(clk_period) recword = 5'b10101; //it should be 5'b11111
|
188 |
|
|
#(clk_period) recword = 5'b01010;
|
189 |
|
|
#(clk_period) recword = 5'b11110;
|
190 |
|
|
#(clk_period) recword = 5'b0;
|
191 |
|
|
|
192 |
|
|
#(20*clk_period) start = 1;
|
193 |
|
|
#(clk_period) start = 0;
|
194 |
|
|
//Third received word contains 8 error symbols.
|
195 |
|
|
//Because the number of errors is greater than correction
|
196 |
|
|
//capability, decoder will resume decoding failure at the end of
|
197 |
|
|
//outputted received word.
|
198 |
|
|
recword = 5'b10100;
|
199 |
|
|
#(clk_period) recword = 5'b00100;
|
200 |
|
|
#(clk_period) recword = 5'b00101;
|
201 |
|
|
#(clk_period) recword = 5'b10001;
|
202 |
|
|
#(clk_period) recword = 5'b10110;
|
203 |
|
|
#(clk_period) recword = 5'b00100; //it should be 5'b00001
|
204 |
|
|
#(clk_period) recword = 5'b00010;
|
205 |
|
|
#(clk_period) recword = 5'b11100;
|
206 |
|
|
#(clk_period) recword = 5'b10010; //it should be 5'b00011
|
207 |
|
|
#(clk_period) recword = 5'b10101; //it should be 5'b10001
|
208 |
|
|
#(clk_period) recword = 5'b00110;
|
209 |
|
|
#(clk_period) recword = 5'b10011; //it should be 5'b00111
|
210 |
|
|
#(clk_period) recword = 5'b01010;
|
211 |
|
|
#(clk_period) recword = 5'b11111;
|
212 |
|
|
#(clk_period) recword = 5'b01011;
|
213 |
|
|
#(clk_period) recword = 5'b10100;
|
214 |
|
|
#(clk_period) recword = 5'b00110; //it should be 5'b00100
|
215 |
|
|
#(clk_period) recword = 5'b00101;
|
216 |
|
|
#(clk_period) recword = 5'b00100; //it should be 5'b00001
|
217 |
|
|
#(clk_period) recword = 5'b10110; //it should be 5'b10111
|
218 |
|
|
#(clk_period) recword = 5'b10100;
|
219 |
|
|
#(clk_period) recword = 5'b00010;
|
220 |
|
|
#(clk_period) recword = 5'b10110;
|
221 |
|
|
#(clk_period) recword = 5'b00100;
|
222 |
|
|
#(clk_period) recword = 5'b01011;
|
223 |
|
|
#(clk_period) recword = 5'b00110;
|
224 |
|
|
#(clk_period) recword = 5'b11110;
|
225 |
|
|
#(clk_period) recword = 5'b10010; //it should be 5'b10100
|
226 |
|
|
#(clk_period) recword = 5'b11111;
|
227 |
|
|
#(clk_period) recword = 5'b01010;
|
228 |
|
|
#(clk_period) recword = 5'b11110;
|
229 |
|
|
#(clk_period) recword = 5'b0;
|
230 |
|
|
end
|
231 |
|
|
|
232 |
|
|
|
233 |
|
|
RSDecoder rsdecoder(recword, start, clock1, clock2, reset, ready,
|
234 |
|
|
errfound, decode_fail, dataoutstart, dataoutend,
|
235 |
|
|
corr_recword);
|
236 |
|
|
|
237 |
|
|
endmodule
|