42 // input data comes this way (standart 8/10 bit notation) 43 // cycle 0: {[hgfedcba]=1st byte,[hgfedcba]=0st byte} 44 // cycle 1: {[hgfedcba]=3rd byte,[hgfedcba]=2dn byte} 45 // => {[cycle1 data], [cycle0 data]} = as if we were reading by dwords 48 // outdata contains comma 50 // pulse, indicating that stream was once again adjusted to a comma 51 // if asserted after link was down - OK 52 // if asserted during a work - most likely indicates an error in a stream 54 // asserted when input stream looks like comma, but it is not 55 // later on after 10/8 it would get something link NOTINTHETABLE error anyways 58 // only comma character = K28.5, has 5 '1's or 5 '0's in a row. 59 // after we met it, call it a comma group, we could compare other symbols 64 always @ (posedge clk) 66 assign window = {indata_r[17:0], indata[19:14]}; 68 // search for a comma group - parallel 24-bit window into 20 5-bit words 69 // transposed -> 5 x 20-bit words 75 assign lane0 = window[19:0]; 76 assign lane1 = window[20:1]; 77 assign lane2 = window[21:2]; 78 assign lane3 = window[22:3]; 79 assign lane4 = window[23:4]; 80 // calcute at what position in a window comma group is detected, 81 // so the position in actual {indata_r, indata} would be +2 from the left side 82 wire [19:0] comma_pos; 83 assign comma_pos = lane0 & lane1 & lane2 & lane3 & lane4; 87 // TODO make it less expensive 90 always @ (
posedge clk)
94 // there is only 1 matched subwindow due to 20-bit comma's non-repetative pattern 101 wire [
19:
0]
comma_p =
20'b10101010100101111100;
102 wire [
19:
0]
comma_n =
20'b10101010101010000011;
106 for (
ii =
0;
ii <
20;
ii =
ii +
1)
107 begin:
look_for_comma 109 // assign comma_match[ii] = subwindow[ii] == 20'b01010101010011111010 | subwindow[ii] == 20'b01010101011100000101; 110 // stream comes inverted 118 // save the shift count 123 wire [38:0] shifted_window; 124 assign shifted_window = comma_detected ? {window >> (comma_match - 1)} : {window >> (comma_match_prev - 1)}; 133 for (
ii =
1;
ii <
20;
ii =
ii +
1)
134 begin:
or_all_possible_windows 142 // aligned_data <= comma_detected ? {window >> (comma_match - 1)}[19:0] : {window >> (comma_match_prev - 1)}[19:0];
14772aligned_datareg[19:0]
14770comma_matchwire[19:0]
14777shifted_windowwire[19:0]
[19:0] 14769subwindowwire[19:0]
[19:0] 14778ored_subwindowwire[19:0]
[19:0] 14779ored_subwindow_comdetwire[19:0]
14771comma_match_pwire[19:0]
14773comma_match_prevreg[19:0]