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

Subversion Repositories qaz_libs

[/] [qaz_libs/] [trunk/] [camera_link/] [sim/] [src/] [tb_channel_link_rx_if.sv] - Blame information for rev 27

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

Line No. Rev Author Line
1 27 qaztronic
// --------------------------------------------------------------------
2
//
3
// --------------------------------------------------------------------
4
 
5
 
6
interface
7
  tb_channel_link_rx_if
8
  (
9
    input [3:0]  p,
10
    input [3:0]  n,
11
    input [4:0]  invert_mux,
12
    input        reset,
13
    input        clk_p,
14
    input        clk_n
15
  );
16
 
17
    // --------------------------------------------------------------------
18
    //
19
    timeunit 1ps / 1ps;
20
    time clk_period = 0;
21
    time clk_7x_period = 0;
22
    time strobe_delay = 0;
23
 
24
 
25
    // --------------------------------------------------------------------
26
    //
27
    int bit_index;
28
    logic clk_7x;
29
    wire tx_clk = invert_mux[4] ? ~clk_p : clk_p;
30
 
31
 
32
    // --------------------------------------------------------------------
33
    //
34
    default clocking cb @(posedge tx_clk);
35
      input p;
36
      input n;
37
      input reset;
38
    endclocking
39
 
40
 
41
    // --------------------------------------------------------------------
42
    //
43
    localparam B = 7;
44
 
45
 
46
    // --------------------------------------------------------------------
47
    //
48
    task
49
      generate_clocks
50
      (
51
        time clk_7x_period,
52
        time strobe_delay
53
      );
54
 
55
        bit_index = 5;
56
 
57
        forever
58
          @(cb)
59
          begin
60
 
61
            #strobe_delay;
62
            clk_7x <= 1;
63
 
64
            generate_clk_7x_fork : fork
65
            begin
66
              repeat((B * 2) - 1)
67
              begin
68
                #(clk_7x_period / 2);
69
                clk_7x <= ~clk_7x;
70
 
71
                if(clk_7x == 1)
72
                  if(bit_index == 6)
73
                    bit_index = 0;
74
                  else
75
                    bit_index++;
76
 
77
              end
78
            end
79
            join_none
80
 
81
          end
82
 
83
    endtask: generate_clocks
84
 
85
 
86
    // --------------------------------------------------------------------
87
    //
88
    logic [6:0] rx_in [4];
89
 
90
    always @(posedge clk_7x)
91
    begin
92
      rx_in[3][bit_index] <= invert_mux[3] ? ~p[3] : p[3];
93
      rx_in[2][bit_index] <= invert_mux[2] ? ~p[2] : p[2];
94
      rx_in[1][bit_index] <= invert_mux[1] ? ~p[1] : p[1];
95
      rx_in[0][bit_index] <= invert_mux[0] ? ~p[0] : p[0];
96
    end
97
 
98
 
99
    // --------------------------------------------------------------------
100
    //
101
    logic [27:0] rx_data;
102
 
103
    always @(posedge clk_7x)
104
      if(bit_index == 6)
105
      begin
106
        //        6           5             4           3             2           1             0
107
        {rx_data[27], rx_data[ 5], rx_data[10], rx_data[11], rx_data[16], rx_data[17], rx_data[23]} <= {invert_mux[3] ? ~p[3] : p[3], rx_in[3][5:0]};
108
        {rx_data[19], rx_data[20], rx_data[21], rx_data[22], rx_data[24], rx_data[25], rx_data[26]} <= {invert_mux[2] ? ~p[2] : p[2], rx_in[2][5:0]};
109
        {rx_data[ 8], rx_data[ 9], rx_data[12], rx_data[13], rx_data[14], rx_data[15], rx_data[18]} <= {invert_mux[1] ? ~p[1] : p[1], rx_in[1][5:0]};
110
        {rx_data[ 0], rx_data[ 1], rx_data[ 2], rx_data[ 3], rx_data[ 4], rx_data[ 6], rx_data[ 7]} <= {invert_mux[0] ? ~p[0] : p[0], rx_in[0][5:0]};
111
      end
112
 
113
 
114
    // --------------------------------------------------------------------
115
    //
116
    wire        dval       = rx_data[26];
117
    wire        fval       = rx_data[25];
118
    wire        lval       = rx_data[24];
119
    wire        spare      = rx_data[23];
120
    wire [7:0]  port_a_d_g = {rx_data[5],      rx_data[27],    rx_data[6], rx_data[4:0]};
121
    wire [7:0]  port_b_e_h = {rx_data[11],     rx_data[10],    rx_data[14:12], rx_data[9:7]};
122
    wire [7:0]  port_c_f   = {rx_data[17:16],  rx_data[22:18], rx_data[15]};
123
 
124
 
125
    // --------------------------------------------------------------------
126
    //
127
    task
128
      init_clocks;
129
 
130
        time clk_rise_t;
131
 
132
        @(cb iff ~reset);
133
        clk_rise_t = $time;
134
 
135
        @(cb iff ~reset);
136
        clk_period  = $time - clk_rise_t;
137
        clk_7x_period = clk_period / B;
138
        strobe_delay = clk_7x_period / 2;
139
 
140
        $display("^^^ %16.t | %m | clk_period     = %t, ", $time, clk_period);
141
        $display("^^^ %16.t | %m | clk_7x_period  = %t", $time, clk_7x_period);
142
        $display("^^^ %16.t | %m | strobe_delay   = %t", $time, strobe_delay);
143
 
144
        generate_clocks_fork : fork
145
          generate_clocks(clk_7x_period, strobe_delay);
146
        join_none
147
 
148
    endtask: init_clocks
149
 
150
 
151
    // --------------------------------------------------------------------
152
    //
153
    initial
154
    begin
155
 
156
      wait(~reset);
157
      #500ns;
158
 
159
      init_clocks();
160
    end
161
 
162
 
163
    // --------------------------------------------------------------------
164
    //
165
 
166
endinterface
167
 

powered by: WebSVN 2.1.0

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