OpenCores
URL https://opencores.org/ocsvn/qaz_libs/qaz_libs/trunk

Subversion Repositories qaz_libs

[/] [qaz_libs/] [trunk/] [BFM/] [src/] [8b10b/] [deserializer_8b10b_bfm_if.sv] - Blame information for rev 49

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 46 qaztronic
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
//// Copyright (C) 2018 Authors and OPENCORES.ORG                 ////
4
////                                                              ////
5
//// This source file may be used and distributed without         ////
6
//// restriction provided that this copyright statement is not    ////
7
//// removed from the file and that any derivative work contains  ////
8
//// the original copyright notice and the associated disclaimer. ////
9
////                                                              ////
10
//// This source file is free software; you can redistribute it   ////
11
//// and/or modify it under the terms of the GNU Lesser General   ////
12
//// Public License as published by the Free Software Foundation; ////
13
//// either version 2.1 of the License, or (at your option) any   ////
14
//// later version.                                               ////
15
////                                                              ////
16
//// This source is distributed in the hope that it will be       ////
17
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
18
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
19
//// PURPOSE.  See the GNU Lesser General Public License for more ////
20
//// details.                                                     ////
21
////                                                              ////
22
//// You should have received a copy of the GNU Lesser General    ////
23
//// Public License along with this source; if not, download it   ////
24
//// from http://www.opencores.org/lgpl.shtml                     ////
25
////                                                              ////
26
//////////////////////////////////////////////////////////////////////
27
// Chuck Benz, Hollis, NH   Copyright (c)2002
28
//
29
// The information and description contained herein is the
30
// property of Chuck Benz.
31
//
32
// Permission is granted for any reuse of this information
33
// and description as long as this copyright notice is
34
// preserved.  Modifications may be made as long as this
35
// notice is preserved.
36
// per Widmer and Franaszek
37
 
38
interface
39
  deserializer_8b10b_bfm_if
40
  ( input clk
41
  , input serial_in
42
  );
43
 
44
// --------------------------------------------------------------------
45
// --------------------------------------------------------------------
46
// module decode_8b10b (datain, dispin, dataout, dispout, code_err, disp_err) ;
47
  // input [9:0]   datain ;
48
  // input              dispin ;
49
  // output [8:0]       dataout ;
50
  // output     dispout ;
51
  // output     code_err ;
52
  // output     disp_err ;
53
 
54
  wire [9:0] datain;
55
  wire dispin;
56
  wire [8:0]    dataout ;
57
  wire  code_err ;
58
  wire  disp_err ;
59
 
60
  wire ai = datain[0] ;
61
  wire bi = datain[1] ;
62
  wire ci = datain[2] ;
63
  wire di = datain[3] ;
64
  wire ei = datain[4] ;
65
  wire ii = datain[5] ;
66
  wire fi = datain[6] ;
67
  wire gi = datain[7] ;
68
  wire hi = datain[8] ;
69
  wire ji = datain[9] ;
70
 
71
  wire aeqb = (ai & bi) | (!ai & !bi) ;
72
  wire ceqd = (ci & di) | (!ci & !di) ;
73
  wire p22 = (ai & bi & !ci & !di) |
74
             (ci & di & !ai & !bi) |
75
             ( !aeqb & !ceqd) ;
76
  wire p13 = ( !aeqb & !ci & !di) |
77
             ( !ceqd & !ai & !bi) ;
78
  wire p31 = ( !aeqb & ci & di) |
79
             ( !ceqd & ai & bi) ;
80
 
81
  wire p40 = ai & bi & ci & di ;
82
  wire p04 = !ai & !bi & !ci & !di ;
83
 
84
  wire disp6a = p31 | (p22 & dispin) ; // pos disp if p22 and was pos, or p31.
85
   wire disp6a2 = p31 & dispin ;  // disp is ++ after 4 bits
86
   wire disp6a0 = p13 & ! dispin ; // -- disp after 4 bits
87
 
88
  wire disp6b = (((ei & ii & ! disp6a0) | (disp6a & (ei | ii)) | disp6a2 |
89
                  (ei & ii & di)) & (ei | ii | di)) ;
90
 
91
  // The 5B/6B decoding special cases where ABCDE != abcde
92
 
93
  wire p22bceeqi = p22 & bi & ci & (ei == ii) ;
94
  wire p22bncneeqi = p22 & !bi & !ci & (ei == ii) ;
95
  wire p13in = p13 & !ii ;
96
  wire p31i = p31 & ii ;
97
  wire p13dei = p13 & di & ei & ii ;
98
  wire p22aceeqi = p22 & ai & ci & (ei == ii) ;
99
  wire p22ancneeqi = p22 & !ai & !ci & (ei == ii) ;
100
  wire p13en = p13 & !ei ;
101
  wire anbnenin = !ai & !bi & !ei & !ii ;
102
  wire abei = ai & bi & ei & ii ;
103
  wire cdei = ci & di & ei & ii ;
104
  wire cndnenin = !ci & !di & !ei & !ii ;
105
 
106
  // non-zero disparity cases:
107
  wire p22enin = p22 & !ei & !ii ;
108
  wire p22ei = p22 & ei & ii ;
109
  //wire p13in = p12 & !ii ;
110
  //wire p31i = p31 & ii ;
111
  wire p31dnenin = p31 & !di & !ei & !ii ;
112
  //wire p13dei = p13 & di & ei & ii ;
113
  wire p31e = p31 & ei ;
114
 
115
  wire compa = p22bncneeqi | p31i | p13dei | p22ancneeqi |
116
                p13en | abei | cndnenin ;
117
  wire compb = p22bceeqi | p31i | p13dei | p22aceeqi |
118
                p13en | abei | cndnenin ;
119
  wire compc = p22bceeqi | p31i | p13dei | p22ancneeqi |
120
                p13en | anbnenin | cndnenin ;
121
  wire compd = p22bncneeqi | p31i | p13dei | p22aceeqi |
122
                p13en | abei | cndnenin ;
123
  wire compe = p22bncneeqi | p13in | p13dei | p22ancneeqi |
124
                p13en | anbnenin | cndnenin ;
125
 
126
  wire ao = ai ^ compa ;
127
  wire bo = bi ^ compb ;
128
  wire co = ci ^ compc ;
129
  wire _do = di ^ compd ;
130
  wire eo = ei ^ compe ;
131
 
132
  wire feqg = (fi & gi) | (!fi & !gi) ;
133
  wire heqj = (hi & ji) | (!hi & !ji) ;
134
  wire fghj22 = (fi & gi & !hi & !ji) |
135
                (!fi & !gi & hi & ji) |
136
                ( !feqg & !heqj) ;
137
  wire fghjp13 = ( !feqg & !hi & !ji) |
138
                 ( !heqj & !fi & !gi) ;
139
  wire fghjp31 = ( (!feqg) & hi & ji) |
140
                 ( !heqj & fi & gi) ;
141
 
142
  wire dispout = (fghjp31 | (disp6b & fghj22) | (hi & ji)) & (hi | ji) ;
143
 
144
  wire ko = ( (ci & di & ei & ii) | ( !ci & !di & !ei & !ii) |
145
                (p13 & !ei & ii & gi & hi & ji) |
146
                (p31 & ei & !ii & !gi & !hi & !ji)) ;
147
 
148
  wire alt7 =   (fi & !gi & !hi & // 1000 cases, where disp6b is 1
149
                 ((dispin & ci & di & !ei & !ii) | ko |
150
                  (dispin & !ci & di & !ei & !ii))) |
151
                (!fi & gi & hi & // 0111 cases, where disp6b is 0
152
                 (( !dispin & !ci & !di & ei & ii) | ko |
153
                  ( !dispin & ci & !di & ei & ii))) ;
154
 
155
  wire k28 = (ci & di & ei & ii) | ! (ci | di | ei | ii) ;
156
  // k28 with positive disp into fghi - .1, .2, .5, and .6 special cases
157
  wire k28p = ! (ci | di | ei | ii) ;
158
  wire fo = (ji & !fi & (hi | !gi | k28p)) |
159
            (fi & !ji & (!hi | gi | !k28p)) |
160
            (k28p & gi & hi) |
161
            (!k28p & !gi & !hi) ;
162
  wire go = (ji & !fi & (hi | !gi | !k28p)) |
163
            (fi & !ji & (!hi | gi |k28p)) |
164
            (!k28p & gi & hi) |
165
            (k28p & !gi & !hi) ;
166
  wire ho = ((ji ^ hi) & ! ((!fi & gi & !hi & ji & !k28p) | (!fi & gi & hi & !ji & k28p) |
167
                            (fi & !gi & !hi & ji & !k28p) | (fi & !gi & hi & !ji & k28p))) |
168
            (!fi & gi & hi & ji) | (fi & !gi & !hi & !ji) ;
169
 
170
  wire disp6p = (p31 & (ei | ii)) | (p22 & ei & ii) ;
171
  wire disp6n = (p13 & ! (ei & ii)) | (p22 & !ei & !ii) ;
172
  wire disp4p = fghjp31 ;
173
  wire disp4n = fghjp13 ;
174
 
175
  assign code_err = p40 | p04 | (fi & gi & hi & ji) | (!fi & !gi & !hi & !ji) |
176
                    (p13 & !ei & !ii) | (p31 & ei & ii) |
177
                    (ei & ii & fi & gi & hi) | (!ei & !ii & !fi & !gi & !hi) |
178
                    (ei & !ii & gi & hi & ji) | (!ei & ii & !gi & !hi & !ji) |
179
                    (!p31 & ei & !ii & !gi & !hi & !ji) |
180
                    (!p13 & !ei & ii & gi & hi & ji) |
181
                    (((ei & ii & !gi & !hi & !ji) |
182
                      (!ei & !ii & gi & hi & ji)) &
183
                     ! ((ci & di & ei) | (!ci & !di & !ei))) |
