aboutsummaryrefslogtreecommitdiffstats
path: root/top/eth_test/eth_tb.v
blob: 451ce1e7edcc50f157f4a1edfc92b4057d96c82b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////

// Nearly everything is an input

module eth_tb();
   // Misc, debug
   wire led1;
   wire led2;
   wire [31:0] debug;
   wire [1:0]  debug_clk;
   
   // Expansion
   wire        exp_pps_in;
   wire        exp_pps_out;
   
   // GMII
   //   GMII-CTRL
   wire        GMII_COL;
   wire        GMII_CRS;
   
   //   GMII-TX
   wire [7:0]  GMII_TXD;
   wire        GMII_TX_EN;
   wire        GMII_TX_ER;
   wire        GMII_GTX_CLK;
   wire        GMII_TX_CLK;  // 100mbps clk
   
   //   GMII-RX
   wire [7:0]  GMII_RXD;
   wire        GMII_RX_CLK;
   wire        GMII_RX_DV;
   wire        GMII_RX_ER;
   
   //   GMII-Management
   wire        MDIO;
   wire        MDC;
   wire        PHY_INTn;   // open drain
   wire        PHY_RESETn;
   wire        PHY_CLK;   // possibly use on-board osc
   
   // RAM
   wire [17:0] RAM_D;
   wire [18:0] RAM_A;
   wire        RAM_CE1n;
   wire        RAM_CENn;
   wire        RAM_CLK;
   wire        RAM_WEn;
   wire        RAM_OEn;
   wire        RAM_LDn;
   
   // SERDES
   wire        ser_enable;
   wire        ser_prbsen;
   wire        ser_loopen;
   wire        ser_rx_en;
   
   wire        ser_tx_clk;
   wire [15:0] ser_t;
   wire        ser_tklsb;
   wire        ser_tkmsb;
   
   wire        ser_rx_clk;
   wire [15:0] ser_r;
   wire        ser_rklsb;
   wire        ser_rkmsb;
   
   // CPLD interface
   wire        cpld_din, cpld_clk, cpld_detached, cpld_start, cpld_mode, cpld_done;
      
   // ADC
   wire [13:0] adc_a;
   wire        adc_ovf_a;
   wire        adc_oen_a;
   wire        adc_pdn_a;
   
   wire [13:0] adc_b;
   wire        adc_ovf_b;
   wire        adc_oen_b;
   wire        adc_pdn_b;
   
   // DAC
   wire [15:0] dac_a;
   wire [15:0] dac_b;
   
   // I2C
   wire        SCL;
   wire        SDA;
   
   // Clock Gen Control
   wire [1:0]  clk_en;
   wire [1:0]  clk_sel;
   wire        clk_func;        // FIXME is an input to control the 9510
   wire        clk_status;
   
   // Clocks
   reg        clk_fpga;
   wire        clk_to_mac;
   wire        pps_in;
   
   // Generic SPI
   wire        sclk, mosi, miso;   
   wire        sen_clk;
   wire        sen_dac;
   wire        sen_tx_db;
   wire        sen_tx_adc;
   wire        sen_tx_dac;
   wire        sen_rx_db;
   wire        sen_rx_adc;
   wire        sen_rx_dac;
   
   // GPIO to DBoards
   wire [15:0] io_tx;
   wire [15:0] io_rx;
   
   wire        wb_clk, wb_rst;
   wire        start, clock_ready;
   
   reg 	       aux_clk;

   initial aux_clk= 1'b0;
   always #25 aux_clk = ~aux_clk;
   
   initial clk_fpga = 1'bx;
   initial #3007 clk_fpga = 1'b0;
   always #7 clk_fpga = ~clk_fpga;


   wire        div_clk;
   reg [2:0]   div_ctr = 0;
   
   always @(posedge clk_fpga or negedge clk_fpga)
     if(div_ctr==5)
       div_ctr = 0;
     else
       div_ctr = div_ctr + 1;
   assign      div_clk = (div_ctr == 0) | (div_ctr == 1) | (div_ctr == 2);
   
   assign      dsp_clk = clk_fpga;
   assign      wb_clk = clock_ready ? div_clk : aux_clk;

   initial
     $monitor($time, ,clock_ready);
   
   initial begin
      $dumpfile("eth_tb.vcd");
      $dumpvars(0,eth_tb);
   end

   initial #10000000 $finish;

   cpld_model 
     cpld_model (.aux_clk(aux_clk),.start(cpld_start),.mode(cpld_mode),.done(cpld_done),
		 .dout(cpld_din),.sclk(cpld_clk),.detached(cpld_detached));
   
   eth_sim_top eth_sim_top(.dsp_clk		(dsp_clk),
			   .wb_clk            (wb_clk),
			   .clock_ready	(clock_ready),
			   .clk_to_mac	(clk_to_mac),
			   .pps_in		(pps_in),
			   .led1		(led1),
			   .led2		(led2),
			   .debug		(debug[31:0]),
			   .debug_clk		(debug_clk[1:0]),
			   .exp_pps_in	(exp_pps_in),
			   .exp_pps_out	(exp_pps_out),
			   .GMII_COL		(GMII_COL),
			   .GMII_CRS		(GMII_CRS),
			   .GMII_TXD		(GMII_TXD[7:0]),
			   .GMII_TX_EN	(GMII_TX_EN),
			   .GMII_TX_ER	(GMII_TX_ER),
			   .GMII_GTX_CLK	(GMII_GTX_CLK),
			   .GMII_TX_CLK	(GMII_TX_CLK),
			   .GMII_RXD		(GMII_RXD[7:0]),
			   .GMII_RX_CLK	(GMII_RX_CLK),
			   .GMII_RX_DV	(GMII_RX_DV),
			   .GMII_RX_ER	(GMII_RX_ER),
			   .MDIO		(MDIO),
			   .MDC		(MDC),
			   .PHY_INTn		(PHY_INTn),
			   .PHY_RESETn	(PHY_RESETn),
			   .PHY_CLK		(PHY_CLK),
			   .ser_enable	(ser_enable),
			   .ser_prbsen	(ser_prbsen),
			   .ser_loopen	(ser_loopen),
			   .ser_rx_en		(ser_rx_en),
			   .ser_tx_clk	(ser_tx_clk),
			   .ser_t		(ser_t[15:0]),
			   .ser_tklsb		(ser_tklsb),
			   .ser_tkmsb		(ser_tkmsb),
			   .ser_rx_clk	(ser_rx_clk),
			   .ser_r		(ser_r[15:0]),
			   .ser_rklsb		(ser_rklsb),
			   .ser_rkmsb		(ser_rkmsb),
			   .cpld_start	(cpld_start),
			   .cpld_mode		(cpld_mode),
			   .cpld_done		(cpld_done),
			   .cpld_din		(cpld_din),
			   .cpld_clk		(cpld_clk),
			   .cpld_detached	(cpld_detached),
			   .adc_a		(adc_a[13:0]),
			   .adc_ovf_a		(adc_ovf_a),
			   .adc_oen_a		(adc_oen_a),
			   .adc_pdn_a		(adc_pdn_a),
			   .adc_b		(adc_b[13:0]),
			   .adc_ovf_b		(adc_ovf_b),
			   .adc_oen_b		(adc_oen_b),
			   .adc_pdn_b		(adc_pdn_b),
			   .dac_a		(dac_a[15:0]),
			   .dac_b		(dac_b[15:0]),
			   .scl_pad_i		(scl_pad_i),
			   .scl_pad_o		(scl_pad_o),
			   .scl_pad_oen_o	(scl_pad_oen_o),
			   .sda_pad_i		(sda_pad_i),
			   .sda_pad_o		(sda_pad_o),
			   .sda_pad_oen_o	(sda_pad_oen_o),
			   .clk_en		(clk_en[1:0]),
			   .clk_sel		(clk_sel[1:0]),
			   .clk_func		(clk_func),
			   .clk_status	(clk_status),
			   .sclk		(sclk),
			   .mosi		(mosi),
			   .miso		(miso),
			   .sen_clk		(sen_clk),
			   .sen_dac		(sen_dac),
			   .sen_tx_db		(sen_tx_db),
			   .sen_tx_adc	(sen_tx_adc),
			   .sen_tx_dac	(sen_tx_dac),
			   .sen_rx_db		(sen_rx_db),
			   .sen_rx_adc	(sen_rx_adc),
			   .sen_rx_dac	(sen_rx_dac),
			   .io_tx		(io_tx[15:0]),
			   .io_rx		(io_rx[15:0]));
   
   // Experimental printf-like function
   always @(posedge wb_clk)
     begin
	if((eth_sim_top.m0_we == 1'd1)&&(eth_sim_top.m0_adr == 16'hC000))
	  $write("%x",eth_sim_top.m0_dat_i);
	if((eth_sim_top.m0_we == 1'd1)&&(eth_sim_top.m0_adr == 16'hC100))
	  $display("%x",eth_sim_top.m0_dat_i);
	if((eth_sim_top.m0_we == 1'd1)&&(eth_sim_top.m0_adr == 16'hC004))
	  $write("%c",eth_sim_top.m0_dat_i);
	if((eth_sim_top.m0_we == 1'd1)&&(eth_sim_top.m0_adr == 16'hC104))
	  $display("%c",eth_sim_top.m0_dat_i);
	if((eth_sim_top.m0_we == 1'd1)&&(eth_sim_top.m0_adr == 16'hC008))
	  $display("");
     end
	

endmodule // u2_sim_top

// Local Variables:
// verilog-library-directories:("." "subdir" "subdir2")
// verilog-library-files:("/home/matt/u2f/top/u2_basic/u2_basic.v")
// verilog-library-extensions:(".v" ".h")
// End: