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

Subversion Repositories qaz_libs

[/] [qaz_libs/] [trunk/] [coaxpress/] [cx_encoder.v] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 qaztronic
//
2
//
3
//
4
 
5
`timescale 10ps/1ps
6
 
7
 
8
module
9
  cx_encoder
10
  #(
11
    parameter CLK_PERIOD      = 320
12
  )
13
  (
14
    output data_out
15
  );
16
 
17
  // --------------------------------------------------------------------
18
  //
19
  wire tx_clock;
20
 
21
  tb_clk #( .CLK_PERIOD(CLK_PERIOD) ) i_tx_clock  ( tx_clock );
22
 
23
 
24
  // --------------------------------------------------------------------
25
  //
26
  wire tx_clock_10x;
27
  wire clock_good;
28
 
29
  clock_mult
30
    #( .MULT(10) )
31
    tx_clock_10x_i
32
    (
33
      .clock_in(tx_clock),
34
      .clock_out(tx_clock_10x),
35
      .clock_good(clock_good),
36
 
37
      .reset(1'b0)
38
    );
39
 
40
 
41
  // --------------------------------------------------------------------
42
  //
43
  reg [9:0] word_10b[3:0];
44
  reg       word_10b_out;
45
  integer   word_10b_index = 0;
46
  integer   bit_index;
47
 
48
  initial
49
    begin
50
 
51
      repeat(3)
52
        @(posedge tx_clock);
53
 
54
      forever
55
        for( word_10b_index = 0; word_10b_index < 4; word_10b_index = word_10b_index + 1)
56
          for( bit_index = 0; bit_index < 10; bit_index = bit_index + 1)
57
            @(negedge tx_clock_10x)
58
              word_10b_out <= word_10b[word_10b_index][bit_index];
59
 
60
    end
61
 
62
 
63
  // --------------------------------------------------------------------
64
  //
65
  function automatic [8:0] encode_8b_word;
66
  input [7:0] word_k;
67
  input [4:0] word_5b;
68
  input [2:0] word_3b;
69
    if( (word_k == "k") | (word_k == "K") )
70
      encode_8b_word = { 1'b1, word_3b, word_5b };
71
    else
72
      encode_8b_word = { 1'b0, word_3b, word_5b };
73
  endfunction
74
 
75
  localparam K27_7 = encode_8b_word( "K", 27, 7 );  //  K27.7 Start of data packet indication
76
  localparam K28_0 = encode_8b_word( "K", 28, 0 );  //  K28.0 GPIO indication
77
  localparam K28_1 = encode_8b_word( "K", 28, 1 );  //  K28.1 Used for alignment
78
  localparam K28_2 = encode_8b_word( "K", 28, 2 );  //  K28.2 Rising trigger indication
79
  localparam K28_3 = encode_8b_word( "K", 28, 3 );  //  K28.3 Stream marker – see section 7.2
80
  localparam K28_4 = encode_8b_word( "K", 28, 4 );  //  K28.4 Falling trigger indication
81
  localparam K28_5 = encode_8b_word( "K", 28, 5 );  //  K28.5 Used for alignment
82
  localparam K28_6 = encode_8b_word( "K", 28, 6 );  //  K28.6 I/O acknowledgement
83
  localparam K28_7 = encode_8b_word( "K", 28, 7 );  //  K29.7 End of data packet indication
84
 
85
  localparam D21_5 = encode_8b_word( "D", 21, 5 );
86
 
87
 
88
  // --------------------------------------------------------------------
89
  //
90
  reg   [8:0] encode_8b10b_datain_mux   = 0;
91
  reg         encode_8b10b_dispin       = 0;  // 0 = neg disp; 1 = pos disp
92
  wire  [9:0] encode_8b10b_dataout_mux;
93
  wire        encode_8b10b_dispout;
94
 
95
  encode_8b10b
96
    i_encode_8b10b
97
    (
98
      .datain(encode_8b10b_datain_mux),
99
      .dispin(encode_8b10b_dispin),
100
      .dataout(encode_8b10b_dataout_mux),
101
      .dispout(encode_8b10b_dispout)
102
    );
103
 
104
 
105
  // --------------------------------------------------------------------
106
  //
107
  reg   [8:0] word_8b[3:0];
108
  reg         word_8b_we = 0;
109
 
110
  initial
111
    begin
112
      word_8b[0] = K28_5;
113
      word_8b[1] = K28_1;
114
      word_8b[2] = K28_1;
115
      word_8b[3] = D21_5;
116
    end
117
 
118
  always @(posedge tx_clock)
119
    begin
120
      encode_8b10b_datain_mux   = word_8b[word_10b_index];
121
      #1;
122
      word_8b_we = 1;
123
      encode_8b10b_dispin       = encode_8b10b_dispout;
124
      word_10b[word_10b_index]  = encode_8b10b_dataout_mux;
125
      #1;
126
      word_8b_we = 0;
127
    end
128
 
129
 
130
  // --------------------------------------------------------------------
131
  //  debug
132
`ifdef DEBUG_COAXPRESS
133
  wire [8:0]  dbg_8b_word =     {
134
                                  i_encode_8b10b.ai,
135
                                  i_encode_8b10b.bi,
136
                                  i_encode_8b10b.ci,
137
                                  i_encode_8b10b.di,
138
                                  i_encode_8b10b.ei,
139
                                  i_encode_8b10b.fi,
140
                                  i_encode_8b10b.gi,
141
                                  i_encode_8b10b.hi,
142
                                  i_encode_8b10b.ki
143
                                };