184
                    (disp6p & disp4p) | (disp6n & disp4n) |
185
                    (ai & bi & ci & !ei & !ii & ((!fi & !gi) | fghjp13)) |
186
                    (!ai & !bi & !ci & ei & ii & ((fi & gi) | fghjp31)) |
187
                    (fi & gi & !hi & !ji & disp6p) |
188
                    (!fi & !gi & hi & ji & disp6n) |
189
                    (ci & di & ei & ii & !fi & !gi & !hi) |
190
                    (!ci & !di & !ei & !ii & fi & gi & hi) ;
191
 
192
  assign dataout = {ko, ho, go, fo, eo, _do, co, bo, ao} ;
193
 
194
  // my disp err fires for any legal codes that violate disparity, may fire for illegal codes
195
   assign disp_err = ((dispin & disp6p) | (disp6n & !dispin) |
196
                      (dispin & !disp6n & fi & gi) |
197
                      (dispin & ai & bi & ci) |
198
                      (dispin & !disp6n & disp4p) |
199
                      (!dispin & !disp6p & !fi & !gi) |
200
                      (!dispin & !ai & !bi & !ci) |
201
                      (!dispin & !disp6p & disp4n) |
202
                      (disp6p & disp4p) | (disp6n & disp4n)) ;
203
 
204
// endmodule
205
// --------------------------------------------------------------------
206
// --------------------------------------------------------------------
207
 
208
  // --------------------------------------------------------------------
209
  localparam COMMAS_TO_LOCK = 5;
210
  localparam K28_5 = 10'b1010000011;
211
 
212
  // --------------------------------------------------------------------
213
  logic [9:0] parallel_data = 0;
214
  logic [9:0] comma_char = K28_5;
215
  int cycle;
216
  bit dataout_valid;
217
 
218
  // --------------------------------------------------------------------
219
  default clocking cb @(posedge clk);
220
    input serial_in;
221
    inout parallel_data;
222
    inout cycle;
223
    inout dataout_valid;
224
  endclocking
225
 
226
  // --------------------------------------------------------------------
227
  task zero_cycle_delay;
228
    ##0;
229
  endtask: zero_cycle_delay
230
 
231
  // --------------------------------------------------------------------
232
  wire comma_sync = (parallel_data == comma_char);
233
 
234
  always @(cb)
235
    cb.parallel_data <= {cb.serial_in, cb.parallel_data[9:1]};
236
 
237
  // --------------------------------------------------------------------
238
  always @(cb)
239
    if(comma_sync)
240
      cb.cycle <= 1;
241
    else if(cb.cycle == 9)
242
      cb.cycle <= 0;
243
    else
244
      cb.cycle <= cb.cycle + 1;
245
 
246
  // --------------------------------------------------------------------
247
  int locked_count = 0;
248
  wire locked = locked_count >= COMMAS_TO_LOCK;
249
 
250
  always @(cb iff comma_sync)
251
    if(cb.cycle == 0)
252
    begin
253
      if(locked_count < COMMAS_TO_LOCK)
254
        locked_count++;
255
    end
256
    else
257
      locked_count = 0;
258
 
259
  // --------------------------------------------------------------------
260
  reg [9:0] parallel_data_r;
261
  wire [9:0] parallel_data_msb = {<<{parallel_data_r}};
262
  wire [5:0] data_6b = parallel_data_msb[9:4];
263
  wire [3:0] data_4b = parallel_data_msb[3:0];
264
 
265
  always @(cb)
266
    if(cb.cycle == 0)
267
      parallel_data_r <= cb.parallel_data;
268
 
269
  // --------------------------------------------------------------------
270
  int disparity;
271
  int running_disparity;
272
 
273
  always @(cb)
274
    if(~locked)
275
      if(dispout)
276
        running_disparity = 1;
277
      else
278
        running_disparity = -1;
279
    else if(cb.cycle == 0)
280
    begin
281
      disparity = 0;
282
      for(int i = 0; i < 10; i++)
283
        if(cb.parallel_data[i] == 1'b1)
284
          disparity++;
285
        else
286
          disparity--;
287
      running_disparity = running_disparity - disparity;
288
    end
289
 
290
  // --------------------------------------------------------------------
291
  assign datain = parallel_data_r;
292
  logic dispin_r;
293
  assign dispin = dispin_r;
294
 
295
  always @(cb)
296
    if(cb.cycle == 0)
297
      dispin_r <= dispout;
298
 
299
  // --------------------------------------------------------------------
300
  always @(cb)
301
    if(cb.cycle == 5)
302
      cb.dataout_valid <= 1;
303
    else
304
      cb.dataout_valid <= 0;
305
 
306
  // --------------------------------------------------------------------
307
  wire [7:0] dataout_msb = {<<{dataout[7:0]}};
308
  wire [4:0] data_5b = dataout[4:0];
309
  wire [2:0] data_3b = dataout[7:5];
310
  wire data_k = dataout[8];
311
 
312
// --------------------------------------------------------------------
313
endinterface

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.