1 | |
---|
2 | //******************************************************************************** |
---|
3 | // File: decoder_system.v |
---|
4 | // Author: Yang Sun (ysun@rice.edu) |
---|
5 | // Birth: $ 11/25/07 |
---|
6 | // Des: decoder system |
---|
7 | // History: $ 11/25/07, Uncoded decoder |
---|
8 | // $ 12/1/07, Added Viterbi decoder (VBD) |
---|
9 | // $ 09/27/08: Added dec-puncture |
---|
10 | //******************************************************************************** |
---|
11 | module decoder_system ( |
---|
12 | clk , // I, clock |
---|
13 | nrst , // I, n reset |
---|
14 | start , // I, start pulse |
---|
15 | in_dec , |
---|
16 | coding_en , |
---|
17 | zero_tail , |
---|
18 | sym_start , // I, sym start |
---|
19 | hdr_mod_level , // I, header modulation level |
---|
20 | vin , // I, data valid input |
---|
21 | llr_a , // I, LLR bit a |
---|
22 | llr_b , // I, LLR bit b |
---|
23 | llr_buf_empty , // I, LLR buffer empty |
---|
24 | unc_buf_rd , // O, LLR buffer read by unc |
---|
25 | vout , // O, data valid output |
---|
26 | dout , // O, byte data output |
---|
27 | nbyte , // O, num of bytes |
---|
28 | byte_cnt , // O, byte cnt |
---|
29 | cc_rate , // O, code rate |
---|
30 | data_coded , // O, coded system |
---|
31 | in_fullrate // O, in full rate |
---|
32 | ) ; |
---|
33 | |
---|
34 | input clk ; |
---|
35 | input start ; |
---|
36 | input in_dec ; |
---|
37 | input coding_en ; |
---|
38 | input zero_tail ; |
---|
39 | input sym_start ; |
---|
40 | input [3:0] hdr_mod_level ; |
---|
41 | input nrst ; |
---|
42 | input vin ; |
---|
43 | input [3:0] llr_a ; |
---|
44 | input [3:0] llr_b ; |
---|
45 | input llr_buf_empty ; |
---|
46 | |
---|
47 | output unc_buf_rd ; |
---|
48 | output vout ; |
---|
49 | output [7:0] dout ; |
---|
50 | |
---|
51 | output [13:0] nbyte ; |
---|
52 | output reg [13:0] byte_cnt ; |
---|
53 | output [1:0] cc_rate ; |
---|
54 | output data_coded ; |
---|
55 | output in_fullrate ; |
---|
56 | |
---|
57 | //============================== |
---|
58 | //Internal signal |
---|
59 | //============================== |
---|
60 | wire hd_a ; |
---|
61 | wire hd_b ; |
---|
62 | wire unc_vout ; |
---|
63 | wire [7:0] unc_byte_out ; |
---|
64 | wire unc_vin ; |
---|
65 | |
---|
66 | wire ld_mod_type ; |
---|
67 | wire ld_payload_lsb ; |
---|
68 | wire ld_payload_msb ; |
---|
69 | reg ld_payload ; |
---|
70 | wire ld_rate ; |
---|
71 | reg update_mod_type ; |
---|
72 | |
---|
73 | wire [13:0] num_payload_i ; |
---|
74 | reg [13:0] num_payload ; |
---|
75 | reg [7:0] num_payload_low ; |
---|
76 | reg [7:0] num_payload_high ; |
---|
77 | |
---|
78 | reg [16:0] bit_cnt ; |
---|
79 | wire input_done ; |
---|
80 | reg input_done_s0 ; |
---|
81 | wire pkt_end ; |
---|
82 | |
---|
83 | wire [3:0] vb_b1 ; |
---|
84 | wire [3:0] vb_b0 ; |
---|
85 | wire vb_vin ; |
---|
86 | wire vb_vout ; |
---|
87 | wire [7:0] vb_dout ; |
---|
88 | wire vb_done ; |
---|
89 | |
---|
90 | wire [7:0] dec_byte ; |
---|
91 | wire dec_val ; |
---|
92 | |
---|
93 | wire [4:0] descramb_addr ; |
---|
94 | wire [7:0] descramb_data ; |
---|
95 | |
---|
96 | reg [3:0] mod_type_i ; |
---|
97 | wire [13:0] input_byte_cnt ; |
---|
98 | |
---|
99 | reg [3:0] sym_cnt ; |
---|
100 | |
---|
101 | wire vb_start ; |
---|
102 | wire vb_end ; |
---|
103 | |
---|
104 | reg [1:0] cc_rate_i ; |
---|
105 | reg in_baserate ; |
---|
106 | reg data_coded_i ; |
---|
107 | wire dout_sel ; |
---|
108 | |
---|
109 | //============================== |
---|
110 | // Main body of code |
---|
111 | //============================== |
---|
112 | assign nbyte = num_payload ; |
---|
113 | assign vout = dec_val ; |
---|
114 | assign dout = dec_byte ; |
---|
115 | |
---|
116 | assign data_coded = data_coded_i ; |
---|
117 | |
---|
118 | assign hd_a = llr_a [3] ; |
---|
119 | assign hd_b = llr_b [3] ; |
---|
120 | |
---|
121 | always @ (posedge clk or negedge nrst) |
---|
122 | if (~nrst) |
---|
123 | sym_cnt <= 0 ; |
---|
124 | else if (start) |
---|
125 | sym_cnt <= 0 ; |
---|
126 | else if (sym_start) |
---|
127 | sym_cnt <= (sym_cnt == 9 ? sym_cnt : sym_cnt +1) ; |
---|
128 | |
---|
129 | //?? assign unc_vin = in_fullrate & ~llr_buf_empty & ~data_coded ; |
---|
130 | |
---|
131 | assign unc_vin = coding_en ? (in_fullrate & ~llr_buf_empty & ~data_coded) : (in_dec & ~llr_buf_empty) ; |
---|
132 | assign unc_buf_rd = coding_en ? (unc_vin & ~data_coded) : unc_vin ; |
---|
133 | //===================================== |
---|
134 | // uncodede decoder |
---|
135 | //===================================== |
---|
136 | unc_decoder unc_decoder ( |
---|
137 | .clk (clk ), // clock |
---|
138 | .nrst (nrst ), // n reset |
---|
139 | .hd_a (hd_a ), // hard decision of I |
---|
140 | .hd_b (hd_b ), // hard decision of Q |
---|
141 | .start (start ), // start decoding pulse |
---|
142 | .vin (unc_vin ), // valid input |
---|
143 | .vout (unc_vout ), // valid output |
---|
144 | .dout (unc_byte_out ) // byte out |
---|
145 | ) ; |
---|
146 | |
---|
147 | always @ (posedge clk or negedge nrst) |
---|
148 | if (~nrst) |
---|
149 | bit_cnt <= 0 ; |
---|
150 | else if (start) |
---|
151 | bit_cnt <= 0 ; |
---|
152 | else if (vin) |
---|
153 | bit_cnt <= bit_cnt +2 ; |
---|
154 | |
---|
155 | assign input_byte_cnt = bit_cnt [16:3] ; |
---|
156 | assign input_done = (bit_cnt [16:4] == (data_coded_i ? num_payload : 24)) ; |
---|
157 | always @ (posedge clk) |
---|
158 | input_done_s0 <= input_done ; |
---|
159 | assign pkt_end = input_done & ~input_done_s0 ; |
---|
160 | |
---|
161 | assign vb_vin = vin ; |
---|
162 | assign vb_b1 = llr_a ; |
---|
163 | assign vb_b0 = llr_b ; |
---|
164 | |
---|
165 | //====================================================== |
---|
166 | // Viter decoder system |
---|
167 | //====================================================== |
---|
168 | vb_decoder_top vb_decoder_top ( |
---|
169 | .clk (clk ), //I |
---|
170 | .nrst (nrst ), //I |
---|
171 | .packet_start (vb_start ), //I |
---|
172 | .zero_tail (zero_tail ), |
---|
173 | .packet_end (vb_end ), //I |
---|
174 | .vin (vb_vin ), //I |
---|
175 | .llr_b1 (vb_b1 ), //I |
---|
176 | .llr_b0 (vb_b0 ), //I |
---|
177 | .vout (vb_vout ), //O |
---|
178 | .done (vb_done ), //O |
---|
179 | .dout_in_byte (vb_dout ) //O |
---|
180 | ) ; |
---|
181 | |
---|
182 | |
---|
183 | // Select |
---|
184 | assign dout_sel = (in_baserate | data_coded) & coding_en ; |
---|
185 | |
---|
186 | assign dec_byte = dout_sel ? vb_dout : unc_byte_out ; |
---|
187 | assign dec_val = dout_sel ? vb_vout : unc_vout ; |
---|
188 | |
---|
189 | assign descramb_addr = byte_cnt [4:0] ; |
---|
190 | //=================================== |
---|
191 | // de-scrambler |
---|
192 | //=================================== |
---|
193 | scrambler descrambler ( |
---|
194 | .addr (descramb_addr ), // address 32 |
---|
195 | .din (dec_byte ), // byte in |
---|
196 | .dout (descramb_data ) // byte out |
---|
197 | ) ; |
---|
198 | |
---|
199 | always @ (posedge clk or negedge nrst) |
---|
200 | if (~nrst) |
---|
201 | byte_cnt <= 0 ; |
---|
202 | else if (start) |
---|
203 | byte_cnt <= 0 ; |
---|
204 | else if (dec_val) |
---|
205 | byte_cnt <= byte_cnt +1 ; |
---|
206 | |
---|
207 | assign ld_mod_type = dec_val & (byte_cnt == 0) ; |
---|
208 | assign ld_payload_msb = byte_cnt == 2 ; |
---|
209 | assign ld_payload_lsb = byte_cnt == 3 ; |
---|
210 | assign ld_rate = byte_cnt == 1 ; |
---|
211 | |
---|
212 | always @* |
---|
213 | begin |
---|
214 | update_mod_type = 1'b0 ; |
---|
215 | if(sym_start) |
---|
216 | begin |
---|
217 | if(coding_en) |
---|
218 | case(hdr_mod_level) |
---|
219 | 4'd1: update_mod_type = (sym_cnt == 8) ; |
---|
220 | 4'd2: update_mod_type = (sym_cnt == 4) ; |
---|
221 | 4'd4: update_mod_type = (sym_cnt == 2) ; |
---|
222 | endcase |
---|
223 | else |
---|
224 | case(hdr_mod_level) |
---|
225 | 4'd1: update_mod_type = (sym_cnt == 4) ; |
---|
226 | 4'd2: update_mod_type = (sym_cnt == 2) ; |
---|
227 | 4'd4: update_mod_type = (sym_cnt == 1) ; |
---|
228 | endcase |
---|
229 | end |
---|
230 | end |
---|
231 | |
---|
232 | // Header is always not punctured |
---|
233 | assign cc_rate = coding_en ? (in_baserate ? 2'd0 : cc_rate_i) : 2'd0 ; |
---|
234 | |
---|
235 | always @ (posedge clk or negedge nrst) |
---|
236 | if (~nrst) |
---|
237 | begin |
---|
238 | num_payload_low <= 64 ; |
---|
239 | num_payload_high <= 0 ; |
---|
240 | cc_rate_i <= 0 ; |
---|
241 | data_coded_i <= 1'b1 ; |
---|
242 | end |
---|
243 | else if (start) |
---|
244 | begin |
---|
245 | num_payload_low <= 64 ; |
---|
246 | num_payload_high <= 0 ; |
---|
247 | cc_rate_i <= 0 ; |
---|
248 | data_coded_i <= 1'b1 ; |
---|
249 | end |
---|
250 | else if (dec_val) |
---|
251 | begin |
---|
252 | if (ld_payload_lsb) |
---|
253 | num_payload_low <= descramb_data ; |
---|
254 | if (ld_payload_msb) |
---|
255 | num_payload_high <= descramb_data ; |
---|
256 | if (ld_rate) |
---|
257 | begin |
---|
258 | cc_rate_i <= descramb_data[1:0] ; |
---|
259 | data_coded_i <= (descramb_data[1:0] != 2'b11) ; |
---|
260 | end |
---|
261 | end |
---|
262 | |
---|
263 | always @ (posedge clk) |
---|
264 | ld_payload <= ld_payload_lsb ; |
---|
265 | |
---|
266 | assign num_payload_i = {num_payload_high [5:0], num_payload_low} ; |
---|
267 | always @ (posedge clk or negedge nrst) |
---|
268 | if (~nrst) |
---|
269 | num_payload <= 64 ; |
---|
270 | else if (start) |
---|
271 | num_payload <= 64 ; |
---|
272 | else if (ld_payload) |
---|
273 | num_payload <= num_payload_i ; |
---|
274 | |
---|
275 | always @ (posedge clk or negedge nrst) |
---|
276 | if (~nrst) |
---|
277 | mod_type_i <= 2 ; |
---|
278 | else if (start) |
---|
279 | mod_type_i <= 2 ; |
---|
280 | else if (ld_mod_type) |
---|
281 | mod_type_i <= descramb_data [3:0] ; |
---|
282 | |
---|
283 | assign in_fullrate = ~in_baserate ; |
---|
284 | always @ (posedge clk or negedge nrst) |
---|
285 | if (~nrst) |
---|
286 | in_baserate <= 1'b1 ; |
---|
287 | else if (start) |
---|
288 | in_baserate <= 1'b1 ; |
---|
289 | else if (update_mod_type) |
---|
290 | in_baserate <= 1'b0 ; |
---|
291 | |
---|
292 | assign vb_start = start ; |
---|
293 | assign vb_end = pkt_end ; |
---|
294 | |
---|
295 | endmodule |
---|
296 | |
---|
297 | //************************************************************** |
---|
298 | // File: depunc.v |
---|
299 | // Author: Yang Sun (ysun@rice.edu) |
---|
300 | // Created: $ 2/4/07 |
---|
301 | // Des: viterbi decoder system |
---|
302 | // History: $ 02/04/07, Support puncture 2/3, 3/4 |
---|
303 | // $ 09/27/08: updated |
---|
304 | //************************************************************** |
---|
305 | module depunc ( |
---|
306 | clk , |
---|
307 | nrst , |
---|
308 | start , |
---|
309 | dav , // I, data available |
---|
310 | din , |
---|
311 | vout , |
---|
312 | dout_a , |
---|
313 | dout_b , |
---|
314 | buf_rd , |
---|
315 | rate // 0 = 1/2, 1 = 2/3, 2 = 3/4 |
---|
316 | ) ; |
---|
317 | |
---|
318 | parameter SW = 4 ; // soft input precision |
---|
319 | |
---|
320 | input clk ; |
---|
321 | input nrst ; |
---|
322 | input start ; |
---|
323 | input dav ; |
---|
324 | input [SW*2 -1:0] din ; |
---|
325 | input [1:0] rate ; |
---|
326 | output vout ; |
---|
327 | output [SW -1:0] dout_a ; |
---|
328 | output [SW -1:0] dout_b ; |
---|
329 | output buf_rd ; |
---|
330 | |
---|
331 | //================================================= |
---|
332 | //Internal signal |
---|
333 | //================================================= |
---|
334 | reg [1:0] cnt ; |
---|
335 | |
---|
336 | wire rd ; |
---|
337 | wire rd_r12 ; |
---|
338 | wire rd_r34 ; |
---|
339 | wire rd_r23 ; |
---|
340 | wire r23_ext ; |
---|
341 | reg r23_ext_s0 ; |
---|
342 | wire r34_ext ; |
---|
343 | |
---|
344 | reg [SW -1:0] app_i_r34 ; |
---|
345 | reg [SW -1:0] app_q_r34 ; |
---|
346 | reg [SW -1:0] app_i_r23 ; |
---|
347 | reg [SW -1:0] app_q_r23 ; |
---|
348 | wire [SW -1:0] app_i_r12 ; |
---|
349 | wire [SW -1:0] app_q_r12 ; |
---|
350 | wire [SW -1:0] app_i_mux ; |
---|
351 | wire [SW -1:0] app_q_mux ; |
---|
352 | wire app_valid ; |
---|
353 | wire [SW*2 -1:0] iq_data_buf ; |
---|
354 | reg [SW*2 -1:0] iq_data_buf_lat ; |
---|
355 | |
---|
356 | //================================================= |
---|
357 | // Main RTL |
---|
358 | //================================================= |
---|
359 | assign buf_rd = rd ; |
---|
360 | assign dout_a = app_i_mux ; |
---|
361 | assign dout_b = app_q_mux ; |
---|
362 | assign vout = app_valid ; |
---|
363 | |
---|
364 | always @ (posedge clk or negedge nrst) |
---|
365 | if (~nrst) |
---|
366 | cnt <= 0 ; |
---|
367 | else if (start) |
---|
368 | cnt <= 0 ; |
---|
369 | else if (dav) |
---|
370 | begin |
---|
371 | if (rate == 1) |
---|
372 | cnt <= cnt + 1 ; |
---|
373 | else if (rate ==2) |
---|
374 | cnt <= (cnt == 2 ? 0 : cnt +1) ; |
---|
375 | end |
---|
376 | |
---|
377 | // for rate = 1/2 |
---|
378 | assign rd_r12 = dav ; |
---|
379 | |
---|
380 | // for rate = 2/3 |
---|
381 | assign r23_ext = cnt == 3 ; |
---|
382 | always @ (posedge clk) |
---|
383 | r23_ext_s0 <= r23_ext ; |
---|
384 | |
---|
385 | assign r23_ext_p = ~r23_ext_s0 & r23_ext ; |
---|
386 | assign rd_r23 = dav & ~r23_ext ; |
---|
387 | |
---|
388 | // for rate = 3/4 |
---|
389 | assign rd_r34 = dav & (cnt != 2) ; |
---|
390 | assign r34_ext = dav & (cnt == 2) ; |
---|
391 | |
---|
392 | // mux |
---|
393 | assign rd = rate == 0 ? rd_r12 : rate == 1 ? rd_r23 : rd_r34 ; |
---|
394 | |
---|
395 | assign iq_data_buf = din ; |
---|
396 | always @ (posedge clk) |
---|
397 | if (rd) |
---|
398 | iq_data_buf_lat <= iq_data_buf ; |
---|
399 | |
---|
400 | // rate = 2/3 |
---|
401 | always @* |
---|
402 | begin |
---|
403 | app_i_r23 = 0 ; |
---|
404 | app_q_r23 = 0 ; |
---|
405 | case (cnt) |
---|
406 | 0: begin |
---|
407 | app_i_r23 = iq_data_buf [SW*2 -1 : SW] ; |
---|
408 | app_q_r23 = iq_data_buf [SW -1: 0] ; |
---|
409 | end |
---|
410 | 1: begin |
---|
411 | app_i_r23 = iq_data_buf [SW*2 -1 : SW] ; |
---|
412 | app_q_r23 = 0 ; |
---|
413 | end |
---|
414 | 2: begin |
---|
415 | app_i_r23 = iq_data_buf_lat [SW -1: 0] ; |
---|
416 | app_q_r23 = iq_data_buf [SW*2 -1 : SW] ; |
---|
417 | end |
---|
418 | 3: begin |
---|
419 | app_i_r23 = iq_data_buf_lat [SW -1: 0] ; |
---|
420 | app_q_r23 = 0 ; |
---|
421 | end |
---|
422 | endcase |
---|
423 | end |
---|
424 | |
---|
425 | // rate = 3/4 |
---|
426 | always @* |
---|
427 | begin |
---|
428 | app_i_r34 = 0 ; |
---|
429 | app_q_r34 = 0 ; |
---|
430 | case (cnt) |
---|
431 | 0: begin |
---|
432 | app_i_r34 = iq_data_buf [SW*2 -1 : SW] ; |
---|
433 | app_q_r34 = iq_data_buf [SW -1: 0] ; |
---|
434 | end |
---|
435 | 1: begin |
---|
436 | app_i_r34 = iq_data_buf [SW*2 -1 : SW] ; |
---|
437 | app_q_r34 = 0 ; |
---|
438 | end |
---|
439 | 2: begin |
---|
440 | app_i_r34 = 0 ; |
---|
441 | app_q_r34 = iq_data_buf_lat [SW -1: 0] ; |
---|
442 | end |
---|
443 | default: begin |
---|
444 | app_i_r34 = 0 ; |
---|
445 | app_q_r34 = 0 ; |
---|
446 | end |
---|
447 | endcase |
---|
448 | end |
---|
449 | |
---|
450 | // rate = 1/2 |
---|
451 | assign app_i_r12 = iq_data_buf [SW*2 -1 : SW] ; |
---|
452 | assign app_q_r12 = iq_data_buf [SW -1: 0] ; |
---|
453 | |
---|
454 | assign app_i_mux = rate == 0 ? app_i_r12 : rate == 1 ? app_i_r23 : app_i_r34 ; |
---|
455 | assign app_q_mux = rate == 0 ? app_q_r12 : rate == 1 ? app_q_r23 : app_q_r34 ; |
---|
456 | |
---|
457 | assign app_valid = rate == 0 ? rd_r12 : rate == 1 ? (rd_r23 | r23_ext_p) : (rd_r34 | r34_ext) ; |
---|
458 | |
---|
459 | endmodule |
---|
460 | |
---|
461 | |
---|
462 | |
---|
463 | //********************************************************* |
---|
464 | // File: fifo_16x8.v |
---|
465 | // Author: Y. Sun |
---|
466 | // Des: 16x8 FIFO |
---|
467 | //********************************************************* |
---|
468 | module fifo_16x8 ( |
---|
469 | clk , // I, clock |
---|
470 | nrst , // I, async reset |
---|
471 | reset , // I, sync reset |
---|
472 | wdata , // I, write data |
---|
473 | wr , // I, write enable |
---|
474 | rd , // I, read enable |
---|
475 | rdata , // O, read data |
---|
476 | empty , // O, empty |
---|
477 | full // O, full |
---|
478 | ) ; |
---|
479 | |
---|
480 | parameter WIDTH = 8 ; |
---|
481 | parameter DEPTH = 16 ; |
---|
482 | parameter ADDR_BITS = 4 ; |
---|
483 | |
---|
484 | input clk ; |
---|
485 | input nrst ; |
---|
486 | input reset ; |
---|
487 | input [WIDTH-1:0] wdata ; |
---|
488 | input wr ; |
---|
489 | input rd ; |
---|
490 | output [WIDTH-1:0] rdata ; |
---|
491 | output empty ; |
---|
492 | output full ; |
---|
493 | |
---|
494 | |
---|
495 | //============================ |
---|
496 | // Internal signals |
---|
497 | //============================ |
---|
498 | reg [WIDTH-1:0] mem [DEPTH-1:0] ; |
---|
499 | reg [ADDR_BITS:0] cnt ; |
---|
500 | reg [ADDR_BITS-1:0] waddr ; |
---|
501 | reg [ADDR_BITS-1:0] raddr ; |
---|
502 | |
---|
503 | //============================ |
---|
504 | // Main RTL Code |
---|
505 | //============================ |
---|
506 | assign empty = cnt == 0 ; |
---|
507 | assign full = cnt == DEPTH ; |
---|
508 | |
---|
509 | |
---|
510 | always @ (posedge clk or negedge nrst) |
---|
511 | if(~nrst) |
---|
512 | cnt <= 0 ; |
---|
513 | else |
---|
514 | begin |
---|
515 | if (reset) |
---|
516 | cnt <= 0 ; |
---|
517 | else if (wr & ~rd) |
---|
518 | cnt <= cnt +1 ; |
---|
519 | else if (rd & ~wr) |
---|
520 | cnt <= cnt -1 ; |
---|
521 | end |
---|
522 | |
---|
523 | always @ (posedge clk or negedge nrst) |
---|
524 | if(~nrst) |
---|
525 | waddr <= 0 ; |
---|
526 | else |
---|
527 | begin |
---|
528 | if (reset) |
---|
529 | waddr <= 0 ; |
---|
530 | else if (wr) |
---|
531 | waddr <= waddr == DEPTH -1 ? 0 : waddr +1 ; |
---|
532 | end |
---|
533 | |
---|
534 | always @ (posedge clk or negedge nrst) |
---|
535 | if(~nrst) |
---|
536 | raddr <= 0 ; |
---|
537 | else |
---|
538 | begin |
---|
539 | if (reset) |
---|
540 | raddr <= 0 ; |
---|
541 | else if (rd) |
---|
542 | raddr <= raddr == DEPTH -1 ? 0 : raddr +1 ; |
---|
543 | end |
---|
544 | |
---|
545 | always @ (posedge clk) |
---|
546 | if (wr) |
---|
547 | mem [waddr] <= wdata ; |
---|
548 | |
---|
549 | assign rdata = mem [raddr] ; |
---|
550 | |
---|
551 | endmodule |
---|
552 | |
---|
553 | //************************************************************** |
---|
554 | // File: llr_buffer.v |
---|
555 | // Author: Yang Sun (ysun@rice.edu) |
---|
556 | // Created: $ 2/4/07 |
---|
557 | // Des: Buffer IQ data for viterbi decoder |
---|
558 | // History: $ 09/27/07 :updated |
---|
559 | //************************************************************** |
---|
560 | module llr_buffer ( |
---|
561 | clk , |
---|
562 | nrst , |
---|
563 | reset , |
---|
564 | din , |
---|
565 | dout , |
---|
566 | wr , |
---|
567 | rd , |
---|
568 | empty , |
---|
569 | full |
---|
570 | ) ; |
---|
571 | |
---|
572 | parameter DEPTH = 256 ; // 128 slots |
---|
573 | parameter ADDRW = 8 ; |
---|
574 | parameter SW = 4 ; |
---|
575 | |
---|
576 | input clk ; // system clock |
---|
577 | input nrst ; |
---|
578 | input reset ; |
---|
579 | input [SW*2 -1:0] din ; |
---|
580 | input wr ; |
---|
581 | input rd ; |
---|
582 | output [SW*2 -1:0] dout ; |
---|
583 | output empty ; |
---|
584 | output full ; |
---|
585 | |
---|
586 | //============================================== |
---|
587 | // Internal signal |
---|
588 | //============================================== |
---|
589 | reg [SW*2 -1:0] mem [DEPTH -1:0] ; |
---|
590 | wire [SW*2 -1:0] data ; |
---|
591 | |
---|
592 | reg [ADDRW :0] waddr ; |
---|
593 | reg [ADDRW :0] raddr ; |
---|
594 | wire [ADDRW -1:0] waddr_i ; |
---|
595 | wire [ADDRW -1:0] raddr_i ; |
---|
596 | |
---|
597 | //============================================== |
---|
598 | // Main RTL |
---|
599 | //============================================== |
---|
600 | assign dout = data ; |
---|
601 | assign waddr_i = waddr [ADDRW -1 : 0] ; |
---|
602 | assign raddr_i = raddr [ADDRW -1 : 0] ; |
---|
603 | assign empty = (waddr [ADDRW] ~^ raddr [ADDRW]) & (waddr_i == raddr_i) ; |
---|
604 | assign full = (waddr [ADDRW] ^ raddr [ADDRW]) & (waddr_i == raddr_i) ; |
---|
605 | |
---|
606 | always @ (posedge clk or negedge nrst) |
---|
607 | if (~nrst) |
---|
608 | waddr <= 0 ; |
---|
609 | else if (reset) |
---|
610 | waddr <= 0 ; |
---|
611 | else if (wr) |
---|
612 | waddr <= waddr + 1 ; |
---|
613 | |
---|
614 | always @ (posedge clk or negedge nrst) |
---|
615 | if (~nrst) |
---|
616 | raddr <= 0 ; |
---|
617 | else if (reset) |
---|
618 | raddr <= 0 ; |
---|
619 | else if (rd) |
---|
620 | raddr <= raddr + 1 ; |
---|
621 | |
---|
622 | always @ (posedge clk) |
---|
623 | if (wr) |
---|
624 | mem [waddr_i] <= din ; |
---|
625 | |
---|
626 | assign data = mem [raddr_i] ; |
---|
627 | |
---|
628 | |
---|
629 | endmodule |
---|
630 | |
---|
631 | //************************************************************** |
---|
632 | // File: max_metric_logic.v |
---|
633 | // Author: Yang Sun (ysun@rice.edu) |
---|
634 | // Birth: $ 1/14/07 |
---|
635 | // Des: The top level of viterbi decoder |
---|
636 | // Take 5 bit soft value is [-16 : +15] |
---|
637 | // K = 7. g0 = 133, g1 = 171 |
---|
638 | // History: $ 1/14/07, Init coding |
---|
639 | // $ 1/22/07, K = 5, Zero latency |
---|
640 | // $ 12/1/07: Updated |
---|
641 | //************************************************************** |
---|
642 | module max_metric_logic ( |
---|
643 | a , // I, metric a |
---|
644 | b , // I, metric b |
---|
645 | c , // I, metric c |
---|
646 | d , // I, metric d |
---|
647 | sa , // I, state a |
---|
648 | sb , // I, state b |
---|
649 | sc , // I, state c |
---|
650 | sd , // I, state d |
---|
651 | state , // O, state |
---|
652 | max // O, max metric |
---|
653 | ) ; |
---|
654 | |
---|
655 | parameter M = 7 ; |
---|
656 | parameter K = 7 ; |
---|
657 | |
---|
658 | input [M -1:0] a ; |
---|
659 | input [M -1:0] b ; |
---|
660 | input [M -1:0] c ; |
---|
661 | input [M -1:0] d ; |
---|
662 | |
---|
663 | input [K -2:0] sa ; |
---|
664 | input [K -2:0] sb ; |
---|
665 | input [K -2:0] sc ; |
---|
666 | input [K -2:0] sd ; |
---|
667 | |
---|
668 | output [K -2:0] state ; |
---|
669 | output [M -1:0] max ; |
---|
670 | |
---|
671 | //================================== |
---|
672 | //Internal signal |
---|
673 | //================================== |
---|
674 | |
---|
675 | reg [K -2:0] pos0 ; |
---|
676 | reg [K -2:0] pos1 ; |
---|
677 | reg [M -1:0] max0 ; |
---|
678 | reg [M -1:0] max1 ; |
---|
679 | reg [M -1:0] tmp ; |
---|
680 | reg [K -2:0] state_i ; |
---|
681 | reg [M -1:0] max_i ; |
---|
682 | |
---|
683 | //================================== |
---|
684 | // Main body of code |
---|
685 | //================================== |
---|
686 | assign state = state_i ; |
---|
687 | assign max = max_i ; |
---|
688 | |
---|
689 | always @* |
---|
690 | begin |
---|
691 | tmp = a-b ; |
---|
692 | if(~tmp[M -1]) |
---|
693 | begin |
---|
694 | max0 = a ; |
---|
695 | pos0 = sa ; |
---|
696 | end |
---|
697 | else |
---|
698 | begin |
---|
699 | max0 = b ; |
---|
700 | pos0 = sb ; |
---|
701 | end |
---|
702 | |
---|
703 | tmp = c-d ; |
---|
704 | if(~tmp[M-1]) |
---|
705 | begin |
---|
706 | max1 = c ; |
---|
707 | pos1 = sc ; |
---|
708 | end |
---|
709 | else |
---|
710 | begin |
---|
711 | max1 = d ; |
---|
712 | pos1 = sd ; |
---|
713 | end |
---|
714 | |
---|
715 | tmp = max0 - max1 ; |
---|
716 | if (~tmp[M-1]) |
---|
717 | begin |
---|
718 | max_i = max0 ; |
---|
719 | state_i = pos0 ; |
---|
720 | end |
---|
721 | else |
---|
722 | begin |
---|
723 | state_i = pos1 ; |
---|
724 | max_i = max1 ; |
---|
725 | end |
---|
726 | end |
---|
727 | |
---|
728 | endmodule |
---|
729 | |
---|
730 | //************************************************************** |
---|
731 | // File: max_metric |
---|
732 | // Author: Yang Sun (ysun@rice.edu) |
---|
733 | // Birth: $ 1/14/07 |
---|
734 | // Des: Find max metric |
---|
735 | // K = 7. g0 = 133, g1 = 171 |
---|
736 | // History: $ 1/14/07, Init coding |
---|
737 | // $ 1/22/07, K = 5 |
---|
738 | // $ 2/23/07, 1 pipeline |
---|
739 | // $ 12/1/07: updated |
---|
740 | //************************************************************** |
---|
741 | module max_metric ( |
---|
742 | clk , // I, clock |
---|
743 | a , // I, metric a |
---|
744 | b , // I, metric b |
---|
745 | c , // I, metric c |
---|
746 | d , // I, metric d |
---|
747 | sa , // I, state a |
---|
748 | sb , // I, state b |
---|
749 | sc , // I, state c |
---|
750 | sd , // I, state d |
---|
751 | state , // O, state |
---|
752 | max // O, max metric |
---|
753 | ) ; |
---|
754 | |
---|
755 | parameter M = 7 ; |
---|
756 | parameter K = 7 ; |
---|
757 | |
---|
758 | input clk ; |
---|
759 | input [M -1:0] a ; |
---|
760 | input [M -1:0] b ; |
---|
761 | input [M -1:0] c ; |
---|
762 | input [M -1:0] d ; |
---|
763 | |
---|
764 | input [K -2:0] sa ; |
---|
765 | input [K -2:0] sb ; |
---|
766 | input [K -2:0] sc ; |
---|
767 | input [K -2:0] sd ; |
---|
768 | |
---|
769 | output [K -2:0] state ; |
---|
770 | output [M -1:0] max ; |
---|
771 | |
---|
772 | //===================================== |
---|
773 | //Internal signal |
---|
774 | //===================================== |
---|
775 | reg [K -2:0] pos0 ; |
---|
776 | reg [K -2:0] pos1 ; |
---|
777 | reg [M -1:0] max0 ; |
---|
778 | reg [M -1:0] max1 ; |
---|
779 | reg [M -1:0] tmp ; |
---|
780 | reg [K -2:0] state_i ; |
---|
781 | reg [M -1:0] max_i ; |
---|
782 | reg [K -2:0] state_reg ; |
---|
783 | reg [M -1:0] max_reg ; |
---|
784 | |
---|
785 | //===================================== |
---|
786 | // Main RTL code |
---|
787 | //===================================== |
---|
788 | assign state = state_reg ; |
---|
789 | assign max = max_reg ; |
---|
790 | |
---|
791 | always @ (posedge clk) |
---|
792 | begin |
---|
793 | state_reg <= state_i ; |
---|
794 | max_reg <= max_i ; |
---|
795 | end |
---|
796 | |
---|
797 | always @* |
---|
798 | begin |
---|
799 | tmp = a-b ; |
---|
800 | if(~tmp[M -1]) |
---|
801 | begin |
---|
802 | max0 = a ; |
---|
803 | pos0 = sa ; |
---|
804 | end |
---|
805 | else |
---|
806 | begin |
---|
807 | max0 = b ; |
---|
808 | pos0 = sb ; |
---|
809 | end |
---|
810 | |
---|
811 | tmp = c-d ; |
---|
812 | if(~tmp[M-1]) |
---|
813 | begin |
---|
814 | max1 = c ; |
---|
815 | pos1 = sc ; |
---|
816 | end |
---|
817 | else |
---|
818 | begin |
---|
819 | max1 = d ; |
---|
820 | pos1 = sd ; |
---|
821 | end |
---|
822 | |
---|
823 | tmp = max0 - max1 ; |
---|
824 | if (~tmp[M-1]) |
---|
825 | begin |
---|
826 | max_i = max0 ; |
---|
827 | state_i = pos0 ; |
---|
828 | end |
---|
829 | else |
---|
830 | begin |
---|
831 | state_i = pos1 ; |
---|
832 | max_i = max1 ; |
---|
833 | end |
---|
834 | end |
---|
835 | |
---|
836 | endmodule |
---|
837 | |
---|
838 | //********************************************************* |
---|
839 | // File: out_ctrl |
---|
840 | // Author: Y. Sun |
---|
841 | // Des: Convert the outputs into clk/2 domain |
---|
842 | // I have to convert the output into clk/2 domain |
---|
843 | // coz the downstream block takes clk/2 signals |
---|
844 | //********************************************************* |
---|
845 | module out_ctrl ( |
---|
846 | clk , // I, clock |
---|
847 | nrst , // I, async reset |
---|
848 | start , // I, start |
---|
849 | vin , // I, write enable |
---|
850 | din , // I, write data |
---|
851 | vout , // O, read enable |
---|
852 | dout , // O, read data |
---|
853 | idx_out // O, out index |
---|
854 | ) ; |
---|
855 | |
---|
856 | input clk ; |
---|
857 | input nrst ; |
---|
858 | input start ; |
---|
859 | input vin ; |
---|
860 | input [7:0] din ; |
---|
861 | output vout ; |
---|
862 | output [7:0] dout ; |
---|
863 | output [13:0] idx_out ; |
---|
864 | |
---|
865 | reg en ; |
---|
866 | wire ff_empty ; |
---|
867 | wire ff_rd ; |
---|
868 | wire [7:0] ff_rdata ; |
---|
869 | reg [7:0] data_lat ; |
---|
870 | reg ff_rd_d ; |
---|
871 | reg ff_rd_dd ; |
---|
872 | reg [13:0] cnt ; |
---|
873 | |
---|
874 | //============================ |
---|
875 | // Main RTL Code |
---|
876 | //============================ |
---|
877 | assign vout = ff_rd_d | ff_rd_dd ; |
---|
878 | assign dout = data_lat ; |
---|
879 | assign idx_out = cnt ; |
---|
880 | |
---|
881 | always @(posedge clk or negedge nrst) |
---|
882 | if(~nrst) |
---|
883 | en <= 1'b1 ; |
---|
884 | else if (start) |
---|
885 | en <= 1'b1 ; |
---|
886 | else |
---|
887 | en <= ~en ; |
---|
888 | |
---|
889 | assign ff_rd = ~ff_empty & en ; |
---|
890 | |
---|
891 | fifo_16x8 fifo_16x8 ( |
---|
892 | .clk (clk ), |
---|
893 | .nrst (nrst ), |
---|
894 | .reset (start ), |
---|
895 | .wr (vin ), |
---|
896 | .wdata (din ), |
---|
897 | .rd (ff_rd ), |
---|
898 | .rdata (ff_rdata ), |
---|
899 | .empty (ff_empty ), |
---|
900 | .full ( ) |
---|
901 | ) ; |
---|
902 | |
---|
903 | always @(posedge clk or negedge nrst) |
---|
904 | if(~nrst) |
---|
905 | data_lat <= 0 ; |
---|
906 | else if (ff_rd) |
---|
907 | data_lat <= ff_rdata ; |
---|
908 | |
---|
909 | always @(posedge clk or negedge nrst) |
---|
910 | if(~nrst) |
---|
911 | begin |
---|
912 | ff_rd_d <= 1'b0 ; |
---|
913 | ff_rd_dd <= 1'b0 ; |
---|
914 | end |
---|
915 | else if (start) |
---|
916 | begin |
---|
917 | ff_rd_dd <= 1'b0 ; |
---|
918 | ff_rd_d <= 1'b0 ; |
---|
919 | end |
---|
920 | else |
---|
921 | begin |
---|
922 | ff_rd_dd <= ff_rd_d ; |
---|
923 | ff_rd_d <= ff_rd ; |
---|
924 | end |
---|
925 | |
---|
926 | always @(posedge clk or negedge nrst) |
---|
927 | if(~nrst) |
---|
928 | cnt <= 0 ; |
---|
929 | else if (start) |
---|
930 | cnt <= 0 ; |
---|
931 | else if (ff_rd_dd) |
---|
932 | cnt <= cnt +1 ; |
---|
933 | |
---|
934 | |
---|
935 | endmodule |
---|
936 | |
---|
937 | |
---|
938 | //******************************************************************************** |
---|
939 | // Module: round_data.v |
---|
940 | // Author: Yang Sun (ysun@rice.edu) |
---|
941 | // Birth: $ 4/29/07 |
---|
942 | // Des: Round with 1 latency |
---|
943 | // History: $ 4/29/07, Init coding |
---|
944 | // $ 05/04/08: Fixed a bug |
---|
945 | //******************************************************************************** |
---|
946 | module round_data ( |
---|
947 | clk, din, dout |
---|
948 | ) ; |
---|
949 | |
---|
950 | input clk ; |
---|
951 | input [12:0] din ; |
---|
952 | output reg [3:0] dout ; |
---|
953 | |
---|
954 | //===================================== |
---|
955 | //Internal signal |
---|
956 | //===================================== |
---|
957 | reg [3:0] tmp ; |
---|
958 | |
---|
959 | //===================================== |
---|
960 | // Main body of code |
---|
961 | //===================================== |
---|
962 | |
---|
963 | always @ (posedge clk) |
---|
964 | dout <= tmp ; |
---|
965 | |
---|
966 | always @* |
---|
967 | begin |
---|
968 | if ((~din[12]) && (din[11:10] != 2'b00)) |
---|
969 | tmp = 4'b0111 ; |
---|
970 | else if (din[12] && (din[11:10] != 2'b11)) |
---|
971 | tmp = 4'b1000 ; |
---|
972 | else if (din[12:10] == 3'b000) // positive |
---|
973 | begin |
---|
974 | if ((din[9:7] != 3'b111) & din[6]) |
---|
975 | tmp = din[10:7] +1 ; |
---|
976 | else |
---|
977 | tmp = din[10:7] ; |
---|
978 | end |
---|
979 | else // negtive |
---|
980 | begin |
---|
981 | if ((din[9:7] != 3'b000) & din[6]) |
---|
982 | tmp = din[10:7] +1 ; |
---|
983 | else |
---|
984 | tmp = din[10:7] ; |
---|
985 | end |
---|
986 | end |
---|
987 | |
---|
988 | endmodule |
---|
989 | //******************************************************************************** |
---|
990 | // File: scrambler.v |
---|
991 | // Author: Yang Sun (ysun@rice.edu) |
---|
992 | // Des: byte scrambler |
---|
993 | // History: $ 12/1/07, Created |
---|
994 | //******************************************************************************** |
---|
995 | `ifndef INCLUDE_SCRAMBLER |
---|
996 | `define INCLUDE_SCRAMBLER |
---|
997 | module scrambler ( |
---|
998 | addr , // address 32 |
---|
999 | din , // byte in |
---|
1000 | dout // byte out |
---|
1001 | ) ; |
---|
1002 | |
---|
1003 | input [4:0] addr ; |
---|
1004 | input [7:0] din ; |
---|
1005 | output [7:0] dout ; |
---|
1006 | |
---|
1007 | //============================== |
---|
1008 | //Internal signal |
---|
1009 | //============================== |
---|
1010 | reg [7:0] scram_mask ; |
---|
1011 | |
---|
1012 | //============================== |
---|
1013 | // Main RTL code |
---|
1014 | //============================== |
---|
1015 | assign dout = din ^ scram_mask ; |
---|
1016 | |
---|
1017 | always @* |
---|
1018 | begin |
---|
1019 | case (addr[4:0]) |
---|
1020 | 0: scram_mask = 40 ; |
---|
1021 | 1: scram_mask = 198 ; |
---|
1022 | 2: scram_mask = 78 ; |
---|
1023 | 3: scram_mask = 63 ; |
---|
1024 | 4: scram_mask = 82 ; |
---|
1025 | 5: scram_mask = 173 ; |
---|
1026 | 6: scram_mask = 102 ; |
---|
1027 | 7: scram_mask = 245 ; |
---|
1028 | 8: scram_mask = 48 ; |
---|
1029 | 9: scram_mask = 111 ; |
---|
1030 | 10: scram_mask = 172 ; |
---|
1031 | 11: scram_mask = 115 ; |
---|
1032 | 12: scram_mask = 147 ; |
---|
1033 | 13: scram_mask = 230 ; |
---|
1034 | 14: scram_mask = 216 ; |
---|
1035 | 15: scram_mask = 93 ; |
---|
1036 | 16: scram_mask = 72 ; |
---|
1037 | 17: scram_mask = 65 ; |
---|
1038 | 18: scram_mask = 62 ; |
---|
1039 | 19: scram_mask = 2 ; |
---|
1040 | 20: scram_mask = 205 ; |
---|
1041 | 21: scram_mask = 242 ; |
---|
1042 | 22: scram_mask = 122 ; |
---|
1043 | 23: scram_mask = 90 ; |
---|
1044 | 24: scram_mask = 128 ; |
---|
1045 | 25: scram_mask = 83 ; |
---|
1046 | 26: scram_mask = 105 ; |
---|
1047 | 27: scram_mask = 97 ; |
---|
1048 | 28: scram_mask = 73 ; |
---|
1049 | 29: scram_mask = 10 ; |
---|
1050 | 30: scram_mask = 5 ; |
---|
1051 | 31: scram_mask = 252 ; |
---|
1052 | default: scram_mask = 40 ; |
---|
1053 | endcase |
---|
1054 | end |
---|
1055 | |
---|
1056 | endmodule |
---|
1057 | `endif |
---|
1058 | |
---|
1059 | //******************************************************************************** |
---|
1060 | // Module: Multiplier |
---|
1061 | // Author: Yang Sun (ysun@rice.edu) |
---|
1062 | // Birth: $ 4/29/07 |
---|
1063 | // Description: Mult with 1 latency |
---|
1064 | // History: $ 4/29/07, Init coding |
---|
1065 | //******************************************************************************** |
---|
1066 | module smult ( |
---|
1067 | clk, a_in, b_in, p_out |
---|
1068 | ) ; |
---|
1069 | |
---|
1070 | parameter AWID = 8 ; |
---|
1071 | parameter BWID = 5 ; |
---|
1072 | parameter PWID = AWID + BWID ; |
---|
1073 | |
---|
1074 | input clk ; |
---|
1075 | input [AWID -1:0] a_in ; |
---|
1076 | input [BWID -1:0] b_in ; |
---|
1077 | output [PWID -1:0] p_out ; |
---|
1078 | |
---|
1079 | //*********************************************** |
---|
1080 | //Internal signal |
---|
1081 | //*********************************************** |
---|
1082 | wire [AWID -1:0] a_tmp ; |
---|
1083 | wire a_sgn ; |
---|
1084 | reg a_sgn_pipe ; |
---|
1085 | reg [PWID -1:0] p_tmp ; |
---|
1086 | wire [PWID -1:0] p_tmp2 ; |
---|
1087 | //*********************************************** |
---|
1088 | // Main body of code |
---|
1089 | //*********************************************** |
---|
1090 | assign p_out = p_tmp2 ; |
---|
1091 | assign a_tmp = a_sgn ? ~a_in +1 : a_in ; |
---|
1092 | assign a_sgn = a_in [AWID -1] ; |
---|
1093 | |
---|
1094 | always @ (posedge clk) |
---|
1095 | p_tmp <= a_tmp * b_in ; |
---|
1096 | |
---|
1097 | always @ (posedge clk) |
---|
1098 | a_sgn_pipe <= a_sgn ; |
---|
1099 | |
---|
1100 | |
---|
1101 | assign p_tmp2 = a_sgn_pipe ? ~p_tmp +1 : p_tmp ; |
---|
1102 | |
---|
1103 | endmodule |
---|
1104 | |
---|
1105 | //******************************************************************************** |
---|
1106 | // File: soft_demapper.v |
---|
1107 | // Author: Yang Sun (ysun@rice.edu) |
---|
1108 | // Birth: $ 4/29/07 |
---|
1109 | // Des: Produce soft LLR for I/Q |
---|
1110 | // History: $ 4/29/07: Init coding |
---|
1111 | // $ 4/17/08: Added 16-QAM support |
---|
1112 | //******************************************************************************** |
---|
1113 | module soft_demapper ( |
---|
1114 | clk , |
---|
1115 | nrst , |
---|
1116 | start , |
---|
1117 | coding_en , |
---|
1118 | mod_level , |
---|
1119 | vin , |
---|
1120 | xk_index , |
---|
1121 | rx_i , |
---|
1122 | rx_q , |
---|
1123 | scale_qpsk , |
---|
1124 | scale_16qam , |
---|
1125 | soft_decoding , |
---|
1126 | in_fullrate , |
---|
1127 | sym_start , |
---|
1128 | hdr_mod_level , |
---|
1129 | vout , |
---|
1130 | llr_a , |
---|
1131 | llr_b |
---|
1132 | ) ; |
---|
1133 | |
---|
1134 | input clk ; |
---|
1135 | input nrst ; |
---|
1136 | input start ; |
---|
1137 | input coding_en ; |
---|
1138 | input [3:0] mod_level ; // 0=Invalid, 1=BPSK, 2=QPSK, 4=16-QAM |
---|
1139 | input vin ; // valid input |
---|
1140 | input [5:0] xk_index ; // FFT index |
---|
1141 | input [15:0] rx_i ; // FIX_16_15 |
---|
1142 | input [15:0] rx_q ; // FIX_16_15 |
---|
1143 | input [3:0] scale_qpsk ; // 0~15 sclae factor |
---|
1144 | input [4:0] scale_16qam ; // 0~31 sclae factor |
---|
1145 | input soft_decoding ; |
---|
1146 | input in_fullrate ; |
---|
1147 | |
---|
1148 | output sym_start ; |
---|
1149 | output [3:0] hdr_mod_level ; |
---|
1150 | output vout ; |
---|
1151 | output [3:0] llr_a ; |
---|
1152 | output [3:0] llr_b ; |
---|
1153 | |
---|
1154 | |
---|
1155 | //================================================ |
---|
1156 | //Internal signal |
---|
1157 | //================================================ |
---|
1158 | wire mod_vld ; |
---|
1159 | reg mod_vld_d ; |
---|
1160 | reg mod_vld_dd ; |
---|
1161 | reg mod_vld_ddd ; |
---|
1162 | wire llr_vld ; |
---|
1163 | wire [7:0] recv_fix_8_7 ; |
---|
1164 | wire [12:0] soft_a_mult ; |
---|
1165 | wire [12:0] soft_b_mult ; |
---|
1166 | wire [3:0] soft_a_round ; |
---|
1167 | wire [3:0] soft_b_round ; |
---|
1168 | |
---|
1169 | reg [7:0] rx_q_d ; |
---|
1170 | reg [7:0] rx_i_d ; |
---|
1171 | |
---|
1172 | wire [7:0] soft_a ; |
---|
1173 | reg [7:0] soft_b ; |
---|
1174 | |
---|
1175 | reg [3:0] hard_a ; |
---|
1176 | reg [3:0] hard_b ; |
---|
1177 | |
---|
1178 | reg [3:0] hard_a_s0 ; |
---|
1179 | reg [3:0] hard_b_s0 ; |
---|
1180 | wire [8:0] abs_tmp ; |
---|
1181 | wire [7:0] abs_tmp_sat ; |
---|
1182 | |
---|
1183 | wire [4:0] llr_scale ; |
---|
1184 | |
---|
1185 | reg [7:0] input_cnt ; |
---|
1186 | reg bpsk_sel ; |
---|
1187 | wire mod_ld ; |
---|
1188 | reg [3:0] mod_level_lat ; |
---|
1189 | wire [3:0] mod_type ; |
---|
1190 | wire bpsk ; |
---|
1191 | wire qpsk ; |
---|
1192 | wire qam16 ; |
---|
1193 | reg first_sym ; |
---|
1194 | reg first_sym_d ; |
---|
1195 | reg first_sym_dd ; |
---|
1196 | reg [3:0] hdr_mod_level_lat ; |
---|
1197 | |
---|
1198 | //================================================ |
---|
1199 | // Main body of code |
---|
1200 | //================================================ |
---|
1201 | assign llr_a = (soft_decoding & coding_en) ? soft_a_round : hard_a_s0 ; |
---|
1202 | assign llr_b = (soft_decoding & coding_en) ? soft_b_round : hard_b_s0 ; |
---|
1203 | assign vout = llr_vld ; |
---|
1204 | assign sym_start = vin & (xk_index == 0) ; |
---|
1205 | |
---|
1206 | |
---|
1207 | assign hdr_mod_level = hdr_mod_level_lat ; |
---|
1208 | |
---|
1209 | // 16-QAM |
---|
1210 | always @ (posedge clk or negedge nrst) |
---|
1211 | if(~nrst) |
---|
1212 | rx_q_d <= 0 ; |
---|
1213 | else if (vin) |
---|
1214 | rx_q_d <= rx_q [15:8] ; |
---|
1215 | |
---|
1216 | // BPSK |
---|
1217 | always @ (posedge clk or negedge nrst) |
---|
1218 | if(~nrst) |
---|
1219 | rx_i_d <= 0 ; |
---|
1220 | else if (mod_vld_d) |
---|
1221 | rx_i_d <= rx_i [15:8] ; |
---|
1222 | |
---|
1223 | assign mod_ld = vin & (xk_index == 1) ; |
---|
1224 | always @ (posedge clk or negedge nrst) |
---|
1225 | if(~nrst) |
---|
1226 | mod_level_lat <= 2 ; |
---|
1227 | else if (mod_ld) |
---|
1228 | mod_level_lat <= mod_level ; |
---|
1229 | |
---|
1230 | assign mod_type = mod_ld ? mod_level : mod_level_lat ; |
---|
1231 | |
---|
1232 | always @ (posedge clk or negedge nrst) |
---|
1233 | if(~nrst) |
---|
1234 | first_sym <= 1'b0 ; |
---|
1235 | else if (start) |
---|
1236 | first_sym <= 1'b1 ; |
---|
1237 | else if (sym_start) |
---|
1238 | first_sym <= 1'b0 ; |
---|
1239 | |
---|
1240 | always @ (posedge clk or negedge nrst) |
---|
1241 | if(~nrst) |
---|
1242 | {first_sym_dd, first_sym_d} <= 2'd0 ; |
---|
1243 | else |
---|
1244 | {first_sym_dd, first_sym_d} <= {first_sym_d, first_sym} ; |
---|
1245 | |
---|
1246 | |
---|
1247 | always @ (posedge clk or negedge nrst) |
---|
1248 | if(~nrst) |
---|
1249 | hdr_mod_level_lat <= 2 ; |
---|
1250 | else if (first_sym_dd & (mod_ld)) |
---|
1251 | hdr_mod_level_lat <= mod_level ; |
---|
1252 | |
---|
1253 | // Trancate 16_15 to 8_7 |
---|
1254 | //assign recv_fix_8_7 = in_fullrate ? (mod_type == 1 ? rx_i_s0 : (vin ? rx_i [15:8] : rx_q_s0)) : rx_i[15:8] ; |
---|
1255 | |
---|
1256 | assign bpsk = (mod_type == 1) ; |
---|
1257 | assign qpsk = (mod_type == 2) ; |
---|
1258 | assign qam16 =(mod_type == 4) ; |
---|
1259 | |
---|
1260 | assign recv_fix_8_7 = bpsk ? rx_i_d : (vin ? rx_i[15:8] : rx_q_d) ; |
---|
1261 | |
---|
1262 | //assign abs_tmp = recv_fix_8_7 [7] ? -recv_fix_8_7 : recv_fix_8_7 ; |
---|
1263 | assign abs_tmp = (recv_fix_8_7 ^{8{recv_fix_8_7[7]}}) + recv_fix_8_7[7] ; |
---|
1264 | assign abs_tmp_sat = abs_tmp[8] ? 8'hff : abs_tmp[7:0] ; |
---|
1265 | |
---|
1266 | assign soft_a = recv_fix_8_7 ; |
---|
1267 | assign llr_scale = (bpsk | qpsk) ? scale_qpsk : scale_16qam ; |
---|
1268 | |
---|
1269 | always @* |
---|
1270 | begin |
---|
1271 | if (bpsk) // BPSK |
---|
1272 | soft_b = rx_i[15:8] ; |
---|
1273 | else if (qpsk) // QPSK |
---|
1274 | soft_b = rx_q[15:8] ; |
---|
1275 | else // 16-QAM |
---|
1276 | soft_b = 8'b0100_0000 - abs_tmp_sat ; // 0.5 - |Y| |
---|
1277 | end |
---|
1278 | |
---|
1279 | always @ (posedge clk or negedge nrst) |
---|
1280 | if(~nrst) |
---|
1281 | begin |
---|
1282 | hard_a <= 1'b0 ; |
---|
1283 | hard_b <= 1'b0 ; |
---|
1284 | end |
---|
1285 | else |
---|
1286 | begin |
---|
1287 | hard_a <= soft_a [7] ? 4'hf : 4'h1 ; |
---|
1288 | hard_b <= soft_b [7] ? 4'hf : 4'h1 ; |
---|
1289 | end |
---|
1290 | |
---|
1291 | always @ (posedge clk or negedge nrst) |
---|
1292 | if(~nrst) |
---|
1293 | begin |
---|
1294 | hard_a_s0 <= 1'b0 ; |
---|
1295 | hard_b_s0 <= 1'b0 ; |
---|
1296 | end |
---|
1297 | else |
---|
1298 | begin |
---|
1299 | hard_a_s0 <= hard_a ; |
---|
1300 | hard_b_s0 <= hard_b ; |
---|
1301 | end |
---|
1302 | |
---|
1303 | //================================ |
---|
1304 | // signed MULT |
---|
1305 | //================================ |
---|
1306 | smult smult_a ( |
---|
1307 | .clk (clk ), //I |
---|
1308 | .a_in (soft_a ), //I |
---|
1309 | .b_in (llr_scale ), //I |
---|
1310 | .p_out (soft_a_mult) //O |
---|
1311 | ) ; |
---|
1312 | |
---|
1313 | //================================ |
---|
1314 | // signed MULT |
---|
1315 | //================================ |
---|
1316 | smult smult_b ( |
---|
1317 | .clk (clk ), //I |
---|
1318 | .a_in (soft_b ), //I |
---|
1319 | .b_in (llr_scale ), //I |
---|
1320 | .p_out (soft_b_mult) //O |
---|
1321 | ) ; |
---|
1322 | |
---|
1323 | //================================ |
---|
1324 | // Round |
---|
1325 | //================================ |
---|
1326 | round_data data_i ( |
---|
1327 | .clk (clk ), //I |
---|
1328 | .din (soft_a_mult ), //I |
---|
1329 | .dout (soft_a_round ) //O |
---|
1330 | ) ; |
---|
1331 | |
---|
1332 | //================================ |
---|
1333 | // Round |
---|
1334 | //================================ |
---|
1335 | round_data data_q ( |
---|
1336 | .clk (clk ), //I |
---|
1337 | .din (soft_b_mult ), //I |
---|
1338 | .dout (soft_b_round ) //O |
---|
1339 | ) ; |
---|
1340 | |
---|
1341 | //assign mod_pipe = in_fullrate ? (mod_type == 1 ? (mod_s0 & bpsk_sel) : (mod_type == 2 ? mod_s0 : (mod_s0 | mod_s1))) : mod_s0 ; |
---|
1342 | assign llr_vld = bpsk ? (mod_vld_dd & bpsk_sel) : (qpsk ? mod_vld_dd : (mod_vld_dd | mod_vld_ddd)) ; |
---|
1343 | |
---|
1344 | assign mod_vld = vin & (mod_level != 0) ; |
---|
1345 | always @ (posedge clk ) |
---|
1346 | {mod_vld_ddd, mod_vld_dd,mod_vld_d} <= {mod_vld_dd, mod_vld_d,mod_vld} ; |
---|
1347 | |
---|
1348 | always @ (posedge clk or negedge nrst) |
---|
1349 | if (~nrst) |
---|
1350 | input_cnt <= 0 ; |
---|
1351 | else if (start) |
---|
1352 | input_cnt <= 0 ; |
---|
1353 | else if (llr_vld) |
---|
1354 | begin |
---|
1355 | if (input_cnt != 192) |
---|
1356 | input_cnt <= input_cnt +1 ; |
---|
1357 | end |
---|
1358 | |
---|
1359 | always @ (posedge clk or negedge nrst) |
---|
1360 | if (~nrst) |
---|
1361 | bpsk_sel <= 1'b0 ; |
---|
1362 | else if (start) |
---|
1363 | bpsk_sel <= 1'b0 ; |
---|
1364 | else if (mod_vld_dd) |
---|
1365 | bpsk_sel <= ~bpsk_sel ; |
---|
1366 | |
---|
1367 | endmodule |
---|
1368 | |
---|
1369 | |
---|
1370 | //******************************************************************************** |
---|
1371 | // File: unc_decoder.v |
---|
1372 | // Author: Yang Sun (ysun@rice.edu) |
---|
1373 | // Birth: $ 12/1/07 |
---|
1374 | // Des: decoder system |
---|
1375 | // History: $ 12/1/07, Uncoded decoder |
---|
1376 | // $ 10/11/08, added BPSK |
---|
1377 | //******************************************************************************** |
---|
1378 | module unc_decoder ( |
---|
1379 | clk , // clock |
---|
1380 | nrst , // n reset |
---|
1381 | hd_a , // hard decision of a |
---|
1382 | hd_b , // hard decision of b |
---|
1383 | start , // start decoding pulse |
---|
1384 | vin , // valid input |
---|
1385 | vout , // valid output |
---|
1386 | dout // byte out |
---|
1387 | ) ; |
---|
1388 | |
---|
1389 | input clk ; |
---|
1390 | input nrst ; |
---|
1391 | input hd_a ; |
---|
1392 | input hd_b ; |
---|
1393 | input start ; |
---|
1394 | input vin ; |
---|
1395 | output vout ; |
---|
1396 | output [7:0] dout ; |
---|
1397 | |
---|
1398 | //============================== |
---|
1399 | //Internal signal |
---|
1400 | //============================== |
---|
1401 | reg [7:2] tmpd ; |
---|
1402 | reg [1:0] cnt ; |
---|
1403 | wire [1:0] data_2b ; |
---|
1404 | |
---|
1405 | //============================== |
---|
1406 | // Main RTL code |
---|
1407 | //============================== |
---|
1408 | assign data_2b = {hd_a, hd_b} ; |
---|
1409 | always @ (posedge clk or negedge nrst) |
---|
1410 | if (~nrst) |
---|
1411 | tmpd <= 0 ; |
---|
1412 | else if (start) |
---|
1413 | tmpd <= 0 ; |
---|
1414 | else if (vin) |
---|
1415 | begin |
---|
1416 | case (cnt) |
---|
1417 | 3'd0: tmpd [7:6] <= data_2b ; |
---|
1418 | 3'd1: tmpd [5:4] <= data_2b ; |
---|
1419 | 3'd2: tmpd [3:2] <= data_2b ; |
---|
1420 | default: tmpd <= tmpd ; |
---|
1421 | endcase |
---|
1422 | end |
---|
1423 | |
---|
1424 | always @ (posedge clk or negedge nrst) |
---|
1425 | if (~nrst) |
---|
1426 | cnt <= 0 ; |
---|
1427 | else if (start) |
---|
1428 | cnt <= 0 ; |
---|
1429 | else if (vin) |
---|
1430 | cnt <= cnt +1 ; |
---|
1431 | |
---|
1432 | assign vout = vin & (cnt == 3) ; |
---|
1433 | assign dout = {tmpd, data_2b} ; |
---|
1434 | |
---|
1435 | endmodule |
---|
1436 | |
---|
1437 | //************************************************************** |
---|
1438 | // File: unpack_m2n.v |
---|
1439 | // Author: Yang Sun (ysun@rice.edu) |
---|
1440 | // Birth: $ 1/15/07 |
---|
1441 | // Des: unpack from M bit to N bit, M > N |
---|
1442 | // History: $ 1/15/07, Init coding |
---|
1443 | // $ 1/21/07, K = 7 |
---|
1444 | // $ 3/23, Fixed a naming problem for sysgen |
---|
1445 | // Can not use VHDL reserved key world |
---|
1446 | // $ 12/1/07: Updated |
---|
1447 | //************************************************************** |
---|
1448 | |
---|
1449 | module unpack_m2n ( |
---|
1450 | clk , // I, clock |
---|
1451 | nrst , // I, n reset |
---|
1452 | start , // I, start pulse |
---|
1453 | din , // I, data input |
---|
1454 | vin , // I, valid input |
---|
1455 | dout , // O, data output |
---|
1456 | vout , // O, valid output |
---|
1457 | remain , // I, remain |
---|
1458 | last , // I, last data |
---|
1459 | done // O, done |
---|
1460 | ) ; |
---|
1461 | |
---|
1462 | parameter BITM = 40 ; |
---|
1463 | parameter BITN = 8 ; |
---|
1464 | parameter LW = 6 ; |
---|
1465 | |
---|
1466 | input clk ; |
---|
1467 | input nrst ; |
---|
1468 | input start ; |
---|
1469 | input [BITM-1 :0] din ; |
---|
1470 | input vin ; |
---|
1471 | input [LW -1:0] remain ; |
---|
1472 | input last ; |
---|
1473 | |
---|
1474 | output [BITN-1 :0] dout ; |
---|
1475 | output vout ; |
---|
1476 | output done ; |
---|
1477 | |
---|
1478 | //================================================ |
---|
1479 | //Internal signal |
---|
1480 | //================================================ |
---|
1481 | reg [BITM + BITN -1 :0] sreg ; |
---|
1482 | wire [BITM + BITN -1 :0] sreg_next ; |
---|
1483 | reg [LW -1 : 0] cnt ; |
---|
1484 | wire rd ; |
---|
1485 | wire [BITN-1 :0] data ; |
---|
1486 | wire [BITM + BITN -1 :0] tmp ; |
---|
1487 | wire [BITM + BITN -1 :0] tmp2 ; |
---|
1488 | wire [LW -1 : 0] shift ; |
---|
1489 | reg last_i ; |
---|
1490 | reg last_byte_s0 ; |
---|
1491 | wire last_byte ; |
---|
1492 | |
---|
1493 | //================================================ |
---|
1494 | // Main RTL code |
---|
1495 | //================================================ |
---|
1496 | assign dout = data ; |
---|
1497 | assign vout = rd ; |
---|
1498 | |
---|
1499 | always @ (posedge clk or negedge nrst) |
---|
1500 | if (~nrst) |
---|
1501 | cnt <= 0 ; |
---|
1502 | else if (start) |
---|
1503 | cnt <= 0 ; |
---|
1504 | else if (vin) |
---|
1505 | begin |
---|
1506 | if (~last) |
---|
1507 | cnt <= cnt + BITM ; |
---|
1508 | else |
---|
1509 | cnt <= cnt + remain ; |
---|
1510 | end |
---|
1511 | else if (rd) |
---|
1512 | cnt <= cnt - BITN ; |
---|
1513 | |
---|
1514 | assign rd = cnt >= BITN ; |
---|
1515 | assign data = sreg [BITM + BITN -1 : BITM] ; |
---|
1516 | assign tmp = {{BITM{1'b0}}, din} ; |
---|
1517 | assign shift = BITN - cnt ; |
---|
1518 | assign tmp2 = (tmp << shift) | sreg ; |
---|
1519 | assign sreg_next = vin ? tmp2 : rd ? {sreg[BITM -1 : 0], {BITN{1'b0}}} : sreg ; |
---|
1520 | |
---|
1521 | always @ (posedge clk or negedge nrst) |
---|
1522 | if (~nrst) |
---|
1523 | sreg <= 0 ; |
---|
1524 | else if (start) |
---|
1525 | sreg <= 0 ; |
---|
1526 | else |
---|
1527 | sreg <= sreg_next ; |
---|
1528 | |
---|
1529 | always @ (posedge clk or negedge nrst) |
---|
1530 | if (~nrst) |
---|
1531 | last_i <= 1'b0 ; |
---|
1532 | else if (start) |
---|
1533 | last_i <= 1'b0 ; |
---|
1534 | else if (vin & last) |
---|
1535 | last_i <= 1'b1 ; |
---|
1536 | |
---|
1537 | assign last_byte = last_i && cnt < BITN ; |
---|
1538 | always @ (posedge clk) |
---|
1539 | last_byte_s0 <= last_byte ; |
---|
1540 | |
---|
1541 | assign done = ~last_byte_s0 & last_byte ; |
---|
1542 | |
---|
1543 | endmodule |
---|
1544 | //***************************************************************** |
---|
1545 | // File: vb_decoder_top.v |
---|
1546 | // Author: Yang Sun (ysun@rice.edu) |
---|
1547 | // Birth: $ 1/15/07 |
---|
1548 | // Des: viterbi decoder top level |
---|
1549 | // Take 5 bit soft value is [-16 : +15] |
---|
1550 | // K = 3. g0 =7, g1 = 5 |
---|
1551 | // K = 7. g0 = 133, g1 = 171 |
---|
1552 | // History: $ 1/15/07, Init coding |
---|
1553 | // $ 1/21/07, K = 7 |
---|
1554 | // $ 1/27/07, Change to LLR domain |
---|
1555 | // $ 2/4/07, Support puncture 2/3, 3/4 |
---|
1556 | // $ 3/22/07, Remove puncture and iq buffer for WARP |
---|
1557 | // $ 3/23/07, Fixed a naming problem for sysgen |
---|
1558 | // Can not use VHDL reserved key world |
---|
1559 | // $ 4/20/07, K = 7 |
---|
1560 | // $ 4/22/07, Change quantilization to -4 ~ 4 9-level |
---|
1561 | // $ 12/1/07: Modified for OFDM V7 |
---|
1562 | //***************************************************************** |
---|
1563 | module vb_decoder_top ( |
---|
1564 | clk , // I, clock |
---|
1565 | nrst , // I, n reset |
---|
1566 | packet_start, // I, packet start pulse |
---|
1567 | packet_end , // I, packet end pulse |
---|
1568 | zero_tail , // I, the code is zero terminated |
---|
1569 | vin , // I, valid input |
---|
1570 | llr_b1 , // I, 1st LLR |
---|
1571 | llr_b0 , // I, 2nd LLR |
---|
1572 | vout , // O, valid output |
---|
1573 | dout_in_byte, // O, decoded output in byte |
---|
1574 | done // O, decoding done |
---|
1575 | ) ; |
---|
1576 | |
---|
1577 | parameter SW = 4 ; // soft input precision |
---|
1578 | parameter M = 7 ; // Metric precision |
---|
1579 | parameter R = 48 ; // reliable trace |
---|
1580 | parameter C = 40 ; // unreliable trace |
---|
1581 | parameter L = 88 ; // total trace depth |
---|
1582 | parameter LW = 7 ; // L width |
---|
1583 | parameter K = 7 ; // constraint length |
---|
1584 | parameter N = 64 ; // number of states |
---|
1585 | parameter TR = 128 ; // trace buffer depth |
---|
1586 | parameter TRW = 7 ; // trace buffer address width |
---|
1587 | |
---|
1588 | input clk ; // system clock |
---|
1589 | input nrst ; // active low reset |
---|
1590 | input packet_start ; // start of packet pulse |
---|
1591 | input zero_tail ; // 1 = the code is terminated with 0, 0 = no termination |
---|
1592 | input packet_end ; // end of packet pulse |
---|
1593 | input vin ; // data valid input |
---|
1594 | input [SW -1:0] llr_b1 ; // soft value for bit1 |
---|
1595 | input [SW -1:0] llr_b0 ; // soft value for bit0 |
---|
1596 | |
---|
1597 | output done ; |
---|
1598 | output vout ; |
---|
1599 | output [7:0] dout_in_byte ; |
---|
1600 | |
---|
1601 | //============================================= |
---|
1602 | //Internal signal |
---|
1603 | //============================================= |
---|
1604 | wire [LW -1:0] remain ; |
---|
1605 | wire dec_vout ; |
---|
1606 | wire [R-1:0] dec_dout ; |
---|
1607 | wire dec_done ; |
---|
1608 | |
---|
1609 | //============================================= |
---|
1610 | // Main RTL code |
---|
1611 | //============================================= |
---|
1612 | |
---|
1613 | //================================================================ |
---|
1614 | // Viterbi decoder core logic |
---|
1615 | //================================================================ |
---|
1616 | viterbi_core #(SW, M, R, C, L, LW, K, N, TR, TRW) viterbi_core ( |
---|
1617 | .clk (clk ), //IN |
---|
1618 | .nrst (nrst ), //IN |
---|
1619 | .packet_start (packet_start ), //IN |
---|
1620 | .packet_end (packet_end ), //IN |
---|
1621 | .zero_tail (zero_tail ), |
---|
1622 | `ifdef INT_PUNC //Internal puncture |
---|
1623 | .dv_in (llr_valid ), //IN |
---|
1624 | .llr1 (llr1_depunc ), //IN[SW-1:0] |
---|
1625 | .llr0 (llr0_depunc ), //IN[SW-1:0] |
---|
1626 | `else |
---|
1627 | .dv_in (vin ), //IN |
---|
1628 | .llr1 (llr_b1 ), //IN[SW-1:0] |
---|
1629 | .llr0 (llr_b0 ), //IN[SW-1:0] |
---|
1630 | `endif |
---|
1631 | .remain (remain ), //OUT[LW -1:0] |
---|
1632 | .done (dec_done ), //OUT |
---|
1633 | .dv_out (dec_vout ), //OUT |
---|
1634 | .dout (dec_dout ) //OUT[R -1:0] |
---|
1635 | ) ; |
---|
1636 | |
---|
1637 | //============================================= |
---|
1638 | // x to 8bit unpacking |
---|
1639 | //============================================= |
---|
1640 | unpack_m2n #(R, 8, LW) unpack_Rto8 ( |
---|
1641 | .clk (clk ), //IN |
---|
1642 | .nrst (nrst ), //IN |
---|
1643 | .start (packet_start ), //IN |
---|
1644 | .din (dec_dout ), //IN[R -1:0] |
---|
1645 | .vin (dec_vout ), //IN |
---|
1646 | .last (dec_done ), //IN |
---|
1647 | .remain (remain ), //IN[LW -1:0] |
---|
1648 | .dout (dout_in_byte ), //OUT |
---|
1649 | .vout (vout ), //OUT |
---|
1650 | .done (done ) //OUT |
---|
1651 | ) ; |
---|
1652 | |
---|
1653 | endmodule |
---|
1654 | |
---|
1655 | //************************************************************** |
---|
1656 | // File: viterbi_core |
---|
1657 | // Author: Yang Sun (ysun@rice.edu) |
---|
1658 | // Birth: $ 1/14/07 |
---|
1659 | // Des: The top level of viterbi decoder |
---|
1660 | // Take 4 bit soft value is [-8 : +7] |
---|
1661 | // K = 3. g0 = 7, g1 = 5 |
---|
1662 | // K = 5, g0 (A) = 1 + x + x^2 + x^4, g1 (B) = 1 + x^3 + x^4 |
---|
1663 | // K = 7, g0 (A) = 1 + x^2 + x^3 + x^4 + x^5 |
---|
1664 | // g1 (B) = 1 + x + x^2 + x^3 + x^6 |
---|
1665 | // History: $ 1/14/07, Init coding, K = 3 |
---|
1666 | // $ 1/22/07, K = 5 |
---|
1667 | // $ 1/26/07, Updated |
---|
1668 | // $ 1/27/07, Change to LLR domain |
---|
1669 | // $ 2/18/07, Supported K = 7 |
---|
1670 | // $ 2/23/07, Added pipeline to max_metric |
---|
1671 | // $ 12/1/07, Updated |
---|
1672 | //************************************************************** |
---|
1673 | //`define ZERO_TERM |
---|
1674 | |
---|
1675 | module viterbi_core ( |
---|
1676 | clk , // I, clock |
---|
1677 | nrst , // I, n reset |
---|
1678 | packet_start, // I, packet start pulse |
---|
1679 | zero_tail , // I, the code is zero terminated |
---|
1680 | dv_in , // I, data valid input |
---|
1681 | llr0 , // I, LLR 2nd |
---|
1682 | llr1 , // I, LLR 1st |
---|
1683 | packet_end , // I, packet end pulse |
---|
1684 | dv_out , // O, data valid out |
---|
1685 | dout , // O, data out |
---|
1686 | done , // O, done pulse |
---|
1687 | remain // O, remain data cnt |
---|
1688 | ) ; |
---|
1689 | |
---|
1690 | parameter SW = 4 ; // soft input precision |
---|
1691 | parameter M = 7 ; // metric width |
---|
1692 | |
---|
1693 | parameter R = 48 ; // reliable trace |
---|
1694 | parameter C = 40 ; // unreliable trace |
---|
1695 | parameter L = 88 ; // total trace depth |
---|
1696 | parameter LW = 7 ; // L width |
---|
1697 | |
---|
1698 | parameter K = 7 ; // constraint length |
---|
1699 | parameter N = 64 ; // number of states = 2^(K-1) |
---|
1700 | parameter TR = 128 ; // trace buffer |
---|
1701 | parameter TRW = 7 ; // trace |
---|
1702 | |
---|
1703 | input clk ; // system clock |
---|
1704 | input nrst ; // active low reset |
---|
1705 | input packet_start ; // start of packet pulse |
---|
1706 | input zero_tail ; // 1 = the code is terminated with 0, 0 = no termination |
---|
1707 | input packet_end ; // end of packet pulse |
---|
1708 | input dv_in ; // data valid input |
---|
1709 | input [SW -1:0] llr1 ; // LLR soft value for bit1, LLR = log(Pr(ci=0/ri)/Pr(ci=1/ri)) |
---|
1710 | input [SW -1:0] llr0 ; // LLR soft value for bit0, LLR = log(Pr(ci=0/ri)/Pr(ci=1/ri)) |
---|
1711 | |
---|
1712 | output done ; |
---|
1713 | output [LW -1:0] remain ; |
---|
1714 | output dv_out ; |
---|
1715 | output [R-1:0] dout ; |
---|
1716 | |
---|
1717 | //====================================== |
---|
1718 | //Internal signal |
---|
1719 | //====================================== |
---|
1720 | wire [SW:0] branch_00 ; |
---|
1721 | wire [SW:0] branch_01 ; |
---|
1722 | wire [SW:0] branch_10 ; |
---|
1723 | wire [SW:0] branch_11 ; |
---|
1724 | |
---|
1725 | wire [SW:0] branch_A_0 ; |
---|
1726 | wire [SW:0] branch_B_0 ; |
---|
1727 | wire [SW:0] branch_A_1 ; |
---|
1728 | wire [SW:0] branch_B_1 ; |
---|
1729 | wire [SW:0] branch_A_2 ; |
---|
1730 | wire [SW:0] branch_B_2 ; |
---|
1731 | wire [SW:0] branch_A_3 ; |
---|
1732 | wire [SW:0] branch_B_3 ; |
---|
1733 | wire [SW:0] branch_A_4 ; |
---|
1734 | wire [SW:0] branch_B_4 ; |
---|
1735 | wire [SW:0] branch_A_5 ; |
---|
1736 | wire [SW:0] branch_B_5 ; |
---|
1737 | wire [SW:0] branch_A_6 ; |
---|
1738 | wire [SW:0] branch_B_6 ; |
---|
1739 | wire [SW:0] branch_A_7 ; |
---|
1740 | wire [SW:0] branch_B_7 ; |
---|
1741 | wire [SW:0] branch_A_8 ; |
---|
1742 | wire [SW:0] branch_B_8 ; |
---|
1743 | wire [SW:0] branch_A_9 ; |
---|
1744 | wire [SW:0] branch_B_9 ; |
---|
1745 | wire [SW:0] branch_A_10 ; |
---|
1746 | wire [SW:0] branch_B_10 ; |
---|
1747 | wire [SW:0] branch_A_11 ; |
---|
1748 | wire [SW:0] branch_B_11 ; |
---|
1749 | wire [SW:0] branch_A_12 ; |
---|
1750 | wire [SW:0] branch_B_12 ; |
---|
1751 | wire [SW:0] branch_A_13 ; |
---|
1752 | wire [SW:0] branch_B_13 ; |
---|
1753 | wire [SW:0] branch_A_14 ; |
---|
1754 | wire [SW:0] branch_B_14 ; |
---|
1755 | wire [SW:0] branch_A_15 ; |
---|
1756 | wire [SW:0] branch_B_15 ; |
---|
1757 | wire [SW:0] branch_A_16 ; |
---|
1758 | wire [SW:0] branch_B_16 ; |
---|
1759 | wire [SW:0] branch_A_17; |
---|
1760 | wire [SW:0] branch_B_17; |
---|
1761 | wire [SW:0] branch_A_18; |
---|
1762 | wire [SW:0] branch_B_18; |
---|
1763 | wire [SW:0] branch_A_19; |
---|
1764 | wire [SW:0] branch_B_19; |
---|
1765 | wire [SW:0] branch_A_20; |
---|
1766 | wire [SW:0] branch_B_20; |
---|
1767 | wire [SW:0] branch_A_21; |
---|
1768 | wire [SW:0] branch_B_21; |
---|
1769 | wire [SW:0] branch_A_22; |
---|
1770 | wire [SW:0] branch_B_22; |
---|
1771 | wire [SW:0] branch_A_23; |
---|
1772 | wire [SW:0] branch_B_23; |
---|
1773 | wire [SW:0] branch_A_24; |
---|
1774 | wire [SW:0] branch_B_24; |
---|
1775 | wire [SW:0] branch_A_25; |
---|
1776 | wire [SW:0] branch_B_25; |
---|
1777 | wire [SW:0] branch_A_26 ; |
---|
1778 | wire [SW:0] branch_B_26 ; |
---|
1779 | wire [SW:0] branch_A_27 ; |
---|
1780 | wire [SW:0] branch_B_27 ; |
---|
1781 | wire [SW:0] branch_A_28 ; |
---|
1782 | wire [SW:0] branch_B_28 ; |
---|
1783 | wire [SW:0] branch_A_29 ; |
---|
1784 | wire [SW:0] branch_B_29 ; |
---|
1785 | wire [SW:0] branch_A_30 ; |
---|
1786 | wire [SW:0] branch_B_30 ; |
---|
1787 | wire [SW:0] branch_A_31 ; |
---|
1788 | wire [SW:0] branch_B_31 ; |
---|
1789 | wire [SW:0] branch_A_32; |
---|
1790 | wire [SW:0] branch_B_32; |
---|
1791 | wire [SW:0] branch_A_33; |
---|
1792 | wire [SW:0] branch_B_33; |
---|
1793 | wire [SW:0] branch_A_34; |
---|
1794 | wire [SW:0] branch_B_34; |
---|
1795 | wire [SW:0] branch_A_35; |
---|
1796 | wire [SW:0] branch_B_35; |
---|
1797 | wire [SW:0] branch_A_36; |
---|
1798 | wire [SW:0] branch_B_36; |
---|
1799 | wire [SW:0] branch_A_37; |
---|
1800 | wire [SW:0] branch_B_37; |
---|
1801 | wire [SW:0] branch_A_38; |
---|
1802 | wire [SW:0] branch_B_38; |
---|
1803 | wire [SW:0] branch_A_39; |
---|
1804 | wire [SW:0] branch_B_39; |
---|
1805 | wire [SW:0] branch_A_40; |
---|
1806 | wire [SW:0] branch_B_40; |
---|
1807 | wire [SW:0] branch_A_41; |
---|
1808 | wire [SW:0] branch_B_41; |
---|
1809 | wire [SW:0] branch_A_42 ; |
---|
1810 | wire [SW:0] branch_B_42 ; |
---|
1811 | wire [SW:0] branch_A_43 ; |
---|
1812 | wire [SW:0] branch_B_43 ; |
---|
1813 | wire [SW:0] branch_A_44 ; |
---|
1814 | wire [SW:0] branch_B_44 ; |
---|
1815 | wire [SW:0] branch_A_45 ; |
---|
1816 | wire [SW:0] branch_B_45 ; |
---|
1817 | wire [SW:0] branch_A_46 ; |
---|
1818 | wire [SW:0] branch_B_46 ; |
---|
1819 | wire [SW:0] branch_A_47 ; |
---|
1820 | wire [SW:0] branch_B_47 ; |
---|
1821 | wire [SW:0] branch_A_48; |
---|
1822 | wire [SW:0] branch_B_48; |
---|
1823 | wire [SW:0] branch_A_49; |
---|
1824 | wire [SW:0] branch_B_49; |
---|
1825 | wire [SW:0] branch_A_50; |
---|
1826 | wire [SW:0] branch_B_50; |
---|
1827 | wire [SW:0] branch_A_51; |
---|
1828 | wire [SW:0] branch_B_51; |
---|
1829 | wire [SW:0] branch_A_52; |
---|
1830 | wire [SW:0] branch_B_52; |
---|
1831 | wire [SW:0] branch_A_53; |
---|
1832 | wire [SW:0] branch_B_53; |
---|
1833 | wire [SW:0] branch_A_54; |
---|
1834 | wire [SW:0] branch_B_54; |
---|
1835 | wire [SW:0] branch_A_55; |
---|
1836 | wire [SW:0] branch_B_55; |
---|
1837 | wire [SW:0] branch_A_56; |
---|
1838 | wire [SW:0] branch_B_56; |
---|
1839 | wire [SW:0] branch_A_57; |
---|
1840 | wire [SW:0] branch_B_57; |
---|
1841 | wire [SW:0] branch_A_58 ; |
---|
1842 | wire [SW:0] branch_B_58 ; |
---|
1843 | wire [SW:0] branch_A_59 ; |
---|
1844 | wire [SW:0] branch_B_59 ; |
---|
1845 | wire [SW:0] branch_A_60 ; |
---|
1846 | wire [SW:0] branch_B_60 ; |
---|
1847 | wire [SW:0] branch_A_61 ; |
---|
1848 | wire [SW:0] branch_B_61 ; |
---|
1849 | wire [SW:0] branch_A_62 ; |
---|
1850 | wire [SW:0] branch_B_62 ; |
---|
1851 | wire [SW:0] branch_A_63 ; |
---|
1852 | wire [SW:0] branch_B_63 ; |
---|
1853 | |
---|
1854 | reg [M -1:0] metric_0 ; |
---|
1855 | reg [M -1:0] metric_1 ; |
---|
1856 | reg [M -1:0] metric_2 ; |
---|
1857 | reg [M -1:0] metric_3 ; |
---|
1858 | reg [M -1:0] metric_4 ; |
---|
1859 | reg [M -1:0] metric_5 ; |
---|
1860 | reg [M -1:0] metric_6 ; |
---|
1861 | reg [M -1:0] metric_7 ; |
---|
1862 | reg [M -1:0] metric_8 ; |
---|
1863 | reg [M -1:0] metric_9 ; |
---|
1864 | reg [M -1:0] metric_10 ; |
---|
1865 | reg [M -1:0] metric_11 ; |
---|
1866 | reg [M -1:0] metric_12 ; |
---|
1867 | reg [M -1:0] metric_13 ; |
---|
1868 | reg [M -1:0] metric_14 ; |
---|
1869 | reg [M -1:0] metric_15 ; |
---|
1870 | reg [M -1:0] metric_16; |
---|
1871 | reg [M -1:0] metric_17; |
---|
1872 | reg [M -1:0] metric_18; |
---|
1873 | reg [M -1:0] metric_19; |
---|
1874 | reg [M -1:0] metric_20; |
---|
1875 | reg [M -1:0] metric_21; |
---|
1876 | reg [M -1:0] metric_22; |
---|
1877 | reg [M -1:0] metric_23; |
---|
1878 | reg [M -1:0] metric_24; |
---|
1879 | reg [M -1:0] metric_25; |
---|
1880 | reg [M -1:0] metric_26 ; |
---|
1881 | reg [M -1:0] metric_27 ; |
---|
1882 | reg [M -1:0] metric_28 ; |
---|
1883 | reg [M -1:0] metric_29 ; |
---|
1884 | reg [M -1:0] metric_30 ; |
---|
1885 | reg [M -1:0] metric_31 ; |
---|
1886 | reg [M -1:0] metric_32; |
---|
1887 | reg [M -1:0] metric_33; |
---|
1888 | reg [M -1:0] metric_34; |
---|
1889 | reg [M -1:0] metric_35; |
---|
1890 | reg [M -1:0] metric_36; |
---|
1891 | reg [M -1:0] metric_37; |
---|
1892 | reg [M -1:0] metric_38; |
---|
1893 | reg [M -1:0] metric_39; |
---|
1894 | reg [M -1:0] metric_40; |
---|
1895 | reg [M -1:0] metric_41; |
---|
1896 | reg [M -1:0] metric_42 ; |
---|
1897 | reg [M -1:0] metric_43 ; |
---|
1898 | reg [M -1:0] metric_44 ; |
---|
1899 | reg [M -1:0] metric_45 ; |
---|
1900 | reg [M -1:0] metric_46 ; |
---|
1901 | reg [M -1:0] metric_47 ; |
---|
1902 | reg [M -1:0] metric_48; |
---|
1903 | reg [M -1:0] metric_49; |
---|
1904 | reg [M -1:0] metric_50; |
---|
1905 | reg [M -1:0] metric_51; |
---|
1906 | reg [M -1:0] metric_52; |
---|
1907 | reg [M -1:0] metric_53; |
---|
1908 | reg [M -1:0] metric_54; |
---|
1909 | reg [M -1:0] metric_55; |
---|
1910 | reg [M -1:0] metric_56; |
---|
1911 | reg [M -1:0] metric_57; |
---|
1912 | reg [M -1:0] metric_58 ; |
---|
1913 | reg [M -1:0] metric_59 ; |
---|
1914 | reg [M -1:0] metric_60 ; |
---|
1915 | reg [M -1:0] metric_61 ; |
---|
1916 | reg [M -1:0] metric_62 ; |
---|
1917 | reg [M -1:0] metric_63 ; |
---|
1918 | |
---|
1919 | wire [M -1:0] metric_next_0 ; |
---|
1920 | wire [M -1:0] metric_next_1 ; |
---|
1921 | wire [M -1:0] metric_next_2 ; |
---|
1922 | wire [M -1:0] metric_next_3 ; |
---|
1923 | wire [M -1:0] metric_next_4 ; |
---|
1924 | wire [M -1:0] metric_next_5 ; |
---|
1925 | wire [M -1:0] metric_next_6 ; |
---|
1926 | wire [M -1:0] metric_next_7 ; |
---|
1927 | wire [M -1:0] metric_next_8 ; |
---|
1928 | wire [M -1:0] metric_next_9 ; |
---|
1929 | wire [M -1:0] metric_next_10 ; |
---|
1930 | wire [M -1:0] metric_next_11 ; |
---|
1931 | wire [M -1:0] metric_next_12 ; |
---|
1932 | wire [M -1:0] metric_next_13 ; |
---|
1933 | wire [M -1:0] metric_next_14 ; |
---|
1934 | wire [M -1:0] metric_next_15 ; |
---|
1935 | wire [M -1:0] metric_next_16; |
---|
1936 | wire [M -1:0] metric_next_17; |
---|
1937 | wire [M -1:0] metric_next_18; |
---|
1938 | wire [M -1:0] metric_next_19; |
---|
1939 | wire [M -1:0] metric_next_20; |
---|
1940 | wire [M -1:0] metric_next_21; |
---|
1941 | wire [M -1:0] metric_next_22; |
---|
1942 | wire [M -1:0] metric_next_23; |
---|
1943 | wire [M -1:0] metric_next_24; |
---|
1944 | wire [M -1:0] metric_next_25; |
---|
1945 | wire [M -1:0] metric_next_26 ; |
---|
1946 | wire [M -1:0] metric_next_27 ; |
---|
1947 | wire [M -1:0] metric_next_28 ; |
---|
1948 | wire [M -1:0] metric_next_29 ; |
---|
1949 | wire [M -1:0] metric_next_30 ; |
---|
1950 | wire [M -1:0] metric_next_31 ; |
---|
1951 | wire [M -1:0] metric_next_32; |
---|
1952 | wire [M -1:0] metric_next_33; |
---|
1953 | wire [M -1:0] metric_next_34; |
---|
1954 | wire [M -1:0] metric_next_35; |
---|
1955 | wire [M -1:0] metric_next_36; |
---|
1956 | wire [M -1:0] metric_next_37; |
---|
1957 | wire [M -1:0] metric_next_38; |
---|
1958 | wire [M -1:0] metric_next_39; |
---|
1959 | wire [M -1:0] metric_next_40; |
---|
1960 | wire [M -1:0] metric_next_41; |
---|
1961 | wire [M -1:0] metric_next_42 ; |
---|
1962 | wire [M -1:0] metric_next_43 ; |
---|
1963 | wire [M -1:0] metric_next_44 ; |
---|
1964 | wire [M -1:0] metric_next_45 ; |
---|
1965 | wire [M -1:0] metric_next_46 ; |
---|
1966 | wire [M -1:0] metric_next_47 ; |
---|
1967 | wire [M -1:0] metric_next_48; |
---|
1968 | wire [M -1:0] metric_next_49; |
---|
1969 | wire [M -1:0] metric_next_50; |
---|
1970 | wire [M -1:0] metric_next_51; |
---|
1971 | wire [M -1:0] metric_next_52; |
---|
1972 | wire [M -1:0] metric_next_53; |
---|
1973 | wire [M -1:0] metric_next_54; |
---|
1974 | wire [M -1:0] metric_next_55; |
---|
1975 | wire [M -1:0] metric_next_56; |
---|
1976 | wire [M -1:0] metric_next_57; |
---|
1977 | wire [M -1:0] metric_next_58 ; |
---|
1978 | wire [M -1:0] metric_next_59 ; |
---|
1979 | wire [M -1:0] metric_next_60 ; |
---|
1980 | wire [M -1:0] metric_next_61 ; |
---|
1981 | wire [M -1:0] metric_next_62 ; |
---|
1982 | wire [M -1:0] metric_next_63 ; |
---|
1983 | |
---|
1984 | wire [M -1:0] metric_A_0 ; |
---|
1985 | wire [M -1:0] metric_B_0 ; |
---|
1986 | wire [M -1:0] metric_A_1 ; |
---|
1987 | wire [M -1:0] metric_B_1 ; |
---|
1988 | wire [M -1:0] metric_A_2 ; |
---|
1989 | wire [M -1:0] metric_B_2 ; |
---|
1990 | wire [M -1:0] metric_A_3 ; |
---|
1991 | wire [M -1:0] metric_B_3 ; |
---|
1992 | wire [M -1:0] metric_A_4 ; |
---|
1993 | wire [M -1:0] metric_B_4 ; |
---|
1994 | wire [M -1:0] metric_A_5 ; |
---|
1995 | wire [M -1:0] metric_B_5 ; |
---|
1996 | wire [M -1:0] metric_A_6 ; |
---|
1997 | wire [M -1:0] metric_B_6 ; |
---|
1998 | wire [M -1:0] metric_A_7 ; |
---|
1999 | wire [M -1:0] metric_B_7 ; |
---|
2000 | wire [M -1:0] metric_A_8 ; |
---|
2001 | wire [M -1:0] metric_B_8 ; |
---|
2002 | wire [M -1:0] metric_A_9 ; |
---|
2003 | wire [M -1:0] metric_B_9 ; |
---|
2004 | wire [M -1:0] metric_A_10 ; |
---|
2005 | wire [M -1:0] metric_B_10 ; |
---|
2006 | wire [M -1:0] metric_A_11 ; |
---|
2007 | wire [M -1:0] metric_B_11 ; |
---|
2008 | wire [M -1:0] metric_A_12 ; |
---|
2009 | wire [M -1:0] metric_B_12 ; |
---|
2010 | wire [M -1:0] metric_A_13 ; |
---|
2011 | wire [M -1:0] metric_B_13 ; |
---|
2012 | wire [M -1:0] metric_A_14 ; |
---|
2013 | wire [M -1:0] metric_B_14 ; |
---|
2014 | wire [M -1:0] metric_A_15 ; |
---|
2015 | wire [M -1:0] metric_B_15 ; |
---|
2016 | wire [M -1:0] metric_A_16; |
---|
2017 | wire [M -1:0] metric_B_16; |
---|
2018 | wire [M -1:0] metric_A_17; |
---|
2019 | wire [M -1:0] metric_B_17; |
---|
2020 | wire [M -1:0] metric_A_18; |
---|
2021 | wire [M -1:0] metric_B_18; |
---|
2022 | wire [M -1:0] metric_A_19; |
---|
2023 | wire [M -1:0] metric_B_19; |
---|
2024 | wire [M -1:0] metric_A_20; |
---|
2025 | wire [M -1:0] metric_B_20; |
---|
2026 | wire [M -1:0] metric_A_21; |
---|
2027 | wire [M -1:0] metric_B_21; |
---|
2028 | wire [M -1:0] metric_A_22; |
---|
2029 | wire [M -1:0] metric_B_22; |
---|
2030 | wire [M -1:0] metric_A_23; |
---|
2031 | wire [M -1:0] metric_B_23; |
---|
2032 | wire [M -1:0] metric_A_24; |
---|
2033 | wire [M -1:0] metric_B_24; |
---|
2034 | wire [M -1:0] metric_A_25; |
---|
2035 | wire [M -1:0] metric_B_25; |
---|
2036 | wire [M -1:0] metric_A_26 ; |
---|
2037 | wire [M -1:0] metric_B_26 ; |
---|
2038 | wire [M -1:0] metric_A_27 ; |
---|
2039 | wire [M -1:0] metric_B_27 ; |
---|
2040 | wire [M -1:0] metric_A_28 ; |
---|
2041 | wire [M -1:0] metric_B_28 ; |
---|
2042 | wire [M -1:0] metric_A_29 ; |
---|
2043 | wire [M -1:0] metric_B_29 ; |
---|
2044 | wire [M -1:0] metric_A_30 ; |
---|
2045 | wire [M -1:0] metric_B_30 ; |
---|
2046 | wire [M -1:0] metric_A_31 ; |
---|
2047 | wire [M -1:0] metric_B_31 ; |
---|
2048 | wire [M -1:0] metric_A_32; |
---|
2049 | wire [M -1:0] metric_B_32; |
---|
2050 | wire [M -1:0] metric_A_33; |
---|
2051 | wire [M -1:0] metric_B_33; |
---|
2052 | wire [M -1:0] metric_A_34; |
---|
2053 | wire [M -1:0] metric_B_34; |
---|
2054 | wire [M -1:0] metric_A_35; |
---|
2055 | wire [M -1:0] metric_B_35; |
---|
2056 | wire [M -1:0] metric_A_36; |
---|
2057 | wire [M -1:0] metric_B_36; |
---|
2058 | wire [M -1:0] metric_A_37; |
---|
2059 | wire [M -1:0] metric_B_37; |
---|
2060 | wire [M -1:0] metric_A_38; |
---|
2061 | wire [M -1:0] metric_B_38; |
---|
2062 | wire [M -1:0] metric_A_39; |
---|
2063 | wire [M -1:0] metric_B_39; |
---|
2064 | wire [M -1:0] metric_A_40; |
---|
2065 | wire [M -1:0] metric_B_40; |
---|
2066 | wire [M -1:0] metric_A_41; |
---|
2067 | wire [M -1:0] metric_B_41; |
---|
2068 | wire [M -1:0] metric_A_42 ; |
---|
2069 | wire [M -1:0] metric_B_42 ; |
---|
2070 | wire [M -1:0] metric_A_43 ; |
---|
2071 | wire [M -1:0] metric_B_43 ; |
---|
2072 | wire [M -1:0] metric_A_44 ; |
---|
2073 | wire [M -1:0] metric_B_44 ; |
---|
2074 | wire [M -1:0] metric_A_45 ; |
---|
2075 | wire [M -1:0] metric_B_45 ; |
---|
2076 | wire [M -1:0] metric_A_46 ; |
---|
2077 | wire [M -1:0] metric_B_46 ; |
---|
2078 | wire [M -1:0] metric_A_47 ; |
---|
2079 | wire [M -1:0] metric_B_47 ; |
---|
2080 | wire [M -1:0] metric_A_48; |
---|
2081 | wire [M -1:0] metric_B_48; |
---|
2082 | wire [M -1:0] metric_A_49; |
---|
2083 | wire [M -1:0] metric_B_49; |
---|
2084 | wire [M -1:0] metric_A_50; |
---|
2085 | wire [M -1:0] metric_B_50; |
---|
2086 | wire [M -1:0] metric_A_51; |
---|
2087 | wire [M -1:0] metric_B_51; |
---|
2088 | wire [M -1:0] metric_A_52; |
---|
2089 | wire [M -1:0] metric_B_52; |
---|
2090 | wire [M -1:0] metric_A_53; |
---|
2091 | wire [M -1:0] metric_B_53; |
---|
2092 | wire [M -1:0] metric_A_54; |
---|
2093 | wire [M -1:0] metric_B_54; |
---|
2094 | wire [M -1:0] metric_A_55; |
---|
2095 | wire [M -1:0] metric_B_55; |
---|
2096 | wire [M -1:0] metric_A_56; |
---|
2097 | wire [M -1:0] metric_B_56; |
---|
2098 | wire [M -1:0] metric_A_57; |
---|
2099 | wire [M -1:0] metric_B_57; |
---|
2100 | wire [M -1:0] metric_A_58 ; |
---|
2101 | wire [M -1:0] metric_B_58 ; |
---|
2102 | wire [M -1:0] metric_A_59 ; |
---|
2103 | wire [M -1:0] metric_B_59 ; |
---|
2104 | wire [M -1:0] metric_A_60 ; |
---|
2105 | wire [M -1:0] metric_B_60 ; |
---|
2106 | wire [M -1:0] metric_A_61 ; |
---|
2107 | wire [M -1:0] metric_B_61 ; |
---|
2108 | wire [M -1:0] metric_A_62 ; |
---|
2109 | wire [M -1:0] metric_B_62 ; |
---|
2110 | wire [M -1:0] metric_A_63 ; |
---|
2111 | wire [M -1:0] metric_B_63 ; |
---|
2112 | |
---|
2113 | // 64 state tran |
---|
2114 | reg [0:0] tran_state_0 [TR -1:0] ; |
---|
2115 | reg [0:0] tran_state_1 [TR -1:0] ; |
---|
2116 | reg [0:0] tran_state_2 [TR -1:0] ; |
---|
2117 | reg [0:0] tran_state_3 [TR -1:0] ; |
---|
2118 | reg [0:0] tran_state_4 [TR -1:0] ; |
---|
2119 | reg [0:0] tran_state_5 [TR -1:0] ; |
---|
2120 | reg [0:0] tran_state_6 [TR -1:0] ; |
---|
2121 | reg [0:0] tran_state_7 [TR -1:0] ; |
---|
2122 | reg [0:0] tran_state_8 [TR -1:0] ; |
---|
2123 | reg [0:0] tran_state_9 [TR -1:0] ; |
---|
2124 | reg [0:0] tran_state_10 [TR -1:0] ; |
---|
2125 | reg [0:0] tran_state_11 [TR -1:0] ; |
---|
2126 | reg [0:0] tran_state_12 [TR -1:0] ; |
---|
2127 | reg [0:0] tran_state_13 [TR -1:0] ; |
---|
2128 | reg [0:0] tran_state_14 [TR -1:0] ; |
---|
2129 | reg [0:0] tran_state_15 [TR -1:0] ; |
---|
2130 | reg [0:0] tran_state_16 [TR -1:0] ; |
---|
2131 | reg [0:0] tran_state_17 [TR -1:0] ; |
---|
2132 | reg [0:0] tran_state_18 [TR -1:0] ; |
---|
2133 | reg [0:0] tran_state_19 [TR -1:0] ; |
---|
2134 | reg [0:0] tran_state_20 [TR -1:0] ; |
---|
2135 | reg [0:0] tran_state_21 [TR -1:0] ; |
---|
2136 | reg [0:0] tran_state_22 [TR -1:0] ; |
---|
2137 | reg [0:0] tran_state_23 [TR -1:0] ; |
---|
2138 | reg [0:0] tran_state_24 [TR -1:0] ; |
---|
2139 | reg [0:0] tran_state_25 [TR -1:0] ; |
---|
2140 | reg [0:0] tran_state_26 [TR -1:0] ; |
---|
2141 | reg [0:0] tran_state_27 [TR -1:0] ; |
---|
2142 | reg [0:0] tran_state_28 [TR -1:0] ; |
---|
2143 | reg [0:0] tran_state_29 [TR -1:0] ; |
---|
2144 | reg [0:0] tran_state_30 [TR -1:0] ; |
---|
2145 | reg [0:0] tran_state_31 [TR -1:0] ; |
---|
2146 | reg [0:0] tran_state_32 [TR -1:0] ; |
---|
2147 | reg [0:0] tran_state_33 [TR -1:0] ; |
---|
2148 | reg [0:0] tran_state_34 [TR -1:0] ; |
---|
2149 | reg [0:0] tran_state_35 [TR -1:0] ; |
---|
2150 | reg [0:0] tran_state_36 [TR -1:0] ; |
---|
2151 | reg [0:0] tran_state_37 [TR -1:0] ; |
---|
2152 | reg [0:0] tran_state_38 [TR -1:0] ; |
---|
2153 | reg [0:0] tran_state_39 [TR -1:0] ; |
---|
2154 | reg [0:0] tran_state_40 [TR -1:0] ; |
---|
2155 | reg [0:0] tran_state_41 [TR -1:0] ; |
---|
2156 | reg [0:0] tran_state_42 [TR -1:0] ; |
---|
2157 | reg [0:0] tran_state_43 [TR -1:0] ; |
---|
2158 | reg [0:0] tran_state_44 [TR -1:0] ; |
---|
2159 | reg [0:0] tran_state_45 [TR -1:0] ; |
---|
2160 | reg [0:0] tran_state_46 [TR -1:0] ; |
---|
2161 | reg [0:0] tran_state_47 [TR -1:0] ; |
---|
2162 | reg [0:0] tran_state_48 [TR -1:0] ; |
---|
2163 | reg [0:0] tran_state_49 [TR -1:0] ; |
---|
2164 | reg [0:0] tran_state_50 [TR -1:0] ; |
---|
2165 | reg [0:0] tran_state_51 [TR -1:0] ; |
---|
2166 | reg [0:0] tran_state_52 [TR -1:0] ; |
---|
2167 | reg [0:0] tran_state_53 [TR -1:0] ; |
---|
2168 | reg [0:0] tran_state_54 [TR -1:0] ; |
---|
2169 | reg [0:0] tran_state_55 [TR -1:0] ; |
---|
2170 | reg [0:0] tran_state_56 [TR -1:0] ; |
---|
2171 | reg [0:0] tran_state_57 [TR -1:0] ; |
---|
2172 | reg [0:0] tran_state_58 [TR -1:0] ; |
---|
2173 | reg [0:0] tran_state_59 [TR -1:0] ; |
---|
2174 | reg [0:0] tran_state_60 [TR -1:0] ; |
---|
2175 | reg [0:0] tran_state_61 [TR -1:0] ; |
---|
2176 | reg [0:0] tran_state_62 [TR -1:0] ; |
---|
2177 | reg [0:0] tran_state_63 [TR -1:0] ; |
---|
2178 | |
---|
2179 | reg [TRW -1:0] wptr ; |
---|
2180 | reg [TRW -1:0] last_wptr ; |
---|
2181 | |
---|
2182 | wire [M -1:0] diff_0 ; |
---|
2183 | wire [M -1:0] diff_1 ; |
---|
2184 | wire [M -1:0] diff_2 ; |
---|
2185 | wire [M -1:0] diff_3 ; |
---|
2186 | wire [M -1:0] diff_4 ; |
---|
2187 | wire [M -1:0] diff_5 ; |
---|
2188 | wire [M -1:0] diff_6 ; |
---|
2189 | wire [M -1:0] diff_7 ; |
---|
2190 | wire [M -1:0] diff_8 ; |
---|
2191 | wire [M -1:0] diff_9 ; |
---|
2192 | wire [M -1:0] diff_10; |
---|
2193 | wire [M -1:0] diff_11; |
---|
2194 | wire [M -1:0] diff_12; |
---|
2195 | wire [M -1:0] diff_13; |
---|
2196 | wire [M -1:0] diff_14; |
---|
2197 | wire [M -1:0] diff_15; |
---|
2198 | wire [M -1:0] diff_16; |
---|
2199 | wire [M -1:0] diff_17; |
---|
2200 | wire [M -1:0] diff_18; |
---|
2201 | wire [M -1:0] diff_19; |
---|
2202 | wire [M -1:0] diff_20; |
---|
2203 | wire [M -1:0] diff_21; |
---|
2204 | wire [M -1:0] diff_22; |
---|
2205 | wire [M -1:0] diff_23; |
---|
2206 | wire [M -1:0] diff_24; |
---|
2207 | wire [M -1:0] diff_25; |
---|
2208 | wire [M -1:0] diff_26; |
---|
2209 | wire [M -1:0] diff_27; |
---|
2210 | wire [M -1:0] diff_28; |
---|
2211 | wire [M -1:0] diff_29; |
---|
2212 | wire [M -1:0] diff_30; |
---|
2213 | wire [M -1:0] diff_31; |
---|
2214 | wire [M -1:0] diff_32; |
---|
2215 | wire [M -1:0] diff_33; |
---|
2216 | wire [M -1:0] diff_34; |
---|
2217 | wire [M -1:0] diff_35; |
---|
2218 | wire [M -1:0] diff_36; |
---|
2219 | wire [M -1:0] diff_37; |
---|
2220 | wire [M -1:0] diff_38; |
---|
2221 | wire [M -1:0] diff_39; |
---|
2222 | wire [M -1:0] diff_40; |
---|
2223 | wire [M -1:0] diff_41; |
---|
2224 | wire [M -1:0] diff_42; |
---|
2225 | wire [M -1:0] diff_43; |
---|
2226 | wire [M -1:0] diff_44; |
---|
2227 | wire [M -1:0] diff_45; |
---|
2228 | wire [M -1:0] diff_46; |
---|
2229 | wire [M -1:0] diff_47; |
---|
2230 | wire [M -1:0] diff_48; |
---|
2231 | wire [M -1:0] diff_49; |
---|
2232 | wire [M -1:0] diff_50; |
---|
2233 | wire [M -1:0] diff_51; |
---|
2234 | wire [M -1:0] diff_52; |
---|
2235 | wire [M -1:0] diff_53; |
---|
2236 | wire [M -1:0] diff_54; |
---|
2237 | wire [M -1:0] diff_55; |
---|
2238 | wire [M -1:0] diff_56; |
---|
2239 | wire [M -1:0] diff_57; |
---|
2240 | wire [M -1:0] diff_58; |
---|
2241 | wire [M -1:0] diff_59; |
---|
2242 | wire [M -1:0] diff_60; |
---|
2243 | wire [M -1:0] diff_61; |
---|
2244 | wire [M -1:0] diff_62; |
---|
2245 | wire [M -1:0] diff_63; |
---|
2246 | |
---|
2247 | reg nd ; |
---|
2248 | reg [LW -1:0] cnt ; |
---|
2249 | reg trace ; |
---|
2250 | reg trace_en ; |
---|
2251 | wire trace_done ; |
---|
2252 | reg trace_done_s0 ; |
---|
2253 | wire trace_done_pos ; |
---|
2254 | reg [TRW -1:0] trace_cnt ; |
---|
2255 | reg [L-1:0] res ; |
---|
2256 | wire [L-1:0] res_shift ; |
---|
2257 | wire [K-2: 0] init_state_i ; |
---|
2258 | reg [K-2: 0] trace_state ; |
---|
2259 | |
---|
2260 | wire [K-2: 0] cur_state0 ; |
---|
2261 | wire [K-2: 0] cur_state1 ; |
---|
2262 | wire [K-2: 0] next_state ; |
---|
2263 | reg [TRW -1:0] trace_start_wptr ; |
---|
2264 | wire [TRW -1:0] trace_start_pos ; |
---|
2265 | wire [TRW -1:0] trace_start_pos0 ; |
---|
2266 | wire [TRW -1:0] trace_start_pos1 ; |
---|
2267 | reg last_trace ; |
---|
2268 | reg last_trace_s0 ; |
---|
2269 | wire trace2 ; |
---|
2270 | reg trace2_s1 ; |
---|
2271 | reg trace2_s2 ; |
---|
2272 | reg trace_pos ; |
---|
2273 | wire trace_pos_i ; |
---|
2274 | reg [LW -1:0] last_trace_num ; |
---|
2275 | reg flush_en ; |
---|
2276 | wire flush ; |
---|
2277 | reg done_i ; |
---|
2278 | |
---|
2279 | wire [K-2: 0] state_0 ; |
---|
2280 | wire [K-2: 0] state_1 ; |
---|
2281 | wire [K-2: 0] state_2 ; |
---|
2282 | wire [K-2: 0] state_3 ; |
---|
2283 | wire [K-2: 0] state_4 ; |
---|
2284 | wire [K-2: 0] state_5 ; |
---|
2285 | wire [K-2: 0] state_6 ; |
---|
2286 | wire [K-2: 0] state_7 ; |
---|
2287 | wire [K-2: 0] state_8 ; |
---|
2288 | wire [K-2: 0] state_9 ; |
---|
2289 | wire [K-2: 0] state_10 ; |
---|
2290 | wire [K-2: 0] state_11 ; |
---|
2291 | wire [K-2: 0] state_12 ; |
---|
2292 | wire [K-2: 0] state_13 ; |
---|
2293 | wire [K-2: 0] state_14 ; |
---|
2294 | wire [K-2: 0] state_15 ; |
---|
2295 | |
---|
2296 | wire [K-2: 0] state_s1_0 ; |
---|
2297 | wire [K-2: 0] state_s1_1 ; |
---|
2298 | wire [K-2: 0] state_s1_2 ; |
---|
2299 | wire [K-2: 0] state_s1_3 ; |
---|
2300 | |
---|
2301 | wire [K-2: 0] state_s2_0 ; |
---|
2302 | |
---|
2303 | wire [M-1: 0] max_0 ; |
---|
2304 | wire [M-1: 0] max_1 ; |
---|
2305 | wire [M-1: 0] max_2 ; |
---|
2306 | wire [M-1: 0] max_3 ; |
---|
2307 | wire [M-1: 0] max_4 ; |
---|
2308 | wire [M-1: 0] max_5 ; |
---|
2309 | wire [M-1: 0] max_6 ; |
---|
2310 | wire [M-1: 0] max_7 ; |
---|
2311 | wire [M-1: 0] max_8 ; |
---|
2312 | wire [M-1: 0] max_9 ; |
---|
2313 | wire [M-1: 0] max_10 ; |
---|
2314 | wire [M-1: 0] max_11 ; |
---|
2315 | wire [M-1: 0] max_12 ; |
---|
2316 | wire [M-1: 0] max_13 ; |
---|
2317 | wire [M-1: 0] max_14 ; |
---|
2318 | wire [M-1: 0] max_15 ; |
---|
2319 | |
---|
2320 | wire [M-1: 0] max_s1_0 ; |
---|
2321 | wire [M-1: 0] max_s1_1 ; |
---|
2322 | wire [M-1: 0] max_s1_2 ; |
---|
2323 | wire [M-1: 0] max_s1_3 ; |
---|
2324 | |
---|
2325 | //reg [M-1: 0] max_s1_0_s0 ; |
---|
2326 | //reg [M-1: 0] max_s1_1_s0 ; |
---|
2327 | //reg [M-1: 0] max_s1_2_s0 ; |
---|
2328 | //reg [M-1: 0] max_s1_3_s0 ; |
---|
2329 | |
---|
2330 | //wire [M-1: 0] max_s2_0 ; |
---|
2331 | |
---|
2332 | wire [N -1:0] tran_all_0 ; |
---|
2333 | wire [N -1:0] tran_all_1 ; |
---|
2334 | |
---|
2335 | reg [6:0] flush_cnt ; |
---|
2336 | wire [LW -1:0] rem_i ; |
---|
2337 | reg [LW -1:0] last_cnt ; |
---|
2338 | wire [LW -1:0] last_cnt_next ; |
---|
2339 | reg last_trace_d0 ; |
---|
2340 | reg last_trace_d1 ; |
---|
2341 | reg last_trace_d2 ; |
---|
2342 | reg last_trace_d3 ; |
---|
2343 | reg last_trace_d4 ; |
---|
2344 | reg last_trace_d5 ; |
---|
2345 | reg one_more_out ; |
---|
2346 | reg in_dec ; |
---|
2347 | wire dv_in_gate ; |
---|
2348 | reg trace_pos_s0 ; |
---|
2349 | |
---|
2350 | //====================================== |
---|
2351 | // Main body of code |
---|
2352 | //====================================== |
---|
2353 | assign dv_out = trace_done_pos | one_more_out ; |
---|
2354 | assign res_shift = res << last_trace_num ; |
---|
2355 | assign dout = res_shift [L -1:C] ; |
---|
2356 | assign remain = last_trace ? rem_i : 0 ; |
---|
2357 | assign done = dv_out & done_i ; |
---|
2358 | assign rem_i = ~last_cnt_next[LW-1] ? 0 : last_cnt ; |
---|
2359 | |
---|
2360 | //assign dv_in_gate = dv_in & in_dec ; |
---|
2361 | assign dv_in_gate = dv_in & in_dec & (~packet_end) ; |
---|
2362 | |
---|
2363 | always @ (posedge clk or negedge nrst) |
---|
2364 | if (~nrst) |
---|
2365 | in_dec <= 1'b0 ; |
---|
2366 | else if (packet_start) |
---|
2367 | in_dec <= 1'b1 ; |
---|
2368 | else if (packet_end) |
---|
2369 | in_dec <= 1'b0 ; |
---|
2370 | |
---|
2371 | |
---|
2372 | //{coe_0 coe_1}, generated from C model gen_table |
---|
2373 | //0 0; |
---|
2374 | //0 1; |
---|
2375 | //1 0; |
---|
2376 | //1 1; |
---|
2377 | //1 0; |
---|
2378 | //1 1; |
---|
2379 | //0 0; |
---|
2380 | //0 1; |
---|
2381 | |
---|
2382 | assign branch_00 = {llr1[SW -1], llr1} + {llr0[SW -1], llr0} ; //LLR(bit1) + LLR(bit0) |
---|
2383 | assign branch_01 = {llr1[SW -1], llr1} ; //LLR(bit1) |
---|
2384 | assign branch_10 = {llr0[SW -1], llr0} ; //LLR(bit0) |
---|
2385 | assign branch_11 = 0 ; //0 |
---|
2386 | |
---|
2387 | assign branch_A_0 = branch_00 ; |
---|
2388 | assign branch_B_0 = branch_11 ; |
---|
2389 | assign branch_A_1 = branch_10 ; |
---|
2390 | assign branch_B_1 = branch_01 ; |
---|
2391 | assign branch_A_2 = branch_00 ; |
---|
2392 | assign branch_B_2 = branch_11 ; |
---|
2393 | assign branch_A_3 = branch_10 ; |
---|
2394 | assign branch_B_3 = branch_01 ; |
---|
2395 | assign branch_A_4 = branch_11 ; |
---|
2396 | assign branch_B_4 = branch_00 ; |
---|
2397 | assign branch_A_5 = branch_01 ; |
---|
2398 | assign branch_B_5 = branch_10 ; |
---|
2399 | assign branch_A_6 = branch_11 ; |
---|
2400 | assign branch_B_6 = branch_00 ; |
---|
2401 | assign branch_A_7 = branch_01 ; |
---|
2402 | assign branch_B_7 = branch_10 ; |
---|
2403 | assign branch_A_8 = branch_11 ; |
---|
2404 | assign branch_B_8 = branch_00 ; |
---|
2405 | assign branch_A_9 = branch_01 ; |
---|
2406 | assign branch_B_9 = branch_10 ; |
---|
2407 | assign branch_A_10 = branch_11 ; |
---|
2408 | assign branch_B_10 = branch_00 ; |
---|
2409 | assign branch_A_11 = branch_01 ; |
---|
2410 | assign branch_B_11 = branch_10 ; |
---|
2411 | assign branch_A_12 = branch_00 ; |
---|
2412 | assign branch_B_12 = branch_11 ; |
---|
2413 | assign branch_A_13 = branch_10 ; |
---|
2414 | assign branch_B_13 = branch_01 ; |
---|
2415 | assign branch_A_14 = branch_00 ; |
---|
2416 | assign branch_B_14 = branch_11 ; |
---|
2417 | assign branch_A_15 = branch_10 ; |
---|
2418 | assign branch_B_15 = branch_01 ; |
---|
2419 | assign branch_A_16 = branch_01 ; |
---|
2420 | assign branch_B_16 = branch_10 ; |
---|
2421 | assign branch_A_17 = branch_11 ; |
---|
2422 | assign branch_B_17 = branch_00 ; |
---|
2423 | assign branch_A_18 = branch_01 ; |
---|
2424 | assign branch_B_18 = branch_10 ; |
---|
2425 | assign branch_A_19 = branch_11 ; |
---|
2426 | assign branch_B_19 = branch_00 ; |
---|
2427 | assign branch_A_20 = branch_10 ; |
---|
2428 | assign branch_B_20 = branch_01 ; |
---|
2429 | assign branch_A_21 = branch_00 ; |
---|
2430 | assign branch_B_21 = branch_11 ; |
---|
2431 | assign branch_A_22 = branch_10 ; |
---|
2432 | assign branch_B_22 = branch_01 ; |
---|
2433 | assign branch_A_23 = branch_00 ; |
---|
2434 | assign branch_B_23 = branch_11 ; |
---|
2435 | assign branch_A_24 = branch_10 ; |
---|
2436 | assign branch_B_24 = branch_01 ; |
---|
2437 | assign branch_A_25 = branch_00 ; |
---|
2438 | assign branch_B_25 = branch_11 ; |
---|
2439 | assign branch_A_26 = branch_10 ; |
---|
2440 | assign branch_B_26 = branch_01 ; |
---|
2441 | assign branch_A_27 = branch_00 ; |
---|
2442 | assign branch_B_27 = branch_11 ; |
---|
2443 | assign branch_A_28 = branch_01 ; |
---|
2444 | assign branch_B_28 = branch_10 ; |
---|
2445 | assign branch_A_29 = branch_11 ; |
---|
2446 | assign branch_B_29 = branch_00 ; |
---|
2447 | assign branch_A_30 = branch_01 ; |
---|
2448 | assign branch_B_30 = branch_10 ; |
---|
2449 | assign branch_A_31 = branch_11 ; |
---|
2450 | assign branch_B_31 = branch_00 ; |
---|
2451 | |
---|
2452 | assign branch_A_32 = branch_B_0 ; |
---|
2453 | assign branch_B_32 = branch_A_0 ; |
---|
2454 | assign branch_A_33 = branch_B_1 ; |
---|
2455 | assign branch_B_33 = branch_A_1 ; |
---|
2456 | assign branch_A_34 = branch_B_2 ; |
---|
2457 | assign branch_B_34 = branch_A_2 ; |
---|
2458 | assign branch_A_35 = branch_B_3 ; |
---|
2459 | assign branch_B_35 = branch_A_3 ; |
---|
2460 | assign branch_A_36 = branch_B_4 ; |
---|
2461 | assign branch_B_36 = branch_A_4 ; |
---|
2462 | assign branch_A_37 = branch_B_5 ; |
---|
2463 | assign branch_B_37 = branch_A_5 ; |
---|
2464 | assign branch_A_38 = branch_B_6 ; |
---|
2465 | assign branch_B_38 = branch_A_6 ; |
---|
2466 | assign branch_A_39 = branch_B_7 ; |
---|
2467 | assign branch_B_39 = branch_A_7 ; |
---|
2468 | assign branch_A_40 = branch_B_8 ; |
---|
2469 | assign branch_B_40 = branch_A_8 ; |
---|
2470 | assign branch_A_41 = branch_B_9 ; |
---|
2471 | assign branch_B_41 = branch_A_9 ; |
---|
2472 | assign branch_A_42 = branch_B_10 ; |
---|
2473 | assign branch_B_42 = branch_A_10 ; |
---|
2474 | assign branch_A_43 = branch_B_11 ; |
---|
2475 | assign branch_B_43 = branch_A_11 ; |
---|
2476 | assign branch_A_44 = branch_B_12 ; |
---|
2477 | assign branch_B_44 = branch_A_12 ; |
---|
2478 | assign branch_A_45 = branch_B_13 ; |
---|
2479 | assign branch_B_45 = branch_A_13 ; |
---|
2480 | assign branch_A_46 = branch_B_14 ; |
---|
2481 | assign branch_B_46 = branch_A_14 ; |
---|
2482 | assign branch_A_47 = branch_B_15 ; |
---|
2483 | assign branch_B_47 = branch_A_15 ; |
---|
2484 | assign branch_A_48 = branch_B_16 ; |
---|
2485 | assign branch_B_48 = branch_A_16 ; |
---|
2486 | assign branch_A_49 = branch_B_17 ; |
---|
2487 | assign branch_B_49 = branch_A_17 ; |
---|
2488 | assign branch_A_50 = branch_B_18 ; |
---|
2489 | assign branch_B_50 = branch_A_18 ; |
---|
2490 | assign branch_A_51 = branch_B_19 ; |
---|
2491 | assign branch_B_51 = branch_A_19 ; |
---|
2492 | assign branch_A_52 = branch_B_20 ; |
---|
2493 | assign branch_B_52 = branch_A_20 ; |
---|
2494 | assign branch_A_53 = branch_B_21 ; |
---|
2495 | assign branch_B_53 = branch_A_21 ; |
---|
2496 | assign branch_A_54 = branch_B_22 ; |
---|
2497 | assign branch_B_54 = branch_A_22 ; |
---|
2498 | assign branch_A_55 = branch_B_23 ; |
---|
2499 | assign branch_B_55 = branch_A_23 ; |
---|
2500 | assign branch_A_56 = branch_B_24 ; |
---|
2501 | assign branch_B_56 = branch_A_24 ; |
---|
2502 | assign branch_A_57 = branch_B_25 ; |
---|
2503 | assign branch_B_57 = branch_A_25 ; |
---|
2504 | assign branch_A_58 = branch_B_26 ; |
---|
2505 | assign branch_B_58 = branch_A_26 ; |
---|
2506 | assign branch_A_59 = branch_B_27 ; |
---|
2507 | assign branch_B_59 = branch_A_27 ; |
---|
2508 | assign branch_A_60 = branch_B_28 ; |
---|
2509 | assign branch_B_60 = branch_A_28 ; |
---|
2510 | assign branch_A_61 = branch_B_29 ; |
---|
2511 | assign branch_B_61 = branch_A_29 ; |
---|
2512 | assign branch_A_62 = branch_B_30 ; |
---|
2513 | assign branch_B_62 = branch_A_30 ; |
---|
2514 | assign branch_A_63 = branch_B_31 ; |
---|
2515 | assign branch_B_63 = branch_A_31 ; |
---|
2516 | |
---|
2517 | assign metric_A_0 = metric_0 + {{(M -SW -1){branch_A_0[SW]}}, branch_A_0} ; |
---|
2518 | assign metric_B_0 = metric_1 + {{(M -SW -1){branch_B_0[SW]}}, branch_B_0} ; |
---|
2519 | assign metric_A_1 = metric_2 + {{(M -SW -1){branch_A_1[SW]}}, branch_A_1} ; |
---|
2520 | assign metric_B_1 = metric_3 + {{(M -SW -1){branch_B_1[SW]}}, branch_B_1} ; |
---|
2521 | assign metric_A_2 = metric_4 + {{(M -SW -1){branch_A_2[SW]}}, branch_A_2} ; |
---|
2522 | assign metric_B_2 = metric_5 + {{(M -SW -1){branch_B_2[SW]}}, branch_B_2} ; |
---|
2523 | assign metric_A_3 = metric_6 + {{(M -SW -1){branch_A_3[SW]}}, branch_A_3} ; |
---|
2524 | assign metric_B_3 = metric_7 + {{(M -SW -1){branch_B_3[SW]}}, branch_B_3} ; |
---|
2525 | assign metric_A_4 = metric_8 + {{(M -SW -1){branch_A_4[SW]}}, branch_A_4} ; |
---|
2526 | assign metric_B_4 = metric_9 + {{(M -SW -1){branch_B_4[SW]}}, branch_B_4} ; |
---|
2527 | assign metric_A_5 = metric_10 + {{(M -SW -1){branch_A_5[SW]}}, branch_A_5} ; |
---|
2528 | assign metric_B_5 = metric_11 + {{(M -SW -1){branch_B_5[SW]}}, branch_B_5} ; |
---|
2529 | assign metric_A_6 = metric_12 + {{(M -SW -1){branch_A_6[SW]}}, branch_A_6} ; |
---|
2530 | assign metric_B_6 = metric_13 + {{(M -SW -1){branch_B_6[SW]}}, branch_B_6} ; |
---|
2531 | assign metric_A_7 = metric_14 + {{(M -SW -1){branch_A_7[SW]}}, branch_A_7} ; |
---|
2532 | assign metric_B_7 = metric_15 + {{(M -SW -1){branch_B_7[SW]}}, branch_B_7} ; |
---|
2533 | assign metric_A_8 = metric_16 + {{(M -SW -1){branch_A_8[SW]}}, branch_A_8} ; |
---|
2534 | assign metric_B_8 = metric_17 + {{(M -SW -1){branch_B_8[SW]}}, branch_B_8} ; |
---|
2535 | assign metric_A_9 = metric_18 + {{(M -SW -1){branch_A_9[SW]}}, branch_A_9} ; |
---|
2536 | assign metric_B_9 = metric_19 + {{(M -SW -1){branch_B_9[SW]}}, branch_B_9} ; |
---|
2537 | assign metric_A_10 = metric_20 + {{(M -SW -1){branch_A_10[SW]}}, branch_A_10} ; |
---|
2538 | assign metric_B_10 = metric_21 + {{(M -SW -1){branch_B_10[SW]}}, branch_B_10} ; |
---|
2539 | assign metric_A_11 = metric_22 + {{(M -SW -1){branch_A_11[SW]}}, branch_A_11} ; |
---|
2540 | assign metric_B_11 = metric_23 + {{(M -SW -1){branch_B_11[SW]}}, branch_B_11} ; |
---|
2541 | assign metric_A_12 = metric_24 + {{(M -SW -1){branch_A_12[SW]}}, branch_A_12} ; |
---|
2542 | assign metric_B_12 = metric_25 + {{(M -SW -1){branch_B_12[SW]}}, branch_B_12} ; |
---|
2543 | assign metric_A_13 = metric_26 + {{(M -SW -1){branch_A_13[SW]}}, branch_A_13} ; |
---|
2544 | assign metric_B_13 = metric_27 + {{(M -SW -1){branch_B_13[SW]}}, branch_B_13} ; |
---|
2545 | assign metric_A_14 = metric_28 + {{(M -SW -1){branch_A_14[SW]}}, branch_A_14} ; |
---|
2546 | assign metric_B_14 = metric_29 + {{(M -SW -1){branch_B_14[SW]}}, branch_B_14} ; |
---|
2547 | assign metric_A_15 = metric_30 + {{(M -SW -1){branch_A_15[SW]}}, branch_A_15} ; |
---|
2548 | assign metric_B_15 = metric_31 + {{(M -SW -1){branch_B_15[SW]}}, branch_B_15} ; |
---|
2549 | assign metric_A_16 = metric_32 + {{(M -SW -1){branch_A_16[SW]}}, branch_A_16} ; |
---|
2550 | assign metric_B_16 = metric_33 + {{(M -SW -1){branch_B_16[SW]}}, branch_B_16} ; |
---|
2551 | assign metric_A_17 = metric_34 + {{(M -SW -1){branch_A_17[SW]}}, branch_A_17} ; |
---|
2552 | assign metric_B_17 = metric_35 + {{(M -SW -1){branch_B_17[SW]}}, branch_B_17} ; |
---|
2553 | assign metric_A_18 = metric_36 + {{(M -SW -1){branch_A_18[SW]}}, branch_A_18} ; |
---|
2554 | assign metric_B_18 = metric_37 + {{(M -SW -1){branch_B_18[SW]}}, branch_B_18} ; |
---|
2555 | assign metric_A_19 = metric_38 + {{(M -SW -1){branch_A_19[SW]}}, branch_A_19} ; |
---|
2556 | assign metric_B_19 = metric_39 + {{(M -SW -1){branch_B_19[SW]}}, branch_B_19} ; |
---|
2557 | assign metric_A_20 = metric_40 + {{(M -SW -1){branch_A_20[SW]}}, branch_A_20} ; |
---|
2558 | assign metric_B_20 = metric_41 + {{(M -SW -1){branch_B_20[SW]}}, branch_B_20} ; |
---|
2559 | assign metric_A_21 = metric_42 + {{(M -SW -1){branch_A_21[SW]}}, branch_A_21} ; |
---|
2560 | assign metric_B_21 = metric_43 + {{(M -SW -1){branch_B_21[SW]}}, branch_B_21} ; |
---|
2561 | assign metric_A_22 = metric_44 + {{(M -SW -1){branch_A_22[SW]}}, branch_A_22} ; |
---|
2562 | assign metric_B_22 = metric_45 + {{(M -SW -1){branch_B_22[SW]}}, branch_B_22} ; |
---|
2563 | assign metric_A_23 = metric_46 + {{(M -SW -1){branch_A_23[SW]}}, branch_A_23} ; |
---|
2564 | assign metric_B_23 = metric_47 + {{(M -SW -1){branch_B_23[SW]}}, branch_B_23} ; |
---|
2565 | assign metric_A_24 = metric_48 + {{(M -SW -1){branch_A_24[SW]}}, branch_A_24} ; |
---|
2566 | assign metric_B_24 = metric_49 + {{(M -SW -1){branch_B_24[SW]}}, branch_B_24} ; |
---|
2567 | assign metric_A_25 = metric_50 + {{(M -SW -1){branch_A_25[SW]}}, branch_A_25} ; |
---|
2568 | assign metric_B_25 = metric_51 + {{(M -SW -1){branch_B_25[SW]}}, branch_B_25} ; |
---|
2569 | assign metric_A_26 = metric_52 + {{(M -SW -1){branch_A_26[SW]}}, branch_A_26} ; |
---|
2570 | assign metric_B_26 = metric_53 + {{(M -SW -1){branch_B_26[SW]}}, branch_B_26} ; |
---|
2571 | assign metric_A_27 = metric_54 + {{(M -SW -1){branch_A_27[SW]}}, branch_A_27} ; |
---|
2572 | assign metric_B_27 = metric_55 + {{(M -SW -1){branch_B_27[SW]}}, branch_B_27} ; |
---|
2573 | assign metric_A_28 = metric_56 + {{(M -SW -1){branch_A_28[SW]}}, branch_A_28} ; |
---|
2574 | assign metric_B_28 = metric_57 + {{(M -SW -1){branch_B_28[SW]}}, branch_B_28} ; |
---|
2575 | assign metric_A_29 = metric_58 + {{(M -SW -1){branch_A_29[SW]}}, branch_A_29} ; |
---|
2576 | assign metric_B_29 = metric_59 + {{(M -SW -1){branch_B_29[SW]}}, branch_B_29} ; |
---|
2577 | assign metric_A_30 = metric_60 + {{(M -SW -1){branch_A_30[SW]}}, branch_A_30} ; |
---|
2578 | assign metric_B_30 = metric_61 + {{(M -SW -1){branch_B_30[SW]}}, branch_B_30} ; |
---|
2579 | assign metric_A_31 = metric_62 + {{(M -SW -1){branch_A_31[SW]}}, branch_A_31} ; |
---|
2580 | assign metric_B_31 = metric_63 + {{(M -SW -1){branch_B_31[SW]}}, branch_B_31} ; |
---|
2581 | assign metric_A_32 = metric_0 + {{(M -SW -1){branch_A_32[SW]}}, branch_A_32} ; |
---|
2582 | assign metric_B_32 = metric_1 + {{(M -SW -1){branch_B_32[SW]}}, branch_B_32} ; |
---|
2583 | assign metric_A_33 = metric_2 + {{(M -SW -1){branch_A_33[SW]}}, branch_A_33} ; |
---|
2584 | assign metric_B_33 = metric_3 + {{(M -SW -1){branch_B_33[SW]}}, branch_B_33} ; |
---|
2585 | assign metric_A_34 = metric_4 + {{(M -SW -1){branch_A_34[SW]}}, branch_A_34} ; |
---|
2586 | assign metric_B_34 = metric_5 + {{(M -SW -1){branch_B_34[SW]}}, branch_B_34} ; |
---|
2587 | assign metric_A_35 = metric_6 + {{(M -SW -1){branch_A_35[SW]}}, branch_A_35} ; |
---|
2588 | assign metric_B_35 = metric_7 + {{(M -SW -1){branch_B_35[SW]}}, branch_B_35} ; |
---|
2589 | assign metric_A_36 = metric_8 + {{(M -SW -1){branch_A_36[SW]}}, branch_A_36} ; |
---|
2590 | assign metric_B_36 = metric_9 + {{(M -SW -1){branch_B_36[SW]}}, branch_B_36} ; |
---|
2591 | assign metric_A_37 = metric_10 + {{(M -SW -1){branch_A_37[SW]}}, branch_A_37} ; |
---|
2592 | assign metric_B_37 = metric_11 + {{(M -SW -1){branch_B_37[SW]}}, branch_B_37} ; |
---|
2593 | assign metric_A_38 = metric_12 + {{(M -SW -1){branch_A_38[SW]}}, branch_A_38} ; |
---|
2594 | assign metric_B_38 = metric_13 + {{(M -SW -1){branch_B_38[SW]}}, branch_B_38} ; |
---|
2595 | assign metric_A_39 = metric_14 + {{(M -SW -1){branch_A_39[SW]}}, branch_A_39} ; |
---|
2596 | assign metric_B_39 = metric_15 + {{(M -SW -1){branch_B_39[SW]}}, branch_B_39} ; |
---|
2597 | assign metric_A_40 = metric_16 + {{(M -SW -1){branch_A_40[SW]}}, branch_A_40} ; |
---|
2598 | assign metric_B_40 = metric_17 + {{(M -SW -1){branch_B_40[SW]}}, branch_B_40} ; |
---|
2599 | assign metric_A_41 = metric_18 + {{(M -SW -1){branch_A_41[SW]}}, branch_A_41} ; |
---|
2600 | assign metric_B_41 = metric_19 + {{(M -SW -1){branch_B_41[SW]}}, branch_B_41} ; |
---|
2601 | assign metric_A_42 = metric_20 + {{(M -SW -1){branch_A_42[SW]}}, branch_A_42} ; |
---|
2602 | assign metric_B_42 = metric_21 + {{(M -SW -1){branch_B_42[SW]}}, branch_B_42} ; |
---|
2603 | assign metric_A_43 = metric_22 + {{(M -SW -1){branch_A_43[SW]}}, branch_A_43} ; |
---|
2604 | assign metric_B_43 = metric_23 + {{(M -SW -1){branch_B_43[SW]}}, branch_B_43} ; |
---|
2605 | assign metric_A_44 = metric_24 + {{(M -SW -1){branch_A_44[SW]}}, branch_A_44} ; |
---|
2606 | assign metric_B_44 = metric_25 + {{(M -SW -1){branch_B_44[SW]}}, branch_B_44} ; |
---|
2607 | assign metric_A_45 = metric_26 + {{(M -SW -1){branch_A_45[SW]}}, branch_A_45} ; |
---|
2608 | assign metric_B_45 = metric_27 + {{(M -SW -1){branch_B_45[SW]}}, branch_B_45} ; |
---|
2609 | assign metric_A_46 = metric_28 + {{(M -SW -1){branch_A_46[SW]}}, branch_A_46} ; |
---|
2610 | assign metric_B_46 = metric_29 + {{(M -SW -1){branch_B_46[SW]}}, branch_B_46} ; |
---|
2611 | assign metric_A_47 = metric_30 + {{(M -SW -1){branch_A_47[SW]}}, branch_A_47} ; |
---|
2612 | assign metric_B_47 = metric_31 + {{(M -SW -1){branch_B_47[SW]}}, branch_B_47} ; |
---|
2613 | assign metric_A_48 = metric_32 + {{(M -SW -1){branch_A_48[SW]}}, branch_A_48} ; |
---|
2614 | assign metric_B_48 = metric_33 + {{(M -SW -1){branch_B_48[SW]}}, branch_B_48} ; |
---|
2615 | assign metric_A_49 = metric_34 + {{(M -SW -1){branch_A_49[SW]}}, branch_A_49} ; |
---|
2616 | assign metric_B_49 = metric_35 + {{(M -SW -1){branch_B_49[SW]}}, branch_B_49} ; |
---|
2617 | assign metric_A_50 = metric_36 + {{(M -SW -1){branch_A_50[SW]}}, branch_A_50} ; |
---|
2618 | assign metric_B_50 = metric_37 + {{(M -SW -1){branch_B_50[SW]}}, branch_B_50} ; |
---|
2619 | assign metric_A_51 = metric_38 + {{(M -SW -1){branch_A_51[SW]}}, branch_A_51} ; |
---|
2620 | assign metric_B_51 = metric_39 + {{(M -SW -1){branch_B_51[SW]}}, branch_B_51} ; |
---|
2621 | assign metric_A_52 = metric_40 + {{(M -SW -1){branch_A_52[SW]}}, branch_A_52} ; |
---|
2622 | assign metric_B_52 = metric_41 + {{(M -SW -1){branch_B_52[SW]}}, branch_B_52} ; |
---|
2623 | assign metric_A_53 = metric_42 + {{(M -SW -1){branch_A_53[SW]}}, branch_A_53} ; |
---|
2624 | assign metric_B_53 = metric_43 + {{(M -SW -1){branch_B_53[SW]}}, branch_B_53} ; |
---|
2625 | assign metric_A_54 = metric_44 + {{(M -SW -1){branch_A_54[SW]}}, branch_A_54} ; |
---|
2626 | assign metric_B_54 = metric_45 + {{(M -SW -1){branch_B_54[SW]}}, branch_B_54} ; |
---|
2627 | assign metric_A_55 = metric_46 + {{(M -SW -1){branch_A_55[SW]}}, branch_A_55} ; |
---|
2628 | assign metric_B_55 = metric_47 + {{(M -SW -1){branch_B_55[SW]}}, branch_B_55} ; |
---|
2629 | assign metric_A_56 = metric_48 + {{(M -SW -1){branch_A_56[SW]}}, branch_A_56} ; |
---|
2630 | assign metric_B_56 = metric_49 + {{(M -SW -1){branch_B_56[SW]}}, branch_B_56} ; |
---|
2631 | assign metric_A_57 = metric_50 + {{(M -SW -1){branch_A_57[SW]}}, branch_A_57} ; |
---|
2632 | assign metric_B_57 = metric_51 + {{(M -SW -1){branch_B_57[SW]}}, branch_B_57} ; |
---|
2633 | assign metric_A_58 = metric_52 + {{(M -SW -1){branch_A_58[SW]}}, branch_A_58} ; |
---|
2634 | assign metric_B_58 = metric_53 + {{(M -SW -1){branch_B_58[SW]}}, branch_B_58} ; |
---|
2635 | assign metric_A_59 = metric_54 + {{(M -SW -1){branch_A_59[SW]}}, branch_A_59} ; |
---|
2636 | assign metric_B_59 = metric_55 + {{(M -SW -1){branch_B_59[SW]}}, branch_B_59} ; |
---|
2637 | assign metric_A_60 = metric_56 + {{(M -SW -1){branch_A_60[SW]}}, branch_A_60} ; |
---|
2638 | assign metric_B_60 = metric_57 + {{(M -SW -1){branch_B_60[SW]}}, branch_B_60} ; |
---|
2639 | assign metric_A_61 = metric_58 + {{(M -SW -1){branch_A_61[SW]}}, branch_A_61} ; |
---|
2640 | assign metric_B_61 = metric_59 + {{(M -SW -1){branch_B_61[SW]}}, branch_B_61} ; |
---|
2641 | assign metric_A_62 = metric_60 + {{(M -SW -1){branch_A_62[SW]}}, branch_A_62} ; |
---|
2642 | assign metric_B_62 = metric_61 + {{(M -SW -1){branch_B_62[SW]}}, branch_B_62} ; |
---|
2643 | assign metric_A_63 = metric_62 + {{(M -SW -1){branch_A_63[SW]}}, branch_A_63} ; |
---|
2644 | assign metric_B_63 = metric_63 + {{(M -SW -1){branch_B_63[SW]}}, branch_B_63} ; |
---|
2645 | |
---|
2646 | assign diff_0 = metric_A_0 - metric_B_0 ; |
---|
2647 | assign diff_1 = metric_A_1 - metric_B_1 ; |
---|
2648 | assign diff_2 = metric_A_2 - metric_B_2 ; |
---|
2649 | assign diff_3 = metric_A_3 - metric_B_3 ; |
---|
2650 | assign diff_4 = metric_A_4 - metric_B_4 ; |
---|
2651 | assign diff_5 = metric_A_5 - metric_B_5 ; |
---|
2652 | assign diff_6 = metric_A_6 - metric_B_6 ; |
---|
2653 | assign diff_7 = metric_A_7 - metric_B_7 ; |
---|
2654 | assign diff_8 = metric_A_8 - metric_B_8 ; |
---|
2655 | assign diff_9 = metric_A_9 - metric_B_9 ; |
---|
2656 | assign diff_10 = metric_A_10 - metric_B_10 ; |
---|
2657 | assign diff_11 = metric_A_11 - metric_B_11 ; |
---|
2658 | assign diff_12 = metric_A_12 - metric_B_12 ; |
---|
2659 | assign diff_13 = metric_A_13 - metric_B_13 ; |
---|
2660 | assign diff_14 = metric_A_14 - metric_B_14 ; |
---|
2661 | assign diff_15 = metric_A_15 - metric_B_15 ; |
---|
2662 | assign diff_16 = metric_A_16 - metric_B_16 ; |
---|
2663 | assign diff_17 = metric_A_17 - metric_B_17 ; |
---|
2664 | assign diff_18 = metric_A_18 - metric_B_18 ; |
---|
2665 | assign diff_19 = metric_A_19 - metric_B_19 ; |
---|
2666 | assign diff_20 = metric_A_20 - metric_B_20 ; |
---|
2667 | assign diff_21 = metric_A_21 - metric_B_21 ; |
---|
2668 | assign diff_22 = metric_A_22 - metric_B_22 ; |
---|
2669 | assign diff_23 = metric_A_23 - metric_B_23 ; |
---|
2670 | assign diff_24 = metric_A_24 - metric_B_24 ; |
---|
2671 | assign diff_25 = metric_A_25 - metric_B_25 ; |
---|
2672 | assign diff_26 = metric_A_26 - metric_B_26 ; |
---|
2673 | assign diff_27 = metric_A_27 - metric_B_27 ; |
---|
2674 | assign diff_28 = metric_A_28 - metric_B_28 ; |
---|
2675 | assign diff_29 = metric_A_29 - metric_B_29 ; |
---|
2676 | assign diff_30 = metric_A_30 - metric_B_30 ; |
---|
2677 | assign diff_31 = metric_A_31 - metric_B_31 ; |
---|
2678 | assign diff_32 = metric_A_32 - metric_B_32 ; |
---|
2679 | assign diff_33 = metric_A_33 - metric_B_33 ; |
---|
2680 | assign diff_34 = metric_A_34 - metric_B_34 ; |
---|
2681 | assign diff_35 = metric_A_35 - metric_B_35 ; |
---|
2682 | assign diff_36 = metric_A_36 - metric_B_36 ; |
---|
2683 | assign diff_37 = metric_A_37 - metric_B_37 ; |
---|
2684 | assign diff_38 = metric_A_38 - metric_B_38 ; |
---|
2685 | assign diff_39 = metric_A_39 - metric_B_39 ; |
---|
2686 | assign diff_40 = metric_A_40 - metric_B_40 ; |
---|
2687 | assign diff_41 = metric_A_41 - metric_B_41 ; |
---|
2688 | assign diff_42 = metric_A_42 - metric_B_42 ; |
---|
2689 | assign diff_43 = metric_A_43 - metric_B_43 ; |
---|
2690 | assign diff_44 = metric_A_44 - metric_B_44 ; |
---|
2691 | assign diff_45 = metric_A_45 - metric_B_45 ; |
---|
2692 | assign diff_46 = metric_A_46 - metric_B_46 ; |
---|
2693 | assign diff_47 = metric_A_47 - metric_B_47 ; |
---|
2694 | assign diff_48 = metric_A_48 - metric_B_48 ; |
---|
2695 | assign diff_49 = metric_A_49 - metric_B_49 ; |
---|
2696 | assign diff_50 = metric_A_50 - metric_B_50 ; |
---|
2697 | assign diff_51 = metric_A_51 - metric_B_51 ; |
---|
2698 | assign diff_52 = metric_A_52 - metric_B_52 ; |
---|
2699 | assign diff_53 = metric_A_53 - metric_B_53 ; |
---|
2700 | assign diff_54 = metric_A_54 - metric_B_54 ; |
---|
2701 | assign diff_55 = metric_A_55 - metric_B_55 ; |
---|
2702 | assign diff_56 = metric_A_56 - metric_B_56 ; |
---|
2703 | assign diff_57 = metric_A_57 - metric_B_57 ; |
---|
2704 | assign diff_58 = metric_A_58 - metric_B_58 ; |
---|
2705 | assign diff_59 = metric_A_59 - metric_B_59 ; |
---|
2706 | assign diff_60 = metric_A_60 - metric_B_60 ; |
---|
2707 | assign diff_61 = metric_A_61 - metric_B_61 ; |
---|
2708 | assign diff_62 = metric_A_62 - metric_B_62 ; |
---|
2709 | assign diff_63 = metric_A_63 - metric_B_63 ; |
---|
2710 | |
---|
2711 | assign metric_next_0 = diff_0 [M -1] ? metric_B_0 : metric_A_0 ; |
---|
2712 | assign metric_next_1 = diff_1 [M -1] ? metric_B_1 : metric_A_1 ; |
---|
2713 | assign metric_next_2 = diff_2 [M -1] ? metric_B_2 : metric_A_2 ; |
---|
2714 | assign metric_next_3 = diff_3 [M -1] ? metric_B_3 : metric_A_3 ; |
---|
2715 | assign metric_next_4 = diff_4 [M -1] ? metric_B_4 : metric_A_4 ; |
---|
2716 | assign metric_next_5 = diff_5 [M -1] ? metric_B_5 : metric_A_5 ; |
---|
2717 | assign metric_next_6 = diff_6 [M -1] ? metric_B_6 : metric_A_6 ; |
---|
2718 | assign metric_next_7 = diff_7 [M -1] ? metric_B_7 : metric_A_7 ; |
---|
2719 | assign metric_next_8 = diff_8 [M -1] ? metric_B_8 : metric_A_8 ; |
---|
2720 | assign metric_next_9 = diff_9 [M -1] ? metric_B_9 : metric_A_9 ; |
---|
2721 | assign metric_next_10 = diff_10 [M -1] ? metric_B_10 : metric_A_10 ; |
---|
2722 | assign metric_next_11 = diff_11 [M -1] ? metric_B_11 : metric_A_11 ; |
---|
2723 | assign metric_next_12 = diff_12 [M -1] ? metric_B_12 : metric_A_12 ; |
---|
2724 | assign metric_next_13 = diff_13 [M -1] ? metric_B_13 : metric_A_13 ; |
---|
2725 | assign metric_next_14 = diff_14 [M -1] ? metric_B_14 : metric_A_14 ; |
---|
2726 | assign metric_next_15 = diff_15 [M -1] ? metric_B_15 : metric_A_15 ; |
---|
2727 | assign metric_next_16 = diff_16 [M -1] ? metric_B_16 : metric_A_16 ; |
---|
2728 | assign metric_next_17 = diff_17 [M -1] ? metric_B_17 : metric_A_17 ; |
---|
2729 | assign metric_next_18 = diff_18 [M -1] ? metric_B_18 : metric_A_18 ; |
---|
2730 | assign metric_next_19 = diff_19 [M -1] ? metric_B_19 : metric_A_19 ; |
---|
2731 | assign metric_next_20 = diff_20 [M -1] ? metric_B_20 : metric_A_20 ; |
---|
2732 | assign metric_next_21 = diff_21 [M -1] ? metric_B_21 : metric_A_21 ; |
---|
2733 | assign metric_next_22 = diff_22 [M -1] ? metric_B_22 : metric_A_22 ; |
---|
2734 | assign metric_next_23 = diff_23 [M -1] ? metric_B_23 : metric_A_23 ; |
---|
2735 | assign metric_next_24 = diff_24 [M -1] ? metric_B_24 : metric_A_24 ; |
---|
2736 | assign metric_next_25 = diff_25 [M -1] ? metric_B_25 : metric_A_25 ; |
---|
2737 | assign metric_next_26 = diff_26 [M -1] ? metric_B_26 : metric_A_26 ; |
---|
2738 | assign metric_next_27 = diff_27 [M -1] ? metric_B_27 : metric_A_27 ; |
---|
2739 | assign metric_next_28 = diff_28 [M -1] ? metric_B_28 : metric_A_28 ; |
---|
2740 | assign metric_next_29 = diff_29 [M -1] ? metric_B_29 : metric_A_29 ; |
---|
2741 | assign metric_next_30 = diff_30 [M -1] ? metric_B_30 : metric_A_30 ; |
---|
2742 | assign metric_next_31 = diff_31 [M -1] ? metric_B_31 : metric_A_31 ; |
---|
2743 | assign metric_next_32 = diff_32 [M -1] ? metric_B_32 : metric_A_32 ; |
---|
2744 | assign metric_next_33 = diff_33 [M -1] ? metric_B_33 : metric_A_33 ; |
---|
2745 | assign metric_next_34 = diff_34 [M -1] ? metric_B_34 : metric_A_34 ; |
---|
2746 | assign metric_next_35 = diff_35 [M -1] ? metric_B_35 : metric_A_35 ; |
---|
2747 | assign metric_next_36 = diff_36 [M -1] ? metric_B_36 : metric_A_36 ; |
---|
2748 | assign metric_next_37 = diff_37 [M -1] ? metric_B_37 : metric_A_37 ; |
---|
2749 | assign metric_next_38 = diff_38 [M -1] ? metric_B_38 : metric_A_38 ; |
---|
2750 | assign metric_next_39 = diff_39 [M -1] ? metric_B_39 : metric_A_39 ; |
---|
2751 | assign metric_next_40 = diff_40 [M -1] ? metric_B_40 : metric_A_40 ; |
---|
2752 | assign metric_next_41 = diff_41 [M -1] ? metric_B_41 : metric_A_41 ; |
---|
2753 | assign metric_next_42 = diff_42 [M -1] ? metric_B_42 : metric_A_42 ; |
---|
2754 | assign metric_next_43 = diff_43 [M -1] ? metric_B_43 : metric_A_43 ; |
---|
2755 | assign metric_next_44 = diff_44 [M -1] ? metric_B_44 : metric_A_44 ; |
---|
2756 | assign metric_next_45 = diff_45 [M -1] ? metric_B_45 : metric_A_45 ; |
---|
2757 | assign metric_next_46 = diff_46 [M -1] ? metric_B_46 : metric_A_46 ; |
---|
2758 | assign metric_next_47 = diff_47 [M -1] ? metric_B_47 : metric_A_47 ; |
---|
2759 | assign metric_next_48 = diff_48 [M -1] ? metric_B_48 : metric_A_48 ; |
---|
2760 | assign metric_next_49 = diff_49 [M -1] ? metric_B_49 : metric_A_49 ; |
---|
2761 | assign metric_next_50 = diff_50 [M -1] ? metric_B_50 : metric_A_50 ; |
---|
2762 | assign metric_next_51 = diff_51 [M -1] ? metric_B_51 : metric_A_51 ; |
---|
2763 | assign metric_next_52 = diff_52 [M -1] ? metric_B_52 : metric_A_52 ; |
---|
2764 | assign metric_next_53 = diff_53 [M -1] ? metric_B_53 : metric_A_53 ; |
---|
2765 | assign metric_next_54 = diff_54 [M -1] ? metric_B_54 : metric_A_54 ; |
---|
2766 | assign metric_next_55 = diff_55 [M -1] ? metric_B_55 : metric_A_55 ; |
---|
2767 | assign metric_next_56 = diff_56 [M -1] ? metric_B_56 : metric_A_56 ; |
---|
2768 | assign metric_next_57 = diff_57 [M -1] ? metric_B_57 : metric_A_57 ; |
---|
2769 | assign metric_next_58 = diff_58 [M -1] ? metric_B_58 : metric_A_58 ; |
---|
2770 | assign metric_next_59 = diff_59 [M -1] ? metric_B_59 : metric_A_59 ; |
---|
2771 | assign metric_next_60 = diff_60 [M -1] ? metric_B_60 : metric_A_60 ; |
---|
2772 | assign metric_next_61 = diff_61 [M -1] ? metric_B_61 : metric_A_61 ; |
---|
2773 | assign metric_next_62 = diff_62 [M -1] ? metric_B_62 : metric_A_62 ; |
---|
2774 | assign metric_next_63 = diff_63 [M -1] ? metric_B_63 : metric_A_63 ; |
---|
2775 | |
---|
2776 | always @ (posedge clk or negedge nrst) |
---|
2777 | if (~nrst) |
---|
2778 | begin |
---|
2779 | metric_0 <= 10 ; |
---|
2780 | metric_1 <= 0 ; |
---|
2781 | metric_2 <= 0 ; |
---|
2782 | metric_3 <= 0 ; |
---|
2783 | metric_4 <= 0 ; |
---|
2784 | metric_5 <= 0 ; |
---|
2785 | metric_6 <= 0 ; |
---|
2786 | metric_7 <= 0 ; |
---|
2787 | metric_8 <= 0 ; |
---|
2788 | metric_9 <= 0 ; |
---|
2789 | metric_10 <= 0 ; |
---|
2790 | metric_11 <= 0 ; |
---|
2791 | metric_12 <= 0 ; |
---|
2792 | metric_13 <= 0 ; |
---|
2793 | metric_14 <= 0 ; |
---|
2794 | metric_15 <= 0 ; |
---|
2795 | metric_16 <= 0 ; |
---|
2796 | metric_17 <= 0 ; |
---|
2797 | metric_18 <= 0 ; |
---|
2798 | metric_19 <= 0 ; |
---|
2799 | metric_20 <= 0 ; |
---|
2800 | metric_21 <= 0 ; |
---|
2801 | metric_22 <= 0 ; |
---|
2802 | metric_23 <= 0 ; |
---|
2803 | metric_24 <= 0 ; |
---|
2804 | metric_25 <= 0 ; |
---|
2805 | metric_26 <= 0 ; |
---|
2806 | metric_27 <= 0 ; |
---|
2807 | metric_28 <= 0 ; |
---|
2808 | metric_29 <= 0 ; |
---|
2809 | metric_30 <= 0 ; |
---|
2810 | metric_31 <= 0 ; |
---|
2811 | metric_32 <= 0 ; |
---|
2812 | metric_33 <= 0 ; |
---|
2813 | metric_34 <= 0 ; |
---|
2814 | metric_35 <= 0 ; |
---|
2815 | metric_36 <= 0 ; |
---|
2816 | metric_37 <= 0 ; |
---|
2817 | metric_38 <= 0 ; |
---|
2818 | metric_39 <= 0 ; |
---|
2819 | metric_40 <= 0 ; |
---|
2820 | metric_41 <= 0 ; |
---|
2821 | metric_42 <= 0 ; |
---|
2822 | metric_43 <= 0 ; |
---|
2823 | metric_44 <= 0 ; |
---|
2824 | metric_45 <= 0 ; |
---|
2825 | metric_46 <= 0 ; |
---|
2826 | metric_47 <= 0 ; |
---|
2827 | metric_48 <= 0 ; |
---|
2828 | metric_49 <= 0 ; |
---|
2829 | metric_50 <= 0 ; |
---|
2830 | metric_51 <= 0 ; |
---|
2831 | metric_52 <= 0 ; |
---|
2832 | metric_53 <= 0 ; |
---|
2833 | metric_54 <= 0 ; |
---|
2834 | metric_55 <= 0 ; |
---|
2835 | metric_56 <= 0 ; |
---|
2836 | metric_57 <= 0 ; |
---|
2837 | metric_58 <= 0 ; |
---|
2838 | metric_59 <= 0 ; |
---|
2839 | metric_60 <= 0 ; |
---|
2840 | metric_61 <= 0 ; |
---|
2841 | metric_62 <= 0 ; |
---|
2842 | metric_63 <= 0 ; |
---|
2843 | end |
---|
2844 | else if (packet_start) |
---|
2845 | begin |
---|
2846 | metric_0 <= 10 ; |
---|
2847 | metric_1 <= 0 ; |
---|
2848 | metric_2 <= 0 ; |
---|
2849 | metric_3 <= 0 ; |
---|
2850 | metric_4 <= 0 ; |
---|
2851 | metric_5 <= 0 ; |
---|
2852 | metric_6 <= 0 ; |
---|
2853 | metric_7 <= 0 ; |
---|
2854 | metric_8 <= 0 ; |
---|
2855 | metric_9 <= 0 ; |
---|
2856 | metric_10 <= 0 ; |
---|
2857 | metric_11 <= 0 ; |
---|
2858 | metric_12 <= 0 ; |
---|
2859 | metric_13 <= 0 ; |
---|
2860 | metric_14 <= 0 ; |
---|
2861 | metric_15 <= 0 ; |
---|
2862 | metric_16 <= 0 ; |
---|
2863 | metric_17 <= 0 ; |
---|
2864 | metric_18 <= 0 ; |
---|
2865 | metric_19 <= 0 ; |
---|
2866 | metric_20 <= 0 ; |
---|
2867 | metric_21 <= 0 ; |
---|
2868 | metric_22 <= 0 ; |
---|
2869 | metric_23 <= 0 ; |
---|
2870 | metric_24 <= 0 ; |
---|
2871 | metric_25 <= 0 ; |
---|
2872 | metric_26 <= 0 ; |
---|
2873 | metric_27 <= 0 ; |
---|
2874 | metric_28 <= 0 ; |
---|
2875 | metric_29 <= 0 ; |
---|
2876 | metric_30 <= 0 ; |
---|
2877 | metric_31 <= 0 ; |
---|
2878 | metric_32 <= 0 ; |
---|
2879 | metric_33 <= 0 ; |
---|
2880 | metric_34 <= 0 ; |
---|
2881 | metric_35 <= 0 ; |
---|
2882 | metric_36 <= 0 ; |
---|
2883 | metric_37 <= 0 ; |
---|
2884 | metric_38 <= 0 ; |
---|
2885 | metric_39 <= 0 ; |
---|
2886 | metric_40 <= 0 ; |
---|
2887 | metric_41 <= 0 ; |
---|
2888 | metric_42 <= 0 ; |
---|
2889 | metric_43 <= 0 ; |
---|
2890 | metric_44 <= 0 ; |
---|
2891 | metric_45 <= 0 ; |
---|
2892 | metric_46 <= 0 ; |
---|
2893 | metric_47 <= 0 ; |
---|
2894 | metric_48 <= 0 ; |
---|
2895 | metric_49 <= 0 ; |
---|
2896 | metric_50 <= 0 ; |
---|
2897 | metric_51 <= 0 ; |
---|
2898 | metric_52 <= 0 ; |
---|
2899 | metric_53 <= 0 ; |
---|
2900 | metric_54 <= 0 ; |
---|
2901 | metric_55 <= 0 ; |
---|
2902 | metric_56 <= 0 ; |
---|
2903 | metric_57 <= 0 ; |
---|
2904 | metric_58 <= 0 ; |
---|
2905 | metric_59 <= 0 ; |
---|
2906 | metric_60 <= 0 ; |
---|
2907 | metric_61 <= 0 ; |
---|
2908 | metric_62 <= 0 ; |
---|
2909 | metric_63 <= 0 ; |
---|
2910 | end |
---|
2911 | else if (dv_in_gate) |
---|
2912 | begin |
---|
2913 | // update metric |
---|
2914 | metric_0 <= metric_next_0 ; |
---|
2915 | metric_1 <= metric_next_1 ; |
---|
2916 | metric_2 <= metric_next_2 ; |
---|
2917 | metric_3 <= metric_next_3 ; |
---|
2918 | metric_4 <= metric_next_4 ; |
---|
2919 | metric_5 <= metric_next_5 ; |
---|
2920 | metric_6 <= metric_next_6 ; |
---|
2921 | metric_7 <= metric_next_7 ; |
---|
2922 | metric_8 <= metric_next_8 ; |
---|
2923 | metric_9 <= metric_next_9 ; |
---|
2924 | metric_10 <= metric_next_10; |
---|
2925 | metric_11 <= metric_next_11; |
---|
2926 | metric_12 <= metric_next_12; |
---|
2927 | metric_13 <= metric_next_13; |
---|
2928 | metric_14 <= metric_next_14; |
---|
2929 | metric_15 <= metric_next_15; |
---|
2930 | metric_16 <= metric_next_16 ; |
---|
2931 | metric_17 <= metric_next_17; |
---|
2932 | metric_18 <= metric_next_18; |
---|
2933 | metric_19 <= metric_next_19; |
---|
2934 | metric_20 <= metric_next_20; |
---|
2935 | metric_21 <= metric_next_21; |
---|
2936 | metric_22 <= metric_next_22; |
---|
2937 | metric_23 <= metric_next_23; |
---|
2938 | metric_24 <= metric_next_24; |
---|
2939 | metric_25 <= metric_next_25; |
---|
2940 | metric_26 <= metric_next_26; |
---|
2941 | metric_27 <= metric_next_27; |
---|
2942 | metric_28 <= metric_next_28; |
---|
2943 | metric_29 <= metric_next_29; |
---|
2944 | metric_30 <= metric_next_30; |
---|
2945 | metric_31 <= metric_next_31; |
---|
2946 | metric_32 <= metric_next_32 ; |
---|
2947 | metric_33 <= metric_next_33; |
---|
2948 | metric_34 <= metric_next_34; |
---|
2949 | metric_35 <= metric_next_35; |
---|
2950 | metric_36 <= metric_next_36; |
---|
2951 | metric_37 <= metric_next_37; |
---|
2952 | metric_38 <= metric_next_38; |
---|
2953 | metric_39 <= metric_next_39; |
---|
2954 | metric_40 <= metric_next_40; |
---|
2955 | metric_41 <= metric_next_41; |
---|
2956 | metric_42 <= metric_next_42; |
---|
2957 | metric_43 <= metric_next_43; |
---|
2958 | metric_44 <= metric_next_44; |
---|
2959 | metric_45 <= metric_next_45; |
---|
2960 | metric_46 <= metric_next_46; |
---|
2961 | metric_47 <= metric_next_47; |
---|
2962 | metric_48 <= metric_next_48 ; |
---|
2963 | metric_49 <= metric_next_49; |
---|
2964 | metric_50 <= metric_next_50; |
---|
2965 | metric_51 <= metric_next_51; |
---|
2966 | metric_52 <= metric_next_52; |
---|
2967 | metric_53 <= metric_next_53; |
---|
2968 | metric_54 <= metric_next_54; |
---|
2969 | metric_55 <= metric_next_55; |
---|
2970 | metric_56 <= metric_next_56; |
---|
2971 | metric_57 <= metric_next_57; |
---|
2972 | metric_58 <= metric_next_58; |
---|
2973 | metric_59 <= metric_next_59; |
---|
2974 | metric_60 <= metric_next_60; |
---|
2975 | metric_61 <= metric_next_61; |
---|
2976 | metric_62 <= metric_next_62; |
---|
2977 | metric_63 <= metric_next_63; |
---|
2978 | end |
---|
2979 | |
---|
2980 | always @ (posedge clk or negedge nrst) |
---|
2981 | if (~nrst) |
---|
2982 | wptr <= 0 ; |
---|
2983 | else if (packet_start) |
---|
2984 | wptr <= 0 ; |
---|
2985 | else if (dv_in_gate) |
---|
2986 | wptr <= wptr + 1 ; |
---|
2987 | |
---|
2988 | always @ (posedge clk or negedge nrst) |
---|
2989 | if (~nrst) |
---|
2990 | last_wptr <= 1'b0 ; |
---|
2991 | else if (dv_in_gate) |
---|
2992 | last_wptr <= wptr ; |
---|
2993 | |
---|
2994 | always @ (posedge clk) |
---|
2995 | if(dv_in_gate) |
---|
2996 | begin |
---|
2997 | // update transition |
---|
2998 | tran_state_0 [wptr] <= diff_0 [M -1] ; |
---|
2999 | tran_state_1 [wptr] <= diff_1 [M -1] ; |
---|
3000 | tran_state_2 [wptr] <= diff_2 [M -1] ; |
---|
3001 | tran_state_3 [wptr] <= diff_3 [M -1] ; |
---|
3002 | tran_state_4 [wptr] <= diff_4 [M -1] ; |
---|
3003 | tran_state_5 [wptr] <= diff_5 [M -1] ; |
---|
3004 | tran_state_6 [wptr] <= diff_6 [M -1] ; |
---|
3005 | tran_state_7 [wptr] <= diff_7 [M -1] ; |
---|
3006 | tran_state_8 [wptr] <= diff_8 [M -1] ; |
---|
3007 | tran_state_9 [wptr] <= diff_9 [M -1] ; |
---|
3008 | tran_state_10 [wptr] <= diff_10 [M -1] ; |
---|
3009 | tran_state_11 [wptr] <= diff_11 [M -1] ; |
---|
3010 | tran_state_12 [wptr] <= diff_12 [M -1] ; |
---|
3011 | tran_state_13 [wptr] <= diff_13 [M -1] ; |
---|
3012 | tran_state_14 [wptr] <= diff_14 [M -1] ; |
---|
3013 | tran_state_15 [wptr] <= diff_15 [M -1] ; |
---|
3014 | tran_state_16 [wptr] <= diff_16 [M -1] ; |
---|
3015 | tran_state_17 [wptr] <= diff_17 [M -1] ; |
---|
3016 | tran_state_18 [wptr] <= diff_18 [M -1] ; |
---|
3017 | tran_state_19 [wptr] <= diff_19 [M -1] ; |
---|
3018 | tran_state_20 [wptr] <= diff_20 [M -1] ; |
---|
3019 | tran_state_21 [wptr] <= diff_21 [M -1] ; |
---|
3020 | tran_state_22 [wptr] <= diff_22 [M -1] ; |
---|
3021 | tran_state_23 [wptr] <= diff_23 [M -1] ; |
---|
3022 | tran_state_24 [wptr] <= diff_24 [M -1] ; |
---|
3023 | tran_state_25 [wptr] <= diff_25 [M -1] ; |
---|
3024 | tran_state_26 [wptr] <= diff_26 [M -1] ; |
---|
3025 | tran_state_27 [wptr] <= diff_27 [M -1] ; |
---|
3026 | tran_state_28 [wptr] <= diff_28 [M -1] ; |
---|
3027 | tran_state_29 [wptr] <= diff_29 [M -1] ; |
---|
3028 | tran_state_30 [wptr] <= diff_30 [M -1] ; |
---|
3029 | tran_state_31 [wptr] <= diff_31 [M -1] ; |
---|
3030 | tran_state_32 [wptr] <= diff_32 [M -1] ; |
---|
3031 | tran_state_33 [wptr] <= diff_33 [M -1] ; |
---|
3032 | tran_state_34 [wptr] <= diff_34 [M -1] ; |
---|
3033 | tran_state_35 [wptr] <= diff_35 [M -1] ; |
---|
3034 | tran_state_36 [wptr] <= diff_36 [M -1] ; |
---|
3035 | tran_state_37 [wptr] <= diff_37 [M -1] ; |
---|
3036 | tran_state_38 [wptr] <= diff_38 [M -1] ; |
---|
3037 | tran_state_39 [wptr] <= diff_39 [M -1] ; |
---|
3038 | tran_state_40 [wptr] <= diff_40 [M -1] ; |
---|
3039 | tran_state_41 [wptr] <= diff_41 [M -1] ; |
---|
3040 | tran_state_42 [wptr] <= diff_42 [M -1] ; |
---|
3041 | tran_state_43 [wptr] <= diff_43 [M -1] ; |
---|
3042 | tran_state_44 [wptr] <= diff_44 [M -1] ; |
---|
3043 | tran_state_45 [wptr] <= diff_45 [M -1] ; |
---|
3044 | tran_state_46 [wptr] <= diff_46 [M -1] ; |
---|
3045 | tran_state_47 [wptr] <= diff_47 [M -1] ; |
---|
3046 | tran_state_48 [wptr] <= diff_48 [M -1] ; |
---|
3047 | tran_state_49 [wptr] <= diff_49 [M -1] ; |
---|
3048 | tran_state_50 [wptr] <= diff_50 [M -1] ; |
---|
3049 | tran_state_51 [wptr] <= diff_51 [M -1] ; |
---|
3050 | tran_state_52 [wptr] <= diff_52 [M -1] ; |
---|
3051 | tran_state_53 [wptr] <= diff_53 [M -1] ; |
---|
3052 | tran_state_54 [wptr] <= diff_54 [M -1] ; |
---|
3053 | tran_state_55 [wptr] <= diff_55 [M -1] ; |
---|
3054 | tran_state_56 [wptr] <= diff_56 [M -1] ; |
---|
3055 | tran_state_57 [wptr] <= diff_57 [M -1] ; |
---|
3056 | tran_state_58 [wptr] <= diff_58 [M -1] ; |
---|
3057 | tran_state_59 [wptr] <= diff_59 [M -1] ; |
---|
3058 | tran_state_60 [wptr] <= diff_60 [M -1] ; |
---|
3059 | tran_state_61 [wptr] <= diff_61 [M -1] ; |
---|
3060 | tran_state_62 [wptr] <= diff_62 [M -1] ; |
---|
3061 | tran_state_63 [wptr] <= diff_63 [M -1] ; |
---|
3062 | end |
---|
3063 | |
---|
3064 | always @ (posedge clk or negedge nrst) |
---|
3065 | if (~nrst) |
---|
3066 | begin |
---|
3067 | trace <= 1'b0 ; |
---|
3068 | cnt <= 0 ; |
---|
3069 | trace_start_wptr <= 0 ; |
---|
3070 | end |
---|
3071 | else if (packet_start) |
---|
3072 | begin |
---|
3073 | trace <= 1'b0 ; |
---|
3074 | cnt <= 0 ; |
---|
3075 | end |
---|
3076 | else if (dv_in_gate) |
---|
3077 | begin |
---|
3078 | if (cnt == L-1) |
---|
3079 | begin |
---|
3080 | trace <= 1'b1 ; |
---|
3081 | trace_start_wptr <= wptr ; |
---|
3082 | cnt <= C ; |
---|
3083 | end |
---|
3084 | else |
---|
3085 | begin |
---|
3086 | trace <= 1'b0 ; |
---|
3087 | cnt <= cnt + 1 ; |
---|
3088 | end |
---|
3089 | end |
---|
3090 | else if (trace2) |
---|
3091 | trace_start_wptr <= last_wptr ; |
---|
3092 | else |
---|
3093 | trace <= 1'b0 ; |
---|
3094 | |
---|
3095 | always @ (posedge clk or negedge nrst) |
---|
3096 | if (~nrst) |
---|
3097 | begin |
---|
3098 | flush_en <= 1'b0 ; |
---|
3099 | flush_cnt <= 0 ; |
---|
3100 | end |
---|
3101 | else if (packet_end) |
---|
3102 | begin |
---|
3103 | flush_en <= 1 ; |
---|
3104 | flush_cnt <= 0 ; |
---|
3105 | end |
---|
3106 | else if (flush_en) |
---|
3107 | begin |
---|
3108 | if (flush_cnt == 63) |
---|
3109 | flush_en <= 1'b0 ; |
---|
3110 | else |
---|
3111 | flush_cnt <= flush_cnt + 1 ; |
---|
3112 | end |
---|
3113 | |
---|
3114 | assign flush = flush_cnt == 60 ; |
---|
3115 | |
---|
3116 | always @ (posedge clk or negedge nrst) |
---|
3117 | if (~nrst) |
---|
3118 | done_i <= 1'b0 ; |
---|
3119 | else if (packet_start) |
---|
3120 | done_i <= 1'b0 ; |
---|
3121 | //else if (packet_end && cnt == L-1) |
---|
3122 | else if (trace2 & last_cnt_next[LW-1]) |
---|
3123 | done_i <= 1'b1 ; |
---|
3124 | else if (last_trace_d3) |
---|
3125 | done_i <= 1'b1 ; |
---|
3126 | |
---|
3127 | |
---|
3128 | always @ (posedge clk or negedge nrst) |
---|
3129 | if (~nrst) |
---|
3130 | last_trace <= 1'b0 ; |
---|
3131 | else if (packet_start) |
---|
3132 | last_trace <= 1'b0 ; |
---|
3133 | else if (flush && trace_done && cnt !=L-1 ) |
---|
3134 | last_trace <= 1'b1 ; |
---|
3135 | |
---|
3136 | always @ (posedge clk) |
---|
3137 | last_trace_s0 <= last_trace ; |
---|
3138 | |
---|
3139 | assign trace2 = ~last_trace_s0 & last_trace ; |
---|
3140 | assign trace_pos_i = trace | trace2 ; |
---|
3141 | |
---|
3142 | always @ (posedge clk or negedge nrst) |
---|
3143 | if (~nrst) |
---|
3144 | begin |
---|
3145 | trace2_s1 <= 1'b0 ; |
---|
3146 | trace2_s2 <= 1'b0 ; |
---|
3147 | end |
---|
3148 | else |
---|
3149 | begin |
---|
3150 | trace2_s1 <= trace2 ; |
---|
3151 | trace2_s2 <= trace2_s1 ; |
---|
3152 | end |
---|
3153 | |
---|
3154 | |
---|
3155 | always @ (posedge clk) |
---|
3156 | begin |
---|
3157 | trace_pos_s0 <= trace_pos_i ; |
---|
3158 | trace_pos <= trace_pos_s0 ; |
---|
3159 | end |
---|
3160 | |
---|
3161 | always @ (posedge clk or negedge nrst) |
---|
3162 | if(~nrst) |
---|
3163 | last_trace_num <= 0 ; |
---|
3164 | else |
---|
3165 | begin |
---|
3166 | if (packet_start) |
---|
3167 | last_trace_num <= 0 ; |
---|
3168 | else if (trace2) |
---|
3169 | last_trace_num <= L -cnt ; |
---|
3170 | else if (last_trace_d0) |
---|
3171 | last_trace_num <= last_trace_num + R ; |
---|
3172 | end |
---|
3173 | |
---|
3174 | always @ (posedge clk) |
---|
3175 | begin |
---|
3176 | last_trace_d0 <= last_trace & trace_done_pos ; |
---|
3177 | last_trace_d1 <= last_trace_d0 ; |
---|
3178 | last_trace_d2 <= last_trace_d1 ; |
---|
3179 | last_trace_d3 <= last_trace_d2 ; |
---|
3180 | last_trace_d4 <= last_trace_d3 ; |
---|
3181 | last_trace_d5 <= last_trace_d4 ; |
---|
3182 | end |
---|
3183 | |
---|
3184 | assign last_cnt_next = last_cnt - R ; |
---|
3185 | |
---|
3186 | always @ (posedge clk or negedge nrst) |
---|
3187 | if(~nrst) |
---|
3188 | begin |
---|
3189 | one_more_out <= 1'b0 ; |
---|
3190 | last_cnt <= 0 ; |
---|
3191 | end |
---|
3192 | else |
---|
3193 | begin |
---|
3194 | if (packet_start) |
---|
3195 | begin |
---|
3196 | one_more_out <= 1'b0 ; |
---|
3197 | last_cnt <= 0 ; |
---|
3198 | end |
---|
3199 | else if (flush) |
---|
3200 | last_cnt <= cnt ; |
---|
3201 | else if (last_trace_d5) |
---|
3202 | begin |
---|
3203 | if (~last_cnt_next[LW-1]) |
---|
3204 | begin |
---|
3205 | last_cnt <= last_cnt_next ; |
---|
3206 | one_more_out <= 1'b1 ; |
---|
3207 | end |
---|
3208 | end |
---|
3209 | else |
---|
3210 | one_more_out <= 1'b0 ; |
---|
3211 | end |
---|
3212 | |
---|
3213 | always @ (posedge clk or negedge nrst) |
---|
3214 | if (~nrst) |
---|
3215 | trace_en <= 0 ; |
---|
3216 | else if (packet_start) |
---|
3217 | trace_en <= 0 ; |
---|
3218 | else if (trace_pos) |
---|
3219 | trace_en <= 1'b1 ; |
---|
3220 | else if (trace_cnt == L-2) |
---|
3221 | trace_en <= 1'b0 ; |
---|
3222 | |
---|
3223 | always @ (posedge clk or negedge nrst) |
---|
3224 | if (~nrst) |
---|
3225 | trace_cnt <= 0 ; |
---|
3226 | else if (trace_pos) |
---|
3227 | trace_cnt <= 0 ; |
---|
3228 | else if (trace_en) |
---|
3229 | trace_cnt <= trace_cnt + 2; |
---|
3230 | |
---|
3231 | assign trace_done = trace_cnt == L ; |
---|
3232 | |
---|
3233 | always @ (posedge clk) |
---|
3234 | trace_done_s0 <= trace_done ; |
---|
3235 | assign trace_done_pos = ~trace_done_s0 & trace_done ; |
---|
3236 | |
---|
3237 | //============================== |
---|
3238 | // Get max metric |
---|
3239 | //============================== |
---|
3240 | max_metric #(M, K) max_metric_0 ( |
---|
3241 | .clk (clk ), |
---|
3242 | .a (metric_0 ), |
---|
3243 | .b (metric_1 ), |
---|
3244 | .c (metric_2 ), |
---|
3245 | .d (metric_3 ), |
---|
3246 | .sa (6'd0 ), |
---|
3247 | .sb (6'd1 ), |
---|
3248 | .sc (6'd2 ), |
---|
3249 | .sd (6'd3 ), |
---|
3250 | .state (state_0 ), |
---|
3251 | .max (max_0 ) |
---|
3252 | ) ; |
---|
3253 | |
---|
3254 | //============================== |
---|
3255 | // Get max metric |
---|
3256 | //============================== |
---|
3257 | max_metric #(M, K) max_metric_1 ( |
---|
3258 | .clk (clk ), |
---|
3259 | .a (metric_4 ), |
---|
3260 | .b (metric_5 ), |
---|
3261 | .c (metric_6 ), |
---|
3262 | .d (metric_7 ), |
---|
3263 | .sa (6'd4 ), |
---|
3264 | .sb (6'd5 ), |
---|
3265 | .sc (6'd6 ), |
---|
3266 | .sd (6'd7 ), |
---|
3267 | .state (state_1 ), |
---|
3268 | .max (max_1 ) |
---|
3269 | ) ; |
---|
3270 | |
---|
3271 | //============================== |
---|
3272 | // Get max metric |
---|
3273 | //============================== |
---|
3274 | max_metric #(M, K) max_metric_2 ( |
---|
3275 | .clk (clk ), |
---|
3276 | .a (metric_8 ), |
---|
3277 | .b (metric_9 ), |
---|
3278 | .c (metric_10 ), |
---|
3279 | .d (metric_11 ), |
---|
3280 | .sa (6'd8 ), |
---|
3281 | .sb (6'd9 ), |
---|
3282 | .sc (6'd10 ), |
---|
3283 | .sd (6'd11 ), |
---|
3284 | .state (state_2 ), |
---|
3285 | .max (max_2 ) |
---|
3286 | ) ; |
---|
3287 | |
---|
3288 | //============================== |
---|
3289 | // Get max metric |
---|
3290 | //============================== |
---|
3291 | max_metric #(M, K) max_metric_3 ( |
---|
3292 | .clk (clk ), |
---|
3293 | .a (metric_12 ), |
---|
3294 | .b (metric_13 ), |
---|
3295 | .c (metric_14 ), |
---|
3296 | .d (metric_15 ), |
---|
3297 | .sa (6'd12 ), |
---|
3298 | .sb (6'd13 ), |
---|
3299 | .sc (6'd14 ), |
---|
3300 | .sd (6'd15 ), |
---|
3301 | .state (state_3 ), |
---|
3302 | .max (max_3 ) |
---|
3303 | ) ; |
---|
3304 | |
---|
3305 | //============================== |
---|
3306 | // Get max metric |
---|
3307 | //============================== |
---|
3308 | max_metric #(M, K) max_metric_4 ( |
---|
3309 | .clk (clk ), |
---|
3310 | .a (metric_16 ), |
---|
3311 | .b (metric_17 ), |
---|
3312 | .c (metric_18 ), |
---|
3313 | .d (metric_19 ), |
---|
3314 | .sa (6'd16 ), |
---|
3315 | .sb (6'd17 ), |
---|
3316 | .sc (6'd18 ), |
---|
3317 | .sd (6'd19 ), |
---|
3318 | .state (state_4 ), |
---|
3319 | .max (max_4 ) |
---|
3320 | ) ; |
---|
3321 | |
---|
3322 | //============================== |
---|
3323 | // Get max metric |
---|
3324 | //============================== |
---|
3325 | max_metric #(M, K) max_metric_5 ( |
---|
3326 | .clk (clk ), |
---|
3327 | .a (metric_20 ), |
---|
3328 | .b (metric_21 ), |
---|
3329 | .c (metric_22 ), |
---|
3330 | .d (metric_23 ), |
---|
3331 | .sa (6'd20 ), |
---|
3332 | .sb (6'd21 ), |
---|
3333 | .sc (6'd22 ), |
---|
3334 | .sd (6'd23 ), |
---|
3335 | .state (state_5 ), |
---|
3336 | .max (max_5 ) |
---|
3337 | ) ; |
---|
3338 | |
---|
3339 | //============================== |
---|
3340 | // Get max metric |
---|
3341 | //============================== |
---|
3342 | max_metric #(M, K) max_metric_6 ( |
---|
3343 | .clk (clk ), |
---|
3344 | .a (metric_24 ), |
---|
3345 | .b (metric_25 ), |
---|
3346 | .c (metric_26 ), |
---|
3347 | .d (metric_27 ), |
---|
3348 | .sa (6'd24 ), |
---|
3349 | .sb (6'd25 ), |
---|
3350 | .sc (6'd26 ), |
---|
3351 | .sd (6'd27 ), |
---|
3352 | .state (state_6 ), |
---|
3353 | .max (max_6 ) |
---|
3354 | ) ; |
---|
3355 | |
---|
3356 | //============================== |
---|
3357 | // Get max metric |
---|
3358 | //============================== |
---|
3359 | max_metric #(M, K) max_metric_7 ( |
---|
3360 | .clk (clk ), |
---|
3361 | .a (metric_28 ), |
---|
3362 | .b (metric_29 ), |
---|
3363 | .c (metric_30 ), |
---|
3364 | .d (metric_31 ), |
---|
3365 | .sa (6'd28 ), |
---|
3366 | .sb (6'd29 ), |
---|
3367 | .sc (6'd30 ), |
---|
3368 | .sd (6'd31 ), |
---|
3369 | .state (state_7 ), |
---|
3370 | .max (max_7 ) |
---|
3371 | ) ; |
---|
3372 | |
---|
3373 | //============================== |
---|
3374 | // Get max metric |
---|
3375 | //============================== |
---|
3376 | max_metric #(M, K) max_metric_8 ( |
---|
3377 | .clk (clk ), |
---|
3378 | .a (metric_32 ), |
---|
3379 | .b (metric_33 ), |
---|
3380 | .c (metric_34 ), |
---|
3381 | .d (metric_35 ), |
---|
3382 | .sa (6'd32 ), |
---|
3383 | .sb (6'd33 ), |
---|
3384 | .sc (6'd34 ), |
---|
3385 | .sd (6'd35 ), |
---|
3386 | .state (state_8 ), |
---|
3387 | .max (max_8 ) |
---|
3388 | ) ; |
---|
3389 | |
---|
3390 | //============================== |
---|
3391 | // Get max metric |
---|
3392 | //============================== |
---|
3393 | max_metric #(M, K) max_metric_9 ( |
---|
3394 | .clk (clk ), |
---|
3395 | .a (metric_36 ), |
---|
3396 | .b (metric_37 ), |
---|
3397 | .c (metric_38 ), |
---|
3398 | .d (metric_39 ), |
---|
3399 | .sa (6'd36 ), |
---|
3400 | .sb (6'd37 ), |
---|
3401 | .sc (6'd38 ), |
---|
3402 | .sd (6'd39 ), |
---|
3403 | .state (state_9 ), |
---|
3404 | .max (max_9 ) |
---|
3405 | ) ; |
---|
3406 | |
---|
3407 | //============================== |
---|
3408 | // Get max metric |
---|
3409 | //============================== |
---|
3410 | max_metric #(M, K) max_metric_10 ( |
---|
3411 | .clk (clk ), |
---|
3412 | .a (metric_40 ), |
---|
3413 | .b (metric_41 ), |
---|
3414 | .c (metric_42 ), |
---|
3415 | .d (metric_43 ), |
---|
3416 | .sa (6'd40 ), |
---|
3417 | .sb (6'd41 ), |
---|
3418 | .sc (6'd42 ), |
---|
3419 | .sd (6'd43 ), |
---|
3420 | .state (state_10 ), |
---|
3421 | .max (max_10 ) |
---|
3422 | ) ; |
---|
3423 | |
---|
3424 | //============================== |
---|
3425 | // Get max metric |
---|
3426 | //============================== |
---|
3427 | max_metric #(M, K) max_metric_11 ( |
---|
3428 | .clk (clk ), |
---|
3429 | .a (metric_44 ), |
---|
3430 | .b (metric_45 ), |
---|
3431 | .c (metric_46 ), |
---|
3432 | .d (metric_47 ), |
---|
3433 | .sa (6'd44 ), |
---|
3434 | .sb (6'd45 ), |
---|
3435 | .sc (6'd46 ), |
---|
3436 | .sd (6'd47 ), |
---|
3437 | .state (state_11 ), |
---|
3438 | .max (max_11 ) |
---|
3439 | ) ; |
---|
3440 | |
---|
3441 | //============================== |
---|
3442 | // Get max metric |
---|
3443 | //============================== |
---|
3444 | max_metric #(M, K) max_metric_12 ( |
---|
3445 | .clk (clk ), |
---|
3446 | .a (metric_48 ), |
---|
3447 | .b (metric_49 ), |
---|
3448 | .c (metric_50 ), |
---|
3449 | .d (metric_51 ), |
---|
3450 | .sa (6'd48 ), |
---|
3451 | .sb (6'd49 ), |
---|
3452 | .sc (6'd50 ), |
---|
3453 | .sd (6'd51 ), |
---|
3454 | .state (state_12 ), |
---|
3455 | .max (max_12 ) |
---|
3456 | ) ; |
---|
3457 | |
---|
3458 | //============================== |
---|
3459 | // Get max metric |
---|
3460 | //============================== |
---|
3461 | max_metric #(M, K) max_metric_13 ( |
---|
3462 | .clk (clk ), |
---|
3463 | .a (metric_52 ), |
---|
3464 | .b (metric_53 ), |
---|
3465 | .c (metric_54 ), |
---|
3466 | .d (metric_55 ), |
---|
3467 | .sa (6'd52 ), |
---|
3468 | .sb (6'd53 ), |
---|
3469 | .sc (6'd54 ), |
---|
3470 | .sd (6'd55 ), |
---|
3471 | .state (state_13 ), |
---|
3472 | .max (max_13 ) |
---|
3473 | ) ; |
---|
3474 | |
---|
3475 | //============================== |
---|
3476 | // Get max metric |
---|
3477 | //============================== |
---|
3478 | max_metric #(M, K) max_metric_14 ( |
---|
3479 | .clk (clk ), |
---|
3480 | .a (metric_56 ), |
---|
3481 | .b (metric_57 ), |
---|
3482 | .c (metric_58 ), |
---|
3483 | .d (metric_59 ), |
---|
3484 | .sa (6'd56 ), |
---|
3485 | .sb (6'd57 ), |
---|
3486 | .sc (6'd58 ), |
---|
3487 | .sd (6'd59 ), |
---|
3488 | .state (state_14 ), |
---|
3489 | .max (max_14 ) |
---|
3490 | ) ; |
---|
3491 | |
---|
3492 | //============================== |
---|
3493 | // Get max metric |
---|
3494 | //============================== |
---|
3495 | max_metric #(M, K) max_metric_15 ( |
---|
3496 | .clk (clk ), |
---|
3497 | .a (metric_60 ), |
---|
3498 | .b (metric_61 ), |
---|
3499 | .c (metric_62 ), |
---|
3500 | .d (metric_63 ), |
---|
3501 | .sa (6'd60 ), |
---|
3502 | .sb (6'd61 ), |
---|
3503 | .sc (6'd62 ), |
---|
3504 | .sd (6'd63 ), |
---|
3505 | .state (state_15 ), |
---|
3506 | .max (max_15 ) |
---|
3507 | ) ; |
---|
3508 | |
---|
3509 | //============================== |
---|
3510 | // Get max metric |
---|
3511 | //============================== |
---|
3512 | max_metric #(M, K) max_metric_s1_0 ( |
---|
3513 | .clk (clk ), |
---|
3514 | .a (max_0 ), |
---|
3515 | .b (max_1 ), |
---|
3516 | .c (max_2 ), |
---|
3517 | .d (max_3 ), |
---|
3518 | .sa (state_0 ), |
---|
3519 | .sb (state_1 ), |
---|
3520 | .sc (state_2 ), |
---|
3521 | .sd (state_3 ), |
---|
3522 | .state (state_s1_0 ), |
---|
3523 | .max (max_s1_0 ) |
---|
3524 | ) ; |
---|
3525 | |
---|
3526 | //============================== |
---|
3527 | // Get max metric |
---|
3528 | //============================== |
---|
3529 | max_metric #(M, K) max_metric_s1_1 ( |
---|
3530 | .clk (clk ), |
---|
3531 | .a (max_4 ), |
---|
3532 | .b (max_5 ), |
---|
3533 | .c (max_6 ), |
---|
3534 | .d (max_7 ), |
---|
3535 | .sa (state_4 ), |
---|
3536 | .sb (state_5 ), |
---|
3537 | .sc (state_6 ), |
---|
3538 | .sd (state_7 ), |
---|
3539 | .state (state_s1_1 ), |
---|
3540 | .max (max_s1_1 ) |
---|
3541 | ) ; |
---|
3542 | |
---|
3543 | //============================== |
---|
3544 | // Get max metric |
---|
3545 | //============================== |
---|
3546 | max_metric #(M, K) max_metric_s1_2 ( |
---|
3547 | .clk (clk ), |
---|
3548 | .a (max_8 ), |
---|
3549 | .b (max_9 ), |
---|
3550 | .c (max_10 ), |
---|
3551 | .d (max_11 ), |
---|
3552 | .sa (state_8 ), |
---|
3553 | .sb (state_9 ), |
---|
3554 | .sc (state_10 ), |
---|
3555 | .sd (state_11 ), |
---|
3556 | .state (state_s1_2 ), |
---|
3557 | .max (max_s1_2 ) |
---|
3558 | ) ; |
---|
3559 | |
---|
3560 | //============================== |
---|
3561 | // Get max metric |
---|
3562 | //============================== |
---|
3563 | max_metric #(M, K) max_metric_s1_3 ( |
---|
3564 | .clk (clk ), |
---|
3565 | .a (max_12 ), |
---|
3566 | .b (max_13 ), |
---|
3567 | .c (max_14 ), |
---|
3568 | .d (max_15 ), |
---|
3569 | .sa (state_12 ), |
---|
3570 | .sb (state_13 ), |
---|
3571 | .sc (state_14 ), |
---|
3572 | .sd (state_15 ), |
---|
3573 | .state (state_s1_3 ), |
---|
3574 | .max (max_s1_3 ) |
---|
3575 | ) ; |
---|
3576 | |
---|
3577 | //============================== |
---|
3578 | // Get max metric |
---|
3579 | //============================== |
---|
3580 | max_metric_logic #(M, K) max_metric_s2_0 ( |
---|
3581 | .a (max_s1_0 ), |
---|
3582 | .b (max_s1_1 ), |
---|
3583 | .c (max_s1_2 ), |
---|
3584 | .d (max_s1_3 ), |
---|
3585 | .sa (state_s1_0 ), |
---|
3586 | .sb (state_s1_1 ), |
---|
3587 | .sc (state_s1_2 ), |
---|
3588 | .sd (state_s1_3 ), |
---|
3589 | .state (state_s2_0 ), |
---|
3590 | .max ( ) |
---|
3591 | ) ; |
---|
3592 | |
---|
3593 | assign init_state_i = state_s2_0 ; |
---|
3594 | |
---|
3595 | always @ (posedge clk or negedge nrst) |
---|
3596 | if(~nrst) |
---|
3597 | trace_state <= 0 ; |
---|
3598 | else |
---|
3599 | begin |
---|
3600 | if (trace_pos) |
---|
3601 | begin |
---|
3602 | if(zero_tail & trace2_s2) |
---|
3603 | trace_state <= 0 ; |
---|
3604 | else |
---|
3605 | trace_state <= init_state_i ; |
---|
3606 | end |
---|
3607 | else if (trace_en) |
---|
3608 | trace_state <= next_state ; |
---|
3609 | end |
---|
3610 | |
---|
3611 | assign trace_start_pos = trace_start_wptr ; |
---|
3612 | |
---|
3613 | assign trace_start_pos0 = trace_start_pos - trace_cnt ; |
---|
3614 | assign trace_start_pos1 = trace_start_pos - trace_cnt -1 ; |
---|
3615 | |
---|
3616 | assign cur_state0 = trace_state ; |
---|
3617 | |
---|
3618 | assign tran_all_0 = { |
---|
3619 | tran_state_63[trace_start_pos0], tran_state_62[trace_start_pos0], tran_state_61[trace_start_pos0], tran_state_60[trace_start_pos0], |
---|
3620 | tran_state_59[trace_start_pos0], tran_state_58[trace_start_pos0], tran_state_57[trace_start_pos0], tran_state_56[trace_start_pos0], |
---|
3621 | tran_state_55[trace_start_pos0], tran_state_54[trace_start_pos0], tran_state_53[trace_start_pos0], tran_state_52[trace_start_pos0], |
---|
3622 | tran_state_51[trace_start_pos0], tran_state_50[trace_start_pos0], tran_state_49[trace_start_pos0], tran_state_48[trace_start_pos0], |
---|
3623 | |
---|
3624 | tran_state_47[trace_start_pos0], tran_state_46[trace_start_pos0], tran_state_45[trace_start_pos0], tran_state_44[trace_start_pos0], |
---|
3625 | tran_state_43[trace_start_pos0], tran_state_42[trace_start_pos0], tran_state_41[trace_start_pos0], tran_state_40[trace_start_pos0], |
---|
3626 | tran_state_39[trace_start_pos0], tran_state_38[trace_start_pos0], tran_state_37[trace_start_pos0], tran_state_36[trace_start_pos0], |
---|
3627 | tran_state_35[trace_start_pos0], tran_state_34[trace_start_pos0], tran_state_33[trace_start_pos0], tran_state_32[trace_start_pos0], |
---|
3628 | |
---|
3629 | tran_state_31[trace_start_pos0], tran_state_30[trace_start_pos0], tran_state_29[trace_start_pos0], tran_state_28[trace_start_pos0], |
---|
3630 | tran_state_27[trace_start_pos0], tran_state_26[trace_start_pos0], tran_state_25[trace_start_pos0], tran_state_24[trace_start_pos0], |
---|
3631 | tran_state_23[trace_start_pos0], tran_state_22[trace_start_pos0], tran_state_21[trace_start_pos0], tran_state_20[trace_start_pos0], |
---|
3632 | tran_state_19[trace_start_pos0], tran_state_18[trace_start_pos0], tran_state_17[trace_start_pos0], tran_state_16[trace_start_pos0], |
---|
3633 | |
---|
3634 | tran_state_15[trace_start_pos0], tran_state_14[trace_start_pos0], tran_state_13[trace_start_pos0], tran_state_12[trace_start_pos0], |
---|
3635 | tran_state_11[trace_start_pos0], tran_state_10[trace_start_pos0], tran_state_9[trace_start_pos0], tran_state_8[trace_start_pos0], |
---|
3636 | tran_state_7[trace_start_pos0], tran_state_6[trace_start_pos0], tran_state_5[trace_start_pos0], tran_state_4[trace_start_pos0], |
---|
3637 | tran_state_3[trace_start_pos0], tran_state_2[trace_start_pos0], tran_state_1[trace_start_pos0], tran_state_0[trace_start_pos0]} ; |
---|
3638 | |
---|
3639 | assign tran_all_1 = { |
---|
3640 | tran_state_63[trace_start_pos1], tran_state_62[trace_start_pos1], tran_state_61[trace_start_pos1], tran_state_60[trace_start_pos1], |
---|
3641 | tran_state_59[trace_start_pos1], tran_state_58[trace_start_pos1], tran_state_57[trace_start_pos1], tran_state_56[trace_start_pos1], |
---|
3642 | tran_state_55[trace_start_pos1], tran_state_54[trace_start_pos1], tran_state_53[trace_start_pos1], tran_state_52[trace_start_pos1], |
---|
3643 | tran_state_51[trace_start_pos1], tran_state_50[trace_start_pos1], tran_state_49[trace_start_pos1], tran_state_48[trace_start_pos1], |
---|
3644 | |
---|
3645 | tran_state_47[trace_start_pos1], tran_state_46[trace_start_pos1], tran_state_45[trace_start_pos1], tran_state_44[trace_start_pos1], |
---|
3646 | tran_state_43[trace_start_pos1], tran_state_42[trace_start_pos1], tran_state_41[trace_start_pos1], tran_state_40[trace_start_pos1], |
---|
3647 | tran_state_39[trace_start_pos1], tran_state_38[trace_start_pos1], tran_state_37[trace_start_pos1], tran_state_36[trace_start_pos1], |
---|
3648 | tran_state_35[trace_start_pos1], tran_state_34[trace_start_pos1], tran_state_33[trace_start_pos1], tran_state_32[trace_start_pos1], |
---|
3649 | |
---|
3650 | tran_state_31[trace_start_pos1], tran_state_30[trace_start_pos1], tran_state_29[trace_start_pos1], tran_state_28[trace_start_pos1], |
---|
3651 | tran_state_27[trace_start_pos1], tran_state_26[trace_start_pos1], tran_state_25[trace_start_pos1], tran_state_24[trace_start_pos1], |
---|
3652 | tran_state_23[trace_start_pos1], tran_state_22[trace_start_pos1], tran_state_21[trace_start_pos1], tran_state_20[trace_start_pos1], |
---|
3653 | tran_state_19[trace_start_pos1], tran_state_18[trace_start_pos1], tran_state_17[trace_start_pos1], tran_state_16[trace_start_pos1], |
---|
3654 | |
---|
3655 | tran_state_15[trace_start_pos1], tran_state_14[trace_start_pos1], tran_state_13[trace_start_pos1], tran_state_12[trace_start_pos1], |
---|
3656 | tran_state_11[trace_start_pos1], tran_state_10[trace_start_pos1], tran_state_9[trace_start_pos1], tran_state_8[trace_start_pos1], |
---|
3657 | tran_state_7[trace_start_pos1], tran_state_6[trace_start_pos1], tran_state_5[trace_start_pos1], tran_state_4[trace_start_pos1], |
---|
3658 | tran_state_3[trace_start_pos1], tran_state_2[trace_start_pos1], tran_state_1[trace_start_pos1], tran_state_0[trace_start_pos1]} ; |
---|
3659 | |
---|
3660 | |
---|
3661 | assign cur_state1 = get_next_trace_state (cur_state0, tran_all_0) ; |
---|
3662 | assign next_state = get_next_trace_state (cur_state1, tran_all_1) ; |
---|
3663 | |
---|
3664 | assign state0_bit = cur_state0 [K -2] ; |
---|
3665 | assign state1_bit = cur_state1 [K -2] ; |
---|
3666 | |
---|
3667 | always @ (posedge clk or negedge nrst) |
---|
3668 | if(~nrst) |
---|
3669 | res <= 0 ; |
---|
3670 | else |
---|
3671 | begin |
---|
3672 | if (trace_pos) |
---|
3673 | res <= 0 ; |
---|
3674 | else if (trace_en) |
---|
3675 | begin |
---|
3676 | res <= {state1_bit, state0_bit, res [L-1:2]} ; |
---|
3677 | end |
---|
3678 | end |
---|
3679 | |
---|
3680 | //====================================== |
---|
3681 | // function: get_next_trace_state |
---|
3682 | //====================================== |
---|
3683 | function [K-2:0] get_next_trace_state ; |
---|
3684 | input [K-2:0] cur_state_in ; |
---|
3685 | input [N -1:0] tran_state_in ; |
---|
3686 | reg [N -1:0] tmp ; |
---|
3687 | begin |
---|
3688 | tmp = tran_state_in >> cur_state_in ; |
---|
3689 | get_next_trace_state = {cur_state_in [K-3:0], tmp[0]} ; |
---|
3690 | end |
---|
3691 | endfunction |
---|
3692 | |
---|
3693 | endmodule |
---|
3694 | |
---|
3695 | |
---|