144
 
145
  wire [5:0]  dbg_5b_6b_word =  {
146
                                  i_encode_8b10b.ao,
147
                                  i_encode_8b10b.bo,
148
                                  i_encode_8b10b.co,
149
                                  i_encode_8b10b.do,
150
                                  i_encode_8b10b.eo,
151
                                  i_encode_8b10b.io
152
                                };
153
 
154
  wire [3:0]  dbg_3b_4b_word =  {
155
                                  i_encode_8b10b.fo,
156
                                  i_encode_8b10b.go,
157
                                  i_encode_8b10b.ho,
158
                                  i_encode_8b10b.jo
159
                                };
160
 
161
  reg [9:0] dbg_serial_ls;
162
  reg [9:0] dbg_serial_rs;
163
 
164
  always @(posedge tx_clock_10x)
165
    begin
166
      dbg_serial_ls = { dbg_serial_ls[8:0], data_out };
167
      dbg_serial_rs = { data_out, dbg_serial_rs[9:1] };
168
    end
169
 
170
  localparam K27_7_10b = 10'b110110_1000;  //  K27.7 Start of data packet indication
171
  localparam K28_0_10b = 10'b001111_0100;  //  K28.0 GPIO indication
172
  localparam K28_6_10b = 10'b001111_0110;  //  K28.6 I/O acknowledgement
173
  localparam K28_1_10b = 10'b001111_1001;  //  K28.1 Used for alignment
174
  localparam K28_2_10b = 10'b001111_0101;  //  K28.2 Rising trigger indication
175
  localparam K28_3_10b = 10'b001111_0011;  //  K28.3 Stream marker – see section 7.2
176
  localparam K28_4_10b = 10'b001111_0010;  //  K28.4 Falling trigger indication
177
  localparam K28_5_10b = 10'b001111_1010;  //  K28.5 Used for alignment
178
  localparam K28_7_10b = 10'b001111_1000;  //  K29.7 End of data packet indication
179
 
180
  localparam D21_5_10b = 10'b101010_1010;
181
 
182
 
183
  wire dbg_K28_5_10b_is_ls = (dbg_serial_ls == K28_5_10b) | (dbg_serial_ls == ~K28_5_10b);
184
  wire dbg_K28_1_10b_is_ls = (dbg_serial_ls == K28_1_10b) | (dbg_serial_ls == ~K28_1_10b);
185
  wire dbg_D21_5_10b_is_ls = (dbg_serial_ls == D21_5_10b) | (dbg_serial_ls == ~D21_5_10b);
186
 
187
  wire dbg_K28_5_10b_is_rs = (dbg_serial_rs == K28_5_10b) | (dbg_serial_rs == ~K28_5_10b);
188
  wire dbg_K28_1_10b_is_rs = (dbg_serial_rs == K28_1_10b) | (dbg_serial_rs == ~K28_1_10b);
189
  wire dbg_D21_5_10b_is_rs = (dbg_serial_rs == D21_5_10b) | (dbg_serial_rs == ~D21_5_10b);
190
`endif
191
 
192
 
193
  // --------------------------------------------------------------------
194
  //
195
  assign data_out = word_10b_out;
196
 
197
 
198
endmodule
199
 
200
 
201
 

powered by: WebSVN 2.1.0

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