| 1 |
116 |
mohor |
//////////////////////////////////////////////////////////////////////
|
| 2 |
|
|
//// ////
|
| 3 |
|
|
//// tb_ethernet.v ////
|
| 4 |
|
|
//// ////
|
| 5 |
|
|
//// This file is part of the Ethernet IP core project ////
|
| 6 |
|
|
//// http://www.opencores.org/projects/ethmac/ ////
|
| 7 |
|
|
//// ////
|
| 8 |
|
|
//// Author(s): ////
|
| 9 |
169 |
mohor |
//// - Tadej Markovic, tadej@opencores.org ////
|
| 10 |
243 |
tadejm |
//// - Igor Mohor, igorM@opencores.org ////
|
| 11 |
116 |
mohor |
//// ////
|
| 12 |
169 |
mohor |
//// All additional information is available in the Readme.txt ////
|
| 13 |
116 |
mohor |
//// file. ////
|
| 14 |
|
|
//// ////
|
| 15 |
|
|
//////////////////////////////////////////////////////////////////////
|
| 16 |
|
|
//// ////
|
| 17 |
|
|
//// Copyright (C) 2001, 2002 Authors ////
|
| 18 |
|
|
//// ////
|
| 19 |
|
|
//// This source file may be used and distributed without ////
|
| 20 |
|
|
//// restriction provided that this copyright statement is not ////
|
| 21 |
|
|
//// removed from the file and that any derivative work contains ////
|
| 22 |
|
|
//// the original copyright notice and the associated disclaimer. ////
|
| 23 |
|
|
//// ////
|
| 24 |
|
|
//// This source file is free software; you can redistribute it ////
|
| 25 |
|
|
//// and/or modify it under the terms of the GNU Lesser General ////
|
| 26 |
|
|
//// Public License as published by the Free Software Foundation; ////
|
| 27 |
|
|
//// either version 2.1 of the License, or (at your option) any ////
|
| 28 |
|
|
//// later version. ////
|
| 29 |
|
|
//// ////
|
| 30 |
|
|
//// This source is distributed in the hope that it will be ////
|
| 31 |
|
|
//// useful, but WITHOUT ANY WARRANTY; without even the implied ////
|
| 32 |
|
|
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ////
|
| 33 |
|
|
//// PURPOSE. See the GNU Lesser General Public License for more ////
|
| 34 |
|
|
//// details. ////
|
| 35 |
|
|
//// ////
|
| 36 |
|
|
//// You should have received a copy of the GNU Lesser General ////
|
| 37 |
|
|
//// Public License along with this source; if not, download it ////
|
| 38 |
|
|
//// from http://www.opencores.org/lgpl.shtml ////
|
| 39 |
|
|
//// ////
|
| 40 |
|
|
//////////////////////////////////////////////////////////////////////
|
| 41 |
|
|
//
|
| 42 |
|
|
// CVS Revision History
|
| 43 |
|
|
//
|
| 44 |
|
|
// $Log: not supported by cvs2svn $
|
| 45 |
274 |
tadejm |
// Revision 1.25 2002/11/27 16:21:55 mohor
|
| 46 |
|
|
// Full duplex control frames tested.
|
| 47 |
|
|
//
|
| 48 |
267 |
mohor |
// Revision 1.24 2002/11/22 17:29:42 mohor
|
| 49 |
|
|
// Flow control test almost finished.
|
| 50 |
|
|
//
|
| 51 |
266 |
mohor |
// Revision 1.23 2002/11/22 02:12:16 mohor
|
| 52 |
|
|
// test_mac_full_duplex_flow_control tests pretty much finished.
|
| 53 |
|
|
// TEST 0: INSERT CONTROL FRM. WHILE TRANSMITTING NORMAL
|
| 54 |
|
|
// FRM. AT 4 TX BD ( 10Mbps ) finished.
|
| 55 |
|
|
// TEST 2: RECEIVE CONTROL FRAMES WITH PASSALL OPTION
|
| 56 |
|
|
// TURNED OFF AT ONE RX BD ( 10Mbps ) finished.
|
| 57 |
|
|
//
|
| 58 |
263 |
mohor |
// Revision 1.22 2002/11/21 13:56:50 mohor
|
| 59 |
|
|
// test_mac_full_duplex_flow test 0 finished. Sending the control (PAUSE) frame
|
| 60 |
|
|
// finished.
|
| 61 |
|
|
//
|
| 62 |
260 |
mohor |
// Revision 1.21 2002/11/19 20:27:45 mohor
|
| 63 |
|
|
// Temp version.
|
| 64 |
|
|
//
|
| 65 |
254 |
mohor |
// Revision 1.20 2002/11/19 17:41:19 tadejm
|
| 66 |
|
|
// Just some updates.
|
| 67 |
|
|
//
|
| 68 |
252 |
tadejm |
// Revision 1.19 2002/11/14 13:12:47 tadejm
|
| 69 |
|
|
// Late collision is not reported any more.
|
| 70 |
|
|
//
|
| 71 |
243 |
tadejm |
// Revision 1.18 2002/10/18 17:03:34 tadejm
|
| 72 |
|
|
// Changed BIST scan signals.
|
| 73 |
|
|
//
|
| 74 |
227 |
tadejm |
// Revision 1.17 2002/10/18 13:58:22 tadejm
|
| 75 |
|
|
// Some code changed due to bug fixes.
|
| 76 |
|
|
//
|
| 77 |
223 |
tadejm |
// Revision 1.16 2002/10/09 13:16:51 tadejm
|
| 78 |
|
|
// Just back-up; not completed testbench and some testcases are not
|
| 79 |
|
|
// wotking properly yet.
|
| 80 |
|
|
//
|
| 81 |
209 |
tadejm |
// Revision 1.15 2002/09/20 14:29:12 tadej
|
| 82 |
|
|
// Full duplex tests modified and testbench bug repaired.
|
| 83 |
|
|
//
|
| 84 |
194 |
tadej |
// Revision 1.14 2002/09/18 17:56:38 tadej
|
| 85 |
|
|
// Some additional reports added
|
| 86 |
|
|
//
|
| 87 |
192 |
tadej |
// Revision 1.13 2002/09/16 17:53:49 tadej
|
| 88 |
|
|
// Full duplex test improved.
|
| 89 |
|
|
//
|
| 90 |
182 |
tadej |
// Revision 1.12 2002/09/16 15:10:42 mohor
|
| 91 |
|
|
// MIIM test look better.
|
| 92 |
|
|
//
|
| 93 |
181 |
mohor |
// Revision 1.11 2002/09/13 19:18:04 mohor
|
| 94 |
|
|
// Bench outputs data to display every 128 bytes.
|
| 95 |
|
|
//
|
| 96 |
180 |
mohor |
// Revision 1.10 2002/09/13 18:44:29 mohor
|
| 97 |
|
|
// Beautiful tests merget together
|
| 98 |
|
|
//
|
| 99 |
179 |
mohor |
// Revision 1.9 2002/09/13 18:41:45 mohor
|
| 100 |
|
|
// Rearanged testcases
|
| 101 |
|
|
//
|
| 102 |
178 |
mohor |
// Revision 1.8 2002/09/13 14:50:15 mohor
|
| 103 |
|
|
// Bug in MIIM fixed.
|
| 104 |
|
|
//
|
| 105 |
177 |
mohor |
// Revision 1.7 2002/09/13 12:29:14 mohor
|
| 106 |
|
|
// Headers changed.
|
| 107 |
|
|
//
|
| 108 |
170 |
mohor |
// Revision 1.6 2002/09/13 11:57:20 mohor
|
| 109 |
|
|
// New testbench. Thanks to Tadej M - "The Spammer".
|
| 110 |
|
|
//
|
| 111 |
121 |
mohor |
// Revision 1.2 2002/07/19 14:02:47 mohor
|
| 112 |
|
|
// Clock mrx_clk set to 2.5 MHz.
|
| 113 |
|
|
//
|
| 114 |
117 |
mohor |
// Revision 1.1 2002/07/19 13:57:53 mohor
|
| 115 |
|
|
// Testing environment also includes traffic cop, memory interface and host
|
| 116 |
|
|
// interface.
|
| 117 |
116 |
mohor |
//
|
| 118 |
|
|
//
|
| 119 |
|
|
//
|
| 120 |
|
|
//
|
| 121 |
117 |
mohor |
//
|
| 122 |
116 |
mohor |
|
| 123 |
|
|
|
| 124 |
169 |
mohor |
`include "eth_phy_defines.v"
|
| 125 |
|
|
`include "wb_model_defines.v"
|
| 126 |
116 |
mohor |
`include "tb_eth_defines.v"
|
| 127 |
|
|
`include "eth_defines.v"
|
| 128 |
|
|
`include "timescale.v"
|
| 129 |
|
|
|
| 130 |
|
|
module tb_ethernet();
|
| 131 |
|
|
|
| 132 |
|
|
|
| 133 |
169 |
mohor |
reg wb_clk;
|
| 134 |
|
|
reg wb_rst;
|
| 135 |
|
|
wire wb_int;
|
| 136 |
116 |
mohor |
|
| 137 |
169 |
mohor |
wire mtx_clk; // This goes to PHY
|
| 138 |
|
|
wire mrx_clk; // This goes to PHY
|
| 139 |
116 |
mohor |
|
| 140 |
|
|
wire [3:0] MTxD;
|
| 141 |
|
|
wire MTxEn;
|
| 142 |
|
|
wire MTxErr;
|
| 143 |
|
|
|
| 144 |
169 |
mohor |
wire [3:0] MRxD; // This goes to PHY
|
| 145 |
|
|
wire MRxDV; // This goes to PHY
|
| 146 |
|
|
wire MRxErr; // This goes to PHY
|
| 147 |
|
|
wire MColl; // This goes to PHY
|
| 148 |
|
|
wire MCrs; // This goes to PHY
|
| 149 |
116 |
mohor |
|
| 150 |
|
|
wire Mdi_I;
|
| 151 |
|
|
wire Mdo_O;
|
| 152 |
|
|
wire Mdo_OE;
|
| 153 |
169 |
mohor |
tri Mdio_IO;
|
| 154 |
116 |
mohor |
wire Mdc_O;
|
| 155 |
|
|
|
| 156 |
|
|
|
| 157 |
169 |
mohor |
parameter Tp = 1;
|
| 158 |
116 |
mohor |
|
| 159 |
121 |
mohor |
|
| 160 |
116 |
mohor |
// Ethernet Slave Interface signals
|
| 161 |
169 |
mohor |
wire [31:0] eth_sl_wb_adr;
|
| 162 |
116 |
mohor |
wire [31:0] eth_sl_wb_adr_i, eth_sl_wb_dat_o, eth_sl_wb_dat_i;
|
| 163 |
|
|
wire [3:0] eth_sl_wb_sel_i;
|
| 164 |
|
|
wire eth_sl_wb_we_i, eth_sl_wb_cyc_i, eth_sl_wb_stb_i, eth_sl_wb_ack_o, eth_sl_wb_err_o;
|
| 165 |
|
|
|
| 166 |
|
|
// Ethernet Master Interface signals
|
| 167 |
|
|
wire [31:0] eth_ma_wb_adr_o, eth_ma_wb_dat_i, eth_ma_wb_dat_o;
|
| 168 |
|
|
wire [3:0] eth_ma_wb_sel_o;
|
| 169 |
|
|
wire eth_ma_wb_we_o, eth_ma_wb_cyc_o, eth_ma_wb_stb_o, eth_ma_wb_ack_i, eth_ma_wb_err_i;
|
| 170 |
|
|
|
| 171 |
|
|
|
| 172 |
|
|
|
| 173 |
|
|
|
| 174 |
|
|
// Connecting Ethernet top module
|
| 175 |
169 |
mohor |
eth_top eth_top
|
| 176 |
116 |
mohor |
(
|
| 177 |
|
|
// WISHBONE common
|
| 178 |
169 |
mohor |
.wb_clk_i(wb_clk), .wb_rst_i(wb_rst),
|
| 179 |
116 |
mohor |
|
| 180 |
|
|
// WISHBONE slave
|
| 181 |
169 |
mohor |
.wb_adr_i(eth_sl_wb_adr_i[11:2]), .wb_sel_i(eth_sl_wb_sel_i), .wb_we_i(eth_sl_wb_we_i),
|
| 182 |
|
|
.wb_cyc_i(eth_sl_wb_cyc_i), .wb_stb_i(eth_sl_wb_stb_i), .wb_ack_o(eth_sl_wb_ack_o),
|
| 183 |
|
|
.wb_err_o(eth_sl_wb_err_o), .wb_dat_i(eth_sl_wb_dat_i), .wb_dat_o(eth_sl_wb_dat_o),
|
| 184 |
116 |
mohor |
|
| 185 |
|
|
// WISHBONE master
|
| 186 |
|
|
.m_wb_adr_o(eth_ma_wb_adr_o), .m_wb_sel_o(eth_ma_wb_sel_o), .m_wb_we_o(eth_ma_wb_we_o),
|
| 187 |
|
|
.m_wb_dat_i(eth_ma_wb_dat_i), .m_wb_dat_o(eth_ma_wb_dat_o), .m_wb_cyc_o(eth_ma_wb_cyc_o),
|
| 188 |
|
|
.m_wb_stb_o(eth_ma_wb_stb_o), .m_wb_ack_i(eth_ma_wb_ack_i), .m_wb_err_i(eth_ma_wb_err_i),
|
| 189 |
|
|
|
| 190 |
|
|
//TX
|
| 191 |
|
|
.mtx_clk_pad_i(mtx_clk), .mtxd_pad_o(MTxD), .mtxen_pad_o(MTxEn), .mtxerr_pad_o(MTxErr),
|
| 192 |
|
|
|
| 193 |
|
|
//RX
|
| 194 |
|
|
.mrx_clk_pad_i(mrx_clk), .mrxd_pad_i(MRxD), .mrxdv_pad_i(MRxDV), .mrxerr_pad_i(MRxErr),
|
| 195 |
|
|
.mcoll_pad_i(MColl), .mcrs_pad_i(MCrs),
|
| 196 |
|
|
|
| 197 |
|
|
// MIIM
|
| 198 |
|
|
.mdc_pad_o(Mdc_O), .md_pad_i(Mdi_I), .md_pad_o(Mdo_O), .md_padoe_o(Mdo_OE),
|
| 199 |
|
|
|
| 200 |
169 |
mohor |
.int_o(wb_int)
|
| 201 |
227 |
tadejm |
|
| 202 |
|
|
// Bist
|
| 203 |
|
|
`ifdef ETH_BIST
|
| 204 |
|
|
,
|
| 205 |
|
|
.scanb_rst (1'b0),
|
| 206 |
|
|
.scanb_clk (1'b0),
|
| 207 |
|
|
.scanb_si (1'b0),
|
| 208 |
|
|
.scanb_so (),
|
| 209 |
|
|
.scanb_en (1'b0)
|
| 210 |
|
|
`endif
|
| 211 |
116 |
mohor |
);
|
| 212 |
|
|
|
| 213 |
|
|
|
| 214 |
|
|
|
| 215 |
169 |
mohor |
// Connecting Ethernet PHY Module
|
| 216 |
|
|
assign Mdio_IO = Mdo_OE ? Mdo_O : 1'bz ;
|
| 217 |
|
|
assign Mdi_I = Mdio_IO;
|
| 218 |
|
|
integer phy_log_file_desc;
|
| 219 |
|
|
|
| 220 |
|
|
eth_phy eth_phy
|
| 221 |
116 |
mohor |
(
|
| 222 |
169 |
mohor |
// WISHBONE reset
|
| 223 |
|
|
.m_rst_n_i(!wb_rst),
|
| 224 |
116 |
mohor |
|
| 225 |
169 |
mohor |
// MAC TX
|
| 226 |
|
|
.mtx_clk_o(mtx_clk), .mtxd_i(MTxD), .mtxen_i(MTxEn), .mtxerr_i(MTxErr),
|
| 227 |
|
|
|
| 228 |
|
|
// MAC RX
|
| 229 |
|
|
.mrx_clk_o(mrx_clk), .mrxd_o(MRxD), .mrxdv_o(MRxDV), .mrxerr_o(MRxErr),
|
| 230 |
|
|
.mcoll_o(MColl), .mcrs_o(MCrs),
|
| 231 |
|
|
|
| 232 |
|
|
// MIIM
|
| 233 |
|
|
.mdc_i(Mdc_O), .md_io(Mdio_IO),
|
| 234 |
|
|
|
| 235 |
|
|
// SYSTEM
|
| 236 |
|
|
.phy_log(phy_log_file_desc)
|
| 237 |
116 |
mohor |
);
|
| 238 |
|
|
|
| 239 |
|
|
|
| 240 |
169 |
mohor |
|
| 241 |
|
|
// Connecting WB Master as Host Interface
|
| 242 |
|
|
integer host_log_file_desc;
|
| 243 |
|
|
|
| 244 |
|
|
WB_MASTER_BEHAVIORAL wb_master
|
| 245 |
116 |
mohor |
(
|
| 246 |
169 |
mohor |
.CLK_I(wb_clk),
|
| 247 |
|
|
.RST_I(wb_rst),
|
| 248 |
|
|
.TAG_I({`WB_TAG_WIDTH{1'b0}}),
|
| 249 |
|
|
.TAG_O(),
|
| 250 |
|
|
.ACK_I(eth_sl_wb_ack_o),
|
| 251 |
|
|
.ADR_O(eth_sl_wb_adr), // only eth_sl_wb_adr_i[11:2] used
|
| 252 |
|
|
.CYC_O(eth_sl_wb_cyc_i),
|
| 253 |
|
|
.DAT_I(eth_sl_wb_dat_o),
|
| 254 |
|
|
.DAT_O(eth_sl_wb_dat_i),
|
| 255 |
|
|
.ERR_I(eth_sl_wb_err_o),
|
| 256 |
|
|
.RTY_I(1'b0), // inactive (1'b0)
|
| 257 |
|
|
.SEL_O(eth_sl_wb_sel_i),
|
| 258 |
|
|
.STB_O(eth_sl_wb_stb_i),
|
| 259 |
|
|
.WE_O (eth_sl_wb_we_i),
|
| 260 |
|
|
.CAB_O() // NOT USED for now!
|
| 261 |
|
|
);
|
| 262 |
|
|
|
| 263 |
|
|
assign eth_sl_wb_adr_i = {20'h0, eth_sl_wb_adr[11:2], 2'h0};
|
| 264 |
|
|
|
| 265 |
|
|
|
| 266 |
|
|
|
| 267 |
|
|
// Connecting WB Slave as Memory Interface Module
|
| 268 |
|
|
integer memory_log_file_desc;
|
| 269 |
|
|
|
| 270 |
|
|
WB_SLAVE_BEHAVIORAL wb_slave
|
| 271 |
|
|
(
|
| 272 |
|
|
.CLK_I(wb_clk),
|
| 273 |
|
|
.RST_I(wb_rst),
|
| 274 |
|
|
.ACK_O(eth_ma_wb_ack_i),
|
| 275 |
|
|
.ADR_I(eth_ma_wb_adr_o),
|
| 276 |
|
|
.CYC_I(eth_ma_wb_cyc_o),
|
| 277 |
|
|
.DAT_O(eth_ma_wb_dat_i),
|
| 278 |
|
|
.DAT_I(eth_ma_wb_dat_o),
|
| 279 |
|
|
.ERR_O(eth_ma_wb_err_i),
|
| 280 |
|
|
.RTY_O(), // NOT USED for now!
|
| 281 |
|
|
.SEL_I(eth_ma_wb_sel_o),
|
| 282 |
|
|
.STB_I(eth_ma_wb_stb_o),
|
| 283 |
|
|
.WE_I (eth_ma_wb_we_o),
|
| 284 |
|
|
.CAB_I(1'b0) // inactive (1'b0)
|
| 285 |
|
|
);
|
| 286 |
|
|
|
| 287 |
|
|
|
| 288 |
|
|
|
| 289 |
|
|
// Connecting WISHBONE Bus Monitors to ethernet master and slave interfaces
|
| 290 |
|
|
integer wb_s_mon_log_file_desc ;
|
| 291 |
|
|
integer wb_m_mon_log_file_desc ;
|
| 292 |
|
|
|
| 293 |
|
|
WB_BUS_MON wb_eth_slave_bus_mon
|
| 294 |
|
|
(
|
| 295 |
116 |
mohor |
// WISHBONE common
|
| 296 |
169 |
mohor |
.CLK_I(wb_clk),
|
| 297 |
|
|
.RST_I(wb_rst),
|
| 298 |
116 |
mohor |
|
| 299 |
169 |
mohor |
// WISHBONE slave
|
| 300 |
|
|
.ACK_I(eth_sl_wb_ack_o),
|
| 301 |
|
|
.ADDR_O({20'h0, eth_sl_wb_adr_i[11:2], 2'b0}),
|
| 302 |
|
|
.CYC_O(eth_sl_wb_cyc_i),
|
| 303 |
|
|
.DAT_I(eth_sl_wb_dat_o),
|
| 304 |
|
|
.DAT_O(eth_sl_wb_dat_i),
|
| 305 |
|
|
.ERR_I(eth_sl_wb_err_o),
|
| 306 |
|
|
.RTY_I(1'b0),
|
| 307 |
|
|
.SEL_O(eth_sl_wb_sel_i),
|
| 308 |
|
|
.STB_O(eth_sl_wb_stb_i),
|
| 309 |
|
|
.WE_O (eth_sl_wb_we_i),
|
| 310 |
|
|
.TAG_I({`WB_TAG_WIDTH{1'b0}}),
|
| 311 |
|
|
.TAG_O(),
|
| 312 |
|
|
.CAB_O(1'b0),
|
| 313 |
|
|
.log_file_desc (wb_s_mon_log_file_desc)
|
| 314 |
|
|
);
|
| 315 |
|
|
|
| 316 |
|
|
WB_BUS_MON wb_eth_master_bus_mon
|
| 317 |
|
|
(
|
| 318 |
|
|
// WISHBONE common
|
| 319 |
|
|
.CLK_I(wb_clk),
|
| 320 |
|
|
.RST_I(wb_rst),
|
| 321 |
|
|
|
| 322 |
116 |
mohor |
// WISHBONE master
|
| 323 |
169 |
mohor |
.ACK_I(eth_ma_wb_ack_i),
|
| 324 |
|
|
.ADDR_O(eth_ma_wb_adr_o),
|
| 325 |
|
|
.CYC_O(eth_ma_wb_cyc_o),
|
| 326 |
|
|
.DAT_I(eth_ma_wb_dat_i),
|
| 327 |
|
|
.DAT_O(eth_ma_wb_dat_o),
|
| 328 |
|
|
.ERR_I(eth_ma_wb_err_i),
|
| 329 |
|
|
.RTY_I(1'b0),
|
| 330 |
|
|
.SEL_O(eth_ma_wb_sel_o),
|
| 331 |
|
|
.STB_O(eth_ma_wb_stb_o),
|
| 332 |
|
|
.WE_O (eth_ma_wb_we_o),
|
| 333 |
|
|
.TAG_I({`WB_TAG_WIDTH{1'b0}}),
|
| 334 |
|
|
.TAG_O(),
|
| 335 |
|
|
.CAB_O(1'b0),
|
| 336 |
|
|
.log_file_desc(wb_m_mon_log_file_desc)
|
| 337 |
116 |
mohor |
);
|
| 338 |
|
|
|
| 339 |
|
|
|
| 340 |
|
|
|
| 341 |
169 |
mohor |
reg StartTB;
|
| 342 |
|
|
integer tb_log_file;
|
| 343 |
116 |
mohor |
|
| 344 |
169 |
mohor |
initial
|
| 345 |
|
|
begin
|
| 346 |
|
|
tb_log_file = $fopen("../log/eth_tb.log");
|
| 347 |
|
|
if (tb_log_file < 2)
|
| 348 |
|
|
begin
|
| 349 |
|
|
$display("*E Could not open/create testbench log file in ../log/ directory!");
|
| 350 |
|
|
$finish;
|
| 351 |
|
|
end
|
| 352 |
|
|
$fdisplay(tb_log_file, "========================== ETHERNET IP Core Testbench results ===========================");
|
| 353 |
|
|
$fdisplay(tb_log_file, " ");
|
| 354 |
116 |
mohor |
|
| 355 |
169 |
mohor |
phy_log_file_desc = $fopen("../log/eth_tb_phy.log");
|
| 356 |
|
|
if (phy_log_file_desc < 2)
|
| 357 |
|
|
begin
|
| 358 |
|
|
$fdisplay(tb_log_file, "*E Could not open/create eth_tb_phy.log file in ../log/ directory!");
|
| 359 |
|
|
$finish;
|
| 360 |
|
|
end
|
| 361 |
|
|
$fdisplay(phy_log_file_desc, "================ PHY Module Testbench access log ================");
|
| 362 |
|
|
$fdisplay(phy_log_file_desc, " ");
|
| 363 |
|
|
|
| 364 |
|
|
memory_log_file_desc = $fopen("../log/eth_tb_memory.log");
|
| 365 |
|
|
if (memory_log_file_desc < 2)
|
| 366 |
|
|
begin
|
| 367 |
|
|
$fdisplay(tb_log_file, "*E Could not open/create eth_tb_memory.log file in ../log/ directory!");
|
| 368 |
|
|
$finish;
|
| 369 |
|
|
end
|
| 370 |
|
|
$fdisplay(memory_log_file_desc, "=============== MEMORY Module Testbench access log ===============");
|
| 371 |
|
|
$fdisplay(memory_log_file_desc, " ");
|
| 372 |
|
|
|
| 373 |
|
|
host_log_file_desc = $fopen("../log/eth_tb_host.log");
|
| 374 |
|
|
if (host_log_file_desc < 2)
|
| 375 |
|
|
begin
|
| 376 |
|
|
$fdisplay(tb_log_file, "*E Could not open/create eth_tb_host.log file in ../log/ directory!");
|
| 377 |
|
|
$finish;
|
| 378 |
|
|
end
|
| 379 |
|
|
$fdisplay(host_log_file_desc, "================ HOST Module Testbench access log ================");
|
| 380 |
|
|
$fdisplay(host_log_file_desc, " ");
|
| 381 |
|
|
|
| 382 |
|
|
wb_s_mon_log_file_desc = $fopen("../log/eth_tb_wb_s_mon.log");
|
| 383 |
|
|
if (wb_s_mon_log_file_desc < 2)
|
| 384 |
|
|
begin
|
| 385 |
|
|
$fdisplay(tb_log_file, "*E Could not open/create eth_tb_wb_s_mon.log file in ../log/ directory!");
|
| 386 |
|
|
$finish;
|
| 387 |
|
|
end
|
| 388 |
|
|
$fdisplay(wb_s_mon_log_file_desc, "============== WISHBONE Slave Bus Monitor error log ==============");
|
| 389 |
|
|
$fdisplay(wb_s_mon_log_file_desc, " ");
|
| 390 |
|
|
$fdisplay(wb_s_mon_log_file_desc, " Only ERRONEOUS conditions are logged !");
|
| 391 |
|
|
$fdisplay(wb_s_mon_log_file_desc, " ");
|
| 392 |
|
|
|
| 393 |
|
|
wb_m_mon_log_file_desc = $fopen("../log/eth_tb_wb_m_mon.log");
|
| 394 |
|
|
if (wb_m_mon_log_file_desc < 2)
|
| 395 |
|
|
begin
|
| 396 |
|
|
$fdisplay(tb_log_file, "*E Could not open/create eth_tb_wb_m_mon.log file in ../log/ directory!");
|
| 397 |
|
|
$finish;
|
| 398 |
|
|
end
|
| 399 |
|
|
$fdisplay(wb_m_mon_log_file_desc, "============= WISHBONE Master Bus Monitor error log =============");
|
| 400 |
|
|
$fdisplay(wb_m_mon_log_file_desc, " ");
|
| 401 |
|
|
$fdisplay(wb_m_mon_log_file_desc, " Only ERRONEOUS conditions are logged !");
|
| 402 |
|
|
$fdisplay(wb_m_mon_log_file_desc, " ");
|
| 403 |
|
|
|
| 404 |
243 |
tadejm |
// Reset pulse
|
| 405 |
|
|
wb_rst = 1'b1;
|
| 406 |
|
|
#423 wb_rst = 1'b0;
|
| 407 |
|
|
|
| 408 |
169 |
mohor |
// Clear memories
|
| 409 |
|
|
clear_memories;
|
| 410 |
243 |
tadejm |
clear_buffer_descriptors;
|
| 411 |
169 |
mohor |
|
| 412 |
|
|
#423 StartTB = 1'b1;
|
| 413 |
|
|
end
|
| 414 |
|
|
|
| 415 |
|
|
|
| 416 |
|
|
|
| 417 |
|
|
// Generating wb_clk clock
|
| 418 |
116 |
mohor |
initial
|
| 419 |
|
|
begin
|
| 420 |
169 |
mohor |
wb_clk=0;
|
| 421 |
|
|
// forever #2.5 wb_clk = ~wb_clk; // 2*2.5 ns -> 200.0 MHz
|
| 422 |
274 |
tadejm |
// forever #5 wb_clk = ~wb_clk; // 2*5 ns -> 100.0 MHz
|
| 423 |
169 |
mohor |
// forever #10 wb_clk = ~wb_clk; // 2*10 ns -> 50.0 MHz
|
| 424 |
|
|
// forever #12.5 wb_clk = ~wb_clk; // 2*12.5 ns -> 40 MHz
|
| 425 |
274 |
tadejm |
forever #15 wb_clk = ~wb_clk; // 2*10 ns -> 33.3 MHz
|
| 426 |
209 |
tadejm |
// forever #20 wb_clk = ~wb_clk; // 2*20 ns -> 25 MHz
|
| 427 |
169 |
mohor |
// forever #25 wb_clk = ~wb_clk; // 2*25 ns -> 20.0 MHz
|
| 428 |
|
|
// forever #31.25 wb_clk = ~wb_clk; // 2*31.25 ns -> 16.0 MHz
|
| 429 |
|
|
// forever #50 wb_clk = ~wb_clk; // 2*50 ns -> 10.0 MHz
|
| 430 |
|
|
// forever #55 wb_clk = ~wb_clk; // 2*55 ns -> 9.1 MHz
|
| 431 |
116 |
mohor |
end
|
| 432 |
|
|
|
| 433 |
|
|
|
| 434 |
|
|
|
| 435 |
169 |
mohor |
integer tests_successfull;
|
| 436 |
|
|
integer tests_failed;
|
| 437 |
|
|
reg [799:0] test_name; // used for tb_log_file
|
| 438 |
121 |
mohor |
|
| 439 |
169 |
mohor |
reg [3:0] wbm_init_waits; // initial wait cycles between CYC_O and STB_O of WB Master
|
| 440 |
|
|
reg [3:0] wbm_subseq_waits; // subsequent wait cycles between STB_Os of WB Master
|
| 441 |
|
|
reg [2:0] wbs_waits; // wait cycles befor WB Slave responds
|
| 442 |
|
|
reg [7:0] wbs_retries; // if RTY response, then this is the number of retries before ACK
|
| 443 |
|
|
|
| 444 |
274 |
tadejm |
reg wbm_working; // tasks wbm_write and wbm_read set signal when working and reset it when stop working
|
| 445 |
|
|
|
| 446 |
|
|
|
| 447 |
116 |
mohor |
initial
|
| 448 |
|
|
begin
|
| 449 |
169 |
mohor |
wait(StartTB); // Start of testbench
|
| 450 |
|
|
|
| 451 |
|
|
// Initial global values
|
| 452 |
|
|
tests_successfull = 0;
|
| 453 |
|
|
tests_failed = 0;
|
| 454 |
274 |
tadejm |
|
| 455 |
|
|
wbm_working = 0;
|
| 456 |
169 |
mohor |
|
| 457 |
|
|
wbm_init_waits = 4'h1;
|
| 458 |
|
|
wbm_subseq_waits = 4'h3;
|
| 459 |
|
|
wbs_waits = 4'h1;
|
| 460 |
|
|
wbs_retries = 8'h2;
|
| 461 |
|
|
wb_slave.cycle_response(`ACK_RESPONSE, wbs_waits, wbs_retries);
|
| 462 |
|
|
|
| 463 |
274 |
tadejm |
// set DIFFERENT mrx_clk to mtx_clk!
|
| 464 |
|
|
// eth_phy.set_mrx_equal_mtx = 1'b0;
|
| 465 |
169 |
mohor |
|
| 466 |
|
|
// Call tests
|
| 467 |
|
|
// ----------
|
| 468 |
274 |
tadejm |
// test_access_to_mac_reg(0, 0); // 0 - 3
|
| 469 |
194 |
tadej |
// test_mii(0, 17); // 0 - 17
|
| 470 |
169 |
mohor |
test_note("PHY generates ideal Carrier sense and Collision signals for following tests");
|
| 471 |
|
|
eth_phy.carrier_sense_real_delay(0);
|
| 472 |
274 |
tadejm |
// test_mac_full_duplex_transmit(0, 23); // 0 - (21)
|
| 473 |
|
|
test_mac_full_duplex_transmit(8, 8); // 0 - (21)
|
| 474 |
|
|
// test_mac_full_duplex_receive(0, 13); // 0 - 13
|
| 475 |
|
|
// test_mac_full_duplex_flow_control(0, 4); // 0 - 5 What 5 stands for ?
|
| 476 |
|
|
// 4 is executed, everything is OK
|
| 477 |
|
|
// test_mac_half_duplex_flow(0, 0);
|
| 478 |
169 |
mohor |
|
| 479 |
243 |
tadejm |
test_note("PHY generates 'real delayed' Carrier sense and Collision signals for following tests");
|
| 480 |
169 |
mohor |
eth_phy.carrier_sense_real_delay(1);
|
| 481 |
|
|
|
| 482 |
|
|
|
| 483 |
|
|
// Finish test's logs
|
| 484 |
|
|
test_summary;
|
| 485 |
|
|
$display("\n\n END of SIMULATION");
|
| 486 |
|
|
$fclose(tb_log_file | phy_log_file_desc | memory_log_file_desc | host_log_file_desc);
|
| 487 |
|
|
$fclose(wb_s_mon_log_file_desc | wb_m_mon_log_file_desc);
|
| 488 |
|
|
|
| 489 |
|
|
$stop;
|
| 490 |
116 |
mohor |
end
|
| 491 |
169 |
mohor |
|
| 492 |
116 |
mohor |
|
| 493 |
169 |
mohor |
|
| 494 |
|
|
//////////////////////////////////////////////////////////////
|
| 495 |
|
|
// Test tasks
|
| 496 |
|
|
//////////////////////////////////////////////////////////////
|
| 497 |
|
|
|
| 498 |
|
|
task test_access_to_mac_reg;
|
| 499 |
|
|
input [31:0] start_task;
|
| 500 |
|
|
input [31:0] end_task;
|
| 501 |
|
|
integer bit_start_1;
|
| 502 |
|
|
integer bit_end_1;
|
| 503 |
|
|
integer bit_start_2;
|
| 504 |
|
|
integer bit_end_2;
|
| 505 |
|
|
integer num_of_reg;
|
| 506 |
|
|
integer i_addr;
|
| 507 |
|
|
integer i_data;
|
| 508 |
|
|
integer i_length;
|
| 509 |
|
|
integer tmp_data;
|
| 510 |
|
|
reg [31:0] tx_bd_num;
|
| 511 |
|
|
reg [((`MAX_BLK_SIZE * 32) - 1):0] burst_data;
|
| 512 |
|
|
reg [((`MAX_BLK_SIZE * 32) - 1):0] burst_tmp_data;
|
| 513 |
|
|
integer i;
|
| 514 |
|
|
integer i1;
|
| 515 |
|
|
integer i2;
|
| 516 |
|
|
integer i3;
|
| 517 |
|
|
integer fail;
|
| 518 |
178 |
mohor |
integer test_num;
|
| 519 |
169 |
mohor |
reg [31:0] addr;
|
| 520 |
|
|
reg [31:0] data;
|
| 521 |
|
|
reg [31:0] data_max;
|
| 522 |
116 |
mohor |
begin
|
| 523 |
169 |
mohor |
// ACCESS TO MAC REGISTERS TEST
|
| 524 |
|
|
test_heading("ACCESS TO MAC REGISTERS TEST");
|
| 525 |
|
|
$display(" ");
|
| 526 |
|
|
$display("ACCESS TO MAC REGISTERS TEST");
|
| 527 |
|
|
fail = 0;
|
| 528 |
|
|
|
| 529 |
192 |
tadej |
// reset MAC registers
|
| 530 |
|
|
hard_reset;
|
| 531 |
|
|
// reset MAC and MII LOGIC with soft reset
|
| 532 |
274 |
tadejm |
//reset_mac;
|
| 533 |
|
|
//reset_mii;
|
| 534 |
169 |
mohor |
|
| 535 |
192 |
tadej |
|
| 536 |
178 |
mohor |
//////////////////////////////////////////////////////////////////////
|
| 537 |
|
|
//// ////
|
| 538 |
|
|
//// test_access_to_mac_reg: ////
|
| 539 |
|
|
//// ////
|
| 540 |
|
|
//// 0: Walking 1 with single cycles across MAC regs. ////
|
| 541 |
|
|
//// 1: Walking 1 with single cycles across MAC buffer descript. ////
|
| 542 |
|
|
//// 2: Test max reg. values and reg. values after writing ////
|
| 543 |
|
|
//// inverse reset values and hard reset of the MAC ////
|
| 544 |
|
|
//// 3: Test buffer desc. RAM preserving values after hard reset ////
|
| 545 |
|
|
//// of the MAC and resetting the logic ////
|
| 546 |
|
|
//// ////
|
| 547 |
|
|
//////////////////////////////////////////////////////////////////////
|
| 548 |
194 |
tadej |
for (test_num = start_task; test_num <= end_task; test_num = test_num + 1)
|
| 549 |
169 |
mohor |
begin
|
| 550 |
|
|
|
| 551 |
178 |
mohor |
////////////////////////////////////////////////////////////////////
|
| 552 |
|
|
//// ////
|
| 553 |
|
|
//// Walking 1 with single cycles across MAC regs. ////
|
| 554 |
|
|
//// ////
|
| 555 |
|
|
////////////////////////////////////////////////////////////////////
|
| 556 |
|
|
if (test_num == 0) // Walking 1 with single cycles across MAC regs.
|
| 557 |
194 |
tadej |
begin
|
| 558 |
|
|
// TEST 0: 'WALKING ONE' WITH SINGLE CYCLES ACROSS MAC REGISTERS ( VARIOUS BUS DELAYS )
|
| 559 |
|
|
test_name = "TEST 0: 'WALKING ONE' WITH SINGLE CYCLES ACROSS MAC REGISTERS ( VARIOUS BUS DELAYS )";
|
| 560 |
|
|
`TIME; $display(" TEST 0: 'WALKING ONE' WITH SINGLE CYCLES ACROSS MAC REGISTERS ( VARIOUS BUS DELAYS )");
|
| 561 |
178 |
mohor |
|
| 562 |
194 |
tadej |
data = 0;
|
| 563 |
|
|
for (i = 0; i <= 4; i = i + 1) // for initial wait cycles on WB bus
|
| 564 |
|
|
begin
|
| 565 |
|
|
wbm_init_waits = i;
|
| 566 |
|
|
wbm_subseq_waits = {$random} % 5; // it is not important for single accesses
|
| 567 |
|
|
for (i_addr = 0; i_addr <= 32'h4C; i_addr = i_addr + 4) // register address
|
| 568 |
|
|
begin
|
| 569 |
|
|
addr = `ETH_BASE + i_addr;
|
| 570 |
|
|
// set ranges of R/W bits
|
| 571 |
|
|
case (addr)
|
| 572 |
|
|
`ETH_MODER:
|
| 573 |
|
|
begin
|
| 574 |
|
|
bit_start_1 = 0;
|
| 575 |
|
|
bit_end_1 = 16;
|
| 576 |
|
|
bit_start_2 = 32; // not used
|
| 577 |
|
|
bit_end_2 = 32; // not used
|
| 578 |
|
|
end
|
| 579 |
|
|
`ETH_INT: // READONLY - tested within INT test
|
| 580 |
|
|
begin
|
| 581 |
|
|
bit_start_1 = 32; // not used
|
| 582 |
|
|
bit_end_1 = 32; // not used
|
| 583 |
|
|
bit_start_2 = 32; // not used
|
| 584 |
|
|
bit_end_2 = 32; // not used
|
| 585 |
|
|
end
|
| 586 |
|
|
`ETH_INT_MASK:
|
| 587 |
|
|
begin
|
| 588 |
|
|
bit_start_1 = 0;
|
| 589 |
|
|
bit_end_1 = 6;
|
| 590 |
|
|
bit_start_2 = 32; // not used
|
| 591 |
|
|
bit_end_2 = 32; // not used
|
| 592 |
|
|
end
|
| 593 |
|
|
`ETH_IPGT:
|
| 594 |
|
|
begin
|
| 595 |
|
|
bit_start_1 = 0;
|
| 596 |
|
|
bit_end_1 = 6;
|
| 597 |
|
|
bit_start_2 = 32; // not used
|
| 598 |
|
|
bit_end_2 = 32; // not used
|
| 599 |
|
|
end
|
| 600 |
|
|
`ETH_IPGR1:
|
| 601 |
|
|
begin
|
| 602 |
|
|
bit_start_1 = 0;
|
| 603 |
|
|
bit_end_1 = 6;
|
| 604 |
|
|
bit_start_2 = 32; // not used
|
| 605 |
|
|
bit_end_2 = 32; // not used
|
| 606 |
|
|
end
|
| 607 |
|
|
`ETH_IPGR2:
|
| 608 |
|
|
begin
|
| 609 |
|
|
bit_start_1 = 0;
|
| 610 |
|
|
bit_end_1 = 6;
|
| 611 |
|
|
bit_start_2 = 32; // not used
|
| 612 |
|
|
bit_end_2 = 32; // not used
|
| 613 |
|
|
end
|
| 614 |
|
|
`ETH_PACKETLEN:
|
| 615 |
|
|
begin
|
| 616 |
|
|
bit_start_1 = 0;
|
| 617 |
|
|
bit_end_1 = 31;
|
| 618 |
|
|
bit_start_2 = 32; // not used
|
| 619 |
|
|
bit_end_2 = 32; // not used
|
| 620 |
|
|
end
|
| 621 |
|
|
`ETH_COLLCONF:
|
| 622 |
|
|
begin
|
| 623 |
|
|
bit_start_1 = 0;
|
| 624 |
|
|
bit_end_1 = 5;
|
| 625 |
|
|
bit_start_2 = 16;
|
| 626 |
|
|
bit_end_2 = 19;
|
| 627 |
|
|
end
|
| 628 |
|
|
`ETH_TX_BD_NUM:
|
| 629 |
|
|
begin
|
| 630 |
|
|
bit_start_1 = 0;
|
| 631 |
|
|
bit_end_1 = 7;
|
| 632 |
|
|
bit_start_2 = 32; // not used
|
| 633 |
|
|
bit_end_2 = 32; // not used
|
| 634 |
|
|
end
|
| 635 |
|
|
`ETH_CTRLMODER:
|
| 636 |
|
|
begin
|
| 637 |
|
|
bit_start_1 = 0;
|
| 638 |
|
|
bit_end_1 = 2;
|
| 639 |
|
|
bit_start_2 = 32; // not used
|
| 640 |
|
|
bit_end_2 = 32; // not used
|
| 641 |
|
|
end
|
| 642 |
|
|
`ETH_MIIMODER:
|
| 643 |
|
|
begin
|
| 644 |
|
|
bit_start_1 = 0;
|
| 645 |
|
|
bit_end_1 = 9;
|
| 646 |
|
|
bit_start_2 = 32; // not used
|
| 647 |
|
|
bit_end_2 = 32; // not used
|
| 648 |
|
|
end
|
| 649 |
|
|
`ETH_MIICOMMAND: // "WRITEONLY" - tested within MIIM test - 3 LSBits are not written here!!!
|
| 650 |
|
|
begin
|
| 651 |
|
|
bit_start_1 = 32; // not used
|
| 652 |
|
|
bit_end_1 = 32; // not used
|
| 653 |
|
|
bit_start_2 = 32; // not used
|
| 654 |
|
|
bit_end_2 = 32; // not used
|
| 655 |
|
|
end
|
| 656 |
|
|
`ETH_MIIADDRESS:
|
| 657 |
|
|
begin
|
| 658 |
|
|
bit_start_1 = 0;
|
| 659 |
|
|
bit_end_1 = 4;
|
| 660 |
|
|
bit_start_2 = 8;
|
| 661 |
|
|
bit_end_2 = 12;
|
| 662 |
|
|
end
|
| 663 |
|
|
`ETH_MIITX_DATA:
|
| 664 |
|
|
begin
|
| 665 |
|
|
bit_start_1 = 0;
|
| 666 |
|
|
bit_end_1 = 15;
|
| 667 |
|
|
bit_start_2 = 32; // not used
|
| 668 |
|
|
bit_end_2 = 32; // not used
|
| 669 |
|
|
end
|
| 670 |
|
|
`ETH_MIIRX_DATA: // READONLY - tested within MIIM test
|
| 671 |
|
|
begin
|
| 672 |
|
|
bit_start_1 = 32; // not used
|
| 673 |
|
|
bit_end_1 = 32; // not used
|
| 674 |
|
|
bit_start_2 = 32; // not used
|
| 675 |
|
|
bit_end_2 = 32; // not used
|
| 676 |
|
|
end
|
| 677 |
|
|
`ETH_MIISTATUS: // READONLY - tested within MIIM test
|
| 678 |
|
|
begin
|
| 679 |
|
|
bit_start_1 = 32; // not used
|
| 680 |
|
|
bit_end_1 = 32; // not used
|
| 681 |
|
|
bit_start_2 = 32; // not used
|
| 682 |
|
|
bit_end_2 = 32; // not used
|
| 683 |
|
|
end
|
| 684 |
|
|
`ETH_MAC_ADDR0:
|
| 685 |
|
|
begin
|
| 686 |
|
|
bit_start_1 = 0;
|
| 687 |
|
|
bit_end_1 = 31;
|
| 688 |
|
|
bit_start_2 = 32; // not used
|
| 689 |
|
|
bit_end_2 = 32; // not used
|
| 690 |
178 |
mohor |
end
|
| 691 |
194 |
tadej |
`ETH_MAC_ADDR1:
|
| 692 |
|
|
begin
|
| 693 |
|
|
bit_start_1 = 0;
|
| 694 |
|
|
bit_end_1 = 15;
|
| 695 |
|
|
bit_start_2 = 32; // not used
|
| 696 |
|
|
bit_end_2 = 32; // not used
|
| 697 |
|
|
end
|
| 698 |
|
|
`ETH_HASH_ADDR0:
|
| 699 |
|
|
begin
|
| 700 |
|
|
bit_start_1 = 0;
|
| 701 |
|
|
bit_end_1 = 31;
|
| 702 |
|
|
bit_start_2 = 32; // not used
|
| 703 |
|
|
bit_end_2 = 32; // not used
|
| 704 |
|
|
end
|
| 705 |
|
|
default: // `ETH_HASH_ADDR1:
|
| 706 |
|
|
begin
|
| 707 |
|
|
bit_start_1 = 0;
|
| 708 |
|
|
bit_end_1 = 31;
|
| 709 |
|
|
bit_start_2 = 32; // not used
|
| 710 |
|
|
bit_end_2 = 32; // not used
|
| 711 |
|
|
end
|
| 712 |
|
|
endcase
|
| 713 |
|
|
|
| 714 |
|
|
for (i_data = 0; i_data <= 31; i_data = i_data + 1) // the position of walking one
|
| 715 |
|
|
begin
|
| 716 |
|
|
data = 1'b1 << i_data;
|
| 717 |
|
|
if ( (addr == `ETH_MIICOMMAND) && (i_data <= 2) ) // DO NOT WRITE to 3 LSBits of MIICOMMAND !!!
|
| 718 |
|
|
;
|
| 719 |
|
|
else
|
| 720 |
178 |
mohor |
begin
|
| 721 |
194 |
tadej |
wbm_write(addr, data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 722 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 723 |
194 |
tadej |
wbm_read(addr, tmp_data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 724 |
|
|
if ( ((i_data >= bit_start_1) && (i_data <= bit_end_1)) ||
|
| 725 |
|
|
((i_data >= bit_start_2) && (i_data <= bit_end_2)) ) // data should be equal to tmp_data
|
| 726 |
|
|
begin
|
| 727 |
|
|
if (tmp_data !== data)
|
| 728 |
178 |
mohor |
begin
|
| 729 |
194 |
tadej |
fail = fail + 1;
|
| 730 |
|
|
test_fail("RW bit of the MAC register was not written or not read");
|
| 731 |
|
|
`TIME;
|
| 732 |
|
|
$display("wbm_init_waits %d, addr %h, data %h, tmp_data %h",
|
| 733 |
|
|
wbm_init_waits, addr, data, tmp_data);
|
| 734 |
|
|
end
|
| 735 |
|
|
end
|
| 736 |
|
|
else // data should not be equal to tmp_data
|
| 737 |
|
|
begin
|
| 738 |
|
|
if (tmp_data === data)
|
| 739 |
178 |
mohor |
begin
|
| 740 |
|
|
fail = fail + 1;
|
| 741 |
194 |
tadej |
test_fail("NON RW bit of the MAC register was written, but it shouldn't be");
|
| 742 |
178 |
mohor |
`TIME;
|
| 743 |
194 |
tadej |
$display("wbm_init_waits %d, addr %h, data %h, tmp_data %h",
|
| 744 |
178 |
mohor |
wbm_init_waits, addr, data, tmp_data);
|
| 745 |
|
|
end
|
| 746 |
194 |
tadej |
end
|
| 747 |
|
|
end
|
| 748 |
|
|
end
|
| 749 |
|
|
end
|
| 750 |
|
|
end
|
| 751 |
209 |
tadejm |
// INTERMEDIATE DISPLAYS (The only one)
|
| 752 |
|
|
$display(" ->buffer descriptors tested with 0, 1, 2, 3 and 4 bus delay cycles");
|
| 753 |
194 |
tadej |
if(fail == 0)
|
| 754 |
|
|
test_ok;
|
| 755 |
|
|
else
|
| 756 |
|
|
fail = 0; // Errors were reported previously
|
| 757 |
|
|
end
|
| 758 |
178 |
mohor |
|
| 759 |
|
|
|
| 760 |
|
|
////////////////////////////////////////////////////////////////////
|
| 761 |
|
|
//// ////
|
| 762 |
|
|
//// Walking 1 with single cycles across MAC buffer descript. ////
|
| 763 |
|
|
//// ////
|
| 764 |
|
|
////////////////////////////////////////////////////////////////////
|
| 765 |
|
|
if (test_num == 1) // Start Walking 1 with single cycles across MAC buffer descript.
|
| 766 |
169 |
mohor |
begin
|
| 767 |
194 |
tadej |
// TEST 1: 'WALKING ONE' WITH SINGLE CYCLES ACROSS MAC BUFFER DESC. ( VARIOUS BUS DELAYS )
|
| 768 |
|
|
test_name = "TEST 1: 'WALKING ONE' WITH SINGLE CYCLES ACROSS MAC BUFFER DESC. ( VARIOUS BUS DELAYS )";
|
| 769 |
|
|
`TIME; $display(" TEST 1: 'WALKING ONE' WITH SINGLE CYCLES ACROSS MAC BUFFER DESC. ( VARIOUS BUS DELAYS )");
|
| 770 |
178 |
mohor |
|
| 771 |
|
|
data = 0;
|
| 772 |
|
|
// set TX and RX buffer descriptors
|
| 773 |
|
|
tx_bd_num = 32'h40;
|
| 774 |
|
|
wbm_write(`ETH_TX_BD_NUM, tx_bd_num, 4'hF, 1, 0, 0);
|
| 775 |
|
|
for (i = 0; i <= 4; i = i + 1) // for initial wait cycles on WB bus
|
| 776 |
|
|
begin
|
| 777 |
169 |
mohor |
wbm_init_waits = i;
|
| 778 |
|
|
wbm_subseq_waits = {$random} % 5; // it is not important for single accesses
|
| 779 |
178 |
mohor |
for (i_addr = 32'h400; i_addr <= 32'h7FC; i_addr = i_addr + 4) // buffer descriptor address
|
| 780 |
169 |
mohor |
begin
|
| 781 |
|
|
addr = `ETH_BASE + i_addr;
|
| 782 |
178 |
mohor |
if (i_addr < (32'h400 + (tx_bd_num << 3))) // TX buffer descriptors
|
| 783 |
|
|
begin
|
| 784 |
|
|
// set ranges of R/W bits
|
| 785 |
|
|
case (addr[3])
|
| 786 |
|
|
1'b0: // buffer control bits
|
| 787 |
|
|
begin
|
| 788 |
|
|
bit_start_1 = 0;
|
| 789 |
|
|
bit_end_1 = 31; // 8;
|
| 790 |
|
|
bit_start_2 = 11;
|
| 791 |
|
|
bit_end_2 = 31;
|
| 792 |
|
|
end
|
| 793 |
|
|
default: // 1'b1: // buffer pointer
|
| 794 |
|
|
begin
|
| 795 |
|
|
bit_start_1 = 0;
|
| 796 |
|
|
bit_end_1 = 31;
|
| 797 |
|
|
bit_start_2 = 32; // not used
|
| 798 |
|
|
bit_end_2 = 32; // not used
|
| 799 |
|
|
end
|
| 800 |
|
|
endcase
|
| 801 |
|
|
end
|
| 802 |
|
|
else // RX buffer descriptors
|
| 803 |
|
|
begin
|
| 804 |
|
|
// set ranges of R/W bits
|
| 805 |
|
|
case (addr[3])
|
| 806 |
|
|
1'b0: // buffer control bits
|
| 807 |
|
|
begin
|
| 808 |
|
|
bit_start_1 = 0;
|
| 809 |
|
|
bit_end_1 = 31; // 7;
|
| 810 |
|
|
bit_start_2 = 13;
|
| 811 |
|
|
bit_end_2 = 31;
|
| 812 |
|
|
end
|
| 813 |
|
|
default: // 1'b1: // buffer pointer
|
| 814 |
|
|
begin
|
| 815 |
|
|
bit_start_1 = 0;
|
| 816 |
|
|
bit_end_1 = 31;
|
| 817 |
|
|
bit_start_2 = 32; // not used
|
| 818 |
|
|
bit_end_2 = 32; // not used
|
| 819 |
|
|
end
|
| 820 |
|
|
endcase
|
| 821 |
|
|
end
|
| 822 |
|
|
|
| 823 |
169 |
mohor |
for (i_data = 0; i_data <= 31; i_data = i_data + 1) // the position of walking one
|
| 824 |
|
|
begin
|
| 825 |
|
|
data = 1'b1 << i_data;
|
| 826 |
178 |
mohor |
if ( (addr[3] == 0) && (i_data == 15) ) // DO NOT WRITE to this bit !!!
|
| 827 |
|
|
;
|
| 828 |
169 |
mohor |
else
|
| 829 |
|
|
begin
|
| 830 |
|
|
wbm_write(addr, data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 831 |
|
|
wbm_read(addr, tmp_data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 832 |
|
|
if ( ((i_data >= bit_start_1) && (i_data <= bit_end_1)) ||
|
| 833 |
|
|
((i_data >= bit_start_2) && (i_data <= bit_end_2)) ) // data should be equal to tmp_data
|
| 834 |
|
|
begin
|
| 835 |
|
|
if (tmp_data !== data)
|
| 836 |
|
|
begin
|
| 837 |
|
|
fail = fail + 1;
|
| 838 |
178 |
mohor |
test_fail("RW bit of the MAC buffer descriptors was not written or not read");
|
| 839 |
169 |
mohor |
`TIME;
|
| 840 |
|
|
$display("wbm_init_waits %d, addr %h, data %h, tmp_data %h",
|
| 841 |
|
|
wbm_init_waits, addr, data, tmp_data);
|
| 842 |
|
|
end
|
| 843 |
|
|
end
|
| 844 |
|
|
else // data should not be equal to tmp_data
|
| 845 |
|
|
begin
|
| 846 |
|
|
if (tmp_data === data)
|
| 847 |
|
|
begin
|
| 848 |
|
|
fail = fail + 1;
|
| 849 |
178 |
mohor |
test_fail("NON RW bit of the MAC buffer descriptors was written, but it shouldn't be");
|
| 850 |
169 |
mohor |
`TIME;
|
| 851 |
|
|
$display("wbm_init_waits %d, addr %h, data %h, tmp_data %h",
|
| 852 |
|
|
wbm_init_waits, addr, data, tmp_data);
|
| 853 |
|
|
end
|
| 854 |
|
|
end
|
| 855 |
|
|
end
|
| 856 |
|
|
end
|
| 857 |
|
|
end
|
| 858 |
178 |
mohor |
// INTERMEDIATE DISPLAYS
|
| 859 |
|
|
case (i)
|
| 860 |
209 |
tadejm |
0: $display(" ->buffer descriptors tested with 0 bus delay");
|
| 861 |
|
|
1: $display(" ->buffer descriptors tested with 1 bus delay cycle");
|
| 862 |
|
|
2: $display(" ->buffer descriptors tested with 2 bus delay cycles");
|
| 863 |
|
|
3: $display(" ->buffer descriptors tested with 3 bus delay cycles");
|
| 864 |
|
|
default: $display(" ->buffer descriptors tested with 4 bus delay cycles");
|
| 865 |
178 |
mohor |
endcase
|
| 866 |
|
|
end
|
| 867 |
|
|
if(fail == 0)
|
| 868 |
|
|
test_ok;
|
| 869 |
|
|
else
|
| 870 |
|
|
fail = 0;
|
| 871 |
169 |
mohor |
end
|
| 872 |
178 |
mohor |
|
| 873 |
|
|
|
| 874 |
|
|
////////////////////////////////////////////////////////////////////
|
| 875 |
|
|
//// ////
|
| 876 |
|
|
//// Test max reg. values and reg. values after writing ////
|
| 877 |
|
|
//// inverse reset values and hard reset of the MAC ////
|
| 878 |
|
|
//// ////
|
| 879 |
|
|
////////////////////////////////////////////////////////////////////
|
| 880 |
|
|
if (test_num == 2) // Start this task
|
| 881 |
169 |
mohor |
begin
|
| 882 |
194 |
tadej |
// TEST 2: MAX REG. VALUES AND REG. VALUES AFTER WRITING INVERSE RESET VALUES AND HARD RESET OF THE MAC
|
| 883 |
178 |
mohor |
test_name =
|
| 884 |
194 |
tadej |
"TEST 2: MAX REG. VALUES AND REG. VALUES AFTER WRITING INVERSE RESET VALUES AND HARD RESET OF THE MAC";
|
| 885 |
178 |
mohor |
`TIME; $display(
|
| 886 |
194 |
tadej |
" TEST 2: MAX REG. VALUES AND REG. VALUES AFTER WRITING INVERSE RESET VALUES AND HARD RESET OF THE MAC");
|
| 887 |
178 |
mohor |
|
| 888 |
|
|
// reset MAC registers
|
| 889 |
|
|
hard_reset;
|
| 890 |
|
|
for (i = 0; i <= 4; i = i + 1) // 0, 2 - WRITE; 1, 3, 4 - READ
|
| 891 |
169 |
mohor |
begin
|
| 892 |
178 |
mohor |
for (i_addr = 0; i_addr <= 32'h4C; i_addr = i_addr + 4) // register address
|
| 893 |
169 |
mohor |
begin
|
| 894 |
178 |
mohor |
addr = `ETH_BASE + i_addr;
|
| 895 |
|
|
// set ranges of R/W bits
|
| 896 |
|
|
case (addr)
|
| 897 |
|
|
`ETH_MODER:
|
| 898 |
169 |
mohor |
begin
|
| 899 |
178 |
mohor |
data = 32'h0000_A800;
|
| 900 |
|
|
data_max = 32'h0001_FFFF;
|
| 901 |
169 |
mohor |
end
|
| 902 |
178 |
mohor |
`ETH_INT: // READONLY - tested within INT test
|
| 903 |
169 |
mohor |
begin
|
| 904 |
178 |
mohor |
data = 32'h0000_0000;
|
| 905 |
|
|
data_max = 32'h0000_0000;
|
| 906 |
169 |
mohor |
end
|
| 907 |
|
|
`ETH_INT_MASK:
|
| 908 |
178 |
mohor |
begin
|
| 909 |
|
|
data = 32'h0000_0000;
|
| 910 |
|
|
data_max = 32'h0000_007F;
|
| 911 |
|
|
end
|
| 912 |
169 |
mohor |
`ETH_IPGT:
|
| 913 |
178 |
mohor |
begin
|
| 914 |
|
|
data = 32'h0000_0012;
|
| 915 |
|
|
data_max = 32'h0000_007F;
|
| 916 |
|
|
end
|
| 917 |
169 |
mohor |
`ETH_IPGR1:
|
| 918 |
178 |
mohor |
begin
|
| 919 |
|
|
data = 32'h0000_000C;
|
| 920 |
|
|
data_max = 32'h0000_007F;
|
| 921 |
|
|
end
|
| 922 |
169 |
mohor |
`ETH_IPGR2:
|
| 923 |
178 |
mohor |
begin
|
| 924 |
|
|
data = 32'h0000_0012;
|
| 925 |
|
|
data_max = 32'h0000_007F;
|
| 926 |
|
|
end
|
| 927 |
169 |
mohor |
`ETH_PACKETLEN:
|
| 928 |
178 |
mohor |
begin
|
| 929 |
|
|
data = 32'h0040_0600;
|
| 930 |
|
|
data_max = 32'hFFFF_FFFF;
|
| 931 |
|
|
end
|
| 932 |
169 |
mohor |
`ETH_COLLCONF:
|
| 933 |
178 |
mohor |
begin
|
| 934 |
|
|
data = 32'h000F_003F;
|
| 935 |
|
|
data_max = 32'h000F_003F;
|
| 936 |
|
|
end
|
| 937 |
169 |
mohor |
`ETH_TX_BD_NUM:
|
| 938 |
178 |
mohor |
begin
|
| 939 |
|
|
data = 32'h0000_0040;
|
| 940 |
|
|
data_max = 32'h0000_0080;
|
| 941 |
|
|
end
|
| 942 |
169 |
mohor |
`ETH_CTRLMODER:
|
| 943 |
178 |
mohor |
begin
|
| 944 |
|
|
data = 32'h0000_0000;
|
| 945 |
|
|
data_max = 32'h0000_0007;
|
| 946 |
|
|
end
|
| 947 |
169 |
mohor |
`ETH_MIIMODER:
|
| 948 |
178 |
mohor |
begin
|
| 949 |
|
|
data = 32'h0000_0064;
|
| 950 |
|
|
data_max = 32'h0000_03FF;
|
| 951 |
|
|
end
|
| 952 |
169 |
mohor |
`ETH_MIICOMMAND: // "WRITEONLY" - tested within MIIM test - 3 LSBits are not written here!!!
|
| 953 |
178 |
mohor |
begin
|
| 954 |
|
|
data = 32'h0000_0000;
|
| 955 |
|
|
data_max = 32'h0000_0007;
|
| 956 |
|
|
end
|
| 957 |
169 |
mohor |
`ETH_MIIADDRESS:
|
| 958 |
178 |
mohor |
begin
|
| 959 |
|
|
data = 32'h0000_0000;
|
| 960 |
|
|
data_max = 32'h0000_1F1F;
|
| 961 |
|
|
end
|
| 962 |
169 |
mohor |
`ETH_MIITX_DATA:
|
| 963 |
178 |
mohor |
begin
|
| 964 |
|
|
data = 32'h0000_0000;
|
| 965 |
|
|
data_max = 32'h0000_FFFF;
|
| 966 |
|
|
end
|
| 967 |
169 |
mohor |
`ETH_MIIRX_DATA: // READONLY - tested within MIIM test
|
| 968 |
|
|
begin
|
| 969 |
178 |
mohor |
data = 32'h0000_0000;
|
| 970 |
|
|
data_max = 32'h0000_0000;
|
| 971 |
169 |
mohor |
end
|
| 972 |
178 |
mohor |
`ETH_MIISTATUS: // READONLY - tested within MIIM test
|
| 973 |
169 |
mohor |
begin
|
| 974 |
178 |
mohor |
data = 32'h0000_0000;
|
| 975 |
|
|
data_max = 32'h0000_0000;
|
| 976 |
169 |
mohor |
end
|
| 977 |
178 |
mohor |
`ETH_MAC_ADDR0:
|
| 978 |
169 |
mohor |
begin
|
| 979 |
178 |
mohor |
data = 32'h0000_0000;
|
| 980 |
|
|
data_max = 32'hFFFF_FFFF;
|
| 981 |
169 |
mohor |
end
|
| 982 |
178 |
mohor |
`ETH_MAC_ADDR1:
|
| 983 |
169 |
mohor |
begin
|
| 984 |
178 |
mohor |
data = 32'h0000_0000;
|
| 985 |
|
|
data_max = 32'h0000_FFFF;
|
| 986 |
169 |
mohor |
end
|
| 987 |
178 |
mohor |
`ETH_HASH_ADDR0:
|
| 988 |
169 |
mohor |
begin
|
| 989 |
178 |
mohor |
data = 32'h0000_0000;
|
| 990 |
|
|
data_max = 32'hFFFF_FFFF;
|
| 991 |
169 |
mohor |
end
|
| 992 |
178 |
mohor |
default: // `ETH_HASH_ADDR1:
|
| 993 |
169 |
mohor |
begin
|
| 994 |
178 |
mohor |
data = 32'h0000_0000;
|
| 995 |
|
|
data_max = 32'hFFFF_FFFF;
|
| 996 |
169 |
mohor |
end
|
| 997 |
|
|
endcase
|
| 998 |
178 |
mohor |
|
| 999 |
|
|
wbm_init_waits = {$random} % 3;
|
| 1000 |
|
|
wbm_subseq_waits = {$random} % 5; // it is not important for single accesses
|
| 1001 |
|
|
if (i == 0)
|
| 1002 |
274 |
tadejm |
begin
|
| 1003 |
178 |
mohor |
wbm_write(addr, ~data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 1004 |
274 |
tadejm |
end
|
| 1005 |
178 |
mohor |
else if (i == 2)
|
| 1006 |
274 |
tadejm |
begin
|
| 1007 |
178 |
mohor |
wbm_write(addr, 32'hFFFFFFFF, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 1008 |
274 |
tadejm |
end
|
| 1009 |
178 |
mohor |
else if ((i == 1) || (i == 4))
|
| 1010 |
169 |
mohor |
begin
|
| 1011 |
178 |
mohor |
wbm_read(addr, tmp_data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 1012 |
|
|
if (tmp_data !== data)
|
| 1013 |
|
|
begin
|
| 1014 |
|
|
fail = fail + 1;
|
| 1015 |
|
|
test_fail("RESET value of the MAC register is not correct");
|
| 1016 |
|
|
`TIME;
|
| 1017 |
|
|
$display(" addr %h, data %h, tmp_data %h", addr, data, tmp_data);
|
| 1018 |
|
|
end
|
| 1019 |
169 |
mohor |
end
|
| 1020 |
178 |
mohor |
else // check maximum values
|
| 1021 |
169 |
mohor |
begin
|
| 1022 |
|
|
wbm_read(addr, tmp_data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 1023 |
178 |
mohor |
if (addr == `ETH_TX_BD_NUM) // previous data should remain in this register
|
| 1024 |
169 |
mohor |
begin
|
| 1025 |
|
|
if (tmp_data !== data)
|
| 1026 |
|
|
begin
|
| 1027 |
|
|
fail = fail + 1;
|
| 1028 |
178 |
mohor |
test_fail("Previous value of the TX_BD_NUM register did not remain");
|
| 1029 |
169 |
mohor |
`TIME;
|
| 1030 |
178 |
mohor |
$display(" addr %h, data_max %h, tmp_data %h", addr, data_max, tmp_data);
|
| 1031 |
169 |
mohor |
end
|
| 1032 |
178 |
mohor |
// try maximum (80)
|
| 1033 |
|
|
wbm_write(addr, data_max, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 1034 |
|
|
wbm_read(addr, tmp_data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 1035 |
|
|
if (tmp_data !== data_max)
|
| 1036 |
|
|
begin
|
| 1037 |
|
|
fail = fail + 1;
|
| 1038 |
|
|
test_fail("MAX value of the TX_BD_NUM register is not correct");
|
| 1039 |
|
|
`TIME;
|
| 1040 |
|
|
$display(" addr %h, data_max %h, tmp_data %h", addr, data_max, tmp_data);
|
| 1041 |
|
|
end
|
| 1042 |
|
|
// try one less than maximum (80)
|
| 1043 |
|
|
wbm_write(addr, (data_max - 1), 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 1044 |
|
|
wbm_read(addr, tmp_data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 1045 |
|
|
if (tmp_data !== (data_max - 1))
|
| 1046 |
|
|
begin
|
| 1047 |
|
|
fail = fail + 1;
|
| 1048 |
|
|
test_fail("ONE less than MAX value of the TX_BD_NUM register is not correct");
|
| 1049 |
|
|
`TIME;
|
| 1050 |
|
|
$display(" addr %h, data_max %h, tmp_data %h", addr, data_max, tmp_data);
|
| 1051 |
|
|
end
|
| 1052 |
|
|
// try one more than maximum (80)
|
| 1053 |
|
|
wbm_write(addr, (data_max + 1), 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 1054 |
|
|
wbm_read(addr, tmp_data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 1055 |
|
|
if (tmp_data !== (data_max - 1)) // previous data should remain in this register
|
| 1056 |
|
|
begin
|
| 1057 |
|
|
fail = fail + 1;
|
| 1058 |
|
|
test_fail("Previous value of the TX_BD_NUM register did not remain");
|
| 1059 |
|
|
`TIME;
|
| 1060 |
|
|
$display(" addr %h, data_max %h, tmp_data %h", addr, data_max, tmp_data);
|
| 1061 |
|
|
end
|
| 1062 |
169 |
mohor |
end
|
| 1063 |
178 |
mohor |
else
|
| 1064 |
169 |
mohor |
begin
|
| 1065 |
178 |
mohor |
if (tmp_data !== data_max)
|
| 1066 |
169 |
mohor |
begin
|
| 1067 |
|
|
fail = fail + 1;
|
| 1068 |
178 |
mohor |
test_fail("MAX value of the MAC register is not correct");
|
| 1069 |
169 |
mohor |
`TIME;
|
| 1070 |
178 |
mohor |
$display(" addr %h, data_max %h, tmp_data %h", addr, data_max, tmp_data);
|
| 1071 |
169 |
mohor |
end
|
| 1072 |
|
|
end
|
| 1073 |
|
|
end
|
| 1074 |
|
|
end
|
| 1075 |
178 |
mohor |
// reset MAC registers
|
| 1076 |
|
|
if ((i == 0) || (i == 3))
|
| 1077 |
|
|
hard_reset;
|
| 1078 |
169 |
mohor |
end
|
| 1079 |
178 |
mohor |
if(fail == 0)
|
| 1080 |
|
|
test_ok;
|
| 1081 |
|
|
else
|
| 1082 |
|
|
fail = 0;
|
| 1083 |
169 |
mohor |
end
|
| 1084 |
116 |
mohor |
|
| 1085 |
156 |
mohor |
|
| 1086 |
181 |
mohor |
////////////////////////////////////////////////////////////////////
|
| 1087 |
|
|
//// ////
|
| 1088 |
|
|
//// Test buffer desc. ram preserving values after hard reset ////
|
| 1089 |
|
|
//// of the mac and reseting the logic ////
|
| 1090 |
|
|
//// ////
|
| 1091 |
|
|
////////////////////////////////////////////////////////////////////
|
| 1092 |
178 |
mohor |
if (test_num == 3) // Start this task
|
| 1093 |
169 |
mohor |
begin
|
| 1094 |
194 |
tadej |
// TEST 3: BUFFER DESC. RAM PRESERVING VALUES AFTER HARD RESET OF THE MAC AND RESETING THE LOGIC
|
| 1095 |
|
|
test_name = "TEST 3: BUFFER DESC. RAM PRESERVING VALUES AFTER HARD RESET OF THE MAC AND RESETING THE LOGIC";
|
| 1096 |
178 |
mohor |
`TIME;
|
| 1097 |
194 |
tadej |
$display(" TEST 3: BUFFER DESC. RAM PRESERVING VALUES AFTER HARD RESET OF THE MAC AND RESETING THE LOGIC");
|
| 1098 |
178 |
mohor |
|
| 1099 |
|
|
// reset MAC registers
|
| 1100 |
|
|
hard_reset;
|
| 1101 |
|
|
// reset LOGIC with soft reset
|
| 1102 |
274 |
tadejm |
// reset_mac;
|
| 1103 |
|
|
// reset_mii;
|
| 1104 |
178 |
mohor |
for (i = 0; i <= 3; i = i + 1) // 0, 2 - WRITE; 1, 3 - READ
|
| 1105 |
169 |
mohor |
begin
|
| 1106 |
178 |
mohor |
for (i_addr = 32'h400; i_addr <= 32'h7FC; i_addr = i_addr + 4) // buffer descriptor address
|
| 1107 |
169 |
mohor |
begin
|
| 1108 |
178 |
mohor |
addr = `ETH_BASE + i_addr;
|
| 1109 |
|
|
|
| 1110 |
|
|
wbm_init_waits = {$random} % 3;
|
| 1111 |
|
|
wbm_subseq_waits = {$random} % 5; // it is not important for single accesses
|
| 1112 |
|
|
if (i == 0)
|
| 1113 |
169 |
mohor |
begin
|
| 1114 |
178 |
mohor |
data = 32'hFFFFFFFF;
|
| 1115 |
|
|
wbm_write(addr, 32'hFFFFFFFF, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 1116 |
169 |
mohor |
end
|
| 1117 |
178 |
mohor |
else if (i == 2)
|
| 1118 |
169 |
mohor |
begin
|
| 1119 |
178 |
mohor |
data = 32'h00000000;
|
| 1120 |
|
|
wbm_write(addr, 32'h00000000, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 1121 |
169 |
mohor |
end
|
| 1122 |
|
|
else
|
| 1123 |
|
|
begin
|
| 1124 |
178 |
mohor |
wbm_read(addr, tmp_data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 1125 |
|
|
if (tmp_data !== data)
|
| 1126 |
169 |
mohor |
begin
|
| 1127 |
|
|
fail = fail + 1;
|
| 1128 |
178 |
mohor |
test_fail("PRESERVED value of the MAC buffer descriptors is not correct");
|
| 1129 |
169 |
mohor |
`TIME;
|
| 1130 |
178 |
mohor |
$display(" addr %h, data %h, tmp_data %h", addr, data, tmp_data);
|
| 1131 |
169 |
mohor |
end
|
| 1132 |
|
|
end
|
| 1133 |
|
|
end
|
| 1134 |
178 |
mohor |
if ((i == 0) || (i == 2))
|
| 1135 |
|
|
begin
|
| 1136 |
|
|
// reset MAC registers
|
| 1137 |
|
|
hard_reset;
|
| 1138 |
|
|
// reset LOGIC with soft reset
|
| 1139 |
274 |
tadejm |
// reset_mac;
|
| 1140 |
|
|
// reset_mii;
|
| 1141 |
178 |
mohor |
end
|
| 1142 |
169 |
mohor |
end
|
| 1143 |
178 |
mohor |
if(fail == 0)
|
| 1144 |
|
|
test_ok;
|
| 1145 |
|
|
else
|
| 1146 |
|
|
fail = 0;
|
| 1147 |
169 |
mohor |
end
|
| 1148 |
116 |
mohor |
|
| 1149 |
|
|
|
| 1150 |
178 |
mohor |
if (test_num == 4) // Start this task
|
| 1151 |
169 |
mohor |
begin
|
| 1152 |
194 |
tadej |
/* // TEST 4: 'WALKING ONE' WITH BURST CYCLES ACROSS MAC REGISTERS ( VARIOUS BUS DELAYS )
|
| 1153 |
|
|
test_name = "TEST 4: 'WALKING ONE' WITH BURST CYCLES ACROSS MAC REGISTERS ( VARIOUS BUS DELAYS )";
|
| 1154 |
|
|
`TIME; $display(" TEST 4: 'WALKING ONE' WITH BURST CYCLES ACROSS MAC REGISTERS ( VARIOUS BUS DELAYS )");
|
| 1155 |
178 |
mohor |
|
| 1156 |
|
|
data = 0;
|
| 1157 |
|
|
burst_data = 0;
|
| 1158 |
|
|
burst_tmp_data = 0;
|
| 1159 |
|
|
i_length = 10; // two bursts for length 20
|
| 1160 |
|
|
for (i = 0; i <= 4; i = i + 1) // for initial wait cycles on WB bus
|
| 1161 |
|
|
begin
|
| 1162 |
|
|
for (i1 = 0; i1 <= 4; i1 = i1 + 1) // for initial wait cycles on WB bus
|
| 1163 |
|
|
begin
|
| 1164 |
|
|
wbm_init_waits = i;
|
| 1165 |
|
|
wbm_subseq_waits = i1;
|
| 1166 |
|
|
#1;
|
| 1167 |
|
|
for (i_data = 0; i_data <= 31; i_data = i_data + 1) // the position of walking one
|
| 1168 |
|
|
begin
|
| 1169 |
|
|
data = 1'b1 << i_data;
|
| 1170 |
|
|
#1;
|
| 1171 |
|
|
for (i2 = 32'h4C; i2 >= 0; i2 = i2 - 4)
|
| 1172 |
|
|
begin
|
| 1173 |
|
|
burst_data = burst_data << 32;
|
| 1174 |
|
|
// DO NOT WRITE to 3 LSBits of MIICOMMAND !!!
|
| 1175 |
|
|
if ( ((`ETH_BASE + i2) == `ETH_MIICOMMAND) && (i_data <= 2) )
|
| 1176 |
|
|
begin
|
| 1177 |
|
|
#1 burst_data[31:0] = 0;
|
| 1178 |
|
|
end
|
| 1179 |
|
|
else
|
| 1180 |
|
|
begin
|
| 1181 |
|
|
#1 burst_data[31:0] = data;
|
| 1182 |
|
|
end
|
| 1183 |
|
|
end
|
| 1184 |
|
|
#1;
|
| 1185 |
|
|
// 2 burst writes
|
| 1186 |
|
|
addr = `ETH_BASE; // address of a first burst
|
| 1187 |
|
|
wbm_write(addr, burst_data[(32 * 10 - 1):0], 4'hF, i_length, wbm_init_waits, wbm_subseq_waits);
|
| 1188 |
|
|
burst_tmp_data = burst_data >> (32 * i_length);
|
| 1189 |
|
|
addr = addr + 32'h28; // address of a second burst
|
| 1190 |
|
|
wbm_write(addr, burst_tmp_data[(32 * 10 - 1):0], 4'hF, i_length, wbm_init_waits, wbm_subseq_waits);
|
| 1191 |
|
|
#1;
|
| 1192 |
|
|
// 2 burst reads
|
| 1193 |
|
|
addr = `ETH_BASE; // address of a first burst
|
| 1194 |
|
|
wbm_read(addr, burst_tmp_data[(32 * 10 - 1):0], 4'hF, i_length,
|
| 1195 |
|
|
wbm_init_waits, wbm_subseq_waits); // first burst
|
| 1196 |
|
|
burst_tmp_data = burst_tmp_data << (32 * i_length);
|
| 1197 |
|
|
addr = addr + 32'h28; // address of a second burst
|
| 1198 |
|
|
wbm_read(addr, burst_tmp_data[(32 * 10 - 1):0], 4'hF, i_length,
|
| 1199 |
|
|
wbm_init_waits, wbm_subseq_waits); // second burst
|
| 1200 |
|
|
#1;
|
| 1201 |
|
|
for (i2 = 0; i2 <= 32'h4C; i2 = i2 + 4)
|
| 1202 |
|
|
begin
|
| 1203 |
|
|
// set ranges of R/W bits
|
| 1204 |
|
|
case (`ETH_BASE + i2)
|
| 1205 |
|
|
`ETH_MODER:
|
| 1206 |
|
|
begin
|
| 1207 |
|
|
bit_start_1 = 0;
|
| 1208 |
|
|
bit_end_1 = 16;
|
| 1209 |
|
|
bit_start_2 = 32; // not used
|
| 1210 |
|
|
bit_end_2 = 32; // not used
|
| 1211 |
|
|
end
|
| 1212 |
|
|
`ETH_INT: // READONLY - tested within INT test
|
| 1213 |
|
|
begin
|
| 1214 |
|
|
bit_start_1 = 32; // not used
|
| 1215 |
|
|
bit_end_1 = 32; // not used
|
| 1216 |
|
|
bit_start_2 = 32; // not used
|
| 1217 |
|
|
bit_end_2 = 32; // not used
|
| 1218 |
|
|
end
|
| 1219 |
|
|
`ETH_INT_MASK:
|
| 1220 |
|
|
begin
|
| 1221 |
|
|
bit_start_1 = 0;
|
| 1222 |
|
|
bit_end_1 = 6;
|
| 1223 |
|
|
bit_start_2 = 32; // not used
|
| 1224 |
|
|
bit_end_2 = 32; // not used
|
| 1225 |
|
|
end
|
| 1226 |
|
|
`ETH_IPGT:
|
| 1227 |
|
|
begin
|
| 1228 |
|
|
bit_start_1 = 0;
|
| 1229 |
|
|
bit_end_1 = 6;
|
| 1230 |
|
|
bit_start_2 = 32; // not used
|
| 1231 |
|
|
bit_end_2 = 32; // not used
|
| 1232 |
|
|
end
|
| 1233 |
|
|
`ETH_IPGR1:
|
| 1234 |
|
|
begin
|
| 1235 |
|
|
bit_start_1 = 0;
|
| 1236 |
|
|
bit_end_1 = 6;
|
| 1237 |
|
|
bit_start_2 = 32; // not used
|
| 1238 |
|
|
bit_end_2 = 32; // not used
|
| 1239 |
|
|
end
|
| 1240 |
|
|
`ETH_IPGR2:
|
| 1241 |
|
|
begin
|
| 1242 |
|
|
bit_start_1 = 0;
|
| 1243 |
|
|
bit_end_1 = 6;
|
| 1244 |
|
|
bit_start_2 = 32; // not used
|
| 1245 |
|
|
bit_end_2 = 32; // not used
|
| 1246 |
|
|
end
|
| 1247 |
|
|
`ETH_PACKETLEN:
|
| 1248 |
|
|
begin
|
| 1249 |
|
|
bit_start_1 = 0;
|
| 1250 |
|
|
bit_end_1 = 31;
|
| 1251 |
|
|
bit_start_2 = 32; // not used
|
| 1252 |
|
|
bit_end_2 = 32; // not used
|
| 1253 |
|
|
end
|
| 1254 |
|
|
`ETH_COLLCONF:
|
| 1255 |
|
|
begin
|
| 1256 |
|
|
bit_start_1 = 0;
|
| 1257 |
|
|
bit_end_1 = 5;
|
| 1258 |
|
|
bit_start_2 = 16;
|
| 1259 |
|
|
bit_end_2 = 19;
|
| 1260 |
|
|
end
|
| 1261 |
|
|
`ETH_TX_BD_NUM:
|
| 1262 |
|
|
begin
|
| 1263 |
|
|
bit_start_1 = 0;
|
| 1264 |
|
|
bit_end_1 = 7;
|
| 1265 |
|
|
bit_start_2 = 32; // not used
|
| 1266 |
|
|
bit_end_2 = 32; // not used
|
| 1267 |
|
|
end
|
| 1268 |
|
|
`ETH_CTRLMODER:
|
| 1269 |
|
|
begin
|
| 1270 |
|
|
bit_start_1 = 0;
|
| 1271 |
|
|
bit_end_1 = 2;
|
| 1272 |
|
|
bit_start_2 = 32; // not used
|
| 1273 |
|
|
bit_end_2 = 32; // not used
|
| 1274 |
|
|
end
|
| 1275 |
|
|
`ETH_MIIMODER:
|
| 1276 |
|
|
begin
|
| 1277 |
|
|
bit_start_1 = 0;
|
| 1278 |
|
|
bit_end_1 = 9;
|
| 1279 |
|
|
bit_start_2 = 32; // not used
|
| 1280 |
|
|
bit_end_2 = 32; // not used
|
| 1281 |
|
|
end
|
| 1282 |
|
|
`ETH_MIICOMMAND: // "WRITEONLY" - tested within MIIM test - 3 LSBits are not written here!!!
|
| 1283 |
|
|
begin
|
| 1284 |
|
|
bit_start_1 = 32; // not used
|
| 1285 |
|
|
bit_end_1 = 32; // not used
|
| 1286 |
|
|
bit_start_2 = 32; // not used
|
| 1287 |
|
|
bit_end_2 = 32; // not used
|
| 1288 |
|
|
end
|
| 1289 |
|
|
`ETH_MIIADDRESS:
|
| 1290 |
|
|
begin
|
| 1291 |
|
|
bit_start_1 = 0;
|
| 1292 |
|
|
bit_end_1 = 4;
|
| 1293 |
|
|
bit_start_2 = 8;
|
| 1294 |
|
|
bit_end_2 = 12;
|
| 1295 |
|
|
end
|
| 1296 |
|
|
`ETH_MIITX_DATA:
|
| 1297 |
|
|
begin
|
| 1298 |
|
|
bit_start_1 = 0;
|
| 1299 |
|
|
bit_end_1 = 15;
|
| 1300 |
|
|
bit_start_2 = 32; // not used
|
| 1301 |
|
|
bit_end_2 = 32; // not used
|
| 1302 |
|
|
end
|
| 1303 |
|
|
`ETH_MIIRX_DATA: // READONLY - tested within MIIM test
|
| 1304 |
|
|
begin
|
| 1305 |
|
|
bit_start_1 = 32; // not used
|
| 1306 |
|
|
bit_end_1 = 32; // not used
|
| 1307 |
|
|
bit_start_2 = 32; // not used
|
| 1308 |
|
|
bit_end_2 = 32; // not used
|
| 1309 |
|
|
end
|
| 1310 |
|
|
`ETH_MIISTATUS: // READONLY - tested within MIIM test
|
| 1311 |
|
|
begin
|
| 1312 |
|
|
bit_start_1 = 32; // not used
|
| 1313 |
|
|
bit_end_1 = 32; // not used
|
| 1314 |
|
|
bit_start_2 = 32; // not used
|
| 1315 |
|
|
bit_end_2 = 32; // not used
|
| 1316 |
|
|
end
|
| 1317 |
|
|
`ETH_MAC_ADDR0:
|
| 1318 |
|
|
begin
|
| 1319 |
|
|
bit_start_1 = 0;
|
| 1320 |
|
|
bit_end_1 = 31;
|
| 1321 |
|
|
bit_start_2 = 32; // not used
|
| 1322 |
|
|
bit_end_2 = 32; // not used
|
| 1323 |
|
|
end
|
| 1324 |
|
|
`ETH_MAC_ADDR1:
|
| 1325 |
|
|
begin
|
| 1326 |
|
|
bit_start_1 = 0;
|
| 1327 |
|
|
bit_end_1 = 15;
|
| 1328 |
|
|
bit_start_2 = 32; // not used
|
| 1329 |
|
|
bit_end_2 = 32; // not used
|
| 1330 |
|
|
end
|
| 1331 |
|
|
`ETH_HASH_ADDR0:
|
| 1332 |
|
|
begin
|
| 1333 |
|
|
bit_start_1 = 0;
|
| 1334 |
|
|
bit_end_1 = 31;
|
| 1335 |
|
|
bit_start_2 = 32; // not used
|
| 1336 |
|
|
bit_end_2 = 32; // not used
|
| 1337 |
|
|
end
|
| 1338 |
|
|
default: // `ETH_HASH_ADDR1:
|
| 1339 |
|
|
begin
|
| 1340 |
|
|
bit_start_1 = 0;
|
| 1341 |
|
|
bit_end_1 = 31;
|
| 1342 |
|
|
bit_start_2 = 32; // not used
|
| 1343 |
|
|
bit_end_2 = 32; // not used
|
| 1344 |
|
|
end
|
| 1345 |
|
|
endcase
|
| 1346 |
|
|
#1;
|
| 1347 |
|
|
// 3 LSBits of MIICOMMAND are NOT written !!!
|
| 1348 |
|
|
if ( ((`ETH_BASE + i2) == `ETH_MIICOMMAND) && (i_data <= 2) )
|
| 1349 |
|
|
begin
|
| 1350 |
|
|
if (burst_tmp_data[31:0] !== burst_data[31:0])
|
| 1351 |
|
|
begin
|
| 1352 |
|
|
fail = fail + 1;
|
| 1353 |
|
|
test_fail("NON WR bit of the MAC MIICOMMAND register was wrong written or read");
|
| 1354 |
|
|
`TIME;
|
| 1355 |
|
|
$display("wbm_init_waits %d, wbm_subseq_waits %d, addr %h, data %h, tmp_data %h",
|
| 1356 |
|
|
wbm_init_waits, wbm_subseq_waits, i2, burst_data[31:0], burst_tmp_data[31:0]);
|
| 1357 |
|
|
end
|
| 1358 |
|
|
end
|
| 1359 |
|
|
else
|
| 1360 |
|
|
begin
|
| 1361 |
|
|
if ( ((i_data >= bit_start_1) && (i_data <= bit_end_1)) ||
|
| 1362 |
|
|
((i_data >= bit_start_2) && (i_data <= bit_end_2)) ) // data should be equal to tmp_data
|
| 1363 |
|
|
begin
|
| 1364 |
|
|
if (burst_tmp_data[31:0] !== burst_data[31:0])
|
| 1365 |
|
|
begin
|
| 1366 |
|
|
fail = fail + 1;
|
| 1367 |
|
|
test_fail("RW bit of the MAC register was not written or not read");
|
| 1368 |
|
|
`TIME;
|
| 1369 |
|
|
$display("wbm_init_waits %d, wbm_subseq_waits %d, addr %h, data %h, tmp_data %h",
|
| 1370 |
|
|
wbm_init_waits, wbm_subseq_waits, i2, burst_data[31:0], burst_tmp_data[31:0]);
|
| 1371 |
|
|
end
|
| 1372 |
|
|
end
|
| 1373 |
|
|
else // data should not be equal to tmp_data
|
| 1374 |
|
|
begin
|
| 1375 |
|
|
if (burst_tmp_data[31:0] === burst_data[31:0])
|
| 1376 |
|
|
begin
|
| 1377 |
|
|
fail = fail + 1;
|
| 1378 |
|
|
test_fail("NON RW bit of the MAC register was written, but it shouldn't be");
|
| 1379 |
|
|
`TIME;
|
| 1380 |
|
|
$display("wbm_init_waits %d, wbm_subseq_waits %d, addr %h, data %h, tmp_data %h",
|
| 1381 |
|
|
wbm_init_waits, wbm_subseq_waits, i2, burst_data[31:0], burst_tmp_data[31:0]);
|
| 1382 |
|
|
end
|
| 1383 |
|
|
end
|
| 1384 |
|
|
end
|
| 1385 |
|
|
burst_tmp_data = burst_tmp_data >> 32;
|
| 1386 |
|
|
burst_data = burst_data >> 32;
|
| 1387 |
|
|
end
|
| 1388 |
|
|
end
|
| 1389 |
|
|
end
|
| 1390 |
|
|
end
|
| 1391 |
|
|
if(fail == 0)
|
| 1392 |
|
|
test_ok;
|
| 1393 |
|
|
else
|
| 1394 |
|
|
fail = 0;*/
|
| 1395 |
|
|
end
|
| 1396 |
116 |
mohor |
|
| 1397 |
169 |
mohor |
end
|
| 1398 |
156 |
mohor |
|
| 1399 |
169 |
mohor |
end
|
| 1400 |
|
|
endtask // test_access_to_mac_reg
|
| 1401 |
156 |
mohor |
|
| 1402 |
|
|
|
| 1403 |
169 |
mohor |
task test_mii;
|
| 1404 |
|
|
input [31:0] start_task;
|
| 1405 |
|
|
input [31:0] end_task;
|
| 1406 |
|
|
integer i;
|
| 1407 |
|
|
integer i1;
|
| 1408 |
|
|
integer i2;
|
| 1409 |
|
|
integer i3;
|
| 1410 |
|
|
integer cnt;
|
| 1411 |
|
|
integer fail;
|
| 1412 |
181 |
mohor |
integer test_num;
|
| 1413 |
169 |
mohor |
reg [8:0] clk_div; // only 8 bits are valid!
|
| 1414 |
|
|
reg [4:0] phy_addr;
|
| 1415 |
|
|
reg [4:0] reg_addr;
|
| 1416 |
|
|
reg [15:0] phy_data;
|
| 1417 |
|
|
reg [15:0] tmp_data;
|
| 1418 |
|
|
begin
|
| 1419 |
|
|
// MIIM MODULE TEST
|
| 1420 |
|
|
test_heading("MIIM MODULE TEST");
|
| 1421 |
|
|
$display(" ");
|
| 1422 |
|
|
$display("MIIM MODULE TEST");
|
| 1423 |
|
|
fail = 0;
|
| 1424 |
156 |
mohor |
|
| 1425 |
192 |
tadej |
// reset MAC registers
|
| 1426 |
|
|
hard_reset;
|
| 1427 |
|
|
// reset MAC and MII LOGIC with soft reset
|
| 1428 |
274 |
tadejm |
//reset_mac;
|
| 1429 |
|
|
//reset_mii;
|
| 1430 |
116 |
mohor |
|
| 1431 |
194 |
tadej |
|
| 1432 |
181 |
mohor |
//////////////////////////////////////////////////////////////////////
|
| 1433 |
|
|
//// ////
|
| 1434 |
|
|
//// test_mii: ////
|
| 1435 |
|
|
//// ////
|
| 1436 |
|
|
//// 0: Test clock divider of mii management module with all ////
|
| 1437 |
|
|
//// possible frequences. ////
|
| 1438 |
|
|
//// 1: Test various readings from 'real' phy registers. ////
|
| 1439 |
|
|
//// 2: Test various writings to 'real' phy registers (control ////
|
| 1440 |
|
|
//// and non writable registers) ////
|
| 1441 |
|
|
//// 3: Test reset phy through mii management module ////
|
| 1442 |
|
|
//// 4: Test 'walking one' across phy address (with and without ////
|
| 1443 |
|
|
//// preamble) ////
|
| 1444 |
|
|
//// 5: Test 'walking one' across phy's register address (with ////
|
| 1445 |
|
|
//// and without preamble) ////
|
| 1446 |
|
|
//// 6: Test 'walking one' across phy's data (with and without ////
|
| 1447 |
|
|
//// preamble) ////
|
| 1448 |
|
|
//// 7: Test reading from phy with wrong phy address (host ////
|
| 1449 |
|
|
//// reading high 'z' data) ////
|
| 1450 |
|
|
//// 8: Test writing to phy with wrong phy address and reading ////
|
| 1451 |
|
|
//// from correct one ////
|
| 1452 |
|
|
//// 9: Test sliding stop scan command immediately after read ////
|
| 1453 |
|
|
//// request (with and without preamble) ////
|
| 1454 |
|
|
//// 10: Test sliding stop scan command immediately after write ////
|
| 1455 |
|
|
//// request (with and without preamble) ////
|
| 1456 |
|
|
//// 11: Test busy and nvalid status durations during write ////
|
| 1457 |
|
|
//// (with and without preamble) ////
|
| 1458 |
|
|
//// 12: Test busy and nvalid status durations during write ////
|
| 1459 |
|
|
//// (with and without preamble) ////
|
| 1460 |
|
|
//// 13: Test busy and nvalid status durations during scan (with ////
|
| 1461 |
|
|
//// and without preamble) ////
|
| 1462 |
|
|
//// 14: Test scan status from phy with detecting link-fail bit ////
|
| 1463 |
|
|
//// (with and without preamble) ////
|
| 1464 |
|
|
//// 15: Test scan status from phy with sliding link-fail bit ////
|
| 1465 |
|
|
//// (with and without preamble) ////
|
| 1466 |
|
|
//// 16: Test sliding stop scan command immediately after scan ////
|
| 1467 |
|
|
//// request (with and without preamble) ////
|
| 1468 |
|
|
//// 17: Test sliding stop scan command after 2. scan (with and ////
|
| 1469 |
|
|
//// without preamble) ////
|
| 1470 |
|
|
//// ////
|
| 1471 |
|
|
//////////////////////////////////////////////////////////////////////
|
| 1472 |
194 |
tadej |
for (test_num = start_task; test_num <= end_task; test_num = test_num + 1)
|
| 1473 |
169 |
mohor |
begin
|
| 1474 |
194 |
tadej |
|
| 1475 |
181 |
mohor |
////////////////////////////////////////////////////////////////////
|
| 1476 |
|
|
//// ////
|
| 1477 |
|
|
//// Test clock divider of mii management module with all ////
|
| 1478 |
|
|
//// possible frequences. ////
|
| 1479 |
|
|
//// ////
|
| 1480 |
|
|
////////////////////////////////////////////////////////////////////
|
| 1481 |
|
|
if (test_num == 0) // Test clock divider of mii management module with all possible frequences.
|
| 1482 |
169 |
mohor |
begin
|
| 1483 |
194 |
tadej |
// TEST 0: CLOCK DIVIDER OF MII MANAGEMENT MODULE WITH ALL POSSIBLE FREQUENCES
|
| 1484 |
|
|
test_name = "TEST 0: CLOCK DIVIDER OF MII MANAGEMENT MODULE WITH ALL POSSIBLE FREQUENCES";
|
| 1485 |
|
|
`TIME; $display(" TEST 0: CLOCK DIVIDER OF MII MANAGEMENT MODULE WITH ALL POSSIBLE FREQUENCES");
|
| 1486 |
181 |
mohor |
|
| 1487 |
|
|
wait(Mdc_O); // wait for MII clock to be 1
|
| 1488 |
|
|
for(clk_div = 0; clk_div <= 255; clk_div = clk_div + 1)
|
| 1489 |
|
|
begin
|
| 1490 |
|
|
i1 = 0;
|
| 1491 |
|
|
i2 = 0;
|
| 1492 |
|
|
#Tp mii_set_clk_div(clk_div[7:0]);
|
| 1493 |
|
|
@(posedge Mdc_O);
|
| 1494 |
|
|
#Tp;
|
| 1495 |
|
|
fork
|
| 1496 |
169 |
mohor |
begin
|
| 1497 |
181 |
mohor |
@(posedge Mdc_O);
|
| 1498 |
169 |
mohor |
#Tp;
|
| 1499 |
181 |
mohor |
disable count_i1;
|
| 1500 |
|
|
disable count_i2;
|
| 1501 |
169 |
mohor |
end
|
| 1502 |
181 |
mohor |
begin: count_i1
|
| 1503 |
|
|
forever
|
| 1504 |
|
|
begin
|
| 1505 |
|
|
@(posedge wb_clk);
|
| 1506 |
|
|
i1 = i1 + 1;
|
| 1507 |
|
|
#Tp;
|
| 1508 |
|
|
end
|
| 1509 |
|
|
end
|
| 1510 |
|
|
begin: count_i2
|
| 1511 |
|
|
forever
|
| 1512 |
|
|
begin
|
| 1513 |
|
|
@(negedge wb_clk);
|
| 1514 |
|
|
i2 = i2 + 1;
|
| 1515 |
|
|
#Tp;
|
| 1516 |
|
|
end
|
| 1517 |
|
|
end
|
| 1518 |
|
|
join
|
| 1519 |
|
|
if((clk_div[7:0] == 0) || (clk_div[7:0] == 1) || (clk_div[7:0] == 2) || (clk_div[7:0] == 3))
|
| 1520 |
|
|
begin
|
| 1521 |
|
|
if((i1 == i2) && (i1 == 2))
|
| 1522 |
169 |
mohor |
begin
|
| 1523 |
|
|
end
|
| 1524 |
181 |
mohor |
else
|
| 1525 |
|
|
begin
|
| 1526 |
|
|
fail = fail + 1;
|
| 1527 |
209 |
tadejm |
test_fail("Clock divider of MII module did'nt divide frequency corectly (it should divide by 2)");
|
| 1528 |
181 |
mohor |
end
|
| 1529 |
169 |
mohor |
end
|
| 1530 |
|
|
else
|
| 1531 |
|
|
begin
|
| 1532 |
181 |
mohor |
if((i1 == i2) && (i1 == {clk_div[7:1], 1'b0}))
|
| 1533 |
|
|
begin
|
| 1534 |
|
|
end
|
| 1535 |
|
|
else
|
| 1536 |
|
|
begin
|
| 1537 |
|
|
fail = fail + 1;
|
| 1538 |
|
|
test_fail("Clock divider of MII module did'nt divide frequency corectly");
|
| 1539 |
|
|
end
|
| 1540 |
169 |
mohor |
end
|
| 1541 |
|
|
end
|
| 1542 |
181 |
mohor |
if(fail == 0)
|
| 1543 |
|
|
test_ok;
|
| 1544 |
169 |
mohor |
else
|
| 1545 |
181 |
mohor |
fail = 0;
|
| 1546 |
|
|
end
|
| 1547 |
|
|
|
| 1548 |
|
|
|
| 1549 |
|
|
////////////////////////////////////////////////////////////////////
|
| 1550 |
|
|
//// ////
|
| 1551 |
|
|
//// Test various readings from 'real' phy registers. ////
|
| 1552 |
|
|
//// ////
|
| 1553 |
|
|
////////////////////////////////////////////////////////////////////
|
| 1554 |
|
|
if (test_num == 1) // Test various readings from 'real' phy registers.
|
| 1555 |
|
|
begin
|
| 1556 |
194 |
tadej |
// TEST 1: VARIOUS READINGS FROM 'REAL' PHY REGISTERS
|
| 1557 |
|
|
test_name = "TEST 1: VARIOUS READINGS FROM 'REAL' PHY REGISTERS";
|
| 1558 |
|
|
`TIME; $display(" TEST 1: VARIOUS READINGS FROM 'REAL' PHY REGISTERS");
|
| 1559 |
181 |
mohor |
|
| 1560 |
|
|
// set the fastest possible MII
|
| 1561 |
|
|
clk_div = 0;
|
| 1562 |
|
|
mii_set_clk_div(clk_div[7:0]);
|
| 1563 |
|
|
// set address
|
| 1564 |
|
|
reg_addr = 5'h1F;
|
| 1565 |
|
|
phy_addr = 5'h1;
|
| 1566 |
|
|
while(reg_addr >= 5'h4)
|
| 1567 |
169 |
mohor |
begin
|
| 1568 |
181 |
mohor |
// read request
|
| 1569 |
|
|
#Tp mii_read_req(phy_addr, reg_addr);
|
| 1570 |
|
|
check_mii_busy; // wait for read to finish
|
| 1571 |
|
|
// read data
|
| 1572 |
274 |
tadejm |
wbm_read(`ETH_MIIRX_DATA, phy_data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 1573 |
181 |
mohor |
if (phy_data !== 16'hDEAD)
|
| 1574 |
169 |
mohor |
begin
|
| 1575 |
181 |
mohor |
test_fail("Wrong data was read from PHY from 'not used' address space");
|
| 1576 |
|
|
fail = fail + 1;
|
| 1577 |
169 |
mohor |
end
|
| 1578 |
181 |
mohor |
if (reg_addr == 5'h4) // go out of for loop
|
| 1579 |
|
|
reg_addr = 5'h3;
|
| 1580 |
169 |
mohor |
else
|
| 1581 |
181 |
mohor |
reg_addr = reg_addr - 5'h9;
|
| 1582 |
169 |
mohor |
end
|
| 1583 |
181 |
mohor |
|
| 1584 |
|
|
// set address
|
| 1585 |
|
|
reg_addr = 5'h3;
|
| 1586 |
|
|
// read request
|
| 1587 |
|
|
#Tp mii_read_req(phy_addr, reg_addr);
|
| 1588 |
|
|
check_mii_busy; // wait for read to finish
|
| 1589 |
|
|
// read data
|
| 1590 |
274 |
tadejm |
wbm_read(`ETH_MIIRX_DATA, phy_data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 1591 |
181 |
mohor |
if (phy_data !== {`PHY_ID2, `MAN_MODEL_NUM, `MAN_REVISION_NUM})
|
| 1592 |
|
|
begin
|
| 1593 |
|
|
test_fail("Wrong data was read from PHY from ID register 2");
|
| 1594 |
|
|
fail = fail + 1;
|
| 1595 |
|
|
end
|
| 1596 |
|
|
if(fail == 0)
|
| 1597 |
|
|
test_ok;
|
| 1598 |
|
|
else
|
| 1599 |
|
|
fail = 0;
|
| 1600 |
169 |
mohor |
end
|
| 1601 |
116 |
mohor |
|
| 1602 |
|
|
|
| 1603 |
181 |
mohor |
////////////////////////////////////////////////////////////////////
|
| 1604 |
|
|
//// ////
|
| 1605 |
|
|
//// Test various writings to 'real' phy registers (control ////
|
| 1606 |
|
|
//// and non writable registers) ////
|
| 1607 |
|
|
//// ////
|
| 1608 |
|
|
////////////////////////////////////////////////////////////////////
|
| 1609 |
|
|
if (test_num == 2) //
|
| 1610 |
169 |
mohor |
begin
|
| 1611 |
194 |
tadej |
// TEST 2: VARIOUS WRITINGS TO 'REAL' PHY REGISTERS ( CONTROL AND NON WRITABLE REGISTERS )
|
| 1612 |
|
|
test_name = "TEST 2: VARIOUS WRITINGS TO 'REAL' PHY REGISTERS ( CONTROL AND NON WRITABLE REGISTERS )";
|
| 1613 |
|
|
`TIME; $display(" TEST 2: VARIOUS WRITINGS TO 'REAL' PHY REGISTERS ( CONTROL AND NON WRITABLE REGISTERS )");
|
| 1614 |
181 |
mohor |
|
| 1615 |
|
|
// negate data and try to write into unwritable register
|
| 1616 |
|
|
tmp_data = ~phy_data;
|
| 1617 |
|
|
// write request
|
| 1618 |
|
|
#Tp mii_write_req(phy_addr, reg_addr, tmp_data);
|
| 1619 |
|
|
check_mii_busy; // wait for write to finish
|
| 1620 |
169 |
mohor |
// read request
|
| 1621 |
|
|
#Tp mii_read_req(phy_addr, reg_addr);
|
| 1622 |
|
|
check_mii_busy; // wait for read to finish
|
| 1623 |
|
|
// read data
|
| 1624 |
274 |
tadejm |
wbm_read(`ETH_MIIRX_DATA, tmp_data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 1625 |
181 |
mohor |
if (tmp_data !== phy_data)
|
| 1626 |
|
|
begin
|
| 1627 |
|
|
test_fail("Data was written into unwritable PHY register - ID register 2");
|
| 1628 |
|
|
fail = fail + 1;
|
| 1629 |
|
|
end
|
| 1630 |
|
|
|
| 1631 |
|
|
// set address
|
| 1632 |
|
|
reg_addr = 5'h0; // control register
|
| 1633 |
|
|
// read request
|
| 1634 |
|
|
#Tp mii_read_req(phy_addr, reg_addr);
|
| 1635 |
|
|
check_mii_busy; // wait for read to finish
|
| 1636 |
|
|
// read data
|
| 1637 |
274 |
tadejm |
wbm_read(`ETH_MIIRX_DATA, tmp_data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 1638 |
181 |
mohor |
// write request
|
| 1639 |
|
|
phy_data = 16'h7DFF; // bit 15 (RESET bit) and bit 9 are self clearing bits
|
| 1640 |
|
|
#Tp mii_write_req(phy_addr, reg_addr, phy_data);
|
| 1641 |
|
|
check_mii_busy; // wait for write to finish
|
| 1642 |
|
|
// read request
|
| 1643 |
|
|
#Tp mii_read_req(phy_addr, reg_addr);
|
| 1644 |
|
|
check_mii_busy; // wait for read to finish
|
| 1645 |
|
|
// read data
|
| 1646 |
274 |
tadejm |
wbm_read(`ETH_MIIRX_DATA, phy_data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 1647 |
181 |
mohor |
if (phy_data !== 16'h7DFF)
|
| 1648 |
169 |
mohor |
begin
|
| 1649 |
181 |
mohor |
test_fail("Data was not correctly written into OR read from writable PHY register - control register");
|
| 1650 |
169 |
mohor |
fail = fail + 1;
|
| 1651 |
|
|
end
|
| 1652 |
181 |
mohor |
// write request
|
| 1653 |
|
|
#Tp mii_write_req(phy_addr, reg_addr, tmp_data);
|
| 1654 |
|
|
check_mii_busy; // wait for write to finish
|
| 1655 |
|
|
// read request
|
| 1656 |
|
|
#Tp mii_read_req(phy_addr, reg_addr);
|
| 1657 |
|
|
check_mii_busy; // wait for read to finish
|
| 1658 |
|
|
// read data
|
| 1659 |
274 |
tadejm |
wbm_read(`ETH_MIIRX_DATA, phy_data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 1660 |
181 |
mohor |
if (phy_data !== tmp_data)
|
| 1661 |
|
|
begin
|
| 1662 |
|
|
test_fail("Data was not correctly written into OR read from writable PHY register - control register");
|
| 1663 |
|
|
fail = fail + 1;
|
| 1664 |
|
|
end
|
| 1665 |
|
|
if(fail == 0)
|
| 1666 |
|
|
test_ok;
|
| 1667 |
116 |
mohor |
else
|
| 1668 |
181 |
mohor |
fail = 0;
|
| 1669 |
169 |
mohor |
end
|
| 1670 |
116 |
mohor |
|
| 1671 |
|
|
|
| 1672 |
181 |
mohor |
////////////////////////////////////////////////////////////////////
|
| 1673 |
|
|
//// ////
|
| 1674 |
|
|
//// Test reset phy through mii management module ////
|
| 1675 |
|
|
//// ////
|
| 1676 |
|
|
////////////////////////////////////////////////////////////////////
|
| 1677 |
|
|
if (test_num == 3) //
|
| 1678 |
169 |
mohor |
begin
|
| 1679 |
194 |
tadej |
// TEST 3: RESET PHY THROUGH MII MANAGEMENT MODULE
|
| 1680 |
|
|
test_name = "TEST 3: RESET PHY THROUGH MII MANAGEMENT MODULE";
|
| 1681 |
|
|
`TIME; $display(" TEST 3: RESET PHY THROUGH MII MANAGEMENT MODULE");
|
| 1682 |
181 |
mohor |
|
| 1683 |
|
|
// set address
|
| 1684 |
|
|
reg_addr = 5'h0; // control register
|
| 1685 |
|
|
// write request
|
| 1686 |
|
|
phy_data = 16'h7DFF; // bit 15 (RESET bit) and bit 9 are self clearing bits
|
| 1687 |
|
|
#Tp mii_write_req(phy_addr, reg_addr, phy_data);
|
| 1688 |
|
|
check_mii_busy; // wait for write to finish
|
| 1689 |
|
|
// read request
|
| 1690 |
|
|
#Tp mii_read_req(phy_addr, reg_addr);
|
| 1691 |
|
|
check_mii_busy; // wait for read to finish
|
| 1692 |
|
|
// read data
|
| 1693 |
274 |
tadejm |
wbm_read(`ETH_MIIRX_DATA, tmp_data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 1694 |
181 |
mohor |
if (phy_data !== tmp_data)
|
| 1695 |
|
|
begin
|
| 1696 |
|
|
test_fail("Data was not correctly written into OR read from writable PHY register - control register");
|
| 1697 |
|
|
fail = fail + 1;
|
| 1698 |
|
|
end
|
| 1699 |
|
|
// set reset bit - selfclearing bit in PHY
|
| 1700 |
|
|
phy_data = phy_data | 16'h8000;
|
| 1701 |
|
|
// write request
|
| 1702 |
|
|
#Tp mii_write_req(phy_addr, reg_addr, phy_data);
|
| 1703 |
|
|
check_mii_busy; // wait for write to finish
|
| 1704 |
|
|
// read request
|
| 1705 |
|
|
#Tp mii_read_req(phy_addr, reg_addr);
|
| 1706 |
|
|
check_mii_busy; // wait for read to finish
|
| 1707 |
|
|
// read data
|
| 1708 |
274 |
tadejm |
wbm_read(`ETH_MIIRX_DATA, tmp_data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 1709 |
181 |
mohor |
// check self clearing of reset bit
|
| 1710 |
|
|
if (tmp_data[15] !== 1'b0)
|
| 1711 |
|
|
begin
|
| 1712 |
|
|
test_fail("Reset bit should be self cleared - control register");
|
| 1713 |
|
|
fail = fail + 1;
|
| 1714 |
|
|
end
|
| 1715 |
|
|
// check reset value of control register
|
| 1716 |
|
|
if (tmp_data !== {2'h0, (`LED_CFG1 || `LED_CFG2), `LED_CFG1, 3'h0, `LED_CFG3, 8'h0})
|
| 1717 |
|
|
begin
|
| 1718 |
|
|
test_fail("PHY was not reset correctly AND/OR reset bit not self cleared");
|
| 1719 |
|
|
fail = fail + 1;
|
| 1720 |
|
|
end
|
| 1721 |
|
|
if(fail == 0)
|
| 1722 |
|
|
test_ok;
|
| 1723 |
|
|
else
|
| 1724 |
|
|
fail = 0;
|
| 1725 |
169 |
mohor |
end
|
| 1726 |
|
|
|
| 1727 |
|
|
|
| 1728 |
181 |
mohor |
////////////////////////////////////////////////////////////////////
|
| 1729 |
|
|
//// ////
|
| 1730 |
|
|
//// Test 'walking one' across phy address (with and without ////
|
| 1731 |
|
|
//// preamble) ////
|
| 1732 |
|
|
//// ////
|
| 1733 |
|
|
////////////////////////////////////////////////////////////////////
|
| 1734 |
|
|
if (test_num == 4) //
|
| 1735 |
169 |
mohor |
begin
|
| 1736 |
194 |
tadej |
// TEST 4: 'WALKING ONE' ACROSS PHY ADDRESS ( WITH AND WITHOUT PREAMBLE )
|
| 1737 |
|
|
test_name = "TEST 4: 'WALKING ONE' ACROSS PHY ADDRESS ( WITH AND WITHOUT PREAMBLE )";
|
| 1738 |
|
|
`TIME; $display(" TEST 4: 'WALKING ONE' ACROSS PHY ADDRESS ( WITH AND WITHOUT PREAMBLE )");
|
| 1739 |
181 |
mohor |
|
| 1740 |
|
|
// set PHY to test mode
|
| 1741 |
|
|
#Tp eth_phy.test_regs(1); // set test registers (wholy writable registers) and respond to all PHY addresses
|
| 1742 |
|
|
for (i = 0; i <= 1; i = i + 1)
|
| 1743 |
169 |
mohor |
begin
|
| 1744 |
181 |
mohor |
#Tp eth_phy.preamble_suppresed(i);
|
| 1745 |
|
|
#Tp eth_phy.clear_test_regs;
|
| 1746 |
|
|
// MII mode register
|
| 1747 |
|
|
wbm_write(`ETH_MIIMODER, (`ETH_MIIMODER_NOPRE & {23'h0, i, 8'h0}), 4'hF, 1, wbm_init_waits,
|
| 1748 |
|
|
wbm_subseq_waits);
|
| 1749 |
|
|
// walk one across phy address
|
| 1750 |
|
|
for (phy_addr = 5'h1; phy_addr > 5'h0; phy_addr = phy_addr << 1)
|
| 1751 |
169 |
mohor |
begin
|
| 1752 |
181 |
mohor |
reg_addr = $random;
|
| 1753 |
|
|
tmp_data = $random;
|
| 1754 |
|
|
// write request
|
| 1755 |
|
|
#Tp mii_write_req(phy_addr, reg_addr, tmp_data);
|
| 1756 |
|
|
check_mii_busy; // wait for write to finish
|
| 1757 |
|
|
// read request
|
| 1758 |
|
|
#Tp mii_read_req(phy_addr, reg_addr);
|
| 1759 |
|
|
check_mii_busy; // wait for read to finish
|
| 1760 |
|
|
// read data
|
| 1761 |
274 |
tadejm |
wbm_read(`ETH_MIIRX_DATA, phy_data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 1762 |
181 |
mohor |
#Tp;
|
| 1763 |
|
|
if (phy_data !== tmp_data)
|
| 1764 |
|
|
begin
|
| 1765 |
|
|
if (i)
|
| 1766 |
|
|
test_fail("Data was not correctly written into OR read from test registers (without preamble)");
|
| 1767 |
|
|
else
|
| 1768 |
|
|
test_fail("Data was not correctly written into OR read from test registers (with preamble)");
|
| 1769 |
|
|
fail = fail + 1;
|
| 1770 |
|
|
end
|
| 1771 |
|
|
@(posedge wb_clk);
|
| 1772 |
|
|
#Tp;
|
| 1773 |
169 |
mohor |
end
|
| 1774 |
|
|
end
|
| 1775 |
181 |
mohor |
// set PHY to normal mode
|
| 1776 |
|
|
#Tp eth_phy.test_regs(0);
|
| 1777 |
|
|
#Tp eth_phy.preamble_suppresed(0);
|
| 1778 |
|
|
// MII mode register
|
| 1779 |
|
|
wbm_write(`ETH_MIIMODER, 32'h0, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 1780 |
|
|
if(fail == 0)
|
| 1781 |
|
|
test_ok;
|
| 1782 |
|
|
else
|
| 1783 |
|
|
fail = 0;
|
| 1784 |
169 |
mohor |
end
|
| 1785 |
|
|
|
| 1786 |
|
|
|
| 1787 |
181 |
mohor |
////////////////////////////////////////////////////////////////////
|
| 1788 |
|
|
//// ////
|
| 1789 |
|
|
//// Test 'walking one' across phy's register address (with ////
|
| 1790 |
|
|
//// and without preamble) ////
|
| 1791 |
|
|
//// ////
|
| 1792 |
|
|
////////////////////////////////////////////////////////////////////
|
| 1793 |
|
|
if (test_num == 5) //
|
| 1794 |
169 |
mohor |
begin
|
| 1795 |
194 |
tadej |
// TEST 5: 'WALKING ONE' ACROSS PHY'S REGISTER ADDRESS ( WITH AND WITHOUT PREAMBLE )
|
| 1796 |
|
|
test_name = "TEST 5: 'WALKING ONE' ACROSS PHY'S REGISTER ADDRESS ( WITH AND WITHOUT PREAMBLE )";
|
| 1797 |
|
|
`TIME; $display(" TEST 5: 'WALKING ONE' ACROSS PHY'S REGISTER ADDRESS ( WITH AND WITHOUT PREAMBLE )");
|
| 1798 |
181 |
mohor |
|
| 1799 |
|
|
// set PHY to test mode
|
| 1800 |
|
|
#Tp eth_phy.test_regs(1); // set test registers (wholy writable registers) and respond to all PHY addresses
|
| 1801 |
|
|
for (i = 0; i <= 1; i = i + 1)
|
| 1802 |
169 |
mohor |
begin
|
| 1803 |
181 |
mohor |
#Tp eth_phy.preamble_suppresed(i);
|
| 1804 |
|
|
#Tp eth_phy.clear_test_regs;
|
| 1805 |
|
|
// MII mode register
|
| 1806 |
|
|
wbm_write(`ETH_MIIMODER, (`ETH_MIIMODER_NOPRE & {23'h0, i, 8'h0}), 4'hF, 1, wbm_init_waits,
|
| 1807 |
|
|
wbm_subseq_waits);
|
| 1808 |
|
|
// walk one across reg address
|
| 1809 |
|
|
for (reg_addr = 5'h1; reg_addr > 5'h0; reg_addr = reg_addr << 1)
|
| 1810 |
169 |
mohor |
begin
|
| 1811 |
181 |
mohor |
phy_addr = $random;
|
| 1812 |
|
|
tmp_data = $random;
|
| 1813 |
|
|
// write request
|
| 1814 |
|
|
#Tp mii_write_req(phy_addr, reg_addr, tmp_data);
|
| 1815 |
|
|
check_mii_busy; // wait for write to finish
|
| 1816 |
|
|
// read request
|
| 1817 |
|
|
#Tp mii_read_req(phy_addr, reg_addr);
|
| 1818 |
|
|
check_mii_busy; // wait for read to finish
|
| 1819 |
|
|
// read data
|
| 1820 |
274 |
tadejm |
wbm_read(`ETH_MIIRX_DATA, phy_data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 1821 |
181 |
mohor |
#Tp;
|
| 1822 |
|
|
if (phy_data !== tmp_data)
|
| 1823 |
|
|
begin
|
| 1824 |
|
|
if (i)
|
| 1825 |
|
|
test_fail("Data was not correctly written into OR read from test registers (without preamble)");
|
| 1826 |
|
|
else
|
| 1827 |
|
|
test_fail("Data was not correctly written into OR read from test registers (with preamble)");
|
| 1828 |
|
|
fail = fail + 1;
|
| 1829 |
|
|
end
|
| 1830 |
|
|
@(posedge wb_clk);
|
| 1831 |
|
|
#Tp;
|
| 1832 |
169 |
mohor |
end
|
| 1833 |
|
|
end
|
| 1834 |
181 |
mohor |
// set PHY to normal mode
|
| 1835 |
|
|
#Tp eth_phy.test_regs(0);
|
| 1836 |
|
|
#Tp eth_phy.preamble_suppresed(0);
|
| 1837 |
|
|
// MII mode register
|
| 1838 |
|
|
wbm_write(`ETH_MIIMODER, 32'h0, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 1839 |
|
|
if(fail == 0)
|
| 1840 |
|
|
test_ok;
|
| 1841 |
|
|
else
|
| 1842 |
|
|
fail = 0;
|
| 1843 |
169 |
mohor |
end
|
| 1844 |
|
|
|
| 1845 |
|
|
|
| 1846 |
181 |
mohor |
////////////////////////////////////////////////////////////////////
|
| 1847 |
|
|
//// ////
|
| 1848 |
|
|
//// Test 'walking one' across phy's data (with and without ////
|
| 1849 |
|
|
//// preamble) ////
|
| 1850 |
|
|
//// ////
|
| 1851 |
|
|
////////////////////////////////////////////////////////////////////
|
| 1852 |
|
|
if (test_num == 6) //
|
| 1853 |
169 |
mohor |
begin
|
| 1854 |
194 |
tadej |
// TEST 6: 'WALKING ONE' ACROSS PHY'S DATA ( WITH AND WITHOUT PREAMBLE )
|
| 1855 |
|
|
test_name = "TEST 6: 'WALKING ONE' ACROSS PHY'S DATA ( WITH AND WITHOUT PREAMBLE )";
|
| 1856 |
|
|
`TIME; $display(" TEST 6: 'WALKING ONE' ACROSS PHY'S DATA ( WITH AND WITHOUT PREAMBLE )");
|
| 1857 |
181 |
mohor |
|
| 1858 |
|
|
// set PHY to test mode
|
| 1859 |
|
|
#Tp eth_phy.test_regs(1); // set test registers (wholy writable registers) and respond to all PHY addresses
|
| 1860 |
|
|
for (i = 0; i <= 1; i = i + 1)
|
| 1861 |
169 |
mohor |
begin
|
| 1862 |
181 |
mohor |
#Tp eth_phy.preamble_suppresed(i);
|
| 1863 |
|
|
#Tp eth_phy.clear_test_regs;
|
| 1864 |
|
|
// MII mode register
|
| 1865 |
|
|
wbm_write(`ETH_MIIMODER, (`ETH_MIIMODER_NOPRE & {23'h0, i, 8'h0}), 4'hF, 1, wbm_init_waits,
|
| 1866 |
|
|
wbm_subseq_waits);
|
| 1867 |
|
|
// walk one across data
|
| 1868 |
|
|
for (tmp_data = 16'h1; tmp_data > 16'h0; tmp_data = tmp_data << 1)
|
| 1869 |
169 |
mohor |
begin
|
| 1870 |
181 |
mohor |
phy_addr = $random;
|
| 1871 |
|
|
reg_addr = $random;
|
| 1872 |
|
|
// write request
|
| 1873 |
|
|
#Tp mii_write_req(phy_addr, reg_addr, tmp_data);
|
| 1874 |
|
|
check_mii_busy; // wait for write to finish
|
| 1875 |
|
|
// read request
|
| 1876 |
|
|
#Tp mii_read_req(phy_addr, reg_addr);
|
| 1877 |
|
|
check_mii_busy; // wait for read to finish
|
| 1878 |
|
|
// read data
|
| 1879 |
274 |
tadejm |
wbm_read(`ETH_MIIRX_DATA, phy_data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 1880 |
181 |
mohor |
#Tp;
|
| 1881 |
|
|
if (phy_data !== tmp_data)
|
| 1882 |
|
|
begin
|
| 1883 |
|
|
if (i)
|
| 1884 |
|
|
test_fail("Data was not correctly written into OR read from test registers (without preamble)");
|
| 1885 |
|
|
else
|
| 1886 |
|
|
test_fail("Data was not correctly written into OR read from test registers (with preamble)");
|
| 1887 |
|
|
fail = fail + 1;
|
| 1888 |
|
|
end
|
| 1889 |
|
|
@(posedge wb_clk);
|
| 1890 |
|
|
#Tp;
|
| 1891 |
169 |
mohor |
end
|
| 1892 |
|
|
end
|
| 1893 |
181 |
mohor |
// set PHY to normal mode
|
| 1894 |
|
|
#Tp eth_phy.test_regs(0);
|
| 1895 |
|
|
#Tp eth_phy.preamble_suppresed(0);
|
| 1896 |
|
|
// MII mode register
|
| 1897 |
|
|
wbm_write(`ETH_MIIMODER, 32'h0, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 1898 |
|
|
if(fail == 0)
|
| 1899 |
|
|
test_ok;
|
| 1900 |
|
|
else
|
| 1901 |
|
|
fail = 0;
|
| 1902 |
169 |
mohor |
end
|
| 1903 |
|
|
|
| 1904 |
|
|
|
| 1905 |
181 |
mohor |
////////////////////////////////////////////////////////////////////
|
| 1906 |
|
|
//// ////
|
| 1907 |
|
|
//// Test reading from phy with wrong phy address (host ////
|
| 1908 |
|
|
//// reading high 'z' data) ////
|
| 1909 |
|
|
//// ////
|
| 1910 |
|
|
////////////////////////////////////////////////////////////////////
|
| 1911 |
|
|
if (test_num == 7) //
|
| 1912 |
169 |
mohor |
begin
|
| 1913 |
194 |
tadej |
// TEST 7: READING FROM PHY WITH WRONG PHY ADDRESS ( HOST READING HIGH 'Z' DATA )
|
| 1914 |
|
|
test_name = "TEST 7: READING FROM PHY WITH WRONG PHY ADDRESS ( HOST READING HIGH 'Z' DATA )";
|
| 1915 |
|
|
`TIME; $display(" TEST 7: READING FROM PHY WITH WRONG PHY ADDRESS ( HOST READING HIGH 'Z' DATA )");
|
| 1916 |
181 |
mohor |
|
| 1917 |
|
|
phy_addr = 5'h2; // wrong PHY address
|
| 1918 |
|
|
// read request
|
| 1919 |
|
|
#Tp mii_read_req(phy_addr, reg_addr);
|
| 1920 |
|
|
check_mii_busy; // wait for read to finish
|
| 1921 |
|
|
// read data
|
| 1922 |
|
|
$display(" => Two errors will be displayed from WB Bus Monitor, because correct HIGH Z data was read");
|
| 1923 |
274 |
tadejm |
wbm_read(`ETH_MIIRX_DATA, tmp_data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 1924 |
181 |
mohor |
if (tmp_data !== 16'hzzzz)
|
| 1925 |
|
|
begin
|
| 1926 |
|
|
test_fail("Data was read from PHY register with wrong PHY address - control register");
|
| 1927 |
|
|
fail = fail + 1;
|
| 1928 |
|
|
end
|
| 1929 |
|
|
if(fail == 0)
|
| 1930 |
|
|
test_ok;
|
| 1931 |
|
|
else
|
| 1932 |
|
|
fail = 0;
|
| 1933 |
169 |
mohor |
end
|
| 1934 |
|
|
|
| 1935 |
|
|
|
| 1936 |
181 |
mohor |
////////////////////////////////////////////////////////////////////
|
| 1937 |
|
|
//// ////
|
| 1938 |
|
|
//// Test writing to phy with wrong phy address and reading ////
|
| 1939 |
|
|
//// from correct one ////
|
| 1940 |
|
|
//// ////
|
| 1941 |
|
|
////////////////////////////////////////////////////////////////////
|
| 1942 |
|
|
if (test_num == 8) //
|
| 1943 |
169 |
mohor |
begin
|
| 1944 |
194 |
tadej |
// TEST 8: WRITING TO PHY WITH WRONG PHY ADDRESS AND READING FROM CORRECT ONE
|
| 1945 |
|
|
test_name = "TEST 8: WRITING TO PHY WITH WRONG PHY ADDRESS AND READING FROM CORRECT ONE";
|
| 1946 |
|
|
`TIME; $display(" TEST 8: WRITING TO PHY WITH WRONG PHY ADDRESS AND READING FROM CORRECT ONE");
|
| 1947 |
181 |
mohor |
|
| 1948 |
|
|
// set address
|
| 1949 |
|
|
reg_addr = 5'h0; // control register
|
| 1950 |
|
|
phy_addr = 5'h2; // wrong PHY address
|
| 1951 |
|
|
// write request
|
| 1952 |
|
|
phy_data = 16'h7DFF; // bit 15 (RESET bit) and bit 9 are self clearing bits
|
| 1953 |
|
|
#Tp mii_write_req(phy_addr, reg_addr, phy_data);
|
| 1954 |
|
|
check_mii_busy; // wait for write to finish
|
| 1955 |
|
|
|
| 1956 |
|
|
phy_addr = 5'h1; // correct PHY address
|
| 1957 |
|
|
// read request
|
| 1958 |
|
|
#Tp mii_read_req(phy_addr, reg_addr);
|
| 1959 |
|
|
check_mii_busy; // wait for read to finish
|
| 1960 |
|
|
// read data
|
| 1961 |
274 |
tadejm |
wbm_read(`ETH_MIIRX_DATA, tmp_data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 1962 |
181 |
mohor |
if (phy_data === tmp_data)
|
| 1963 |
|
|
begin
|
| 1964 |
|
|
test_fail("Data was written into PHY register with wrong PHY address - control register");
|
| 1965 |
|
|
fail = fail + 1;
|
| 1966 |
|
|
end
|
| 1967 |
|
|
if(fail == 0)
|
| 1968 |
|
|
test_ok;
|
| 1969 |
|
|
else
|
| 1970 |
|
|
fail = 0;
|
| 1971 |
169 |
mohor |
end
|
| 1972 |
|
|
|
| 1973 |
|
|
|
| 1974 |
181 |
mohor |
////////////////////////////////////////////////////////////////////
|
| 1975 |
|
|
//// ////
|
| 1976 |
|
|
//// Test sliding stop scan command immediately after read ////
|
| 1977 |
|
|
//// request (with and without preamble) ////
|
| 1978 |
|
|
//// ////
|
| 1979 |
|
|
////////////////////////////////////////////////////////////////////
|
| 1980 |
|
|
if (test_num == 9) //
|
| 1981 |
169 |
mohor |
begin
|
| 1982 |
194 |
tadej |
// TEST 9: SLIDING STOP SCAN COMMAND IMMEDIATELY AFTER READ REQUEST ( WITH AND WITHOUT PREAMBLE )
|
| 1983 |
|
|
test_name = "TEST 9: SLIDING STOP SCAN COMMAND IMMEDIATELY AFTER READ REQUEST ( WITH AND WITHOUT PREAMBLE )";
|
| 1984 |
181 |
mohor |
`TIME;
|
| 1985 |
194 |
tadej |
$display(" TEST 9: SLIDING STOP SCAN COMMAND IMMEDIATELY AFTER READ REQUEST ( WITH AND WITHOUT PREAMBLE )");
|
| 1986 |
181 |
mohor |
|
| 1987 |
|
|
for (i2 = 0; i2 <= 1; i2 = i2 + 1) // choose preamble or not
|
| 1988 |
169 |
mohor |
begin
|
| 1989 |
181 |
mohor |
#Tp eth_phy.preamble_suppresed(i2);
|
| 1990 |
|
|
// MII mode register
|
| 1991 |
|
|
wbm_write(`ETH_MIIMODER, (`ETH_MIIMODER_NOPRE & {23'h0, i2, 8'h0}), 4'hF, 1, wbm_init_waits,
|
| 1992 |
|
|
wbm_subseq_waits);
|
| 1993 |
|
|
i = 0;
|
| 1994 |
|
|
cnt = 0;
|
| 1995 |
|
|
while (i < 80) // delay for sliding of writing a STOP SCAN command
|
| 1996 |
169 |
mohor |
begin
|
| 1997 |
181 |
mohor |
for (i3 = 0; i3 <= 1; i3 = i3 + 1) // choose read or write after read will be finished
|
| 1998 |
|
|
begin
|
| 1999 |
|
|
// set address
|
| 2000 |
|
|
reg_addr = 5'h0; // control register
|
| 2001 |
|
|
phy_addr = 5'h1; // correct PHY address
|
| 2002 |
|
|
cnt = 0;
|
| 2003 |
|
|
// read request
|
| 2004 |
|
|
#Tp mii_read_req(phy_addr, reg_addr);
|
| 2005 |
|
|
fork
|
| 2006 |
|
|
begin
|
| 2007 |
|
|
repeat(i) @(posedge Mdc_O);
|
| 2008 |
|
|
// write command 0x0 into MII command register
|
| 2009 |
|
|
// MII command written while read in progress
|
| 2010 |
|
|
wbm_write(`ETH_MIICOMMAND, 32'h0, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 2011 |
|
|
@(posedge wb_clk);
|
| 2012 |
|
|
#Tp check_mii_busy; // wait for read to finish
|
| 2013 |
|
|
end
|
| 2014 |
|
|
begin
|
| 2015 |
|
|
// wait for serial bus to become active
|
| 2016 |
|
|
wait(Mdio_IO !== 1'bz);
|
| 2017 |
|
|
// count transfer length
|
| 2018 |
|
|
while( (Mdio_IO !== 1'bz) || ((cnt == 47) && (i2 == 0)) || ((cnt == 15) && (i2 == 1)) )
|
| 2019 |
|
|
begin
|
| 2020 |
|
|
@(posedge Mdc_O);
|
| 2021 |
|
|
#Tp cnt = cnt + 1;
|
| 2022 |
|
|
end
|
| 2023 |
|
|
end
|
| 2024 |
|
|
join
|
| 2025 |
|
|
// check transfer length
|
| 2026 |
|
|
if (i2) // without preamble
|
| 2027 |
169 |
mohor |
begin
|
| 2028 |
181 |
mohor |
if (cnt != 33) // at this value Mdio_IO is HIGH Z
|
| 2029 |
|
|
begin
|
| 2030 |
|
|
test_fail("Read request did not proceed correctly, while SCAN STOP command was written");
|
| 2031 |
|
|
fail = fail + 1;
|
| 2032 |
|
|
end
|
| 2033 |
169 |
mohor |
end
|
| 2034 |
181 |
mohor |
else // with preamble
|
| 2035 |
169 |
mohor |
begin
|
| 2036 |
181 |
mohor |
if (cnt != 65) // at this value Mdio_IO is HIGH Z
|
| 2037 |
|
|
begin
|
| 2038 |
|
|
test_fail("Read request did not proceed correctly, while SCAN STOP command was written");
|
| 2039 |
|
|
fail = fail + 1;
|
| 2040 |
|
|
end
|
| 2041 |
|
|
end
|
| 2042 |
|
|
// check the BUSY signal to see if the bus is still IDLE
|
| 2043 |
|
|
for (i1 = 0; i1 < 8; i1 = i1 + 1)
|
| 2044 |
|
|
check_mii_busy; // wait for bus to become idle
|
| 2045 |
|
|
|
| 2046 |
|
|
// try normal write or read after read was finished
|
| 2047 |
|
|
#Tp phy_data = {8'h7D, (i[7:0] + 1)};
|
| 2048 |
|
|
#Tp cnt = 0;
|
| 2049 |
|
|
if (i3 == 0) // write after read
|
| 2050 |
|
|
begin
|
| 2051 |
|
|
// write request
|
| 2052 |
|
|
#Tp mii_write_req(phy_addr, reg_addr, phy_data);
|
| 2053 |
169 |
mohor |
// wait for serial bus to become active
|
| 2054 |
|
|
wait(Mdio_IO !== 1'bz);
|
| 2055 |
|
|
// count transfer length
|
| 2056 |
181 |
mohor |
while(Mdio_IO !== 1'bz)
|
| 2057 |
169 |
mohor |
begin
|
| 2058 |
|
|
@(posedge Mdc_O);
|
| 2059 |
|
|
#Tp cnt = cnt + 1;
|
| 2060 |
|
|
end
|
| 2061 |
181 |
mohor |
@(posedge Mdc_O);
|
| 2062 |
|
|
// read request
|
| 2063 |
|
|
#Tp mii_read_req(phy_addr, reg_addr);
|
| 2064 |
|
|
check_mii_busy; // wait for read to finish
|
| 2065 |
|
|
// read and check data
|
| 2066 |
274 |
tadejm |
wbm_read(`ETH_MIIRX_DATA, tmp_data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 2067 |
181 |
mohor |
if (phy_data !== tmp_data)
|
| 2068 |
|
|
begin
|
| 2069 |
|
|
test_fail("Data was not correctly written into OR read from PHY register - control register");
|
| 2070 |
|
|
fail = fail + 1;
|
| 2071 |
|
|
end
|
| 2072 |
169 |
mohor |
end
|
| 2073 |
181 |
mohor |
else // read after read
|
| 2074 |
169 |
mohor |
begin
|
| 2075 |
181 |
mohor |
// read request
|
| 2076 |
|
|
#Tp mii_read_req(phy_addr, reg_addr);
|
| 2077 |
|
|
// wait for serial bus to become active
|
| 2078 |
|
|
wait(Mdio_IO !== 1'bz);
|
| 2079 |
|
|
// count transfer length
|
| 2080 |
|
|
while( (Mdio_IO !== 1'bz) || ((cnt == 47) && (i2 == 0)) || ((cnt == 15) && (i2 == 1)) )
|
| 2081 |
|
|
begin
|
| 2082 |
|
|
@(posedge Mdc_O);
|
| 2083 |
|
|
#Tp cnt = cnt + 1;
|
| 2084 |
|
|
end
|
| 2085 |
169 |
mohor |
@(posedge Mdc_O);
|
| 2086 |
181 |
mohor |
check_mii_busy; // wait for read to finish
|
| 2087 |
|
|
// read and check data
|
| 2088 |
274 |
tadejm |
wbm_read(`ETH_MIIRX_DATA, tmp_data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 2089 |
181 |
mohor |
if (phy_data !== tmp_data)
|
| 2090 |
|
|
begin
|
| 2091 |
|
|
test_fail("Data was not correctly written into OR read from PHY register - control register");
|
| 2092 |
|
|
fail = fail + 1;
|
| 2093 |
|
|
end
|
| 2094 |
169 |
mohor |
end
|
| 2095 |
181 |
mohor |
// check if transfer was a proper length
|
| 2096 |
|
|
if (i2) // without preamble
|
| 2097 |
169 |
mohor |
begin
|
| 2098 |
181 |
mohor |
if (cnt != 33) // at this value Mdio_IO is HIGH Z
|
| 2099 |
|
|
begin
|
| 2100 |
|
|
test_fail("New request did not proceed correctly, after read request");
|
| 2101 |
|
|
fail = fail + 1;
|
| 2102 |
|
|
end
|
| 2103 |
169 |
mohor |
end
|
| 2104 |
181 |
mohor |
else // with preamble
|
| 2105 |
169 |
mohor |
begin
|
| 2106 |
181 |
mohor |
if (cnt != 65) // at this value Mdio_IO is HIGH Z
|
| 2107 |
|
|
begin
|
| 2108 |
|
|
test_fail("New request did not proceed correctly, after read request");
|
| 2109 |
|
|
fail = fail + 1;
|
| 2110 |
|
|
end
|
| 2111 |
169 |
mohor |
end
|
| 2112 |
|
|
end
|
| 2113 |
181 |
mohor |
#Tp;
|
| 2114 |
|
|
// set delay of writing the command
|
| 2115 |
169 |
mohor |
if (i2) // without preamble
|
| 2116 |
|
|
begin
|
| 2117 |
181 |
mohor |
case(i)
|
| 2118 |
|
|
0, 1: i = i + 1;
|
| 2119 |
|
|
18, 19, 20, 21, 22,
|
| 2120 |
|
|
23, 24, 25, 26, 27,
|
| 2121 |
|
|
28, 29, 30, 31, 32,
|
| 2122 |
|
|
33, 34, 35: i = i + 1;
|
| 2123 |
|
|
36: i = 80;
|
| 2124 |
|
|
default: i = 18;
|
| 2125 |
|
|
endcase
|
| 2126 |
169 |
mohor |
end
|
| 2127 |
|
|
else // with preamble
|
| 2128 |
|
|
begin
|
| 2129 |
181 |
mohor |
case(i)
|
| 2130 |
|
|
0, 1: i = i + 1;
|
| 2131 |
|
|
50, 51, 52, 53, 54,
|
| 2132 |
|
|
55, 56, 57, 58, 59,
|
| 2133 |
|
|
60, 61, 62, 63, 64,
|
| 2134 |
|
|
65, 66, 67: i = i + 1;
|
| 2135 |
|
|
68: i = 80;
|
| 2136 |
|
|
default: i = 50;
|
| 2137 |
|
|
endcase
|
| 2138 |
169 |
mohor |
end
|
| 2139 |
181 |
mohor |
@(posedge wb_clk);
|
| 2140 |
169 |
mohor |
end
|
| 2141 |
|
|
end
|
| 2142 |
181 |
mohor |
// set PHY to normal mode
|
| 2143 |
|
|
#Tp eth_phy.preamble_suppresed(0);
|
| 2144 |
|
|
// MII mode register
|
| 2145 |
|
|
wbm_write(`ETH_MIIMODER, 32'h0, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 2146 |
|
|
if(fail == 0)
|
| 2147 |
|
|
test_ok;
|
| 2148 |
|
|
else
|
| 2149 |
|
|
fail = 0;
|
| 2150 |
169 |
mohor |
end
|
| 2151 |
|
|
|
| 2152 |
|
|
|
| 2153 |
181 |
mohor |
////////////////////////////////////////////////////////////////////
|
| 2154 |
|
|
//// ////
|
| 2155 |
|
|
//// Test sliding stop scan command immediately after write ////
|
| 2156 |
|
|
//// request (with and without preamble) ////
|
| 2157 |
|
|
//// ////
|
| 2158 |
|
|
////////////////////////////////////////////////////////////////////
|
| 2159 |
|
|
if (test_num == 10) //
|
| 2160 |
169 |
mohor |
begin
|
| 2161 |
194 |
tadej |
// TEST 10: SLIDING STOP SCAN COMMAND IMMEDIATELY AFTER WRITE REQUEST ( WITH AND WITHOUT PREAMBLE )
|
| 2162 |
|
|
test_name = "TEST 10: SLIDING STOP SCAN COMMAND IMMEDIATELY AFTER WRITE REQUEST ( WITH AND WITHOUT PREAMBLE )";
|
| 2163 |
181 |
mohor |
`TIME;
|
| 2164 |
194 |
tadej |
$display(" TEST 10: SLIDING STOP SCAN COMMAND IMMEDIATELY AFTER WRITE REQUEST ( WITH AND WITHOUT PREAMBLE )");
|
| 2165 |
181 |
mohor |
|
| 2166 |
|
|
for (i2 = 0; i2 <= 1; i2 = i2 + 1) // choose preamble or not
|
| 2167 |
169 |
mohor |
begin
|
| 2168 |
181 |
mohor |
#Tp eth_phy.preamble_suppresed(i2);
|
| 2169 |
|
|
// MII mode register
|
| 2170 |
|
|
wbm_write(`ETH_MIIMODER, (`ETH_MIIMODER_NOPRE & {23'h0, i2, 8'h0}), 4'hF, 1, wbm_init_waits,
|
| 2171 |
|
|
wbm_subseq_waits);
|
| 2172 |
|
|
i = 0;
|
| 2173 |
|
|
cnt = 0;
|
| 2174 |
|
|
while (i < 80) // delay for sliding of writing a STOP SCAN command
|
| 2175 |
169 |
mohor |
begin
|
| 2176 |
181 |
mohor |
for (i3 = 0; i3 <= 1; i3 = i3 + 1) // choose read or write after write will be finished
|
| 2177 |
|
|
begin
|
| 2178 |
|
|
// set address
|
| 2179 |
|
|
reg_addr = 5'h0; // control register
|
| 2180 |
|
|
phy_addr = 5'h1; // correct PHY address
|
| 2181 |
|
|
cnt = 0;
|
| 2182 |
|
|
// write request
|
| 2183 |
|
|
phy_data = {8'h75, (i[7:0] + 1)};
|
| 2184 |
|
|
#Tp mii_write_req(phy_addr, reg_addr, phy_data);
|
| 2185 |
|
|
fork
|
| 2186 |
|
|
begin
|
| 2187 |
|
|
repeat(i) @(posedge Mdc_O);
|
| 2188 |
|
|
// write command 0x0 into MII command register
|
| 2189 |
|
|
// MII command written while read in progress
|
| 2190 |
|
|
wbm_write(`ETH_MIICOMMAND, 32'h0, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 2191 |
|
|
@(posedge wb_clk);
|
| 2192 |
|
|
#Tp check_mii_busy; // wait for write to finish
|
| 2193 |
|
|
end
|
| 2194 |
|
|
begin
|
| 2195 |
|
|
// wait for serial bus to become active
|
| 2196 |
|
|
wait(Mdio_IO !== 1'bz);
|
| 2197 |
|
|
// count transfer length
|
| 2198 |
|
|
while(Mdio_IO !== 1'bz)
|
| 2199 |
|
|
begin
|
| 2200 |
|
|
@(posedge Mdc_O);
|
| 2201 |
|
|
#Tp cnt = cnt + 1;
|
| 2202 |
|
|
end
|
| 2203 |
|
|
end
|
| 2204 |
|
|
join
|
| 2205 |
|
|
// check transfer length
|
| 2206 |
|
|
if (i2) // without preamble
|
| 2207 |
169 |
mohor |
begin
|
| 2208 |
181 |
mohor |
if (cnt != 33) // at this value Mdio_IO is HIGH Z
|
| 2209 |
|
|
begin
|
| 2210 |
|
|
test_fail("Write request did not proceed correctly, while SCAN STOP command was written");
|
| 2211 |
|
|
fail = fail + 1;
|
| 2212 |
|
|
end
|
| 2213 |
169 |
mohor |
end
|
| 2214 |
181 |
mohor |
else // with preamble
|
| 2215 |
169 |
mohor |
begin
|
| 2216 |
181 |
mohor |
if (cnt != 65) // at this value Mdio_IO is HIGH Z
|
| 2217 |
|
|
begin
|
| 2218 |
|
|
test_fail("Write request did not proceed correctly, while SCAN STOP command was written");
|
| 2219 |
|
|
fail = fail + 1;
|
| 2220 |
|
|
end
|
| 2221 |
|
|
end
|
| 2222 |
|
|
// check the BUSY signal to see if the bus is still IDLE
|
| 2223 |
|
|
for (i1 = 0; i1 < 8; i1 = i1 + 1)
|
| 2224 |
|
|
check_mii_busy; // wait for bus to become idle
|
| 2225 |
|
|
|
| 2226 |
|
|
// try normal write or read after write was finished
|
| 2227 |
|
|
#Tp cnt = 0;
|
| 2228 |
|
|
if (i3 == 0) // write after write
|
| 2229 |
|
|
begin
|
| 2230 |
|
|
phy_data = {8'h7A, (i[7:0] + 1)};
|
| 2231 |
|
|
// write request
|
| 2232 |
|
|
#Tp mii_write_req(phy_addr, reg_addr, phy_data);
|
| 2233 |
169 |
mohor |
// wait for serial bus to become active
|
| 2234 |
|
|
wait(Mdio_IO !== 1'bz);
|
| 2235 |
|
|
// count transfer length
|
| 2236 |
|
|
while(Mdio_IO !== 1'bz)
|
| 2237 |
|
|
begin
|
| 2238 |
|
|
@(posedge Mdc_O);
|
| 2239 |
|
|
#Tp cnt = cnt + 1;
|
| 2240 |
|
|
end
|
| 2241 |
181 |
mohor |
@(posedge Mdc_O);
|
| 2242 |
|
|
// read request
|
| 2243 |
|
|
#Tp mii_read_req(phy_addr, reg_addr);
|
| 2244 |
|
|
check_mii_busy; // wait for read to finish
|
| 2245 |
|
|
// read and check data
|
| 2246 |
274 |
tadejm |
wbm_read(`ETH_MIIRX_DATA, tmp_data , 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 2247 |
181 |
mohor |
if (phy_data !== tmp_data)
|
| 2248 |
|
|
begin
|
| 2249 |
|
|
test_fail("Data was not correctly written into OR read from PHY register - control register");
|
| 2250 |
|
|
fail = fail + 1;
|
| 2251 |
|
|
end
|
| 2252 |
169 |
mohor |
end
|
| 2253 |
181 |
mohor |
else // read after write
|
| 2254 |
169 |
mohor |
begin
|
| 2255 |
181 |
mohor |
// read request
|
| 2256 |
|
|
#Tp mii_read_req(phy_addr, reg_addr);
|
| 2257 |
|
|
// wait for serial bus to become active
|
| 2258 |
|
|
wait(Mdio_IO !== 1'bz);
|
| 2259 |
|
|
// count transfer length
|
| 2260 |
|
|
while( (Mdio_IO !== 1'bz) || ((cnt == 47) && (i2 == 0)) || ((cnt == 15) && (i2 == 1)) )
|
| 2261 |
|
|
begin
|
| 2262 |
|
|
@(posedge Mdc_O);
|
| 2263 |
|
|
#Tp cnt = cnt + 1;
|
| 2264 |
|
|
end
|
| 2265 |
169 |
mohor |
@(posedge Mdc_O);
|
| 2266 |
181 |
mohor |
check_mii_busy; // wait for read to finish
|
| 2267 |
|
|
// read and check data
|
| 2268 |
274 |
tadejm |
wbm_read(`ETH_MIIRX_DATA, tmp_data , 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 2269 |
181 |
mohor |
if (phy_data !== tmp_data)
|
| 2270 |
|
|
begin
|
| 2271 |
|
|
test_fail("Data was not correctly written into OR read from PHY register - control register");
|
| 2272 |
|
|
fail = fail + 1;
|
| 2273 |
|
|
end
|
| 2274 |
169 |
mohor |
end
|
| 2275 |
181 |
mohor |
// check if transfer was a proper length
|
| 2276 |
|
|
if (i2) // without preamble
|
| 2277 |
169 |
mohor |
begin
|
| 2278 |
181 |
mohor |
if (cnt != 33) // at this value Mdio_IO is HIGH Z
|
| 2279 |
|
|
begin
|
| 2280 |
|
|
test_fail("New request did not proceed correctly, after write request");
|
| 2281 |
|
|
fail = fail + 1;
|
| 2282 |
|
|
end
|
| 2283 |
169 |
mohor |
end
|
| 2284 |
181 |
mohor |
else // with preamble
|
| 2285 |
169 |
mohor |
begin
|
| 2286 |
181 |
mohor |
if (cnt != 65) // at this value Mdio_IO is HIGH Z
|
| 2287 |
|
|
begin
|
| 2288 |
|
|
test_fail("New request did not proceed correctly, after write request");
|
| 2289 |
|
|
fail = fail + 1;
|
| 2290 |
|
|
end
|
| 2291 |
169 |
mohor |
end
|
| 2292 |
|
|
end
|
| 2293 |
181 |
mohor |
#Tp;
|
| 2294 |
|
|
// set delay of writing the command
|
| 2295 |
169 |
mohor |
if (i2) // without preamble
|
| 2296 |
|
|
begin
|
| 2297 |
181 |
mohor |
case(i)
|
| 2298 |
|
|
0, 1: i = i + 1;
|
| 2299 |
|
|
18, 19, 20, 21, 22,
|
| 2300 |
|
|
23, 24, 25, 26, 27,
|
| 2301 |
|
|
28, 29, 30, 31, 32,
|
| 2302 |
|
|
33, 34, 35: i = i + 1;
|
| 2303 |
|
|
36: i = 80;
|
| 2304 |
|
|
default: i = 18;
|
| 2305 |
|
|
endcase
|
| 2306 |
169 |
mohor |
end
|
| 2307 |
|
|
else // with preamble
|
| 2308 |
|
|
begin
|
| 2309 |
181 |
mohor |
case(i)
|
| 2310 |
|
|
0, 1: i = i + 1;
|
| 2311 |
|
|
50, 51, 52, 53, 54,
|
| 2312 |
|
|
55, 56, 57, 58, 59,
|
| 2313 |
|
|
60, 61, 62, 63, 64,
|
| 2314 |
|
|
65, 66, 67: i = i + 1;
|
| 2315 |
|
|
68: i = 80;
|
| 2316 |
|
|
default: i = 50;
|
| 2317 |
|
|
endcase
|
| 2318 |
169 |
mohor |
end
|
| 2319 |
181 |
mohor |
@(posedge wb_clk);
|
| 2320 |
169 |
mohor |
end
|
| 2321 |
|
|
end
|
| 2322 |
181 |
mohor |
// set PHY to normal mode
|
| 2323 |
|
|
#Tp eth_phy.preamble_suppresed(0);
|
| 2324 |
|
|
// MII mode register
|
| 2325 |
|
|
wbm_write(`ETH_MIIMODER, 32'h0, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 2326 |
|
|
if(fail == 0)
|
| 2327 |
|
|
test_ok;
|
| 2328 |
|
|
else
|
| 2329 |
|
|
fail = 0;
|
| 2330 |
169 |
mohor |
end
|
| 2331 |
|
|
|
| 2332 |
|
|
|
| 2333 |
181 |
mohor |
////////////////////////////////////////////////////////////////////
|
| 2334 |
|
|
//// ////
|
| 2335 |
|
|
//// Test busy and nvalid status durations during write (with ////
|
| 2336 |
|
|
//// and without preamble) ////
|
| 2337 |
|
|
//// ////
|
| 2338 |
|
|
////////////////////////////////////////////////////////////////////
|
| 2339 |
|
|
if (test_num == 11) //
|
| 2340 |
169 |
mohor |
begin
|
| 2341 |
194 |
tadej |
// TEST 11: BUSY AND NVALID STATUS DURATIONS DURING WRITE ( WITH AND WITHOUT PREAMBLE )
|
| 2342 |
|
|
test_name = "TEST 11: BUSY AND NVALID STATUS DURATIONS DURING WRITE ( WITH AND WITHOUT PREAMBLE )";
|
| 2343 |
|
|
`TIME; $display(" TEST 11: BUSY AND NVALID STATUS DURATIONS DURING WRITE ( WITH AND WITHOUT PREAMBLE )");
|
| 2344 |
181 |
mohor |
|
| 2345 |
|
|
reset_mii; // reset MII
|
| 2346 |
|
|
// set link up, if it wasn't due to previous tests, since there weren't PHY registers
|
| 2347 |
|
|
#Tp eth_phy.link_up_down(1);
|
| 2348 |
|
|
// set the MII
|
| 2349 |
|
|
clk_div = 64;
|
| 2350 |
|
|
mii_set_clk_div(clk_div[7:0]);
|
| 2351 |
|
|
// set address
|
| 2352 |
|
|
reg_addr = 5'h1; // status register
|
| 2353 |
|
|
phy_addr = 5'h1; // correct PHY address
|
| 2354 |
|
|
|
| 2355 |
|
|
for (i = 0; i <= 1; i = i + 1)
|
| 2356 |
169 |
mohor |
begin
|
| 2357 |
181 |
mohor |
#Tp eth_phy.preamble_suppresed(i);
|
| 2358 |
|
|
// MII mode register
|
| 2359 |
|
|
wbm_write(`ETH_MIIMODER, (`ETH_MIIMODER_NOPRE & {23'h0, i, 8'h0}) | (`ETH_MIIMODER_CLKDIV & clk_div),
|
| 2360 |
|
|
4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 2361 |
|
|
@(posedge Mdc_O);
|
| 2362 |
|
|
// write request
|
| 2363 |
|
|
#Tp mii_write_req(phy_addr, reg_addr, 16'h5A5A);
|
| 2364 |
|
|
// read data from MII status register - Busy and Nvalid bits
|
| 2365 |
274 |
tadejm |
wbm_read(`ETH_MIISTATUS, phy_data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 2366 |
181 |
mohor |
|
| 2367 |
|
|
// check MII IO signal and Busy and Nvalid bits
|
| 2368 |
|
|
if (Mdio_IO !== 1'bz) // Mdio_IO should be HIGH Z here - testbench selfcheck
|
| 2369 |
169 |
mohor |
begin
|
| 2370 |
181 |
mohor |
test_fail("Testbench error - read was to late, Mdio_IO is not HIGH Z - set higher clock divider");
|
| 2371 |
|
|
if (phy_data[`ETH_MIISTATUS_BUSY] === 1'b0)
|
| 2372 |
|
|
begin
|
| 2373 |
|
|
test_fail("Busy signal was not set while MII IO signal is not HIGH Z anymore - 1. read");
|
| 2374 |
|
|
fail = fail + 1;
|
| 2375 |
|
|
end
|
| 2376 |
|
|
if (phy_data[`ETH_MIISTATUS_NVALID] !== 1'b0)
|
| 2377 |
|
|
begin
|
| 2378 |
|
|
test_fail("Nvalid signal was set during write");
|
| 2379 |
|
|
fail = fail + 1;
|
| 2380 |
|
|
end
|
| 2381 |
169 |
mohor |
end
|
| 2382 |
181 |
mohor |
else // Busy bit should already be set to '1', due to reads from MII status register
|
| 2383 |
169 |
mohor |
begin
|
| 2384 |
181 |
mohor |
if (phy_data[`ETH_MIISTATUS_BUSY] === 1'b0)
|
| 2385 |
|
|
begin
|
| 2386 |
|
|
test_fail("Busy signal should be set after write, due to reads from MII status register");
|
| 2387 |
|
|
fail = fail + 1;
|
| 2388 |
|
|
end
|
| 2389 |
|
|
if (phy_data[`ETH_MIISTATUS_NVALID] !== 1'b0)
|
| 2390 |
|
|
begin
|
| 2391 |
|
|
test_fail("Nvalid signal was set during write");
|
| 2392 |
|
|
fail = fail + 1;
|
| 2393 |
|
|
end
|
| 2394 |
169 |
mohor |
end
|
| 2395 |
181 |
mohor |
|
| 2396 |
|
|
// wait for serial bus to become active
|
| 2397 |
|
|
wait(Mdio_IO !== 1'bz);
|
| 2398 |
|
|
// count transfer bits
|
| 2399 |
|
|
if (i)
|
| 2400 |
169 |
mohor |
begin
|
| 2401 |
181 |
mohor |
repeat(32) @(posedge Mdc_O);
|
| 2402 |
169 |
mohor |
end
|
| 2403 |
181 |
mohor |
else
|
| 2404 |
169 |
mohor |
begin
|
| 2405 |
181 |
mohor |
repeat(64) @(posedge Mdc_O);
|
| 2406 |
169 |
mohor |
end
|
| 2407 |
181 |
mohor |
// read data from MII status register - Busy and Nvalid bits
|
| 2408 |
274 |
tadejm |
wbm_read(`ETH_MIISTATUS, phy_data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 2409 |
181 |
mohor |
|
| 2410 |
|
|
// check MII IO signal and Busy and Nvalid bits
|
| 2411 |
|
|
if (Mdio_IO === 1'bz) // Mdio_IO should not be HIGH Z here - testbench selfcheck
|
| 2412 |
169 |
mohor |
begin
|
| 2413 |
181 |
mohor |
test_fail("Testbench error - read was to late, Mdio_IO is HIGH Z - set higher clock divider");
|
| 2414 |
|
|
if (phy_data[`ETH_MIISTATUS_BUSY] === 1'b0)
|
| 2415 |
|
|
begin
|
| 2416 |
|
|
test_fail("Busy signal should be set while MII IO signal is not active anymore");
|
| 2417 |
|
|
fail = fail + 1;
|
| 2418 |
|
|
end
|
| 2419 |
|
|
if (phy_data[`ETH_MIISTATUS_NVALID] !== 1'b0)
|
| 2420 |
|
|
begin
|
| 2421 |
|
|
test_fail("Nvalid signal was set during write");
|
| 2422 |
|
|
fail = fail + 1;
|
| 2423 |
|
|
end
|
| 2424 |
169 |
mohor |
end
|
| 2425 |
181 |
mohor |
else // Busy bit should still be set to '1'
|
| 2426 |
169 |
mohor |
begin
|
| 2427 |
181 |
mohor |
if (phy_data[`ETH_MIISTATUS_BUSY] === 1'b0)
|
| 2428 |
|
|
begin
|
| 2429 |
|
|
test_fail("Busy signal should be set while MII IO signal not HIGH Z");
|
| 2430 |
|
|
fail = fail + 1;
|
| 2431 |
|
|
end
|
| 2432 |
|
|
if (phy_data[`ETH_MIISTATUS_NVALID] !== 1'b0)
|
| 2433 |
|
|
begin
|
| 2434 |
|
|
test_fail("Nvalid signal was set during write");
|
| 2435 |
|
|
fail = fail + 1;
|
| 2436 |
|
|
end
|
| 2437 |
169 |
mohor |
end
|
| 2438 |
181 |
mohor |
|
| 2439 |
|
|
// wait for next negative clock edge
|
| 2440 |
|
|
@(negedge Mdc_O);
|
| 2441 |
169 |
mohor |
// read data from MII status register - Busy and Nvalid bits
|
| 2442 |
274 |
tadejm |
wbm_read(`ETH_MIISTATUS, phy_data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 2443 |
181 |
mohor |
|
| 2444 |
169 |
mohor |
// check MII IO signal and Busy and Nvalid bits
|
| 2445 |
|
|
if (Mdio_IO !== 1'bz) // Mdio_IO should be HIGH Z here - testbench selfcheck
|
| 2446 |
|
|
begin
|
| 2447 |
|
|
test_fail("Testbench error - read was to early, Mdio_IO is not HIGH Z - set higher clock divider");
|
| 2448 |
|
|
if (phy_data[`ETH_MIISTATUS_BUSY] === 1'b0)
|
| 2449 |
|
|
begin
|
| 2450 |
|
|
test_fail("Busy signal was not set while MII IO signal is not HIGH Z");
|
| 2451 |
|
|
fail = fail + 1;
|
| 2452 |
|
|
end
|
| 2453 |
|
|
if (phy_data[`ETH_MIISTATUS_NVALID] !== 1'b0)
|
| 2454 |
|
|
begin
|
| 2455 |
|
|
test_fail("Nvalid signal was set during write");
|
| 2456 |
|
|
fail = fail + 1;
|
| 2457 |
|
|
end
|
| 2458 |
|
|
end
|
| 2459 |
181 |
mohor |
else // Busy bit should still be set to '1'
|
| 2460 |
169 |
mohor |
begin
|
| 2461 |
|
|
if (phy_data[`ETH_MIISTATUS_BUSY] === 1'b0)
|
| 2462 |
|
|
begin
|
| 2463 |
181 |
mohor |
test_fail("Busy signal should be set after MII IO signal become HIGH Z");
|
| 2464 |
|
|
fail = fail + 1;
|
| 2465 |
169 |
mohor |
end
|
| 2466 |
181 |
mohor |
if (phy_data[`ETH_MIISTATUS_NVALID] !== 1'b0)
|
| 2467 |
169 |
mohor |
begin
|
| 2468 |
181 |
mohor |
test_fail("Nvalid signal was set during write");
|
| 2469 |
|
|
fail = fail + 1;
|
| 2470 |
|
|
end
|
| 2471 |
|
|
end
|
| 2472 |
|
|
|
| 2473 |
|
|
// wait for Busy to become inactive
|
| 2474 |
|
|
i1 = 0;
|
| 2475 |
|
|
while (i1 <= 2)
|
| 2476 |
|
|
begin
|
| 2477 |
|
|
// wait for next positive clock edge
|
| 2478 |
|
|
@(posedge Mdc_O);
|
| 2479 |
|
|
// read data from MII status register - Busy and Nvalid bits
|
| 2480 |
274 |
tadejm |
wbm_read(`ETH_MIISTATUS, phy_data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 2481 |
181 |
mohor |
|
| 2482 |
|
|
// check MII IO signal and Busy and Nvalid bits
|
| 2483 |
|
|
if (Mdio_IO !== 1'bz) // Mdio_IO should be HIGH Z here - testbench selfcheck
|
| 2484 |
|
|
begin
|
| 2485 |
|
|
test_fail("Testbench error - read was to early, Mdio_IO is not HIGH Z - set higher clock divider");
|
| 2486 |
|
|
if (phy_data[`ETH_MIISTATUS_BUSY] === 1'b0)
|
| 2487 |
169 |
mohor |
begin
|
| 2488 |
181 |
mohor |
test_fail("Busy signal was not set while MII IO signal is not HIGH Z");
|
| 2489 |
169 |
mohor |
fail = fail + 1;
|
| 2490 |
|
|
end
|
| 2491 |
181 |
mohor |
if (phy_data[`ETH_MIISTATUS_NVALID] !== 1'b0)
|
| 2492 |
|
|
begin
|
| 2493 |
|
|
test_fail("Nvalid signal was set during write");
|
| 2494 |
|
|
fail = fail + 1;
|
| 2495 |
|
|
end
|
| 2496 |
169 |
mohor |
end
|
| 2497 |
181 |
mohor |
else // wait for Busy bit to be set to '0'
|
| 2498 |
169 |
mohor |
begin
|
| 2499 |
181 |
mohor |
if (phy_data[`ETH_MIISTATUS_BUSY] === 1'b0)
|
| 2500 |
|
|
begin
|
| 2501 |
|
|
i1 = 3; // end of Busy checking
|
| 2502 |
|
|
end
|
| 2503 |
|
|
else
|
| 2504 |
|
|
begin
|
| 2505 |
|
|
if (i1 == 2)
|
| 2506 |
|
|
begin
|
| 2507 |
|
|
test_fail("Busy signal should be cleared after 2 periods after MII IO signal become HIGH Z");
|
| 2508 |
|
|
fail = fail + 1;
|
| 2509 |
|
|
end
|
| 2510 |
|
|
#Tp i1 = i1 + 1;
|
| 2511 |
|
|
end
|
| 2512 |
|
|
if (phy_data[`ETH_MIISTATUS_NVALID] !== 1'b0)
|
| 2513 |
|
|
begin
|
| 2514 |
|
|
test_fail("Nvalid signal was set after write");
|
| 2515 |
|
|
fail = fail + 1;
|
| 2516 |
|
|
end
|
| 2517 |
169 |
mohor |
end
|
| 2518 |
|
|
end
|
| 2519 |
|
|
end
|
| 2520 |
181 |
mohor |
// set PHY to normal mode
|
| 2521 |
|
|
#Tp eth_phy.preamble_suppresed(0);
|
| 2522 |
|
|
// MII mode register
|
| 2523 |
|
|
wbm_write(`ETH_MIIMODER, 32'h0, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 2524 |
|
|
if(fail == 0)
|
| 2525 |
|
|
test_ok;
|
| 2526 |
|
|
else
|
| 2527 |
|
|
fail = 0;
|
| 2528 |
116 |
mohor |
end
|
| 2529 |
|
|
|
| 2530 |
|
|
|
| 2531 |
181 |
mohor |
////////////////////////////////////////////////////////////////////
|
| 2532 |
|
|
//// ////
|
| 2533 |
|
|
//// Test busy and nvalid status durations during write (with ////
|
| 2534 |
|
|
//// and without preamble) ////
|
| 2535 |
|
|
//// ////
|
| 2536 |
|
|
////////////////////////////////////////////////////////////////////
|
| 2537 |
|
|
if (test_num == 12) //
|
| 2538 |
169 |
mohor |
begin
|
| 2539 |
194 |
tadej |
// TEST 12: BUSY AND NVALID STATUS DURATIONS DURING READ ( WITH AND WITHOUT PREAMBLE )
|
| 2540 |
|
|
test_name = "TEST 12: BUSY AND NVALID STATUS DURATIONS DURING READ ( WITH AND WITHOUT PREAMBLE )";
|
| 2541 |
|
|
`TIME; $display(" TEST 12: BUSY AND NVALID STATUS DURATIONS DURING READ ( WITH AND WITHOUT PREAMBLE )");
|
| 2542 |
181 |
mohor |
|
| 2543 |
|
|
reset_mii; // reset MII
|
| 2544 |
|
|
// set link up, if it wasn't due to previous tests, since there weren't PHY registers
|
| 2545 |
|
|
#Tp eth_phy.link_up_down(1);
|
| 2546 |
|
|
// set the MII
|
| 2547 |
|
|
clk_div = 64;
|
| 2548 |
|
|
mii_set_clk_div(clk_div[7:0]);
|
| 2549 |
|
|
// set address
|
| 2550 |
|
|
reg_addr = 5'h1; // status register
|
| 2551 |
|
|
phy_addr = 5'h1; // correct PHY address
|
| 2552 |
|
|
|
| 2553 |
|
|
for (i = 0; i <= 1; i = i + 1)
|
| 2554 |
169 |
mohor |
begin
|
| 2555 |
181 |
mohor |
#Tp eth_phy.preamble_suppresed(i);
|
| 2556 |
|
|
// MII mode register
|
| 2557 |
|
|
wbm_write(`ETH_MIIMODER, (`ETH_MIIMODER_NOPRE & {23'h0, i, 8'h0}) | (`ETH_MIIMODER_CLKDIV & clk_div),
|
| 2558 |
|
|
4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 2559 |
169 |
mohor |
@(posedge Mdc_O);
|
| 2560 |
181 |
mohor |
// read request
|
| 2561 |
|
|
#Tp mii_read_req(phy_addr, reg_addr);
|
| 2562 |
169 |
mohor |
// read data from MII status register - Busy and Nvalid bits
|
| 2563 |
274 |
tadejm |
wbm_read(`ETH_MIISTATUS, phy_data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 2564 |
181 |
mohor |
|
| 2565 |
169 |
mohor |
// check MII IO signal and Busy and Nvalid bits
|
| 2566 |
|
|
if (Mdio_IO !== 1'bz) // Mdio_IO should be HIGH Z here - testbench selfcheck
|
| 2567 |
|
|
begin
|
| 2568 |
181 |
mohor |
test_fail("Testbench error - read was to late, Mdio_IO is not HIGH Z - set higher clock divider");
|
| 2569 |
169 |
mohor |
if (phy_data[`ETH_MIISTATUS_BUSY] === 1'b0)
|
| 2570 |
|
|
begin
|
| 2571 |
181 |
mohor |
test_fail("Busy signal was not set while MII IO signal is not HIGH Z anymore - 1. read");
|
| 2572 |
169 |
mohor |
fail = fail + 1;
|
| 2573 |
|
|
end
|
| 2574 |
|
|
if (phy_data[`ETH_MIISTATUS_NVALID] !== 1'b0)
|
| 2575 |
|
|
begin
|
| 2576 |
|
|
test_fail("Nvalid signal was set during read");
|
| 2577 |
|
|
fail = fail + 1;
|
| 2578 |
|
|
end
|
| 2579 |
|
|
end
|
| 2580 |
181 |
mohor |
else // Busy bit should already be set to '1', due to reads from MII status register
|
| 2581 |
169 |
mohor |
begin
|
| 2582 |
|
|
if (phy_data[`ETH_MIISTATUS_BUSY] === 1'b0)
|
| 2583 |
|
|
begin
|
| 2584 |
181 |
mohor |
test_fail("Busy signal should be set after read, due to reads from MII status register");
|
| 2585 |
|
|
fail = fail + 1;
|
| 2586 |
169 |
mohor |
end
|
| 2587 |
|
|
if (phy_data[`ETH_MIISTATUS_NVALID] !== 1'b0)
|
| 2588 |
|
|
begin
|
| 2589 |
181 |
mohor |
test_fail("Nvalid signal was set during read");
|
| 2590 |
169 |
mohor |
fail = fail + 1;
|
| 2591 |
|
|
end
|
| 2592 |
|
|
end
|
| 2593 |
181 |
mohor |
|
| 2594 |
|
|
// wait for serial bus to become active
|
| 2595 |
|
|
wait(Mdio_IO !== 1'bz);
|
| 2596 |
|
|
// count transfer bits
|
| 2597 |
|
|
if (i)
|
| 2598 |
169 |
mohor |
begin
|
| 2599 |
181 |
mohor |
repeat(31) @(posedge Mdc_O);
|
| 2600 |
169 |
mohor |
end
|
| 2601 |
181 |
mohor |
else
|
| 2602 |
169 |
mohor |
begin
|
| 2603 |
181 |
mohor |
repeat(63) @(posedge Mdc_O);
|
| 2604 |
169 |
mohor |
end
|
| 2605 |
181 |
mohor |
// wait for next negative clock edge
|
| 2606 |
|
|
@(negedge Mdc_O);
|
| 2607 |
|
|
// read data from MII status register - Busy and Nvalid bits
|
| 2608 |
274 |
tadejm |
wbm_read(`ETH_MIISTATUS, phy_data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 2609 |
181 |
mohor |
|
| 2610 |
|
|
// check MII IO signal and Busy and Nvalid bits
|
| 2611 |
|
|
if (Mdio_IO === 1'bz) // Mdio_IO should not be HIGH Z here - testbench selfcheck
|
| 2612 |
169 |
mohor |
begin
|
| 2613 |
181 |
mohor |
test_fail("Testbench error - read was to late, Mdio_IO is HIGH Z - set higher clock divider");
|
| 2614 |
|
|
if (phy_data[`ETH_MIISTATUS_BUSY] === 1'b0)
|
| 2615 |
|
|
begin
|
| 2616 |
|
|
test_fail("Busy signal should be set while MII IO signal is not active anymore");
|
| 2617 |
|
|
fail = fail + 1;
|
| 2618 |
|
|
end
|
| 2619 |
|
|
if (phy_data[`ETH_MIISTATUS_NVALID] !== 1'b0)
|
| 2620 |
|
|
begin
|
| 2621 |
|
|
test_fail("Nvalid signal was set during read");
|
| 2622 |
|
|
fail = fail + 1;
|
| 2623 |
|
|
end
|
| 2624 |
169 |
mohor |
end
|
| 2625 |
181 |
mohor |
else // Busy bit should still be set to '1'
|
| 2626 |
169 |
mohor |
begin
|
| 2627 |
181 |
mohor |
if (phy_data[`ETH_MIISTATUS_BUSY] === 1'b0)
|
| 2628 |
|
|
begin
|
| 2629 |
|
|
test_fail("Busy signal should be set while MII IO signal not HIGH Z");
|
| 2630 |
|
|
fail = fail + 1;
|
| 2631 |
|
|
end
|
| 2632 |
|
|
if (phy_data[`ETH_MIISTATUS_NVALID] !== 1'b0)
|
| 2633 |
|
|
begin
|
| 2634 |
|
|
test_fail("Nvalid signal was set during read");
|
| 2635 |
|
|
fail = fail + 1;
|
| 2636 |
|
|
end
|
| 2637 |
169 |
mohor |
end
|
| 2638 |
181 |
mohor |
|
| 2639 |
169 |
mohor |
// wait for next positive clock edge
|
| 2640 |
|
|
@(posedge Mdc_O);
|
| 2641 |
|
|
// read data from MII status register - Busy and Nvalid bits
|
| 2642 |
274 |
tadejm |
wbm_read(`ETH_MIISTATUS, phy_data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 2643 |
181 |
mohor |
|
| 2644 |
169 |
mohor |
// check MII IO signal and Busy and Nvalid bits
|
| 2645 |
|
|
if (Mdio_IO !== 1'bz) // Mdio_IO should be HIGH Z here - testbench selfcheck
|
| 2646 |
|
|
begin
|
| 2647 |
|
|
test_fail("Testbench error - read was to early, Mdio_IO is not HIGH Z - set higher clock divider");
|
| 2648 |
181 |
mohor |
if (phy_data[`ETH_MIISTATUS_BUSY] === 1'b0)
|
| 2649 |
169 |
mohor |
begin
|
| 2650 |
181 |
mohor |
test_fail("Busy signal was not set while MII IO signal is not HIGH Z");
|
| 2651 |
|
|
fail = fail + 1;
|
| 2652 |
|
|
end
|
| 2653 |
|
|
if (phy_data[`ETH_MIISTATUS_NVALID] !== 1'b0)
|
| 2654 |
|
|
begin
|
| 2655 |
|
|
test_fail("Nvalid signal was set during read");
|
| 2656 |
|
|
fail = fail + 1;
|
| 2657 |
|
|
end
|
| 2658 |
|
|
end
|
| 2659 |
|
|
else // Busy bit should still be set to '1'
|
| 2660 |
|
|
begin
|
| 2661 |
|
|
if (phy_data[`ETH_MIISTATUS_BUSY] === 1'b0)
|
| 2662 |
|
|
begin
|
| 2663 |
|
|
test_fail("Busy signal should be set after MII IO signal become HIGH Z");
|
| 2664 |
|
|
fail = fail + 1;
|
| 2665 |
|
|
end
|
| 2666 |
|
|
if (phy_data[`ETH_MIISTATUS_NVALID] !== 1'b0)
|
| 2667 |
|
|
begin
|
| 2668 |
|
|
test_fail("Nvalid signal was set during read");
|
| 2669 |
|
|
fail = fail + 1;
|
| 2670 |
|
|
end
|
| 2671 |
|
|
end
|
| 2672 |
|
|
|
| 2673 |
|
|
// wait for Busy to become inactive
|
| 2674 |
|
|
i1 = 0;
|
| 2675 |
|
|
while (i1 <= 2)
|
| 2676 |
|
|
begin
|
| 2677 |
|
|
// wait for next positive clock edge
|
| 2678 |
|
|
@(posedge Mdc_O);
|
| 2679 |
|
|
// read data from MII status register - Busy and Nvalid bits
|
| 2680 |
274 |
tadejm |
wbm_read(`ETH_MIISTATUS, phy_data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 2681 |
181 |
mohor |
|
| 2682 |
|
|
// check MII IO signal and Busy and Nvalid bits
|
| 2683 |
|
|
if (Mdio_IO !== 1'bz) // Mdio_IO should be HIGH Z here - testbench selfcheck
|
| 2684 |
|
|
begin
|
| 2685 |
|
|
test_fail("Testbench error - read was to early, Mdio_IO is not HIGH Z - set higher clock divider");
|
| 2686 |
169 |
mohor |
if (phy_data[`ETH_MIISTATUS_BUSY] === 1'b0)
|
| 2687 |
|
|
begin
|
| 2688 |
|
|
test_fail("Busy signal was not set while MII IO signal is not HIGH Z");
|
| 2689 |
|
|
fail = fail + 1;
|
| 2690 |
|
|
end
|
| 2691 |
181 |
mohor |
if (phy_data[`ETH_MIISTATUS_NVALID] !== 1'b0)
|
| 2692 |
169 |
mohor |
begin
|
| 2693 |
181 |
mohor |
test_fail("Nvalid signal was set during read");
|
| 2694 |
169 |
mohor |
fail = fail + 1;
|
| 2695 |
|
|
end
|
| 2696 |
|
|
end
|
| 2697 |
181 |
mohor |
else // wait for Busy bit to be set to '0'
|
| 2698 |
169 |
mohor |
begin
|
| 2699 |
|
|
if (phy_data[`ETH_MIISTATUS_BUSY] === 1'b0)
|
| 2700 |
|
|
begin
|
| 2701 |
|
|
i1 = 3; // end of Busy checking
|
| 2702 |
|
|
end
|
| 2703 |
|
|
else
|
| 2704 |
|
|
begin
|
| 2705 |
|
|
if (i1 == 2)
|
| 2706 |
|
|
begin
|
| 2707 |
|
|
test_fail("Busy signal should be cleared after 2 periods after MII IO signal become HIGH Z");
|
| 2708 |
|
|
fail = fail + 1;
|
| 2709 |
|
|
end
|
| 2710 |
|
|
#Tp i1 = i1 + 1;
|
| 2711 |
|
|
end
|
| 2712 |
181 |
mohor |
if (phy_data[`ETH_MIISTATUS_NVALID] !== 1'b0)
|
| 2713 |
169 |
mohor |
begin
|
| 2714 |
181 |
mohor |
test_fail("Nvalid signal was set after read");
|
| 2715 |
169 |
mohor |
fail = fail + 1;
|
| 2716 |
|
|
end
|
| 2717 |
|
|
end
|
| 2718 |
|
|
end
|
| 2719 |
|
|
end
|
| 2720 |
181 |
mohor |
// set PHY to normal mode
|
| 2721 |
|
|
#Tp eth_phy.preamble_suppresed(0);
|
| 2722 |
|
|
// MII mode register
|
| 2723 |
|
|
wbm_write(`ETH_MIIMODER, 32'h0, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 2724 |
|
|
if(fail == 0)
|
| 2725 |
|
|
test_ok;
|
| 2726 |
|
|
else
|
| 2727 |
|
|
fail = 0;
|
| 2728 |
169 |
mohor |
end
|
| 2729 |
|
|
|
| 2730 |
|
|
|
| 2731 |
181 |
mohor |
////////////////////////////////////////////////////////////////////
|
| 2732 |
|
|
//// ////
|
| 2733 |
|
|
//// Test busy and nvalid status durations during scan (with ////
|
| 2734 |
|
|
//// and without preamble) ////
|
| 2735 |
|
|
//// ////
|
| 2736 |
|
|
////////////////////////////////////////////////////////////////////
|
| 2737 |
|
|
if (test_num == 13) //
|
| 2738 |
169 |
mohor |
begin
|
| 2739 |
194 |
tadej |
// TEST 13: BUSY AND NVALID STATUS DURATIONS DURING SCAN ( WITH AND WITHOUT PREAMBLE )
|
| 2740 |
|
|
test_name = "TEST 13: BUSY AND NVALID STATUS DURATIONS DURING SCAN ( WITH AND WITHOUT PREAMBLE )";
|
| 2741 |
|
|
`TIME; $display(" TEST 13: BUSY AND NVALID STATUS DURATIONS DURING SCAN ( WITH AND WITHOUT PREAMBLE )");
|
| 2742 |
181 |
mohor |
|
| 2743 |
|
|
reset_mii; // reset MII
|
| 2744 |
|
|
// set link up, if it wasn't due to previous tests, since there weren't PHY registers
|
| 2745 |
|
|
#Tp eth_phy.link_up_down(1);
|
| 2746 |
|
|
// set the MII
|
| 2747 |
|
|
clk_div = 64;
|
| 2748 |
|
|
mii_set_clk_div(clk_div[7:0]);
|
| 2749 |
|
|
// set address
|
| 2750 |
|
|
reg_addr = 5'h1; // status register
|
| 2751 |
|
|
phy_addr = 5'h1; // correct PHY address
|
| 2752 |
|
|
|
| 2753 |
|
|
for (i = 0; i <= 1; i = i + 1)
|
| 2754 |
169 |
mohor |
begin
|
| 2755 |
181 |
mohor |
#Tp eth_phy.preamble_suppresed(i);
|
| 2756 |
|
|
// MII mode register
|
| 2757 |
|
|
wbm_write(`ETH_MIIMODER, (`ETH_MIIMODER_NOPRE & {23'h0, i, 8'h0}) | (`ETH_MIIMODER_CLKDIV & clk_div),
|
| 2758 |
|
|
4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 2759 |
|
|
@(posedge Mdc_O);
|
| 2760 |
|
|
// scan request
|
| 2761 |
|
|
#Tp mii_scan_req(phy_addr, reg_addr);
|
| 2762 |
|
|
// read data from MII status register - Busy and Nvalid bits
|
| 2763 |
274 |
tadejm |
wbm_read(`ETH_MIISTATUS, phy_data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 2764 |
181 |
mohor |
|
| 2765 |
|
|
// check MII IO signal and Busy and Nvalid bits
|
| 2766 |
|
|
if (Mdio_IO !== 1'bz) // Mdio_IO should be HIGH Z here - testbench selfcheck
|
| 2767 |
169 |
mohor |
begin
|
| 2768 |
181 |
mohor |
test_fail("Testbench error - read was to late, Mdio_IO is not HIGH Z - set higher clock divider");
|
| 2769 |
|
|
if (phy_data[`ETH_MIISTATUS_BUSY] === 1'b0)
|
| 2770 |
|
|
begin
|
| 2771 |
|
|
test_fail("Busy signal was not set while MII IO signal is not HIGH Z anymore - 1. read");
|
| 2772 |
|
|
fail = fail + 1;
|
| 2773 |
|
|
end
|
| 2774 |
|
|
if (phy_data[`ETH_MIISTATUS_NVALID] === 1'b0)
|
| 2775 |
|
|
begin
|
| 2776 |
|
|
test_fail("Nvalid signal was not set while MII IO signal is not HIGH Z anymore - 1. read");
|
| 2777 |
|
|
fail = fail + 1;
|
| 2778 |
|
|
end
|
| 2779 |
169 |
mohor |
end
|
| 2780 |
181 |
mohor |
else // Busy bit should already be set to '1', due to reads from MII status register
|
| 2781 |
169 |
mohor |
begin
|
| 2782 |
181 |
mohor |
if (phy_data[`ETH_MIISTATUS_BUSY] === 1'b0)
|
| 2783 |
|
|
begin
|
| 2784 |
|
|
test_fail("Busy signal should be set after scan, due to reads from MII status register");
|
| 2785 |
|
|
fail = fail + 1;
|
| 2786 |
|
|
end
|
| 2787 |
|
|
if (phy_data[`ETH_MIISTATUS_NVALID] === 1'b0)
|
| 2788 |
|
|
begin
|
| 2789 |
|
|
test_fail("Nvalid signal should be set after scan, due to reads from MII status register");
|
| 2790 |
|
|
fail = fail + 1;
|
| 2791 |
|
|
end
|
| 2792 |
169 |
mohor |
end
|
| 2793 |
181 |
mohor |
|
| 2794 |
|
|
// wait for serial bus to become active
|
| 2795 |
169 |
mohor |
wait(Mdio_IO !== 1'bz);
|
| 2796 |
181 |
mohor |
// count transfer bits
|
| 2797 |
|
|
if (i)
|
| 2798 |
169 |
mohor |
begin
|
| 2799 |
181 |
mohor |
repeat(21) @(posedge Mdc_O);
|
| 2800 |
169 |
mohor |
end
|
| 2801 |
181 |
mohor |
else
|
| 2802 |
169 |
mohor |
begin
|
| 2803 |
181 |
mohor |
repeat(53) @(posedge Mdc_O);
|
| 2804 |
169 |
mohor |
end
|
| 2805 |
181 |
mohor |
// stop scan
|
| 2806 |
|
|
#Tp mii_scan_finish; // finish scan operation
|
| 2807 |
|
|
|
| 2808 |
|
|
// wait for next positive clock edge
|
| 2809 |
|
|
repeat(10) @(posedge Mdc_O);
|
| 2810 |
|
|
// read data from MII status register - Busy and Nvalid bits
|
| 2811 |
274 |
tadejm |
wbm_read(`ETH_MIISTATUS, phy_data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 2812 |
181 |
mohor |
|
| 2813 |
|
|
// check MII IO signal and Busy and Nvalid bits
|
| 2814 |
|
|
if (Mdio_IO === 1'bz) // Mdio_IO should not be HIGH Z here - testbench selfcheck
|
| 2815 |
169 |
mohor |
begin
|
| 2816 |
181 |
mohor |
test_fail("Testbench error - read was to late, Mdio_IO is HIGH Z - set higher clock divider");
|
| 2817 |
|
|
if (phy_data[`ETH_MIISTATUS_BUSY] === 1'b0)
|
| 2818 |
169 |
mohor |
begin
|
| 2819 |
181 |
mohor |
test_fail("Busy signal should be set while MII IO signal is not active anymore");
|
| 2820 |
169 |
mohor |
fail = fail + 1;
|
| 2821 |
|
|
end
|
| 2822 |
181 |
mohor |
// Nvalid signal can be cleared here - it is still Testbench error
|
| 2823 |
169 |
mohor |
end
|
| 2824 |
181 |
mohor |
else // Busy bit should still be set to '1', Nvalid bit should still be set to '1'
|
| 2825 |
169 |
mohor |
begin
|
| 2826 |
181 |
mohor |
if (phy_data[`ETH_MIISTATUS_BUSY] === 1'b0)
|
| 2827 |
169 |
mohor |
begin
|
| 2828 |
181 |
mohor |
test_fail("Busy signal should be set while MII IO signal not HIGH Z");
|
| 2829 |
169 |
mohor |
fail = fail + 1;
|
| 2830 |
|
|
end
|
| 2831 |
181 |
mohor |
if (phy_data[`ETH_MIISTATUS_NVALID] === 1'b0)
|
| 2832 |
169 |
mohor |
begin
|
| 2833 |
181 |
mohor |
test_fail("Nvalid signal should be set while MII IO signal not HIGH Z");
|
| 2834 |
169 |
mohor |
fail = fail + 1;
|
| 2835 |
|
|
end
|
| 2836 |
181 |
mohor |
end
|
| 2837 |
|
|
|
| 2838 |
|
|
// wait for next negative clock edge
|
| 2839 |
|
|
@(negedge Mdc_O);
|
| 2840 |
|
|
// read data from MII status register - Busy and Nvalid bits
|
| 2841 |
274 |
tadejm |
wbm_read(`ETH_MIISTATUS, phy_data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 2842 |
181 |
mohor |
|
| 2843 |
|
|
// check MII IO signal and Busy and Nvalid bits
|
| 2844 |
|
|
if (Mdio_IO === 1'bz) // Mdio_IO should not be HIGH Z here - testbench selfcheck
|
| 2845 |
|
|
begin
|
| 2846 |
|
|
test_fail("Testbench error - read was to late, Mdio_IO is HIGH Z - set higher clock divider");
|
| 2847 |
|
|
if (phy_data[`ETH_MIISTATUS_BUSY] === 1'b0)
|
| 2848 |
169 |
mohor |
begin
|
| 2849 |
181 |
mohor |
test_fail("Busy signal should be set while MII IO signal is not active anymore");
|
| 2850 |
|
|
fail = fail + 1;
|
| 2851 |
169 |
mohor |
end
|
| 2852 |
181 |
mohor |
// Nvalid signal can be cleared here - it is still Testbench error
|
| 2853 |
169 |
mohor |
end
|
| 2854 |
181 |
mohor |
else // Busy bit should still be set to '1', Nvalid bit should still be set to '1'
|
| 2855 |
169 |
mohor |
begin
|
| 2856 |
181 |
mohor |
if (phy_data[`ETH_MIISTATUS_BUSY] === 1'b0)
|
| 2857 |
169 |
mohor |
begin
|
| 2858 |
181 |
mohor |
test_fail("Busy signal should be set while MII IO signal not HIGH Z");
|
| 2859 |
|
|
fail = fail + 1;
|
| 2860 |
169 |
mohor |
end
|
| 2861 |
181 |
mohor |
if (phy_data[`ETH_MIISTATUS_NVALID] === 1'b0)
|
| 2862 |
169 |
mohor |
begin
|
| 2863 |
181 |
mohor |
test_fail("Nvalid signal should be set while MII IO signal not HIGH Z");
|
| 2864 |
|
|
fail = fail + 1;
|
| 2865 |
169 |
mohor |
end
|
| 2866 |
|
|
end
|
| 2867 |
181 |
mohor |
|
| 2868 |
|
|
// wait for next negative clock edge
|
| 2869 |
|
|
@(posedge Mdc_O);
|
| 2870 |
|
|
// read data from MII status register - Busy and Nvalid bits
|
| 2871 |
274 |
tadejm |
wbm_read(`ETH_MIISTATUS, phy_data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 2872 |
181 |
mohor |
|
| 2873 |
|
|
// check MII IO signal and Busy and Nvalid bits
|
| 2874 |
|
|
if (Mdio_IO !== 1'bz) // Mdio_IO should be HIGH Z here - testbench selfcheck
|
| 2875 |
169 |
mohor |
begin
|
| 2876 |
181 |
mohor |
test_fail("Testbench error - read was to early, Mdio_IO is not HIGH Z - set higher clock divider");
|
| 2877 |
|
|
if (phy_data[`ETH_MIISTATUS_BUSY] === 1'b0)
|
| 2878 |
169 |
mohor |
begin
|
| 2879 |
181 |
mohor |
test_fail("Busy signal was not set while MII IO signal is not HIGH Z");
|
| 2880 |
169 |
mohor |
fail = fail + 1;
|
| 2881 |
|
|
end
|
| 2882 |
181 |
mohor |
if (phy_data[`ETH_MIISTATUS_NVALID] === 1'b0)
|
| 2883 |
169 |
mohor |
begin
|
| 2884 |
181 |
mohor |
test_fail("Nvalid signal was not set while MII IO signal is not HIGH Z");
|
| 2885 |
169 |
mohor |
fail = fail + 1;
|
| 2886 |
|
|
end
|
| 2887 |
|
|
end
|
| 2888 |
181 |
mohor |
else // Busy bit should still be set to '1', Nvalid bit can be set to '0'
|
| 2889 |
169 |
mohor |
begin
|
| 2890 |
181 |
mohor |
if (phy_data[`ETH_MIISTATUS_BUSY] === 1'b0)
|
| 2891 |
169 |
mohor |
begin
|
| 2892 |
181 |
mohor |
test_fail("Busy signal should be set after MII IO signal become HIGH Z");
|
| 2893 |
|
|
fail = fail + 1;
|
| 2894 |
169 |
mohor |
end
|
| 2895 |
181 |
mohor |
if (phy_data[`ETH_MIISTATUS_NVALID] === 1'b0)
|
| 2896 |
169 |
mohor |
begin
|
| 2897 |
181 |
mohor |
i2 = 1; // check finished
|
| 2898 |
169 |
mohor |
end
|
| 2899 |
181 |
mohor |
else
|
| 2900 |
169 |
mohor |
begin
|
| 2901 |
181 |
mohor |
i2 = 0; // check must continue
|
| 2902 |
169 |
mohor |
end
|
| 2903 |
|
|
end
|
| 2904 |
181 |
mohor |
|
| 2905 |
|
|
// wait for Busy to become inactive
|
| 2906 |
|
|
i1 = 0;
|
| 2907 |
|
|
while ((i1 <= 2) || (i2 == 0))
|
| 2908 |
|
|
begin
|
| 2909 |
|
|
// wait for next positive clock edge
|
| 2910 |
|
|
@(posedge Mdc_O);
|
| 2911 |
|
|
// read data from MII status register - Busy and Nvalid bits
|
| 2912 |
274 |
tadejm |
wbm_read(`ETH_MIISTATUS, phy_data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 2913 |
181 |
mohor |
|
| 2914 |
|
|
// check MII IO signal and Busy and Nvalid bits
|
| 2915 |
|
|
if (Mdio_IO !== 1'bz) // Mdio_IO should be HIGH Z here - testbench selfcheck
|
| 2916 |
169 |
mohor |
begin
|
| 2917 |
181 |
mohor |
test_fail("Testbench error - read was to early, Mdio_IO is not HIGH Z - set higher clock divider");
|
| 2918 |
|
|
if (i1 <= 2)
|
| 2919 |
169 |
mohor |
begin
|
| 2920 |
181 |
mohor |
if (phy_data[`ETH_MIISTATUS_BUSY] === 1'b0)
|
| 2921 |
169 |
mohor |
begin
|
| 2922 |
181 |
mohor |
test_fail("Busy signal was not set while MII IO signal is not HIGH Z");
|
| 2923 |
169 |
mohor |
fail = fail + 1;
|
| 2924 |
|
|
end
|
| 2925 |
|
|
end
|
| 2926 |
181 |
mohor |
if (i2 == 0)
|
| 2927 |
169 |
mohor |
begin
|
| 2928 |
181 |
mohor |
if (phy_data[`ETH_MIISTATUS_NVALID] === 1'b0)
|
| 2929 |
169 |
mohor |
begin
|
| 2930 |
181 |
mohor |
test_fail("Nvalid signal was not set while MII IO signal is not HIGH Z");
|
| 2931 |
169 |
mohor |
fail = fail + 1;
|
| 2932 |
|
|
end
|
| 2933 |
|
|
end
|
| 2934 |
|
|
end
|
| 2935 |
181 |
mohor |
else // wait for Busy bit to be set to '0'
|
| 2936 |
169 |
mohor |
begin
|
| 2937 |
181 |
mohor |
if (i1 <= 2)
|
| 2938 |
169 |
mohor |
begin
|
| 2939 |
181 |
mohor |
if (phy_data[`ETH_MIISTATUS_BUSY] === 1'b0)
|
| 2940 |
169 |
mohor |
begin
|
| 2941 |
181 |
mohor |
i1 = 3; // end of Busy checking
|
| 2942 |
169 |
mohor |
end
|
| 2943 |
181 |
mohor |
else
|
| 2944 |
169 |
mohor |
begin
|
| 2945 |
181 |
mohor |
if (i1 == 2)
|
| 2946 |
169 |
mohor |
begin
|
| 2947 |
181 |
mohor |
test_fail("Busy signal should be cleared after 2 periods after MII IO signal become HIGH Z");
|
| 2948 |
169 |
mohor |
fail = fail + 1;
|
| 2949 |
|
|
end
|
| 2950 |
181 |
mohor |
#Tp i1 = i1 + 1;
|
| 2951 |
169 |
mohor |
end
|
| 2952 |
181 |
mohor |
end
|
| 2953 |
|
|
if (i2 == 0)
|
| 2954 |
|
|
begin
|
| 2955 |
|
|
if (phy_data[`ETH_MIISTATUS_NVALID] === 1'b0)
|
| 2956 |
169 |
mohor |
begin
|
| 2957 |
181 |
mohor |
i2 = 1;
|
| 2958 |
169 |
mohor |
end
|
| 2959 |
181 |
mohor |
else
|
| 2960 |
|
|
begin
|
| 2961 |
|
|
test_fail("Nvalid signal should be cleared after MII IO signal become HIGH Z");
|
| 2962 |
|
|
fail = fail + 1;
|
| 2963 |
|
|
end
|
| 2964 |
169 |
mohor |
end
|
| 2965 |
|
|
end
|
| 2966 |
181 |
mohor |
end
|
| 2967 |
|
|
end
|
| 2968 |
|
|
// set PHY to normal mode
|
| 2969 |
|
|
#Tp eth_phy.preamble_suppresed(0);
|
| 2970 |
|
|
// MII mode register
|
| 2971 |
|
|
wbm_write(`ETH_MIIMODER, 32'h0, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 2972 |
|
|
if(fail == 0)
|
| 2973 |
|
|
test_ok;
|
| 2974 |
|
|
else
|
| 2975 |
|
|
fail = 0;
|
| 2976 |
|
|
end
|
| 2977 |
|
|
|
| 2978 |
|
|
|
| 2979 |
|
|
////////////////////////////////////////////////////////////////////
|
| 2980 |
|
|
//// ////
|
| 2981 |
|
|
//// Test scan status from phy with detecting link-fail bit ////
|
| 2982 |
|
|
//// (with and without preamble) ////
|
| 2983 |
|
|
//// ////
|
| 2984 |
|
|
////////////////////////////////////////////////////////////////////
|
| 2985 |
|
|
if (test_num == 14) //
|
| 2986 |
|
|
begin
|
| 2987 |
194 |
tadej |
// TEST 14: SCAN STATUS FROM PHY WITH DETECTING LINK-FAIL BIT ( WITH AND WITHOUT PREAMBLE )
|
| 2988 |
|
|
test_name = "TEST 14: SCAN STATUS FROM PHY WITH DETECTING LINK-FAIL BIT ( WITH AND WITHOUT PREAMBLE )";
|
| 2989 |
|
|
`TIME; $display(" TEST 14: SCAN STATUS FROM PHY WITH DETECTING LINK-FAIL BIT ( WITH AND WITHOUT PREAMBLE )");
|
| 2990 |
181 |
mohor |
|
| 2991 |
|
|
reset_mii; // reset MII
|
| 2992 |
|
|
// set link up, if it wasn't due to previous tests, since there weren't PHY registers
|
| 2993 |
|
|
#Tp eth_phy.link_up_down(1);
|
| 2994 |
|
|
// set MII speed
|
| 2995 |
|
|
clk_div = 6;
|
| 2996 |
|
|
mii_set_clk_div(clk_div[7:0]);
|
| 2997 |
|
|
// set address
|
| 2998 |
|
|
reg_addr = 5'h1; // status register
|
| 2999 |
|
|
phy_addr = 5'h1; // correct PHY address
|
| 3000 |
|
|
|
| 3001 |
|
|
// read request
|
| 3002 |
|
|
#Tp mii_read_req(phy_addr, reg_addr);
|
| 3003 |
|
|
check_mii_busy; // wait for read to finish
|
| 3004 |
|
|
// read data from PHY status register - remember LINK-UP status
|
| 3005 |
274 |
tadejm |
wbm_read(`ETH_MIIRX_DATA, tmp_data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 3006 |
181 |
mohor |
|
| 3007 |
|
|
for (i = 0; i <= 1; i = i + 1)
|
| 3008 |
|
|
begin
|
| 3009 |
|
|
#Tp eth_phy.preamble_suppresed(i);
|
| 3010 |
|
|
// MII mode register
|
| 3011 |
|
|
wbm_write(`ETH_MIIMODER, (`ETH_MIIMODER_NOPRE & {23'h0, i, 8'h0}) | (`ETH_MIIMODER_CLKDIV & clk_div),
|
| 3012 |
|
|
4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 3013 |
|
|
if (i)
|
| 3014 |
|
|
begin
|
| 3015 |
|
|
// change saved data when preamble is suppressed
|
| 3016 |
|
|
#Tp tmp_data = tmp_data | 16'h0040; // put bit 6 to ONE
|
| 3017 |
|
|
end
|
| 3018 |
|
|
|
| 3019 |
|
|
// scan request
|
| 3020 |
|
|
#Tp mii_scan_req(phy_addr, reg_addr);
|
| 3021 |
|
|
check_mii_scan_valid; // wait for scan to make first data valid
|
| 3022 |
|
|
|
| 3023 |
169 |
mohor |
fork
|
| 3024 |
181 |
mohor |
begin
|
| 3025 |
169 |
mohor |
repeat(2) @(posedge Mdc_O);
|
| 3026 |
|
|
// read data from PHY status register
|
| 3027 |
274 |
tadejm |
wbm_read(`ETH_MIIRX_DATA, phy_data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 3028 |
181 |
mohor |
if (phy_data !== tmp_data)
|
| 3029 |
169 |
mohor |
begin
|
| 3030 |
181 |
mohor |
test_fail("Data was not correctly scaned from status register");
|
| 3031 |
169 |
mohor |
fail = fail + 1;
|
| 3032 |
|
|
end
|
| 3033 |
|
|
// read data from MII status register
|
| 3034 |
274 |
tadejm |
wbm_read(`ETH_MIISTATUS, phy_data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 3035 |
181 |
mohor |
if (phy_data[0] !== 1'b0)
|
| 3036 |
169 |
mohor |
begin
|
| 3037 |
181 |
mohor |
test_fail("Link FAIL bit was set in the MII status register");
|
| 3038 |
169 |
mohor |
fail = fail + 1;
|
| 3039 |
|
|
end
|
| 3040 |
|
|
end
|
| 3041 |
|
|
begin
|
| 3042 |
181 |
mohor |
// Completely check second scan
|
| 3043 |
169 |
mohor |
#Tp cnt = 0;
|
| 3044 |
|
|
// wait for serial bus to become active - second scan
|
| 3045 |
|
|
wait(Mdio_IO !== 1'bz);
|
| 3046 |
|
|
// count transfer length
|
| 3047 |
181 |
mohor |
while( (Mdio_IO !== 1'bz) || ((cnt == 47) && (i == 0)) || ((cnt == 15) && (i == 1)) )
|
| 3048 |
169 |
mohor |
begin
|
| 3049 |
|
|
@(posedge Mdc_O);
|
| 3050 |
|
|
#Tp cnt = cnt + 1;
|
| 3051 |
|
|
end
|
| 3052 |
|
|
// check transfer length
|
| 3053 |
181 |
mohor |
if (i) // without preamble
|
| 3054 |
169 |
mohor |
begin
|
| 3055 |
|
|
if (cnt != 33) // at this value Mdio_IO is HIGH Z
|
| 3056 |
|
|
begin
|
| 3057 |
181 |
mohor |
test_fail("Second scan request did not proceed correctly");
|
| 3058 |
169 |
mohor |
fail = fail + 1;
|
| 3059 |
|
|
end
|
| 3060 |
|
|
end
|
| 3061 |
|
|
else // with preamble
|
| 3062 |
|
|
begin
|
| 3063 |
|
|
if (cnt != 65) // at this value Mdio_IO is HIGH Z
|
| 3064 |
|
|
begin
|
| 3065 |
181 |
mohor |
test_fail("Second scan request did not proceed correctly");
|
| 3066 |
169 |
mohor |
fail = fail + 1;
|
| 3067 |
|
|
end
|
| 3068 |
|
|
end
|
| 3069 |
|
|
end
|
| 3070 |
|
|
join
|
| 3071 |
181 |
mohor |
// check third to fifth scans
|
| 3072 |
|
|
for (i3 = 0; i3 <= 2; i3 = i3 + 1)
|
| 3073 |
|
|
begin
|
| 3074 |
|
|
fork
|
| 3075 |
169 |
mohor |
begin
|
| 3076 |
|
|
repeat(2) @(posedge Mdc_O);
|
| 3077 |
|
|
// read data from PHY status register
|
| 3078 |
274 |
tadejm |
wbm_read(`ETH_MIIRX_DATA, phy_data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 3079 |
181 |
mohor |
if (phy_data !== tmp_data)
|
| 3080 |
169 |
mohor |
begin
|
| 3081 |
181 |
mohor |
test_fail("Data was not correctly scaned from status register");
|
| 3082 |
|
|
fail = fail + 1;
|
| 3083 |
169 |
mohor |
end
|
| 3084 |
|
|
// read data from MII status register
|
| 3085 |
274 |
tadejm |
wbm_read(`ETH_MIISTATUS, phy_data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 3086 |
181 |
mohor |
if (phy_data[0] !== 1'b0)
|
| 3087 |
169 |
mohor |
begin
|
| 3088 |
181 |
mohor |
test_fail("Link FAIL bit was set in the MII status register");
|
| 3089 |
|
|
fail = fail + 1;
|
| 3090 |
169 |
mohor |
end
|
| 3091 |
181 |
mohor |
if (i3 == 2) // after fourth scan read
|
| 3092 |
169 |
mohor |
begin
|
| 3093 |
181 |
mohor |
@(posedge Mdc_O);
|
| 3094 |
|
|
// change saved data
|
| 3095 |
|
|
#Tp tmp_data = tmp_data & 16'hFFFB; // put bit 3 to ZERO
|
| 3096 |
|
|
// set link down
|
| 3097 |
|
|
#Tp eth_phy.link_up_down(0);
|
| 3098 |
169 |
mohor |
end
|
| 3099 |
|
|
end
|
| 3100 |
|
|
begin
|
| 3101 |
181 |
mohor |
// Completely check scans
|
| 3102 |
|
|
#Tp cnt = 0;
|
| 3103 |
|
|
// wait for serial bus to become active - second scan
|
| 3104 |
|
|
wait(Mdio_IO !== 1'bz);
|
| 3105 |
|
|
// count transfer length
|
| 3106 |
|
|
while( (Mdio_IO !== 1'bz) || ((cnt == 47) && (i == 0)) || ((cnt == 15) && (i == 1)) )
|
| 3107 |
169 |
mohor |
begin
|
| 3108 |
181 |
mohor |
@(posedge Mdc_O);
|
| 3109 |
|
|
#Tp cnt = cnt + 1;
|
| 3110 |
|
|
end
|
| 3111 |
|
|
// check transfer length
|
| 3112 |
|
|
if (i) // without preamble
|
| 3113 |
|
|
begin
|
| 3114 |
|
|
if (cnt != 33) // at this value Mdio_IO is HIGH Z
|
| 3115 |
169 |
mohor |
begin
|
| 3116 |
181 |
mohor |
test_fail("Fifth scan request did not proceed correctly");
|
| 3117 |
|
|
fail = fail + 1;
|
| 3118 |
169 |
mohor |
end
|
| 3119 |
181 |
mohor |
end
|
| 3120 |
|
|
else // with preamble
|
| 3121 |
|
|
begin
|
| 3122 |
|
|
if (cnt != 65) // at this value Mdio_IO is HIGH Z
|
| 3123 |
169 |
mohor |
begin
|
| 3124 |
181 |
mohor |
test_fail("Fifth scan request did not proceed correctly");
|
| 3125 |
|
|
fail = fail + 1;
|
| 3126 |
169 |
mohor |
end
|
| 3127 |
|
|
end
|
| 3128 |
|
|
end
|
| 3129 |
181 |
mohor |
join
|
| 3130 |
|
|
end
|
| 3131 |
|
|
|
| 3132 |
|
|
fork
|
| 3133 |
|
|
begin
|
| 3134 |
|
|
repeat(2) @(posedge Mdc_O);
|
| 3135 |
|
|
// read data from PHY status register
|
| 3136 |
274 |
tadejm |
wbm_read(`ETH_MIIRX_DATA, phy_data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 3137 |
181 |
mohor |
if (phy_data !== tmp_data)
|
| 3138 |
|
|
begin
|
| 3139 |
|
|
test_fail("Data was not correctly scaned from status register");
|
| 3140 |
|
|
fail = fail + 1;
|
| 3141 |
|
|
end
|
| 3142 |
|
|
// read data from MII status register
|
| 3143 |
274 |
tadejm |
wbm_read(`ETH_MIISTATUS, phy_data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 3144 |
181 |
mohor |
if (phy_data[0] === 1'b0)
|
| 3145 |
|
|
begin
|
| 3146 |
|
|
test_fail("Link FAIL bit was not set in the MII status register");
|
| 3147 |
|
|
fail = fail + 1;
|
| 3148 |
|
|
end
|
| 3149 |
|
|
// wait to see if data stayed latched
|
| 3150 |
|
|
repeat(4) @(posedge Mdc_O);
|
| 3151 |
|
|
// read data from PHY status register
|
| 3152 |
274 |
tadejm |
wbm_read(`ETH_MIIRX_DATA, phy_data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 3153 |
181 |
mohor |
if (phy_data !== tmp_data)
|
| 3154 |
|
|
begin
|
| 3155 |
|
|
test_fail("Data was not latched correctly in status register");
|
| 3156 |
|
|
fail = fail + 1;
|
| 3157 |
|
|
end
|
| 3158 |
|
|
// read data from MII status register
|
| 3159 |
274 |
tadejm |
wbm_read(`ETH_MIISTATUS, phy_data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 3160 |
181 |
mohor |
if (phy_data[0] === 1'b0)
|
| 3161 |
|
|
begin
|
| 3162 |
|
|
test_fail("Link FAIL bit was not set in the MII status register");
|
| 3163 |
|
|
fail = fail + 1;
|
| 3164 |
|
|
end
|
| 3165 |
|
|
// change saved data
|
| 3166 |
|
|
#Tp tmp_data = tmp_data | 16'h0004; // put bit 2 to ONE
|
| 3167 |
|
|
// set link up
|
| 3168 |
|
|
#Tp eth_phy.link_up_down(1);
|
| 3169 |
|
|
end
|
| 3170 |
|
|
begin
|
| 3171 |
|
|
// Wait for sixth scan
|
| 3172 |
|
|
// wait for serial bus to become active - sixth scan
|
| 3173 |
|
|
wait(Mdio_IO !== 1'bz);
|
| 3174 |
|
|
// wait for serial bus to become inactive - turn-around cycle in sixth scan
|
| 3175 |
|
|
wait(Mdio_IO === 1'bz);
|
| 3176 |
|
|
// wait for serial bus to become active - end of turn-around cycle in sixth scan
|
| 3177 |
|
|
wait(Mdio_IO !== 1'bz);
|
| 3178 |
|
|
// wait for serial bus to become inactive - end of sixth scan
|
| 3179 |
|
|
wait(Mdio_IO === 1'bz);
|
| 3180 |
|
|
end
|
| 3181 |
169 |
mohor |
join
|
| 3182 |
181 |
mohor |
|
| 3183 |
|
|
@(posedge Mdc_O);
|
| 3184 |
169 |
mohor |
// read data from PHY status register
|
| 3185 |
274 |
tadejm |
wbm_read(`ETH_MIIRX_DATA, phy_data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 3186 |
169 |
mohor |
if (phy_data !== tmp_data)
|
| 3187 |
|
|
begin
|
| 3188 |
181 |
mohor |
test_fail("Data was not correctly scaned from status register");
|
| 3189 |
169 |
mohor |
fail = fail + 1;
|
| 3190 |
|
|
end
|
| 3191 |
|
|
// read data from MII status register
|
| 3192 |
274 |
tadejm |
wbm_read(`ETH_MIISTATUS, phy_data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 3193 |
169 |
mohor |
if (phy_data[0] !== 1'b0)
|
| 3194 |
|
|
begin
|
| 3195 |
|
|
test_fail("Link FAIL bit was set in the MII status register");
|
| 3196 |
|
|
fail = fail + 1;
|
| 3197 |
|
|
end
|
| 3198 |
181 |
mohor |
// wait to see if data stayed latched
|
| 3199 |
|
|
repeat(4) @(posedge Mdc_O);
|
| 3200 |
|
|
// read data from PHY status register
|
| 3201 |
274 |
tadejm |
wbm_read(`ETH_MIIRX_DATA, phy_data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 3202 |
181 |
mohor |
if (phy_data !== tmp_data)
|
| 3203 |
169 |
mohor |
begin
|
| 3204 |
181 |
mohor |
test_fail("Data was not correctly scaned from status register");
|
| 3205 |
|
|
fail = fail + 1;
|
| 3206 |
169 |
mohor |
end
|
| 3207 |
181 |
mohor |
// read data from MII status register
|
| 3208 |
274 |
tadejm |
wbm_read(`ETH_MIISTATUS, phy_data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 3209 |
181 |
mohor |
if (phy_data[0] !== 1'b0)
|
| 3210 |
169 |
mohor |
begin
|
| 3211 |
181 |
mohor |
test_fail("Link FAIL bit was set in the MII status register");
|
| 3212 |
|
|
fail = fail + 1;
|
| 3213 |
169 |
mohor |
end
|
| 3214 |
181 |
mohor |
|
| 3215 |
|
|
// STOP SCAN
|
| 3216 |
|
|
#Tp mii_scan_finish; // finish scan operation
|
| 3217 |
|
|
#Tp check_mii_busy; // wait for scan to finish
|
| 3218 |
169 |
mohor |
end
|
| 3219 |
181 |
mohor |
// set PHY to normal mode
|
| 3220 |
|
|
#Tp eth_phy.preamble_suppresed(0);
|
| 3221 |
|
|
// MII mode register
|
| 3222 |
|
|
wbm_write(`ETH_MIIMODER, 32'h0, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 3223 |
|
|
if(fail == 0)
|
| 3224 |
|
|
test_ok;
|
| 3225 |
|
|
else
|
| 3226 |
|
|
fail = 0;
|
| 3227 |
169 |
mohor |
end
|
| 3228 |
|
|
|
| 3229 |
|
|
|
| 3230 |
181 |
mohor |
////////////////////////////////////////////////////////////////////
|
| 3231 |
|
|
//// ////
|
| 3232 |
|
|
//// Test scan status from phy with sliding link-fail bit ////
|
| 3233 |
|
|
//// (with and without preamble) ////
|
| 3234 |
|
|
//// ////
|
| 3235 |
|
|
////////////////////////////////////////////////////////////////////
|
| 3236 |
|
|
if (test_num == 15) //
|
| 3237 |
169 |
mohor |
begin
|
| 3238 |
194 |
tadej |
// TEST 15: SCAN STATUS FROM PHY WITH SLIDING LINK-FAIL BIT ( WITH AND WITHOUT PREAMBLE )
|
| 3239 |
|
|
test_name = "TEST 15: SCAN STATUS FROM PHY WITH SLIDING LINK-FAIL BIT ( WITH AND WITHOUT PREAMBLE )";
|
| 3240 |
|
|
`TIME; $display(" TEST 15: SCAN STATUS FROM PHY WITH SLIDING LINK-FAIL BIT ( WITH AND WITHOUT PREAMBLE )");
|
| 3241 |
181 |
mohor |
|
| 3242 |
|
|
// set address
|
| 3243 |
|
|
reg_addr = 5'h1; // status register
|
| 3244 |
|
|
phy_addr = 5'h1; // correct PHY address
|
| 3245 |
|
|
|
| 3246 |
|
|
// read request
|
| 3247 |
|
|
#Tp mii_read_req(phy_addr, reg_addr);
|
| 3248 |
|
|
check_mii_busy; // wait for read to finish
|
| 3249 |
|
|
// read data from PHY status register - remember LINK-UP status
|
| 3250 |
274 |
tadejm |
wbm_read(`ETH_MIIRX_DATA, tmp_data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 3251 |
181 |
mohor |
|
| 3252 |
|
|
for (i2 = 0; i2 <= 1; i2 = i2 + 1) // choose preamble or not
|
| 3253 |
169 |
mohor |
begin
|
| 3254 |
181 |
mohor |
#Tp eth_phy.preamble_suppresed(i2);
|
| 3255 |
|
|
// MII mode register
|
| 3256 |
|
|
#Tp wbm_write(`ETH_MIIMODER, (`ETH_MIIMODER_NOPRE & {23'h0, i2, 8'h0}), 4'hF, 1, wbm_init_waits,
|
| 3257 |
|
|
wbm_subseq_waits);
|
| 3258 |
|
|
if (i2)
|
| 3259 |
169 |
mohor |
begin
|
| 3260 |
181 |
mohor |
// change saved data when preamble is suppressed
|
| 3261 |
|
|
#Tp tmp_data = tmp_data | 16'h0040; // put bit 6 to ONE
|
| 3262 |
|
|
end
|
| 3263 |
|
|
|
| 3264 |
|
|
i = 0;
|
| 3265 |
|
|
while (i < 80) // delay for sliding of LinkFail bit
|
| 3266 |
|
|
begin
|
| 3267 |
|
|
// first there are two scans
|
| 3268 |
|
|
#Tp cnt = 0;
|
| 3269 |
169 |
mohor |
// scan request
|
| 3270 |
|
|
#Tp mii_scan_req(phy_addr, reg_addr);
|
| 3271 |
181 |
mohor |
#Tp check_mii_scan_valid; // wait for scan to make first data valid
|
| 3272 |
|
|
|
| 3273 |
|
|
// check second scan
|
| 3274 |
169 |
mohor |
fork
|
| 3275 |
181 |
mohor |
begin
|
| 3276 |
|
|
repeat(4) @(posedge Mdc_O);
|
| 3277 |
|
|
// read data from PHY status register
|
| 3278 |
274 |
tadejm |
wbm_read(`ETH_MIIRX_DATA, phy_data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 3279 |
181 |
mohor |
if (phy_data !== tmp_data)
|
| 3280 |
169 |
mohor |
begin
|
| 3281 |
181 |
mohor |
test_fail("Second data was not correctly scaned from status register");
|
| 3282 |
|
|
fail = fail + 1;
|
| 3283 |
169 |
mohor |
end
|
| 3284 |
181 |
mohor |
// read data from MII status register
|
| 3285 |
274 |
tadejm |
wbm_read(`ETH_MIISTATUS, phy_data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 3286 |
181 |
mohor |
if (phy_data[0] !== 1'b0)
|
| 3287 |
|
|
begin
|
| 3288 |
|
|
test_fail("Link FAIL bit was set in the MII status register");
|
| 3289 |
|
|
fail = fail + 1;
|
| 3290 |
|
|
end
|
| 3291 |
|
|
end
|
| 3292 |
|
|
begin
|
| 3293 |
|
|
// Completely check scan
|
| 3294 |
|
|
#Tp cnt = 0;
|
| 3295 |
|
|
// wait for serial bus to become active - second scan
|
| 3296 |
|
|
wait(Mdio_IO !== 1'bz);
|
| 3297 |
|
|
// count transfer length
|
| 3298 |
|
|
while( (Mdio_IO !== 1'bz) || ((cnt == 47) && (i2 == 0)) || ((cnt == 15) && (i2 == 1)) )
|
| 3299 |
|
|
begin
|
| 3300 |
|
|
@(posedge Mdc_O);
|
| 3301 |
|
|
#Tp cnt = cnt + 1;
|
| 3302 |
|
|
end
|
| 3303 |
|
|
// check transfer length
|
| 3304 |
|
|
if (i2) // without preamble
|
| 3305 |
|
|
begin
|
| 3306 |
|
|
if (cnt != 33) // at this value Mdio_IO is HIGH Z
|
| 3307 |
169 |
mohor |
begin
|
| 3308 |
181 |
mohor |
test_fail("Second scan request did not proceed correctly");
|
| 3309 |
|
|
fail = fail + 1;
|
| 3310 |
169 |
mohor |
end
|
| 3311 |
181 |
mohor |
end
|
| 3312 |
|
|
else // with preamble
|
| 3313 |
|
|
begin
|
| 3314 |
|
|
if (cnt != 65) // at this value Mdio_IO is HIGH Z
|
| 3315 |
|
|
begin
|
| 3316 |
|
|
test_fail("Second scan request did not proceed correctly");
|
| 3317 |
|
|
fail = fail + 1;
|
| 3318 |
|
|
end
|
| 3319 |
|
|
end
|
| 3320 |
|
|
end
|
| 3321 |
|
|
join
|
| 3322 |
|
|
// reset counter
|
| 3323 |
|
|
#Tp cnt = 0;
|
| 3324 |
|
|
// SLIDING LINK DOWN and CHECK
|
| 3325 |
|
|
fork
|
| 3326 |
|
|
begin
|
| 3327 |
|
|
// set link down
|
| 3328 |
|
|
repeat(i) @(posedge Mdc_O);
|
| 3329 |
|
|
// set link down
|
| 3330 |
|
|
#Tp eth_phy.link_up_down(0);
|
| 3331 |
|
|
end
|
| 3332 |
|
|
begin
|
| 3333 |
|
|
// check data in MII registers after each scan in this fork statement
|
| 3334 |
169 |
mohor |
if (i2) // without preamble
|
| 3335 |
181 |
mohor |
wait (cnt == 32);
|
| 3336 |
|
|
else // with preamble
|
| 3337 |
|
|
wait (cnt == 64);
|
| 3338 |
|
|
repeat(3) @(posedge Mdc_O);
|
| 3339 |
|
|
// read data from PHY status register
|
| 3340 |
274 |
tadejm |
wbm_read(`ETH_MIIRX_DATA, phy_data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 3341 |
181 |
mohor |
if ( ((i < 49) && !i2) || ((i < 17) && i2) )
|
| 3342 |
169 |
mohor |
begin
|
| 3343 |
181 |
mohor |
if (phy_data !== (tmp_data & 16'hFFFB)) // bit 3 is ZERO
|
| 3344 |
169 |
mohor |
begin
|
| 3345 |
181 |
mohor |
test_fail("Third data was not correctly scaned from status register");
|
| 3346 |
169 |
mohor |
fail = fail + 1;
|
| 3347 |
|
|
end
|
| 3348 |
|
|
end
|
| 3349 |
181 |
mohor |
else
|
| 3350 |
169 |
mohor |
begin
|
| 3351 |
181 |
mohor |
if (phy_data !== tmp_data)
|
| 3352 |
169 |
mohor |
begin
|
| 3353 |
181 |
mohor |
test_fail("Third data was not correctly scaned from status register");
|
| 3354 |
169 |
mohor |
fail = fail + 1;
|
| 3355 |
|
|
end
|
| 3356 |
|
|
end
|
| 3357 |
181 |
mohor |
// read data from MII status register
|
| 3358 |
274 |
tadejm |
wbm_read(`ETH_MIISTATUS, phy_data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 3359 |
181 |
mohor |
if ( ((i < 49) && !i2) || ((i < 17) && i2) )
|
| 3360 |
169 |
mohor |
begin
|
| 3361 |
181 |
mohor |
if (phy_data[0] === 1'b0)
|
| 3362 |
|
|
begin
|
| 3363 |
|
|
test_fail("Link FAIL bit was not set in the MII status register");
|
| 3364 |
|
|
fail = fail + 1;
|
| 3365 |
|
|
end
|
| 3366 |
169 |
mohor |
end
|
| 3367 |
181 |
mohor |
else
|
| 3368 |
169 |
mohor |
begin
|
| 3369 |
181 |
mohor |
if (phy_data[0] !== 1'b0)
|
| 3370 |
169 |
mohor |
begin
|
| 3371 |
181 |
mohor |
test_fail("Link FAIL bit was set in the MII status register");
|
| 3372 |
169 |
mohor |
fail = fail + 1;
|
| 3373 |
|
|
end
|
| 3374 |
|
|
end
|
| 3375 |
181 |
mohor |
end
|
| 3376 |
|
|
begin
|
| 3377 |
|
|
// check length
|
| 3378 |
|
|
for (i3 = 0; i3 <= 1; i3 = i3 + 1) // two scans
|
| 3379 |
169 |
mohor |
begin
|
| 3380 |
181 |
mohor |
#Tp cnt = 0;
|
| 3381 |
|
|
// wait for serial bus to become active if there is more than one scan
|
| 3382 |
|
|
wait(Mdio_IO !== 1'bz);
|
| 3383 |
|
|
// count transfer length
|
| 3384 |
|
|
while( (Mdio_IO !== 1'bz) || ((cnt == 47) && (i2 == 0)) || ((cnt == 15) && (i2 == 1)) )
|
| 3385 |
169 |
mohor |
begin
|
| 3386 |
181 |
mohor |
@(posedge Mdc_O);
|
| 3387 |
|
|
#Tp cnt = cnt + 1;
|
| 3388 |
169 |
mohor |
end
|
| 3389 |
181 |
mohor |
// check transfer length
|
| 3390 |
|
|
if (i2) // without preamble
|
| 3391 |
|
|
begin
|
| 3392 |
|
|
if (cnt != 33) // at this value Mdio_IO is HIGH Z
|
| 3393 |
|
|
begin
|
| 3394 |
|
|
test_fail("3. or 4. scan request did not proceed correctly, while SCAN STOP was written");
|
| 3395 |
|
|
fail = fail + 1;
|
| 3396 |
|
|
end
|
| 3397 |
|
|
end
|
| 3398 |
|
|
else // with preamble
|
| 3399 |
|
|
begin
|
| 3400 |
|
|
if (cnt != 65) // at this value Mdio_IO is HIGH Z
|
| 3401 |
|
|
begin
|
| 3402 |
|
|
test_fail("3. or 4. scan request did not proceed correctly, while SCAN STOP was written");
|
| 3403 |
|
|
fail = fail + 1;
|
| 3404 |
|
|
end
|
| 3405 |
|
|
end
|
| 3406 |
169 |
mohor |
end
|
| 3407 |
|
|
end
|
| 3408 |
|
|
join
|
| 3409 |
181 |
mohor |
// reset counter
|
| 3410 |
|
|
#Tp cnt = 0;
|
| 3411 |
|
|
// check fifth scan and data from fourth scan
|
| 3412 |
|
|
fork
|
| 3413 |
169 |
mohor |
begin
|
| 3414 |
181 |
mohor |
repeat(2) @(posedge Mdc_O);
|
| 3415 |
|
|
// read data from PHY status register
|
| 3416 |
274 |
tadejm |
wbm_read(`ETH_MIIRX_DATA, phy_data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 3417 |
181 |
mohor |
if (phy_data !== (tmp_data & 16'hFFFB)) // bit 3 is ZERO
|
| 3418 |
169 |
mohor |
begin
|
| 3419 |
181 |
mohor |
test_fail("4. data was not correctly scaned from status register");
|
| 3420 |
|
|
fail = fail + 1;
|
| 3421 |
169 |
mohor |
end
|
| 3422 |
181 |
mohor |
// read data from MII status register
|
| 3423 |
274 |
tadejm |
wbm_read(`ETH_MIISTATUS, phy_data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 3424 |
181 |
mohor |
if (phy_data[0] === 1'b0)
|
| 3425 |
169 |
mohor |
begin
|
| 3426 |
181 |
mohor |
test_fail("Link FAIL bit was not set in the MII status register");
|
| 3427 |
169 |
mohor |
fail = fail + 1;
|
| 3428 |
|
|
end
|
| 3429 |
|
|
end
|
| 3430 |
|
|
begin
|
| 3431 |
181 |
mohor |
// Completely check intermediate scan
|
| 3432 |
|
|
#Tp cnt = 0;
|
| 3433 |
|
|
// wait for serial bus to become active - second scan
|
| 3434 |
169 |
mohor |
wait(Mdio_IO !== 1'bz);
|
| 3435 |
|
|
// count transfer length
|
| 3436 |
|
|
while( (Mdio_IO !== 1'bz) || ((cnt == 47) && (i2 == 0)) || ((cnt == 15) && (i2 == 1)) )
|
| 3437 |
|
|
begin
|
| 3438 |
|
|
@(posedge Mdc_O);
|
| 3439 |
|
|
#Tp cnt = cnt + 1;
|
| 3440 |
|
|
end
|
| 3441 |
181 |
mohor |
// check transfer length
|
| 3442 |
|
|
if (i2) // without preamble
|
| 3443 |
169 |
mohor |
begin
|
| 3444 |
181 |
mohor |
if (cnt != 33) // at this value Mdio_IO is HIGH Z
|
| 3445 |
|
|
begin
|
| 3446 |
|
|
test_fail("Fifth scan request did not proceed correctly");
|
| 3447 |
|
|
fail = fail + 1;
|
| 3448 |
|
|
end
|
| 3449 |
169 |
mohor |
end
|
| 3450 |
181 |
mohor |
else // with preamble
|
| 3451 |
|
|
begin
|
| 3452 |
|
|
if (cnt != 65) // at this value Mdio_IO is HIGH Z
|
| 3453 |
|
|
begin
|
| 3454 |
|
|
test_fail("Fifth scan request did not proceed correctly");
|
| 3455 |
|
|
fail = fail + 1;
|
| 3456 |
|
|
end
|
| 3457 |
|
|
end
|
| 3458 |
169 |
mohor |
end
|
| 3459 |
181 |
mohor |
join
|
| 3460 |
|
|
// reset counter
|
| 3461 |
|
|
#Tp cnt = 0;
|
| 3462 |
|
|
// SLIDING LINK UP and CHECK
|
| 3463 |
|
|
fork
|
| 3464 |
169 |
mohor |
begin
|
| 3465 |
181 |
mohor |
// set link up
|
| 3466 |
|
|
repeat(i) @(posedge Mdc_O);
|
| 3467 |
|
|
// set link up
|
| 3468 |
|
|
#Tp eth_phy.link_up_down(1);
|
| 3469 |
169 |
mohor |
end
|
| 3470 |
181 |
mohor |
begin
|
| 3471 |
|
|
// check data in MII registers after each scan in this fork statement
|
| 3472 |
|
|
repeat(2) @(posedge Mdc_O);
|
| 3473 |
|
|
if (i2) // without preamble
|
| 3474 |
|
|
wait (cnt == 32);
|
| 3475 |
|
|
else // with preamble
|
| 3476 |
|
|
wait (cnt == 64);
|
| 3477 |
|
|
repeat(3) @(posedge Mdc_O);
|
| 3478 |
|
|
// read data from PHY status register
|
| 3479 |
274 |
tadejm |
wbm_read(`ETH_MIIRX_DATA, phy_data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 3480 |
181 |
mohor |
if ( ((i < 49) && !i2) || ((i < 17) && i2) )
|
| 3481 |
|
|
begin
|
| 3482 |
|
|
if (phy_data !== tmp_data)
|
| 3483 |
|
|
begin
|
| 3484 |
|
|
test_fail("6. data was not correctly scaned from status register");
|
| 3485 |
|
|
fail = fail + 1;
|
| 3486 |
|
|
end
|
| 3487 |
|
|
end
|
| 3488 |
|
|
else
|
| 3489 |
|
|
begin
|
| 3490 |
|
|
if (phy_data !== (tmp_data & 16'hFFFB)) // bit 3 is ZERO
|
| 3491 |
|
|
begin
|
| 3492 |
|
|
test_fail("6. data was not correctly scaned from status register");
|
| 3493 |
|
|
fail = fail + 1;
|
| 3494 |
|
|
end
|
| 3495 |
|
|
end
|
| 3496 |
|
|
// read data from MII status register
|
| 3497 |
274 |
tadejm |
wbm_read(`ETH_MIISTATUS, phy_data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 3498 |
181 |
mohor |
if ( ((i < 49) && !i2) || ((i < 17) && i2) )
|
| 3499 |
|
|
begin
|
| 3500 |
|
|
if (phy_data[0] !== 1'b0)
|
| 3501 |
|
|
begin
|
| 3502 |
|
|
test_fail("Link FAIL bit was set in the MII status register");
|
| 3503 |
|
|
fail = fail + 1;
|
| 3504 |
|
|
end
|
| 3505 |
|
|
end
|
| 3506 |
|
|
else
|
| 3507 |
|
|
begin
|
| 3508 |
|
|
if (phy_data[0] === 1'b0)
|
| 3509 |
|
|
begin
|
| 3510 |
|
|
test_fail("Link FAIL bit was not set in the MII status register");
|
| 3511 |
|
|
fail = fail + 1;
|
| 3512 |
|
|
end
|
| 3513 |
|
|
end
|
| 3514 |
|
|
end
|
| 3515 |
|
|
begin
|
| 3516 |
|
|
// check length
|
| 3517 |
|
|
for (i3 = 0; i3 <= 1; i3 = i3 + 1) // two scans
|
| 3518 |
|
|
begin
|
| 3519 |
|
|
#Tp cnt = 0;
|
| 3520 |
|
|
// wait for serial bus to become active if there is more than one scan
|
| 3521 |
|
|
wait(Mdio_IO !== 1'bz);
|
| 3522 |
|
|
// count transfer length
|
| 3523 |
|
|
while( (Mdio_IO !== 1'bz) || ((cnt == 47) && (i2 == 0)) || ((cnt == 15) && (i2 == 1)) )
|
| 3524 |
|
|
begin
|
| 3525 |
|
|
@(posedge Mdc_O);
|
| 3526 |
|
|
#Tp cnt = cnt + 1;
|
| 3527 |
|
|
end
|
| 3528 |
|
|
// check transfer length
|
| 3529 |
|
|
if (i2) // without preamble
|
| 3530 |
|
|
begin
|
| 3531 |
|
|
if (cnt != 33) // at this value Mdio_IO is HIGH Z
|
| 3532 |
|
|
begin
|
| 3533 |
|
|
test_fail("Scan request did not proceed correctly, while SCAN STOP was written");
|
| 3534 |
|
|
fail = fail + 1;
|
| 3535 |
|
|
end
|
| 3536 |
|
|
end
|
| 3537 |
|
|
else // with preamble
|
| 3538 |
|
|
begin
|
| 3539 |
|
|
if (cnt != 65) // at this value Mdio_IO is HIGH Z
|
| 3540 |
|
|
begin
|
| 3541 |
|
|
test_fail("Scan request did not proceed correctly, while SCAN STOP was written");
|
| 3542 |
|
|
fail = fail + 1;
|
| 3543 |
|
|
end
|
| 3544 |
|
|
end
|
| 3545 |
|
|
end
|
| 3546 |
|
|
end
|
| 3547 |
|
|
join
|
| 3548 |
|
|
// check last scan
|
| 3549 |
|
|
repeat(4) @(posedge Mdc_O);
|
| 3550 |
|
|
// read data from PHY status register
|
| 3551 |
274 |
tadejm |
wbm_read(`ETH_MIIRX_DATA, phy_data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 3552 |
181 |
mohor |
if (phy_data !== tmp_data)
|
| 3553 |
|
|
begin
|
| 3554 |
|
|
test_fail("7. data was not correctly scaned from status register");
|
| 3555 |
|
|
fail = fail + 1;
|
| 3556 |
169 |
mohor |
end
|
| 3557 |
181 |
mohor |
// read data from MII status register
|
| 3558 |
274 |
tadejm |
wbm_read(`ETH_MIISTATUS, phy_data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 3559 |
181 |
mohor |
if (phy_data[0] !== 1'b0)
|
| 3560 |
|
|
begin
|
| 3561 |
|
|
test_fail("Link FAIL bit was set in the MII status register");
|
| 3562 |
|
|
fail = fail + 1;
|
| 3563 |
|
|
end
|
| 3564 |
|
|
|
| 3565 |
|
|
#Tp mii_scan_finish; // finish scan operation
|
| 3566 |
|
|
#Tp check_mii_busy; // wait for scan to finish
|
| 3567 |
|
|
#Tp;
|
| 3568 |
|
|
// set delay of writing the command
|
| 3569 |
|
|
if (i2) // without preamble
|
| 3570 |
|
|
begin
|
| 3571 |
|
|
case(i)
|
| 3572 |
|
|
0, 1, 2, 3, 4: i = i + 1;
|
| 3573 |
|
|
13, 14, 15, 16, 17,
|
| 3574 |
|
|
18, 19, 20, 21, 22,
|
| 3575 |
|
|
23, 24, 25, 26, 27,
|
| 3576 |
|
|
28, 29, 30, 31, 32,
|
| 3577 |
|
|
33, 34, 35: i = i + 1;
|
| 3578 |
|
|
36: i = 80;
|
| 3579 |
|
|
default: i = 13;
|
| 3580 |
|
|
endcase
|
| 3581 |
|
|
end
|
| 3582 |
169 |
mohor |
else // with preamble
|
| 3583 |
|
|
begin
|
| 3584 |
181 |
mohor |
case(i)
|
| 3585 |
|
|
0, 1, 2, 3, 4: i = i + 1;
|
| 3586 |
|
|
45, 46, 47, 48, 49,
|
| 3587 |
|
|
50, 51, 52, 53, 54,
|
| 3588 |
|
|
55, 56, 57, 58, 59,
|
| 3589 |
|
|
60, 61, 62, 63, 64,
|
| 3590 |
|
|
65, 66, 67: i = i + 1;
|
| 3591 |
|
|
68: i = 80;
|
| 3592 |
|
|
default: i = 45;
|
| 3593 |
|
|
endcase
|
| 3594 |
169 |
mohor |
end
|
| 3595 |
181 |
mohor |
@(posedge wb_clk);
|
| 3596 |
|
|
#Tp;
|
| 3597 |
169 |
mohor |
end
|
| 3598 |
|
|
end
|
| 3599 |
181 |
mohor |
// set PHY to normal mode
|
| 3600 |
|
|
#Tp eth_phy.preamble_suppresed(0);
|
| 3601 |
|
|
// MII mode register
|
| 3602 |
|
|
wbm_write(`ETH_MIIMODER, 32'h0, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 3603 |
|
|
if(fail == 0)
|
| 3604 |
|
|
test_ok;
|
| 3605 |
|
|
else
|
| 3606 |
|
|
fail = 0;
|
| 3607 |
169 |
mohor |
end
|
| 3608 |
|
|
|
| 3609 |
|
|
|
| 3610 |
181 |
mohor |
////////////////////////////////////////////////////////////////////
|
| 3611 |
|
|
//// ////
|
| 3612 |
|
|
//// Test sliding stop scan command immediately after scan ////
|
| 3613 |
|
|
//// request (with and without preamble) ////
|
| 3614 |
|
|
//// ////
|
| 3615 |
|
|
////////////////////////////////////////////////////////////////////
|
| 3616 |
|
|
if (test_num == 16) //
|
| 3617 |
116 |
mohor |
begin
|
| 3618 |
194 |
tadej |
// TEST 16: SLIDING STOP SCAN COMMAND IMMEDIATELY AFTER SCAN REQUEST ( WITH AND WITHOUT PREAMBLE )
|
| 3619 |
|
|
test_name = "TEST 16: SLIDING STOP SCAN COMMAND IMMEDIATELY AFTER SCAN REQUEST ( WITH AND WITHOUT PREAMBLE )";
|
| 3620 |
181 |
mohor |
`TIME;
|
| 3621 |
194 |
tadej |
$display(" TEST 16: SLIDING STOP SCAN COMMAND IMMEDIATELY AFTER SCAN REQUEST ( WITH AND WITHOUT PREAMBLE )");
|
| 3622 |
181 |
mohor |
|
| 3623 |
|
|
for (i2 = 0; i2 <= 1; i2 = i2 + 1) // choose preamble or not
|
| 3624 |
169 |
mohor |
begin
|
| 3625 |
181 |
mohor |
#Tp eth_phy.preamble_suppresed(i2);
|
| 3626 |
|
|
// MII mode register
|
| 3627 |
|
|
wbm_write(`ETH_MIIMODER, (`ETH_MIIMODER_NOPRE & {23'h0, i2, 8'h0}), 4'hF, 1, wbm_init_waits,
|
| 3628 |
|
|
wbm_subseq_waits);
|
| 3629 |
|
|
i = 0;
|
| 3630 |
|
|
cnt = 0;
|
| 3631 |
|
|
while (i < 80) // delay for sliding of writing a STOP SCAN command
|
| 3632 |
169 |
mohor |
begin
|
| 3633 |
181 |
mohor |
for (i3 = 0; i3 <= 1; i3 = i3 + 1) // choose read or write after scan will be finished
|
| 3634 |
169 |
mohor |
begin
|
| 3635 |
181 |
mohor |
// set address
|
| 3636 |
|
|
reg_addr = 5'h0; // control register
|
| 3637 |
|
|
phy_addr = 5'h1; // correct PHY address
|
| 3638 |
|
|
cnt = 0;
|
| 3639 |
|
|
// scan request
|
| 3640 |
|
|
#Tp mii_scan_req(phy_addr, reg_addr);
|
| 3641 |
|
|
fork
|
| 3642 |
|
|
begin
|
| 3643 |
|
|
repeat(i) @(posedge Mdc_O);
|
| 3644 |
|
|
// write command 0x0 into MII command register
|
| 3645 |
|
|
// MII command written while scan in progress
|
| 3646 |
|
|
wbm_write(`ETH_MIICOMMAND, 32'h0, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 3647 |
|
|
@(posedge wb_clk);
|
| 3648 |
|
|
#Tp check_mii_busy; // wait for scan to finish
|
| 3649 |
|
|
@(posedge wb_clk);
|
| 3650 |
|
|
disable check;
|
| 3651 |
|
|
end
|
| 3652 |
|
|
begin: check
|
| 3653 |
|
|
// wait for serial bus to become active
|
| 3654 |
|
|
wait(Mdio_IO !== 1'bz);
|
| 3655 |
|
|
// count transfer length
|
| 3656 |
|
|
while( (Mdio_IO !== 1'bz) || ((cnt == 47) && (i2 == 0)) || ((cnt == 15) && (i2 == 1)) )
|
| 3657 |
|
|
begin
|
| 3658 |
|
|
@(posedge Mdc_O);
|
| 3659 |
|
|
#Tp cnt = cnt + 1;
|
| 3660 |
|
|
end
|
| 3661 |
|
|
// check transfer length
|
| 3662 |
|
|
if (i2) // without preamble
|
| 3663 |
|
|
begin
|
| 3664 |
|
|
if (cnt != 33) // at this value Mdio_IO is HIGH Z
|
| 3665 |
|
|
begin
|
| 3666 |
|
|
test_fail("First scan request did not proceed correctly, while SCAN STOP was written");
|
| 3667 |
|
|
fail = fail + 1;
|
| 3668 |
|
|
end
|
| 3669 |
|
|
end
|
| 3670 |
|
|
else // with preamble
|
| 3671 |
|
|
begin
|
| 3672 |
|
|
if (cnt != 65) // at this value Mdio_IO is HIGH Z
|
| 3673 |
|
|
begin
|
| 3674 |
|
|
test_fail("First scan request did not proceed correctly, while SCAN STOP was written");
|
| 3675 |
|
|
fail = fail + 1;
|
| 3676 |
|
|
end
|
| 3677 |
|
|
end
|
| 3678 |
|
|
cnt = 0;
|
| 3679 |
|
|
// wait for serial bus to become active if there is more than one scan
|
| 3680 |
|
|
wait(Mdio_IO !== 1'bz);
|
| 3681 |
|
|
// count transfer length
|
| 3682 |
|
|
while( (Mdio_IO !== 1'bz) || ((cnt == 47) && (i2 == 0)) || ((cnt == 15) && (i2 == 1)) )
|
| 3683 |
|
|
begin
|
| 3684 |
|
|
@(posedge Mdc_O);
|
| 3685 |
|
|
#Tp cnt = cnt + 1;
|
| 3686 |
|
|
end
|
| 3687 |
|
|
// check transfer length
|
| 3688 |
|
|
if (i2) // without preamble
|
| 3689 |
|
|
begin
|
| 3690 |
|
|
if (cnt != 33) // at this value Mdio_IO is HIGH Z
|
| 3691 |
|
|
begin
|
| 3692 |
|
|
test_fail("First scan request did not proceed correctly, while SCAN STOP was written");
|
| 3693 |
|
|
fail = fail + 1;
|
| 3694 |
|
|
end
|
| 3695 |
|
|
end
|
| 3696 |
|
|
else // with preamble
|
| 3697 |
|
|
begin
|
| 3698 |
|
|
if (cnt != 65) // at this value Mdio_IO is HIGH Z
|
| 3699 |
|
|
begin
|
| 3700 |
|
|
test_fail("First scan request did not proceed correctly, while SCAN STOP was written");
|
| 3701 |
|
|
fail = fail + 1;
|
| 3702 |
|
|
end
|
| 3703 |
|
|
end
|
| 3704 |
|
|
end
|
| 3705 |
|
|
join
|
| 3706 |
|
|
// check the BUSY signal to see if the bus is still IDLE
|
| 3707 |
|
|
for (i1 = 0; i1 < 8; i1 = i1 + 1)
|
| 3708 |
|
|
check_mii_busy; // wait for bus to become idle
|
| 3709 |
|
|
|
| 3710 |
|
|
// try normal write or read after scan was finished
|
| 3711 |
|
|
phy_data = {8'h7D, (i[7:0] + 1)};
|
| 3712 |
|
|
cnt = 0;
|
| 3713 |
|
|
if (i3 == 0) // write after scan
|
| 3714 |
169 |
mohor |
begin
|
| 3715 |
181 |
mohor |
// write request
|
| 3716 |
|
|
#Tp mii_write_req(phy_addr, reg_addr, phy_data);
|
| 3717 |
|
|
// wait for serial bus to become active
|
| 3718 |
|
|
wait(Mdio_IO !== 1'bz);
|
| 3719 |
|
|
// count transfer length
|
| 3720 |
|
|
while(Mdio_IO !== 1'bz)
|
| 3721 |
|
|
begin
|
| 3722 |
|
|
@(posedge Mdc_O);
|
| 3723 |
|
|
#Tp cnt = cnt + 1;
|
| 3724 |
|
|
end
|
| 3725 |
169 |
mohor |
@(posedge Mdc_O);
|
| 3726 |
181 |
mohor |
// read request
|
| 3727 |
|
|
#Tp mii_read_req(phy_addr, reg_addr);
|
| 3728 |
|
|
check_mii_busy; // wait for read to finish
|
| 3729 |
|
|
// read and check data
|
| 3730 |
274 |
tadejm |
wbm_read(`ETH_MIIRX_DATA, tmp_data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 3731 |
181 |
mohor |
if (phy_data !== tmp_data)
|
| 3732 |
169 |
mohor |
begin
|
| 3733 |
181 |
mohor |
test_fail("Data was not correctly written into OR read from PHY register - control register");
|
| 3734 |
169 |
mohor |
fail = fail + 1;
|
| 3735 |
|
|
end
|
| 3736 |
|
|
end
|
| 3737 |
181 |
mohor |
else // read after scan
|
| 3738 |
169 |
mohor |
begin
|
| 3739 |
181 |
mohor |
// read request
|
| 3740 |
|
|
#Tp mii_read_req(phy_addr, reg_addr);
|
| 3741 |
|
|
// wait for serial bus to become active
|
| 3742 |
|
|
wait(Mdio_IO !== 1'bz);
|
| 3743 |
|
|
// count transfer length
|
| 3744 |
|
|
while( (Mdio_IO !== 1'bz) || ((cnt == 47) && (i2 == 0)) || ((cnt == 15) && (i2 == 1)) )
|
| 3745 |
169 |
mohor |
begin
|
| 3746 |
181 |
mohor |
@(posedge Mdc_O);
|
| 3747 |
|
|
#Tp cnt = cnt + 1;
|
| 3748 |
|
|
end
|
| 3749 |
|
|
@(posedge Mdc_O);
|
| 3750 |
|
|
check_mii_busy; // wait for read to finish
|
| 3751 |
|
|
// read and check data
|
| 3752 |
274 |
tadejm |
wbm_read(`ETH_MIIRX_DATA, tmp_data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 3753 |
181 |
mohor |
if (phy_data !== tmp_data)
|
| 3754 |
|
|
begin
|
| 3755 |
|
|
test_fail("Data was not correctly written into OR read from PHY register - control register");
|
| 3756 |
169 |
mohor |
fail = fail + 1;
|
| 3757 |
|
|
end
|
| 3758 |
|
|
end
|
| 3759 |
181 |
mohor |
// check if transfer was a proper length
|
| 3760 |
169 |
mohor |
if (i2) // without preamble
|
| 3761 |
|
|
begin
|
| 3762 |
|
|
if (cnt != 33) // at this value Mdio_IO is HIGH Z
|
| 3763 |
|
|
begin
|
| 3764 |
181 |
mohor |
test_fail("New request did not proceed correctly, after scan request");
|
| 3765 |
169 |
mohor |
fail = fail + 1;
|
| 3766 |
|
|
end
|
| 3767 |
|
|
end
|
| 3768 |
|
|
else // with preamble
|
| 3769 |
|
|
begin
|
| 3770 |
|
|
if (cnt != 65) // at this value Mdio_IO is HIGH Z
|
| 3771 |
|
|
begin
|
| 3772 |
181 |
mohor |
test_fail("New request did not proceed correctly, after scan request");
|
| 3773 |
169 |
mohor |
fail = fail + 1;
|
| 3774 |
|
|
end
|
| 3775 |
|
|
end
|
| 3776 |
|
|
end
|
| 3777 |
181 |
mohor |
#Tp;
|
| 3778 |
|
|
// set delay of writing the command
|
| 3779 |
|
|
if (i2) // without preamble
|
| 3780 |
|
|
begin
|
| 3781 |
|
|
case(i)
|
| 3782 |
|
|
0, 1: i = i + 1;
|
| 3783 |
|
|
18, 19, 20, 21, 22,
|
| 3784 |
|
|
23, 24, 25, 26, 27,
|
| 3785 |
|
|
28, 29, 30, 31, 32,
|
| 3786 |
|
|
33, 34, 35: i = i + 1;
|
| 3787 |
|
|
36: i = 80;
|
| 3788 |
|
|
default: i = 18;
|
| 3789 |
|
|
endcase
|
| 3790 |
|
|
end
|
| 3791 |
|
|
else // with preamble
|
| 3792 |
|
|
begin
|
| 3793 |
|
|
case(i)
|
| 3794 |
|
|
0, 1: i = i + 1;
|
| 3795 |
|
|
50, 51, 52, 53, 54,
|
| 3796 |
|
|
55, 56, 57, 58, 59,
|
| 3797 |
|
|
60, 61, 62, 63, 64,
|
| 3798 |
|
|
65, 66, 67: i = i + 1;
|
| 3799 |
|
|
68: i = 80;
|
| 3800 |
|
|
default: i = 50;
|
| 3801 |
|
|
endcase
|
| 3802 |
|
|
end
|
| 3803 |
|
|
@(posedge wb_clk);
|
| 3804 |
|
|
end
|
| 3805 |
|
|
end
|
| 3806 |
|
|
// set PHY to normal mode
|
| 3807 |
|
|
#Tp eth_phy.preamble_suppresed(0);
|
| 3808 |
|
|
// MII mode register
|
| 3809 |
|
|
wbm_write(`ETH_MIIMODER, 32'h0, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 3810 |
|
|
if(fail == 0)
|
| 3811 |
|
|
test_ok;
|
| 3812 |
|
|
else
|
| 3813 |
|
|
fail = 0;
|
| 3814 |
|
|
end
|
| 3815 |
169 |
mohor |
|
| 3816 |
181 |
mohor |
|
| 3817 |
|
|
////////////////////////////////////////////////////////////////////
|
| 3818 |
|
|
//// ////
|
| 3819 |
|
|
//// Test sliding stop scan command after 2. scan (with and ////
|
| 3820 |
|
|
//// without preamble) ////
|
| 3821 |
|
|
//// ////
|
| 3822 |
|
|
////////////////////////////////////////////////////////////////////
|
| 3823 |
|
|
if (test_num == 17) //
|
| 3824 |
|
|
begin
|
| 3825 |
194 |
tadej |
// TEST 17: SLIDING STOP SCAN COMMAND AFTER 2. SCAN ( WITH AND WITHOUT PREAMBLE )
|
| 3826 |
|
|
test_name = "TEST 17: SLIDING STOP SCAN COMMAND AFTER 2. SCAN ( WITH AND WITHOUT PREAMBLE )";
|
| 3827 |
|
|
`TIME; $display(" TEST 17: SLIDING STOP SCAN COMMAND AFTER 2. SCAN ( WITH AND WITHOUT PREAMBLE )");
|
| 3828 |
181 |
mohor |
|
| 3829 |
|
|
for (i2 = 0; i2 <= 1; i2 = i2 + 1) // choose preamble or not
|
| 3830 |
|
|
begin
|
| 3831 |
|
|
#Tp eth_phy.preamble_suppresed(i2);
|
| 3832 |
|
|
// MII mode register
|
| 3833 |
|
|
wbm_write(`ETH_MIIMODER, (`ETH_MIIMODER_NOPRE & {23'h0, i2, 8'h0}), 4'hF, 1, wbm_init_waits,
|
| 3834 |
|
|
wbm_subseq_waits);
|
| 3835 |
|
|
|
| 3836 |
|
|
i = 0;
|
| 3837 |
|
|
cnt = 0;
|
| 3838 |
|
|
while (i < 80) // delay for sliding of writing a STOP SCAN command
|
| 3839 |
|
|
begin
|
| 3840 |
|
|
for (i3 = 0; i3 <= 1; i3 = i3 + 1) // choose read or write after scan will be finished
|
| 3841 |
|
|
begin
|
| 3842 |
|
|
// first there are two scans
|
| 3843 |
|
|
// set address
|
| 3844 |
|
|
reg_addr = 5'h0; // control register
|
| 3845 |
|
|
phy_addr = 5'h1; // correct PHY address
|
| 3846 |
|
|
cnt = 0;
|
| 3847 |
|
|
// scan request
|
| 3848 |
|
|
#Tp mii_scan_req(phy_addr, reg_addr);
|
| 3849 |
|
|
// wait and check first 2 scans
|
| 3850 |
169 |
mohor |
begin
|
| 3851 |
|
|
// wait for serial bus to become active
|
| 3852 |
|
|
wait(Mdio_IO !== 1'bz);
|
| 3853 |
|
|
// count transfer length
|
| 3854 |
|
|
while( (Mdio_IO !== 1'bz) || ((cnt == 47) && (i2 == 0)) || ((cnt == 15) && (i2 == 1)) )
|
| 3855 |
|
|
begin
|
| 3856 |
|
|
@(posedge Mdc_O);
|
| 3857 |
|
|
#Tp cnt = cnt + 1;
|
| 3858 |
|
|
end
|
| 3859 |
|
|
// check transfer length
|
| 3860 |
|
|
if (i2) // without preamble
|
| 3861 |
|
|
begin
|
| 3862 |
|
|
if (cnt != 33) // at this value Mdio_IO is HIGH Z
|
| 3863 |
|
|
begin
|
| 3864 |
|
|
test_fail("First scan request did not proceed correctly, while SCAN STOP was written");
|
| 3865 |
|
|
fail = fail + 1;
|
| 3866 |
|
|
end
|
| 3867 |
|
|
end
|
| 3868 |
|
|
else // with preamble
|
| 3869 |
|
|
begin
|
| 3870 |
|
|
if (cnt != 65) // at this value Mdio_IO is HIGH Z
|
| 3871 |
|
|
begin
|
| 3872 |
|
|
test_fail("First scan request did not proceed correctly, while SCAN STOP was written");
|
| 3873 |
|
|
fail = fail + 1;
|
| 3874 |
|
|
end
|
| 3875 |
|
|
end
|
| 3876 |
|
|
cnt = 0;
|
| 3877 |
|
|
// wait for serial bus to become active if there is more than one scan
|
| 3878 |
|
|
wait(Mdio_IO !== 1'bz);
|
| 3879 |
|
|
// count transfer length
|
| 3880 |
|
|
while( (Mdio_IO !== 1'bz) || ((cnt == 47) && (i2 == 0)) || ((cnt == 15) && (i2 == 1)) )
|
| 3881 |
|
|
begin
|
| 3882 |
|
|
@(posedge Mdc_O);
|
| 3883 |
|
|
#Tp cnt = cnt + 1;
|
| 3884 |
|
|
end
|
| 3885 |
|
|
// check transfer length
|
| 3886 |
|
|
if (i2) // without preamble
|
| 3887 |
|
|
begin
|
| 3888 |
|
|
if (cnt != 33) // at this value Mdio_IO is HIGH Z
|
| 3889 |
|
|
begin
|
| 3890 |
|
|
test_fail("First scan request did not proceed correctly, while SCAN STOP was written");
|
| 3891 |
|
|
fail = fail + 1;
|
| 3892 |
|
|
end
|
| 3893 |
|
|
end
|
| 3894 |
|
|
else // with preamble
|
| 3895 |
|
|
begin
|
| 3896 |
|
|
if (cnt != 65) // at this value Mdio_IO is HIGH Z
|
| 3897 |
|
|
begin
|
| 3898 |
|
|
test_fail("First scan request did not proceed correctly, while SCAN STOP was written");
|
| 3899 |
|
|
fail = fail + 1;
|
| 3900 |
|
|
end
|
| 3901 |
|
|
end
|
| 3902 |
|
|
end
|
| 3903 |
|
|
|
| 3904 |
181 |
mohor |
// reset counter
|
| 3905 |
|
|
cnt = 0;
|
| 3906 |
|
|
fork
|
| 3907 |
|
|
begin
|
| 3908 |
|
|
repeat(i) @(posedge Mdc_O);
|
| 3909 |
|
|
// write command 0x0 into MII command register
|
| 3910 |
|
|
// MII command written while scan in progress
|
| 3911 |
|
|
wbm_write(`ETH_MIICOMMAND, 32'h0, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 3912 |
|
|
@(posedge wb_clk);
|
| 3913 |
|
|
#Tp check_mii_busy; // wait for scan to finish
|
| 3914 |
|
|
@(posedge wb_clk);
|
| 3915 |
|
|
disable check_3;
|
| 3916 |
|
|
end
|
| 3917 |
|
|
begin: check_3
|
| 3918 |
|
|
// wait for serial bus to become active
|
| 3919 |
|
|
wait(Mdio_IO !== 1'bz);
|
| 3920 |
|
|
// count transfer length
|
| 3921 |
|
|
while( (Mdio_IO !== 1'bz) || ((cnt == 47) && (i2 == 0)) || ((cnt == 15) && (i2 == 1)) )
|
| 3922 |
|
|
begin
|
| 3923 |
|
|
@(posedge Mdc_O);
|
| 3924 |
|
|
#Tp cnt = cnt + 1;
|
| 3925 |
|
|
end
|
| 3926 |
|
|
// check transfer length
|
| 3927 |
|
|
if (i2) // without preamble
|
| 3928 |
|
|
begin
|
| 3929 |
|
|
if (cnt != 33) // at this value Mdio_IO is HIGH Z
|
| 3930 |
|
|
begin
|
| 3931 |
|
|
test_fail("First scan request did not proceed correctly, while SCAN STOP was written");
|
| 3932 |
|
|
fail = fail + 1;
|
| 3933 |
|
|
end
|
| 3934 |
|
|
end
|
| 3935 |
|
|
else // with preamble
|
| 3936 |
|
|
begin
|
| 3937 |
|
|
if (cnt != 65) // at this value Mdio_IO is HIGH Z
|
| 3938 |
|
|
begin
|
| 3939 |
|
|
test_fail("First scan request did not proceed correctly, while SCAN STOP was written");
|
| 3940 |
|
|
fail = fail + 1;
|
| 3941 |
|
|
end
|
| 3942 |
|
|
end
|
| 3943 |
|
|
cnt = 0;
|
| 3944 |
|
|
// wait for serial bus to become active if there is more than one scan
|
| 3945 |
|
|
wait(Mdio_IO !== 1'bz);
|
| 3946 |
|
|
// count transfer length
|
| 3947 |
|
|
while( (Mdio_IO !== 1'bz) || ((cnt == 47) && (i2 == 0)) || ((cnt == 15) && (i2 == 1)) )
|
| 3948 |
|
|
begin
|
| 3949 |
|
|
@(posedge Mdc_O);
|
| 3950 |
|
|
#Tp cnt = cnt + 1;
|
| 3951 |
|
|
end
|
| 3952 |
|
|
// check transfer length
|
| 3953 |
|
|
if (i2) // without preamble
|
| 3954 |
|
|
begin
|
| 3955 |
|
|
if (cnt != 33) // at this value Mdio_IO is HIGH Z
|
| 3956 |
|
|
begin
|
| 3957 |
|
|
test_fail("First scan request did not proceed correctly, while SCAN STOP was written");
|
| 3958 |
|
|
fail = fail + 1;
|
| 3959 |
|
|
end
|
| 3960 |
|
|
end
|
| 3961 |
|
|
else // with preamble
|
| 3962 |
|
|
begin
|
| 3963 |
|
|
if (cnt != 65) // at this value Mdio_IO is HIGH Z
|
| 3964 |
|
|
begin
|
| 3965 |
|
|
test_fail("First scan request did not proceed correctly, while SCAN STOP was written");
|
| 3966 |
|
|
fail = fail + 1;
|
| 3967 |
|
|
end
|
| 3968 |
|
|
end
|
| 3969 |
|
|
end
|
| 3970 |
|
|
join
|
| 3971 |
|
|
// check the BUSY signal to see if the bus is still IDLE
|
| 3972 |
|
|
for (i1 = 0; i1 < 8; i1 = i1 + 1)
|
| 3973 |
|
|
check_mii_busy; // wait for bus to become idle
|
| 3974 |
|
|
|
| 3975 |
|
|
// try normal write or read after scan was finished
|
| 3976 |
|
|
phy_data = {8'h7D, (i[7:0] + 1)};
|
| 3977 |
|
|
cnt = 0;
|
| 3978 |
|
|
if (i3 == 0) // write after scan
|
| 3979 |
169 |
mohor |
begin
|
| 3980 |
181 |
mohor |
// write request
|
| 3981 |
|
|
#Tp mii_write_req(phy_addr, reg_addr, phy_data);
|
| 3982 |
|
|
// wait for serial bus to become active
|
| 3983 |
|
|
wait(Mdio_IO !== 1'bz);
|
| 3984 |
|
|
// count transfer length
|
| 3985 |
|
|
while(Mdio_IO !== 1'bz)
|
| 3986 |
|
|
begin
|
| 3987 |
|
|
@(posedge Mdc_O);
|
| 3988 |
|
|
#Tp cnt = cnt + 1;
|
| 3989 |
|
|
end
|
| 3990 |
169 |
mohor |
@(posedge Mdc_O);
|
| 3991 |
181 |
mohor |
// read request
|
| 3992 |
|
|
#Tp mii_read_req(phy_addr, reg_addr);
|
| 3993 |
|
|
check_mii_busy; // wait for read to finish
|
| 3994 |
|
|
// read and check data
|
| 3995 |
274 |
tadejm |
wbm_read(`ETH_MIIRX_DATA, tmp_data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 3996 |
181 |
mohor |
if (phy_data !== tmp_data)
|
| 3997 |
|
|
begin
|
| 3998 |
|
|
test_fail("Data was not correctly written into OR read from PHY register - control register");
|
| 3999 |
|
|
fail = fail + 1;
|
| 4000 |
|
|
end
|
| 4001 |
169 |
mohor |
end
|
| 4002 |
181 |
mohor |
else // read after scan
|
| 4003 |
169 |
mohor |
begin
|
| 4004 |
181 |
mohor |
// read request
|
| 4005 |
|
|
#Tp mii_read_req(phy_addr, reg_addr);
|
| 4006 |
|
|
// wait for serial bus to become active
|
| 4007 |
|
|
wait(Mdio_IO !== 1'bz);
|
| 4008 |
|
|
// count transfer length
|
| 4009 |
|
|
while( (Mdio_IO !== 1'bz) || ((cnt == 47) && (i2 == 0)) || ((cnt == 15) && (i2 == 1)) )
|
| 4010 |
|
|
begin
|
| 4011 |
|
|
@(posedge Mdc_O);
|
| 4012 |
|
|
#Tp cnt = cnt + 1;
|
| 4013 |
|
|
end
|
| 4014 |
|
|
@(posedge Mdc_O);
|
| 4015 |
|
|
check_mii_busy; // wait for read to finish
|
| 4016 |
|
|
// read and check data
|
| 4017 |
274 |
tadejm |
wbm_read(`ETH_MIIRX_DATA, tmp_data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 4018 |
181 |
mohor |
if (phy_data !== tmp_data)
|
| 4019 |
|
|
begin
|
| 4020 |
|
|
test_fail("Data was not correctly written into OR read from PHY register - control register");
|
| 4021 |
|
|
fail = fail + 1;
|
| 4022 |
|
|
end
|
| 4023 |
169 |
mohor |
end
|
| 4024 |
181 |
mohor |
// check if transfer was a proper length
|
| 4025 |
|
|
if (i2) // without preamble
|
| 4026 |
169 |
mohor |
begin
|
| 4027 |
181 |
mohor |
if (cnt != 33) // at this value Mdio_IO is HIGH Z
|
| 4028 |
|
|
begin
|
| 4029 |
|
|
test_fail("New request did not proceed correctly, after scan request");
|
| 4030 |
|
|
fail = fail + 1;
|
| 4031 |
|
|
end
|
| 4032 |
169 |
mohor |
end
|
| 4033 |
181 |
mohor |
else // with preamble
|
| 4034 |
169 |
mohor |
begin
|
| 4035 |
181 |
mohor |
if (cnt != 65) // at this value Mdio_IO is HIGH Z
|
| 4036 |
|
|
begin
|
| 4037 |
|
|
test_fail("New request did not proceed correctly, after scan request");
|
| 4038 |
|
|
fail = fail + 1;
|
| 4039 |
|
|
end
|
| 4040 |
169 |
mohor |
end
|
| 4041 |
|
|
end
|
| 4042 |
181 |
mohor |
#Tp;
|
| 4043 |
|
|
// set delay of writing the command
|
| 4044 |
169 |
mohor |
if (i2) // without preamble
|
| 4045 |
|
|
begin
|
| 4046 |
181 |
mohor |
case(i)
|
| 4047 |
|
|
0, 1: i = i + 1;
|
| 4048 |
|
|
18, 19, 20, 21, 22,
|
| 4049 |
|
|
23, 24, 25, 26, 27,
|
| 4050 |
|
|
28, 29, 30, 31, 32,
|
| 4051 |
|
|
33, 34, 35: i = i + 1;
|
| 4052 |
|
|
36: i = 80;
|
| 4053 |
|
|
default: i = 18;
|
| 4054 |
|
|
endcase
|
| 4055 |
169 |
mohor |
end
|
| 4056 |
|
|
else // with preamble
|
| 4057 |
|
|
begin
|
| 4058 |
181 |
mohor |
case(i)
|
| 4059 |
|
|
0, 1: i = i + 1;
|
| 4060 |
|
|
50, 51, 52, 53, 54,
|
| 4061 |
|
|
55, 56, 57, 58, 59,
|
| 4062 |
|
|
60, 61, 62, 63, 64,
|
| 4063 |
|
|
65, 66, 67: i = i + 1;
|
| 4064 |
|
|
68: i = 80;
|
| 4065 |
|
|
default: i = 50;
|
| 4066 |
|
|
endcase
|
| 4067 |
169 |
mohor |
end
|
| 4068 |
181 |
mohor |
@(posedge wb_clk);
|
| 4069 |
116 |
mohor |
end
|
| 4070 |
|
|
end
|
| 4071 |
181 |
mohor |
// set PHY to normal mode
|
| 4072 |
|
|
#Tp eth_phy.preamble_suppresed(0);
|
| 4073 |
|
|
// MII mode register
|
| 4074 |
|
|
wbm_write(`ETH_MIIMODER, 32'h0, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 4075 |
|
|
if(fail == 0)
|
| 4076 |
|
|
test_ok;
|
| 4077 |
|
|
else
|
| 4078 |
|
|
fail = 0;
|
| 4079 |
169 |
mohor |
end
|
| 4080 |
116 |
mohor |
|
| 4081 |
181 |
mohor |
end // for (test_num=start_task; test_num <= end_task; test_num=test_num+1)
|
| 4082 |
|
|
|
| 4083 |
169 |
mohor |
end
|
| 4084 |
|
|
endtask // test_mii
|
| 4085 |
|
|
|
| 4086 |
|
|
|
| 4087 |
|
|
task test_mac_full_duplex_transmit;
|
| 4088 |
|
|
input [31:0] start_task;
|
| 4089 |
|
|
input [31:0] end_task;
|
| 4090 |
|
|
integer bit_start_1;
|
| 4091 |
|
|
integer bit_end_1;
|
| 4092 |
|
|
integer bit_start_2;
|
| 4093 |
|
|
integer bit_end_2;
|
| 4094 |
|
|
integer num_of_reg;
|
| 4095 |
209 |
tadejm |
integer num_of_frames;
|
| 4096 |
|
|
integer num_of_bd;
|
| 4097 |
169 |
mohor |
integer i_addr;
|
| 4098 |
|
|
integer i_data;
|
| 4099 |
|
|
integer i_length;
|
| 4100 |
209 |
tadejm |
integer tmp_len;
|
| 4101 |
|
|
integer tmp_bd;
|
| 4102 |
|
|
integer tmp_bd_num;
|
| 4103 |
169 |
mohor |
integer tmp_data;
|
| 4104 |
209 |
tadejm |
integer tmp_ipgt;
|
| 4105 |
194 |
tadej |
integer test_num;
|
| 4106 |
169 |
mohor |
reg [31:0] tx_bd_num;
|
| 4107 |
|
|
reg [((`MAX_BLK_SIZE * 32) - 1):0] burst_data;
|
| 4108 |
|
|
reg [((`MAX_BLK_SIZE * 32) - 1):0] burst_tmp_data;
|
| 4109 |
|
|
integer i;
|
| 4110 |
|
|
integer i1;
|
| 4111 |
|
|
integer i2;
|
| 4112 |
|
|
integer i3;
|
| 4113 |
|
|
integer fail;
|
| 4114 |
|
|
integer speed;
|
| 4115 |
209 |
tadejm |
reg frame_started;
|
| 4116 |
|
|
reg frame_ended;
|
| 4117 |
|
|
reg wait_for_frame;
|
| 4118 |
169 |
mohor |
reg [31:0] addr;
|
| 4119 |
|
|
reg [31:0] data;
|
| 4120 |
|
|
reg [31:0] tmp;
|
| 4121 |
|
|
reg [ 7:0] st_data;
|
| 4122 |
|
|
reg [15:0] max_tmp;
|
| 4123 |
|
|
reg [15:0] min_tmp;
|
| 4124 |
274 |
tadejm |
integer a, b, c;
|
| 4125 |
169 |
mohor |
begin
|
| 4126 |
|
|
// MAC FULL DUPLEX TRANSMIT TEST
|
| 4127 |
|
|
test_heading("MAC FULL DUPLEX TRANSMIT TEST");
|
| 4128 |
|
|
$display(" ");
|
| 4129 |
|
|
$display("MAC FULL DUPLEX TRANSMIT TEST");
|
| 4130 |
|
|
fail = 0;
|
| 4131 |
|
|
|
| 4132 |
|
|
// reset MAC registers
|
| 4133 |
|
|
hard_reset;
|
| 4134 |
|
|
// reset MAC and MII LOGIC with soft reset
|
| 4135 |
274 |
tadejm |
//reset_mac;
|
| 4136 |
|
|
//reset_mii;
|
| 4137 |
169 |
mohor |
// set wb slave response
|
| 4138 |
|
|
wb_slave.cycle_response(`ACK_RESPONSE, wbs_waits, wbs_retries);
|
| 4139 |
|
|
|
| 4140 |
|
|
/*
|
| 4141 |
|
|
TASKS for set and control TX buffer descriptors (also send packet - set_tx_bd_ready):
|
| 4142 |
|
|
-------------------------------------------------------------------------------------
|
| 4143 |
|
|
set_tx_bd
|
| 4144 |
|
|
(tx_bd_num_start[6:0], tx_bd_num_end[6:0], len[15:0], irq, pad, crc, txpnt[31:0]);
|
| 4145 |
|
|
set_tx_bd_wrap
|
| 4146 |
|
|
(tx_bd_num_end[6:0]);
|
| 4147 |
|
|
set_tx_bd_ready
|
| 4148 |
|
|
(tx_bd_num_start[6:0], tx_bd_num_end[6:0]);
|
| 4149 |
|
|
check_tx_bd
|
| 4150 |
|
|
(tx_bd_num_start[6:0], tx_bd_status[31:0]);
|
| 4151 |
|
|
clear_tx_bd
|
| 4152 |
|
|
(tx_bd_num_start[6:0], tx_bd_num_end[6:0]);
|
| 4153 |
|
|
|
| 4154 |
|
|
TASKS for set and control RX buffer descriptors:
|
| 4155 |
|
|
------------------------------------------------
|
| 4156 |
|
|
set_rx_bd
|
| 4157 |
|
|
(rx_bd_num_strat[6:0], rx_bd_num_end[6:0], irq, rxpnt[31:0]);
|
| 4158 |
|
|
set_rx_bd_wrap
|
| 4159 |
|
|
(rx_bd_num_end[6:0]);
|
| 4160 |
|
|
set_rx_bd_empty
|
| 4161 |
|
|
(rx_bd_num_strat[6:0], rx_bd_num_end[6:0]);
|
| 4162 |
|
|
check_rx_bd
|
| 4163 |
|
|
(rx_bd_num_end[6:0], rx_bd_status);
|
| 4164 |
|
|
clear_rx_bd
|
| 4165 |
|
|
(rx_bd_num_strat[6:0], rx_bd_num_end[6:0]);
|
| 4166 |
|
|
|
| 4167 |
|
|
TASKS for set and check TX packets:
|
| 4168 |
|
|
-----------------------------------
|
| 4169 |
|
|
set_tx_packet
|
| 4170 |
|
|
(txpnt[31:0], len[15:0], eth_start_data[7:0]);
|
| 4171 |
|
|
check_tx_packet
|
| 4172 |
|
|
(txpnt_wb[31:0], txpnt_phy[31:0], len[15:0], failure[31:0]);
|
| 4173 |
|
|
|
| 4174 |
|
|
TASKS for set and check RX packets:
|
| 4175 |
|
|
-----------------------------------
|
| 4176 |
|
|
set_rx_packet
|
| 4177 |
|
|
(rxpnt[31:0], len[15:0], plus_nibble, d_addr[47:0], s_addr[47:0], type_len[15:0], start_data[7:0]);
|
| 4178 |
|
|
check_rx_packet
|
| 4179 |
|
|
(rxpnt_phy[31:0], rxpnt_wb[31:0], len[15:0], plus_nibble, successful_nibble, failure[31:0]);
|
| 4180 |
|
|
|
| 4181 |
|
|
TASKS for append and check CRC to/of TX packet:
|
| 4182 |
|
|
-----------------------------------------------
|
| 4183 |
|
|
append_tx_crc
|
| 4184 |
|
|
(txpnt_wb[31:0], len[15:0], negated_crc);
|
| 4185 |
|
|
check_tx_crc
|
| 4186 |
|
|
(txpnt_phy[31:0], len[15:0], negated_crc, failure[31:0]);
|
| 4187 |
|
|
|
| 4188 |
|
|
TASK for append CRC to RX packet (CRC is checked together with check_rx_packet):
|
| 4189 |
|
|
--------------------------------------------------------------------------------
|
| 4190 |
|
|
append_rx_crc
|
| 4191 |
|
|
(rxpnt_phy[31:0], len[15:0], plus_nibble, negated_crc);
|
| 4192 |
|
|
*/
|
| 4193 |
|
|
|
| 4194 |
194 |
tadej |
//////////////////////////////////////////////////////////////////////
|
| 4195 |
|
|
//// ////
|
| 4196 |
|
|
//// test_mac_full_duplex_transmit: ////
|
| 4197 |
|
|
//// ////
|
| 4198 |
|
|
//// 0: Test no transmit when all buffers are RX ( 10Mbps ). ////
|
| 4199 |
|
|
//// 1: Test no transmit when all buffers are RX ( 100Mbps ). ////
|
| 4200 |
|
|
//// 2: Test transmit packets form MINFL to MAXFL sizes at ////
|
| 4201 |
|
|
//// one TX buffer decriptor ( 10Mbps ). ////
|
| 4202 |
|
|
//// 3: Test transmit packets form MINFL to MAXFL sizes at ////
|
| 4203 |
|
|
//// one TX buffer decriptor ( 100Mbps ). ////
|
| 4204 |
|
|
//// ////
|
| 4205 |
|
|
//////////////////////////////////////////////////////////////////////
|
| 4206 |
|
|
for (test_num = start_task; test_num <= end_task; test_num = test_num + 1)
|
| 4207 |
169 |
mohor |
begin
|
| 4208 |
|
|
|
| 4209 |
194 |
tadej |
////////////////////////////////////////////////////////////////////
|
| 4210 |
|
|
//// ////
|
| 4211 |
|
|
//// Test no transmit when all buffers are RX ( 10Mbps ). ////
|
| 4212 |
|
|
//// ////
|
| 4213 |
|
|
////////////////////////////////////////////////////////////////////
|
| 4214 |
|
|
if (test_num == 0) // Test no transmit when all buffers are RX ( 10Mbps ).
|
| 4215 |
169 |
mohor |
begin
|
| 4216 |
194 |
tadej |
// TEST 0: NO TRANSMIT WHEN ALL BUFFERS ARE RX ( 10Mbps )
|
| 4217 |
|
|
test_name = "TEST 0: NO TRANSMIT WHEN ALL BUFFERS ARE RX ( 10Mbps )";
|
| 4218 |
|
|
`TIME; $display(" TEST 0: NO TRANSMIT WHEN ALL BUFFERS ARE RX ( 10Mbps )");
|
| 4219 |
|
|
|
| 4220 |
|
|
// unmask interrupts
|
| 4221 |
209 |
tadejm |
wbm_write(`ETH_INT_MASK, `ETH_INT_TXB | `ETH_INT_TXE | `ETH_INT_RXB | `ETH_INT_RXE | `ETH_INT_BUSY |
|
| 4222 |
194 |
tadej |
`ETH_INT_TXC | `ETH_INT_RXC, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 4223 |
|
|
// set all buffer descriptors to RX - must be set before TX enable
|
| 4224 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 4225 |
194 |
tadej |
wbm_write(`ETH_TX_BD_NUM, 32'h0, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 4226 |
|
|
// enable TX, set full-duplex mode, padding and CRC appending
|
| 4227 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 4228 |
194 |
tadej |
wbm_write(`ETH_MODER, `ETH_MODER_TXEN | `ETH_MODER_FULLD | `ETH_MODER_PAD | `ETH_MODER_CRCEN,
|
| 4229 |
|
|
4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 4230 |
|
|
|
| 4231 |
|
|
// write to phy's control register for 10Mbps
|
| 4232 |
|
|
#Tp eth_phy.control_bit14_10 = 5'b00000; // bit 13 reset - speed 10
|
| 4233 |
|
|
#Tp eth_phy.control_bit8_0 = 9'h1_00; // bit 6 reset - (10/100), bit 8 set - FD
|
| 4234 |
|
|
speed = 10;
|
| 4235 |
|
|
|
| 4236 |
|
|
i = 0;
|
| 4237 |
|
|
while (i < 128)
|
| 4238 |
169 |
mohor |
begin
|
| 4239 |
194 |
tadej |
for (i1 = 0; i1 <= i; i1 = i1 + 1)
|
| 4240 |
169 |
mohor |
begin
|
| 4241 |
194 |
tadej |
set_tx_packet((`MEMORY_BASE + (i1 * 200)), 100, 0);
|
| 4242 |
|
|
set_tx_bd(i1, i1, 100, 1'b1, 1'b1, 1'b1, (`MEMORY_BASE + (i1 * 200)));
|
| 4243 |
169 |
mohor |
end
|
| 4244 |
194 |
tadej |
set_tx_bd_wrap(i);
|
| 4245 |
|
|
fork
|
| 4246 |
|
|
begin
|
| 4247 |
|
|
set_tx_bd_ready(0, i);
|
| 4248 |
|
|
repeat(20) @(negedge mtx_clk);
|
| 4249 |
|
|
#1 disable check_tx_en10;
|
| 4250 |
|
|
end
|
| 4251 |
|
|
begin: check_tx_en10
|
| 4252 |
|
|
wait (MTxEn === 1'b1);
|
| 4253 |
|
|
test_fail("Tramsmit should not start at all");
|
| 4254 |
|
|
fail = fail + 1;
|
| 4255 |
|
|
`TIME; $display("*E Transmit of %d packets should not start at all - active MTxEn", i);
|
| 4256 |
|
|
end
|
| 4257 |
|
|
join
|
| 4258 |
|
|
for (i2 = 0; i2 < 20; i2 = i2 + 1)
|
| 4259 |
169 |
mohor |
begin
|
| 4260 |
194 |
tadej |
check_tx_bd(0, tmp);
|
| 4261 |
|
|
#1;
|
| 4262 |
|
|
if (tmp[15] === 1'b0)
|
| 4263 |
|
|
begin
|
| 4264 |
|
|
test_fail("Tramsmit should not start at all");
|
| 4265 |
|
|
fail = fail + 1;
|
| 4266 |
|
|
`TIME; $display("*E Transmit of %d packets should not start at all - ready is 0", i);
|
| 4267 |
|
|
end
|
| 4268 |
|
|
if (tmp[8:0] !== 0)
|
| 4269 |
|
|
begin
|
| 4270 |
|
|
test_fail("Tramsmit should not be finished since it should not start at all");
|
| 4271 |
|
|
fail = fail + 1;
|
| 4272 |
|
|
`TIME; $display("*E Transmit of should not be finished since it should not start at all");
|
| 4273 |
|
|
end
|
| 4274 |
|
|
@(posedge wb_clk);
|
| 4275 |
169 |
mohor |
end
|
| 4276 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 4277 |
194 |
tadej |
wbm_read(`ETH_INT, tmp, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 4278 |
|
|
if (tmp[6:0] !== 0)
|
| 4279 |
169 |
mohor |
begin
|
| 4280 |
194 |
tadej |
test_fail("Tramsmit should not get INT since it should not start at all");
|
| 4281 |
169 |
mohor |
fail = fail + 1;
|
| 4282 |
194 |
tadej |
`TIME; $display("*E Transmit of should not get INT since it should not start at all");
|
| 4283 |
169 |
mohor |
end
|
| 4284 |
194 |
tadej |
clear_tx_bd(0, i);
|
| 4285 |
|
|
if ((i < 5) || (i > 124))
|
| 4286 |
|
|
i = i + 1;
|
| 4287 |
|
|
else
|
| 4288 |
|
|
i = i + 120;
|
| 4289 |
116 |
mohor |
end
|
| 4290 |
194 |
tadej |
// disable TX
|
| 4291 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 4292 |
194 |
tadej |
wbm_write(`ETH_MODER, `ETH_MODER_FULLD | `ETH_MODER_PAD | `ETH_MODER_CRCEN,
|
| 4293 |
|
|
4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 4294 |
|
|
if(fail == 0)
|
| 4295 |
|
|
test_ok;
|
| 4296 |
116 |
mohor |
else
|
| 4297 |
194 |
tadej |
fail = 0;
|
| 4298 |
169 |
mohor |
end
|
| 4299 |
116 |
mohor |
|
| 4300 |
|
|
|
| 4301 |
194 |
tadej |
////////////////////////////////////////////////////////////////////
|
| 4302 |
|
|
//// ////
|
| 4303 |
|
|
//// Test no transmit when all buffers are RX ( 100Mbps ). ////
|
| 4304 |
|
|
//// ////
|
| 4305 |
|
|
////////////////////////////////////////////////////////////////////
|
| 4306 |
|
|
if (test_num == 1) // Test no transmit when all buffers are RX ( 100Mbps ).
|
| 4307 |
169 |
mohor |
begin
|
| 4308 |
194 |
tadej |
// TEST 1: NO TRANSMIT WHEN ALL BUFFERS ARE RX ( 100Mbps )
|
| 4309 |
|
|
test_name = "TEST 1: NO TRANSMIT WHEN ALL BUFFERS ARE RX ( 100Mbps )";
|
| 4310 |
|
|
`TIME; $display(" TEST 1: NO TRANSMIT WHEN ALL BUFFERS ARE RX ( 100Mbps )");
|
| 4311 |
|
|
|
| 4312 |
|
|
// unmask interrupts
|
| 4313 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 4314 |
209 |
tadejm |
wbm_write(`ETH_INT_MASK, `ETH_INT_TXB | `ETH_INT_TXE | `ETH_INT_RXB | `ETH_INT_RXE | `ETH_INT_BUSY |
|
| 4315 |
194 |
tadej |
`ETH_INT_TXC | `ETH_INT_RXC, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 4316 |
|
|
// set all buffer descriptors to RX - must be set before TX enable
|
| 4317 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 4318 |
194 |
tadej |
wbm_write(`ETH_TX_BD_NUM, 32'h0, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 4319 |
|
|
// enable TX, set full-duplex mode, padding and CRC appending
|
| 4320 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 4321 |
194 |
tadej |
wbm_write(`ETH_MODER, `ETH_MODER_TXEN | `ETH_MODER_FULLD | `ETH_MODER_PAD | `ETH_MODER_CRCEN,
|
| 4322 |
|
|
4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 4323 |
|
|
|
| 4324 |
|
|
// write to phy's control register for 100Mbps
|
| 4325 |
|
|
#Tp eth_phy.control_bit14_10 = 5'b01000; // bit 13 set - speed 100
|
| 4326 |
|
|
#Tp eth_phy.control_bit8_0 = 9'h1_00; // bit 6 reset - (10/100), bit 8 set - FD
|
| 4327 |
|
|
speed = 100;
|
| 4328 |
|
|
|
| 4329 |
|
|
i = 0;
|
| 4330 |
|
|
while (i < 128)
|
| 4331 |
169 |
mohor |
begin
|
| 4332 |
194 |
tadej |
for (i1 = 0; i1 <= i; i1 = i1 + 1)
|
| 4333 |
169 |
mohor |
begin
|
| 4334 |
194 |
tadej |
set_tx_packet((`MEMORY_BASE + (i1 * 200)), 100, 0);
|
| 4335 |
|
|
set_tx_bd(i1, i1, 100, 1'b1, 1'b1, 1'b1, (`MEMORY_BASE + (i1 * 200)));
|
| 4336 |
169 |
mohor |
end
|
| 4337 |
194 |
tadej |
set_tx_bd_wrap(i);
|
| 4338 |
|
|
fork
|
| 4339 |
|
|
begin
|
| 4340 |
|
|
set_tx_bd_ready(0, i);
|
| 4341 |
|
|
repeat(20) @(negedge mtx_clk);
|
| 4342 |
|
|
#1 disable check_tx_en100;
|
| 4343 |
|
|
end
|
| 4344 |
|
|
begin: check_tx_en100
|
| 4345 |
|
|
wait (MTxEn === 1'b1);
|
| 4346 |
|
|
test_fail("Tramsmit should not start at all");
|
| 4347 |
|
|
fail = fail + 1;
|
| 4348 |
|
|
`TIME; $display("*E Transmit of %d packets should not start at all - active MTxEn", i);
|
| 4349 |
|
|
end
|
| 4350 |
|
|
join
|
| 4351 |
|
|
for (i2 = 0; i2 < 20; i2 = i2 + 1)
|
| 4352 |
169 |
mohor |
begin
|
| 4353 |
194 |
tadej |
check_tx_bd(0, tmp);
|
| 4354 |
|
|
#1;
|
| 4355 |
|
|
if (tmp[15] === 1'b0)
|
| 4356 |
|
|
begin
|
| 4357 |
|
|
test_fail("Tramsmit should not start at all");
|
| 4358 |
|
|
fail = fail + 1;
|
| 4359 |
|
|
`TIME; $display("*E Transmit of %d packets should not start at all - ready is 0", i);
|
| 4360 |
|
|
end
|
| 4361 |
|
|
if (tmp[8:0] !== 0)
|
| 4362 |
|
|
begin
|
| 4363 |
|
|
test_fail("Tramsmit should not be finished since it should not start at all");
|
| 4364 |
|
|
fail = fail + 1;
|
| 4365 |
|
|
`TIME; $display("*E Transmit of should not be finished since it should not start at all");
|
| 4366 |
|
|
end
|
| 4367 |
|
|
@(posedge wb_clk);
|
| 4368 |
169 |
mohor |
end
|
| 4369 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 4370 |
194 |
tadej |
wbm_read(`ETH_INT, tmp, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 4371 |
|
|
if (tmp[6:0] !== 0)
|
| 4372 |
169 |
mohor |
begin
|
| 4373 |
194 |
tadej |
test_fail("Tramsmit should not get INT since it should not start at all");
|
| 4374 |
169 |
mohor |
fail = fail + 1;
|
| 4375 |
194 |
tadej |
`TIME; $display("*E Transmit of should not get INT since it should not start at all");
|
| 4376 |
169 |
mohor |
end
|
| 4377 |
194 |
tadej |
clear_tx_bd(0, i);
|
| 4378 |
|
|
if ((i < 5) || (i > 124))
|
| 4379 |
|
|
i = i + 1;
|
| 4380 |
|
|
else
|
| 4381 |
|
|
i = i + 120;
|
| 4382 |
169 |
mohor |
end
|
| 4383 |
194 |
tadej |
// disable TX
|
| 4384 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 4385 |
194 |
tadej |
wbm_write(`ETH_MODER, `ETH_MODER_FULLD | `ETH_MODER_PAD | `ETH_MODER_CRCEN,
|
| 4386 |
|
|
4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 4387 |
|
|
if(fail == 0)
|
| 4388 |
|
|
test_ok;
|
| 4389 |
169 |
mohor |
else
|
| 4390 |
194 |
tadej |
fail = 0;
|
| 4391 |
169 |
mohor |
end
|
| 4392 |
|
|
|
| 4393 |
|
|
|
| 4394 |
194 |
tadej |
////////////////////////////////////////////////////////////////////
|
| 4395 |
|
|
//// ////
|
| 4396 |
|
|
//// Test transmit packets form MINFL to MAXFL sizes at ////
|
| 4397 |
|
|
//// one TX buffer decriptor ( 10Mbps ). ////
|
| 4398 |
|
|
//// ////
|
| 4399 |
|
|
////////////////////////////////////////////////////////////////////
|
| 4400 |
209 |
tadejm |
if (test_num == 2) // without and with padding
|
| 4401 |
169 |
mohor |
begin
|
| 4402 |
194 |
tadej |
// TEST 2: TRANSMIT PACKETS FROM MINFL TO MAXFL SIZES AT ONE TX BD ( 10Mbps )
|
| 4403 |
|
|
test_name = "TEST 2: TRANSMIT PACKETS FROM MINFL TO MAXFL SIZES AT ONE TX BD ( 10Mbps )";
|
| 4404 |
|
|
`TIME; $display(" TEST 2: TRANSMIT PACKETS FROM MINFL TO MAXFL SIZES AT ONE TX BD ( 10Mbps )");
|
| 4405 |
|
|
|
| 4406 |
|
|
max_tmp = 0;
|
| 4407 |
|
|
min_tmp = 0;
|
| 4408 |
|
|
// set one TX buffer descriptor - must be set before TX enable
|
| 4409 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 4410 |
194 |
tadej |
wbm_write(`ETH_TX_BD_NUM, 32'h1, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 4411 |
209 |
tadejm |
// enable TX, set full-duplex mode, NO padding and CRC appending
|
| 4412 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 4413 |
209 |
tadejm |
wbm_write(`ETH_MODER, `ETH_MODER_TXEN | `ETH_MODER_FULLD | `ETH_MODER_CRCEN,
|
| 4414 |
194 |
tadej |
4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 4415 |
|
|
// prepare two packets of MAXFL length
|
| 4416 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 4417 |
194 |
tadej |
wbm_read(`ETH_PACKETLEN, tmp, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 4418 |
|
|
max_tmp = tmp[15:0]; // 18 bytes consists of 6B dest addr, 6B source addr, 2B type/len, 4B CRC
|
| 4419 |
|
|
min_tmp = tmp[31:16];
|
| 4420 |
209 |
tadejm |
st_data = 8'h01;
|
| 4421 |
|
|
set_tx_packet(`MEMORY_BASE, (max_tmp), st_data); // length without CRC
|
| 4422 |
194 |
tadej |
st_data = 8'h10;
|
| 4423 |
209 |
tadejm |
set_tx_packet((`MEMORY_BASE + max_tmp), (max_tmp), st_data); // length without CRC
|
| 4424 |
194 |
tadej |
// check WB INT signal
|
| 4425 |
|
|
if (wb_int !== 1'b0)
|
| 4426 |
169 |
mohor |
begin
|
| 4427 |
194 |
tadej |
test_fail("WB INT signal should not be set");
|
| 4428 |
|
|
fail = fail + 1;
|
| 4429 |
169 |
mohor |
end
|
| 4430 |
194 |
tadej |
|
| 4431 |
|
|
// write to phy's control register for 10Mbps
|
| 4432 |
|
|
#Tp eth_phy.control_bit14_10 = 5'b00000; // bit 13 reset - speed 10
|
| 4433 |
|
|
#Tp eth_phy.control_bit8_0 = 9'h1_00; // bit 6 reset - (10/100), bit 8 set - FD
|
| 4434 |
|
|
speed = 10;
|
| 4435 |
|
|
|
| 4436 |
|
|
i_length = (min_tmp - 4);
|
| 4437 |
|
|
while (i_length <= (max_tmp - 4))
|
| 4438 |
169 |
mohor |
begin
|
| 4439 |
194 |
tadej |
// choose generating carrier sense and collision for first and last 64 lengths of frames
|
| 4440 |
|
|
case (i_length[1:0])
|
| 4441 |
|
|
2'h0: // Interrupt is generated
|
| 4442 |
169 |
mohor |
begin
|
| 4443 |
194 |
tadej |
// enable interrupt generation
|
| 4444 |
209 |
tadejm |
set_tx_bd(0, 0, i_length, 1'b1, 1'b1, 1'b1, (`MEMORY_BASE + i_length[1:0]));
|
| 4445 |
194 |
tadej |
// unmask interrupts
|
| 4446 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 4447 |
209 |
tadejm |
wbm_write(`ETH_INT_MASK, `ETH_INT_TXB | `ETH_INT_TXE | `ETH_INT_RXB | `ETH_INT_RXE | `ETH_INT_BUSY |
|
| 4448 |
194 |
tadej |
`ETH_INT_TXC | `ETH_INT_RXC, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 4449 |
|
|
// not detect carrier sense in FD and no collision
|
| 4450 |
|
|
eth_phy.carrier_sense_tx_fd_detect(0);
|
| 4451 |
|
|
eth_phy.collision(0);
|
| 4452 |
169 |
mohor |
end
|
| 4453 |
194 |
tadej |
2'h1: // Interrupt is not generated
|
| 4454 |
169 |
mohor |
begin
|
| 4455 |
194 |
tadej |
// enable interrupt generation
|
| 4456 |
209 |
tadejm |
set_tx_bd(0, 0, i_length, 1'b1, 1'b1, 1'b1, ((`MEMORY_BASE + i_length[1:0]) + max_tmp));
|
| 4457 |
194 |
tadej |
// mask interrupts
|
| 4458 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 4459 |
194 |
tadej |
wbm_write(`ETH_INT_MASK, 32'h0, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 4460 |
|
|
// detect carrier sense in FD and no collision
|
| 4461 |
|
|
eth_phy.carrier_sense_tx_fd_detect(1);
|
| 4462 |
|
|
eth_phy.collision(0);
|
| 4463 |
169 |
mohor |
end
|
| 4464 |
194 |
tadej |
2'h2: // Interrupt is not generated
|
| 4465 |
|
|
begin
|
| 4466 |
|
|
// disable interrupt generation
|
| 4467 |
209 |
tadejm |
set_tx_bd(0, 0, i_length, 1'b0, 1'b1, 1'b1, (`MEMORY_BASE + i_length[1:0]));
|
| 4468 |
194 |
tadej |
// unmask interrupts
|
| 4469 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 4470 |
209 |
tadejm |
wbm_write(`ETH_INT_MASK, `ETH_INT_TXB | `ETH_INT_TXE | `ETH_INT_RXB | `ETH_INT_RXE | `ETH_INT_BUSY |
|
| 4471 |
194 |
tadej |
`ETH_INT_TXC | `ETH_INT_RXC, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 4472 |
|
|
// not detect carrier sense in FD and set collision
|
| 4473 |
|
|
eth_phy.carrier_sense_tx_fd_detect(0);
|
| 4474 |
|
|
eth_phy.collision(1);
|
| 4475 |
|
|
end
|
| 4476 |
|
|
default: // 2'h3: // Interrupt is not generated
|
| 4477 |
|
|
begin
|
| 4478 |
|
|
// disable interrupt generation
|
| 4479 |
209 |
tadejm |
set_tx_bd(0, 0, i_length, 1'b0, 1'b1, 1'b1, ((`MEMORY_BASE + i_length[1:0]) + max_tmp));
|
| 4480 |
194 |
tadej |
// mask interrupts
|
| 4481 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 4482 |
194 |
tadej |
wbm_write(`ETH_INT_MASK, 32'h0, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 4483 |
|
|
// detect carrier sense in FD and set collision
|
| 4484 |
|
|
eth_phy.carrier_sense_tx_fd_detect(1);
|
| 4485 |
|
|
eth_phy.collision(1);
|
| 4486 |
|
|
end
|
| 4487 |
|
|
endcase
|
| 4488 |
|
|
eth_phy.set_tx_mem_addr(max_tmp);
|
| 4489 |
|
|
// set wrap bit
|
| 4490 |
|
|
set_tx_bd_wrap(0);
|
| 4491 |
|
|
set_tx_bd_ready(0, 0);
|
| 4492 |
169 |
mohor |
#1 check_tx_bd(0, data);
|
| 4493 |
274 |
tadejm |
|
| 4494 |
|
|
|
| 4495 |
194 |
tadej |
if (i_length < min_tmp) // just first four
|
| 4496 |
169 |
mohor |
begin
|
| 4497 |
194 |
tadej |
while (data[15] === 1)
|
| 4498 |
|
|
begin
|
| 4499 |
|
|
#1 check_tx_bd(0, data);
|
| 4500 |
|
|
@(posedge wb_clk);
|
| 4501 |
|
|
end
|
| 4502 |
209 |
tadejm |
repeat (1) @(posedge wb_clk);
|
| 4503 |
169 |
mohor |
end
|
| 4504 |
194 |
tadej |
else if (i_length > (max_tmp - 8)) // just last four
|
| 4505 |
192 |
tadej |
begin
|
| 4506 |
194 |
tadej |
tmp = 0;
|
| 4507 |
|
|
wait (MTxEn === 1'b1); // start transmit
|
| 4508 |
|
|
while (tmp < (i_length - 20))
|
| 4509 |
|
|
begin
|
| 4510 |
|
|
#1 tmp = tmp + 1;
|
| 4511 |
|
|
@(posedge wb_clk);
|
| 4512 |
|
|
end
|
| 4513 |
|
|
#1 check_tx_bd(0, data);
|
| 4514 |
|
|
while (data[15] === 1)
|
| 4515 |
|
|
begin
|
| 4516 |
|
|
#1 check_tx_bd(0, data);
|
| 4517 |
|
|
@(posedge wb_clk);
|
| 4518 |
|
|
end
|
| 4519 |
209 |
tadejm |
repeat (1) @(posedge wb_clk);
|
| 4520 |
192 |
tadej |
end
|
| 4521 |
|
|
else
|
| 4522 |
|
|
begin
|
| 4523 |
194 |
tadej |
wait (MTxEn === 1'b1); // start transmit
|
| 4524 |
|
|
#1 check_tx_bd(0, data);
|
| 4525 |
|
|
if (data[15] !== 1)
|
| 4526 |
|
|
begin
|
| 4527 |
|
|
test_fail("Wrong buffer descriptor's ready bit read out from MAC");
|
| 4528 |
|
|
fail = fail + 1;
|
| 4529 |
|
|
end
|
| 4530 |
|
|
wait (MTxEn === 1'b0); // end transmit
|
| 4531 |
|
|
while (data[15] === 1)
|
| 4532 |
|
|
begin
|
| 4533 |
|
|
#1 check_tx_bd(0, data);
|
| 4534 |
|
|
@(posedge wb_clk);
|
| 4535 |
|
|
end
|
| 4536 |
|
|
repeat (1) @(posedge wb_clk);
|
| 4537 |
192 |
tadej |
end
|
| 4538 |
274 |
tadejm |
|
| 4539 |
|
|
repeat(5) @(posedge mtx_clk); // Wait some time so PHY stores the CRC igor
|
| 4540 |
|
|
|
| 4541 |
194 |
tadej |
// check length of a PACKET
|
| 4542 |
|
|
if (eth_phy.tx_len != (i_length + 4))
|
| 4543 |
192 |
tadej |
begin
|
| 4544 |
194 |
tadej |
test_fail("Wrong length of the packet out from MAC");
|
| 4545 |
192 |
tadej |
fail = fail + 1;
|
| 4546 |
|
|
end
|
| 4547 |
194 |
tadej |
// checking in the following if statement is performed only for first and last 64 lengths
|
| 4548 |
|
|
if ( ((i_length + 4) <= (min_tmp + 64)) || ((i_length + 4) > (max_tmp - 64)) )
|
| 4549 |
192 |
tadej |
begin
|
| 4550 |
194 |
tadej |
// check transmitted TX packet data
|
| 4551 |
|
|
if (i_length[0] == 0)
|
| 4552 |
|
|
begin
|
| 4553 |
209 |
tadejm |
check_tx_packet((`MEMORY_BASE + i_length[1:0]), max_tmp, i_length, tmp);
|
| 4554 |
194 |
tadej |
end
|
| 4555 |
|
|
else
|
| 4556 |
|
|
begin
|
| 4557 |
209 |
tadejm |
check_tx_packet(((`MEMORY_BASE + i_length[1:0]) + max_tmp), max_tmp, i_length, tmp);
|
| 4558 |
194 |
tadej |
end
|
| 4559 |
|
|
if (tmp > 0)
|
| 4560 |
|
|
begin
|
| 4561 |
|
|
test_fail("Wrong data of the transmitted packet");
|
| 4562 |
|
|
fail = fail + 1;
|
| 4563 |
|
|
end
|
| 4564 |
|
|
// check transmited TX packet CRC
|
| 4565 |
|
|
check_tx_crc(max_tmp, i_length, 1'b0, tmp); // length without CRC
|
| 4566 |
274 |
tadejm |
|
| 4567 |
194 |
tadej |
if (tmp > 0)
|
| 4568 |
|
|
begin
|
| 4569 |
|
|
test_fail("Wrong CRC of the transmitted packet");
|
| 4570 |
|
|
fail = fail + 1;
|
| 4571 |
|
|
end
|
| 4572 |
192 |
tadej |
end
|
| 4573 |
194 |
tadej |
// check WB INT signal
|
| 4574 |
|
|
if (i_length[1:0] == 2'h0)
|
| 4575 |
192 |
tadej |
begin
|
| 4576 |
194 |
tadej |
if (wb_int !== 1'b1)
|
| 4577 |
|
|
begin
|
| 4578 |
|
|
`TIME; $display("*E WB INT signal should be set");
|
| 4579 |
|
|
test_fail("WB INT signal should be set");
|
| 4580 |
|
|
fail = fail + 1;
|
| 4581 |
|
|
end
|
| 4582 |
192 |
tadej |
end
|
| 4583 |
194 |
tadej |
else
|
| 4584 |
192 |
tadej |
begin
|
| 4585 |
194 |
tadej |
if (wb_int !== 1'b0)
|
| 4586 |
|
|
begin
|
| 4587 |
|
|
`TIME; $display("*E WB INT signal should not be set");
|
| 4588 |
|
|
test_fail("WB INT signal should not be set");
|
| 4589 |
|
|
fail = fail + 1;
|
| 4590 |
|
|
end
|
| 4591 |
192 |
tadej |
end
|
| 4592 |
194 |
tadej |
// check TX buffer descriptor of a packet
|
| 4593 |
|
|
check_tx_bd(0, data);
|
| 4594 |
|
|
if (i_length[1] == 1'b0) // interrupt enabled
|
| 4595 |
192 |
tadej |
begin
|
| 4596 |
194 |
tadej |
if (data[15:0] !== 16'h7800)
|
| 4597 |
|
|
begin
|
| 4598 |
|
|
`TIME; $display("*E TX buffer descriptor status is not correct: %0h", data[15:0]);
|
| 4599 |
|
|
test_fail("TX buffer descriptor status is not correct");
|
| 4600 |
|
|
fail = fail + 1;
|
| 4601 |
|
|
end
|
| 4602 |
192 |
tadej |
end
|
| 4603 |
194 |
tadej |
else // interrupt not enabled
|
| 4604 |
192 |
tadej |
begin
|
| 4605 |
194 |
tadej |
if (data[15:0] !== 16'h3800)
|
| 4606 |
|
|
begin
|
| 4607 |
|
|
`TIME; $display("*E TX buffer descriptor status is not correct: %0h", data[15:0]);
|
| 4608 |
|
|
test_fail("TX buffer descriptor status is not correct");
|
| 4609 |
|
|
fail = fail + 1;
|
| 4610 |
|
|
end
|
| 4611 |
192 |
tadej |
end
|
| 4612 |
194 |
tadej |
// clear TX buffer descriptor
|
| 4613 |
|
|
clear_tx_bd(0, 0);
|
| 4614 |
|
|
// check interrupts
|
| 4615 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 4616 |
194 |
tadej |
wbm_read(`ETH_INT, data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 4617 |
|
|
if ((i_length[1:0] == 2'h0) || (i_length[1:0] == 2'h1))
|
| 4618 |
192 |
tadej |
begin
|
| 4619 |
194 |
tadej |
if ((data & `ETH_INT_TXB) !== 1'b1)
|
| 4620 |
|
|
begin
|
| 4621 |
|
|
`TIME; $display("*E Interrupt Transmit Buffer was not set, interrupt reg: %0h", data);
|
| 4622 |
|
|
test_fail("Interrupt Transmit Buffer was not set");
|
| 4623 |
|
|
fail = fail + 1;
|
| 4624 |
|
|
end
|
| 4625 |
|
|
if ((data & (~`ETH_INT_TXB)) !== 0)
|
| 4626 |
|
|
begin
|
| 4627 |
|
|
`TIME; $display("*E Other interrupts (except Transmit Buffer) were set, interrupt reg: %0h", data);
|
| 4628 |
|
|
test_fail("Other interrupts (except Transmit Buffer) were set");
|
| 4629 |
|
|
fail = fail + 1;
|
| 4630 |
|
|
end
|
| 4631 |
192 |
tadej |
end
|
| 4632 |
194 |
tadej |
else
|
| 4633 |
192 |
tadej |
begin
|
| 4634 |
194 |
tadej |
if (data !== 0)
|
| 4635 |
|
|
begin
|
| 4636 |
|
|
`TIME; $display("*E Any of interrupts (except Transmit Buffer) was set, interrupt reg: %0h, len: %0h", data, i_length[1:0]);
|
| 4637 |
|
|
test_fail("Any of interrupts (except Transmit Buffer) was set");
|
| 4638 |
|
|
fail = fail + 1;
|
| 4639 |
|
|
end
|
| 4640 |
192 |
tadej |
end
|
| 4641 |
194 |
tadej |
// clear interrupts
|
| 4642 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 4643 |
194 |
tadej |
wbm_write(`ETH_INT, data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 4644 |
|
|
// check WB INT signal
|
| 4645 |
|
|
if (wb_int !== 1'b0)
|
| 4646 |
192 |
tadej |
begin
|
| 4647 |
194 |
tadej |
test_fail("WB INT signal should not be set");
|
| 4648 |
192 |
tadej |
fail = fail + 1;
|
| 4649 |
|
|
end
|
| 4650 |
194 |
tadej |
// INTERMEDIATE DISPLAYS
|
| 4651 |
|
|
if ((i_length + 4) == (min_tmp + 64))
|
| 4652 |
209 |
tadejm |
begin
|
| 4653 |
194 |
tadej |
// starting length is min_tmp, ending length is (min_tmp + 64)
|
| 4654 |
209 |
tadejm |
$display(" pads appending to packets is NOT selected");
|
| 4655 |
|
|
$display(" ->packets with lengths from %0d (MINFL) to %0d are checked (length increasing by 1 byte)",
|
| 4656 |
194 |
tadej |
min_tmp, (min_tmp + 64));
|
| 4657 |
209 |
tadejm |
// set padding, remain the rest
|
| 4658 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 4659 |
209 |
tadejm |
wbm_write(`ETH_MODER, `ETH_MODER_TXEN | `ETH_MODER_FULLD | `ETH_MODER_PAD | `ETH_MODER_CRCEN,
|
| 4660 |
|
|
4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 4661 |
|
|
end
|
| 4662 |
194 |
tadej |
else if ((i_length + 4) == (max_tmp - 16))
|
| 4663 |
209 |
tadejm |
begin
|
| 4664 |
194 |
tadej |
// starting length is for +128 longer than previous ending length, while ending length is tmp_data
|
| 4665 |
209 |
tadejm |
$display(" pads appending to packets is selected");
|
| 4666 |
|
|
$display(" ->packets with lengths from %0d to %0d are checked (length increasing by 128 bytes)",
|
| 4667 |
194 |
tadej |
(min_tmp + 64 + 128), tmp_data);
|
| 4668 |
209 |
tadejm |
// reset padding, remain the rest
|
| 4669 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 4670 |
209 |
tadejm |
wbm_write(`ETH_MODER, `ETH_MODER_TXEN | `ETH_MODER_FULLD | `ETH_MODER_CRCEN,
|
| 4671 |
|
|
4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 4672 |
|
|
end
|
| 4673 |
194 |
tadej |
else if ((i_length + 4) == max_tmp)
|
| 4674 |
209 |
tadejm |
begin
|
| 4675 |
|
|
$display(" pads appending to packets is NOT selected");
|
| 4676 |
|
|
$display(" ->packets with lengths from %0d to %0d (MAXFL) are checked (length increasing by 1 byte)",
|
| 4677 |
194 |
tadej |
(max_tmp - (4 + 16)), max_tmp);
|
| 4678 |
209 |
tadejm |
end
|
| 4679 |
194 |
tadej |
// set length (loop variable)
|
| 4680 |
|
|
if ((i_length + 4) < (min_tmp + 64))
|
| 4681 |
|
|
i_length = i_length + 1;
|
| 4682 |
|
|
else if ( ((i_length + 4) >= (min_tmp + 64)) && ((i_length + 4) <= (max_tmp - 256)) )
|
| 4683 |
|
|
begin
|
| 4684 |
|
|
i_length = i_length + 128;
|
| 4685 |
|
|
tmp_data = i_length + 4; // last tmp_data is ending length
|
| 4686 |
|
|
end
|
| 4687 |
|
|
else if ( ((i_length + 4) > (max_tmp - 256)) && ((i_length + 4) < (max_tmp - 16)) )
|
| 4688 |
|
|
i_length = max_tmp - (4 + 16);
|
| 4689 |
|
|
else if ((i_length + 4) >= (max_tmp - 16))
|
| 4690 |
|
|
i_length = i_length + 1;
|
| 4691 |
|
|
else
|
| 4692 |
|
|
begin
|
| 4693 |
|
|
$display("*E TESTBENCH ERROR - WRONG PARAMETERS IN TESTBENCH");
|
| 4694 |
|
|
#10 $stop;
|
| 4695 |
|
|
end
|
| 4696 |
192 |
tadej |
end
|
| 4697 |
194 |
tadej |
// disable TX
|
| 4698 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 4699 |
194 |
tadej |
wbm_write(`ETH_MODER, `ETH_MODER_FULLD | `ETH_MODER_PAD | `ETH_MODER_CRCEN,
|
| 4700 |
|
|
4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 4701 |
|
|
if(fail == 0)
|
| 4702 |
|
|
test_ok;
|
| 4703 |
|
|
else
|
| 4704 |
|
|
fail = 0;
|
| 4705 |
|
|
end
|
| 4706 |
|
|
|
| 4707 |
|
|
|
| 4708 |
|
|
////////////////////////////////////////////////////////////////////
|
| 4709 |
|
|
//// ////
|
| 4710 |
|
|
//// Test transmit packets form MINFL to MAXFL sizes at ////
|
| 4711 |
|
|
//// one TX buffer decriptor ( 100Mbps ). ////
|
| 4712 |
|
|
//// ////
|
| 4713 |
|
|
////////////////////////////////////////////////////////////////////
|
| 4714 |
209 |
tadejm |
if (test_num == 3) // with and without padding
|
| 4715 |
194 |
tadej |
begin
|
| 4716 |
|
|
// TEST 3: TRANSMIT PACKETS FROM MINFL TO MAXFL SIZES AT ONE TX BD ( 100Mbps )
|
| 4717 |
|
|
test_name = "TEST 3: TRANSMIT PACKETS FROM MINFL TO MAXFL SIZES AT ONE TX BD ( 100Mbps )";
|
| 4718 |
|
|
`TIME; $display(" TEST 3: TRANSMIT PACKETS FROM MINFL TO MAXFL SIZES AT ONE TX BD ( 100Mbps )");
|
| 4719 |
|
|
|
| 4720 |
|
|
max_tmp = 0;
|
| 4721 |
|
|
min_tmp = 0;
|
| 4722 |
|
|
// set one TX buffer descriptor - must be set before TX enable
|
| 4723 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 4724 |
194 |
tadej |
wbm_write(`ETH_TX_BD_NUM, 32'h1, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 4725 |
209 |
tadejm |
// enable TX, set full-duplex mode, NO padding and CRC appending
|
| 4726 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 4727 |
209 |
tadejm |
wbm_write(`ETH_MODER, `ETH_MODER_TXEN | `ETH_MODER_FULLD | `ETH_MODER_CRCEN,
|
| 4728 |
194 |
tadej |
4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 4729 |
|
|
// prepare two packets of MAXFL length
|
| 4730 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 4731 |
194 |
tadej |
wbm_read(`ETH_PACKETLEN, tmp, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 4732 |
|
|
max_tmp = tmp[15:0]; // 18 bytes consists of 6B dest addr, 6B source addr, 2B type/len, 4B CRC
|
| 4733 |
|
|
min_tmp = tmp[31:16];
|
| 4734 |
|
|
st_data = 8'h5A;
|
| 4735 |
209 |
tadejm |
set_tx_packet(`MEMORY_BASE, (max_tmp), st_data); // length without CRC
|
| 4736 |
194 |
tadej |
st_data = 8'h10;
|
| 4737 |
209 |
tadejm |
set_tx_packet((`MEMORY_BASE + max_tmp), (max_tmp), st_data); // length without CRC
|
| 4738 |
169 |
mohor |
// check WB INT signal
|
| 4739 |
192 |
tadej |
if (wb_int !== 1'b0)
|
| 4740 |
169 |
mohor |
begin
|
| 4741 |
|
|
test_fail("WB INT signal should not be set");
|
| 4742 |
|
|
fail = fail + 1;
|
| 4743 |
|
|
end
|
| 4744 |
194 |
tadej |
|
| 4745 |
|
|
// write to phy's control register for 100Mbps
|
| 4746 |
|
|
#Tp eth_phy.control_bit14_10 = 5'b01000; // bit 13 set - speed 100
|
| 4747 |
|
|
#Tp eth_phy.control_bit8_0 = 9'h1_00; // bit 6 reset - (10/100), bit 8 set - FD
|
| 4748 |
|
|
speed = 100;
|
| 4749 |
192 |
tadej |
|
| 4750 |
194 |
tadej |
i_length = (min_tmp - 4);
|
| 4751 |
|
|
while (i_length <= (max_tmp - 4))
|
| 4752 |
192 |
tadej |
begin
|
| 4753 |
194 |
tadej |
// choose generating carrier sense and collision
|
| 4754 |
|
|
case (i_length[1:0])
|
| 4755 |
|
|
2'h0: // Interrupt is generated
|
| 4756 |
192 |
tadej |
begin
|
| 4757 |
194 |
tadej |
// enable interrupt generation
|
| 4758 |
209 |
tadejm |
set_tx_bd(0, 0, i_length, 1'b1, 1'b1, 1'b1, (`MEMORY_BASE + i_length[1:0]));
|
| 4759 |
194 |
tadej |
// unmask interrupts
|
| 4760 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 4761 |
209 |
tadejm |
wbm_write(`ETH_INT_MASK, `ETH_INT_TXB | `ETH_INT_TXE | `ETH_INT_RXB | `ETH_INT_RXE | `ETH_INT_BUSY |
|
| 4762 |
194 |
tadej |
`ETH_INT_TXC | `ETH_INT_RXC, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 4763 |
|
|
// not detect carrier sense in FD and no collision
|
| 4764 |
|
|
eth_phy.carrier_sense_tx_fd_detect(0);
|
| 4765 |
|
|
eth_phy.collision(0);
|
| 4766 |
192 |
tadej |
end
|
| 4767 |
194 |
tadej |
2'h1: // Interrupt is not generated
|
| 4768 |
192 |
tadej |
begin
|
| 4769 |
194 |
tadej |
// enable interrupt generation
|
| 4770 |
209 |
tadejm |
set_tx_bd(0, 0, i_length, 1'b1, 1'b1, 1'b1, ((`MEMORY_BASE + i_length[1:0]) + max_tmp));
|
| 4771 |
194 |
tadej |
// mask interrupts
|
| 4772 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 4773 |
194 |
tadej |
wbm_write(`ETH_INT_MASK, 32'h0, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 4774 |
|
|
// detect carrier sense in FD and no collision
|
| 4775 |
|
|
eth_phy.carrier_sense_tx_fd_detect(1);
|
| 4776 |
|
|
eth_phy.collision(0);
|
| 4777 |
192 |
tadej |
end
|
| 4778 |
194 |
tadej |
2'h2: // Interrupt is not generated
|
| 4779 |
|
|
begin
|
| 4780 |
|
|
// disable interrupt generation
|
| 4781 |
209 |
tadejm |
set_tx_bd(0, 0, i_length, 1'b0, 1'b1, 1'b1, (`MEMORY_BASE + i_length[1:0]));
|
| 4782 |
194 |
tadej |
// unmask interrupts
|
| 4783 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 4784 |
209 |
tadejm |
wbm_write(`ETH_INT_MASK, `ETH_INT_TXB | `ETH_INT_TXE | `ETH_INT_RXB | `ETH_INT_RXE | `ETH_INT_BUSY |
|
| 4785 |
194 |
tadej |
`ETH_INT_TXC | `ETH_INT_RXC, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 4786 |
|
|
// not detect carrier sense in FD and set collision
|
| 4787 |
|
|
eth_phy.carrier_sense_tx_fd_detect(0);
|
| 4788 |
|
|
eth_phy.collision(1);
|
| 4789 |
|
|
end
|
| 4790 |
|
|
default: // 2'h3: // Interrupt is not generated
|
| 4791 |
|
|
begin
|
| 4792 |
|
|
// disable interrupt generation
|
| 4793 |
209 |
tadejm |
set_tx_bd(0, 0, i_length, 1'b0, 1'b1, 1'b1, ((`MEMORY_BASE + i_length[1:0]) + max_tmp));
|
| 4794 |
194 |
tadej |
// mask interrupts
|
| 4795 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 4796 |
194 |
tadej |
wbm_write(`ETH_INT_MASK, 32'h0, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 4797 |
|
|
// detect carrier sense in FD and set collision
|
| 4798 |
|
|
eth_phy.carrier_sense_tx_fd_detect(1);
|
| 4799 |
|
|
eth_phy.collision(1);
|
| 4800 |
|
|
end
|
| 4801 |
|
|
endcase
|
| 4802 |
|
|
eth_phy.set_tx_mem_addr(max_tmp);
|
| 4803 |
|
|
// set wrap bit
|
| 4804 |
|
|
set_tx_bd_wrap(0);
|
| 4805 |
|
|
set_tx_bd_ready(0, 0);
|
| 4806 |
192 |
tadej |
#1 check_tx_bd(0, data);
|
| 4807 |
194 |
tadej |
if (i_length < min_tmp) // just first four
|
| 4808 |
192 |
tadej |
begin
|
| 4809 |
194 |
tadej |
while (data[15] === 1)
|
| 4810 |
|
|
begin
|
| 4811 |
|
|
#1 check_tx_bd(0, data);
|
| 4812 |
|
|
@(posedge wb_clk);
|
| 4813 |
|
|
end
|
| 4814 |
209 |
tadejm |
repeat (1) @(posedge wb_clk);
|
| 4815 |
194 |
tadej |
end
|
| 4816 |
|
|
else if (i_length > (max_tmp - 8)) // just last four
|
| 4817 |
|
|
begin
|
| 4818 |
|
|
tmp = 0;
|
| 4819 |
|
|
wait (MTxEn === 1'b1); // start transmit
|
| 4820 |
|
|
while (tmp < (i_length - 20))
|
| 4821 |
|
|
begin
|
| 4822 |
|
|
#1 tmp = tmp + 1;
|
| 4823 |
|
|
@(posedge wb_clk);
|
| 4824 |
|
|
end
|
| 4825 |
192 |
tadej |
#1 check_tx_bd(0, data);
|
| 4826 |
194 |
tadej |
while (data[15] === 1)
|
| 4827 |
|
|
begin
|
| 4828 |
|
|
#1 check_tx_bd(0, data);
|
| 4829 |
|
|
@(posedge wb_clk);
|
| 4830 |
|
|
end
|
| 4831 |
209 |
tadejm |
repeat (1) @(posedge wb_clk);
|
| 4832 |
192 |
tadej |
end
|
| 4833 |
194 |
tadej |
else
|
| 4834 |
|
|
begin
|
| 4835 |
|
|
wait (MTxEn === 1'b1); // start transmit
|
| 4836 |
|
|
#1 check_tx_bd(0, data);
|
| 4837 |
|
|
if (data[15] !== 1)
|
| 4838 |
|
|
begin
|
| 4839 |
|
|
test_fail("Wrong buffer descriptor's ready bit read out from MAC");
|
| 4840 |
|
|
fail = fail + 1;
|
| 4841 |
|
|
end
|
| 4842 |
|
|
wait (MTxEn === 1'b0); // end transmit
|
| 4843 |
|
|
while (data[15] === 1)
|
| 4844 |
|
|
begin
|
| 4845 |
|
|
#1 check_tx_bd(0, data);
|
| 4846 |
|
|
@(posedge wb_clk);
|
| 4847 |
|
|
end
|
| 4848 |
|
|
repeat (1) @(posedge wb_clk);
|
| 4849 |
|
|
end
|
| 4850 |
|
|
// check length of a PACKET
|
| 4851 |
|
|
if (eth_phy.tx_len != (i_length + 4))
|
| 4852 |
|
|
begin
|
| 4853 |
|
|
test_fail("Wrong length of the packet out from MAC");
|
| 4854 |
|
|
fail = fail + 1;
|
| 4855 |
|
|
end
|
| 4856 |
192 |
tadej |
// check transmitted TX packet data
|
| 4857 |
|
|
if (i_length[0] == 0)
|
| 4858 |
|
|
begin
|
| 4859 |
209 |
tadejm |
check_tx_packet((`MEMORY_BASE + i_length[1:0]), max_tmp, i_length, tmp);
|
| 4860 |
192 |
tadej |
end
|
| 4861 |
|
|
else
|
| 4862 |
|
|
begin
|
| 4863 |
209 |
tadejm |
check_tx_packet(((`MEMORY_BASE + i_length[1:0]) + max_tmp), max_tmp, i_length, tmp);
|
| 4864 |
192 |
tadej |
end
|
| 4865 |
|
|
if (tmp > 0)
|
| 4866 |
|
|
begin
|
| 4867 |
|
|
test_fail("Wrong data of the transmitted packet");
|
| 4868 |
|
|
fail = fail + 1;
|
| 4869 |
|
|
end
|
| 4870 |
|
|
// check transmited TX packet CRC
|
| 4871 |
|
|
check_tx_crc(max_tmp, i_length, 1'b0, tmp); // length without CRC
|
| 4872 |
|
|
if (tmp > 0)
|
| 4873 |
|
|
begin
|
| 4874 |
|
|
test_fail("Wrong CRC of the transmitted packet");
|
| 4875 |
|
|
fail = fail + 1;
|
| 4876 |
|
|
end
|
| 4877 |
194 |
tadej |
// check WB INT signal
|
| 4878 |
|
|
if (i_length[1:0] == 2'h0)
|
| 4879 |
192 |
tadej |
begin
|
| 4880 |
194 |
tadej |
if (wb_int !== 1'b1)
|
| 4881 |
|
|
begin
|
| 4882 |
|
|
`TIME; $display("*E WB INT signal should be set");
|
| 4883 |
|
|
test_fail("WB INT signal should be set");
|
| 4884 |
|
|
fail = fail + 1;
|
| 4885 |
|
|
end
|
| 4886 |
192 |
tadej |
end
|
| 4887 |
194 |
tadej |
else
|
| 4888 |
192 |
tadej |
begin
|
| 4889 |
194 |
tadej |
if (wb_int !== 1'b0)
|
| 4890 |
|
|
begin
|
| 4891 |
|
|
`TIME; $display("*E WB INT signal should not be set");
|
| 4892 |
|
|
test_fail("WB INT signal should not be set");
|
| 4893 |
|
|
fail = fail + 1;
|
| 4894 |
|
|
end
|
| 4895 |
192 |
tadej |
end
|
| 4896 |
194 |
tadej |
// check TX buffer descriptor of a packet
|
| 4897 |
|
|
check_tx_bd(0, data);
|
| 4898 |
|
|
if (i_length[1] == 1'b0) // interrupt enabled
|
| 4899 |
192 |
tadej |
begin
|
| 4900 |
194 |
tadej |
if (data[15:0] !== 16'h7800)
|
| 4901 |
|
|
begin
|
| 4902 |
|
|
`TIME; $display("*E TX buffer descriptor status is not correct: %0h", data[15:0]);
|
| 4903 |
|
|
test_fail("TX buffer descriptor status is not correct");
|
| 4904 |
|
|
fail = fail + 1;
|
| 4905 |
|
|
end
|
| 4906 |
192 |
tadej |
end
|
| 4907 |
194 |
tadej |
else // interrupt not enabled
|
| 4908 |
192 |
tadej |
begin
|
| 4909 |
194 |
tadej |
if (data[15:0] !== 16'h3800)
|
| 4910 |
|
|
begin
|
| 4911 |
|
|
`TIME; $display("*E TX buffer descriptor status is not correct: %0h", data[15:0]);
|
| 4912 |
|
|
test_fail("TX buffer descriptor status is not correct");
|
| 4913 |
|
|
fail = fail + 1;
|
| 4914 |
|
|
end
|
| 4915 |
192 |
tadej |
end
|
| 4916 |
194 |
tadej |
// clear TX buffer descriptor
|
| 4917 |
|
|
clear_tx_bd(0, 0);
|
| 4918 |
|
|
// check interrupts
|
| 4919 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 4920 |
194 |
tadej |
wbm_read(`ETH_INT, data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 4921 |
|
|
if ((i_length[1:0] == 2'h0) || (i_length[1:0] == 2'h1))
|
| 4922 |
192 |
tadej |
begin
|
| 4923 |
194 |
tadej |
if ((data & `ETH_INT_TXB) !== 1'b1)
|
| 4924 |
|
|
begin
|
| 4925 |
|
|
`TIME; $display("*E Interrupt Transmit Buffer was not set, interrupt reg: %0h", data);
|
| 4926 |
|
|
test_fail("Interrupt Transmit Buffer was not set");
|
| 4927 |
|
|
fail = fail + 1;
|
| 4928 |
|
|
end
|
| 4929 |
|
|
if ((data & (~`ETH_INT_TXB)) !== 0)
|
| 4930 |
|
|
begin
|
| 4931 |
|
|
`TIME; $display("*E Other interrupts (except Transmit Buffer) were set, interrupt reg: %0h", data);
|
| 4932 |
|
|
test_fail("Other interrupts (except Transmit Buffer) were set");
|
| 4933 |
|
|
fail = fail + 1;
|
| 4934 |
|
|
end
|
| 4935 |
192 |
tadej |
end
|
| 4936 |
194 |
tadej |
else
|
| 4937 |
192 |
tadej |
begin
|
| 4938 |
194 |
tadej |
if (data !== 0)
|
| 4939 |
|
|
begin
|
| 4940 |
|
|
`TIME; $display("*E Any of interrupts (except Transmit Buffer) was set, interrupt reg: %0h", data);
|
| 4941 |
|
|
test_fail("Any of interrupts (except Transmit Buffer) was set");
|
| 4942 |
|
|
fail = fail + 1;
|
| 4943 |
|
|
end
|
| 4944 |
192 |
tadej |
end
|
| 4945 |
194 |
tadej |
// clear interrupts
|
| 4946 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 4947 |
194 |
tadej |
wbm_write(`ETH_INT, data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 4948 |
|
|
// check WB INT signal
|
| 4949 |
|
|
if (wb_int !== 1'b0)
|
| 4950 |
192 |
tadej |
begin
|
| 4951 |
194 |
tadej |
test_fail("WB INT signal should not be set");
|
| 4952 |
192 |
tadej |
fail = fail + 1;
|
| 4953 |
|
|
end
|
| 4954 |
194 |
tadej |
// INTERMEDIATE DISPLAYS
|
| 4955 |
|
|
if ((i_length + 4) == (min_tmp + 64))
|
| 4956 |
209 |
tadejm |
begin
|
| 4957 |
194 |
tadej |
// starting length is min_tmp, ending length is (min_tmp + 64)
|
| 4958 |
209 |
tadejm |
$display(" pads appending to packets is NOT selected");
|
| 4959 |
|
|
$display(" ->packets with lengths from %0d (MINFL) to %0d are checked (length increasing by 1 byte)",
|
| 4960 |
194 |
tadej |
min_tmp, (min_tmp + 64));
|
| 4961 |
209 |
tadejm |
// set padding, remain the rest
|
| 4962 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 4963 |
209 |
tadejm |
wbm_write(`ETH_MODER, `ETH_MODER_TXEN | `ETH_MODER_FULLD | `ETH_MODER_PAD | `ETH_MODER_CRCEN,
|
| 4964 |
|
|
4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 4965 |
|
|
end
|
| 4966 |
194 |
tadej |
else if ((i_length + 4) == (max_tmp - 16))
|
| 4967 |
209 |
tadejm |
begin
|
| 4968 |
194 |
tadej |
// starting length is for +128 longer than previous ending length, while ending length is tmp_data
|
| 4969 |
209 |
tadejm |
$display(" pads appending to packets is selected");
|
| 4970 |
|
|
$display(" ->packets with lengths from %0d to %0d are checked (length increasing by 128 bytes)",
|
| 4971 |
194 |
tadej |
(min_tmp + 64 + 128), tmp_data);
|
| 4972 |
209 |
tadejm |
// reset padding, remain the rest
|
| 4973 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 4974 |
209 |
tadejm |
wbm_write(`ETH_MODER, `ETH_MODER_TXEN | `ETH_MODER_FULLD | `ETH_MODER_CRCEN,
|
| 4975 |
|
|
4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 4976 |
|
|
end
|
| 4977 |
194 |
tadej |
else if ((i_length + 4) == max_tmp)
|
| 4978 |
209 |
tadejm |
begin
|
| 4979 |
|
|
$display(" pads appending to packets is NOT selected");
|
| 4980 |
|
|
$display(" ->packets with lengths from %0d to %0d (MAXFL) are checked (length increasing by 1 byte)",
|
| 4981 |
194 |
tadej |
(max_tmp - (4 + 16)), max_tmp);
|
| 4982 |
209 |
tadejm |
end
|
| 4983 |
194 |
tadej |
// set length (loop variable)
|
| 4984 |
|
|
if ((i_length + 4) < (min_tmp + 64))
|
| 4985 |
|
|
i_length = i_length + 1;
|
| 4986 |
|
|
else if ( ((i_length + 4) >= (min_tmp + 64)) && ((i_length + 4) <= (max_tmp - 256)) )
|
| 4987 |
|
|
begin
|
| 4988 |
|
|
i_length = i_length + 128;
|
| 4989 |
|
|
tmp_data = i_length + 4; // last tmp_data is ending length
|
| 4990 |
|
|
end
|
| 4991 |
|
|
else if ( ((i_length + 4) > (max_tmp - 256)) && ((i_length + 4) < (max_tmp - 16)) )
|
| 4992 |
|
|
i_length = max_tmp - (4 + 16);
|
| 4993 |
|
|
else if ((i_length + 4) >= (max_tmp - 16))
|
| 4994 |
|
|
i_length = i_length + 1;
|
| 4995 |
192 |
tadej |
else
|
| 4996 |
194 |
tadej |
begin
|
| 4997 |
|
|
$display("*E TESTBENCH ERROR - WRONG PARAMETERS IN TESTBENCH");
|
| 4998 |
|
|
#10 $stop;
|
| 4999 |
|
|
end
|
| 5000 |
179 |
mohor |
end
|
| 5001 |
194 |
tadej |
// disable TX
|
| 5002 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 5003 |
194 |
tadej |
wbm_write(`ETH_MODER, `ETH_MODER_FULLD | `ETH_MODER_PAD | `ETH_MODER_CRCEN,
|
| 5004 |
|
|
4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 5005 |
|
|
if(fail == 0)
|
| 5006 |
|
|
test_ok;
|
| 5007 |
|
|
else
|
| 5008 |
|
|
fail = 0;
|
| 5009 |
169 |
mohor |
end
|
| 5010 |
|
|
|
| 5011 |
|
|
|
| 5012 |
209 |
tadejm |
////////////////////////////////////////////////////////////////////
|
| 5013 |
|
|
//// ////
|
| 5014 |
|
|
//// Test transmit packets form MINFL to MAXFL sizes at ////
|
| 5015 |
|
|
//// maximum TX buffer decriptors ( 10Mbps ). ////
|
| 5016 |
|
|
//// ////
|
| 5017 |
|
|
////////////////////////////////////////////////////////////////////
|
| 5018 |
|
|
if (test_num == 4) // without and with padding
|
| 5019 |
|
|
begin
|
| 5020 |
|
|
// TEST 4: TRANSMIT PACKETS FROM MINFL TO MAXFL SIZES AT MAX TX BDs ( 10Mbps )
|
| 5021 |
|
|
test_name = "TEST 4: TRANSMIT PACKETS FROM MINFL TO MAXFL SIZES AT MAX TX BDs ( 10Mbps )";
|
| 5022 |
|
|
`TIME; $display(" TEST 4: TRANSMIT PACKETS FROM MINFL TO MAXFL SIZES AT MAX TX BDs ( 10Mbps )");
|
| 5023 |
|
|
|
| 5024 |
|
|
// reset MAC registers
|
| 5025 |
|
|
hard_reset;
|
| 5026 |
|
|
// reset MAC and MII LOGIC with soft reset
|
| 5027 |
274 |
tadejm |
// reset_mac;
|
| 5028 |
|
|
// reset_mii;
|
| 5029 |
209 |
tadejm |
// set wb slave response
|
| 5030 |
|
|
wb_slave.cycle_response(`ACK_RESPONSE, wbs_waits, wbs_retries);
|
| 5031 |
192 |
tadej |
|
| 5032 |
209 |
tadejm |
max_tmp = 0;
|
| 5033 |
|
|
min_tmp = 0;
|
| 5034 |
|
|
num_of_frames = 0;
|
| 5035 |
|
|
num_of_bd = 0;
|
| 5036 |
|
|
// set maximum TX buffer descriptors (128) - must be set before TX enable
|
| 5037 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 5038 |
209 |
tadejm |
wbm_write(`ETH_TX_BD_NUM, 32'h80, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 5039 |
|
|
// enable TX, set full-duplex mode, NO padding and CRC appending
|
| 5040 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 5041 |
209 |
tadejm |
wbm_write(`ETH_MODER, `ETH_MODER_TXEN | `ETH_MODER_FULLD | `ETH_MODER_CRCEN,
|
| 5042 |
|
|
4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 5043 |
|
|
// prepare two packets of MAXFL length
|
| 5044 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 5045 |
209 |
tadejm |
wbm_read(`ETH_PACKETLEN, tmp, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 5046 |
|
|
max_tmp = tmp[15:0]; // 18 bytes consists of 6B dest addr, 6B source addr, 2B type/len, 4B CRC
|
| 5047 |
|
|
min_tmp = tmp[31:16];
|
| 5048 |
|
|
st_data = 8'hA3;
|
| 5049 |
|
|
set_tx_packet(`MEMORY_BASE, (max_tmp), st_data); // length without CRC
|
| 5050 |
|
|
st_data = 8'h81;
|
| 5051 |
|
|
set_tx_packet((`MEMORY_BASE + max_tmp), (max_tmp), st_data); // length without CRC
|
| 5052 |
|
|
// check WB INT signal
|
| 5053 |
|
|
if (wb_int !== 1'b0)
|
| 5054 |
|
|
begin
|
| 5055 |
|
|
test_fail("WB INT signal should not be set");
|
| 5056 |
|
|
fail = fail + 1;
|
| 5057 |
|
|
end
|
| 5058 |
|
|
|
| 5059 |
|
|
// write to phy's control register for 10Mbps
|
| 5060 |
|
|
#Tp eth_phy.control_bit14_10 = 5'b00000; // bit 13 reset - speed 10
|
| 5061 |
|
|
#Tp eth_phy.control_bit8_0 = 9'h1_00; // bit 6 reset - (10/100), bit 8 set - FD
|
| 5062 |
|
|
speed = 10;
|
| 5063 |
|
|
|
| 5064 |
|
|
i_length = (min_tmp - 4);
|
| 5065 |
|
|
while (i_length <= (max_tmp - 4))
|
| 5066 |
|
|
begin
|
| 5067 |
|
|
// choose generating carrier sense and collision
|
| 5068 |
|
|
case (i_length[1:0])
|
| 5069 |
|
|
2'h0: // Interrupt is generated
|
| 5070 |
|
|
begin
|
| 5071 |
|
|
// Reset_tx_bd nable interrupt generation
|
| 5072 |
|
|
// unmask interrupts
|
| 5073 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 5074 |
209 |
tadejm |
wbm_write(`ETH_INT_MASK, `ETH_INT_TXB | `ETH_INT_TXE | `ETH_INT_RXB | `ETH_INT_RXE | `ETH_INT_BUSY |
|
| 5075 |
|
|
`ETH_INT_TXC | `ETH_INT_RXC, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 5076 |
|
|
// not detect carrier sense in FD and no collision
|
| 5077 |
|
|
eth_phy.carrier_sense_tx_fd_detect(0);
|
| 5078 |
|
|
eth_phy.collision(0);
|
| 5079 |
|
|
end
|
| 5080 |
|
|
2'h1: // Interrupt is not generated
|
| 5081 |
|
|
begin
|
| 5082 |
|
|
// set_tx_bd enable interrupt generation
|
| 5083 |
|
|
// mask interrupts
|
| 5084 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 5085 |
209 |
tadejm |
wbm_write(`ETH_INT_MASK, 32'h0, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 5086 |
|
|
// detect carrier sense in FD and no collision
|
| 5087 |
|
|
eth_phy.carrier_sense_tx_fd_detect(1);
|
| 5088 |
|
|
eth_phy.collision(0);
|
| 5089 |
|
|
end
|
| 5090 |
|
|
2'h2: // Interrupt is not generated
|
| 5091 |
|
|
begin
|
| 5092 |
|
|
// set_tx_bd disable the interrupt generation
|
| 5093 |
|
|
// unmask interrupts
|
| 5094 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 5095 |
209 |
tadejm |
wbm_write(`ETH_INT_MASK, `ETH_INT_TXB | `ETH_INT_TXE | `ETH_INT_RXB | `ETH_INT_RXE | `ETH_INT_BUSY |
|
| 5096 |
|
|
`ETH_INT_TXC | `ETH_INT_RXC, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 5097 |
|
|
// not detect carrier sense in FD and set collision
|
| 5098 |
|
|
eth_phy.carrier_sense_tx_fd_detect(0);
|
| 5099 |
|
|
eth_phy.collision(1);
|
| 5100 |
|
|
end
|
| 5101 |
|
|
default: // 2'h3: // Interrupt is not generated
|
| 5102 |
|
|
begin
|
| 5103 |
|
|
// set_tx_bd disable the interrupt generation
|
| 5104 |
|
|
// mask interrupts
|
| 5105 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 5106 |
209 |
tadejm |
wbm_write(`ETH_INT_MASK, 32'h0, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 5107 |
|
|
// detect carrier sense in FD and set collision
|
| 5108 |
|
|
eth_phy.carrier_sense_tx_fd_detect(1);
|
| 5109 |
|
|
eth_phy.collision(1);
|
| 5110 |
|
|
end
|
| 5111 |
|
|
endcase
|
| 5112 |
|
|
// first destination address on ethernet PHY
|
| 5113 |
|
|
if (i_length[0] == 0)
|
| 5114 |
|
|
eth_phy.set_tx_mem_addr(0);
|
| 5115 |
|
|
else
|
| 5116 |
|
|
eth_phy.set_tx_mem_addr(max_tmp);
|
| 5117 |
|
|
// first 8 frames are transmitted with TX BD 0 (wrap bit on TX BD 0)
|
| 5118 |
|
|
// number of all frames is 154 (146 without first 8)
|
| 5119 |
|
|
if (num_of_frames < 8)
|
| 5120 |
|
|
begin
|
| 5121 |
|
|
case (i_length[1:0])
|
| 5122 |
|
|
2'h0: // Interrupt is generated
|
| 5123 |
|
|
begin
|
| 5124 |
|
|
// enable interrupt generation
|
| 5125 |
|
|
set_tx_bd(0, 0, i_length, 1'b1, 1'b1, 1'b1, (`MEMORY_BASE + i_length[1:0]));
|
| 5126 |
|
|
// interrupts are unmasked
|
| 5127 |
|
|
end
|
| 5128 |
|
|
2'h1: // Interrupt is not generated
|
| 5129 |
|
|
begin
|
| 5130 |
|
|
// enable interrupt generation
|
| 5131 |
|
|
set_tx_bd(0, 0, i_length, 1'b1, 1'b1, 1'b1, ((`MEMORY_BASE + i_length[1:0]) + max_tmp));
|
| 5132 |
|
|
// interrupts are masked
|
| 5133 |
|
|
end
|
| 5134 |
|
|
2'h2: // Interrupt is not generated
|
| 5135 |
|
|
begin
|
| 5136 |
|
|
// disable interrupt generation
|
| 5137 |
|
|
set_tx_bd(0, 0, i_length, 1'b0, 1'b1, 1'b1, (`MEMORY_BASE + i_length[1:0]));
|
| 5138 |
|
|
// interrupts are unmasked
|
| 5139 |
|
|
end
|
| 5140 |
|
|
default: // 2'h3: // Interrupt is not generated
|
| 5141 |
|
|
begin
|
| 5142 |
|
|
// disable interrupt generation
|
| 5143 |
|
|
set_tx_bd(0, 0, i_length, 1'b0, 1'b1, 1'b1, ((`MEMORY_BASE + i_length[1:0]) + max_tmp));
|
| 5144 |
|
|
// interrupts are masked
|
| 5145 |
|
|
end
|
| 5146 |
|
|
endcase
|
| 5147 |
|
|
// set wrap bit
|
| 5148 |
|
|
set_tx_bd_wrap(0);
|
| 5149 |
|
|
end
|
| 5150 |
|
|
// after first 8 number of frames, 128 frames form TX BD 0 to 127 will be transmitted
|
| 5151 |
|
|
else if ((num_of_frames - 8) == 0)
|
| 5152 |
|
|
begin
|
| 5153 |
|
|
tmp_len = i_length; // length of frame
|
| 5154 |
|
|
tmp_bd_num = 0; // TX BD number
|
| 5155 |
|
|
while (tmp_bd_num < 128) // (tmp_len <= (max_tmp - 4)) - this is the last frame
|
| 5156 |
|
|
begin
|
| 5157 |
|
|
// if i_length[1] == 0 then enable interrupt generation otherwise disable it
|
| 5158 |
|
|
// if i_length[0] == 0 then base address is `MEMORY_BASE otherwise it is `MEMORY_BASE + max_tmp
|
| 5159 |
|
|
if (tmp_len[0] == 0)
|
| 5160 |
|
|
set_tx_bd(tmp_bd_num, tmp_bd_num, tmp_len, !tmp_len[1], 1'b1, 1'b1, (`MEMORY_BASE + tmp_len[1:0]));
|
| 5161 |
|
|
else
|
| 5162 |
|
|
set_tx_bd(tmp_bd_num, tmp_bd_num, tmp_len, !tmp_len[1], 1'b1, 1'b1, ((`MEMORY_BASE + tmp_len[1:0]) + max_tmp));
|
| 5163 |
|
|
// set length (loop variable) - THE SAME AS AT THE END OF THIS TASK !!!
|
| 5164 |
|
|
if ((tmp_len + 4) < (min_tmp + 128))
|
| 5165 |
|
|
tmp_len = tmp_len + 1;
|
| 5166 |
|
|
else if ( ((tmp_len + 4) == (min_tmp + 128)) && ((tmp_len + 4) <= (max_tmp - 256)) )
|
| 5167 |
|
|
tmp_len = 256;
|
| 5168 |
|
|
else if ( ((tmp_len + 4) > (min_tmp + 128)) && ((tmp_len + 4) <= (max_tmp - 256)) )
|
| 5169 |
|
|
tmp_len = tmp_len + 128;
|
| 5170 |
|
|
else if ( ((tmp_len + 4) > (max_tmp - 256)) && ((tmp_len + 4) < (max_tmp - 16)) )
|
| 5171 |
|
|
tmp_len = max_tmp - (4 + 16);
|
| 5172 |
|
|
else if ((tmp_len + 4) >= (max_tmp - 16))
|
| 5173 |
|
|
tmp_len = tmp_len + 1;
|
| 5174 |
|
|
// set TX BD number
|
| 5175 |
|
|
tmp_bd_num = tmp_bd_num + 1;
|
| 5176 |
|
|
end
|
| 5177 |
|
|
// set wrap bit
|
| 5178 |
|
|
set_tx_bd_wrap(127);
|
| 5179 |
|
|
end
|
| 5180 |
|
|
// after 128 + first 8 number of frames, 19 frames form TX BD 0 to 18 will be transmitted
|
| 5181 |
|
|
else if ((num_of_frames - 8) == 20) // 128
|
| 5182 |
|
|
begin
|
| 5183 |
|
|
tmp_len = tmp_len; // length of frame remaines from previous settings
|
| 5184 |
|
|
tmp_bd_num = 0; // TX BD number
|
| 5185 |
|
|
while (tmp_bd_num < 19) // (tmp_len <= (max_tmp - 4)) - this is the last frame
|
| 5186 |
|
|
begin
|
| 5187 |
|
|
// if i_length[1] == 0 then enable interrupt generation otherwise disable it
|
| 5188 |
|
|
// if i_length[0] == 0 then base address is `MEMORY_BASE otherwise it is `MEMORY_BASE + max_tmp
|
| 5189 |
|
|
if (tmp_len[0] == 0)
|
| 5190 |
|
|
set_tx_bd(tmp_bd_num, tmp_bd_num, tmp_len, !tmp_len[1], 1'b1, 1'b1, (`MEMORY_BASE + tmp_len[1:0]));
|
| 5191 |
|
|
else
|
| 5192 |
|
|
set_tx_bd(tmp_bd_num, tmp_bd_num, tmp_len, !tmp_len[1], 1'b1, 1'b1, ((`MEMORY_BASE + tmp_len[1:0]) + max_tmp));
|
| 5193 |
|
|
// set length (loop variable) - THE SAME AS AT THE END OF THIS TASK !!!
|
| 5194 |
|
|
if ((tmp_len + 4) < (min_tmp + 128))
|
| 5195 |
|
|
tmp_len = tmp_len + 1;
|
| 5196 |
|
|
else if ( ((tmp_len + 4) == (min_tmp + 128)) && ((tmp_len + 4) <= (max_tmp - 256)) )
|
| 5197 |
|
|
tmp_len = 256;
|
| 5198 |
|
|
else if ( ((tmp_len + 4) > (min_tmp + 128)) && ((tmp_len + 4) <= (max_tmp - 256)) )
|
| 5199 |
|
|
tmp_len = tmp_len + 128;
|
| 5200 |
|
|
else if ( ((tmp_len + 4) > (max_tmp - 256)) && ((tmp_len + 4) < (max_tmp - 16)) )
|
| 5201 |
|
|
tmp_len = max_tmp - (4 + 16);
|
| 5202 |
|
|
else if ((tmp_len + 4) >= (max_tmp - 16))
|
| 5203 |
|
|
tmp_len = tmp_len + 1;
|
| 5204 |
|
|
// set TX BD number
|
| 5205 |
|
|
tmp_bd_num = tmp_bd_num + 1;
|
| 5206 |
|
|
end
|
| 5207 |
|
|
end
|
| 5208 |
|
|
// set ready bit
|
| 5209 |
|
|
if (num_of_frames < 8)
|
| 5210 |
|
|
set_tx_bd_ready(0, 0);
|
| 5211 |
|
|
else if ((num_of_frames - 8) < 128)
|
| 5212 |
|
|
set_tx_bd_ready((num_of_frames - 8), (num_of_frames - 8));
|
| 5213 |
|
|
else if ((num_of_frames - 136) < 19)
|
| 5214 |
|
|
set_tx_bd_ready((num_of_frames - 136), (num_of_frames - 136));
|
| 5215 |
|
|
// CHECK END OF TRANSMITION
|
| 5216 |
|
|
#1 check_tx_bd(num_of_bd, data);
|
| 5217 |
|
|
if (i_length < min_tmp) // just first four
|
| 5218 |
|
|
begin
|
| 5219 |
|
|
while (data[15] === 1)
|
| 5220 |
|
|
begin
|
| 5221 |
|
|
#1 check_tx_bd(num_of_bd, data);
|
| 5222 |
|
|
@(posedge wb_clk);
|
| 5223 |
|
|
end
|
| 5224 |
|
|
repeat (1) @(posedge wb_clk);
|
| 5225 |
|
|
end
|
| 5226 |
|
|
else if (i_length > (max_tmp - 8)) // just last four
|
| 5227 |
|
|
begin
|
| 5228 |
|
|
tmp = 0;
|
| 5229 |
|
|
wait (MTxEn === 1'b1); // start transmit
|
| 5230 |
|
|
while (tmp < (i_length - 20))
|
| 5231 |
|
|
begin
|
| 5232 |
|
|
#1 tmp = tmp + 1;
|
| 5233 |
|
|
@(posedge wb_clk);
|
| 5234 |
|
|
end
|
| 5235 |
|
|
#1 check_tx_bd(num_of_bd, data);
|
| 5236 |
|
|
while (data[15] === 1)
|
| 5237 |
|
|
begin
|
| 5238 |
|
|
#1 check_tx_bd(num_of_bd, data);
|
| 5239 |
|
|
@(posedge wb_clk);
|
| 5240 |
|
|
end
|
| 5241 |
|
|
repeat (1) @(posedge wb_clk);
|
| 5242 |
|
|
end
|
| 5243 |
|
|
else
|
| 5244 |
|
|
begin
|
| 5245 |
|
|
wait (MTxEn === 1'b1); // start transmit
|
| 5246 |
|
|
#1 check_tx_bd(num_of_bd, data);
|
| 5247 |
|
|
if (data[15] !== 1)
|
| 5248 |
|
|
begin
|
| 5249 |
|
|
test_fail("Wrong buffer descriptor's ready bit read out from MAC");
|
| 5250 |
|
|
fail = fail + 1;
|
| 5251 |
|
|
end
|
| 5252 |
|
|
wait (MTxEn === 1'b0); // end transmit
|
| 5253 |
|
|
while (data[15] === 1)
|
| 5254 |
|
|
begin
|
| 5255 |
|
|
#1 check_tx_bd(num_of_bd, data);
|
| 5256 |
|
|
@(posedge wb_clk);
|
| 5257 |
|
|
end
|
| 5258 |
|
|
repeat (1) @(posedge wb_clk);
|
| 5259 |
|
|
end
|
| 5260 |
|
|
// check length of a PACKET
|
| 5261 |
|
|
if (eth_phy.tx_len != (i_length + 4))
|
| 5262 |
|
|
begin
|
| 5263 |
|
|
test_fail("Wrong length of the packet out from MAC");
|
| 5264 |
|
|
fail = fail + 1;
|
| 5265 |
|
|
end
|
| 5266 |
|
|
// check transmitted TX packet data
|
| 5267 |
|
|
if (i_length[0] == 0)
|
| 5268 |
|
|
begin
|
| 5269 |
|
|
check_tx_packet((`MEMORY_BASE + i_length[1:0]), 0, i_length, tmp);
|
| 5270 |
|
|
end
|
| 5271 |
|
|
else
|
| 5272 |
|
|
begin
|
| 5273 |
|
|
check_tx_packet(((`MEMORY_BASE + i_length[1:0]) + max_tmp), max_tmp, i_length, tmp);
|
| 5274 |
|
|
end
|
| 5275 |
|
|
if (tmp > 0)
|
| 5276 |
|
|
begin
|
| 5277 |
|
|
test_fail("Wrong data of the transmitted packet");
|
| 5278 |
|
|
fail = fail + 1;
|
| 5279 |
|
|
end
|
| 5280 |
|
|
// check transmited TX packet CRC
|
| 5281 |
|
|
if (i_length[0] == 0)
|
| 5282 |
|
|
check_tx_crc(0, i_length, 1'b0, tmp); // length without CRC
|
| 5283 |
|
|
else
|
| 5284 |
|
|
check_tx_crc(max_tmp, i_length, 1'b0, tmp); // length without CRC
|
| 5285 |
|
|
if (tmp > 0)
|
| 5286 |
|
|
begin
|
| 5287 |
|
|
test_fail("Wrong CRC of the transmitted packet");
|
| 5288 |
|
|
fail = fail + 1;
|
| 5289 |
|
|
end
|
| 5290 |
|
|
// check WB INT signal
|
| 5291 |
|
|
if (i_length[1:0] == 2'h0)
|
| 5292 |
|
|
begin
|
| 5293 |
|
|
if (wb_int !== 1'b1)
|
| 5294 |
|
|
begin
|
| 5295 |
|
|
`TIME; $display("*E WB INT signal should be set");
|
| 5296 |
|
|
test_fail("WB INT signal should be set");
|
| 5297 |
|
|
fail = fail + 1;
|
| 5298 |
|
|
end
|
| 5299 |
|
|
end
|
| 5300 |
|
|
else
|
| 5301 |
|
|
begin
|
| 5302 |
|
|
if (wb_int !== 1'b0)
|
| 5303 |
|
|
begin
|
| 5304 |
|
|
`TIME; $display("*E WB INT signal should not be set");
|
| 5305 |
|
|
test_fail("WB INT signal should not be set");
|
| 5306 |
|
|
fail = fail + 1;
|
| 5307 |
|
|
end
|
| 5308 |
|
|
end
|
| 5309 |
|
|
// check TX buffer descriptor of a packet
|
| 5310 |
|
|
check_tx_bd(num_of_bd, data);
|
| 5311 |
|
|
if (i_length[1] == 1'b0) // interrupt enabled
|
| 5312 |
|
|
begin
|
| 5313 |
|
|
if ( ((data[15:0] !== 16'h7800) && ((num_of_frames < 8) || ((num_of_frames - 8) == 127))) || // wrap bit
|
| 5314 |
|
|
((data[15:0] !== 16'h5800) && (num_of_frames >= 8) && ((num_of_frames - 8) != 127)) ) // without wrap bit
|
| 5315 |
|
|
begin
|
| 5316 |
|
|
`TIME; $display("*E TX buffer descriptor status is not correct: %0h", data[15:0]);
|
| 5317 |
|
|
test_fail("TX buffer descriptor status is not correct");
|
| 5318 |
|
|
fail = fail + 1;
|
| 5319 |
|
|
end
|
| 5320 |
|
|
end
|
| 5321 |
|
|
else // interrupt not enabled
|
| 5322 |
|
|
begin
|
| 5323 |
|
|
if ( ((data[15:0] !== 16'h3800) && ((num_of_frames < 8) || ((num_of_frames - 8) == 127))) || // wrap bit
|
| 5324 |
|
|
((data[15:0] !== 16'h1800) && (num_of_frames >= 8) && ((num_of_frames - 8) != 127)) ) // without wrap bit
|
| 5325 |
|
|
begin
|
| 5326 |
|
|
`TIME; $display("*E TX buffer descriptor status is not correct: %0h", data[15:0]);
|
| 5327 |
|
|
test_fail("TX buffer descriptor status is not correct");
|
| 5328 |
|
|
fail = fail + 1;
|
| 5329 |
|
|
end
|
| 5330 |
|
|
end
|
| 5331 |
|
|
// clear first half of 8 frames from TX buffer descriptor 0
|
| 5332 |
|
|
if (num_of_frames < 4)
|
| 5333 |
|
|
clear_tx_bd(num_of_bd, num_of_bd);
|
| 5334 |
|
|
// clear BD with wrap bit
|
| 5335 |
|
|
if (num_of_frames == 140)
|
| 5336 |
|
|
clear_tx_bd(127, 127);
|
| 5337 |
|
|
// check interrupts
|
| 5338 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 5339 |
209 |
tadejm |
wbm_read(`ETH_INT, data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 5340 |
|
|
if ((i_length[1:0] == 2'h0) || (i_length[1:0] == 2'h1))
|
| 5341 |
|
|
begin
|
| 5342 |
|
|
if ((data & `ETH_INT_TXB) !== 1'b1)
|
| 5343 |
|
|
begin
|
| 5344 |
|
|
`TIME; $display("*E Interrupt Transmit Buffer was not set, interrupt reg: %0h", data);
|
| 5345 |
|
|
test_fail("Interrupt Transmit Buffer was not set");
|
| 5346 |
|
|
fail = fail + 1;
|
| 5347 |
|
|
end
|
| 5348 |
|
|
if ((data & (~`ETH_INT_TXB)) !== 0)
|
| 5349 |
|
|
begin
|
| 5350 |
|
|
`TIME; $display("*E Other interrupts (except Transmit Buffer) were set, interrupt reg: %0h", data);
|
| 5351 |
|
|
test_fail("Other interrupts (except Transmit Buffer) were set");
|
| 5352 |
|
|
fail = fail + 1;
|
| 5353 |
|
|
end
|
| 5354 |
|
|
end
|
| 5355 |
|
|
else
|
| 5356 |
|
|
begin
|
| 5357 |
|
|
if (data !== 0)
|
| 5358 |
|
|
begin
|
| 5359 |
|
|
`TIME; $display("*E Any of interrupts (except Transmit Buffer) was set, interrupt reg: %0h, len: %0h", data, i_length[1:0]);
|
| 5360 |
|
|
test_fail("Any of interrupts (except Transmit Buffer) was set");
|
| 5361 |
|
|
fail = fail + 1;
|
| 5362 |
|
|
end
|
| 5363 |
|
|
end
|
| 5364 |
|
|
// clear interrupts
|
| 5365 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 5366 |
209 |
tadejm |
wbm_write(`ETH_INT, data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 5367 |
|
|
// check WB INT signal
|
| 5368 |
|
|
if (wb_int !== 1'b0)
|
| 5369 |
|
|
begin
|
| 5370 |
|
|
test_fail("WB INT signal should not be set");
|
| 5371 |
|
|
fail = fail + 1;
|
| 5372 |
|
|
end
|
| 5373 |
|
|
// INTERMEDIATE DISPLAYS
|
| 5374 |
|
|
if ((i_length + 4) == (min_tmp + 7))
|
| 5375 |
|
|
begin
|
| 5376 |
|
|
// starting length is min_tmp, ending length is (min_tmp + 128)
|
| 5377 |
|
|
$display(" pads appending to packets is NOT selected");
|
| 5378 |
|
|
$display(" using only TX BD 0 out of 128 BDs assigned to TX (wrap at first BD - TX BD 0)");
|
| 5379 |
|
|
$display(" ->packets with lengths from %0d (MINFL) to %0d are checked (length increasing by 1 byte)",
|
| 5380 |
|
|
min_tmp, (min_tmp + 7));
|
| 5381 |
|
|
$display(" ->all packets were send from TX BD 0");
|
| 5382 |
|
|
// set padding, remain the rest
|
| 5383 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 5384 |
209 |
tadejm |
wbm_write(`ETH_MODER, `ETH_MODER_TXEN | `ETH_MODER_FULLD | `ETH_MODER_PAD | `ETH_MODER_CRCEN,
|
| 5385 |
|
|
4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 5386 |
|
|
end
|
| 5387 |
|
|
else if ((i_length + 4) == (min_tmp + 128))
|
| 5388 |
|
|
begin
|
| 5389 |
|
|
// starting length is min_tmp, ending length is (min_tmp + 128)
|
| 5390 |
|
|
$display(" pads appending to packets is NOT selected");
|
| 5391 |
|
|
$display(" using all 128 BDs assigned to TX (wrap at 128th BD - TX BD 127)");
|
| 5392 |
|
|
$display(" ->packets with lengths from %0d to %0d are checked (length increasing by 1 byte)",
|
| 5393 |
|
|
(min_tmp + 8), (min_tmp + 128));
|
| 5394 |
|
|
$display(" ->packets were send from TX BD %0d to TX BD %0d respectively",
|
| 5395 |
|
|
1'b0, num_of_bd);
|
| 5396 |
|
|
tmp_bd = num_of_bd + 1;
|
| 5397 |
|
|
// set padding, remain the rest
|
| 5398 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 5399 |
209 |
tadejm |
wbm_write(`ETH_MODER, `ETH_MODER_TXEN | `ETH_MODER_FULLD | `ETH_MODER_PAD | `ETH_MODER_CRCEN,
|
| 5400 |
|
|
4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 5401 |
|
|
end
|
| 5402 |
|
|
else if ((i_length + 4) == (max_tmp - 16))
|
| 5403 |
|
|
begin
|
| 5404 |
|
|
// starting length is for +128 longer than previous ending length, while ending length is tmp_data
|
| 5405 |
|
|
$display(" pads appending to packets is selected");
|
| 5406 |
|
|
$display(" using all 128 BDs assigned to TX (wrap at 128th BD - TX BD 127)");
|
| 5407 |
|
|
$display(" ->packets with lengths from %0d to %0d are checked (length increasing by 128 bytes)",
|
| 5408 |
|
|
(min_tmp + 64 + 128), tmp_data);
|
| 5409 |
|
|
if (tmp_bd > num_of_bd)
|
| 5410 |
|
|
$display(" ->packets were send from TX BD %0d to TX BD 127 and from TX BD 0 to TX BD %0d respectively",
|
| 5411 |
|
|
tmp_bd, num_of_bd);
|
| 5412 |
|
|
else
|
| 5413 |
|
|
$display(" ->packets were send from TX BD %0d to TX BD %0d respectively",
|
| 5414 |
|
|
tmp_bd, num_of_bd);
|
| 5415 |
|
|
tmp_bd = num_of_bd + 1;
|
| 5416 |
|
|
// reset padding, remain the rest
|
| 5417 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 5418 |
209 |
tadejm |
wbm_write(`ETH_MODER, `ETH_MODER_TXEN | `ETH_MODER_FULLD | `ETH_MODER_CRCEN,
|
| 5419 |
|
|
4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 5420 |
|
|
end
|
| 5421 |
|
|
else if ((i_length + 4) == max_tmp)
|
| 5422 |
|
|
begin
|
| 5423 |
|
|
$display(" pads appending to packets is NOT selected");
|
| 5424 |
|
|
$display(" using all 128 BDs assigned to TX (wrap at 128th BD - TX BD 127)");
|
| 5425 |
|
|
$display(" ->packets with lengths from %0d to %0d (MAXFL) are checked (length increasing by 1 byte)",
|
| 5426 |
|
|
(max_tmp - (4 + 16)), max_tmp);
|
| 5427 |
|
|
if (tmp_bd > num_of_bd)
|
| 5428 |
|
|
$display(" ->packets were send from TX BD %0d to TX BD 127 and from TX BD 0 to TX BD %0d respectively",
|
| 5429 |
|
|
tmp_bd, num_of_bd);
|
| 5430 |
|
|
else
|
| 5431 |
|
|
$display(" ->packets were send from TX BD %0d to TX BD %0d respectively",
|
| 5432 |
|
|
tmp_bd, num_of_bd);
|
| 5433 |
|
|
end
|
| 5434 |
|
|
// set length (loop variable)
|
| 5435 |
|
|
if ((i_length + 4) < (min_tmp + 128))
|
| 5436 |
|
|
i_length = i_length + 1;
|
| 5437 |
|
|
else if ( ((i_length + 4) == (min_tmp + 128)) && ((i_length + 4) <= (max_tmp - 256)) )
|
| 5438 |
|
|
i_length = 256;
|
| 5439 |
|
|
else if ( ((i_length + 4) > (min_tmp + 128)) && ((i_length + 4) <= (max_tmp - 256)) )
|
| 5440 |
|
|
begin
|
| 5441 |
|
|
i_length = i_length + 128;
|
| 5442 |
|
|
tmp_data = i_length + 4; // last tmp_data is ending length
|
| 5443 |
|
|
end
|
| 5444 |
|
|
else if ( ((i_length + 4) > (max_tmp - 256)) && ((i_length + 4) < (max_tmp - 16)) )
|
| 5445 |
|
|
i_length = max_tmp - (4 + 16);
|
| 5446 |
|
|
else if ((i_length + 4) >= (max_tmp - 16))
|
| 5447 |
|
|
i_length = i_length + 1;
|
| 5448 |
|
|
else
|
| 5449 |
|
|
begin
|
| 5450 |
|
|
$display("*E TESTBENCH ERROR - WRONG PARAMETERS IN TESTBENCH");
|
| 5451 |
|
|
#10 $stop;
|
| 5452 |
|
|
end
|
| 5453 |
|
|
// the number of frame transmitted
|
| 5454 |
|
|
num_of_frames = num_of_frames + 1;
|
| 5455 |
|
|
if ((num_of_frames <= 8) || ((num_of_frames - 8) == 128))
|
| 5456 |
|
|
num_of_bd = 0;
|
| 5457 |
|
|
else
|
| 5458 |
|
|
num_of_bd = num_of_bd + 1;
|
| 5459 |
|
|
end
|
| 5460 |
|
|
// disable TX
|
| 5461 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 5462 |
209 |
tadejm |
wbm_write(`ETH_MODER, `ETH_MODER_FULLD | `ETH_MODER_PAD | `ETH_MODER_CRCEN,
|
| 5463 |
|
|
4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 5464 |
|
|
@(posedge wb_clk);
|
| 5465 |
|
|
if(fail == 0)
|
| 5466 |
|
|
test_ok;
|
| 5467 |
|
|
else
|
| 5468 |
|
|
fail = 0;
|
| 5469 |
|
|
end
|
| 5470 |
|
|
|
| 5471 |
|
|
|
| 5472 |
|
|
////////////////////////////////////////////////////////////////////
|
| 5473 |
|
|
//// ////
|
| 5474 |
|
|
//// Test transmit packets form MINFL to MAXFL sizes at ////
|
| 5475 |
|
|
//// maximum TX buffer decriptors ( 100Mbps ). ////
|
| 5476 |
|
|
//// ////
|
| 5477 |
|
|
////////////////////////////////////////////////////////////////////
|
| 5478 |
|
|
if (test_num == 5) // with and without padding
|
| 5479 |
|
|
begin
|
| 5480 |
|
|
// TEST 5: TRANSMIT PACKETS FROM MINFL TO MAXFL SIZES AT MAX TX BDs ( 100Mbps )
|
| 5481 |
|
|
test_name = "TEST 5: TRANSMIT PACKETS FROM MINFL TO MAXFL SIZES AT MAX TX BDs ( 100Mbps )";
|
| 5482 |
|
|
`TIME; $display(" TEST 5: TRANSMIT PACKETS FROM MINFL TO MAXFL SIZES AT MAX TX BDs ( 100Mbps )");
|
| 5483 |
|
|
|
| 5484 |
|
|
// reset MAC registers
|
| 5485 |
|
|
hard_reset;
|
| 5486 |
|
|
// reset MAC and MII LOGIC with soft reset
|
| 5487 |
274 |
tadejm |
// reset_mac;
|
| 5488 |
|
|
// reset_mii;
|
| 5489 |
209 |
tadejm |
// set wb slave response
|
| 5490 |
|
|
wb_slave.cycle_response(`ACK_RESPONSE, wbs_waits, wbs_retries);
|
| 5491 |
|
|
|
| 5492 |
|
|
max_tmp = 0;
|
| 5493 |
|
|
min_tmp = 0;
|
| 5494 |
|
|
num_of_frames = 0;
|
| 5495 |
|
|
num_of_bd = 0;
|
| 5496 |
|
|
// set maximum TX buffer descriptors (128) - must be set before TX enable
|
| 5497 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 5498 |
209 |
tadejm |
wbm_write(`ETH_TX_BD_NUM, 32'h80, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 5499 |
|
|
// enable TX, set full-duplex mode, NO padding and CRC appending
|
| 5500 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 5501 |
209 |
tadejm |
wbm_write(`ETH_MODER, `ETH_MODER_TXEN | `ETH_MODER_FULLD | `ETH_MODER_CRCEN,
|
| 5502 |
|
|
4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 5503 |
|
|
// prepare two packets of MAXFL length
|
| 5504 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 5505 |
209 |
tadejm |
wbm_read(`ETH_PACKETLEN, tmp, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 5506 |
|
|
max_tmp = tmp[15:0]; // 18 bytes consists of 6B dest addr, 6B source addr, 2B type/len, 4B CRC
|
| 5507 |
|
|
min_tmp = tmp[31:16];
|
| 5508 |
|
|
st_data = 8'hA5;
|
| 5509 |
|
|
set_tx_packet(`MEMORY_BASE, (max_tmp), st_data); // length without CRC
|
| 5510 |
|
|
st_data = 8'h71;
|
| 5511 |
|
|
set_tx_packet((`MEMORY_BASE + max_tmp), (max_tmp), st_data); // length without CRC
|
| 5512 |
|
|
// check WB INT signal
|
| 5513 |
|
|
if (wb_int !== 1'b0)
|
| 5514 |
|
|
begin
|
| 5515 |
|
|
test_fail("WB INT signal should not be set");
|
| 5516 |
|
|
fail = fail + 1;
|
| 5517 |
|
|
end
|
| 5518 |
|
|
|
| 5519 |
|
|
// write to phy's control register for 100Mbps
|
| 5520 |
|
|
#Tp eth_phy.control_bit14_10 = 5'b01000; // bit 13 set - speed 100
|
| 5521 |
|
|
#Tp eth_phy.control_bit8_0 = 9'h1_00; // bit 6 reset - (10/100), bit 8 set - FD
|
| 5522 |
|
|
speed = 100;
|
| 5523 |
|
|
|
| 5524 |
|
|
i_length = (min_tmp - 4);
|
| 5525 |
|
|
while (i_length <= (max_tmp - 4))
|
| 5526 |
|
|
begin
|
| 5527 |
|
|
// choose generating carrier sense and collision
|
| 5528 |
|
|
case (i_length[1:0])
|
| 5529 |
|
|
2'h0: // Interrupt is generated
|
| 5530 |
|
|
begin
|
| 5531 |
|
|
// Reset_tx_bd nable interrupt generation
|
| 5532 |
|
|
// unmask interrupts
|
| 5533 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 5534 |
209 |
tadejm |
wbm_write(`ETH_INT_MASK, `ETH_INT_TXB | `ETH_INT_TXE | `ETH_INT_RXB | `ETH_INT_RXE | `ETH_INT_BUSY |
|
| 5535 |
|
|
`ETH_INT_TXC | `ETH_INT_RXC, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 5536 |
|
|
// not detect carrier sense in FD and no collision
|
| 5537 |
|
|
eth_phy.carrier_sense_tx_fd_detect(0);
|
| 5538 |
|
|
eth_phy.collision(0);
|
| 5539 |
|
|
end
|
| 5540 |
|
|
2'h1: // Interrupt is not generated
|
| 5541 |
|
|
begin
|
| 5542 |
|
|
// set_tx_bd enable interrupt generation
|
| 5543 |
|
|
// mask interrupts
|
| 5544 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 5545 |
209 |
tadejm |
wbm_write(`ETH_INT_MASK, 32'h0, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 5546 |
|
|
// detect carrier sense in FD and no collision
|
| 5547 |
|
|
eth_phy.carrier_sense_tx_fd_detect(1);
|
| 5548 |
|
|
eth_phy.collision(0);
|
| 5549 |
|
|
end
|
| 5550 |
|
|
2'h2: // Interrupt is not generated
|
| 5551 |
|
|
begin
|
| 5552 |
|
|
// set_tx_bd disable the interrupt generation
|
| 5553 |
|
|
// unmask interrupts
|
| 5554 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 5555 |
209 |
tadejm |
wbm_write(`ETH_INT_MASK, `ETH_INT_TXB | `ETH_INT_TXE | `ETH_INT_RXB | `ETH_INT_RXE | `ETH_INT_BUSY |
|
| 5556 |
|
|
`ETH_INT_TXC | `ETH_INT_RXC, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 5557 |
|
|
// not detect carrier sense in FD and set collision
|
| 5558 |
|
|
eth_phy.carrier_sense_tx_fd_detect(0);
|
| 5559 |
|
|
eth_phy.collision(1);
|
| 5560 |
|
|
end
|
| 5561 |
|
|
default: // 2'h3: // Interrupt is not generated
|
| 5562 |
|
|
begin
|
| 5563 |
|
|
// set_tx_bd disable the interrupt generation
|
| 5564 |
|
|
// mask interrupts
|
| 5565 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 5566 |
209 |
tadejm |
wbm_write(`ETH_INT_MASK, 32'h0, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 5567 |
|
|
// detect carrier sense in FD and set collision
|
| 5568 |
|
|
eth_phy.carrier_sense_tx_fd_detect(1);
|
| 5569 |
|
|
eth_phy.collision(1);
|
| 5570 |
|
|
end
|
| 5571 |
|
|
endcase
|
| 5572 |
|
|
// first destination address on ethernet PHY
|
| 5573 |
|
|
if (i_length[0] == 0)
|
| 5574 |
|
|
eth_phy.set_tx_mem_addr(0);
|
| 5575 |
|
|
else
|
| 5576 |
|
|
eth_phy.set_tx_mem_addr(max_tmp);
|
| 5577 |
|
|
// first 8 frames are transmitted with TX BD 0 (wrap bit on TX BD 0)
|
| 5578 |
|
|
// number of all frames is 154 (146 without first 8)
|
| 5579 |
|
|
if (num_of_frames < 8)
|
| 5580 |
|
|
begin
|
| 5581 |
|
|
case (i_length[1:0])
|
| 5582 |
|
|
2'h0: // Interrupt is generated
|
| 5583 |
|
|
begin
|
| 5584 |
|
|
// enable interrupt generation
|
| 5585 |
|
|
set_tx_bd(0, 0, i_length, 1'b1, 1'b1, 1'b1, (`MEMORY_BASE + i_length[1:0]));
|
| 5586 |
|
|
// interrupts are unmasked
|
| 5587 |
|
|
end
|
| 5588 |
|
|
2'h1: // Interrupt is not generated
|
| 5589 |
|
|
begin
|
| 5590 |
|
|
// enable interrupt generation
|
| 5591 |
|
|
set_tx_bd(0, 0, i_length, 1'b1, 1'b1, 1'b1, ((`MEMORY_BASE + i_length[1:0]) + max_tmp));
|
| 5592 |
|
|
// interrupts are masked
|
| 5593 |
|
|
end
|
| 5594 |
|
|
2'h2: // Interrupt is not generated
|
| 5595 |
|
|
begin
|
| 5596 |
|
|
// disable interrupt generation
|
| 5597 |
|
|
set_tx_bd(0, 0, i_length, 1'b0, 1'b1, 1'b1, (`MEMORY_BASE + i_length[1:0]));
|
| 5598 |
|
|
// interrupts are unmasked
|
| 5599 |
|
|
end
|
| 5600 |
|
|
default: // 2'h3: // Interrupt is not generated
|
| 5601 |
|
|
begin
|
| 5602 |
|
|
// disable interrupt generation
|
| 5603 |
|
|
set_tx_bd(0, 0, i_length, 1'b0, 1'b1, 1'b1, ((`MEMORY_BASE + i_length[1:0]) + max_tmp));
|
| 5604 |
|
|
// interrupts are masked
|
| 5605 |
|
|
end
|
| 5606 |
|
|
endcase
|
| 5607 |
|
|
// set wrap bit
|
| 5608 |
|
|
set_tx_bd_wrap(0);
|
| 5609 |
|
|
end
|
| 5610 |
|
|
// after first 8 number of frames, 128 frames form TX BD 0 to 127 will be transmitted
|
| 5611 |
|
|
else if ((num_of_frames - 8) == 0)
|
| 5612 |
|
|
begin
|
| 5613 |
|
|
tmp_len = i_length; // length of frame
|
| 5614 |
|
|
tmp_bd_num = 0; // TX BD number
|
| 5615 |
|
|
while (tmp_bd_num < 128) // (tmp_len <= (max_tmp - 4)) - this is the last frame
|
| 5616 |
|
|
begin
|
| 5617 |
|
|
// if i_length[1] == 0 then enable interrupt generation otherwise disable it
|
| 5618 |
|
|
// if i_length[0] == 0 then base address is `MEMORY_BASE otherwise it is `MEMORY_BASE + max_tmp
|
| 5619 |
|
|
if (tmp_len[0] == 0)
|
| 5620 |
|
|
set_tx_bd(tmp_bd_num, tmp_bd_num, tmp_len, !tmp_len[1], 1'b1, 1'b1, (`MEMORY_BASE + tmp_len[1:0]));
|
| 5621 |
|
|
else
|
| 5622 |
|
|
set_tx_bd(tmp_bd_num, tmp_bd_num, tmp_len, !tmp_len[1], 1'b1, 1'b1, ((`MEMORY_BASE + tmp_len[1:0]) + max_tmp));
|
| 5623 |
|
|
// set length (loop variable) - THE SAME AS AT THE END OF THIS TASK !!!
|
| 5624 |
|
|
if ((tmp_len + 4) < (min_tmp + 128))
|
| 5625 |
|
|
tmp_len = tmp_len + 1;
|
| 5626 |
|
|
else if ( ((tmp_len + 4) == (min_tmp + 128)) && ((tmp_len + 4) <= (max_tmp - 256)) )
|
| 5627 |
|
|
tmp_len = 256;
|
| 5628 |
|
|
else if ( ((tmp_len + 4) > (min_tmp + 128)) && ((tmp_len + 4) <= (max_tmp - 256)) )
|
| 5629 |
|
|
tmp_len = tmp_len + 128;
|
| 5630 |
|
|
else if ( ((tmp_len + 4) > (max_tmp - 256)) && ((tmp_len + 4) < (max_tmp - 16)) )
|
| 5631 |
|
|
tmp_len = max_tmp - (4 + 16);
|
| 5632 |
|
|
else if ((tmp_len + 4) >= (max_tmp - 16))
|
| 5633 |
|
|
tmp_len = tmp_len + 1;
|
| 5634 |
|
|
// set TX BD number
|
| 5635 |
|
|
tmp_bd_num = tmp_bd_num + 1;
|
| 5636 |
|
|
end
|
| 5637 |
|
|
// set wrap bit
|
| 5638 |
|
|
set_tx_bd_wrap(127);
|
| 5639 |
|
|
end
|
| 5640 |
|
|
// after 128 + first 8 number of frames, 19 frames form TX BD 0 to 18 will be transmitted
|
| 5641 |
|
|
else if ((num_of_frames - 8) == 20) // 128
|
| 5642 |
|
|
begin
|
| 5643 |
|
|
tmp_len = tmp_len; // length of frame remaines from previous settings
|
| 5644 |
|
|
tmp_bd_num = 0; // TX BD number
|
| 5645 |
|
|
while (tmp_bd_num < 19) // (tmp_len <= (max_tmp - 4)) - this is the last frame
|
| 5646 |
|
|
begin
|
| 5647 |
|
|
// if i_length[1] == 0 then enable interrupt generation otherwise disable it
|
| 5648 |
|
|
// if i_length[0] == 0 then base address is `MEMORY_BASE otherwise it is `MEMORY_BASE + max_tmp
|
| 5649 |
|
|
if (tmp_len[0] == 0)
|
| 5650 |
|
|
set_tx_bd(tmp_bd_num, tmp_bd_num, tmp_len, !tmp_len[1], 1'b1, 1'b1, (`MEMORY_BASE + tmp_len[1:0]));
|
| 5651 |
|
|
else
|
| 5652 |
|
|
set_tx_bd(tmp_bd_num, tmp_bd_num, tmp_len, !tmp_len[1], 1'b1, 1'b1, ((`MEMORY_BASE + tmp_len[1:0]) + max_tmp));
|
| 5653 |
|
|
// set length (loop variable) - THE SAME AS AT THE END OF THIS TASK !!!
|
| 5654 |
|
|
if ((tmp_len + 4) < (min_tmp + 128))
|
| 5655 |
|
|
tmp_len = tmp_len + 1;
|
| 5656 |
|
|
else if ( ((tmp_len + 4) == (min_tmp + 128)) && ((tmp_len + 4) <= (max_tmp - 256)) )
|
| 5657 |
|
|
tmp_len = 256;
|
| 5658 |
|
|
else if ( ((tmp_len + 4) > (min_tmp + 128)) && ((tmp_len + 4) <= (max_tmp - 256)) )
|
| 5659 |
|
|
tmp_len = tmp_len + 128;
|
| 5660 |
|
|
else if ( ((tmp_len + 4) > (max_tmp - 256)) && ((tmp_len + 4) < (max_tmp - 16)) )
|
| 5661 |
|
|
tmp_len = max_tmp - (4 + 16);
|
| 5662 |
|
|
else if ((tmp_len + 4) >= (max_tmp - 16))
|
| 5663 |
|
|
tmp_len = tmp_len + 1;
|
| 5664 |
|
|
// set TX BD number
|
| 5665 |
|
|
tmp_bd_num = tmp_bd_num + 1;
|
| 5666 |
|
|
end
|
| 5667 |
|
|
end
|
| 5668 |
|
|
// set ready bit
|
| 5669 |
|
|
if (num_of_frames < 8)
|
| 5670 |
|
|
set_tx_bd_ready(0, 0);
|
| 5671 |
|
|
else if ((num_of_frames - 8) < 128)
|
| 5672 |
|
|
set_tx_bd_ready((num_of_frames - 8), (num_of_frames - 8));
|
| 5673 |
|
|
else if ((num_of_frames - 136) < 19)
|
| 5674 |
|
|
set_tx_bd_ready((num_of_frames - 136), (num_of_frames - 136));
|
| 5675 |
|
|
// CHECK END OF TRANSMITION
|
| 5676 |
|
|
#1 check_tx_bd(num_of_bd, data);
|
| 5677 |
|
|
if (i_length < min_tmp) // just first four
|
| 5678 |
|
|
begin
|
| 5679 |
|
|
while (data[15] === 1)
|
| 5680 |
|
|
begin
|
| 5681 |
|
|
#1 check_tx_bd(num_of_bd, data);
|
| 5682 |
|
|
@(posedge wb_clk);
|
| 5683 |
|
|
end
|
| 5684 |
|
|
repeat (1) @(posedge wb_clk);
|
| 5685 |
|
|
end
|
| 5686 |
|
|
else if (i_length > (max_tmp - 8)) // just last four
|
| 5687 |
|
|
begin
|
| 5688 |
|
|
tmp = 0;
|
| 5689 |
|
|
wait (MTxEn === 1'b1); // start transmit
|
| 5690 |
|
|
while (tmp < (i_length - 20))
|
| 5691 |
|
|
begin
|
| 5692 |
|
|
#1 tmp = tmp + 1;
|
| 5693 |
|
|
@(posedge wb_clk);
|
| 5694 |
|
|
end
|
| 5695 |
|
|
#1 check_tx_bd(num_of_bd, data);
|
| 5696 |
|
|
while (data[15] === 1)
|
| 5697 |
|
|
begin
|
| 5698 |
|
|
#1 check_tx_bd(num_of_bd, data);
|
| 5699 |
|
|
@(posedge wb_clk);
|
| 5700 |
|
|
end
|
| 5701 |
|
|
repeat (1) @(posedge wb_clk);
|
| 5702 |
|
|
end
|
| 5703 |
|
|
else
|
| 5704 |
|
|
begin
|
| 5705 |
|
|
wait (MTxEn === 1'b1); // start transmit
|
| 5706 |
|
|
#1 check_tx_bd(num_of_bd, data);
|
| 5707 |
|
|
if (data[15] !== 1)
|
| 5708 |
|
|
begin
|
| 5709 |
|
|
test_fail("Wrong buffer descriptor's ready bit read out from MAC");
|
| 5710 |
|
|
fail = fail + 1;
|
| 5711 |
|
|
end
|
| 5712 |
|
|
wait (MTxEn === 1'b0); // end transmit
|
| 5713 |
|
|
while (data[15] === 1)
|
| 5714 |
|
|
begin
|
| 5715 |
|
|
#1 check_tx_bd(num_of_bd, data);
|
| 5716 |
|
|
@(posedge wb_clk);
|
| 5717 |
|
|
end
|
| 5718 |
|
|
repeat (1) @(posedge wb_clk);
|
| 5719 |
|
|
end
|
| 5720 |
|
|
// check length of a PACKET
|
| 5721 |
|
|
if (eth_phy.tx_len != (i_length + 4))
|
| 5722 |
|
|
begin
|
| 5723 |
|
|
test_fail("Wrong length of the packet out from MAC");
|
| 5724 |
|
|
fail = fail + 1;
|
| 5725 |
|
|
end
|
| 5726 |
|
|
// checking in the following if statement is performed only for first and last 64 lengths
|
| 5727 |
|
|
// check transmitted TX packet data
|
| 5728 |
|
|
if (i_length[0] == 0)
|
| 5729 |
|
|
begin
|
| 5730 |
|
|
check_tx_packet((`MEMORY_BASE + i_length[1:0]), 0, i_length, tmp);
|
| 5731 |
|
|
end
|
| 5732 |
|
|
else
|
| 5733 |
|
|
begin
|
| 5734 |
|
|
check_tx_packet(((`MEMORY_BASE + i_length[1:0]) + max_tmp), max_tmp, i_length, tmp);
|
| 5735 |
|
|
end
|
| 5736 |
|
|
if (tmp > 0)
|
| 5737 |
|
|
begin
|
| 5738 |
|
|
test_fail("Wrong data of the transmitted packet");
|
| 5739 |
|
|
fail = fail + 1;
|
| 5740 |
|
|
end
|
| 5741 |
|
|
// check transmited TX packet CRC
|
| 5742 |
|
|
if (i_length[0] == 0)
|
| 5743 |
|
|
check_tx_crc(0, i_length, 1'b0, tmp); // length without CRC
|
| 5744 |
|
|
else
|
| 5745 |
|
|
check_tx_crc(max_tmp, i_length, 1'b0, tmp); // length without CRC
|
| 5746 |
|
|
if (tmp > 0)
|
| 5747 |
|
|
begin
|
| 5748 |
|
|
test_fail("Wrong CRC of the transmitted packet");
|
| 5749 |
|
|
fail = fail + 1;
|
| 5750 |
|
|
end
|
| 5751 |
|
|
// check WB INT signal
|
| 5752 |
|
|
if (i_length[1:0] == 2'h0)
|
| 5753 |
|
|
begin
|
| 5754 |
|
|
if (wb_int !== 1'b1)
|
| 5755 |
|
|
begin
|
| 5756 |
|
|
`TIME; $display("*E WB INT signal should be set");
|
| 5757 |
|
|
test_fail("WB INT signal should be set");
|
| 5758 |
|
|
fail = fail + 1;
|
| 5759 |
|
|
end
|
| 5760 |
|
|
end
|
| 5761 |
|
|
else
|
| 5762 |
|
|
begin
|
| 5763 |
|
|
if (wb_int !== 1'b0)
|
| 5764 |
|
|
begin
|
| 5765 |
|
|
`TIME; $display("*E WB INT signal should not be set");
|
| 5766 |
|
|
test_fail("WB INT signal should not be set");
|
| 5767 |
|
|
fail = fail + 1;
|
| 5768 |
|
|
end
|
| 5769 |
|
|
end
|
| 5770 |
|
|
// check TX buffer descriptor of a packet
|
| 5771 |
|
|
check_tx_bd(num_of_bd, data);
|
| 5772 |
|
|
if (i_length[1] == 1'b0) // interrupt enabled
|
| 5773 |
|
|
begin
|
| 5774 |
|
|
if ( ((data[15:0] !== 16'h7800) && ((num_of_frames < 8) || ((num_of_frames - 8) == 127))) || // wrap bit
|
| 5775 |
|
|
((data[15:0] !== 16'h5800) && (num_of_frames >= 8) && ((num_of_frames - 8) != 127)) ) // without wrap bit
|
| 5776 |
|
|
begin
|
| 5777 |
|
|
`TIME; $display("*E TX buffer descriptor status is not correct: %0h", data[15:0]);
|
| 5778 |
|
|
test_fail("TX buffer descriptor status is not correct");
|
| 5779 |
|
|
fail = fail + 1;
|
| 5780 |
|
|
end
|
| 5781 |
|
|
end
|
| 5782 |
|
|
else // interrupt not enabled
|
| 5783 |
|
|
begin
|
| 5784 |
|
|
if ( ((data[15:0] !== 16'h3800) && ((num_of_frames < 8) || ((num_of_frames - 8) == 127))) || // wrap bit
|
| 5785 |
|
|
((data[15:0] !== 16'h1800) && (num_of_frames >= 8) && ((num_of_frames - 8) != 127)) ) // without wrap bit
|
| 5786 |
|
|
begin
|
| 5787 |
|
|
`TIME; $display("*E TX buffer descriptor status is not correct: %0h", data[15:0]);
|
| 5788 |
|
|
test_fail("TX buffer descriptor status is not correct");
|
| 5789 |
|
|
fail = fail + 1;
|
| 5790 |
|
|
end
|
| 5791 |
|
|
end
|
| 5792 |
|
|
// clear first half of 8 frames from TX buffer descriptor 0
|
| 5793 |
|
|
if (num_of_frames < 4)
|
| 5794 |
|
|
clear_tx_bd(num_of_bd, num_of_bd);
|
| 5795 |
|
|
// clear BD with wrap bit
|
| 5796 |
|
|
if (num_of_frames == 140)
|
| 5797 |
|
|
clear_tx_bd(127, 127);
|
| 5798 |
|
|
// check interrupts
|
| 5799 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 5800 |
209 |
tadejm |
wbm_read(`ETH_INT, data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 5801 |
|
|
if ((i_length[1:0] == 2'h0) || (i_length[1:0] == 2'h1))
|
| 5802 |
|
|
begin
|
| 5803 |
|
|
if ((data & `ETH_INT_TXB) !== 1'b1)
|
| 5804 |
|
|
begin
|
| 5805 |
|
|
`TIME; $display("*E Interrupt Transmit Buffer was not set, interrupt reg: %0h", data);
|
| 5806 |
|
|
test_fail("Interrupt Transmit Buffer was not set");
|
| 5807 |
|
|
fail = fail + 1;
|
| 5808 |
|
|
end
|
| 5809 |
|
|
if ((data & (~`ETH_INT_TXB)) !== 0)
|
| 5810 |
|
|
begin
|
| 5811 |
|
|
`TIME; $display("*E Other interrupts (except Transmit Buffer) were set, interrupt reg: %0h", data);
|
| 5812 |
|
|
test_fail("Other interrupts (except Transmit Buffer) were set");
|
| 5813 |
|
|
fail = fail + 1;
|
| 5814 |
|
|
end
|
| 5815 |
|
|
end
|
| 5816 |
|
|
else
|
| 5817 |
|
|
begin
|
| 5818 |
|
|
if (data !== 0)
|
| 5819 |
|
|
begin
|
| 5820 |
|
|
`TIME; $display("*E Any of interrupts (except Transmit Buffer) was set, interrupt reg: %0h, len: %0h", data, i_length[1:0]);
|
| 5821 |
|
|
test_fail("Any of interrupts (except Transmit Buffer) was set");
|
| 5822 |
|
|
fail = fail + 1;
|
| 5823 |
|
|
end
|
| 5824 |
|
|
end
|
| 5825 |
|
|
// clear interrupts
|
| 5826 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 5827 |
209 |
tadejm |
wbm_write(`ETH_INT, data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 5828 |
|
|
// check WB INT signal
|
| 5829 |
|
|
if (wb_int !== 1'b0)
|
| 5830 |
|
|
begin
|
| 5831 |
|
|
test_fail("WB INT signal should not be set");
|
| 5832 |
|
|
fail = fail + 1;
|
| 5833 |
|
|
end
|
| 5834 |
|
|
// INTERMEDIATE DISPLAYS
|
| 5835 |
|
|
if ((i_length + 4) == (min_tmp + 7))
|
| 5836 |
|
|
begin
|
| 5837 |
|
|
// starting length is min_tmp, ending length is (min_tmp + 128)
|
| 5838 |
|
|
$display(" pads appending to packets is NOT selected");
|
| 5839 |
|
|
$display(" using only TX BD 0 out of 128 BDs assigned to TX (wrap at first BD - TX BD 0)");
|
| 5840 |
|
|
$display(" ->packets with lengths from %0d (MINFL) to %0d are checked (length increasing by 1 byte)",
|
| 5841 |
|
|
min_tmp, (min_tmp + 7));
|
| 5842 |
|
|
$display(" ->all packets were send from TX BD 0");
|
| 5843 |
|
|
// set padding, remain the rest
|
| 5844 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 5845 |
209 |
tadejm |
wbm_write(`ETH_MODER, `ETH_MODER_TXEN | `ETH_MODER_FULLD | `ETH_MODER_PAD | `ETH_MODER_CRCEN,
|
| 5846 |
|
|
4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 5847 |
|
|
end
|
| 5848 |
|
|
else if ((i_length + 4) == (min_tmp + 128))
|
| 5849 |
|
|
begin
|
| 5850 |
|
|
// starting length is min_tmp, ending length is (min_tmp + 128)
|
| 5851 |
|
|
$display(" pads appending to packets is NOT selected");
|
| 5852 |
|
|
$display(" using all 128 BDs assigned to TX (wrap at 128th BD - TX BD 127)");
|
| 5853 |
|
|
$display(" ->packets with lengths from %0d to %0d are checked (length increasing by 1 byte)",
|
| 5854 |
|
|
(min_tmp + 8), (min_tmp + 128));
|
| 5855 |
|
|
$display(" ->packets were send from TX BD %0d to TX BD %0d respectively",
|
| 5856 |
|
|
1'b0, num_of_bd);
|
| 5857 |
|
|
tmp_bd = num_of_bd + 1;
|
| 5858 |
|
|
// set padding, remain the rest
|
| 5859 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 5860 |
209 |
tadejm |
wbm_write(`ETH_MODER, `ETH_MODER_TXEN | `ETH_MODER_FULLD | `ETH_MODER_PAD | `ETH_MODER_CRCEN,
|
| 5861 |
|
|
4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 5862 |
|
|
end
|
| 5863 |
|
|
else if ((i_length + 4) == (max_tmp - 16))
|
| 5864 |
|
|
begin
|
| 5865 |
|
|
// starting length is for +128 longer than previous ending length, while ending length is tmp_data
|
| 5866 |
|
|
$display(" pads appending to packets is selected");
|
| 5867 |
|
|
$display(" using all 128 BDs assigned to TX (wrap at 128th BD - TX BD 127)");
|
| 5868 |
|
|
$display(" ->packets with lengths from %0d to %0d are checked (length increasing by 128 bytes)",
|
| 5869 |
|
|
(min_tmp + 64 + 128), tmp_data);
|
| 5870 |
|
|
if (tmp_bd > num_of_bd)
|
| 5871 |
|
|
$display(" ->packets were send from TX BD %0d to TX BD 127 and from TX BD 0 to TX BD %0d respectively",
|
| 5872 |
|
|
tmp_bd, num_of_bd);
|
| 5873 |
|
|
else
|
| 5874 |
|
|
$display(" ->packets were send from TX BD %0d to TX BD %0d respectively",
|
| 5875 |
|
|
tmp_bd, num_of_bd);
|
| 5876 |
|
|
tmp_bd = num_of_bd + 1;
|
| 5877 |
|
|
// reset padding, remain the rest
|
| 5878 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 5879 |
209 |
tadejm |
wbm_write(`ETH_MODER, `ETH_MODER_TXEN | `ETH_MODER_FULLD | `ETH_MODER_CRCEN,
|
| 5880 |
|
|
4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 5881 |
|
|
end
|
| 5882 |
|
|
else if ((i_length + 4) == max_tmp)
|
| 5883 |
|
|
begin
|
| 5884 |
|
|
$display(" pads appending to packets is NOT selected");
|
| 5885 |
|
|
$display(" using all 128 BDs assigned to TX (wrap at 128th BD - TX BD 127)");
|
| 5886 |
|
|
$display(" ->packets with lengths from %0d to %0d (MAXFL) are checked (length increasing by 1 byte)",
|
| 5887 |
|
|
(max_tmp - (4 + 16)), max_tmp);
|
| 5888 |
|
|
if (tmp_bd > num_of_bd)
|
| 5889 |
|
|
$display(" ->packets were send from TX BD %0d to TX BD 127 and from TX BD 0 to TX BD %0d respectively",
|
| 5890 |
|
|
tmp_bd, num_of_bd);
|
| 5891 |
|
|
else
|
| 5892 |
|
|
$display(" ->packets were send from TX BD %0d to TX BD %0d respectively",
|
| 5893 |
|
|
tmp_bd, num_of_bd);
|
| 5894 |
|
|
end
|
| 5895 |
|
|
// set length (loop variable)
|
| 5896 |
|
|
if ((i_length + 4) < (min_tmp + 128))
|
| 5897 |
|
|
i_length = i_length + 1;
|
| 5898 |
|
|
else if ( ((i_length + 4) == (min_tmp + 128)) && ((i_length + 4) <= (max_tmp - 256)) )
|
| 5899 |
|
|
i_length = 256;
|
| 5900 |
|
|
else if ( ((i_length + 4) > (min_tmp + 128)) && ((i_length + 4) <= (max_tmp - 256)) )
|
| 5901 |
|
|
begin
|
| 5902 |
|
|
i_length = i_length + 128;
|
| 5903 |
|
|
tmp_data = i_length + 4; // last tmp_data is ending length
|
| 5904 |
|
|
end
|
| 5905 |
|
|
else if ( ((i_length + 4) > (max_tmp - 256)) && ((i_length + 4) < (max_tmp - 16)) )
|
| 5906 |
|
|
i_length = max_tmp - (4 + 16);
|
| 5907 |
|
|
else if ((i_length + 4) >= (max_tmp - 16))
|
| 5908 |
|
|
i_length = i_length + 1;
|
| 5909 |
|
|
else
|
| 5910 |
|
|
begin
|
| 5911 |
|
|
$display("*E TESTBENCH ERROR - WRONG PARAMETERS IN TESTBENCH");
|
| 5912 |
|
|
#10 $stop;
|
| 5913 |
|
|
end
|
| 5914 |
|
|
// the number of frame transmitted
|
| 5915 |
|
|
num_of_frames = num_of_frames + 1;
|
| 5916 |
|
|
if ((num_of_frames <= 8) || ((num_of_frames - 8) == 128))
|
| 5917 |
|
|
num_of_bd = 0;
|
| 5918 |
|
|
else
|
| 5919 |
|
|
num_of_bd = num_of_bd + 1;
|
| 5920 |
|
|
end
|
| 5921 |
|
|
// disable TX
|
| 5922 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 5923 |
209 |
tadejm |
wbm_write(`ETH_MODER, `ETH_MODER_FULLD | `ETH_MODER_PAD | `ETH_MODER_CRCEN,
|
| 5924 |
|
|
4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 5925 |
|
|
@(posedge wb_clk);
|
| 5926 |
|
|
if(fail == 0)
|
| 5927 |
|
|
test_ok;
|
| 5928 |
|
|
else
|
| 5929 |
|
|
fail = 0;
|
| 5930 |
|
|
end
|
| 5931 |
|
|
|
| 5932 |
|
|
|
| 5933 |
|
|
////////////////////////////////////////////////////////////////////
|
| 5934 |
|
|
//// ////
|
| 5935 |
|
|
//// Test transmit packets form 0 to (MINFL - 1) sizes at ////
|
| 5936 |
|
|
//// 8 TX buffer decriptors ( 10Mbps ). ////
|
| 5937 |
|
|
//// ////
|
| 5938 |
|
|
////////////////////////////////////////////////////////////////////
|
| 5939 |
|
|
if (test_num == 6) //
|
| 5940 |
|
|
begin
|
| 5941 |
|
|
// TEST 6: TRANSMIT PACKETS FROM 0 TO (MINFL - 1) SIZES AT 8 TX BD ( 10Mbps )
|
| 5942 |
|
|
test_name = "TEST 6: TRANSMIT PACKETS FROM 0 TO (MINFL - 1) SIZES AT 8 TX BD ( 10Mbps )";
|
| 5943 |
|
|
`TIME; $display(" TEST 6: TRANSMIT PACKETS FROM 0 TO (MINFL - 1) SIZES AT 8 TX BD ( 10Mbps )");
|
| 5944 |
|
|
|
| 5945 |
|
|
// reset MAC registers
|
| 5946 |
|
|
hard_reset;
|
| 5947 |
|
|
// reset MAC and MII LOGIC with soft reset
|
| 5948 |
274 |
tadejm |
// reset_mac;
|
| 5949 |
|
|
// reset_mii;
|
| 5950 |
209 |
tadejm |
// set wb slave response
|
| 5951 |
|
|
wb_slave.cycle_response(`ACK_RESPONSE, wbs_waits, wbs_retries);
|
| 5952 |
|
|
|
| 5953 |
|
|
max_tmp = 0;
|
| 5954 |
|
|
min_tmp = 0;
|
| 5955 |
|
|
// set 8 TX buffer descriptors - must be set before TX enable
|
| 5956 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 5957 |
209 |
tadejm |
wbm_write(`ETH_TX_BD_NUM, 32'h8, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 5958 |
|
|
// enable TX, set full-duplex mode, padding and CRC appending
|
| 5959 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 5960 |
209 |
tadejm |
wbm_write(`ETH_MODER, `ETH_MODER_TXEN | `ETH_MODER_PAD | `ETH_MODER_FULLD | `ETH_MODER_CRCEN,
|
| 5961 |
|
|
4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 5962 |
|
|
// prepare two packets of MAXFL length
|
| 5963 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 5964 |
209 |
tadejm |
wbm_read(`ETH_PACKETLEN, tmp, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 5965 |
|
|
max_tmp = tmp[15:0]; // 18 bytes consists of 6B dest addr, 6B source addr, 2B type/len, 4B CRC
|
| 5966 |
|
|
min_tmp = tmp[31:16];
|
| 5967 |
|
|
st_data = 8'h12;
|
| 5968 |
|
|
set_tx_packet(`MEMORY_BASE, (max_tmp - 4), st_data); // length without CRC
|
| 5969 |
|
|
st_data = 8'h34;
|
| 5970 |
|
|
set_tx_packet((`MEMORY_BASE + max_tmp), (max_tmp - 4), st_data); // length without CRC
|
| 5971 |
|
|
// check WB INT signal
|
| 5972 |
|
|
if (wb_int !== 1'b0)
|
| 5973 |
|
|
begin
|
| 5974 |
|
|
test_fail("WB INT signal should not be set");
|
| 5975 |
|
|
fail = fail + 1;
|
| 5976 |
|
|
end
|
| 5977 |
|
|
|
| 5978 |
|
|
// write to phy's control register for 10Mbps
|
| 5979 |
|
|
#Tp eth_phy.control_bit14_10 = 5'b00000; // bit 13 reset - speed 10
|
| 5980 |
|
|
#Tp eth_phy.control_bit8_0 = 9'h1_00; // bit 6 reset - (10/100), bit 8 set - FD
|
| 5981 |
|
|
speed = 10;
|
| 5982 |
|
|
|
| 5983 |
|
|
frame_started = 0;
|
| 5984 |
|
|
num_of_frames = 0;
|
| 5985 |
|
|
num_of_bd = 0;
|
| 5986 |
|
|
i_length = 0; // 0;
|
| 5987 |
|
|
while (i_length < 70) // (min_tmp - 4))
|
| 5988 |
|
|
begin
|
| 5989 |
|
|
#1;
|
| 5990 |
|
|
// choose generating carrier sense and collision
|
| 5991 |
|
|
case (i_length[1:0])
|
| 5992 |
|
|
2'h0: // Interrupt is generated
|
| 5993 |
|
|
begin
|
| 5994 |
|
|
// Reset_tx_bd nable interrupt generation
|
| 5995 |
|
|
// unmask interrupts
|
| 5996 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 5997 |
209 |
tadejm |
wbm_write(`ETH_INT_MASK, `ETH_INT_TXB | `ETH_INT_TXE | `ETH_INT_RXB | `ETH_INT_RXE | `ETH_INT_BUSY |
|
| 5998 |
|
|
`ETH_INT_TXC | `ETH_INT_RXC, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 5999 |
|
|
// not detect carrier sense in FD and no collision
|
| 6000 |
|
|
eth_phy.carrier_sense_tx_fd_detect(0);
|
| 6001 |
|
|
eth_phy.collision(0);
|
| 6002 |
|
|
end
|
| 6003 |
|
|
2'h1: // Interrupt is not generated
|
| 6004 |
|
|
begin
|
| 6005 |
|
|
// set_tx_bd enable interrupt generation
|
| 6006 |
|
|
// mask interrupts
|
| 6007 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 6008 |
209 |
tadejm |
wbm_write(`ETH_INT_MASK, 32'h0, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 6009 |
|
|
// detect carrier sense in FD and no collision
|
| 6010 |
|
|
eth_phy.carrier_sense_tx_fd_detect(1);
|
| 6011 |
|
|
eth_phy.collision(0);
|
| 6012 |
|
|
end
|
| 6013 |
|
|
2'h2: // Interrupt is not generated
|
| 6014 |
|
|
begin
|
| 6015 |
|
|
// set_tx_bd disable the interrupt generation
|
| 6016 |
|
|
// unmask interrupts
|
| 6017 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 6018 |
209 |
tadejm |
wbm_write(`ETH_INT_MASK, `ETH_INT_TXB | `ETH_INT_TXE | `ETH_INT_RXB | `ETH_INT_RXE | `ETH_INT_BUSY |
|
| 6019 |
|
|
`ETH_INT_TXC | `ETH_INT_RXC, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 6020 |
|
|
// not detect carrier sense in FD and set collision
|
| 6021 |
|
|
eth_phy.carrier_sense_tx_fd_detect(0);
|
| 6022 |
|
|
eth_phy.collision(1);
|
| 6023 |
|
|
end
|
| 6024 |
|
|
default: // 2'h3: // Interrupt is not generated
|
| 6025 |
|
|
begin
|
| 6026 |
|
|
// set_tx_bd disable the interrupt generation
|
| 6027 |
|
|
// mask interrupts
|
| 6028 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 6029 |
209 |
tadejm |
wbm_write(`ETH_INT_MASK, 32'h0, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 6030 |
|
|
// detect carrier sense in FD and set collision
|
| 6031 |
|
|
eth_phy.carrier_sense_tx_fd_detect(1);
|
| 6032 |
|
|
eth_phy.collision(1);
|
| 6033 |
|
|
end
|
| 6034 |
|
|
endcase
|
| 6035 |
|
|
#1;
|
| 6036 |
|
|
// first destination address on ethernet PHY
|
| 6037 |
|
|
eth_phy.set_tx_mem_addr(num_of_frames * 16);
|
| 6038 |
|
|
// SET packets and wrap bit
|
| 6039 |
|
|
// num_of_frames <= 9 => wrap set to TX BD 0
|
| 6040 |
|
|
if (num_of_frames <= 9)
|
| 6041 |
|
|
begin
|
| 6042 |
|
|
tmp_len = i_length; // length of frame
|
| 6043 |
|
|
tmp_bd_num = 0; // TX BD number
|
| 6044 |
|
|
// if i_length[1] == 0 then enable interrupt generation otherwise disable it
|
| 6045 |
|
|
// if i_length[0] == 0 then base address is `MEMORY_BASE otherwise it is `MEMORY_BASE + max_tmp
|
| 6046 |
|
|
if (tmp_len[0] == 0)
|
| 6047 |
|
|
set_tx_bd(tmp_bd_num, tmp_bd_num, tmp_len, !tmp_len[1], 1'b1, 1'b1, `MEMORY_BASE);
|
| 6048 |
|
|
else
|
| 6049 |
|
|
set_tx_bd(tmp_bd_num, tmp_bd_num, tmp_len, !tmp_len[1], 1'b1, 1'b1, (`MEMORY_BASE + max_tmp));
|
| 6050 |
|
|
// set wrap bit
|
| 6051 |
|
|
set_tx_bd_wrap(0);
|
| 6052 |
|
|
end
|
| 6053 |
|
|
// 10 <= num_of_frames < 18 => wrap set to TX BD 3
|
| 6054 |
|
|
else if ((num_of_frames == 10) || (num_of_frames == 14))
|
| 6055 |
|
|
begin
|
| 6056 |
|
|
tmp_len = i_length; // length of frame
|
| 6057 |
|
|
tmp_bd_num = 0; // TX BD number
|
| 6058 |
|
|
while (tmp_bd_num < 4) //
|
| 6059 |
|
|
begin
|
| 6060 |
|
|
// if i_length[1] == 0 then enable interrupt generation otherwise disable it
|
| 6061 |
|
|
// if i_length[0] == 0 then base address is `MEMORY_BASE otherwise it is `MEMORY_BASE + max_tmp
|
| 6062 |
|
|
if (tmp_len[0] == 0)
|
| 6063 |
|
|
set_tx_bd(tmp_bd_num, tmp_bd_num, tmp_len, !tmp_len[1], 1'b1, 1'b1, `MEMORY_BASE);
|
| 6064 |
|
|
else
|
| 6065 |
|
|
set_tx_bd(tmp_bd_num, tmp_bd_num, tmp_len, !tmp_len[1], 1'b1, 1'b1, (`MEMORY_BASE + max_tmp));
|
| 6066 |
|
|
tmp_len = tmp_len + 1;
|
| 6067 |
|
|
// set TX BD number
|
| 6068 |
|
|
tmp_bd_num = tmp_bd_num + 1;
|
| 6069 |
|
|
end
|
| 6070 |
|
|
// set wrap bit
|
| 6071 |
|
|
set_tx_bd_wrap(3);
|
| 6072 |
|
|
end
|
| 6073 |
|
|
// 18 <= num_of_frames < 28 => wrap set to TX BD 4
|
| 6074 |
|
|
else if ((num_of_frames == 18) || (num_of_frames == 23))
|
| 6075 |
|
|
begin
|
| 6076 |
|
|
tmp_len = i_length; // length of frame
|
| 6077 |
|
|
tmp_bd_num = 0; // TX BD number
|
| 6078 |
|
|
while (tmp_bd_num < 5) //
|
| 6079 |
|
|
begin
|
| 6080 |
|
|
// if i_length[1] == 0 then enable interrupt generation otherwise disable it
|
| 6081 |
|
|
// if i_length[0] == 0 then base address is `MEMORY_BASE otherwise it is `MEMORY_BASE + max_tmp
|
| 6082 |
|
|
if (tmp_len[0] == 0)
|
| 6083 |
|
|
set_tx_bd(tmp_bd_num, tmp_bd_num, tmp_len, !tmp_len[1], 1'b1, 1'b1, `MEMORY_BASE);
|
| 6084 |
|
|
else
|
| 6085 |
|
|
set_tx_bd(tmp_bd_num, tmp_bd_num, tmp_len, !tmp_len[1], 1'b1, 1'b1, (`MEMORY_BASE + max_tmp));
|
| 6086 |
|
|
tmp_len = tmp_len + 1;
|
| 6087 |
|
|
// set TX BD number
|
| 6088 |
|
|
tmp_bd_num = tmp_bd_num + 1;
|
| 6089 |
|
|
end
|
| 6090 |
|
|
// set wrap bit
|
| 6091 |
|
|
set_tx_bd_wrap(4);
|
| 6092 |
|
|
end
|
| 6093 |
|
|
// 28 <= num_of_frames < 40 => wrap set to TX BD 5
|
| 6094 |
|
|
else if ((num_of_frames == 28) || (num_of_frames == 34))
|
| 6095 |
|
|
begin
|
| 6096 |
|
|
tmp_len = i_length; // length of frame
|
| 6097 |
|
|
tmp_bd_num = 0; // TX BD number
|
| 6098 |
|
|
while (tmp_bd_num < 6) //
|
| 6099 |
|
|
begin
|
| 6100 |
|
|
// if i_length[1] == 0 then enable interrupt generation otherwise disable it
|
| 6101 |
|
|
// if i_length[0] == 0 then base address is `MEMORY_BASE otherwise it is `MEMORY_BASE + max_tmp
|
| 6102 |
|
|
if (tmp_len[0] == 0)
|
| 6103 |
|
|
set_tx_bd(tmp_bd_num, tmp_bd_num, tmp_len, !tmp_len[1], 1'b1, 1'b1, `MEMORY_BASE);
|
| 6104 |
|
|
else
|
| 6105 |
|
|
set_tx_bd(tmp_bd_num, tmp_bd_num, tmp_len, !tmp_len[1], 1'b1, 1'b1, (`MEMORY_BASE + max_tmp));
|
| 6106 |
|
|
tmp_len = tmp_len + 1;
|
| 6107 |
|
|
// set TX BD number
|
| 6108 |
|
|
tmp_bd_num = tmp_bd_num + 1;
|
| 6109 |
|
|
end
|
| 6110 |
|
|
// set wrap bit
|
| 6111 |
|
|
set_tx_bd_wrap(5);
|
| 6112 |
|
|
end
|
| 6113 |
|
|
// 40 <= num_of_frames < 54 => wrap set to TX BD 6
|
| 6114 |
|
|
else if ((num_of_frames == 40) || (num_of_frames == 47))
|
| 6115 |
|
|
begin
|
| 6116 |
|
|
tmp_len = i_length; // length of frame
|
| 6117 |
|
|
tmp_bd_num = 0; // TX BD number
|
| 6118 |
|
|
while (tmp_bd_num < 7) //
|
| 6119 |
|
|
begin
|
| 6120 |
|
|
// if i_length[1] == 0 then enable interrupt generation otherwise disable it
|
| 6121 |
|
|
// if i_length[0] == 0 then base address is `MEMORY_BASE otherwise it is `MEMORY_BASE + max_tmp
|
| 6122 |
|
|
if (tmp_len[0] == 0)
|
| 6123 |
|
|
set_tx_bd(tmp_bd_num, tmp_bd_num, tmp_len, !tmp_len[1], 1'b1, 1'b1, `MEMORY_BASE);
|
| 6124 |
|
|
else
|
| 6125 |
|
|
set_tx_bd(tmp_bd_num, tmp_bd_num, tmp_len, !tmp_len[1], 1'b1, 1'b1, (`MEMORY_BASE + max_tmp));
|
| 6126 |
|
|
tmp_len = tmp_len + 1;
|
| 6127 |
|
|
// set TX BD number
|
| 6128 |
|
|
tmp_bd_num = tmp_bd_num + 1;
|
| 6129 |
|
|
end
|
| 6130 |
|
|
// set wrap bit
|
| 6131 |
|
|
set_tx_bd_wrap(6);
|
| 6132 |
|
|
end
|
| 6133 |
|
|
// 54 <= num_of_frames < 70 => wrap set to TX BD 7
|
| 6134 |
|
|
else if ((num_of_frames == 54) || (num_of_frames == 62))
|
| 6135 |
|
|
begin
|
| 6136 |
|
|
tmp_len = i_length; // length of frame
|
| 6137 |
|
|
tmp_bd_num = 0; // TX BD number
|
| 6138 |
|
|
while (tmp_bd_num < 8) //
|
| 6139 |
|
|
begin
|
| 6140 |
|
|
// if i_length[1] == 0 then enable interrupt generation otherwise disable it
|
| 6141 |
|
|
// if i_length[0] == 0 then base address is `MEMORY_BASE otherwise it is `MEMORY_BASE + max_tmp
|
| 6142 |
|
|
if (tmp_len[0] == 0)
|
| 6143 |
|
|
set_tx_bd(tmp_bd_num, tmp_bd_num, tmp_len, !tmp_len[1], 1'b1, 1'b1, `MEMORY_BASE);
|
| 6144 |
|
|
else
|
| 6145 |
|
|
set_tx_bd(tmp_bd_num, tmp_bd_num, tmp_len, !tmp_len[1], 1'b1, 1'b1, (`MEMORY_BASE + max_tmp));
|
| 6146 |
|
|
tmp_len = tmp_len + 1;
|
| 6147 |
|
|
// set TX BD number
|
| 6148 |
|
|
tmp_bd_num = tmp_bd_num + 1;
|
| 6149 |
|
|
end
|
| 6150 |
|
|
// set wrap bit
|
| 6151 |
|
|
set_tx_bd_wrap(7);
|
| 6152 |
|
|
end
|
| 6153 |
|
|
#1;
|
| 6154 |
|
|
// SET ready bit
|
| 6155 |
|
|
if (num_of_frames < 10)
|
| 6156 |
|
|
set_tx_bd_ready(0, 0);
|
| 6157 |
|
|
else if (num_of_frames < 14)
|
| 6158 |
|
|
set_tx_bd_ready((num_of_frames - 10), (num_of_frames - 10));
|
| 6159 |
|
|
else if (num_of_frames < 18)
|
| 6160 |
|
|
set_tx_bd_ready((num_of_frames - 14), (num_of_frames - 14));
|
| 6161 |
|
|
else if (num_of_frames < 23)
|
| 6162 |
|
|
set_tx_bd_ready((num_of_frames - 18), (num_of_frames - 18));
|
| 6163 |
|
|
else if (num_of_frames < 28)
|
| 6164 |
|
|
set_tx_bd_ready((num_of_frames - 23), (num_of_frames - 23));
|
| 6165 |
|
|
else if (num_of_frames < 34)
|
| 6166 |
|
|
set_tx_bd_ready((num_of_frames - 28), (num_of_frames - 28));
|
| 6167 |
|
|
else if (num_of_frames < 40)
|
| 6168 |
|
|
set_tx_bd_ready((num_of_frames - 34), (num_of_frames - 34));
|
| 6169 |
|
|
else if (num_of_frames < 47)
|
| 6170 |
|
|
set_tx_bd_ready((num_of_frames - 40), (num_of_frames - 40));
|
| 6171 |
|
|
else if (num_of_frames < 54)
|
| 6172 |
|
|
set_tx_bd_ready((num_of_frames - 47), (num_of_frames - 47));
|
| 6173 |
|
|
else if (num_of_frames < 62)
|
| 6174 |
|
|
set_tx_bd_ready((num_of_frames - 54), (num_of_frames - 54));
|
| 6175 |
|
|
else if (num_of_frames < 70)
|
| 6176 |
|
|
set_tx_bd_ready((num_of_frames - 62), (num_of_frames - 62));
|
| 6177 |
|
|
// CHECK END OF TRANSMITION
|
| 6178 |
|
|
frame_started = 0;
|
| 6179 |
|
|
if (num_of_frames >= 5)
|
| 6180 |
|
|
#1 check_tx_bd(num_of_bd, data);
|
| 6181 |
|
|
fork
|
| 6182 |
|
|
begin: fr_st
|
| 6183 |
|
|
wait (MTxEn === 1'b1); // start transmit
|
| 6184 |
|
|
frame_started = 1;
|
| 6185 |
|
|
end
|
| 6186 |
|
|
begin
|
| 6187 |
|
|
repeat (30) @(posedge mtx_clk);
|
| 6188 |
|
|
if (num_of_frames < 5)
|
| 6189 |
|
|
begin
|
| 6190 |
|
|
if (frame_started == 1)
|
| 6191 |
|
|
begin
|
| 6192 |
|
|
`TIME; $display("*E Frame should NOT start!");
|
| 6193 |
|
|
end
|
| 6194 |
|
|
disable fr_st;
|
| 6195 |
|
|
end
|
| 6196 |
|
|
else
|
| 6197 |
|
|
begin
|
| 6198 |
|
|
if (frame_started == 0)
|
| 6199 |
|
|
begin
|
| 6200 |
|
|
`TIME; $display("*W Frame should start!");
|
| 6201 |
|
|
disable fr_st;
|
| 6202 |
|
|
end
|
| 6203 |
|
|
end
|
| 6204 |
|
|
end
|
| 6205 |
|
|
join
|
| 6206 |
|
|
// check packets larger than 4 bytes
|
| 6207 |
|
|
if (num_of_frames >= 5)
|
| 6208 |
|
|
begin
|
| 6209 |
|
|
wait (MTxEn === 1'b0); // end transmit
|
| 6210 |
|
|
while (data[15] === 1)
|
| 6211 |
|
|
begin
|
| 6212 |
|
|
#1 check_tx_bd(num_of_bd, data);
|
| 6213 |
|
|
@(posedge wb_clk);
|
| 6214 |
|
|
end
|
| 6215 |
|
|
repeat (1) @(posedge wb_clk);
|
| 6216 |
|
|
// check length of a PACKET
|
| 6217 |
|
|
if (i_length <= (min_tmp - 4))
|
| 6218 |
|
|
begin
|
| 6219 |
|
|
if (eth_phy.tx_len != min_tmp)
|
| 6220 |
|
|
begin
|
| 6221 |
|
|
test_fail("Wrong length of the packet out from MAC");
|
| 6222 |
|
|
fail = fail + 1;
|
| 6223 |
|
|
end
|
| 6224 |
|
|
end
|
| 6225 |
|
|
else
|
| 6226 |
|
|
begin
|
| 6227 |
|
|
if (eth_phy.tx_len != (i_length + 4))
|
| 6228 |
|
|
begin
|
| 6229 |
|
|
test_fail("Wrong length of the packet out from MAC");
|
| 6230 |
|
|
fail = fail + 1;
|
| 6231 |
|
|
end
|
| 6232 |
|
|
end
|
| 6233 |
|
|
// check transmitted TX packet data
|
| 6234 |
|
|
if (i_length[0] == 0)
|
| 6235 |
|
|
begin
|
| 6236 |
|
|
#1 check_tx_packet(`MEMORY_BASE, (num_of_frames * 16), i_length, tmp);
|
| 6237 |
|
|
end
|
| 6238 |
|
|
else
|
| 6239 |
|
|
begin
|
| 6240 |
|
|
#1 check_tx_packet((`MEMORY_BASE + max_tmp), (num_of_frames * 16), i_length, tmp);
|
| 6241 |
|
|
end
|
| 6242 |
|
|
if (tmp > 0)
|
| 6243 |
|
|
begin
|
| 6244 |
|
|
test_fail("Wrong data of the transmitted packet");
|
| 6245 |
|
|
fail = fail + 1;
|
| 6246 |
|
|
end
|
| 6247 |
|
|
// check transmited TX packet CRC
|
| 6248 |
|
|
if (num_of_frames < (min_tmp - 4))
|
| 6249 |
|
|
#1 check_tx_crc((num_of_frames * 16), (min_tmp - 4), 1'b0, tmp); // length without CRC
|
| 6250 |
|
|
else
|
| 6251 |
|
|
#1 check_tx_crc((num_of_frames * 16), i_length, 1'b0, tmp); // length without CRC
|
| 6252 |
|
|
if (tmp > 0)
|
| 6253 |
|
|
begin
|
| 6254 |
|
|
test_fail("Wrong CRC of the transmitted packet");
|
| 6255 |
|
|
fail = fail + 1;
|
| 6256 |
|
|
end
|
| 6257 |
|
|
end
|
| 6258 |
|
|
// check WB INT signal
|
| 6259 |
|
|
if ((i_length[1:0] == 2'h0) && (num_of_frames >= 5))
|
| 6260 |
|
|
begin
|
| 6261 |
|
|
if (wb_int !== 1'b1)
|
| 6262 |
|
|
begin
|
| 6263 |
|
|
`TIME; $display("*E WB INT signal should be set");
|
| 6264 |
|
|
test_fail("WB INT signal should be set");
|
| 6265 |
|
|
fail = fail + 1;
|
| 6266 |
|
|
end
|
| 6267 |
|
|
end
|
| 6268 |
|
|
else
|
| 6269 |
|
|
begin
|
| 6270 |
|
|
if (wb_int !== 1'b0)
|
| 6271 |
|
|
begin
|
| 6272 |
|
|
`TIME; $display("*E WB INT signal should not be set");
|
| 6273 |
|
|
test_fail("WB INT signal should not be set");
|
| 6274 |
|
|
fail = fail + 1;
|
| 6275 |
|
|
end
|
| 6276 |
|
|
end
|
| 6277 |
|
|
// check TX buffer descriptor of a packet
|
| 6278 |
|
|
check_tx_bd(num_of_bd, data);
|
| 6279 |
|
|
if (num_of_frames >= 5)
|
| 6280 |
|
|
begin
|
| 6281 |
|
|
if (i_length[1] == 1'b0) // interrupt enabled
|
| 6282 |
|
|
begin
|
| 6283 |
|
|
if ( (data[15:0] !== 16'h7800) && // wrap bit
|
| 6284 |
|
|
(data[15:0] !== 16'h5800) ) // without wrap bit
|
| 6285 |
|
|
begin
|
| 6286 |
|
|
`TIME; $display("*E TX buffer descriptor status is not correct: %0h", data[15:0]);
|
| 6287 |
|
|
test_fail("TX buffer descriptor status is not correct");
|
| 6288 |
|
|
fail = fail + 1;
|
| 6289 |
|
|
end
|
| 6290 |
|
|
end
|
| 6291 |
|
|
else // interrupt not enabled
|
| 6292 |
|
|
begin
|
| 6293 |
|
|
if ( (data[15:0] !== 16'h3800) && // wrap bit
|
| 6294 |
|
|
(data[15:0] !== 16'h1800) ) // without wrap bit
|
| 6295 |
|
|
begin
|
| 6296 |
|
|
`TIME; $display("*E TX buffer descriptor status is not correct: %0h", data[15:0]);
|
| 6297 |
|
|
test_fail("TX buffer descriptor status is not correct");
|
| 6298 |
|
|
fail = fail + 1;
|
| 6299 |
|
|
end
|
| 6300 |
|
|
end
|
| 6301 |
|
|
end
|
| 6302 |
|
|
else
|
| 6303 |
|
|
begin
|
| 6304 |
|
|
if (data[15] !== 1'b1)
|
| 6305 |
|
|
begin
|
| 6306 |
|
|
`TIME; $display("*E TX buffer descriptor status is not correct: %0h", data[15:0]);
|
| 6307 |
|
|
test_fail("TX buffer descriptor status is not correct");
|
| 6308 |
|
|
fail = fail + 1;
|
| 6309 |
|
|
end
|
| 6310 |
|
|
end
|
| 6311 |
|
|
// clear TX BD with wrap bit
|
| 6312 |
|
|
if (num_of_frames == 63)
|
| 6313 |
|
|
clear_tx_bd(16, 16);
|
| 6314 |
|
|
// check interrupts
|
| 6315 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 6316 |
209 |
tadejm |
wbm_read(`ETH_INT, data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 6317 |
|
|
if ( ((i_length[1:0] == 2'h0) || (i_length[1:0] == 2'h1)) && (num_of_frames >= 5) )
|
| 6318 |
|
|
begin
|
| 6319 |
|
|
if ((data & `ETH_INT_TXB) !== 1'b1)
|
| 6320 |
|
|
begin
|
| 6321 |
|
|
`TIME; $display("*E Interrupt Transmit Buffer was not set, interrupt reg: %0h", data);
|
| 6322 |
|
|
test_fail("Interrupt Transmit Buffer was not set");
|
| 6323 |
|
|
fail = fail + 1;
|
| 6324 |
|
|
end
|
| 6325 |
|
|
if ((data & (~`ETH_INT_TXB)) !== 0)
|
| 6326 |
|
|
begin
|
| 6327 |
|
|
`TIME; $display("*E Other interrupts (except Transmit Buffer) were set, interrupt reg: %0h", data);
|
| 6328 |
|
|
test_fail("Other interrupts (except Transmit Buffer) were set");
|
| 6329 |
|
|
fail = fail + 1;
|
| 6330 |
|
|
end
|
| 6331 |
|
|
end
|
| 6332 |
|
|
else
|
| 6333 |
|
|
begin
|
| 6334 |
|
|
if (data !== 0)
|
| 6335 |
|
|
begin
|
| 6336 |
|
|
`TIME; $display("*E Any of interrupts (except Transmit Buffer) was set, interrupt reg: %0h, len: %0h", data, i_length[1:0]);
|
| 6337 |
|
|
test_fail("Any of interrupts (except Transmit Buffer) was set");
|
| 6338 |
|
|
fail = fail + 1;
|
| 6339 |
|
|
end
|
| 6340 |
|
|
end
|
| 6341 |
|
|
// clear interrupts
|
| 6342 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 6343 |
209 |
tadejm |
wbm_write(`ETH_INT, data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 6344 |
|
|
// check WB INT signal
|
| 6345 |
|
|
if (wb_int !== 1'b0)
|
| 6346 |
|
|
begin
|
| 6347 |
|
|
test_fail("WB INT signal should not be set");
|
| 6348 |
|
|
fail = fail + 1;
|
| 6349 |
|
|
end
|
| 6350 |
|
|
// INTERMEDIATE DISPLAYS
|
| 6351 |
|
|
if (i_length == 3)
|
| 6352 |
|
|
begin
|
| 6353 |
|
|
$display(" pads appending to packets is selected");
|
| 6354 |
|
|
$display(" using 1 BD out of 8 BDs assigned to TX (wrap at 1st BD - TX BD 0)");
|
| 6355 |
|
|
$display(" ->packets with lengths from %0d to %0d are not transmitted (length increasing by 1 byte)",
|
| 6356 |
|
|
0, 3);
|
| 6357 |
|
|
end
|
| 6358 |
|
|
else if (i_length == 9)
|
| 6359 |
|
|
begin
|
| 6360 |
|
|
$display(" using 1 BD out of 8 BDs assigned to TX (wrap at 1st BD - TX BD 0)");
|
| 6361 |
|
|
$display(" ->packet with length 4 is not transmitted (length increasing by 1 byte)");
|
| 6362 |
|
|
$display(" ->packets with lengths from %0d to %0d are checked (length increasing by 1 byte)",
|
| 6363 |
|
|
5, 9);
|
| 6364 |
|
|
end
|
| 6365 |
|
|
else if (i_length == 17)
|
| 6366 |
|
|
begin
|
| 6367 |
|
|
$display(" using 4 BDs out of 8 BDs assigned to TX (wrap at 4th BD - TX BD 3)");
|
| 6368 |
|
|
$display(" ->packets with lengths from %0d to %0d are checked (length increasing by 1 byte)",
|
| 6369 |
|
|
10, 17);
|
| 6370 |
|
|
end
|
| 6371 |
|
|
else if (i_length == 27)
|
| 6372 |
|
|
begin
|
| 6373 |
|
|
$display(" using 5 BDs out of 8 BDs assigned to TX (wrap at 5th BD - TX BD 4)");
|
| 6374 |
|
|
$display(" ->packets with lengths from %0d to %0d are checked (length increasing by 1 byte)",
|
| 6375 |
|
|
18, 27);
|
| 6376 |
|
|
end
|
| 6377 |
|
|
else if (i_length == 40)
|
| 6378 |
|
|
begin
|
| 6379 |
|
|
$display(" using 6 BDs out of 8 BDs assigned to TX (wrap at 6th BD - TX BD 5)");
|
| 6380 |
|
|
$display(" ->packets with lengths from %0d to %0d are checked (length increasing by 1 byte)",
|
| 6381 |
|
|
28, 40);
|
| 6382 |
|
|
end
|
| 6383 |
|
|
else if (i_length == 54)
|
| 6384 |
|
|
begin
|
| 6385 |
|
|
$display(" using 7 BDs out of 8 BDs assigned to TX (wrap at 7th BD - TX BD 6)");
|
| 6386 |
|
|
$display(" ->packets with lengths from %0d to %0d are checked (length increasing by 1 byte)",
|
| 6387 |
|
|
41, 54);
|
| 6388 |
|
|
end
|
| 6389 |
|
|
else if (i_length == 69)
|
| 6390 |
|
|
begin
|
| 6391 |
|
|
$display(" using 8 BDs out of 8 BDs assigned to TX (wrap at 8th BD - TX BD 7)");
|
| 6392 |
|
|
$display(" ->packets with lengths from %0d to %0d are checked (length increasing by 1 byte)",
|
| 6393 |
|
|
55, 69);
|
| 6394 |
|
|
end
|
| 6395 |
|
|
// set length (loop variable)
|
| 6396 |
|
|
i_length = i_length + 1;
|
| 6397 |
|
|
// the number of frame transmitted
|
| 6398 |
|
|
num_of_frames = num_of_frames + 1;
|
| 6399 |
|
|
if (/*(num_of_frames == 2) || (num_of_frames == 4) || (num_of_frames == 7) ||*/ (num_of_frames <= 10) ||
|
| 6400 |
|
|
(num_of_frames == 14) || (num_of_frames == 18) || (num_of_frames == 23) || (num_of_frames == 28) ||
|
| 6401 |
|
|
(num_of_frames == 34) || (num_of_frames == 40) || (num_of_frames == 47) ||
|
| 6402 |
|
|
(num_of_frames == 54) || (num_of_frames == 62))
|
| 6403 |
|
|
num_of_bd = 0;
|
| 6404 |
|
|
else
|
| 6405 |
|
|
num_of_bd = num_of_bd + 1;
|
| 6406 |
|
|
end
|
| 6407 |
|
|
// disable TX
|
| 6408 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 6409 |
209 |
tadejm |
wbm_write(`ETH_MODER, `ETH_MODER_FULLD | `ETH_MODER_PAD | `ETH_MODER_CRCEN,
|
| 6410 |
|
|
4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 6411 |
|
|
@(posedge wb_clk);
|
| 6412 |
|
|
if(fail == 0)
|
| 6413 |
|
|
test_ok;
|
| 6414 |
|
|
else
|
| 6415 |
|
|
fail = 0;
|
| 6416 |
|
|
end
|
| 6417 |
|
|
|
| 6418 |
|
|
|
| 6419 |
|
|
////////////////////////////////////////////////////////////////////
|
| 6420 |
|
|
//// ////
|
| 6421 |
|
|
//// Test transmit packets form 0 to (MINFL - 1) sizes at ////
|
| 6422 |
|
|
//// 8 TX buffer decriptors ( 100Mbps ). ////
|
| 6423 |
|
|
//// ////
|
| 6424 |
|
|
////////////////////////////////////////////////////////////////////
|
| 6425 |
|
|
if (test_num == 7) //
|
| 6426 |
|
|
begin
|
| 6427 |
|
|
// TEST 7: TRANSMIT PACKETS FROM 0 TO (MINFL - 1) SIZES AT 8 TX BD ( 100Mbps )
|
| 6428 |
|
|
test_name = "TEST 7: TRANSMIT PACKETS FROM 0 TO (MINFL - 1) SIZES AT 8 TX BD ( 100Mbps )";
|
| 6429 |
|
|
`TIME; $display(" TEST 7: TRANSMIT PACKETS FROM 0 TO (MINFL - 1) SIZES AT 8 TX BD ( 100Mbps )");
|
| 6430 |
|
|
|
| 6431 |
|
|
// reset MAC registers
|
| 6432 |
|
|
hard_reset;
|
| 6433 |
|
|
// reset MAC and MII LOGIC with soft reset
|
| 6434 |
274 |
tadejm |
// reset_mac;
|
| 6435 |
|
|
// reset_mii;
|
| 6436 |
209 |
tadejm |
// set wb slave response
|
| 6437 |
|
|
wb_slave.cycle_response(`ACK_RESPONSE, wbs_waits, wbs_retries);
|
| 6438 |
|
|
|
| 6439 |
|
|
max_tmp = 0;
|
| 6440 |
|
|
min_tmp = 0;
|
| 6441 |
|
|
// set 8 TX buffer descriptors - must be set before TX enable
|
| 6442 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 6443 |
209 |
tadejm |
wbm_write(`ETH_TX_BD_NUM, 32'h8, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 6444 |
|
|
// enable TX, set full-duplex mode, padding and CRC appending
|
| 6445 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 6446 |
209 |
tadejm |
wbm_write(`ETH_MODER, `ETH_MODER_TXEN | `ETH_MODER_PAD | `ETH_MODER_FULLD | `ETH_MODER_CRCEN,
|
| 6447 |
|
|
4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 6448 |
|
|
// prepare two packets of MAXFL length
|
| 6449 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 6450 |
209 |
tadejm |
wbm_read(`ETH_PACKETLEN, tmp, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 6451 |
|
|
max_tmp = tmp[15:0]; // 18 bytes consists of 6B dest addr, 6B source addr, 2B type/len, 4B CRC
|
| 6452 |
|
|
min_tmp = tmp[31:16];
|
| 6453 |
|
|
st_data = 8'h12;
|
| 6454 |
|
|
set_tx_packet(`MEMORY_BASE, (max_tmp - 4), st_data); // length without CRC
|
| 6455 |
|
|
st_data = 8'h34;
|
| 6456 |
|
|
set_tx_packet((`MEMORY_BASE + max_tmp), (max_tmp - 4), st_data); // length without CRC
|
| 6457 |
|
|
// check WB INT signal
|
| 6458 |
|
|
if (wb_int !== 1'b0)
|
| 6459 |
|
|
begin
|
| 6460 |
|
|
test_fail("WB INT signal should not be set");
|
| 6461 |
|
|
fail = fail + 1;
|
| 6462 |
|
|
end
|
| 6463 |
|
|
|
| 6464 |
|
|
// write to phy's control register for 100Mbps
|
| 6465 |
|
|
#Tp eth_phy.control_bit14_10 = 5'b01000; // bit 13 set - speed 100
|
| 6466 |
|
|
#Tp eth_phy.control_bit8_0 = 9'h1_00; // bit 6 reset - (10/100), bit 8 set - FD
|
| 6467 |
|
|
speed = 100;
|
| 6468 |
|
|
|
| 6469 |
|
|
frame_started = 0;
|
| 6470 |
|
|
num_of_frames = 0;
|
| 6471 |
|
|
num_of_bd = 0;
|
| 6472 |
|
|
i_length = 0; // 0;
|
| 6473 |
|
|
while (i_length < 70) // (min_tmp - 4))
|
| 6474 |
|
|
begin
|
| 6475 |
|
|
#1;
|
| 6476 |
|
|
// choose generating carrier sense and collision
|
| 6477 |
|
|
case (i_length[1:0])
|
| 6478 |
|
|
2'h0: // Interrupt is generated
|
| 6479 |
|
|
begin
|
| 6480 |
|
|
// Reset_tx_bd nable interrupt generation
|
| 6481 |
|
|
// unmask interrupts
|
| 6482 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 6483 |
209 |
tadejm |
wbm_write(`ETH_INT_MASK, `ETH_INT_TXB | `ETH_INT_TXE | `ETH_INT_RXB | `ETH_INT_RXE | `ETH_INT_BUSY |
|
| 6484 |
|
|
`ETH_INT_TXC | `ETH_INT_RXC, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 6485 |
|
|
// not detect carrier sense in FD and no collision
|
| 6486 |
|
|
eth_phy.carrier_sense_tx_fd_detect(0);
|
| 6487 |
|
|
eth_phy.collision(0);
|
| 6488 |
|
|
end
|
| 6489 |
|
|
2'h1: // Interrupt is not generated
|
| 6490 |
|
|
begin
|
| 6491 |
|
|
// set_tx_bd enable interrupt generation
|
| 6492 |
|
|
// mask interrupts
|
| 6493 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 6494 |
209 |
tadejm |
wbm_write(`ETH_INT_MASK, 32'h0, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 6495 |
|
|
// detect carrier sense in FD and no collision
|
| 6496 |
|
|
eth_phy.carrier_sense_tx_fd_detect(1);
|
| 6497 |
|
|
eth_phy.collision(0);
|
| 6498 |
|
|
end
|
| 6499 |
|
|
2'h2: // Interrupt is not generated
|
| 6500 |
|
|
begin
|
| 6501 |
|
|
// set_tx_bd disable the interrupt generation
|
| 6502 |
|
|
// unmask interrupts
|
| 6503 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 6504 |
209 |
tadejm |
wbm_write(`ETH_INT_MASK, `ETH_INT_TXB | `ETH_INT_TXE | `ETH_INT_RXB | `ETH_INT_RXE | `ETH_INT_BUSY |
|
| 6505 |
|
|
`ETH_INT_TXC | `ETH_INT_RXC, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 6506 |
|
|
// not detect carrier sense in FD and set collision
|
| 6507 |
|
|
eth_phy.carrier_sense_tx_fd_detect(0);
|
| 6508 |
|
|
eth_phy.collision(1);
|
| 6509 |
|
|
end
|
| 6510 |
|
|
default: // 2'h3: // Interrupt is not generated
|
| 6511 |
|
|
begin
|
| 6512 |
|
|
// set_tx_bd disable the interrupt generation
|
| 6513 |
|
|
// mask interrupts
|
| 6514 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 6515 |
209 |
tadejm |
wbm_write(`ETH_INT_MASK, 32'h0, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 6516 |
|
|
// detect carrier sense in FD and set collision
|
| 6517 |
|
|
eth_phy.carrier_sense_tx_fd_detect(1);
|
| 6518 |
|
|
eth_phy.collision(1);
|
| 6519 |
|
|
end
|
| 6520 |
|
|
endcase
|
| 6521 |
|
|
#1;
|
| 6522 |
|
|
// first destination address on ethernet PHY
|
| 6523 |
|
|
eth_phy.set_tx_mem_addr(num_of_frames * 16);
|
| 6524 |
|
|
// SET packets and wrap bit
|
| 6525 |
|
|
// num_of_frames <= 9 => wrap set to TX BD 0
|
| 6526 |
|
|
if (num_of_frames <= 9)
|
| 6527 |
|
|
begin
|
| 6528 |
|
|
tmp_len = i_length; // length of frame
|
| 6529 |
|
|
tmp_bd_num = 0; // TX BD number
|
| 6530 |
|
|
// if i_length[1] == 0 then enable interrupt generation otherwise disable it
|
| 6531 |
|
|
// if i_length[0] == 0 then base address is `MEMORY_BASE otherwise it is `MEMORY_BASE + max_tmp
|
| 6532 |
|
|
if (tmp_len[0] == 0)
|
| 6533 |
|
|
set_tx_bd(tmp_bd_num, tmp_bd_num, tmp_len, !tmp_len[1], 1'b1, 1'b1, `MEMORY_BASE);
|
| 6534 |
|
|
else
|
| 6535 |
|
|
set_tx_bd(tmp_bd_num, tmp_bd_num, tmp_len, !tmp_len[1], 1'b1, 1'b1, (`MEMORY_BASE + max_tmp));
|
| 6536 |
|
|
// set wrap bit
|
| 6537 |
|
|
set_tx_bd_wrap(0);
|
| 6538 |
|
|
end
|
| 6539 |
|
|
// 10 <= num_of_frames < 18 => wrap set to TX BD 3
|
| 6540 |
|
|
else if ((num_of_frames == 10) || (num_of_frames == 14))
|
| 6541 |
|
|
begin
|
| 6542 |
|
|
tmp_len = i_length; // length of frame
|
| 6543 |
|
|
tmp_bd_num = 0; // TX BD number
|
| 6544 |
|
|
while (tmp_bd_num < 4) //
|
| 6545 |
|
|
begin
|
| 6546 |
|
|
// if i_length[1] == 0 then enable interrupt generation otherwise disable it
|
| 6547 |
|
|
// if i_length[0] == 0 then base address is `MEMORY_BASE otherwise it is `MEMORY_BASE + max_tmp
|
| 6548 |
|
|
if (tmp_len[0] == 0)
|
| 6549 |
|
|
set_tx_bd(tmp_bd_num, tmp_bd_num, tmp_len, !tmp_len[1], 1'b1, 1'b1, `MEMORY_BASE);
|
| 6550 |
|
|
else
|
| 6551 |
|
|
set_tx_bd(tmp_bd_num, tmp_bd_num, tmp_len, !tmp_len[1], 1'b1, 1'b1, (`MEMORY_BASE + max_tmp));
|
| 6552 |
|
|
tmp_len = tmp_len + 1;
|
| 6553 |
|
|
// set TX BD number
|
| 6554 |
|
|
tmp_bd_num = tmp_bd_num + 1;
|
| 6555 |
|
|
end
|
| 6556 |
|
|
// set wrap bit
|
| 6557 |
|
|
set_tx_bd_wrap(3);
|
| 6558 |
|
|
end
|
| 6559 |
|
|
// 18 <= num_of_frames < 28 => wrap set to TX BD 4
|
| 6560 |
|
|
else if ((num_of_frames == 18) || (num_of_frames == 23))
|
| 6561 |
|
|
begin
|
| 6562 |
|
|
tmp_len = i_length; // length of frame
|
| 6563 |
|
|
tmp_bd_num = 0; // TX BD number
|
| 6564 |
|
|
while (tmp_bd_num < 5) //
|
| 6565 |
|
|
begin
|
| 6566 |
|
|
// if i_length[1] == 0 then enable interrupt generation otherwise disable it
|
| 6567 |
|
|
// if i_length[0] == 0 then base address is `MEMORY_BASE otherwise it is `MEMORY_BASE + max_tmp
|
| 6568 |
|
|
if (tmp_len[0] == 0)
|
| 6569 |
|
|
set_tx_bd(tmp_bd_num, tmp_bd_num, tmp_len, !tmp_len[1], 1'b1, 1'b1, `MEMORY_BASE);
|
| 6570 |
|
|
else
|
| 6571 |
|
|
set_tx_bd(tmp_bd_num, tmp_bd_num, tmp_len, !tmp_len[1], 1'b1, 1'b1, (`MEMORY_BASE + max_tmp));
|
| 6572 |
|
|
tmp_len = tmp_len + 1;
|
| 6573 |
|
|
// set TX BD number
|
| 6574 |
|
|
tmp_bd_num = tmp_bd_num + 1;
|
| 6575 |
|
|
end
|
| 6576 |
|
|
// set wrap bit
|
| 6577 |
|
|
set_tx_bd_wrap(4);
|
| 6578 |
|
|
end
|
| 6579 |
|
|
// 28 <= num_of_frames < 40 => wrap set to TX BD 5
|
| 6580 |
|
|
else if ((num_of_frames == 28) || (num_of_frames == 34))
|
| 6581 |
|
|
begin
|
| 6582 |
|
|
tmp_len = i_length; // length of frame
|
| 6583 |
|
|
tmp_bd_num = 0; // TX BD number
|
| 6584 |
|
|
while (tmp_bd_num < 6) //
|
| 6585 |
|
|
begin
|
| 6586 |
|
|
// if i_length[1] == 0 then enable interrupt generation otherwise disable it
|
| 6587 |
|
|
// if i_length[0] == 0 then base address is `MEMORY_BASE otherwise it is `MEMORY_BASE + max_tmp
|
| 6588 |
|
|
if (tmp_len[0] == 0)
|
| 6589 |
|
|
set_tx_bd(tmp_bd_num, tmp_bd_num, tmp_len, !tmp_len[1], 1'b1, 1'b1, `MEMORY_BASE);
|
| 6590 |
|
|
else
|
| 6591 |
|
|
set_tx_bd(tmp_bd_num, tmp_bd_num, tmp_len, !tmp_len[1], 1'b1, 1'b1, (`MEMORY_BASE + max_tmp));
|
| 6592 |
|
|
tmp_len = tmp_len + 1;
|
| 6593 |
|
|
// set TX BD number
|
| 6594 |
|
|
tmp_bd_num = tmp_bd_num + 1;
|
| 6595 |
|
|
end
|
| 6596 |
|
|
// set wrap bit
|
| 6597 |
|
|
set_tx_bd_wrap(5);
|
| 6598 |
|
|
end
|
| 6599 |
|
|
// 40 <= num_of_frames < 54 => wrap set to TX BD 6
|
| 6600 |
|
|
else if ((num_of_frames == 40) || (num_of_frames == 47))
|
| 6601 |
|
|
begin
|
| 6602 |
|
|
tmp_len = i_length; // length of frame
|
| 6603 |
|
|
tmp_bd_num = 0; // TX BD number
|
| 6604 |
|
|
while (tmp_bd_num < 7) //
|
| 6605 |
|
|
begin
|
| 6606 |
|
|
// if i_length[1] == 0 then enable interrupt generation otherwise disable it
|
| 6607 |
|
|
// if i_length[0] == 0 then base address is `MEMORY_BASE otherwise it is `MEMORY_BASE + max_tmp
|
| 6608 |
|
|
if (tmp_len[0] == 0)
|
| 6609 |
|
|
set_tx_bd(tmp_bd_num, tmp_bd_num, tmp_len, !tmp_len[1], 1'b1, 1'b1, `MEMORY_BASE);
|
| 6610 |
|
|
else
|
| 6611 |
|
|
set_tx_bd(tmp_bd_num, tmp_bd_num, tmp_len, !tmp_len[1], 1'b1, 1'b1, (`MEMORY_BASE + max_tmp));
|
| 6612 |
|
|
tmp_len = tmp_len + 1;
|
| 6613 |
|
|
// set TX BD number
|
| 6614 |
|
|
tmp_bd_num = tmp_bd_num + 1;
|
| 6615 |
|
|
end
|
| 6616 |
|
|
// set wrap bit
|
| 6617 |
|
|
set_tx_bd_wrap(6);
|
| 6618 |
|
|
end
|
| 6619 |
|
|
// 54 <= num_of_frames < 70 => wrap set to TX BD 7
|
| 6620 |
|
|
else if ((num_of_frames == 54) || (num_of_frames == 62))
|
| 6621 |
|
|
begin
|
| 6622 |
|
|
tmp_len = i_length; // length of frame
|
| 6623 |
|
|
tmp_bd_num = 0; // TX BD number
|
| 6624 |
|
|
while (tmp_bd_num < 8) //
|
| 6625 |
|
|
begin
|
| 6626 |
|
|
// if i_length[1] == 0 then enable interrupt generation otherwise disable it
|
| 6627 |
|
|
// if i_length[0] == 0 then base address is `MEMORY_BASE otherwise it is `MEMORY_BASE + max_tmp
|
| 6628 |
|
|
if (tmp_len[0] == 0)
|
| 6629 |
|
|
set_tx_bd(tmp_bd_num, tmp_bd_num, tmp_len, !tmp_len[1], 1'b1, 1'b1, `MEMORY_BASE);
|
| 6630 |
|
|
else
|
| 6631 |
|
|
set_tx_bd(tmp_bd_num, tmp_bd_num, tmp_len, !tmp_len[1], 1'b1, 1'b1, (`MEMORY_BASE + max_tmp));
|
| 6632 |
|
|
tmp_len = tmp_len + 1;
|
| 6633 |
|
|
// set TX BD number
|
| 6634 |
|
|
tmp_bd_num = tmp_bd_num + 1;
|
| 6635 |
|
|
end
|
| 6636 |
|
|
// set wrap bit
|
| 6637 |
|
|
set_tx_bd_wrap(7);
|
| 6638 |
|
|
end
|
| 6639 |
|
|
#1;
|
| 6640 |
|
|
// SET ready bit
|
| 6641 |
|
|
if (num_of_frames < 10)
|
| 6642 |
|
|
set_tx_bd_ready(0, 0);
|
| 6643 |
|
|
else if (num_of_frames < 14)
|
| 6644 |
|
|
set_tx_bd_ready((num_of_frames - 10), (num_of_frames - 10));
|
| 6645 |
|
|
else if (num_of_frames < 18)
|
| 6646 |
|
|
set_tx_bd_ready((num_of_frames - 14), (num_of_frames - 14));
|
| 6647 |
|
|
else if (num_of_frames < 23)
|
| 6648 |
|
|
set_tx_bd_ready((num_of_frames - 18), (num_of_frames - 18));
|
| 6649 |
|
|
else if (num_of_frames < 28)
|
| 6650 |
|
|
set_tx_bd_ready((num_of_frames - 23), (num_of_frames - 23));
|
| 6651 |
|
|
else if (num_of_frames < 34)
|
| 6652 |
|
|
set_tx_bd_ready((num_of_frames - 28), (num_of_frames - 28));
|
| 6653 |
|
|
else if (num_of_frames < 40)
|
| 6654 |
|
|
set_tx_bd_ready((num_of_frames - 34), (num_of_frames - 34));
|
| 6655 |
|
|
else if (num_of_frames < 47)
|
| 6656 |
|
|
set_tx_bd_ready((num_of_frames - 40), (num_of_frames - 40));
|
| 6657 |
|
|
else if (num_of_frames < 54)
|
| 6658 |
|
|
set_tx_bd_ready((num_of_frames - 47), (num_of_frames - 47));
|
| 6659 |
|
|
else if (num_of_frames < 62)
|
| 6660 |
|
|
set_tx_bd_ready((num_of_frames - 54), (num_of_frames - 54));
|
| 6661 |
|
|
else if (num_of_frames < 70)
|
| 6662 |
|
|
set_tx_bd_ready((num_of_frames - 62), (num_of_frames - 62));
|
| 6663 |
|
|
// CHECK END OF TRANSMITION
|
| 6664 |
|
|
frame_started = 0;
|
| 6665 |
|
|
if (num_of_frames >= 5)
|
| 6666 |
|
|
#1 check_tx_bd(num_of_bd, data);
|
| 6667 |
|
|
fork
|
| 6668 |
|
|
begin: fr_st1
|
| 6669 |
|
|
wait (MTxEn === 1'b1); // start transmit
|
| 6670 |
|
|
frame_started = 1;
|
| 6671 |
|
|
end
|
| 6672 |
|
|
begin
|
| 6673 |
274 |
tadejm |
repeat (50) @(posedge mtx_clk); // Increased from 30 to 50 igor
|
| 6674 |
209 |
tadejm |
if (num_of_frames < 5)
|
| 6675 |
|
|
begin
|
| 6676 |
|
|
if (frame_started == 1)
|
| 6677 |
|
|
begin
|
| 6678 |
|
|
`TIME; $display("*E Frame should NOT start!");
|
| 6679 |
|
|
end
|
| 6680 |
|
|
disable fr_st1;
|
| 6681 |
|
|
end
|
| 6682 |
|
|
else
|
| 6683 |
|
|
begin
|
| 6684 |
|
|
if (frame_started == 0)
|
| 6685 |
|
|
begin
|
| 6686 |
|
|
`TIME; $display("*W Frame should start!");
|
| 6687 |
|
|
disable fr_st1;
|
| 6688 |
|
|
end
|
| 6689 |
|
|
end
|
| 6690 |
|
|
end
|
| 6691 |
|
|
join
|
| 6692 |
|
|
// check packets larger than 4 bytes
|
| 6693 |
|
|
if (num_of_frames >= 5)
|
| 6694 |
|
|
begin
|
| 6695 |
|
|
wait (MTxEn === 1'b0); // end transmit
|
| 6696 |
|
|
while (data[15] === 1)
|
| 6697 |
|
|
begin
|
| 6698 |
|
|
#1 check_tx_bd(num_of_bd, data);
|
| 6699 |
|
|
@(posedge wb_clk);
|
| 6700 |
|
|
end
|
| 6701 |
|
|
repeat (1) @(posedge wb_clk);
|
| 6702 |
|
|
// check length of a PACKET
|
| 6703 |
|
|
if (i_length <= (min_tmp - 4))
|
| 6704 |
|
|
begin
|
| 6705 |
|
|
if (eth_phy.tx_len != min_tmp)
|
| 6706 |
|
|
begin
|
| 6707 |
|
|
test_fail("Wrong length of the packet out from MAC");
|
| 6708 |
|
|
fail = fail + 1;
|
| 6709 |
|
|
end
|
| 6710 |
|
|
end
|
| 6711 |
|
|
else
|
| 6712 |
|
|
begin
|
| 6713 |
|
|
if (eth_phy.tx_len != (i_length + 4))
|
| 6714 |
|
|
begin
|
| 6715 |
|
|
test_fail("Wrong length of the packet out from MAC");
|
| 6716 |
|
|
fail = fail + 1;
|
| 6717 |
|
|
end
|
| 6718 |
|
|
end
|
| 6719 |
|
|
// check transmitted TX packet data
|
| 6720 |
|
|
if (i_length[0] == 0)
|
| 6721 |
|
|
begin
|
| 6722 |
|
|
#1 check_tx_packet(`MEMORY_BASE, (num_of_frames * 16), i_length, tmp);
|
| 6723 |
|
|
end
|
| 6724 |
|
|
else
|
| 6725 |
|
|
begin
|
| 6726 |
|
|
#1 check_tx_packet((`MEMORY_BASE + max_tmp), (num_of_frames * 16), i_length, tmp);
|
| 6727 |
|
|
end
|
| 6728 |
|
|
if (tmp > 0)
|
| 6729 |
|
|
begin
|
| 6730 |
|
|
test_fail("Wrong data of the transmitted packet");
|
| 6731 |
|
|
fail = fail + 1;
|
| 6732 |
|
|
end
|
| 6733 |
|
|
// check transmited TX packet CRC
|
| 6734 |
|
|
if (num_of_frames < (min_tmp - 4))
|
| 6735 |
|
|
#1 check_tx_crc((num_of_frames * 16), (min_tmp - 4), 1'b0, tmp); // length without CRC
|
| 6736 |
|
|
else
|
| 6737 |
|
|
#1 check_tx_crc((num_of_frames * 16), i_length, 1'b0, tmp); // length without CRC
|
| 6738 |
|
|
if (tmp > 0)
|
| 6739 |
|
|
begin
|
| 6740 |
|
|
test_fail("Wrong CRC of the transmitted packet");
|
| 6741 |
|
|
fail = fail + 1;
|
| 6742 |
|
|
end
|
| 6743 |
|
|
end
|
| 6744 |
|
|
// check WB INT signal
|
| 6745 |
|
|
if ((i_length[1:0] == 2'h0) && (num_of_frames >= 5))
|
| 6746 |
|
|
begin
|
| 6747 |
|
|
if (wb_int !== 1'b1)
|
| 6748 |
|
|
begin
|
| 6749 |
|
|
`TIME; $display("*E WB INT signal should be set");
|
| 6750 |
|
|
test_fail("WB INT signal should be set");
|
| 6751 |
|
|
fail = fail + 1;
|
| 6752 |
|
|
end
|
| 6753 |
|
|
end
|
| 6754 |
|
|
else
|
| 6755 |
|
|
begin
|
| 6756 |
|
|
if (wb_int !== 1'b0)
|
| 6757 |
|
|
begin
|
| 6758 |
|
|
`TIME; $display("*E WB INT signal should not be set");
|
| 6759 |
|
|
test_fail("WB INT signal should not be set");
|
| 6760 |
|
|
fail = fail + 1;
|
| 6761 |
|
|
end
|
| 6762 |
|
|
end
|
| 6763 |
|
|
// check TX buffer descriptor of a packet
|
| 6764 |
|
|
check_tx_bd(num_of_bd, data);
|
| 6765 |
|
|
if (num_of_frames >= 5)
|
| 6766 |
|
|
begin
|
| 6767 |
|
|
if (i_length[1] == 1'b0) // interrupt enabled
|
| 6768 |
|
|
begin
|
| 6769 |
|
|
if ( (data[15:0] !== 16'h7800) && // wrap bit
|
| 6770 |
|
|
(data[15:0] !== 16'h5800) ) // without wrap bit
|
| 6771 |
|
|
begin
|
| 6772 |
|
|
`TIME; $display("*E TX buffer descriptor status is not correct: %0h", data[15:0]);
|
| 6773 |
|
|
test_fail("TX buffer descriptor status is not correct");
|
| 6774 |
|
|
fail = fail + 1;
|
| 6775 |
|
|
end
|
| 6776 |
|
|
end
|
| 6777 |
|
|
else // interrupt not enabled
|
| 6778 |
|
|
begin
|
| 6779 |
|
|
if ( (data[15:0] !== 16'h3800) && // wrap bit
|
| 6780 |
|
|
(data[15:0] !== 16'h1800) ) // without wrap bit
|
| 6781 |
|
|
begin
|
| 6782 |
|
|
`TIME; $display("*E TX buffer descriptor status is not correct: %0h", data[15:0]);
|
| 6783 |
|
|
test_fail("TX buffer descriptor status is not correct");
|
| 6784 |
|
|
fail = fail + 1;
|
| 6785 |
|
|
end
|
| 6786 |
|
|
end
|
| 6787 |
|
|
end
|
| 6788 |
|
|
else
|
| 6789 |
|
|
begin
|
| 6790 |
|
|
if (data[15] !== 1'b1)
|
| 6791 |
|
|
begin
|
| 6792 |
|
|
`TIME; $display("*E TX buffer descriptor status is not correct: %0h", data[15:0]);
|
| 6793 |
|
|
test_fail("TX buffer descriptor status is not correct");
|
| 6794 |
|
|
fail = fail + 1;
|
| 6795 |
|
|
end
|
| 6796 |
|
|
end
|
| 6797 |
|
|
// clear TX BD with wrap bit
|
| 6798 |
|
|
if (num_of_frames == 63)
|
| 6799 |
|
|
clear_tx_bd(16, 16);
|
| 6800 |
|
|
// check interrupts
|
| 6801 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 6802 |
209 |
tadejm |
wbm_read(`ETH_INT, data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 6803 |
|
|
if ( ((i_length[1:0] == 2'h0) || (i_length[1:0] == 2'h1)) && (num_of_frames >= 5) )
|
| 6804 |
|
|
begin
|
| 6805 |
|
|
if ((data & `ETH_INT_TXB) !== 1'b1)
|
| 6806 |
|
|
begin
|
| 6807 |
|
|
`TIME; $display("*E Interrupt Transmit Buffer was not set, interrupt reg: %0h", data);
|
| 6808 |
|
|
test_fail("Interrupt Transmit Buffer was not set");
|
| 6809 |
|
|
fail = fail + 1;
|
| 6810 |
|
|
end
|
| 6811 |
|
|
if ((data & (~`ETH_INT_TXB)) !== 0)
|
| 6812 |
|
|
begin
|
| 6813 |
|
|
`TIME; $display("*E Other interrupts (except Transmit Buffer) were set, interrupt reg: %0h", data);
|
| 6814 |
|
|
test_fail("Other interrupts (except Transmit Buffer) were set");
|
| 6815 |
|
|
fail = fail + 1;
|
| 6816 |
|
|
end
|
| 6817 |
|
|
end
|
| 6818 |
|
|
else
|
| 6819 |
|
|
begin
|
| 6820 |
|
|
if (data !== 0)
|
| 6821 |
|
|
begin
|
| 6822 |
|
|
`TIME; $display("*E Any of interrupts (except Transmit Buffer) was set, interrupt reg: %0h, len: %0h", data, i_length[1:0]);
|
| 6823 |
|
|
test_fail("Any of interrupts (except Transmit Buffer) was set");
|
| 6824 |
|
|
fail = fail + 1;
|
| 6825 |
|
|
end
|
| 6826 |
|
|
end
|
| 6827 |
|
|
// clear interrupts
|
| 6828 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 6829 |
209 |
tadejm |
wbm_write(`ETH_INT, data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 6830 |
|
|
// check WB INT signal
|
| 6831 |
|
|
if (wb_int !== 1'b0)
|
| 6832 |
|
|
begin
|
| 6833 |
|
|
test_fail("WB INT signal should not be set");
|
| 6834 |
|
|
fail = fail + 1;
|
| 6835 |
|
|
end
|
| 6836 |
|
|
// INTERMEDIATE DISPLAYS
|
| 6837 |
|
|
if (i_length == 3)
|
| 6838 |
|
|
begin
|
| 6839 |
|
|
$display(" pads appending to packets is selected");
|
| 6840 |
|
|
$display(" using 1 BD out of 8 BDs assigned to TX (wrap at 1st BD - TX BD 0)");
|
| 6841 |
|
|
$display(" ->packets with lengths from %0d to %0d are not transmitted (length increasing by 1 byte)",
|
| 6842 |
|
|
0, 3);
|
| 6843 |
|
|
end
|
| 6844 |
|
|
else if (i_length == 9)
|
| 6845 |
|
|
begin
|
| 6846 |
|
|
$display(" using 1 BD out of 8 BDs assigned to TX (wrap at 1st BD - TX BD 0)");
|
| 6847 |
|
|
$display(" ->packet with length 4 is not transmitted (length increasing by 1 byte)");
|
| 6848 |
|
|
$display(" ->packets with lengths from %0d to %0d are checked (length increasing by 1 byte)",
|
| 6849 |
|
|
5, 9);
|
| 6850 |
|
|
end
|
| 6851 |
|
|
else if (i_length == 17)
|
| 6852 |
|
|
begin
|
| 6853 |
|
|
$display(" using 4 BDs out of 8 BDs assigned to TX (wrap at 4th BD - TX BD 3)");
|
| 6854 |
|
|
$display(" ->packets with lengths from %0d to %0d are checked (length increasing by 1 byte)",
|
| 6855 |
|
|
10, 17);
|
| 6856 |
|
|
end
|
| 6857 |
|
|
else if (i_length == 27)
|
| 6858 |
|
|
begin
|
| 6859 |
|
|
$display(" using 5 BDs out of 8 BDs assigned to TX (wrap at 5th BD - TX BD 4)");
|
| 6860 |
|
|
$display(" ->packets with lengths from %0d to %0d are checked (length increasing by 1 byte)",
|
| 6861 |
|
|
18, 27);
|
| 6862 |
|
|
end
|
| 6863 |
|
|
else if (i_length == 40)
|
| 6864 |
|
|
begin
|
| 6865 |
|
|
$display(" using 6 BDs out of 8 BDs assigned to TX (wrap at 6th BD - TX BD 5)");
|
| 6866 |
|
|
$display(" ->packets with lengths from %0d to %0d are checked (length increasing by 1 byte)",
|
| 6867 |
|
|
28, 40);
|
| 6868 |
|
|
end
|
| 6869 |
|
|
else if (i_length == 54)
|
| 6870 |
|
|
begin
|
| 6871 |
|
|
$display(" using 7 BDs out of 8 BDs assigned to TX (wrap at 7th BD - TX BD 6)");
|
| 6872 |
|
|
$display(" ->packets with lengths from %0d to %0d are checked (length increasing by 1 byte)",
|
| 6873 |
|
|
41, 54);
|
| 6874 |
|
|
end
|
| 6875 |
|
|
else if (i_length == 69)
|
| 6876 |
|
|
begin
|
| 6877 |
|
|
$display(" using 8 BDs out of 8 BDs assigned to TX (wrap at 8th BD - TX BD 7)");
|
| 6878 |
|
|
$display(" ->packets with lengths from %0d to %0d are checked (length increasing by 1 byte)",
|
| 6879 |
|
|
55, 69);
|
| 6880 |
|
|
end
|
| 6881 |
|
|
// set length (loop variable)
|
| 6882 |
|
|
i_length = i_length + 1;
|
| 6883 |
|
|
// the number of frame transmitted
|
| 6884 |
|
|
num_of_frames = num_of_frames + 1;
|
| 6885 |
|
|
if (/*(num_of_frames == 2) || (num_of_frames == 4) || (num_of_frames == 7) ||*/ (num_of_frames <= 10) ||
|
| 6886 |
|
|
(num_of_frames == 14) || (num_of_frames == 18) || (num_of_frames == 23) || (num_of_frames == 28) ||
|
| 6887 |
|
|
(num_of_frames == 34) || (num_of_frames == 40) || (num_of_frames == 47) ||
|
| 6888 |
|
|
(num_of_frames == 54) || (num_of_frames == 62))
|
| 6889 |
|
|
num_of_bd = 0;
|
| 6890 |
|
|
else
|
| 6891 |
|
|
num_of_bd = num_of_bd + 1;
|
| 6892 |
|
|
end
|
| 6893 |
|
|
// disable TX
|
| 6894 |
|
|
wbm_write(`ETH_MODER, `ETH_MODER_FULLD | `ETH_MODER_PAD | `ETH_MODER_CRCEN,
|
| 6895 |
|
|
4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 6896 |
|
|
@(posedge wb_clk);
|
| 6897 |
|
|
if(fail == 0)
|
| 6898 |
|
|
test_ok;
|
| 6899 |
|
|
else
|
| 6900 |
|
|
fail = 0;
|
| 6901 |
|
|
end
|
| 6902 |
|
|
|
| 6903 |
|
|
|
| 6904 |
|
|
////////////////////////////////////////////////////////////////////
|
| 6905 |
|
|
//// ////
|
| 6906 |
243 |
tadejm |
//// Test transmit packets (no pads) from 0 to (MINFL - 1) ////
|
| 6907 |
209 |
tadejm |
//// sizes at 8 TX buffer decriptors ( 10Mbps ). ////
|
| 6908 |
|
|
//// ////
|
| 6909 |
|
|
////////////////////////////////////////////////////////////////////
|
| 6910 |
|
|
if (test_num == 8) //
|
| 6911 |
|
|
begin
|
| 6912 |
243 |
tadejm |
// TEST 8: TRANSMIT PACKETS (NO PADs) FROM 0 TO (MINFL - 1) SIZES AT 8 TX BD ( 10Mbps )
|
| 6913 |
|
|
test_name = "TEST 8: TRANSMIT PACKETS (NO PADs) FROM 0 TO (MINFL - 1) SIZES AT 8 TX BD ( 10Mbps )";
|
| 6914 |
|
|
`TIME; $display(" TEST 8: TRANSMIT PACKETS (NO PADs) FROM 0 TO (MINFL - 1) SIZES AT 8 TX BD ( 10Mbps )");
|
| 6915 |
274 |
tadejm |
$display("(%0t) tu smo zdaj", $time);
|
| 6916 |
209 |
tadejm |
// reset MAC registers
|
| 6917 |
|
|
hard_reset;
|
| 6918 |
|
|
// reset MAC and MII LOGIC with soft reset
|
| 6919 |
274 |
tadejm |
// reset_mac;
|
| 6920 |
|
|
// reset_mii;
|
| 6921 |
209 |
tadejm |
// set wb slave response
|
| 6922 |
|
|
wb_slave.cycle_response(`ACK_RESPONSE, wbs_waits, wbs_retries);
|
| 6923 |
|
|
|
| 6924 |
|
|
max_tmp = 0;
|
| 6925 |
|
|
min_tmp = 0;
|
| 6926 |
|
|
// set 8 TX buffer descriptors - must be set before TX enable
|
| 6927 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 6928 |
209 |
tadejm |
wbm_write(`ETH_TX_BD_NUM, 32'h8, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 6929 |
|
|
// enable TX, set full-duplex mode, padding and CRC appending
|
| 6930 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 6931 |
243 |
tadejm |
// wbm_write(`ETH_MODER, `ETH_MODER_TXEN | `ETH_MODER_PAD | `ETH_MODER_FULLD | `ETH_MODER_CRCEN,
|
| 6932 |
|
|
wbm_write(`ETH_MODER, `ETH_MODER_TXEN | `ETH_MODER_FULLD,
|
| 6933 |
209 |
tadejm |
4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 6934 |
|
|
// prepare two packets of MAXFL length
|
| 6935 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 6936 |
209 |
tadejm |
wbm_read(`ETH_PACKETLEN, tmp, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 6937 |
|
|
max_tmp = tmp[15:0]; // 18 bytes consists of 6B dest addr, 6B source addr, 2B type/len, 4B CRC
|
| 6938 |
|
|
min_tmp = tmp[31:16];
|
| 6939 |
|
|
st_data = 8'h12;
|
| 6940 |
|
|
set_tx_packet(`MEMORY_BASE, (max_tmp - 4), st_data); // length without CRC
|
| 6941 |
|
|
st_data = 8'h34;
|
| 6942 |
|
|
set_tx_packet((`MEMORY_BASE + max_tmp), (max_tmp - 4), st_data); // length without CRC
|
| 6943 |
|
|
// check WB INT signal
|
| 6944 |
|
|
if (wb_int !== 1'b0)
|
| 6945 |
|
|
begin
|
| 6946 |
|
|
test_fail("WB INT signal should not be set");
|
| 6947 |
|
|
fail = fail + 1;
|
| 6948 |
|
|
end
|
| 6949 |
|
|
|
| 6950 |
|
|
// write to phy's control register for 10Mbps
|
| 6951 |
|
|
#Tp eth_phy.control_bit14_10 = 5'b00000; // bit 13 reset - speed 10
|
| 6952 |
|
|
#Tp eth_phy.control_bit8_0 = 9'h1_00; // bit 6 reset - (10/100), bit 8 set - FD
|
| 6953 |
|
|
speed = 10;
|
| 6954 |
|
|
|
| 6955 |
|
|
frame_started = 0;
|
| 6956 |
|
|
num_of_frames = 0;
|
| 6957 |
|
|
num_of_bd = 0;
|
| 6958 |
|
|
i_length = 0; // 0;
|
| 6959 |
|
|
while (i_length < 70) // (min_tmp - 4))
|
| 6960 |
|
|
begin
|
| 6961 |
|
|
#1;
|
| 6962 |
|
|
// choose generating carrier sense and collision
|
| 6963 |
|
|
case (i_length[1:0])
|
| 6964 |
|
|
2'h0: // Interrupt is generated
|
| 6965 |
|
|
begin
|
| 6966 |
|
|
// Reset_tx_bd nable interrupt generation
|
| 6967 |
|
|
// unmask interrupts
|
| 6968 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 6969 |
209 |
tadejm |
wbm_write(`ETH_INT_MASK, `ETH_INT_TXB | `ETH_INT_TXE | `ETH_INT_RXB | `ETH_INT_RXE | `ETH_INT_BUSY |
|
| 6970 |
|
|
`ETH_INT_TXC | `ETH_INT_RXC, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 6971 |
|
|
// not detect carrier sense in FD and no collision
|
| 6972 |
|
|
eth_phy.carrier_sense_tx_fd_detect(0);
|
| 6973 |
|
|
eth_phy.collision(0);
|
| 6974 |
|
|
end
|
| 6975 |
|
|
2'h1: // Interrupt is not generated
|
| 6976 |
|
|
begin
|
| 6977 |
|
|
// set_tx_bd enable interrupt generation
|
| 6978 |
|
|
// mask interrupts
|
| 6979 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 6980 |
209 |
tadejm |
wbm_write(`ETH_INT_MASK, 32'h0, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 6981 |
|
|
// detect carrier sense in FD and no collision
|
| 6982 |
|
|
eth_phy.carrier_sense_tx_fd_detect(1);
|
| 6983 |
|
|
eth_phy.collision(0);
|
| 6984 |
|
|
end
|
| 6985 |
|
|
2'h2: // Interrupt is not generated
|
| 6986 |
|
|
begin
|
| 6987 |
|
|
// set_tx_bd disable the interrupt generation
|
| 6988 |
|
|
// unmask interrupts
|
| 6989 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 6990 |
209 |
tadejm |
wbm_write(`ETH_INT_MASK, `ETH_INT_TXB | `ETH_INT_TXE | `ETH_INT_RXB | `ETH_INT_RXE | `ETH_INT_BUSY |
|
| 6991 |
|
|
`ETH_INT_TXC | `ETH_INT_RXC, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 6992 |
|
|
// not detect carrier sense in FD and set collision
|
| 6993 |
|
|
eth_phy.carrier_sense_tx_fd_detect(0);
|
| 6994 |
|
|
eth_phy.collision(1);
|
| 6995 |
|
|
end
|
| 6996 |
|
|
default: // 2'h3: // Interrupt is not generated
|
| 6997 |
|
|
begin
|
| 6998 |
|
|
// set_tx_bd disable the interrupt generation
|
| 6999 |
|
|
// mask interrupts
|
| 7000 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 7001 |
209 |
tadejm |
wbm_write(`ETH_INT_MASK, 32'h0, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 7002 |
|
|
// detect carrier sense in FD and set collision
|
| 7003 |
|
|
eth_phy.carrier_sense_tx_fd_detect(1);
|
| 7004 |
|
|
eth_phy.collision(1);
|
| 7005 |
|
|
end
|
| 7006 |
|
|
endcase
|
| 7007 |
243 |
tadejm |
// // append CRC
|
| 7008 |
|
|
// if ((i_length[0] == 1'b0) && (num_of_frames >= 6))
|
| 7009 |
|
|
// begin
|
| 7010 |
|
|
// append_tx_crc(`MEMORY_BASE, i_length, 1'b0);
|
| 7011 |
|
|
// end
|
| 7012 |
209 |
tadejm |
#1;
|
| 7013 |
|
|
// first destination address on ethernet PHY
|
| 7014 |
|
|
eth_phy.set_tx_mem_addr(num_of_frames * 16);
|
| 7015 |
|
|
// SET packets and wrap bit
|
| 7016 |
|
|
// num_of_frames <= 9 => wrap set to TX BD 0
|
| 7017 |
243 |
tadejm |
if (num_of_frames <= 5)
|
| 7018 |
|
|
begin
|
| 7019 |
|
|
tmp_len = i_length; // length of frame
|
| 7020 |
|
|
tmp_bd_num = 0; // TX BD number
|
| 7021 |
|
|
// if i_length[1] == 0 then enable interrupt generation otherwise disable it
|
| 7022 |
|
|
// if i_length[0] == 0 then base address is `MEMORY_BASE otherwise it is `MEMORY_BASE + max_tmp
|
| 7023 |
274 |
tadejm |
|
| 7024 |
|
|
/*
|
| 7025 |
|
|
input [6:0] tx_bd_num_start;
|
| 7026 |
|
|
input [6:0] tx_bd_num_end;
|
| 7027 |
|
|
input [15:0] len;
|
| 7028 |
|
|
input irq;
|
| 7029 |
|
|
input pad;
|
| 7030 |
|
|
input crc;
|
| 7031 |
|
|
input [31:0] txpnt;
|
| 7032 |
|
|
*/
|
| 7033 |
|
|
|
| 7034 |
|
|
|
| 7035 |
243 |
tadejm |
if (tmp_len[0] == 0) // CRC appended by 'HARDWARE'
|
| 7036 |
274 |
tadejm |
// set_tx_bd(tmp_bd_num, tmp_bd_num, tmp_len, !tmp_len[1], 1'b0, 1'b1, `MEMORY_BASE);
|
| 7037 |
|
|
set_tx_bd(tmp_bd_num, tmp_bd_num, tmp_len, 1'b1, 1'b0, !tmp_len[1], `MEMORY_BASE);
|
| 7038 |
243 |
tadejm |
else
|
| 7039 |
274 |
tadejm |
// set_tx_bd(tmp_bd_num, tmp_bd_num, tmp_len, !tmp_len[1], 1'b0, 1'b1, (`MEMORY_BASE + max_tmp));
|
| 7040 |
|
|
set_tx_bd(tmp_bd_num, tmp_bd_num, tmp_len, 1'b1, 1'b0, !tmp_len[1], (`MEMORY_BASE + max_tmp));
|
| 7041 |
243 |
tadejm |
// set wrap bit
|
| 7042 |
|
|
set_tx_bd_wrap(0);
|
| 7043 |
|
|
end
|
| 7044 |
|
|
else if (num_of_frames <= 9)
|
| 7045 |
|
|
begin
|
| 7046 |
|
|
tmp_len = i_length; // length of frame
|
| 7047 |
|
|
tmp_bd_num = 0; // TX BD number
|
| 7048 |
|
|
// if i_length[1] == 0 then enable interrupt generation otherwise disable it
|
| 7049 |
|
|
// if i_length[0] == 0 then base address is `MEMORY_BASE otherwise it is `MEMORY_BASE + max_tmp
|
| 7050 |
|
|
if (tmp_len[0] == 0) // CRC appended by 'SOFTWARE'
|
| 7051 |
|
|
set_tx_bd(tmp_bd_num, tmp_bd_num, (tmp_len + 0), !tmp_len[1], 1'b0, 1'b0, `MEMORY_BASE);
|
| 7052 |
|
|
else
|
| 7053 |
|
|
set_tx_bd(tmp_bd_num, tmp_bd_num, tmp_len, !tmp_len[1], 1'b0, 1'b1, (`MEMORY_BASE + max_tmp));
|
| 7054 |
|
|
// set wrap bit
|
| 7055 |
|
|
set_tx_bd_wrap(0);
|
| 7056 |
209 |
tadejm |
end
|
| 7057 |
|
|
// 10 <= num_of_frames < 18 => wrap set to TX BD 3
|
| 7058 |
|
|
else if ((num_of_frames == 10) || (num_of_frames == 14))
|
| 7059 |
|
|
begin
|
| 7060 |
|
|
tmp_len = i_length; // length of frame
|
| 7061 |
|
|
tmp_bd_num = 0; // TX BD number
|
| 7062 |
|
|
while (tmp_bd_num < 4) //
|
| 7063 |
|
|
begin
|
| 7064 |
|
|
// if i_length[1] == 0 then enable interrupt generation otherwise disable it
|
| 7065 |
|
|
// if i_length[0] == 0 then base address is `MEMORY_BASE otherwise it is `MEMORY_BASE + max_tmp
|
| 7066 |
|
|
if (tmp_len[0] == 0)
|
| 7067 |
243 |
tadejm |
set_tx_bd(tmp_bd_num, tmp_bd_num, (tmp_len + 0), !tmp_len[1], 1'b0, 1'b0, `MEMORY_BASE);
|
| 7068 |
209 |
tadejm |
else
|
| 7069 |
243 |
tadejm |
set_tx_bd(tmp_bd_num, tmp_bd_num, tmp_len, !tmp_len[1], 1'b0, 1'b1, (`MEMORY_BASE + max_tmp));
|
| 7070 |
209 |
tadejm |
tmp_len = tmp_len + 1;
|
| 7071 |
|
|
// set TX BD number
|
| 7072 |
|
|
tmp_bd_num = tmp_bd_num + 1;
|
| 7073 |
|
|
end
|
| 7074 |
|
|
// set wrap bit
|
| 7075 |
|
|
set_tx_bd_wrap(3);
|
| 7076 |
|
|
end
|
| 7077 |
|
|
// 18 <= num_of_frames < 28 => wrap set to TX BD 4
|
| 7078 |
|
|
else if ((num_of_frames == 18) || (num_of_frames == 23))
|
| 7079 |
|
|
begin
|
| 7080 |
|
|
tmp_len = i_length; // length of frame
|
| 7081 |
|
|
tmp_bd_num = 0; // TX BD number
|
| 7082 |
|
|
while (tmp_bd_num < 5) //
|
| 7083 |
|
|
begin
|
| 7084 |
|
|
// if i_length[1] == 0 then enable interrupt generation otherwise disable it
|
| 7085 |
|
|
// if i_length[0] == 0 then base address is `MEMORY_BASE otherwise it is `MEMORY_BASE + max_tmp
|
| 7086 |
|
|
if (tmp_len[0] == 0)
|
| 7087 |
243 |
tadejm |
set_tx_bd(tmp_bd_num, tmp_bd_num, (tmp_len + 0), !tmp_len[1], 1'b0, 1'b0, `MEMORY_BASE);
|
| 7088 |
|
|
else // when (num_of_frames == 23), (i_length == 23) and therefor i_length[0] == 1 !!!
|
| 7089 |
|
|
set_tx_bd(tmp_bd_num, tmp_bd_num, tmp_len, !tmp_len[1],
|
| 7090 |
|
|
((num_of_frames == 23) && (tmp_bd_num == 0)), 1'b1, (`MEMORY_BASE + max_tmp));
|
| 7091 |
209 |
tadejm |
tmp_len = tmp_len + 1;
|
| 7092 |
|
|
// set TX BD number
|
| 7093 |
|
|
tmp_bd_num = tmp_bd_num + 1;
|
| 7094 |
|
|
end
|
| 7095 |
|
|
// set wrap bit
|
| 7096 |
|
|
set_tx_bd_wrap(4);
|
| 7097 |
|
|
end
|
| 7098 |
|
|
// 28 <= num_of_frames < 40 => wrap set to TX BD 5
|
| 7099 |
|
|
else if ((num_of_frames == 28) || (num_of_frames == 34))
|
| 7100 |
|
|
begin
|
| 7101 |
|
|
tmp_len = i_length; // length of frame
|
| 7102 |
|
|
tmp_bd_num = 0; // TX BD number
|
| 7103 |
|
|
while (tmp_bd_num < 6) //
|
| 7104 |
|
|
begin
|
| 7105 |
|
|
// if i_length[1] == 0 then enable interrupt generation otherwise disable it
|
| 7106 |
|
|
// if i_length[0] == 0 then base address is `MEMORY_BASE otherwise it is `MEMORY_BASE + max_tmp
|
| 7107 |
|
|
if (tmp_len[0] == 0)
|
| 7108 |
243 |
tadejm |
set_tx_bd(tmp_bd_num, tmp_bd_num, (tmp_len + 0), !tmp_len[1], 1'b0, 1'b0, `MEMORY_BASE);
|
| 7109 |
209 |
tadejm |
else
|
| 7110 |
243 |
tadejm |
set_tx_bd(tmp_bd_num, tmp_bd_num, tmp_len, !tmp_len[1], 1'b0, 1'b1, (`MEMORY_BASE + max_tmp));
|
| 7111 |
209 |
tadejm |
tmp_len = tmp_len + 1;
|
| 7112 |
|
|
// set TX BD number
|
| 7113 |
|
|
tmp_bd_num = tmp_bd_num + 1;
|
| 7114 |
|
|
end
|
| 7115 |
|
|
// set wrap bit
|
| 7116 |
|
|
set_tx_bd_wrap(5);
|
| 7117 |
|
|
end
|
| 7118 |
|
|
// 40 <= num_of_frames < 54 => wrap set to TX BD 6
|
| 7119 |
|
|
else if ((num_of_frames == 40) || (num_of_frames == 47))
|
| 7120 |
|
|
begin
|
| 7121 |
|
|
tmp_len = i_length; // length of frame
|
| 7122 |
|
|
tmp_bd_num = 0; // TX BD number
|
| 7123 |
|
|
while (tmp_bd_num < 7) //
|
| 7124 |
|
|
begin
|
| 7125 |
|
|
// if i_length[1] == 0 then enable interrupt generation otherwise disable it
|
| 7126 |
|
|
// if i_length[0] == 0 then base address is `MEMORY_BASE otherwise it is `MEMORY_BASE + max_tmp
|
| 7127 |
|
|
if (tmp_len[0] == 0)
|
| 7128 |
243 |
tadejm |
set_tx_bd(tmp_bd_num, tmp_bd_num, (tmp_len + 0), !tmp_len[1], 1'b0, 1'b0, `MEMORY_BASE);
|
| 7129 |
209 |
tadejm |
else
|
| 7130 |
243 |
tadejm |
set_tx_bd(tmp_bd_num, tmp_bd_num, tmp_len, !tmp_len[1], 1'b0, 1'b1, (`MEMORY_BASE + max_tmp));
|
| 7131 |
209 |
tadejm |
tmp_len = tmp_len + 1;
|
| 7132 |
|
|
// set TX BD number
|
| 7133 |
|
|
tmp_bd_num = tmp_bd_num + 1;
|
| 7134 |
|
|
end
|
| 7135 |
|
|
// set wrap bit
|
| 7136 |
|
|
set_tx_bd_wrap(6);
|
| 7137 |
|
|
end
|
| 7138 |
|
|
// 54 <= num_of_frames < 70 => wrap set to TX BD 7
|
| 7139 |
|
|
else if ((num_of_frames == 54) || (num_of_frames == 62))
|
| 7140 |
|
|
begin
|
| 7141 |
|
|
tmp_len = i_length; // length of frame
|
| 7142 |
|
|
tmp_bd_num = 0; // TX BD number
|
| 7143 |
|
|
while (tmp_bd_num < 8) //
|
| 7144 |
|
|
begin
|
| 7145 |
|
|
// if i_length[1] == 0 then enable interrupt generation otherwise disable it
|
| 7146 |
|
|
// if i_length[0] == 0 then base address is `MEMORY_BASE otherwise it is `MEMORY_BASE + max_tmp
|
| 7147 |
|
|
if (tmp_len[0] == 0)
|
| 7148 |
243 |
tadejm |
set_tx_bd(tmp_bd_num, tmp_bd_num, (tmp_len + 0), !tmp_len[1], 1'b0, 1'b0, `MEMORY_BASE);
|
| 7149 |
209 |
tadejm |
else
|
| 7150 |
243 |
tadejm |
set_tx_bd(tmp_bd_num, tmp_bd_num, tmp_len, !tmp_len[1], 1'b0, 1'b1, (`MEMORY_BASE + max_tmp));
|
| 7151 |
209 |
tadejm |
tmp_len = tmp_len + 1;
|
| 7152 |
|
|
// set TX BD number
|
| 7153 |
|
|
tmp_bd_num = tmp_bd_num + 1;
|
| 7154 |
|
|
end
|
| 7155 |
|
|
// set wrap bit
|
| 7156 |
|
|
set_tx_bd_wrap(7);
|
| 7157 |
|
|
end
|
| 7158 |
|
|
#1;
|
| 7159 |
|
|
// SET ready bit
|
| 7160 |
|
|
if (num_of_frames < 10)
|
| 7161 |
|
|
set_tx_bd_ready(0, 0);
|
| 7162 |
|
|
else if (num_of_frames < 14)
|
| 7163 |
|
|
set_tx_bd_ready((num_of_frames - 10), (num_of_frames - 10));
|
| 7164 |
|
|
else if (num_of_frames < 18)
|
| 7165 |
|
|
set_tx_bd_ready((num_of_frames - 14), (num_of_frames - 14));
|
| 7166 |
|
|
else if (num_of_frames < 23)
|
| 7167 |
|
|
set_tx_bd_ready((num_of_frames - 18), (num_of_frames - 18));
|
| 7168 |
|
|
else if (num_of_frames < 28)
|
| 7169 |
|
|
set_tx_bd_ready((num_of_frames - 23), (num_of_frames - 23));
|
| 7170 |
|
|
else if (num_of_frames < 34)
|
| 7171 |
|
|
set_tx_bd_ready((num_of_frames - 28), (num_of_frames - 28));
|
| 7172 |
|
|
else if (num_of_frames < 40)
|
| 7173 |
|
|
set_tx_bd_ready((num_of_frames - 34), (num_of_frames - 34));
|
| 7174 |
|
|
else if (num_of_frames < 47)
|
| 7175 |
|
|
set_tx_bd_ready((num_of_frames - 40), (num_of_frames - 40));
|
| 7176 |
|
|
else if (num_of_frames < 54)
|
| 7177 |
|
|
set_tx_bd_ready((num_of_frames - 47), (num_of_frames - 47));
|
| 7178 |
|
|
else if (num_of_frames < 62)
|
| 7179 |
|
|
set_tx_bd_ready((num_of_frames - 54), (num_of_frames - 54));
|
| 7180 |
|
|
else if (num_of_frames < 70)
|
| 7181 |
|
|
set_tx_bd_ready((num_of_frames - 62), (num_of_frames - 62));
|
| 7182 |
|
|
// CHECK END OF TRANSMITION
|
| 7183 |
|
|
frame_started = 0;
|
| 7184 |
|
|
if (num_of_frames >= 5)
|
| 7185 |
|
|
#1 check_tx_bd(num_of_bd, data);
|
| 7186 |
|
|
fork
|
| 7187 |
|
|
begin: fr_st2
|
| 7188 |
|
|
wait (MTxEn === 1'b1); // start transmit
|
| 7189 |
|
|
frame_started = 1;
|
| 7190 |
|
|
end
|
| 7191 |
|
|
begin
|
| 7192 |
|
|
repeat (30) @(posedge mtx_clk);
|
| 7193 |
|
|
if (num_of_frames < 5)
|
| 7194 |
|
|
begin
|
| 7195 |
|
|
if (frame_started == 1)
|
| 7196 |
|
|
begin
|
| 7197 |
|
|
`TIME; $display("*E Frame should NOT start!");
|
| 7198 |
|
|
end
|
| 7199 |
|
|
disable fr_st2;
|
| 7200 |
|
|
end
|
| 7201 |
|
|
else
|
| 7202 |
|
|
begin
|
| 7203 |
|
|
if (frame_started == 0)
|
| 7204 |
|
|
begin
|
| 7205 |
|
|
`TIME; $display("*W Frame should start!");
|
| 7206 |
|
|
disable fr_st2;
|
| 7207 |
|
|
end
|
| 7208 |
|
|
end
|
| 7209 |
|
|
end
|
| 7210 |
|
|
join
|
| 7211 |
|
|
// check packets larger than 4 bytes
|
| 7212 |
|
|
if (num_of_frames >= 5)
|
| 7213 |
|
|
begin
|
| 7214 |
|
|
wait (MTxEn === 1'b0); // end transmit
|
| 7215 |
|
|
while (data[15] === 1)
|
| 7216 |
|
|
begin
|
| 7217 |
|
|
#1 check_tx_bd(num_of_bd, data);
|
| 7218 |
|
|
@(posedge wb_clk);
|
| 7219 |
|
|
end
|
| 7220 |
|
|
repeat (1) @(posedge wb_clk);
|
| 7221 |
274 |
tadejm |
|
| 7222 |
|
|
$display("(%0t) 1eth_phy.tx_len = 0x%0x, i_length = 0x%0x", $time, eth_phy.tx_len, i_length);
|
| 7223 |
|
|
$display("(%0t) 1num_of_frames = 0x%0x", $time, num_of_frames);
|
| 7224 |
|
|
|
| 7225 |
243 |
tadejm |
// check length of a PACKET
|
| 7226 |
274 |
tadejm |
if ((eth_phy.tx_len != i_length) && (i_length[0] == 1'b0) && (num_of_frames >= 6)) // (num_of_frames >= 6) igor
|
| 7227 |
|
|
// if ((a !== b) && (b[0] == 1'b0) && (c >= 6))
|
| 7228 |
209 |
tadejm |
begin
|
| 7229 |
|
|
`TIME; $display("*E Wrong length of the packet out from MAC");
|
| 7230 |
|
|
test_fail("Wrong length of the packet out from MAC");
|
| 7231 |
|
|
fail = fail + 1;
|
| 7232 |
|
|
end
|
| 7233 |
274 |
tadejm |
else if ((eth_phy.tx_len != (i_length + 4)) && (num_of_frames != 23)) // i_length + 4 igor
|
| 7234 |
243 |
tadejm |
begin
|
| 7235 |
274 |
tadejm |
`TIME; $display("*E Wrong length of the packet out from MAC yyy");
|
| 7236 |
243 |
tadejm |
test_fail("Wrong length of the packet out from MAC");
|
| 7237 |
|
|
fail = fail + 1;
|
| 7238 |
274 |
tadejm |
$display("(%0t) 2eth_phy.tx_len = 0x%0x, i_length = 0x%0x", $time, eth_phy.tx_len, i_length);
|
| 7239 |
|
|
$display("(%0t) 2num_of_frames = 0x%0x", $time, num_of_frames);
|
| 7240 |
|
|
//a = eth_phy.tx_len;
|
| 7241 |
|
|
//b = i_length;
|
| 7242 |
|
|
//c = num_of_frames;
|
| 7243 |
|
|
//#1;
|
| 7244 |
|
|
//$display("(%0t) 2eth_phy.tx_len = 0x%0x, i_length = 0x%0x", $time, eth_phy.tx_len, i_length);
|
| 7245 |
|
|
//$display("(%0t) 2num_of_frames = 0x%0x", $time, num_of_frames);
|
| 7246 |
|
|
//$display("(%0t) 3eth_phy.tx_len = 0x%0x, i_length = 0x%0x", $time, eth_phy.tx_len, i_length);
|
| 7247 |
|
|
//$display("(%0t) 3num_of_frames = 0x%0x", $time, num_of_frames);
|
| 7248 |
243 |
tadejm |
end
|
| 7249 |
|
|
else if ((eth_phy.tx_len != (min_tmp)) && (num_of_frames == 23))
|
| 7250 |
|
|
begin
|
| 7251 |
274 |
tadejm |
`TIME; $display("*E Wrong length of the packet out from MAC zzz");
|
| 7252 |
243 |
tadejm |
test_fail("Wrong length of the packet out from MAC");
|
| 7253 |
|
|
fail = fail + 1;
|
| 7254 |
|
|
end
|
| 7255 |
209 |
tadejm |
// check transmitted TX packet data
|
| 7256 |
|
|
if (i_length[0] == 0)
|
| 7257 |
|
|
begin
|
| 7258 |
|
|
#1 check_tx_packet(`MEMORY_BASE, (num_of_frames * 16), i_length, tmp);
|
| 7259 |
|
|
end
|
| 7260 |
243 |
tadejm |
else if (num_of_frames == 23) // i_length[0] == 1 here
|
| 7261 |
|
|
begin
|
| 7262 |
|
|
#1 check_tx_packet((`MEMORY_BASE + max_tmp), (num_of_frames * 16), (min_tmp - 4), tmp);
|
| 7263 |
|
|
end
|
| 7264 |
209 |
tadejm |
else
|
| 7265 |
|
|
begin
|
| 7266 |
|
|
#1 check_tx_packet((`MEMORY_BASE + max_tmp), (num_of_frames * 16), i_length, tmp);
|
| 7267 |
|
|
end
|
| 7268 |
|
|
if (tmp > 0)
|
| 7269 |
|
|
begin
|
| 7270 |
|
|
test_fail("Wrong data of the transmitted packet");
|
| 7271 |
|
|
fail = fail + 1;
|
| 7272 |
|
|
end
|
| 7273 |
|
|
// check transmited TX packet CRC
|
| 7274 |
243 |
tadejm |
#1;
|
| 7275 |
|
|
if ((i_length[0] == 1'b0) && (num_of_frames >= 6))
|
| 7276 |
|
|
begin
|
| 7277 |
|
|
end
|
| 7278 |
|
|
else
|
| 7279 |
|
|
check_tx_crc((num_of_frames * 16), (eth_phy.tx_len - 4), 1'b0, tmp); // length without CRC
|
| 7280 |
209 |
tadejm |
if (tmp > 0)
|
| 7281 |
|
|
begin
|
| 7282 |
|
|
test_fail("Wrong CRC of the transmitted packet");
|
| 7283 |
|
|
fail = fail + 1;
|
| 7284 |
|
|
end
|
| 7285 |
|
|
end
|
| 7286 |
|
|
// check WB INT signal
|
| 7287 |
|
|
if ((i_length[1:0] == 2'h0) && (num_of_frames >= 5))
|
| 7288 |
|
|
begin
|
| 7289 |
|
|
if (wb_int !== 1'b1)
|
| 7290 |
|
|
begin
|
| 7291 |
|
|
`TIME; $display("*E WB INT signal should be set");
|
| 7292 |
|
|
test_fail("WB INT signal should be set");
|
| 7293 |
|
|
fail = fail + 1;
|
| 7294 |
|
|
end
|
| 7295 |
|
|
end
|
| 7296 |
|
|
else
|
| 7297 |
|
|
begin
|
| 7298 |
|
|
if (wb_int !== 1'b0)
|
| 7299 |
|
|
begin
|
| 7300 |
|
|
`TIME; $display("*E WB INT signal should not be set");
|
| 7301 |
|
|
test_fail("WB INT signal should not be set");
|
| 7302 |
|
|
fail = fail + 1;
|
| 7303 |
|
|
end
|
| 7304 |
|
|
end
|
| 7305 |
|
|
// check TX buffer descriptor of a packet
|
| 7306 |
|
|
check_tx_bd(num_of_bd, data);
|
| 7307 |
|
|
if (num_of_frames >= 5)
|
| 7308 |
|
|
begin
|
| 7309 |
243 |
tadejm |
if ((i_length[1] == 1'b0) && (i_length[0] == 1'b0)) // interrupt enabled
|
| 7310 |
209 |
tadejm |
begin
|
| 7311 |
243 |
tadejm |
if ( (data[15:0] !== 16'h6000) && // wrap bit
|
| 7312 |
|
|
(data[15:0] !== 16'h4000) ) // without wrap bit
|
| 7313 |
209 |
tadejm |
begin
|
| 7314 |
|
|
`TIME; $display("*E TX buffer descriptor status is not correct: %0h", data[15:0]);
|
| 7315 |
|
|
test_fail("TX buffer descriptor status is not correct");
|
| 7316 |
|
|
fail = fail + 1;
|
| 7317 |
|
|
end
|
| 7318 |
|
|
end
|
| 7319 |
243 |
tadejm |
else if ((i_length[1] == 1'b1) && (i_length[0] == 1'b0)) // interrupt not enabled
|
| 7320 |
209 |
tadejm |
begin
|
| 7321 |
243 |
tadejm |
if ( (data[15:0] !== 16'h2000) && // wrap bit
|
| 7322 |
|
|
(data[15:0] !== 16'h0000) ) // without wrap bit
|
| 7323 |
|
|
begin
|
| 7324 |
|
|
`TIME; $display("*E TX buffer descriptor status is not correct: %0h", data[15:0]);
|
| 7325 |
|
|
test_fail("TX buffer descriptor status is not correct");
|
| 7326 |
|
|
fail = fail + 1;
|
| 7327 |
|
|
end
|
| 7328 |
|
|
end
|
| 7329 |
|
|
else if ((i_length[1] == 1'b0) && (i_length[0] == 1'b1)) // interrupt enabled
|
| 7330 |
|
|
begin
|
| 7331 |
|
|
if ( (data[15:0] !== 16'h6800) && // wrap bit
|
| 7332 |
|
|
(data[15:0] !== 16'h4800) ) // without wrap bit
|
| 7333 |
|
|
begin
|
| 7334 |
|
|
`TIME; $display("*E TX buffer descriptor status is not correct: %0h", data[15:0]);
|
| 7335 |
|
|
test_fail("TX buffer descriptor status is not correct");
|
| 7336 |
|
|
fail = fail + 1;
|
| 7337 |
|
|
end
|
| 7338 |
|
|
end
|
| 7339 |
|
|
else if (num_of_frames != 23) // ((i_length[1] == 1'b1) && (i_length[0] == 1'b1)) // interrupt not enabled
|
| 7340 |
|
|
begin
|
| 7341 |
|
|
if ( (data[15:0] !== 16'h2800) && // wrap bit
|
| 7342 |
|
|
(data[15:0] !== 16'h0800) ) // without wrap bit
|
| 7343 |
|
|
begin
|
| 7344 |
|
|
`TIME; $display("*E TX buffer descriptor status is not correct: %0h", data[15:0]);
|
| 7345 |
|
|
test_fail("TX buffer descriptor status is not correct");
|
| 7346 |
|
|
fail = fail + 1;
|
| 7347 |
|
|
end
|
| 7348 |
|
|
end
|
| 7349 |
|
|
else // ((num_of_frames != 23) && (i_length[1] == 1'b1) && (i_length[0] == 1'b1)) // interrupt not enabled
|
| 7350 |
|
|
begin
|
| 7351 |
209 |
tadejm |
if ( (data[15:0] !== 16'h3800) && // wrap bit
|
| 7352 |
|
|
(data[15:0] !== 16'h1800) ) // without wrap bit
|
| 7353 |
|
|
begin
|
| 7354 |
|
|
`TIME; $display("*E TX buffer descriptor status is not correct: %0h", data[15:0]);
|
| 7355 |
|
|
test_fail("TX buffer descriptor status is not correct");
|
| 7356 |
|
|
fail = fail + 1;
|
| 7357 |
|
|
end
|
| 7358 |
|
|
end
|
| 7359 |
|
|
end
|
| 7360 |
|
|
else
|
| 7361 |
|
|
begin
|
| 7362 |
|
|
if (data[15] !== 1'b1)
|
| 7363 |
|
|
begin
|
| 7364 |
|
|
`TIME; $display("*E TX buffer descriptor status is not correct: %0h", data[15:0]);
|
| 7365 |
|
|
test_fail("TX buffer descriptor status is not correct");
|
| 7366 |
|
|
fail = fail + 1;
|
| 7367 |
|
|
end
|
| 7368 |
|
|
end
|
| 7369 |
|
|
// clear TX BD with wrap bit
|
| 7370 |
|
|
if (num_of_frames == 63)
|
| 7371 |
|
|
clear_tx_bd(16, 16);
|
| 7372 |
|
|
// check interrupts
|
| 7373 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 7374 |
209 |
tadejm |
wbm_read(`ETH_INT, data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 7375 |
|
|
if ( ((i_length[1:0] == 2'h0) || (i_length[1:0] == 2'h1)) && (num_of_frames >= 5) )
|
| 7376 |
|
|
begin
|
| 7377 |
|
|
if ((data & `ETH_INT_TXB) !== 1'b1)
|
| 7378 |
|
|
begin
|
| 7379 |
|
|
`TIME; $display("*E Interrupt Transmit Buffer was not set, interrupt reg: %0h", data);
|
| 7380 |
|
|
test_fail("Interrupt Transmit Buffer was not set");
|
| 7381 |
|
|
fail = fail + 1;
|
| 7382 |
|
|
end
|
| 7383 |
|
|
if ((data & (~`ETH_INT_TXB)) !== 0)
|
| 7384 |
|
|
begin
|
| 7385 |
|
|
`TIME; $display("*E Other interrupts (except Transmit Buffer) were set, interrupt reg: %0h", data);
|
| 7386 |
|
|
test_fail("Other interrupts (except Transmit Buffer) were set");
|
| 7387 |
|
|
fail = fail + 1;
|
| 7388 |
|
|
end
|
| 7389 |
|
|
end
|
| 7390 |
|
|
else
|
| 7391 |
|
|
begin
|
| 7392 |
|
|
if (data !== 0)
|
| 7393 |
|
|
begin
|
| 7394 |
|
|
`TIME; $display("*E Any of interrupts (except Transmit Buffer) was set, interrupt reg: %0h, len: %0h", data, i_length[1:0]);
|
| 7395 |
|
|
test_fail("Any of interrupts (except Transmit Buffer) was set");
|
| 7396 |
|
|
fail = fail + 1;
|
| 7397 |
|
|
end
|
| 7398 |
|
|
end
|
| 7399 |
|
|
// clear interrupts
|
| 7400 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 7401 |
209 |
tadejm |
wbm_write(`ETH_INT, data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 7402 |
|
|
// check WB INT signal
|
| 7403 |
|
|
if (wb_int !== 1'b0)
|
| 7404 |
|
|
begin
|
| 7405 |
|
|
test_fail("WB INT signal should not be set");
|
| 7406 |
|
|
fail = fail + 1;
|
| 7407 |
|
|
end
|
| 7408 |
|
|
// INTERMEDIATE DISPLAYS
|
| 7409 |
|
|
if (i_length == 3)
|
| 7410 |
|
|
begin
|
| 7411 |
274 |
tadejm |
$display(" pads appending to packets is selected"); // Is this line OK? Do we have PADS? igor
|
| 7412 |
209 |
tadejm |
$display(" using 1 BD out of 8 BDs assigned to TX (wrap at 1st BD - TX BD 0)");
|
| 7413 |
|
|
$display(" ->packets with lengths from %0d to %0d are not transmitted (length increasing by 1 byte)",
|
| 7414 |
|
|
0, 3);
|
| 7415 |
|
|
end
|
| 7416 |
|
|
else if (i_length == 9)
|
| 7417 |
|
|
begin
|
| 7418 |
|
|
$display(" using 1 BD out of 8 BDs assigned to TX (wrap at 1st BD - TX BD 0)");
|
| 7419 |
|
|
$display(" ->packet with length 4 is not transmitted (length increasing by 1 byte)");
|
| 7420 |
|
|
$display(" ->packets with lengths from %0d to %0d are checked (length increasing by 1 byte)",
|
| 7421 |
|
|
5, 9);
|
| 7422 |
|
|
end
|
| 7423 |
|
|
else if (i_length == 17)
|
| 7424 |
|
|
begin
|
| 7425 |
|
|
$display(" using 4 BDs out of 8 BDs assigned to TX (wrap at 4th BD - TX BD 3)");
|
| 7426 |
|
|
$display(" ->packets with lengths from %0d to %0d are checked (length increasing by 1 byte)",
|
| 7427 |
|
|
10, 17);
|
| 7428 |
|
|
end
|
| 7429 |
|
|
else if (i_length == 27)
|
| 7430 |
|
|
begin
|
| 7431 |
|
|
$display(" using 5 BDs out of 8 BDs assigned to TX (wrap at 5th BD - TX BD 4)");
|
| 7432 |
|
|
$display(" ->packets with lengths from %0d to %0d are checked (length increasing by 1 byte)",
|
| 7433 |
|
|
18, 27);
|
| 7434 |
|
|
end
|
| 7435 |
|
|
else if (i_length == 40)
|
| 7436 |
|
|
begin
|
| 7437 |
|
|
$display(" using 6 BDs out of 8 BDs assigned to TX (wrap at 6th BD - TX BD 5)");
|
| 7438 |
|
|
$display(" ->packets with lengths from %0d to %0d are checked (length increasing by 1 byte)",
|
| 7439 |
|
|
28, 40);
|
| 7440 |
|
|
end
|
| 7441 |
|
|
else if (i_length == 54)
|
| 7442 |
|
|
begin
|
| 7443 |
|
|
$display(" using 7 BDs out of 8 BDs assigned to TX (wrap at 7th BD - TX BD 6)");
|
| 7444 |
|
|
$display(" ->packets with lengths from %0d to %0d are checked (length increasing by 1 byte)",
|
| 7445 |
|
|
41, 54);
|
| 7446 |
|
|
end
|
| 7447 |
|
|
else if (i_length == 69)
|
| 7448 |
|
|
begin
|
| 7449 |
|
|
$display(" using 8 BDs out of 8 BDs assigned to TX (wrap at 8th BD - TX BD 7)");
|
| 7450 |
|
|
$display(" ->packets with lengths from %0d to %0d are checked (length increasing by 1 byte)",
|
| 7451 |
|
|
55, 69);
|
| 7452 |
|
|
end
|
| 7453 |
|
|
// set length (loop variable)
|
| 7454 |
|
|
i_length = i_length + 1;
|
| 7455 |
|
|
// the number of frame transmitted
|
| 7456 |
|
|
num_of_frames = num_of_frames + 1;
|
| 7457 |
|
|
if (/*(num_of_frames == 2) || (num_of_frames == 4) || (num_of_frames == 7) ||*/ (num_of_frames <= 10) ||
|
| 7458 |
|
|
(num_of_frames == 14) || (num_of_frames == 18) || (num_of_frames == 23) || (num_of_frames == 28) ||
|
| 7459 |
|
|
(num_of_frames == 34) || (num_of_frames == 40) || (num_of_frames == 47) ||
|
| 7460 |
|
|
(num_of_frames == 54) || (num_of_frames == 62))
|
| 7461 |
|
|
num_of_bd = 0;
|
| 7462 |
|
|
else
|
| 7463 |
|
|
num_of_bd = num_of_bd + 1;
|
| 7464 |
|
|
end
|
| 7465 |
|
|
// disable TX
|
| 7466 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 7467 |
209 |
tadejm |
wbm_write(`ETH_MODER, `ETH_MODER_FULLD | `ETH_MODER_PAD | `ETH_MODER_CRCEN,
|
| 7468 |
|
|
4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 7469 |
|
|
@(posedge wb_clk);
|
| 7470 |
|
|
if(fail == 0)
|
| 7471 |
|
|
test_ok;
|
| 7472 |
|
|
else
|
| 7473 |
|
|
fail = 0;
|
| 7474 |
|
|
end
|
| 7475 |
|
|
|
| 7476 |
|
|
|
| 7477 |
|
|
////////////////////////////////////////////////////////////////////
|
| 7478 |
|
|
//// ////
|
| 7479 |
243 |
tadejm |
//// Test transmit packets (no pads) form 0 to (MINFL - 1) ////
|
| 7480 |
209 |
tadejm |
//// sizes at 8 TX buffer decriptors ( 100Mbps ). ////
|
| 7481 |
|
|
//// ////
|
| 7482 |
|
|
////////////////////////////////////////////////////////////////////
|
| 7483 |
|
|
if (test_num == 9) //
|
| 7484 |
|
|
begin
|
| 7485 |
243 |
tadejm |
// TEST 9: TRANSMIT PACKETS (NO PADs) FROM 0 TO (MINFL - 1) SIZES AT 8 TX BD ( 100Mbps )
|
| 7486 |
|
|
test_name = "TEST 9: TRANSMIT PACKETS (NO PADs) FROM 0 TO (MINFL - 1) SIZES AT 8 TX BD ( 100Mbps )";
|
| 7487 |
|
|
`TIME; $display(" TEST 9: TRANSMIT PACKETS (NO PADs) FROM 0 TO (MINFL - 1) SIZES AT 8 TX BD ( 100Mbps )");
|
| 7488 |
209 |
tadejm |
|
| 7489 |
|
|
// reset MAC registers
|
| 7490 |
|
|
hard_reset;
|
| 7491 |
|
|
// reset MAC and MII LOGIC with soft reset
|
| 7492 |
274 |
tadejm |
// reset_mac;
|
| 7493 |
|
|
// reset_mii;
|
| 7494 |
209 |
tadejm |
// set wb slave response
|
| 7495 |
|
|
wb_slave.cycle_response(`ACK_RESPONSE, wbs_waits, wbs_retries);
|
| 7496 |
|
|
|
| 7497 |
|
|
max_tmp = 0;
|
| 7498 |
|
|
min_tmp = 0;
|
| 7499 |
|
|
// set 8 TX buffer descriptors - must be set before TX enable
|
| 7500 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 7501 |
209 |
tadejm |
wbm_write(`ETH_TX_BD_NUM, 32'h8, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 7502 |
|
|
// enable TX, set full-duplex mode, padding and CRC appending
|
| 7503 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 7504 |
209 |
tadejm |
wbm_write(`ETH_MODER, `ETH_MODER_TXEN | `ETH_MODER_PAD | `ETH_MODER_FULLD | `ETH_MODER_CRCEN,
|
| 7505 |
|
|
4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 7506 |
|
|
// prepare two packets of MAXFL length
|
| 7507 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 7508 |
209 |
tadejm |
wbm_read(`ETH_PACKETLEN, tmp, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 7509 |
|
|
max_tmp = tmp[15:0]; // 18 bytes consists of 6B dest addr, 6B source addr, 2B type/len, 4B CRC
|
| 7510 |
|
|
min_tmp = tmp[31:16];
|
| 7511 |
|
|
st_data = 8'h12;
|
| 7512 |
|
|
set_tx_packet(`MEMORY_BASE, (max_tmp - 4), st_data); // length without CRC
|
| 7513 |
|
|
st_data = 8'h34;
|
| 7514 |
|
|
set_tx_packet((`MEMORY_BASE + max_tmp), (max_tmp - 4), st_data); // length without CRC
|
| 7515 |
|
|
// check WB INT signal
|
| 7516 |
|
|
if (wb_int !== 1'b0)
|
| 7517 |
|
|
begin
|
| 7518 |
|
|
test_fail("WB INT signal should not be set");
|
| 7519 |
|
|
fail = fail + 1;
|
| 7520 |
|
|
end
|
| 7521 |
|
|
|
| 7522 |
|
|
// write to phy's control register for 100Mbps
|
| 7523 |
|
|
#Tp eth_phy.control_bit14_10 = 5'b01000; // bit 13 set - speed 100
|
| 7524 |
|
|
#Tp eth_phy.control_bit8_0 = 9'h1_00; // bit 6 reset - (10/100), bit 8 set - FD
|
| 7525 |
|
|
speed = 100;
|
| 7526 |
|
|
|
| 7527 |
|
|
frame_started = 0;
|
| 7528 |
|
|
num_of_frames = 0;
|
| 7529 |
|
|
num_of_bd = 0;
|
| 7530 |
|
|
i_length = 0; // 0;
|
| 7531 |
|
|
while (i_length < 70) // (min_tmp - 4))
|
| 7532 |
|
|
begin
|
| 7533 |
|
|
#1;
|
| 7534 |
|
|
// choose generating carrier sense and collision
|
| 7535 |
|
|
case (i_length[1:0])
|
| 7536 |
|
|
2'h0: // Interrupt is generated
|
| 7537 |
|
|
begin
|
| 7538 |
|
|
// Reset_tx_bd nable interrupt generation
|
| 7539 |
|
|
// unmask interrupts
|
| 7540 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 7541 |
209 |
tadejm |
wbm_write(`ETH_INT_MASK, `ETH_INT_TXB | `ETH_INT_TXE | `ETH_INT_RXB | `ETH_INT_RXE | `ETH_INT_BUSY |
|
| 7542 |
|
|
`ETH_INT_TXC | `ETH_INT_RXC, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 7543 |
|
|
// not detect carrier sense in FD and no collision
|
| 7544 |
|
|
eth_phy.carrier_sense_tx_fd_detect(0);
|
| 7545 |
|
|
eth_phy.collision(0);
|
| 7546 |
|
|
end
|
| 7547 |
|
|
2'h1: // Interrupt is not generated
|
| 7548 |
|
|
begin
|
| 7549 |
|
|
// set_tx_bd enable interrupt generation
|
| 7550 |
|
|
// mask interrupts
|
| 7551 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 7552 |
209 |
tadejm |
wbm_write(`ETH_INT_MASK, 32'h0, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 7553 |
|
|
// detect carrier sense in FD and no collision
|
| 7554 |
|
|
eth_phy.carrier_sense_tx_fd_detect(1);
|
| 7555 |
|
|
eth_phy.collision(0);
|
| 7556 |
|
|
end
|
| 7557 |
|
|
2'h2: // Interrupt is not generated
|
| 7558 |
|
|
begin
|
| 7559 |
|
|
// set_tx_bd disable the interrupt generation
|
| 7560 |
|
|
// unmask interrupts
|
| 7561 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 7562 |
209 |
tadejm |
wbm_write(`ETH_INT_MASK, `ETH_INT_TXB | `ETH_INT_TXE | `ETH_INT_RXB | `ETH_INT_RXE | `ETH_INT_BUSY |
|
| 7563 |
|
|
`ETH_INT_TXC | `ETH_INT_RXC, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 7564 |
|
|
// not detect carrier sense in FD and set collision
|
| 7565 |
|
|
eth_phy.carrier_sense_tx_fd_detect(0);
|
| 7566 |
|
|
eth_phy.collision(1);
|
| 7567 |
|
|
end
|
| 7568 |
|
|
default: // 2'h3: // Interrupt is not generated
|
| 7569 |
|
|
begin
|
| 7570 |
|
|
// set_tx_bd disable the interrupt generation
|
| 7571 |
|
|
// mask interrupts
|
| 7572 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 7573 |
209 |
tadejm |
wbm_write(`ETH_INT_MASK, 32'h0, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 7574 |
|
|
// detect carrier sense in FD and set collision
|
| 7575 |
|
|
eth_phy.carrier_sense_tx_fd_detect(1);
|
| 7576 |
|
|
eth_phy.collision(1);
|
| 7577 |
|
|
end
|
| 7578 |
|
|
endcase
|
| 7579 |
|
|
#1;
|
| 7580 |
|
|
// first destination address on ethernet PHY
|
| 7581 |
|
|
eth_phy.set_tx_mem_addr(num_of_frames * 16);
|
| 7582 |
|
|
// SET packets and wrap bit
|
| 7583 |
|
|
// num_of_frames <= 9 => wrap set to TX BD 0
|
| 7584 |
|
|
if (num_of_frames <= 9)
|
| 7585 |
|
|
begin
|
| 7586 |
|
|
tmp_len = i_length; // length of frame
|
| 7587 |
|
|
tmp_bd_num = 0; // TX BD number
|
| 7588 |
|
|
// if i_length[1] == 0 then enable interrupt generation otherwise disable it
|
| 7589 |
|
|
// if i_length[0] == 0 then base address is `MEMORY_BASE otherwise it is `MEMORY_BASE + max_tmp
|
| 7590 |
|
|
if (tmp_len[0] == 0)
|
| 7591 |
|
|
set_tx_bd(tmp_bd_num, tmp_bd_num, tmp_len, !tmp_len[1], 1'b1, 1'b1, `MEMORY_BASE);
|
| 7592 |
|
|
else
|
| 7593 |
|
|
set_tx_bd(tmp_bd_num, tmp_bd_num, tmp_len, !tmp_len[1], 1'b1, 1'b1, (`MEMORY_BASE + max_tmp));
|
| 7594 |
|
|
// set wrap bit
|
| 7595 |
|
|
set_tx_bd_wrap(0);
|
| 7596 |
|
|
end
|
| 7597 |
|
|
// 10 <= num_of_frames < 18 => wrap set to TX BD 3
|
| 7598 |
|
|
else if ((num_of_frames == 10) || (num_of_frames == 14))
|
| 7599 |
|
|
begin
|
| 7600 |
|
|
tmp_len = i_length; // length of frame
|
| 7601 |
|
|
tmp_bd_num = 0; // TX BD number
|
| 7602 |
|
|
while (tmp_bd_num < 4) //
|
| 7603 |
|
|
begin
|
| 7604 |
|
|
// if i_length[1] == 0 then enable interrupt generation otherwise disable it
|
| 7605 |
|
|
// if i_length[0] == 0 then base address is `MEMORY_BASE otherwise it is `MEMORY_BASE + max_tmp
|
| 7606 |
|
|
if (tmp_len[0] == 0)
|
| 7607 |
|
|
set_tx_bd(tmp_bd_num, tmp_bd_num, tmp_len, !tmp_len[1], 1'b1, 1'b1, `MEMORY_BASE);
|
| 7608 |
|
|
else
|
| 7609 |
|
|
set_tx_bd(tmp_bd_num, tmp_bd_num, tmp_len, !tmp_len[1], 1'b1, 1'b1, (`MEMORY_BASE + max_tmp));
|
| 7610 |
|
|
tmp_len = tmp_len + 1;
|
| 7611 |
|
|
// set TX BD number
|
| 7612 |
|
|
tmp_bd_num = tmp_bd_num + 1;
|
| 7613 |
|
|
end
|
| 7614 |
|
|
// set wrap bit
|
| 7615 |
|
|
set_tx_bd_wrap(3);
|
| 7616 |
|
|
end
|
| 7617 |
|
|
// 18 <= num_of_frames < 28 => wrap set to TX BD 4
|
| 7618 |
|
|
else if ((num_of_frames == 18) || (num_of_frames == 23))
|
| 7619 |
|
|
begin
|
| 7620 |
|
|
tmp_len = i_length; // length of frame
|
| 7621 |
|
|
tmp_bd_num = 0; // TX BD number
|
| 7622 |
|
|
while (tmp_bd_num < 5) //
|
| 7623 |
|
|
begin
|
| 7624 |
|
|
// if i_length[1] == 0 then enable interrupt generation otherwise disable it
|
| 7625 |
|
|
// if i_length[0] == 0 then base address is `MEMORY_BASE otherwise it is `MEMORY_BASE + max_tmp
|
| 7626 |
|
|
if (tmp_len[0] == 0)
|
| 7627 |
|
|
set_tx_bd(tmp_bd_num, tmp_bd_num, tmp_len, !tmp_len[1], 1'b1, 1'b1, `MEMORY_BASE);
|
| 7628 |
|
|
else
|
| 7629 |
|
|
set_tx_bd(tmp_bd_num, tmp_bd_num, tmp_len, !tmp_len[1], 1'b1, 1'b1, (`MEMORY_BASE + max_tmp));
|
| 7630 |
|
|
tmp_len = tmp_len + 1;
|
| 7631 |
|
|
// set TX BD number
|
| 7632 |
|
|
tmp_bd_num = tmp_bd_num + 1;
|
| 7633 |
|
|
end
|
| 7634 |
|
|
// set wrap bit
|
| 7635 |
|
|
set_tx_bd_wrap(4);
|
| 7636 |
|
|
end
|
| 7637 |
|
|
// 28 <= num_of_frames < 40 => wrap set to TX BD 5
|
| 7638 |
|
|
else if ((num_of_frames == 28) || (num_of_frames == 34))
|
| 7639 |
|
|
begin
|
| 7640 |
|
|
tmp_len = i_length; // length of frame
|
| 7641 |
|
|
tmp_bd_num = 0; // TX BD number
|
| 7642 |
|
|
while (tmp_bd_num < 6) //
|
| 7643 |
|
|
begin
|
| 7644 |
|
|
// if i_length[1] == 0 then enable interrupt generation otherwise disable it
|
| 7645 |
|
|
// if i_length[0] == 0 then base address is `MEMORY_BASE otherwise it is `MEMORY_BASE + max_tmp
|
| 7646 |
|
|
if (tmp_len[0] == 0)
|
| 7647 |
|
|
set_tx_bd(tmp_bd_num, tmp_bd_num, tmp_len, !tmp_len[1], 1'b1, 1'b1, `MEMORY_BASE);
|
| 7648 |
|
|
else
|
| 7649 |
|
|
set_tx_bd(tmp_bd_num, tmp_bd_num, tmp_len, !tmp_len[1], 1'b1, 1'b1, (`MEMORY_BASE + max_tmp));
|
| 7650 |
|
|
tmp_len = tmp_len + 1;
|
| 7651 |
|
|
// set TX BD number
|
| 7652 |
|
|
tmp_bd_num = tmp_bd_num + 1;
|
| 7653 |
|
|
end
|
| 7654 |
|
|
// set wrap bit
|
| 7655 |
|
|
set_tx_bd_wrap(5);
|
| 7656 |
|
|
end
|
| 7657 |
|
|
// 40 <= num_of_frames < 54 => wrap set to TX BD 6
|
| 7658 |
|
|
else if ((num_of_frames == 40) || (num_of_frames == 47))
|
| 7659 |
|
|
begin
|
| 7660 |
|
|
tmp_len = i_length; // length of frame
|
| 7661 |
|
|
tmp_bd_num = 0; // TX BD number
|
| 7662 |
|
|
while (tmp_bd_num < 7) //
|
| 7663 |
|
|
begin
|
| 7664 |
|
|
// if i_length[1] == 0 then enable interrupt generation otherwise disable it
|
| 7665 |
|
|
// if i_length[0] == 0 then base address is `MEMORY_BASE otherwise it is `MEMORY_BASE + max_tmp
|
| 7666 |
|
|
if (tmp_len[0] == 0)
|
| 7667 |
|
|
set_tx_bd(tmp_bd_num, tmp_bd_num, tmp_len, !tmp_len[1], 1'b1, 1'b1, `MEMORY_BASE);
|
| 7668 |
|
|
else
|
| 7669 |
|
|
set_tx_bd(tmp_bd_num, tmp_bd_num, tmp_len, !tmp_len[1], 1'b1, 1'b1, (`MEMORY_BASE + max_tmp));
|
| 7670 |
|
|
tmp_len = tmp_len + 1;
|
| 7671 |
|
|
// set TX BD number
|
| 7672 |
|
|
tmp_bd_num = tmp_bd_num + 1;
|
| 7673 |
|
|
end
|
| 7674 |
|
|
// set wrap bit
|
| 7675 |
|
|
set_tx_bd_wrap(6);
|
| 7676 |
|
|
end
|
| 7677 |
|
|
// 54 <= num_of_frames < 70 => wrap set to TX BD 7
|
| 7678 |
|
|
else if ((num_of_frames == 54) || (num_of_frames == 62))
|
| 7679 |
|
|
begin
|
| 7680 |
|
|
tmp_len = i_length; // length of frame
|
| 7681 |
|
|
tmp_bd_num = 0; // TX BD number
|
| 7682 |
|
|
while (tmp_bd_num < 8) //
|
| 7683 |
|
|
begin
|
| 7684 |
|
|
// if i_length[1] == 0 then enable interrupt generation otherwise disable it
|
| 7685 |
|
|
// if i_length[0] == 0 then base address is `MEMORY_BASE otherwise it is `MEMORY_BASE + max_tmp
|
| 7686 |
|
|
if (tmp_len[0] == 0)
|
| 7687 |
|
|
set_tx_bd(tmp_bd_num, tmp_bd_num, tmp_len, !tmp_len[1], 1'b1, 1'b1, `MEMORY_BASE);
|
| 7688 |
|
|
else
|
| 7689 |
|
|
set_tx_bd(tmp_bd_num, tmp_bd_num, tmp_len, !tmp_len[1], 1'b1, 1'b1, (`MEMORY_BASE + max_tmp));
|
| 7690 |
|
|
tmp_len = tmp_len + 1;
|
| 7691 |
|
|
// set TX BD number
|
| 7692 |
|
|
tmp_bd_num = tmp_bd_num + 1;
|
| 7693 |
|
|
end
|
| 7694 |
|
|
// set wrap bit
|
| 7695 |
|
|
set_tx_bd_wrap(7);
|
| 7696 |
|
|
end
|
| 7697 |
|
|
#1;
|
| 7698 |
|
|
// SET ready bit
|
| 7699 |
|
|
if (num_of_frames < 10)
|
| 7700 |
|
|
set_tx_bd_ready(0, 0);
|
| 7701 |
|
|
else if (num_of_frames < 14)
|
| 7702 |
|
|
set_tx_bd_ready((num_of_frames - 10), (num_of_frames - 10));
|
| 7703 |
|
|
else if (num_of_frames < 18)
|
| 7704 |
|
|
set_tx_bd_ready((num_of_frames - 14), (num_of_frames - 14));
|
| 7705 |
|
|
else if (num_of_frames < 23)
|
| 7706 |
|
|
set_tx_bd_ready((num_of_frames - 18), (num_of_frames - 18));
|
| 7707 |
|
|
else if (num_of_frames < 28)
|
| 7708 |
|
|
set_tx_bd_ready((num_of_frames - 23), (num_of_frames - 23));
|
| 7709 |
|
|
else if (num_of_frames < 34)
|
| 7710 |
|
|
set_tx_bd_ready((num_of_frames - 28), (num_of_frames - 28));
|
| 7711 |
|
|
else if (num_of_frames < 40)
|
| 7712 |
|
|
set_tx_bd_ready((num_of_frames - 34), (num_of_frames - 34));
|
| 7713 |
|
|
else if (num_of_frames < 47)
|
| 7714 |
|
|
set_tx_bd_ready((num_of_frames - 40), (num_of_frames - 40));
|
| 7715 |
|
|
else if (num_of_frames < 54)
|
| 7716 |
|
|
set_tx_bd_ready((num_of_frames - 47), (num_of_frames - 47));
|
| 7717 |
|
|
else if (num_of_frames < 62)
|
| 7718 |
|
|
set_tx_bd_ready((num_of_frames - 54), (num_of_frames - 54));
|
| 7719 |
|
|
else if (num_of_frames < 70)
|
| 7720 |
|
|
set_tx_bd_ready((num_of_frames - 62), (num_of_frames - 62));
|
| 7721 |
|
|
// CHECK END OF TRANSMITION
|
| 7722 |
|
|
frame_started = 0;
|
| 7723 |
|
|
if (num_of_frames >= 5)
|
| 7724 |
|
|
#1 check_tx_bd(num_of_bd, data);
|
| 7725 |
|
|
fork
|
| 7726 |
|
|
begin: fr_st3
|
| 7727 |
|
|
wait (MTxEn === 1'b1); // start transmit
|
| 7728 |
|
|
frame_started = 1;
|
| 7729 |
|
|
end
|
| 7730 |
|
|
begin
|
| 7731 |
|
|
repeat (30) @(posedge mtx_clk);
|
| 7732 |
|
|
if (num_of_frames < 5)
|
| 7733 |
|
|
begin
|
| 7734 |
|
|
if (frame_started == 1)
|
| 7735 |
|
|
begin
|
| 7736 |
|
|
`TIME; $display("*E Frame should NOT start!");
|
| 7737 |
|
|
end
|
| 7738 |
|
|
disable fr_st3;
|
| 7739 |
|
|
end
|
| 7740 |
|
|
else
|
| 7741 |
|
|
begin
|
| 7742 |
|
|
if (frame_started == 0)
|
| 7743 |
|
|
begin
|
| 7744 |
|
|
`TIME; $display("*W Frame should start!");
|
| 7745 |
|
|
disable fr_st3;
|
| 7746 |
|
|
end
|
| 7747 |
|
|
end
|
| 7748 |
|
|
end
|
| 7749 |
|
|
join
|
| 7750 |
|
|
// check packets larger than 4 bytes
|
| 7751 |
|
|
if (num_of_frames >= 5)
|
| 7752 |
|
|
begin
|
| 7753 |
|
|
wait (MTxEn === 1'b0); // end transmit
|
| 7754 |
|
|
while (data[15] === 1)
|
| 7755 |
|
|
begin
|
| 7756 |
|
|
#1 check_tx_bd(num_of_bd, data);
|
| 7757 |
|
|
@(posedge wb_clk);
|
| 7758 |
|
|
end
|
| 7759 |
|
|
repeat (1) @(posedge wb_clk);
|
| 7760 |
|
|
// check length of a PACKET
|
| 7761 |
|
|
if (eth_phy.tx_len != (i_length + 4))
|
| 7762 |
|
|
begin
|
| 7763 |
|
|
`TIME; $display("*E Wrong length of the packet out from MAC");
|
| 7764 |
|
|
test_fail("Wrong length of the packet out from MAC");
|
| 7765 |
|
|
fail = fail + 1;
|
| 7766 |
|
|
end
|
| 7767 |
|
|
// check transmitted TX packet data
|
| 7768 |
|
|
if (i_length[0] == 0)
|
| 7769 |
|
|
begin
|
| 7770 |
|
|
#1 check_tx_packet(`MEMORY_BASE, (num_of_frames * 16), i_length, tmp);
|
| 7771 |
|
|
end
|
| 7772 |
|
|
else
|
| 7773 |
|
|
begin
|
| 7774 |
|
|
#1 check_tx_packet((`MEMORY_BASE + max_tmp), (num_of_frames * 16), i_length, tmp);
|
| 7775 |
|
|
end
|
| 7776 |
|
|
if (tmp > 0)
|
| 7777 |
|
|
begin
|
| 7778 |
|
|
test_fail("Wrong data of the transmitted packet");
|
| 7779 |
|
|
fail = fail + 1;
|
| 7780 |
|
|
end
|
| 7781 |
|
|
// check transmited TX packet CRC
|
| 7782 |
|
|
#1 check_tx_crc((num_of_frames * 16), (eth_phy.tx_len - 4), 1'b0, tmp); // length without CRC
|
| 7783 |
|
|
if (tmp > 0)
|
| 7784 |
|
|
begin
|
| 7785 |
|
|
test_fail("Wrong CRC of the transmitted packet");
|
| 7786 |
|
|
fail = fail + 1;
|
| 7787 |
|
|
end
|
| 7788 |
|
|
end
|
| 7789 |
|
|
// check WB INT signal
|
| 7790 |
|
|
if ((i_length[1:0] == 2'h0) && (num_of_frames >= 5))
|
| 7791 |
|
|
begin
|
| 7792 |
|
|
if (wb_int !== 1'b1)
|
| 7793 |
|
|
begin
|
| 7794 |
|
|
`TIME; $display("*E WB INT signal should be set");
|
| 7795 |
|
|
test_fail("WB INT signal should be set");
|
| 7796 |
|
|
fail = fail + 1;
|
| 7797 |
|
|
end
|
| 7798 |
|
|
end
|
| 7799 |
|
|
else
|
| 7800 |
|
|
begin
|
| 7801 |
|
|
if (wb_int !== 1'b0)
|
| 7802 |
|
|
begin
|
| 7803 |
|
|
`TIME; $display("*E WB INT signal should not be set");
|
| 7804 |
|
|
test_fail("WB INT signal should not be set");
|
| 7805 |
|
|
fail = fail + 1;
|
| 7806 |
|
|
end
|
| 7807 |
|
|
end
|
| 7808 |
|
|
// check TX buffer descriptor of a packet
|
| 7809 |
|
|
check_tx_bd(num_of_bd, data);
|
| 7810 |
|
|
if (num_of_frames >= 5)
|
| 7811 |
|
|
begin
|
| 7812 |
|
|
if (i_length[1] == 1'b0) // interrupt enabled
|
| 7813 |
|
|
begin
|
| 7814 |
|
|
if ( (data[15:0] !== 16'h7800) && // wrap bit
|
| 7815 |
|
|
(data[15:0] !== 16'h5800) ) // without wrap bit
|
| 7816 |
|
|
begin
|
| 7817 |
|
|
`TIME; $display("*E TX buffer descriptor status is not correct: %0h", data[15:0]);
|
| 7818 |
|
|
test_fail("TX buffer descriptor status is not correct");
|
| 7819 |
|
|
fail = fail + 1;
|
| 7820 |
|
|
end
|
| 7821 |
|
|
end
|
| 7822 |
|
|
else // interrupt not enabled
|
| 7823 |
|
|
begin
|
| 7824 |
|
|
if ( (data[15:0] !== 16'h3800) && // wrap bit
|
| 7825 |
|
|
(data[15:0] !== 16'h1800) ) // without wrap bit
|
| 7826 |
|
|
begin
|
| 7827 |
|
|
`TIME; $display("*E TX buffer descriptor status is not correct: %0h", data[15:0]);
|
| 7828 |
|
|
test_fail("TX buffer descriptor status is not correct");
|
| 7829 |
|
|
fail = fail + 1;
|
| 7830 |
|
|
end
|
| 7831 |
|
|
end
|
| 7832 |
|
|
end
|
| 7833 |
|
|
else
|
| 7834 |
|
|
begin
|
| 7835 |
|
|
if (data[15] !== 1'b1)
|
| 7836 |
|
|
begin
|
| 7837 |
|
|
`TIME; $display("*E TX buffer descriptor status is not correct: %0h", data[15:0]);
|
| 7838 |
|
|
test_fail("TX buffer descriptor status is not correct");
|
| 7839 |
|
|
fail = fail + 1;
|
| 7840 |
|
|
end
|
| 7841 |
|
|
end
|
| 7842 |
|
|
// clear TX BD with wrap bit
|
| 7843 |
|
|
if (num_of_frames == 63)
|
| 7844 |
|
|
clear_tx_bd(16, 16);
|
| 7845 |
|
|
// check interrupts
|
| 7846 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 7847 |
209 |
tadejm |
wbm_read(`ETH_INT, data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 7848 |
|
|
if ( ((i_length[1:0] == 2'h0) || (i_length[1:0] == 2'h1)) && (num_of_frames >= 5) )
|
| 7849 |
|
|
begin
|
| 7850 |
|
|
if ((data & `ETH_INT_TXB) !== 1'b1)
|
| 7851 |
|
|
begin
|
| 7852 |
|
|
`TIME; $display("*E Interrupt Transmit Buffer was not set, interrupt reg: %0h", data);
|
| 7853 |
|
|
test_fail("Interrupt Transmit Buffer was not set");
|
| 7854 |
|
|
fail = fail + 1;
|
| 7855 |
|
|
end
|
| 7856 |
|
|
if ((data & (~`ETH_INT_TXB)) !== 0)
|
| 7857 |
|
|
begin
|
| 7858 |
|
|
`TIME; $display("*E Other interrupts (except Transmit Buffer) were set, interrupt reg: %0h", data);
|
| 7859 |
|
|
test_fail("Other interrupts (except Transmit Buffer) were set");
|
| 7860 |
|
|
fail = fail + 1;
|
| 7861 |
|
|
end
|
| 7862 |
|
|
end
|
| 7863 |
|
|
else
|
| 7864 |
|
|
begin
|
| 7865 |
|
|
if (data !== 0)
|
| 7866 |
|
|
begin
|
| 7867 |
|
|
`TIME; $display("*E Any of interrupts (except Transmit Buffer) was set, interrupt reg: %0h, len: %0h", data, i_length[1:0]);
|
| 7868 |
|
|
test_fail("Any of interrupts (except Transmit Buffer) was set");
|
| 7869 |
|
|
fail = fail + 1;
|
| 7870 |
|
|
end
|
| 7871 |
|
|
end
|
| 7872 |
|
|
// clear interrupts
|
| 7873 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 7874 |
209 |
tadejm |
wbm_write(`ETH_INT, data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 7875 |
|
|
// check WB INT signal
|
| 7876 |
|
|
if (wb_int !== 1'b0)
|
| 7877 |
|
|
begin
|
| 7878 |
|
|
test_fail("WB INT signal should not be set");
|
| 7879 |
|
|
fail = fail + 1;
|
| 7880 |
|
|
end
|
| 7881 |
|
|
// INTERMEDIATE DISPLAYS
|
| 7882 |
|
|
if (i_length == 3)
|
| 7883 |
|
|
begin
|
| 7884 |
|
|
$display(" pads appending to packets is selected");
|
| 7885 |
|
|
$display(" using 1 BD out of 8 BDs assigned to TX (wrap at 1st BD - TX BD 0)");
|
| 7886 |
|
|
$display(" ->packets with lengths from %0d to %0d are not transmitted (length increasing by 1 byte)",
|
| 7887 |
|
|
0, 3);
|
| 7888 |
|
|
end
|
| 7889 |
|
|
else if (i_length == 9)
|
| 7890 |
|
|
begin
|
| 7891 |
|
|
$display(" using 1 BD out of 8 BDs assigned to TX (wrap at 1st BD - TX BD 0)");
|
| 7892 |
|
|
$display(" ->packet with length 4 is not transmitted (length increasing by 1 byte)");
|
| 7893 |
|
|
$display(" ->packets with lengths from %0d to %0d are checked (length increasing by 1 byte)",
|
| 7894 |
|
|
5, 9);
|
| 7895 |
|
|
end
|
| 7896 |
|
|
else if (i_length == 17)
|
| 7897 |
|
|
begin
|
| 7898 |
|
|
$display(" using 4 BDs out of 8 BDs assigned to TX (wrap at 4th BD - TX BD 3)");
|
| 7899 |
|
|
$display(" ->packets with lengths from %0d to %0d are checked (length increasing by 1 byte)",
|
| 7900 |
|
|
10, 17);
|
| 7901 |
|
|
end
|
| 7902 |
|
|
else if (i_length == 27)
|
| 7903 |
|
|
begin
|
| 7904 |
|
|
$display(" using 5 BDs out of 8 BDs assigned to TX (wrap at 5th BD - TX BD 4)");
|
| 7905 |
|
|
$display(" ->packets with lengths from %0d to %0d are checked (length increasing by 1 byte)",
|
| 7906 |
|
|
18, 27);
|
| 7907 |
|
|
end
|
| 7908 |
|
|
else if (i_length == 40)
|
| 7909 |
|
|
begin
|
| 7910 |
|
|
$display(" using 6 BDs out of 8 BDs assigned to TX (wrap at 6th BD - TX BD 5)");
|
| 7911 |
|
|
$display(" ->packets with lengths from %0d to %0d are checked (length increasing by 1 byte)",
|
| 7912 |
|
|
28, 40);
|
| 7913 |
|
|
end
|
| 7914 |
|
|
else if (i_length == 54)
|
| 7915 |
|
|
begin
|
| 7916 |
|
|
$display(" using 7 BDs out of 8 BDs assigned to TX (wrap at 7th BD - TX BD 6)");
|
| 7917 |
|
|
$display(" ->packets with lengths from %0d to %0d are checked (length increasing by 1 byte)",
|
| 7918 |
|
|
41, 54);
|
| 7919 |
|
|
end
|
| 7920 |
|
|
else if (i_length == 69)
|
| 7921 |
|
|
begin
|
| 7922 |
|
|
$display(" using 8 BDs out of 8 BDs assigned to TX (wrap at 8th BD - TX BD 7)");
|
| 7923 |
|
|
$display(" ->packets with lengths from %0d to %0d are checked (length increasing by 1 byte)",
|
| 7924 |
|
|
55, 69);
|
| 7925 |
|
|
end
|
| 7926 |
|
|
// set length (loop variable)
|
| 7927 |
|
|
i_length = i_length + 1;
|
| 7928 |
|
|
// the number of frame transmitted
|
| 7929 |
|
|
num_of_frames = num_of_frames + 1;
|
| 7930 |
|
|
if (/*(num_of_frames == 2) || (num_of_frames == 4) || (num_of_frames == 7) ||*/ (num_of_frames <= 10) ||
|
| 7931 |
|
|
(num_of_frames == 14) || (num_of_frames == 18) || (num_of_frames == 23) || (num_of_frames == 28) ||
|
| 7932 |
|
|
(num_of_frames == 34) || (num_of_frames == 40) || (num_of_frames == 47) ||
|
| 7933 |
|
|
(num_of_frames == 54) || (num_of_frames == 62))
|
| 7934 |
|
|
num_of_bd = 0;
|
| 7935 |
|
|
else
|
| 7936 |
|
|
num_of_bd = num_of_bd + 1;
|
| 7937 |
|
|
end
|
| 7938 |
|
|
// disable TX
|
| 7939 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 7940 |
209 |
tadejm |
wbm_write(`ETH_MODER, `ETH_MODER_FULLD | `ETH_MODER_PAD | `ETH_MODER_CRCEN,
|
| 7941 |
|
|
4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 7942 |
|
|
@(posedge wb_clk);
|
| 7943 |
|
|
if(fail == 0)
|
| 7944 |
|
|
test_ok;
|
| 7945 |
|
|
else
|
| 7946 |
|
|
fail = 0;
|
| 7947 |
|
|
end
|
| 7948 |
|
|
|
| 7949 |
|
|
|
| 7950 |
|
|
////////////////////////////////////////////////////////////////////
|
| 7951 |
|
|
//// ////
|
| 7952 |
|
|
//// Test transmit packets across MAXFL value at ////
|
| 7953 |
|
|
//// 13 TX buffer decriptors ( 10Mbps ). ////
|
| 7954 |
|
|
//// ////
|
| 7955 |
|
|
////////////////////////////////////////////////////////////////////
|
| 7956 |
|
|
if (test_num == 10) // without and with padding
|
| 7957 |
|
|
begin
|
| 7958 |
|
|
// TEST 10: TRANSMIT PACKETS ACROSS MAXFL VALUE AT 13 TX BDs ( 10Mbps )
|
| 7959 |
|
|
test_name = "TEST 10: TRANSMIT PACKETS ACROSS MAXFL VALUE AT 13 TX BDs ( 10Mbps )";
|
| 7960 |
|
|
`TIME; $display(" TEST 10: TRANSMIT PACKETS ACROSS MAXFL VALUE AT 13 TX BDs ( 10Mbps )");
|
| 7961 |
|
|
|
| 7962 |
|
|
// reset MAC registers
|
| 7963 |
|
|
hard_reset;
|
| 7964 |
|
|
// reset MAC and MII LOGIC with soft reset
|
| 7965 |
274 |
tadejm |
// reset_mac;
|
| 7966 |
|
|
// reset_mii;
|
| 7967 |
209 |
tadejm |
// set wb slave response
|
| 7968 |
|
|
wb_slave.cycle_response(`ACK_RESPONSE, wbs_waits, wbs_retries);
|
| 7969 |
|
|
|
| 7970 |
|
|
max_tmp = 0;
|
| 7971 |
|
|
min_tmp = 0;
|
| 7972 |
|
|
num_of_frames = 0;
|
| 7973 |
|
|
num_of_bd = 0;
|
| 7974 |
|
|
// set 13 TX buffer descriptors - must be set before TX enable
|
| 7975 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 7976 |
209 |
tadejm |
wbm_write(`ETH_TX_BD_NUM, 32'hD, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 7977 |
|
|
// enable TX, set full-duplex mode, NO padding and CRC appending
|
| 7978 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 7979 |
209 |
tadejm |
wbm_write(`ETH_MODER, `ETH_MODER_TXEN | `ETH_MODER_FULLD | `ETH_MODER_CRCEN,
|
| 7980 |
|
|
4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 7981 |
|
|
// prepare a packet of MAXFL + 10 length
|
| 7982 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 7983 |
209 |
tadejm |
wbm_read(`ETH_PACKETLEN, tmp, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 7984 |
|
|
max_tmp = tmp[15:0]; // 18 bytes consists of 6B dest addr, 6B source addr, 2B type/len, 4B CRC
|
| 7985 |
|
|
min_tmp = tmp[31:16];
|
| 7986 |
|
|
st_data = 8'hA3;
|
| 7987 |
|
|
set_tx_packet(`MEMORY_BASE, (max_tmp + 10), st_data); // length without CRC
|
| 7988 |
|
|
// check WB INT signal
|
| 7989 |
|
|
if (wb_int !== 1'b0)
|
| 7990 |
|
|
begin
|
| 7991 |
|
|
test_fail("WB INT signal should not be set");
|
| 7992 |
|
|
fail = fail + 1;
|
| 7993 |
|
|
end
|
| 7994 |
|
|
|
| 7995 |
|
|
// write to phy's control register for 10Mbps
|
| 7996 |
|
|
#Tp eth_phy.control_bit14_10 = 5'b00000; // bit 13 reset - speed 10
|
| 7997 |
|
|
#Tp eth_phy.control_bit8_0 = 9'h1_00; // bit 6 reset - (10/100), bit 8 set - FD
|
| 7998 |
|
|
speed = 10;
|
| 7999 |
|
|
|
| 8000 |
|
|
i_length = (max_tmp - 5);
|
| 8001 |
|
|
while (i_length <= (max_tmp - 3)) // (max_tmp - 4) is the limit
|
| 8002 |
|
|
begin
|
| 8003 |
|
|
$display(" i_length = %0d", i_length);
|
| 8004 |
|
|
// choose generating carrier sense and collision
|
| 8005 |
|
|
// case (i_length[1:0])
|
| 8006 |
|
|
// 2'h0: // Interrupt is generated
|
| 8007 |
|
|
// begin
|
| 8008 |
|
|
// Reset_tx_bd nable interrupt generation
|
| 8009 |
|
|
// unmask interrupts
|
| 8010 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 8011 |
209 |
tadejm |
wbm_write(`ETH_INT_MASK, `ETH_INT_TXB | `ETH_INT_TXE | `ETH_INT_RXB | `ETH_INT_RXE | `ETH_INT_BUSY |
|
| 8012 |
|
|
`ETH_INT_TXC | `ETH_INT_RXC, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 8013 |
|
|
// not detect carrier sense in FD and no collision
|
| 8014 |
|
|
eth_phy.carrier_sense_tx_fd_detect(0);
|
| 8015 |
|
|
eth_phy.collision(0);
|
| 8016 |
|
|
// end
|
| 8017 |
|
|
// 2'h1: // Interrupt is not generated
|
| 8018 |
|
|
// begin
|
| 8019 |
|
|
// set_tx_bd enable interrupt generation
|
| 8020 |
|
|
// mask interrupts
|
| 8021 |
274 |
tadejm |
// wait (wbm_working == 0);
|
| 8022 |
209 |
tadejm |
// wbm_write(`ETH_INT_MASK, 32'h0, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 8023 |
|
|
// detect carrier sense in FD and no collision
|
| 8024 |
|
|
// eth_phy.carrier_sense_tx_fd_detect(1);
|
| 8025 |
|
|
// eth_phy.collision(0);
|
| 8026 |
|
|
// end
|
| 8027 |
|
|
// 2'h2: // Interrupt is not generated
|
| 8028 |
|
|
// begin
|
| 8029 |
|
|
// set_tx_bd disable the interrupt generation
|
| 8030 |
|
|
// unmask interrupts
|
| 8031 |
274 |
tadejm |
// wait (wbm_working == 0);
|
| 8032 |
209 |
tadejm |
// wbm_write(`ETH_INT_MASK, `ETH_INT_TXB | `ETH_INT_TXE | `ETH_INT_RXB | `ETH_INT_RXE | `ETH_INT_BUSY |
|
| 8033 |
|
|
// `ETH_INT_TXC | `ETH_INT_RXC, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 8034 |
|
|
// not detect carrier sense in FD and set collision
|
| 8035 |
|
|
// eth_phy.carrier_sense_tx_fd_detect(0);
|
| 8036 |
|
|
// eth_phy.collision(1);
|
| 8037 |
|
|
// end
|
| 8038 |
|
|
// default: // 2'h3: // Interrupt is not generated
|
| 8039 |
|
|
// begin
|
| 8040 |
|
|
// set_tx_bd disable the interrupt generation
|
| 8041 |
|
|
// mask interrupts
|
| 8042 |
274 |
tadejm |
// wait (wbm_working == 0);
|
| 8043 |
209 |
tadejm |
// wbm_write(`ETH_INT_MASK, 32'h0, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 8044 |
|
|
// detect carrier sense in FD and set collision
|
| 8045 |
|
|
// eth_phy.carrier_sense_tx_fd_detect(1);
|
| 8046 |
|
|
// eth_phy.collision(1);
|
| 8047 |
|
|
// end
|
| 8048 |
|
|
// endcase
|
| 8049 |
|
|
// first destination address on ethernet PHY
|
| 8050 |
|
|
eth_phy.set_tx_mem_addr(0);
|
| 8051 |
|
|
//
|
| 8052 |
|
|
if (num_of_bd == 0)
|
| 8053 |
|
|
begin
|
| 8054 |
|
|
set_tx_bd(0, 0, i_length, 1'b1, 1'b1, 1'b1, `MEMORY_BASE);
|
| 8055 |
|
|
set_tx_bd(1, 1, i_length+1, 1'b1, 1'b1, 1'b1, `MEMORY_BASE);
|
| 8056 |
|
|
set_tx_bd(2, 2, i_length+2, 1'b1, 1'b1, 1'b1, `MEMORY_BASE);
|
| 8057 |
|
|
set_tx_bd_wrap(2);
|
| 8058 |
|
|
set_tx_bd_ready(0, 0);
|
| 8059 |
|
|
end
|
| 8060 |
|
|
else if (num_of_bd == 1)
|
| 8061 |
|
|
set_tx_bd_ready(1, 1);
|
| 8062 |
|
|
else if (num_of_bd == 2)
|
| 8063 |
|
|
set_tx_bd_ready(2, 2);
|
| 8064 |
|
|
|
| 8065 |
|
|
|
| 8066 |
|
|
// tmp_len = i_length; // length of frame
|
| 8067 |
|
|
// tmp_bd_num = 0; // TX BD number
|
| 8068 |
|
|
// while (tmp_bd_num < 8) //
|
| 8069 |
|
|
// begin
|
| 8070 |
|
|
// // if i_length[1] == 0 then enable interrupt generation otherwise disable it
|
| 8071 |
|
|
// // if i_length[0] == 0 then base address is `MEMORY_BASE otherwise it is `MEMORY_BASE + max_tmp
|
| 8072 |
|
|
// if (tmp_len[0] == 0)
|
| 8073 |
|
|
// set_tx_bd(tmp_bd_num, tmp_bd_num, tmp_len, !tmp_len[1], 1'b1, 1'b1, `MEMORY_BASE);
|
| 8074 |
|
|
// else
|
| 8075 |
|
|
// set_tx_bd(tmp_bd_num, tmp_bd_num, tmp_len, !tmp_len[1], 1'b1, 1'b1, (`MEMORY_BASE + 2*max_tmp));
|
| 8076 |
|
|
// // set length (loop variable) - THE SAME AS AT THE END OF THIS TASK !!!
|
| 8077 |
|
|
// tmp_len = tmp_len + 1;
|
| 8078 |
|
|
// // set TX BD number
|
| 8079 |
|
|
// tmp_bd_num = tmp_bd_num + 1;
|
| 8080 |
|
|
// end
|
| 8081 |
|
|
// // set wrap bit
|
| 8082 |
|
|
// set_tx_bd_wrap(7);
|
| 8083 |
|
|
// // set ready bit
|
| 8084 |
|
|
// set_tx_bd_ready((i_length - (max_tmp - 8)), (i_length - (max_tmp - 8)));
|
| 8085 |
|
|
// CHECK END OF TRANSMITION
|
| 8086 |
|
|
check_tx_bd(num_of_bd, data);
|
| 8087 |
|
|
// #1 check_tx_bd((i_length - (max_tmp - 8)), data);
|
| 8088 |
|
|
wait (MTxEn === 1'b1); // start transmit
|
| 8089 |
|
|
check_tx_bd(num_of_bd, data);
|
| 8090 |
|
|
// #1 check_tx_bd((i_length - (max_tmp - 8)), data);
|
| 8091 |
|
|
if (data[15] !== 1)
|
| 8092 |
|
|
begin
|
| 8093 |
|
|
test_fail("Wrong buffer descriptor's ready bit read out from MAC");
|
| 8094 |
|
|
fail = fail + 1;
|
| 8095 |
|
|
end
|
| 8096 |
|
|
wait (MTxEn === 1'b0); // end transmit
|
| 8097 |
|
|
while (data[15] === 1)
|
| 8098 |
|
|
begin
|
| 8099 |
|
|
check_tx_bd(num_of_bd, data);
|
| 8100 |
|
|
// #1 check_tx_bd((i_length - (max_tmp - 8)), data);
|
| 8101 |
|
|
@(posedge wb_clk);
|
| 8102 |
|
|
end
|
| 8103 |
|
|
repeat (1) @(posedge wb_clk);
|
| 8104 |
|
|
// check length of a PACKET
|
| 8105 |
|
|
$display(" eth_phy length = %0d", eth_phy.tx_len);
|
| 8106 |
|
|
tmp_len = eth_phy.tx_len;
|
| 8107 |
|
|
#1;
|
| 8108 |
|
|
if (tmp_len != (i_length + 4))
|
| 8109 |
|
|
// if (eth_phy.tx_len != (i_length + 4))
|
| 8110 |
|
|
begin
|
| 8111 |
|
|
test_fail("Wrong length of the packet out from MAC");
|
| 8112 |
|
|
fail = fail + 1;
|
| 8113 |
|
|
end
|
| 8114 |
|
|
// checking in the following if statement is performed only for first and last 64 lengths
|
| 8115 |
|
|
// if ( ((i_length + 4) <= (min_tmp + 64)) || ((i_length + 4) > (max_tmp - 64)) )
|
| 8116 |
|
|
// begin
|
| 8117 |
|
|
// check transmitted TX packet data
|
| 8118 |
|
|
// if (i_length[0] == 0)
|
| 8119 |
|
|
// begin
|
| 8120 |
|
|
check_tx_packet(`MEMORY_BASE, 0, i_length, tmp);
|
| 8121 |
|
|
// end
|
| 8122 |
|
|
// else
|
| 8123 |
|
|
// begin
|
| 8124 |
|
|
// check_tx_packet((`MEMORY_BASE + 2*max_tmp), 0, i_length, tmp);
|
| 8125 |
|
|
// end
|
| 8126 |
|
|
if (tmp > 0)
|
| 8127 |
|
|
begin
|
| 8128 |
|
|
test_fail("Wrong data of the transmitted packet");
|
| 8129 |
|
|
fail = fail + 1;
|
| 8130 |
|
|
end
|
| 8131 |
|
|
// check transmited TX packet CRC
|
| 8132 |
|
|
// if (i_length[0] == 0)
|
| 8133 |
|
|
check_tx_crc(0, i_length, 1'b0, tmp); // length without CRC
|
| 8134 |
|
|
// else
|
| 8135 |
|
|
// check_tx_crc(0, i_length, 1'b0, tmp); // length without CRC
|
| 8136 |
|
|
if (tmp > 0)
|
| 8137 |
|
|
begin
|
| 8138 |
|
|
test_fail("Wrong CRC of the transmitted packet");
|
| 8139 |
|
|
fail = fail + 1;
|
| 8140 |
|
|
end
|
| 8141 |
|
|
// end
|
| 8142 |
|
|
// check WB INT signal
|
| 8143 |
|
|
// if (i_length[1:0] == 2'h0)
|
| 8144 |
|
|
// begin
|
| 8145 |
|
|
if (wb_int !== 1'b1)
|
| 8146 |
|
|
begin
|
| 8147 |
|
|
`TIME; $display("*E WB INT signal should be set");
|
| 8148 |
|
|
test_fail("WB INT signal should be set");
|
| 8149 |
|
|
fail = fail + 1;
|
| 8150 |
|
|
end
|
| 8151 |
|
|
// end
|
| 8152 |
|
|
// else
|
| 8153 |
|
|
// begin
|
| 8154 |
|
|
// if (wb_int !== 1'b0)
|
| 8155 |
|
|
// begin
|
| 8156 |
|
|
// `TIME; $display("*E WB INT signal should not be set");
|
| 8157 |
|
|
// test_fail("WB INT signal should not be set");
|
| 8158 |
|
|
// fail = fail + 1;
|
| 8159 |
|
|
// end
|
| 8160 |
|
|
// end
|
| 8161 |
|
|
// // check TX buffer descriptor of a packet
|
| 8162 |
|
|
// check_tx_bd((i_length - (max_tmp - 8)), data);
|
| 8163 |
|
|
check_tx_bd(num_of_bd, data);
|
| 8164 |
|
|
if ( ((data[15:0] !== 16'h7800) && (num_of_bd == 2)) || // wrap bit
|
| 8165 |
|
|
((data[15:0] !== 16'h5800) && (num_of_bd < 2)) ) // without wrap bit
|
| 8166 |
|
|
// if (i_length[1] == 1'b0) // interrupt enabled
|
| 8167 |
|
|
// begin
|
| 8168 |
|
|
// if ( ((data[15:0] !== 16'h7800) && ((num_of_frames < 8) || ((num_of_frames - 8) == 127))) || // wrap bit
|
| 8169 |
|
|
// ((data[15:0] !== 16'h5800) && (num_of_frames >= 8) && ((num_of_frames - 8) != 127)) ) // without wrap bit
|
| 8170 |
|
|
begin
|
| 8171 |
|
|
`TIME; $display("*E TX buffer descriptor status is not correct: %0h", data[15:0]);
|
| 8172 |
|
|
test_fail("TX buffer descriptor status is not correct");
|
| 8173 |
|
|
fail = fail + 1;
|
| 8174 |
|
|
end
|
| 8175 |
|
|
// end
|
| 8176 |
|
|
// else // interrupt not enabled
|
| 8177 |
|
|
// begin
|
| 8178 |
|
|
// if ( ((data[15:0] !== 16'h3800) && ((num_of_frames < 8) || ((num_of_frames - 8) == 127))) || // wrap bit
|
| 8179 |
|
|
// ((data[15:0] !== 16'h1800) && (num_of_frames >= 8) && ((num_of_frames - 8) != 127)) ) // without wrap bit
|
| 8180 |
|
|
// begin
|
| 8181 |
|
|
// `TIME; $display("*E TX buffer descriptor status is not correct: %0h", data[15:0]);
|
| 8182 |
|
|
// test_fail("TX buffer descriptor status is not correct");
|
| 8183 |
|
|
// fail = fail + 1;
|
| 8184 |
|
|
// end
|
| 8185 |
|
|
// end
|
| 8186 |
|
|
// // clear first half of 8 frames from TX buffer descriptor 0
|
| 8187 |
|
|
// if (num_of_frames < 4)
|
| 8188 |
|
|
// clear_tx_bd((i_length - (max_tmp - 8)), (i_length - (max_tmp - 8)));
|
| 8189 |
|
|
// check interrupts
|
| 8190 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 8191 |
209 |
tadejm |
wbm_read(`ETH_INT, data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 8192 |
|
|
// if ((i_length[1:0] == 2'h0) || (i_length[1:0] == 2'h1))
|
| 8193 |
|
|
// begin
|
| 8194 |
|
|
if ((data & `ETH_INT_TXB) !== 1'b1)
|
| 8195 |
|
|
begin
|
| 8196 |
|
|
`TIME; $display("*E Interrupt Transmit Buffer was not set, interrupt reg: %0h", data);
|
| 8197 |
|
|
test_fail("Interrupt Transmit Buffer was not set");
|
| 8198 |
|
|
fail = fail + 1;
|
| 8199 |
|
|
end
|
| 8200 |
|
|
if ((data & (~`ETH_INT_TXB)) !== 0)
|
| 8201 |
|
|
begin
|
| 8202 |
|
|
`TIME; $display("*E Other interrupts (except Transmit Buffer) were set, interrupt reg: %0h", data);
|
| 8203 |
|
|
test_fail("Other interrupts (except Transmit Buffer) were set");
|
| 8204 |
|
|
fail = fail + 1;
|
| 8205 |
|
|
end
|
| 8206 |
|
|
// end
|
| 8207 |
|
|
// else
|
| 8208 |
|
|
// begin
|
| 8209 |
|
|
// if (data !== 0)
|
| 8210 |
|
|
// begin
|
| 8211 |
|
|
// `TIME; $display("*E Any of interrupts (except Transmit Buffer) was set, interrupt reg: %0h, len: %0h", data, i_length[1:0]);
|
| 8212 |
|
|
// test_fail("Any of interrupts (except Transmit Buffer) was set");
|
| 8213 |
|
|
// fail = fail + 1;
|
| 8214 |
|
|
// end
|
| 8215 |
|
|
// end
|
| 8216 |
|
|
// clear interrupts
|
| 8217 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 8218 |
209 |
tadejm |
wbm_write(`ETH_INT, data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 8219 |
|
|
// check WB INT signal
|
| 8220 |
|
|
if (wb_int !== 1'b0)
|
| 8221 |
|
|
begin
|
| 8222 |
|
|
test_fail("WB INT signal should not be set");
|
| 8223 |
|
|
fail = fail + 1;
|
| 8224 |
|
|
end
|
| 8225 |
|
|
// INTERMEDIATE DISPLAYS
|
| 8226 |
|
|
if (num_of_bd == 0)
|
| 8227 |
|
|
$display(" ->packet with length %0d sent", (i_length + 4));
|
| 8228 |
|
|
else if (num_of_bd == 1)
|
| 8229 |
|
|
$display(" ->packet with length %0d sent", (i_length + 4));
|
| 8230 |
|
|
else if (num_of_bd == 2)
|
| 8231 |
|
|
$display(" ->packet with length %0d sent", (i_length + 4));
|
| 8232 |
|
|
// set length (loop variable)
|
| 8233 |
|
|
i_length = i_length + 1;
|
| 8234 |
|
|
// the number of frame transmitted
|
| 8235 |
|
|
num_of_frames = num_of_frames + 1;
|
| 8236 |
|
|
num_of_bd = num_of_bd + 1;
|
| 8237 |
|
|
@(posedge wb_clk);
|
| 8238 |
|
|
end
|
| 8239 |
|
|
// disable TX
|
| 8240 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 8241 |
209 |
tadejm |
wbm_write(`ETH_MODER, `ETH_MODER_FULLD | `ETH_MODER_PAD | `ETH_MODER_CRCEN,
|
| 8242 |
|
|
4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 8243 |
|
|
@(posedge wb_clk);
|
| 8244 |
|
|
if(fail == 0)
|
| 8245 |
|
|
test_ok;
|
| 8246 |
|
|
else
|
| 8247 |
|
|
fail = 0;
|
| 8248 |
|
|
end
|
| 8249 |
|
|
|
| 8250 |
|
|
|
| 8251 |
|
|
////////////////////////////////////////////////////////////////////
|
| 8252 |
|
|
//// ////
|
| 8253 |
|
|
//// Test transmit packets across MAXFL value at ////
|
| 8254 |
|
|
//// 13 TX buffer decriptors ( 100Mbps ). ////
|
| 8255 |
|
|
//// ////
|
| 8256 |
|
|
////////////////////////////////////////////////////////////////////
|
| 8257 |
|
|
if (test_num == 11) // without and with padding
|
| 8258 |
|
|
begin
|
| 8259 |
|
|
// TEST 11: TRANSMIT PACKETS ACROSS MAXFL VALUE AT 13 TX BDs ( 100Mbps )
|
| 8260 |
|
|
test_name = "TEST 11: TRANSMIT PACKETS ACROSS MAXFL VALUE AT 13 TX BDs ( 100Mbps )";
|
| 8261 |
|
|
`TIME; $display(" TEST 11: TRANSMIT PACKETS ACROSS MAXFL VALUE AT 13 TX BDs ( 100Mbps )");
|
| 8262 |
|
|
|
| 8263 |
|
|
// reset MAC registers
|
| 8264 |
|
|
hard_reset;
|
| 8265 |
|
|
// reset MAC and MII LOGIC with soft reset
|
| 8266 |
274 |
tadejm |
// reset_mac;
|
| 8267 |
|
|
// reset_mii;
|
| 8268 |
209 |
tadejm |
// set wb slave response
|
| 8269 |
|
|
wb_slave.cycle_response(`ACK_RESPONSE, wbs_waits, wbs_retries);
|
| 8270 |
|
|
|
| 8271 |
|
|
max_tmp = 0;
|
| 8272 |
|
|
min_tmp = 0;
|
| 8273 |
|
|
num_of_frames = 0;
|
| 8274 |
|
|
num_of_bd = 0;
|
| 8275 |
|
|
// set 13 TX buffer descriptors - must be set before TX enable
|
| 8276 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 8277 |
209 |
tadejm |
wbm_write(`ETH_TX_BD_NUM, 32'hD, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 8278 |
|
|
// enable TX, set full-duplex mode, NO padding and CRC appending
|
| 8279 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 8280 |
209 |
tadejm |
wbm_write(`ETH_MODER, `ETH_MODER_TXEN | `ETH_MODER_FULLD | `ETH_MODER_CRCEN,
|
| 8281 |
|
|
4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 8282 |
|
|
// prepare a packet of MAXFL + 10 length
|
| 8283 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 8284 |
209 |
tadejm |
wbm_read(`ETH_PACKETLEN, tmp, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 8285 |
|
|
max_tmp = tmp[15:0]; // 18 bytes consists of 6B dest addr, 6B source addr, 2B type/len, 4B CRC
|
| 8286 |
|
|
min_tmp = tmp[31:16];
|
| 8287 |
|
|
st_data = 8'hA3;
|
| 8288 |
|
|
set_tx_packet(`MEMORY_BASE, (max_tmp + 10), st_data); // length without CRC
|
| 8289 |
|
|
// check WB INT signal
|
| 8290 |
|
|
if (wb_int !== 1'b0)
|
| 8291 |
|
|
begin
|
| 8292 |
|
|
test_fail("WB INT signal should not be set");
|
| 8293 |
|
|
fail = fail + 1;
|
| 8294 |
|
|
end
|
| 8295 |
|
|
|
| 8296 |
|
|
// write to phy's control register for 100Mbps
|
| 8297 |
|
|
#Tp eth_phy.control_bit14_10 = 5'b01000; // bit 13 set - speed 100
|
| 8298 |
|
|
#Tp eth_phy.control_bit8_0 = 9'h1_00; // bit 6 reset - (10/100), bit 8 set - FD
|
| 8299 |
|
|
speed = 100;
|
| 8300 |
|
|
|
| 8301 |
|
|
i_length = (max_tmp - 5);
|
| 8302 |
|
|
while (i_length <= (max_tmp - 3)) // (max_tmp - 4) is the limit
|
| 8303 |
|
|
begin
|
| 8304 |
|
|
$display(" i_length = %0d", i_length);
|
| 8305 |
|
|
// Reset_tx_bd nable interrupt generation
|
| 8306 |
|
|
// unmask interrupts
|
| 8307 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 8308 |
209 |
tadejm |
wbm_write(`ETH_INT_MASK, `ETH_INT_TXB | `ETH_INT_TXE | `ETH_INT_RXB | `ETH_INT_RXE | `ETH_INT_BUSY |
|
| 8309 |
|
|
`ETH_INT_TXC | `ETH_INT_RXC, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 8310 |
|
|
// not detect carrier sense in FD and no collision
|
| 8311 |
|
|
eth_phy.carrier_sense_tx_fd_detect(0);
|
| 8312 |
|
|
eth_phy.collision(0);
|
| 8313 |
|
|
// first destination address on ethernet PHY
|
| 8314 |
|
|
eth_phy.set_tx_mem_addr(0);
|
| 8315 |
|
|
// prepare BDs
|
| 8316 |
|
|
if (num_of_bd == 0)
|
| 8317 |
|
|
begin
|
| 8318 |
|
|
set_tx_bd(0, 0, i_length, 1'b1, 1'b1, 1'b1, `MEMORY_BASE);
|
| 8319 |
|
|
set_tx_bd(1, 1, i_length+1, 1'b1, 1'b1, 1'b1, `MEMORY_BASE);
|
| 8320 |
|
|
set_tx_bd(2, 2, i_length+2, 1'b1, 1'b1, 1'b1, `MEMORY_BASE);
|
| 8321 |
|
|
set_tx_bd_wrap(2);
|
| 8322 |
|
|
set_tx_bd_ready(0, 0);
|
| 8323 |
|
|
end
|
| 8324 |
|
|
else if (num_of_bd == 1)
|
| 8325 |
|
|
set_tx_bd_ready(1, 1);
|
| 8326 |
|
|
else if (num_of_bd == 2)
|
| 8327 |
|
|
set_tx_bd_ready(2, 2);
|
| 8328 |
|
|
// CHECK END OF TRANSMITION
|
| 8329 |
|
|
check_tx_bd(num_of_bd, data);
|
| 8330 |
|
|
wait (MTxEn === 1'b1); // start transmit
|
| 8331 |
|
|
check_tx_bd(num_of_bd, data);
|
| 8332 |
|
|
if (data[15] !== 1)
|
| 8333 |
|
|
begin
|
| 8334 |
|
|
test_fail("Wrong buffer descriptor's ready bit read out from MAC");
|
| 8335 |
|
|
fail = fail + 1;
|
| 8336 |
|
|
end
|
| 8337 |
|
|
wait (MTxEn === 1'b0); // end transmit
|
| 8338 |
|
|
while (data[15] === 1)
|
| 8339 |
|
|
begin
|
| 8340 |
|
|
check_tx_bd(num_of_bd, data);
|
| 8341 |
|
|
@(posedge wb_clk);
|
| 8342 |
|
|
end
|
| 8343 |
|
|
repeat (1) @(posedge wb_clk);
|
| 8344 |
|
|
// check length of a PACKET
|
| 8345 |
|
|
$display(" eth_phy length = %0d", eth_phy.tx_len);
|
| 8346 |
|
|
tmp_len = eth_phy.tx_len;
|
| 8347 |
|
|
#1;
|
| 8348 |
|
|
if (tmp_len != (i_length + 4))
|
| 8349 |
|
|
begin
|
| 8350 |
|
|
test_fail("Wrong length of the packet out from MAC");
|
| 8351 |
|
|
fail = fail + 1;
|
| 8352 |
|
|
end
|
| 8353 |
|
|
// checking packet
|
| 8354 |
|
|
check_tx_packet(`MEMORY_BASE, 0, i_length, tmp);
|
| 8355 |
|
|
if (tmp > 0)
|
| 8356 |
|
|
begin
|
| 8357 |
|
|
test_fail("Wrong data of the transmitted packet");
|
| 8358 |
|
|
fail = fail + 1;
|
| 8359 |
|
|
end
|
| 8360 |
|
|
// check transmited TX packet CRC
|
| 8361 |
|
|
check_tx_crc(0, i_length, 1'b0, tmp); // length without CRC
|
| 8362 |
|
|
if (tmp > 0)
|
| 8363 |
|
|
begin
|
| 8364 |
|
|
test_fail("Wrong CRC of the transmitted packet");
|
| 8365 |
|
|
fail = fail + 1;
|
| 8366 |
|
|
end
|
| 8367 |
|
|
// check WB INT signal
|
| 8368 |
|
|
if (wb_int !== 1'b1)
|
| 8369 |
|
|
begin
|
| 8370 |
|
|
`TIME; $display("*E WB INT signal should be set");
|
| 8371 |
|
|
test_fail("WB INT signal should be set");
|
| 8372 |
|
|
fail = fail + 1;
|
| 8373 |
|
|
end
|
| 8374 |
|
|
// check TX buffer descriptor of a packet
|
| 8375 |
|
|
check_tx_bd(num_of_bd, data);
|
| 8376 |
|
|
if ( ((data[15:0] !== 16'h7800) && (num_of_bd == 2)) || // wrap bit
|
| 8377 |
|
|
((data[15:0] !== 16'h5800) && (num_of_bd < 2)) ) // without wrap bit
|
| 8378 |
|
|
begin
|
| 8379 |
|
|
`TIME; $display("*E TX buffer descriptor status is not correct: %0h", data[15:0]);
|
| 8380 |
|
|
test_fail("TX buffer descriptor status is not correct");
|
| 8381 |
|
|
fail = fail + 1;
|
| 8382 |
|
|
end
|
| 8383 |
|
|
// check interrupts
|
| 8384 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 8385 |
209 |
tadejm |
wbm_read(`ETH_INT, data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 8386 |
|
|
if ((data & `ETH_INT_TXB) !== 1'b1)
|
| 8387 |
|
|
begin
|
| 8388 |
|
|
`TIME; $display("*E Interrupt Transmit Buffer was not set, interrupt reg: %0h", data);
|
| 8389 |
|
|
test_fail("Interrupt Transmit Buffer was not set");
|
| 8390 |
|
|
fail = fail + 1;
|
| 8391 |
|
|
end
|
| 8392 |
|
|
if ((data & (~`ETH_INT_TXB)) !== 0)
|
| 8393 |
|
|
begin
|
| 8394 |
|
|
`TIME; $display("*E Other interrupts (except Transmit Buffer) were set, interrupt reg: %0h", data);
|
| 8395 |
|
|
test_fail("Other interrupts (except Transmit Buffer) were set");
|
| 8396 |
|
|
fail = fail + 1;
|
| 8397 |
|
|
end
|
| 8398 |
|
|
// clear interrupts
|
| 8399 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 8400 |
209 |
tadejm |
wbm_write(`ETH_INT, data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 8401 |
|
|
// check WB INT signal
|
| 8402 |
|
|
if (wb_int !== 1'b0)
|
| 8403 |
|
|
begin
|
| 8404 |
|
|
test_fail("WB INT signal should not be set");
|
| 8405 |
|
|
fail = fail + 1;
|
| 8406 |
|
|
end
|
| 8407 |
|
|
// INTERMEDIATE DISPLAYS
|
| 8408 |
|
|
if (num_of_bd == 0)
|
| 8409 |
|
|
$display(" ->packet with length %0d sent", (i_length + 4));
|
| 8410 |
|
|
else if (num_of_bd == 1)
|
| 8411 |
|
|
$display(" ->packet with length %0d sent", (i_length + 4));
|
| 8412 |
|
|
else if (num_of_bd == 2)
|
| 8413 |
|
|
$display(" ->packet with length %0d sent", (i_length + 4));
|
| 8414 |
|
|
// set length (loop variable)
|
| 8415 |
|
|
i_length = i_length + 1;
|
| 8416 |
|
|
// the number of frame transmitted
|
| 8417 |
|
|
num_of_frames = num_of_frames + 1;
|
| 8418 |
|
|
num_of_bd = num_of_bd + 1;
|
| 8419 |
|
|
@(posedge wb_clk);
|
| 8420 |
|
|
end
|
| 8421 |
|
|
// disable TX
|
| 8422 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 8423 |
209 |
tadejm |
wbm_write(`ETH_MODER, `ETH_MODER_FULLD | `ETH_MODER_PAD | `ETH_MODER_CRCEN,
|
| 8424 |
|
|
4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 8425 |
|
|
@(posedge wb_clk);
|
| 8426 |
|
|
if(fail == 0)
|
| 8427 |
|
|
test_ok;
|
| 8428 |
|
|
else
|
| 8429 |
|
|
fail = 0;
|
| 8430 |
|
|
end
|
| 8431 |
|
|
|
| 8432 |
|
|
|
| 8433 |
|
|
////////////////////////////////////////////////////////////////////
|
| 8434 |
|
|
//// ////
|
| 8435 |
|
|
//// Test transmit packets across changed MAXFL value at ////
|
| 8436 |
|
|
//// 47 TX buffer decriptors ( 10Mbps ). ////
|
| 8437 |
|
|
//// ////
|
| 8438 |
|
|
////////////////////////////////////////////////////////////////////
|
| 8439 |
|
|
if (test_num == 12) // without and with padding
|
| 8440 |
|
|
begin
|
| 8441 |
|
|
// TEST 12: TRANSMIT PACKETS ACROSS CHANGED MAXFL VALUE AT 13 TX BDs ( 10Mbps )
|
| 8442 |
|
|
test_name = "TEST 12: TRANSMIT PACKETS ACROSS CHANGED MAXFL VALUE AT 13 TX BDs ( 10Mbps )";
|
| 8443 |
|
|
`TIME; $display(" TEST 12: TRANSMIT PACKETS ACROSS CHANGED MAXFL VALUE AT 13 TX BDs ( 10Mbps )");
|
| 8444 |
|
|
|
| 8445 |
|
|
// reset MAC registers
|
| 8446 |
|
|
hard_reset;
|
| 8447 |
|
|
// reset MAC and MII LOGIC with soft reset
|
| 8448 |
274 |
tadejm |
// reset_mac;
|
| 8449 |
|
|
// reset_mii;
|
| 8450 |
209 |
tadejm |
// set wb slave response
|
| 8451 |
|
|
wb_slave.cycle_response(`ACK_RESPONSE, wbs_waits, wbs_retries);
|
| 8452 |
|
|
|
| 8453 |
|
|
max_tmp = 0;
|
| 8454 |
|
|
min_tmp = 0;
|
| 8455 |
|
|
num_of_frames = 0;
|
| 8456 |
|
|
num_of_bd = 0;
|
| 8457 |
|
|
// set 47 TX buffer descriptors - must be set before TX enable
|
| 8458 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 8459 |
209 |
tadejm |
wbm_write(`ETH_TX_BD_NUM, 32'h2F, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 8460 |
|
|
// prepare a packet of MAXFL + 10 length
|
| 8461 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 8462 |
209 |
tadejm |
wbm_read(`ETH_PACKETLEN, tmp, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 8463 |
|
|
max_tmp = tmp[15:0]; // 18 bytes consists of 6B dest addr, 6B source addr, 2B type/len, 4B CRC
|
| 8464 |
|
|
min_tmp = tmp[31:16];
|
| 8465 |
|
|
// change MAXFL value
|
| 8466 |
|
|
max_tmp = min_tmp + 53;
|
| 8467 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 8468 |
209 |
tadejm |
wbm_write(`ETH_PACKETLEN, {min_tmp, max_tmp}, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 8469 |
|
|
st_data = 8'h62;
|
| 8470 |
|
|
set_tx_packet(`MEMORY_BASE, max_tmp, st_data); // length with CRC
|
| 8471 |
|
|
append_tx_crc(`MEMORY_BASE, (max_tmp - 5), 1'b0); // for first packet
|
| 8472 |
|
|
// enable TX, set full-duplex mode, NO padding and NO CRC appending
|
| 8473 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 8474 |
209 |
tadejm |
wbm_write(`ETH_MODER, `ETH_MODER_TXEN | `ETH_MODER_FULLD,
|
| 8475 |
|
|
4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 8476 |
|
|
// check WB INT signal
|
| 8477 |
|
|
if (wb_int !== 1'b0)
|
| 8478 |
|
|
begin
|
| 8479 |
|
|
test_fail("WB INT signal should not be set");
|
| 8480 |
|
|
fail = fail + 1;
|
| 8481 |
|
|
end
|
| 8482 |
|
|
|
| 8483 |
|
|
// write to phy's control register for 10Mbps
|
| 8484 |
|
|
#Tp eth_phy.control_bit14_10 = 5'b00000; // bit 13 reset - speed 10
|
| 8485 |
|
|
#Tp eth_phy.control_bit8_0 = 9'h1_00; // bit 6 reset - (10/100), bit 8 set - FD
|
| 8486 |
|
|
speed = 10;
|
| 8487 |
|
|
|
| 8488 |
|
|
i_length = (max_tmp - 5); // (max_tmp - 1); // not (max_tmp - 5) because NO automatic CRC appending
|
| 8489 |
|
|
while (i_length <= (max_tmp - 3)) // (max_tmp + 1)) // (max_tmp) is the limit
|
| 8490 |
|
|
begin
|
| 8491 |
|
|
$display(" i_length = %0d", i_length);
|
| 8492 |
|
|
// prepare packet's CRC
|
| 8493 |
|
|
if (num_of_bd == 1)
|
| 8494 |
|
|
append_tx_crc(`MEMORY_BASE, (max_tmp - 4), 1'b0); // for second and third packets
|
| 8495 |
|
|
// Reset_tx_bd nable interrupt generation
|
| 8496 |
|
|
// unmask interrupts
|
| 8497 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 8498 |
209 |
tadejm |
wbm_write(`ETH_INT_MASK, `ETH_INT_TXB | `ETH_INT_TXE | `ETH_INT_RXB | `ETH_INT_RXE | `ETH_INT_BUSY |
|
| 8499 |
|
|
`ETH_INT_TXC | `ETH_INT_RXC, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 8500 |
|
|
// not detect carrier sense in FD and no collision
|
| 8501 |
|
|
eth_phy.carrier_sense_tx_fd_detect(0);
|
| 8502 |
|
|
eth_phy.collision(0);
|
| 8503 |
|
|
// first destination address on ethernet PHY
|
| 8504 |
|
|
eth_phy.set_tx_mem_addr(0);
|
| 8505 |
|
|
// prepare BDs
|
| 8506 |
|
|
if (num_of_bd == 0)
|
| 8507 |
|
|
begin
|
| 8508 |
|
|
set_tx_bd(0, 0, i_length, 1'b1, 1'b1, 1'b1, `MEMORY_BASE);
|
| 8509 |
|
|
set_tx_bd(1, 1, i_length+1, 1'b1, 1'b1, 1'b1, `MEMORY_BASE);
|
| 8510 |
|
|
set_tx_bd(2, 2, i_length+2, 1'b1, 1'b1, 1'b1, `MEMORY_BASE);
|
| 8511 |
|
|
set_tx_bd_wrap(2);
|
| 8512 |
|
|
set_tx_bd_ready(0, 0);
|
| 8513 |
|
|
end
|
| 8514 |
|
|
else if (num_of_bd == 1)
|
| 8515 |
|
|
set_tx_bd_ready(1, 1);
|
| 8516 |
|
|
else if (num_of_bd == 2)
|
| 8517 |
|
|
set_tx_bd_ready(2, 2);
|
| 8518 |
|
|
// CHECK END OF TRANSMITION
|
| 8519 |
|
|
check_tx_bd(num_of_bd, data);
|
| 8520 |
|
|
wait (MTxEn === 1'b1); // start transmit
|
| 8521 |
|
|
check_tx_bd(num_of_bd, data);
|
| 8522 |
|
|
if (data[15] !== 1)
|
| 8523 |
|
|
begin
|
| 8524 |
|
|
test_fail("Wrong buffer descriptor's ready bit read out from MAC");
|
| 8525 |
|
|
fail = fail + 1;
|
| 8526 |
|
|
end
|
| 8527 |
|
|
wait (MTxEn === 1'b0); // end transmit
|
| 8528 |
|
|
while (data[15] === 1)
|
| 8529 |
|
|
begin
|
| 8530 |
|
|
check_tx_bd(num_of_bd, data);
|
| 8531 |
|
|
@(posedge wb_clk);
|
| 8532 |
|
|
end
|
| 8533 |
|
|
repeat (1) @(posedge wb_clk);
|
| 8534 |
|
|
// check length of a PACKET
|
| 8535 |
|
|
$display(" eth_phy length = %0d", eth_phy.tx_len);
|
| 8536 |
|
|
tmp_len = eth_phy.tx_len;
|
| 8537 |
|
|
#1;
|
| 8538 |
|
|
if (tmp_len != (i_length + 4))
|
| 8539 |
|
|
begin
|
| 8540 |
|
|
test_fail("Wrong length of the packet out from MAC");
|
| 8541 |
|
|
fail = fail + 1;
|
| 8542 |
|
|
end
|
| 8543 |
|
|
// checking packet
|
| 8544 |
|
|
check_tx_packet(`MEMORY_BASE, 0, i_length, tmp);
|
| 8545 |
|
|
if (tmp > 0)
|
| 8546 |
|
|
begin
|
| 8547 |
|
|
test_fail("Wrong data of the transmitted packet");
|
| 8548 |
|
|
fail = fail + 1;
|
| 8549 |
|
|
end
|
| 8550 |
|
|
// check transmited TX packet CRC
|
| 8551 |
|
|
check_tx_crc(0, i_length, 1'b0, tmp); // length without CRC
|
| 8552 |
|
|
if (tmp > 0)
|
| 8553 |
|
|
begin
|
| 8554 |
|
|
test_fail("Wrong CRC of the transmitted packet");
|
| 8555 |
|
|
fail = fail + 1;
|
| 8556 |
|
|
end
|
| 8557 |
|
|
// check WB INT signal
|
| 8558 |
|
|
if (wb_int !== 1'b1)
|
| 8559 |
|
|
begin
|
| 8560 |
|
|
`TIME; $display("*E WB INT signal should be set");
|
| 8561 |
|
|
test_fail("WB INT signal should be set");
|
| 8562 |
|
|
fail = fail + 1;
|
| 8563 |
|
|
end
|
| 8564 |
|
|
// check TX buffer descriptor of a packet
|
| 8565 |
|
|
check_tx_bd(num_of_bd, data);
|
| 8566 |
|
|
if ( ((data[15:0] !== 16'h7800) && (num_of_bd == 2)) || // wrap bit
|
| 8567 |
|
|
((data[15:0] !== 16'h5800) && (num_of_bd < 2)) ) // without wrap bit
|
| 8568 |
|
|
begin
|
| 8569 |
|
|
`TIME; $display("*E TX buffer descriptor status is not correct: %0h", data[15:0]);
|
| 8570 |
|
|
test_fail("TX buffer descriptor status is not correct");
|
| 8571 |
|
|
fail = fail + 1;
|
| 8572 |
|
|
end
|
| 8573 |
|
|
// check interrupts
|
| 8574 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 8575 |
209 |
tadejm |
wbm_read(`ETH_INT, data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 8576 |
|
|
if ((data & `ETH_INT_TXB) !== 1'b1)
|
| 8577 |
|
|
begin
|
| 8578 |
|
|
`TIME; $display("*E Interrupt Transmit Buffer was not set, interrupt reg: %0h", data);
|
| 8579 |
|
|
test_fail("Interrupt Transmit Buffer was not set");
|
| 8580 |
|
|
fail = fail + 1;
|
| 8581 |
|
|
end
|
| 8582 |
|
|
if ((data & (~`ETH_INT_TXB)) !== 0)
|
| 8583 |
|
|
begin
|
| 8584 |
|
|
`TIME; $display("*E Other interrupts (except Transmit Buffer) were set, interrupt reg: %0h", data);
|
| 8585 |
|
|
test_fail("Other interrupts (except Transmit Buffer) were set");
|
| 8586 |
|
|
fail = fail + 1;
|
| 8587 |
|
|
end
|
| 8588 |
|
|
// clear interrupts
|
| 8589 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 8590 |
209 |
tadejm |
wbm_write(`ETH_INT, data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 8591 |
|
|
// check WB INT signal
|
| 8592 |
|
|
if (wb_int !== 1'b0)
|
| 8593 |
|
|
begin
|
| 8594 |
|
|
test_fail("WB INT signal should not be set");
|
| 8595 |
|
|
fail = fail + 1;
|
| 8596 |
|
|
end
|
| 8597 |
|
|
// INTERMEDIATE DISPLAYS
|
| 8598 |
|
|
if (num_of_bd == 0)
|
| 8599 |
|
|
$display(" ->packet with length %0d sent", (i_length + 4));
|
| 8600 |
|
|
else if (num_of_bd == 1)
|
| 8601 |
|
|
$display(" ->packet with length %0d sent", (i_length + 4));
|
| 8602 |
|
|
else if (num_of_bd == 2)
|
| 8603 |
|
|
$display(" ->packet with length %0d sent", (i_length + 4));
|
| 8604 |
|
|
// set length (loop variable)
|
| 8605 |
|
|
i_length = i_length + 1;
|
| 8606 |
|
|
// the number of frame transmitted
|
| 8607 |
|
|
num_of_frames = num_of_frames + 1;
|
| 8608 |
|
|
num_of_bd = num_of_bd + 1;
|
| 8609 |
|
|
@(posedge wb_clk);
|
| 8610 |
|
|
end
|
| 8611 |
|
|
// disable TX
|
| 8612 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 8613 |
209 |
tadejm |
wbm_write(`ETH_MODER, `ETH_MODER_FULLD | `ETH_MODER_PAD | `ETH_MODER_CRCEN,
|
| 8614 |
|
|
4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 8615 |
|
|
@(posedge wb_clk);
|
| 8616 |
|
|
if(fail == 0)
|
| 8617 |
|
|
test_ok;
|
| 8618 |
|
|
else
|
| 8619 |
|
|
fail = 0;
|
| 8620 |
|
|
end
|
| 8621 |
|
|
|
| 8622 |
|
|
|
| 8623 |
|
|
////////////////////////////////////////////////////////////////////
|
| 8624 |
|
|
//// ////
|
| 8625 |
|
|
//// Test transmit packets across changed MAXFL value at ////
|
| 8626 |
|
|
//// 47 TX buffer decriptors ( 100Mbps ). ////
|
| 8627 |
|
|
//// ////
|
| 8628 |
|
|
////////////////////////////////////////////////////////////////////
|
| 8629 |
|
|
if (test_num == 13) // without and with padding
|
| 8630 |
|
|
begin
|
| 8631 |
|
|
// TEST 13: TRANSMIT PACKETS ACROSS CHANGED MAXFL VALUE AT 13 TX BDs ( 100Mbps )
|
| 8632 |
|
|
test_name = "TEST 13: TRANSMIT PACKETS ACROSS CHANGED MAXFL VALUE AT 13 TX BDs ( 100Mbps )";
|
| 8633 |
|
|
`TIME; $display(" TEST 13: TRANSMIT PACKETS ACROSS CHANGED MAXFL VALUE AT 13 TX BDs ( 100Mbps )");
|
| 8634 |
|
|
|
| 8635 |
|
|
// reset MAC registers
|
| 8636 |
|
|
hard_reset;
|
| 8637 |
|
|
// reset MAC and MII LOGIC with soft reset
|
| 8638 |
274 |
tadejm |
// reset_mac;
|
| 8639 |
|
|
// reset_mii;
|
| 8640 |
209 |
tadejm |
// set wb slave response
|
| 8641 |
|
|
wb_slave.cycle_response(`ACK_RESPONSE, wbs_waits, wbs_retries);
|
| 8642 |
|
|
|
| 8643 |
|
|
max_tmp = 0;
|
| 8644 |
|
|
min_tmp = 0;
|
| 8645 |
|
|
num_of_frames = 0;
|
| 8646 |
|
|
num_of_bd = 0;
|
| 8647 |
|
|
// set 47 TX buffer descriptors - must be set before TX enable
|
| 8648 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 8649 |
209 |
tadejm |
wbm_write(`ETH_TX_BD_NUM, 32'h2F, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 8650 |
|
|
// prepare a packet of MAXFL + 10 length
|
| 8651 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 8652 |
209 |
tadejm |
wbm_read(`ETH_PACKETLEN, tmp, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 8653 |
|
|
max_tmp = tmp[15:0]; // 18 bytes consists of 6B dest addr, 6B source addr, 2B type/len, 4B CRC
|
| 8654 |
|
|
min_tmp = tmp[31:16];
|
| 8655 |
|
|
// change MAXFL value
|
| 8656 |
|
|
max_tmp = min_tmp + 53;
|
| 8657 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 8658 |
209 |
tadejm |
wbm_write(`ETH_PACKETLEN, {min_tmp, max_tmp}, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 8659 |
|
|
st_data = 8'h62;
|
| 8660 |
|
|
set_tx_packet(`MEMORY_BASE, max_tmp, st_data); // length with CRC
|
| 8661 |
|
|
append_tx_crc(`MEMORY_BASE, (max_tmp - 5), 1'b0); // for first packet
|
| 8662 |
|
|
// enable TX, set full-duplex mode, NO padding and NO CRC appending
|
| 8663 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 8664 |
209 |
tadejm |
wbm_write(`ETH_MODER, `ETH_MODER_TXEN | `ETH_MODER_FULLD,
|
| 8665 |
|
|
4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 8666 |
|
|
// check WB INT signal
|
| 8667 |
|
|
if (wb_int !== 1'b0)
|
| 8668 |
|
|
begin
|
| 8669 |
|
|
test_fail("WB INT signal should not be set");
|
| 8670 |
|
|
fail = fail + 1;
|
| 8671 |
|
|
end
|
| 8672 |
|
|
|
| 8673 |
|
|
// write to phy's control register for 100Mbps
|
| 8674 |
|
|
#Tp eth_phy.control_bit14_10 = 5'b01000; // bit 13 set - speed 100
|
| 8675 |
|
|
#Tp eth_phy.control_bit8_0 = 9'h1_00; // bit 6 reset - (10/100), bit 8 set - FD
|
| 8676 |
|
|
speed = 100;
|
| 8677 |
|
|
|
| 8678 |
|
|
i_length = (max_tmp - 5); // (max_tmp - 1); // not (max_tmp - 5) because NO automatic CRC appending
|
| 8679 |
|
|
while (i_length <= (max_tmp - 3)) // (max_tmp + 1)) // (max_tmp) is the limit
|
| 8680 |
|
|
begin
|
| 8681 |
|
|
$display(" i_length = %0d", i_length);
|
| 8682 |
|
|
// prepare packet's CRC
|
| 8683 |
|
|
if (num_of_bd == 1)
|
| 8684 |
|
|
append_tx_crc(`MEMORY_BASE, (max_tmp - 4), 1'b0); // for second and third packets
|
| 8685 |
|
|
// Reset_tx_bd nable interrupt generation
|
| 8686 |
|
|
// unmask interrupts
|
| 8687 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 8688 |
209 |
tadejm |
wbm_write(`ETH_INT_MASK, `ETH_INT_TXB | `ETH_INT_TXE | `ETH_INT_RXB | `ETH_INT_RXE | `ETH_INT_BUSY |
|
| 8689 |
|
|
`ETH_INT_TXC | `ETH_INT_RXC, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 8690 |
|
|
// not detect carrier sense in FD and no collision
|
| 8691 |
|
|
eth_phy.carrier_sense_tx_fd_detect(0);
|
| 8692 |
|
|
eth_phy.collision(0);
|
| 8693 |
|
|
// first destination address on ethernet PHY
|
| 8694 |
|
|
eth_phy.set_tx_mem_addr(0);
|
| 8695 |
|
|
// prepare BDs
|
| 8696 |
|
|
if (num_of_bd == 0)
|
| 8697 |
|
|
begin
|
| 8698 |
|
|
set_tx_bd(0, 0, i_length, 1'b1, 1'b1, 1'b1, `MEMORY_BASE);
|
| 8699 |
|
|
set_tx_bd(1, 1, i_length+1, 1'b1, 1'b1, 1'b1, `MEMORY_BASE);
|
| 8700 |
|
|
set_tx_bd(2, 2, i_length+2, 1'b1, 1'b1, 1'b1, `MEMORY_BASE);
|
| 8701 |
|
|
set_tx_bd_wrap(2);
|
| 8702 |
|
|
set_tx_bd_ready(0, 0);
|
| 8703 |
|
|
end
|
| 8704 |
|
|
else if (num_of_bd == 1)
|
| 8705 |
|
|
set_tx_bd_ready(1, 1);
|
| 8706 |
|
|
else if (num_of_bd == 2)
|
| 8707 |
|
|
set_tx_bd_ready(2, 2);
|
| 8708 |
|
|
// CHECK END OF TRANSMITION
|
| 8709 |
|
|
check_tx_bd(num_of_bd, data);
|
| 8710 |
|
|
wait (MTxEn === 1'b1); // start transmit
|
| 8711 |
|
|
check_tx_bd(num_of_bd, data);
|
| 8712 |
|
|
if (data[15] !== 1)
|
| 8713 |
|
|
begin
|
| 8714 |
|
|
test_fail("Wrong buffer descriptor's ready bit read out from MAC");
|
| 8715 |
|
|
fail = fail + 1;
|
| 8716 |
|
|
end
|
| 8717 |
|
|
wait (MTxEn === 1'b0); // end transmit
|
| 8718 |
|
|
while (data[15] === 1)
|
| 8719 |
|
|
begin
|
| 8720 |
|
|
check_tx_bd(num_of_bd, data);
|
| 8721 |
|
|
@(posedge wb_clk);
|
| 8722 |
|
|
end
|
| 8723 |
|
|
repeat (1) @(posedge wb_clk);
|
| 8724 |
|
|
// check length of a PACKET
|
| 8725 |
|
|
$display(" eth_phy length = %0d", eth_phy.tx_len);
|
| 8726 |
|
|
tmp_len = eth_phy.tx_len;
|
| 8727 |
|
|
#1;
|
| 8728 |
|
|
if (tmp_len != (i_length + 4))
|
| 8729 |
|
|
begin
|
| 8730 |
|
|
test_fail("Wrong length of the packet out from MAC");
|
| 8731 |
|
|
fail = fail + 1;
|
| 8732 |
|
|
end
|
| 8733 |
|
|
// checking packet
|
| 8734 |
|
|
check_tx_packet(`MEMORY_BASE, 0, i_length, tmp);
|
| 8735 |
|
|
if (tmp > 0)
|
| 8736 |
|
|
begin
|
| 8737 |
|
|
test_fail("Wrong data of the transmitted packet");
|
| 8738 |
|
|
fail = fail + 1;
|
| 8739 |
|
|
end
|
| 8740 |
|
|
// check transmited TX packet CRC
|
| 8741 |
|
|
check_tx_crc(0, i_length, 1'b0, tmp); // length without CRC
|
| 8742 |
|
|
if (tmp > 0)
|
| 8743 |
|
|
begin
|
| 8744 |
|
|
test_fail("Wrong CRC of the transmitted packet");
|
| 8745 |
|
|
fail = fail + 1;
|
| 8746 |
|
|
end
|
| 8747 |
|
|
// check WB INT signal
|
| 8748 |
|
|
if (wb_int !== 1'b1)
|
| 8749 |
|
|
begin
|
| 8750 |
|
|
`TIME; $display("*E WB INT signal should be set");
|
| 8751 |
|
|
test_fail("WB INT signal should be set");
|
| 8752 |
|
|
fail = fail + 1;
|
| 8753 |
|
|
end
|
| 8754 |
|
|
// check TX buffer descriptor of a packet
|
| 8755 |
|
|
check_tx_bd(num_of_bd, data);
|
| 8756 |
|
|
if ( ((data[15:0] !== 16'h7800) && (num_of_bd == 2)) || // wrap bit
|
| 8757 |
|
|
((data[15:0] !== 16'h5800) && (num_of_bd < 2)) ) // without wrap bit
|
| 8758 |
|
|
begin
|
| 8759 |
|
|
`TIME; $display("*E TX buffer descriptor status is not correct: %0h", data[15:0]);
|
| 8760 |
|
|
test_fail("TX buffer descriptor status is not correct");
|
| 8761 |
|
|
fail = fail + 1;
|
| 8762 |
|
|
end
|
| 8763 |
|
|
// check interrupts
|
| 8764 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 8765 |
209 |
tadejm |
wbm_read(`ETH_INT, data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 8766 |
|
|
if ((data & `ETH_INT_TXB) !== 1'b1)
|
| 8767 |
|
|
begin
|
| 8768 |
|
|
`TIME; $display("*E Interrupt Transmit Buffer was not set, interrupt reg: %0h", data);
|
| 8769 |
|
|
test_fail("Interrupt Transmit Buffer was not set");
|
| 8770 |
|
|
fail = fail + 1;
|
| 8771 |
|
|
end
|
| 8772 |
|
|
if ((data & (~`ETH_INT_TXB)) !== 0)
|
| 8773 |
|
|
begin
|
| 8774 |
|
|
`TIME; $display("*E Other interrupts (except Transmit Buffer) were set, interrupt reg: %0h", data);
|
| 8775 |
|
|
test_fail("Other interrupts (except Transmit Buffer) were set");
|
| 8776 |
|
|
fail = fail + 1;
|
| 8777 |
|
|
end
|
| 8778 |
|
|
// clear interrupts
|
| 8779 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 8780 |
209 |
tadejm |
wbm_write(`ETH_INT, data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 8781 |
|
|
// check WB INT signal
|
| 8782 |
|
|
if (wb_int !== 1'b0)
|
| 8783 |
|
|
begin
|
| 8784 |
|
|
test_fail("WB INT signal should not be set");
|
| 8785 |
|
|
fail = fail + 1;
|
| 8786 |
|
|
end
|
| 8787 |
|
|
// INTERMEDIATE DISPLAYS
|
| 8788 |
|
|
if (num_of_bd == 0)
|
| 8789 |
|
|
$display(" ->packet with length %0d sent", (i_length + 4));
|
| 8790 |
|
|
else if (num_of_bd == 1)
|
| 8791 |
|
|
$display(" ->packet with length %0d sent", (i_length + 4));
|
| 8792 |
|
|
else if (num_of_bd == 2)
|
| 8793 |
|
|
$display(" ->packet with length %0d sent", (i_length + 4));
|
| 8794 |
|
|
// set length (loop variable)
|
| 8795 |
|
|
i_length = i_length + 1;
|
| 8796 |
|
|
// the number of frame transmitted
|
| 8797 |
|
|
num_of_frames = num_of_frames + 1;
|
| 8798 |
|
|
num_of_bd = num_of_bd + 1;
|
| 8799 |
|
|
@(posedge wb_clk);
|
| 8800 |
|
|
end
|
| 8801 |
|
|
// disable TX
|
| 8802 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 8803 |
209 |
tadejm |
wbm_write(`ETH_MODER, `ETH_MODER_FULLD | `ETH_MODER_PAD | `ETH_MODER_CRCEN,
|
| 8804 |
|
|
4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 8805 |
|
|
@(posedge wb_clk);
|
| 8806 |
|
|
if(fail == 0)
|
| 8807 |
|
|
test_ok;
|
| 8808 |
|
|
else
|
| 8809 |
|
|
fail = 0;
|
| 8810 |
|
|
end
|
| 8811 |
|
|
|
| 8812 |
|
|
|
| 8813 |
|
|
////////////////////////////////////////////////////////////////////
|
| 8814 |
|
|
//// ////
|
| 8815 |
|
|
//// Test transmit packets across changed MINFL value at ////
|
| 8816 |
|
|
//// 7 TX buffer decriptors ( 10Mbps ). ////
|
| 8817 |
|
|
//// ////
|
| 8818 |
|
|
////////////////////////////////////////////////////////////////////
|
| 8819 |
|
|
if (test_num == 14) // without and with padding
|
| 8820 |
|
|
begin
|
| 8821 |
|
|
// TEST 14: TRANSMIT PACKETS ACROSS CHANGED MINFL VALUE AT 7 TX BDs ( 10Mbps )
|
| 8822 |
|
|
test_name = "TEST 14: TRANSMIT PACKETS ACROSS CHANGED MINFL VALUE AT 7 TX BDs ( 10Mbps )";
|
| 8823 |
|
|
`TIME; $display(" TEST 14: TRANSMIT PACKETS ACROSS CHANGED MINFL VALUE AT 7 TX BDs ( 10Mbps )");
|
| 8824 |
|
|
|
| 8825 |
|
|
// reset MAC registers
|
| 8826 |
|
|
hard_reset;
|
| 8827 |
|
|
// reset MAC and MII LOGIC with soft reset
|
| 8828 |
274 |
tadejm |
// reset_mac;
|
| 8829 |
|
|
// reset_mii;
|
| 8830 |
209 |
tadejm |
// set wb slave response
|
| 8831 |
|
|
wb_slave.cycle_response(`ACK_RESPONSE, wbs_waits, wbs_retries);
|
| 8832 |
|
|
|
| 8833 |
|
|
max_tmp = 0;
|
| 8834 |
|
|
min_tmp = 0;
|
| 8835 |
|
|
num_of_frames = 0;
|
| 8836 |
|
|
num_of_bd = 0;
|
| 8837 |
|
|
// set 7 TX buffer descriptors - must be set before TX enable
|
| 8838 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 8839 |
209 |
tadejm |
wbm_write(`ETH_TX_BD_NUM, 32'h7, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 8840 |
|
|
// prepare a packet of MAXFL + 10 length
|
| 8841 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 8842 |
209 |
tadejm |
wbm_read(`ETH_PACKETLEN, tmp, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 8843 |
|
|
max_tmp = tmp[15:0]; // 18 bytes consists of 6B dest addr, 6B source addr, 2B type/len, 4B CRC
|
| 8844 |
|
|
min_tmp = tmp[31:16];
|
| 8845 |
|
|
// change MINFL value
|
| 8846 |
|
|
min_tmp = max_tmp - 177;
|
| 8847 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 8848 |
209 |
tadejm |
wbm_write(`ETH_PACKETLEN, {min_tmp, max_tmp}, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 8849 |
|
|
st_data = 8'h62;
|
| 8850 |
|
|
set_tx_packet(`MEMORY_BASE, min_tmp, st_data); // length without CRC
|
| 8851 |
|
|
// enable TX, set full-duplex mode, padding and CRC appending
|
| 8852 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 8853 |
209 |
tadejm |
wbm_write(`ETH_MODER, `ETH_MODER_TXEN | `ETH_MODER_PAD | `ETH_MODER_FULLD | `ETH_MODER_CRCEN,
|
| 8854 |
|
|
4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 8855 |
|
|
// check WB INT signal
|
| 8856 |
|
|
if (wb_int !== 1'b0)
|
| 8857 |
|
|
begin
|
| 8858 |
|
|
test_fail("WB INT signal should not be set");
|
| 8859 |
|
|
fail = fail + 1;
|
| 8860 |
|
|
end
|
| 8861 |
|
|
|
| 8862 |
|
|
// write to phy's control register for 10Mbps
|
| 8863 |
|
|
#Tp eth_phy.control_bit14_10 = 5'b00000; // bit 13 reset - speed 10
|
| 8864 |
|
|
#Tp eth_phy.control_bit8_0 = 9'h1_00; // bit 6 reset - (10/100), bit 8 set - FD
|
| 8865 |
|
|
speed = 10;
|
| 8866 |
|
|
|
| 8867 |
|
|
i_length = (min_tmp - 5);
|
| 8868 |
|
|
while (i_length <= (min_tmp - 3)) // (min_tmp - 4) is the limit
|
| 8869 |
|
|
begin
|
| 8870 |
|
|
$display(" i_length = %0d", i_length);
|
| 8871 |
|
|
// Reset_tx_bd nable interrupt generation
|
| 8872 |
|
|
// unmask interrupts
|
| 8873 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 8874 |
209 |
tadejm |
wbm_write(`ETH_INT_MASK, `ETH_INT_TXB | `ETH_INT_TXE | `ETH_INT_RXB | `ETH_INT_RXE | `ETH_INT_BUSY |
|
| 8875 |
|
|
`ETH_INT_TXC | `ETH_INT_RXC, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 8876 |
|
|
// not detect carrier sense in FD and no collision
|
| 8877 |
|
|
eth_phy.carrier_sense_tx_fd_detect(0);
|
| 8878 |
|
|
eth_phy.collision(0);
|
| 8879 |
|
|
// first destination address on ethernet PHY
|
| 8880 |
|
|
eth_phy.set_tx_mem_addr(0);
|
| 8881 |
|
|
// prepare BDs
|
| 8882 |
|
|
if (num_of_bd == 0)
|
| 8883 |
|
|
begin
|
| 8884 |
|
|
set_tx_bd(0, 0, i_length, 1'b1, 1'b1, 1'b1, `MEMORY_BASE);
|
| 8885 |
|
|
set_tx_bd(1, 1, i_length+1, 1'b1, 1'b1, 1'b1, `MEMORY_BASE);
|
| 8886 |
|
|
set_tx_bd(2, 2, i_length+2, 1'b1, 1'b1, 1'b1, `MEMORY_BASE);
|
| 8887 |
|
|
set_tx_bd_wrap(2);
|
| 8888 |
|
|
set_tx_bd_ready(0, 0);
|
| 8889 |
|
|
end
|
| 8890 |
|
|
else if (num_of_bd == 1)
|
| 8891 |
|
|
set_tx_bd_ready(1, 1);
|
| 8892 |
|
|
else if (num_of_bd == 2)
|
| 8893 |
|
|
set_tx_bd_ready(2, 2);
|
| 8894 |
|
|
// CHECK END OF TRANSMITION
|
| 8895 |
|
|
check_tx_bd(num_of_bd, data);
|
| 8896 |
|
|
wait (MTxEn === 1'b1); // start transmit
|
| 8897 |
|
|
check_tx_bd(num_of_bd, data);
|
| 8898 |
|
|
if (data[15] !== 1)
|
| 8899 |
|
|
begin
|
| 8900 |
|
|
test_fail("Wrong buffer descriptor's ready bit read out from MAC");
|
| 8901 |
|
|
fail = fail + 1;
|
| 8902 |
|
|
end
|
| 8903 |
|
|
wait (MTxEn === 1'b0); // end transmit
|
| 8904 |
|
|
while (data[15] === 1)
|
| 8905 |
|
|
begin
|
| 8906 |
|
|
check_tx_bd(num_of_bd, data);
|
| 8907 |
|
|
@(posedge wb_clk);
|
| 8908 |
|
|
end
|
| 8909 |
|
|
repeat (1) @(posedge wb_clk);
|
| 8910 |
|
|
// check length of a PACKET
|
| 8911 |
|
|
$display(" eth_phy length = %0d", eth_phy.tx_len);
|
| 8912 |
|
|
tmp_len = eth_phy.tx_len;
|
| 8913 |
|
|
#1;
|
| 8914 |
|
|
if (tmp_len != (i_length + 4))
|
| 8915 |
|
|
begin
|
| 8916 |
|
|
test_fail("Wrong length of the packet out from MAC");
|
| 8917 |
|
|
fail = fail + 1;
|
| 8918 |
|
|
end
|
| 8919 |
|
|
// checking packet
|
| 8920 |
|
|
check_tx_packet(`MEMORY_BASE, 0, i_length, tmp);
|
| 8921 |
|
|
if (tmp > 0)
|
| 8922 |
|
|
begin
|
| 8923 |
|
|
test_fail("Wrong data of the transmitted packet");
|
| 8924 |
|
|
fail = fail + 1;
|
| 8925 |
|
|
end
|
| 8926 |
|
|
// check transmited TX packet CRC
|
| 8927 |
|
|
check_tx_crc(0, i_length, 1'b0, tmp); // length without CRC
|
| 8928 |
|
|
if (tmp > 0)
|
| 8929 |
|
|
begin
|
| 8930 |
|
|
test_fail("Wrong CRC of the transmitted packet");
|
| 8931 |
|
|
fail = fail + 1;
|
| 8932 |
|
|
end
|
| 8933 |
|
|
// check WB INT signal
|
| 8934 |
|
|
if (wb_int !== 1'b1)
|
| 8935 |
|
|
begin
|
| 8936 |
|
|
`TIME; $display("*E WB INT signal should be set");
|
| 8937 |
|
|
test_fail("WB INT signal should be set");
|
| 8938 |
|
|
fail = fail + 1;
|
| 8939 |
|
|
end
|
| 8940 |
|
|
// check TX buffer descriptor of a packet
|
| 8941 |
|
|
check_tx_bd(num_of_bd, data);
|
| 8942 |
|
|
if ( ((data[15:0] !== 16'h7800) && (num_of_bd == 2)) || // wrap bit
|
| 8943 |
|
|
((data[15:0] !== 16'h5800) && (num_of_bd < 2)) ) // without wrap bit
|
| 8944 |
|
|
begin
|
| 8945 |
|
|
`TIME; $display("*E TX buffer descriptor status is not correct: %0h", data[15:0]);
|
| 8946 |
|
|
test_fail("TX buffer descriptor status is not correct");
|
| 8947 |
|
|
fail = fail + 1;
|
| 8948 |
|
|
end
|
| 8949 |
|
|
// check interrupts
|
| 8950 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 8951 |
209 |
tadejm |
wbm_read(`ETH_INT, data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 8952 |
|
|
if ((data & `ETH_INT_TXB) !== 1'b1)
|
| 8953 |
|
|
begin
|
| 8954 |
|
|
`TIME; $display("*E Interrupt Transmit Buffer was not set, interrupt reg: %0h", data);
|
| 8955 |
|
|
test_fail("Interrupt Transmit Buffer was not set");
|
| 8956 |
|
|
fail = fail + 1;
|
| 8957 |
|
|
end
|
| 8958 |
|
|
if ((data & (~`ETH_INT_TXB)) !== 0)
|
| 8959 |
|
|
begin
|
| 8960 |
|
|
`TIME; $display("*E Other interrupts (except Transmit Buffer) were set, interrupt reg: %0h", data);
|
| 8961 |
|
|
test_fail("Other interrupts (except Transmit Buffer) were set");
|
| 8962 |
|
|
fail = fail + 1;
|
| 8963 |
|
|
end
|
| 8964 |
|
|
// clear interrupts
|
| 8965 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 8966 |
209 |
tadejm |
wbm_write(`ETH_INT, data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 8967 |
|
|
// check WB INT signal
|
| 8968 |
|
|
if (wb_int !== 1'b0)
|
| 8969 |
|
|
begin
|
| 8970 |
|
|
test_fail("WB INT signal should not be set");
|
| 8971 |
|
|
fail = fail + 1;
|
| 8972 |
|
|
end
|
| 8973 |
|
|
// INTERMEDIATE DISPLAYS
|
| 8974 |
|
|
if (num_of_bd == 0)
|
| 8975 |
|
|
$display(" ->packet with length %0d sent", (i_length + 4));
|
| 8976 |
|
|
else if (num_of_bd == 1)
|
| 8977 |
|
|
$display(" ->packet with length %0d sent", (i_length + 4));
|
| 8978 |
|
|
else if (num_of_bd == 2)
|
| 8979 |
|
|
$display(" ->packet with length %0d sent", (i_length + 4));
|
| 8980 |
|
|
// set length (loop variable)
|
| 8981 |
|
|
i_length = i_length + 1;
|
| 8982 |
|
|
// the number of frame transmitted
|
| 8983 |
|
|
num_of_frames = num_of_frames + 1;
|
| 8984 |
|
|
num_of_bd = num_of_bd + 1;
|
| 8985 |
|
|
@(posedge wb_clk);
|
| 8986 |
|
|
end
|
| 8987 |
|
|
// disable TX
|
| 8988 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 8989 |
209 |
tadejm |
wbm_write(`ETH_MODER, `ETH_MODER_FULLD | `ETH_MODER_PAD | `ETH_MODER_CRCEN,
|
| 8990 |
|
|
4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 8991 |
|
|
@(posedge wb_clk);
|
| 8992 |
|
|
if(fail == 0)
|
| 8993 |
|
|
test_ok;
|
| 8994 |
|
|
else
|
| 8995 |
|
|
fail = 0;
|
| 8996 |
|
|
end
|
| 8997 |
|
|
|
| 8998 |
|
|
|
| 8999 |
|
|
////////////////////////////////////////////////////////////////////
|
| 9000 |
|
|
//// ////
|
| 9001 |
|
|
//// Test transmit packets across changed MINFL value at ////
|
| 9002 |
|
|
//// 7 TX buffer decriptors ( 100Mbps ). ////
|
| 9003 |
|
|
//// ////
|
| 9004 |
|
|
////////////////////////////////////////////////////////////////////
|
| 9005 |
|
|
if (test_num == 15) // without and with padding
|
| 9006 |
|
|
begin
|
| 9007 |
|
|
// TEST 15: TRANSMIT PACKETS ACROSS CHANGED MINFL VALUE AT 7 TX BDs ( 100Mbps )
|
| 9008 |
|
|
test_name = "TEST 15: TRANSMIT PACKETS ACROSS CHANGED MINFL VALUE AT 7 TX BDs ( 100Mbps )";
|
| 9009 |
|
|
`TIME; $display(" TEST 15: TRANSMIT PACKETS ACROSS CHANGED MINFL VALUE AT 7 TX BDs ( 100Mbps )");
|
| 9010 |
|
|
|
| 9011 |
|
|
// reset MAC registers
|
| 9012 |
|
|
hard_reset;
|
| 9013 |
|
|
// reset MAC and MII LOGIC with soft reset
|
| 9014 |
274 |
tadejm |
// reset_mac;
|
| 9015 |
|
|
// reset_mii;
|
| 9016 |
209 |
tadejm |
// set wb slave response
|
| 9017 |
|
|
wb_slave.cycle_response(`ACK_RESPONSE, wbs_waits, wbs_retries);
|
| 9018 |
|
|
|
| 9019 |
|
|
max_tmp = 0;
|
| 9020 |
|
|
min_tmp = 0;
|
| 9021 |
|
|
num_of_frames = 0;
|
| 9022 |
|
|
num_of_bd = 0;
|
| 9023 |
|
|
// set 7 TX buffer descriptors - must be set before TX enable
|
| 9024 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 9025 |
209 |
tadejm |
wbm_write(`ETH_TX_BD_NUM, 32'h7, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 9026 |
|
|
// prepare a packet of MAXFL + 10 length
|
| 9027 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 9028 |
209 |
tadejm |
wbm_read(`ETH_PACKETLEN, tmp, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 9029 |
|
|
max_tmp = tmp[15:0]; // 18 bytes consists of 6B dest addr, 6B source addr, 2B type/len, 4B CRC
|
| 9030 |
|
|
min_tmp = tmp[31:16];
|
| 9031 |
|
|
// change MINFL value
|
| 9032 |
|
|
min_tmp = max_tmp - 177;
|
| 9033 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 9034 |
209 |
tadejm |
wbm_write(`ETH_PACKETLEN, {min_tmp, max_tmp}, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 9035 |
|
|
st_data = 8'h62;
|
| 9036 |
|
|
set_tx_packet(`MEMORY_BASE, min_tmp, st_data); // length without CRC
|
| 9037 |
|
|
// enable TX, set full-duplex mode, padding and CRC appending
|
| 9038 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 9039 |
209 |
tadejm |
wbm_write(`ETH_MODER, `ETH_MODER_TXEN | `ETH_MODER_PAD | `ETH_MODER_FULLD | `ETH_MODER_CRCEN,
|
| 9040 |
|
|
4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 9041 |
|
|
// check WB INT signal
|
| 9042 |
|
|
if (wb_int !== 1'b0)
|
| 9043 |
|
|
begin
|
| 9044 |
|
|
test_fail("WB INT signal should not be set");
|
| 9045 |
|
|
fail = fail + 1;
|
| 9046 |
|
|
end
|
| 9047 |
|
|
|
| 9048 |
|
|
// write to phy's control register for 100Mbps
|
| 9049 |
|
|
#Tp eth_phy.control_bit14_10 = 5'b01000; // bit 13 set - speed 100
|
| 9050 |
|
|
#Tp eth_phy.control_bit8_0 = 9'h1_00; // bit 6 reset - (10/100), bit 8 set - FD
|
| 9051 |
|
|
speed = 100;
|
| 9052 |
|
|
|
| 9053 |
|
|
i_length = (min_tmp - 5);
|
| 9054 |
|
|
while (i_length <= (min_tmp - 3)) // (min_tmp - 4) is the limit
|
| 9055 |
|
|
begin
|
| 9056 |
|
|
$display(" i_length = %0d", i_length);
|
| 9057 |
|
|
// Reset_tx_bd nable interrupt generation
|
| 9058 |
|
|
// unmask interrupts
|
| 9059 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 9060 |
209 |
tadejm |
wbm_write(`ETH_INT_MASK, `ETH_INT_TXB | `ETH_INT_TXE | `ETH_INT_RXB | `ETH_INT_RXE | `ETH_INT_BUSY |
|
| 9061 |
|
|
`ETH_INT_TXC | `ETH_INT_RXC, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 9062 |
|
|
// not detect carrier sense in FD and no collision
|
| 9063 |
|
|
eth_phy.carrier_sense_tx_fd_detect(0);
|
| 9064 |
|
|
eth_phy.collision(0);
|
| 9065 |
|
|
// first destination address on ethernet PHY
|
| 9066 |
|
|
eth_phy.set_tx_mem_addr(0);
|
| 9067 |
|
|
// prepare BDs
|
| 9068 |
|
|
if (num_of_bd == 0)
|
| 9069 |
|
|
begin
|
| 9070 |
|
|
set_tx_bd(0, 0, i_length, 1'b1, 1'b1, 1'b1, `MEMORY_BASE);
|
| 9071 |
|
|
set_tx_bd(1, 1, i_length+1, 1'b1, 1'b1, 1'b1, `MEMORY_BASE);
|
| 9072 |
|
|
set_tx_bd(2, 2, i_length+2, 1'b1, 1'b1, 1'b1, `MEMORY_BASE);
|
| 9073 |
|
|
set_tx_bd_wrap(2);
|
| 9074 |
|
|
set_tx_bd_ready(0, 0);
|
| 9075 |
|
|
end
|
| 9076 |
|
|
else if (num_of_bd == 1)
|
| 9077 |
|
|
set_tx_bd_ready(1, 1);
|
| 9078 |
|
|
else if (num_of_bd == 2)
|
| 9079 |
|
|
set_tx_bd_ready(2, 2);
|
| 9080 |
|
|
// CHECK END OF TRANSMITION
|
| 9081 |
|
|
check_tx_bd(num_of_bd, data);
|
| 9082 |
|
|
wait (MTxEn === 1'b1); // start transmit
|
| 9083 |
|
|
check_tx_bd(num_of_bd, data);
|
| 9084 |
|
|
if (data[15] !== 1)
|
| 9085 |
|
|
begin
|
| 9086 |
|
|
test_fail("Wrong buffer descriptor's ready bit read out from MAC");
|
| 9087 |
|
|
fail = fail + 1;
|
| 9088 |
|
|
end
|
| 9089 |
|
|
wait (MTxEn === 1'b0); // end transmit
|
| 9090 |
|
|
while (data[15] === 1)
|
| 9091 |
|
|
begin
|
| 9092 |
|
|
check_tx_bd(num_of_bd, data);
|
| 9093 |
|
|
@(posedge wb_clk);
|
| 9094 |
|
|
end
|
| 9095 |
|
|
repeat (1) @(posedge wb_clk);
|
| 9096 |
|
|
// check length of a PACKET
|
| 9097 |
|
|
$display(" eth_phy length = %0d", eth_phy.tx_len);
|
| 9098 |
|
|
tmp_len = eth_phy.tx_len;
|
| 9099 |
|
|
#1;
|
| 9100 |
|
|
if (tmp_len != (i_length + 4))
|
| 9101 |
|
|
begin
|
| 9102 |
|
|
test_fail("Wrong length of the packet out from MAC");
|
| 9103 |
|
|
fail = fail + 1;
|
| 9104 |
|
|
end
|
| 9105 |
|
|
// checking packet
|
| 9106 |
|
|
check_tx_packet(`MEMORY_BASE, 0, i_length, tmp);
|
| 9107 |
|
|
if (tmp > 0)
|
| 9108 |
|
|
begin
|
| 9109 |
|
|
test_fail("Wrong data of the transmitted packet");
|
| 9110 |
|
|
fail = fail + 1;
|
| 9111 |
|
|
end
|
| 9112 |
|
|
// check transmited TX packet CRC
|
| 9113 |
|
|
check_tx_crc(0, i_length, 1'b0, tmp); // length without CRC
|
| 9114 |
|
|
if (tmp > 0)
|
| 9115 |
|
|
begin
|
| 9116 |
|
|
test_fail("Wrong CRC of the transmitted packet");
|
| 9117 |
|
|
fail = fail + 1;
|
| 9118 |
|
|
end
|
| 9119 |
|
|
// check WB INT signal
|
| 9120 |
|
|
if (wb_int !== 1'b1)
|
| 9121 |
|
|
begin
|
| 9122 |
|
|
`TIME; $display("*E WB INT signal should be set");
|
| 9123 |
|
|
test_fail("WB INT signal should be set");
|
| 9124 |
|
|
fail = fail + 1;
|
| 9125 |
|
|
end
|
| 9126 |
|
|
// check TX buffer descriptor of a packet
|
| 9127 |
|
|
check_tx_bd(num_of_bd, data);
|
| 9128 |
|
|
if ( ((data[15:0] !== 16'h7800) && (num_of_bd == 2)) || // wrap bit
|
| 9129 |
|
|
((data[15:0] !== 16'h5800) && (num_of_bd < 2)) ) // without wrap bit
|
| 9130 |
|
|
begin
|
| 9131 |
|
|
`TIME; $display("*E TX buffer descriptor status is not correct: %0h", data[15:0]);
|
| 9132 |
|
|
test_fail("TX buffer descriptor status is not correct");
|
| 9133 |
|
|
fail = fail + 1;
|
| 9134 |
|
|
end
|
| 9135 |
|
|
// check interrupts
|
| 9136 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 9137 |
209 |
tadejm |
wbm_read(`ETH_INT, data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 9138 |
|
|
if ((data & `ETH_INT_TXB) !== 1'b1)
|
| 9139 |
|
|
begin
|
| 9140 |
|
|
`TIME; $display("*E Interrupt Transmit Buffer was not set, interrupt reg: %0h", data);
|
| 9141 |
|
|
test_fail("Interrupt Transmit Buffer was not set");
|
| 9142 |
|
|
fail = fail + 1;
|
| 9143 |
|
|
end
|
| 9144 |
|
|
if ((data & (~`ETH_INT_TXB)) !== 0)
|
| 9145 |
|
|
begin
|
| 9146 |
|
|
`TIME; $display("*E Other interrupts (except Transmit Buffer) were set, interrupt reg: %0h", data);
|
| 9147 |
|
|
test_fail("Other interrupts (except Transmit Buffer) were set");
|
| 9148 |
|
|
fail = fail + 1;
|
| 9149 |
|
|
end
|
| 9150 |
|
|
// clear interrupts
|
| 9151 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 9152 |
209 |
tadejm |
wbm_write(`ETH_INT, data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 9153 |
|
|
// check WB INT signal
|
| 9154 |
|
|
if (wb_int !== 1'b0)
|
| 9155 |
|
|
begin
|
| 9156 |
|
|
test_fail("WB INT signal should not be set");
|
| 9157 |
|
|
fail = fail + 1;
|
| 9158 |
|
|
end
|
| 9159 |
|
|
// INTERMEDIATE DISPLAYS
|
| 9160 |
|
|
if (num_of_bd == 0)
|
| 9161 |
|
|
$display(" ->packet with length %0d sent", (i_length + 4));
|
| 9162 |
|
|
else if (num_of_bd == 1)
|
| 9163 |
|
|
$display(" ->packet with length %0d sent", (i_length + 4));
|
| 9164 |
|
|
else if (num_of_bd == 2)
|
| 9165 |
|
|
$display(" ->packet with length %0d sent", (i_length + 4));
|
| 9166 |
|
|
// set length (loop variable)
|
| 9167 |
|
|
i_length = i_length + 1;
|
| 9168 |
|
|
// the number of frame transmitted
|
| 9169 |
|
|
num_of_frames = num_of_frames + 1;
|
| 9170 |
|
|
num_of_bd = num_of_bd + 1;
|
| 9171 |
|
|
@(posedge wb_clk);
|
| 9172 |
|
|
end
|
| 9173 |
|
|
// disable TX
|
| 9174 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 9175 |
209 |
tadejm |
wbm_write(`ETH_MODER, `ETH_MODER_FULLD | `ETH_MODER_PAD | `ETH_MODER_CRCEN,
|
| 9176 |
|
|
4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 9177 |
|
|
@(posedge wb_clk);
|
| 9178 |
|
|
if(fail == 0)
|
| 9179 |
|
|
test_ok;
|
| 9180 |
|
|
else
|
| 9181 |
|
|
fail = 0;
|
| 9182 |
|
|
end
|
| 9183 |
|
|
|
| 9184 |
|
|
|
| 9185 |
|
|
////////////////////////////////////////////////////////////////////
|
| 9186 |
|
|
//// ////
|
| 9187 |
|
|
//// Test transmit packets across MAXFL with HUGEN at ////
|
| 9188 |
|
|
//// 19 TX buffer decriptors ( 10Mbps ). ////
|
| 9189 |
|
|
//// ////
|
| 9190 |
|
|
////////////////////////////////////////////////////////////////////
|
| 9191 |
|
|
if (test_num == 16) // without and with padding
|
| 9192 |
|
|
begin
|
| 9193 |
|
|
// TEST 16: TRANSMIT PACKETS ACROSS MAXFL WITH HUGEN AT 19 TX BDs ( 10Mbps )
|
| 9194 |
|
|
test_name = "TEST 16: TRANSMIT PACKETS ACROSS MAXFL WITH HUGEN AT 19 TX BDs ( 10Mbps )";
|
| 9195 |
|
|
`TIME; $display(" TEST 16: TRANSMIT PACKETS ACROSS MAXFL WITH HUGEN AT 19 TX BDs ( 10Mbps )");
|
| 9196 |
|
|
|
| 9197 |
|
|
// reset MAC registers
|
| 9198 |
|
|
hard_reset;
|
| 9199 |
|
|
// reset MAC and MII LOGIC with soft reset
|
| 9200 |
274 |
tadejm |
// reset_mac;
|
| 9201 |
|
|
// reset_mii;
|
| 9202 |
209 |
tadejm |
// set wb slave response
|
| 9203 |
|
|
wb_slave.cycle_response(`ACK_RESPONSE, wbs_waits, wbs_retries);
|
| 9204 |
|
|
|
| 9205 |
|
|
max_tmp = 0;
|
| 9206 |
|
|
min_tmp = 0;
|
| 9207 |
|
|
num_of_frames = 0;
|
| 9208 |
|
|
num_of_bd = 0;
|
| 9209 |
|
|
// set 19 TX buffer descriptors - must be set before TX enable
|
| 9210 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 9211 |
209 |
tadejm |
wbm_write(`ETH_TX_BD_NUM, 32'h13, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 9212 |
|
|
// prepare a packet of 64k - 1 length (16'hFFFF)
|
| 9213 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 9214 |
209 |
tadejm |
wbm_read(`ETH_PACKETLEN, tmp, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 9215 |
|
|
max_tmp = tmp[15:0]; // 18 bytes consists of 6B dest addr, 6B source addr, 2B type/len, 4B CRC
|
| 9216 |
|
|
min_tmp = tmp[31:16];
|
| 9217 |
|
|
st_data = 8'h8D;
|
| 9218 |
|
|
set_tx_packet(`MEMORY_BASE, 16'hFFFF, st_data); // length with CRC
|
| 9219 |
|
|
// enable TX, set full-duplex mode, NO padding, CRC appending and huge enabled
|
| 9220 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 9221 |
209 |
tadejm |
wbm_write(`ETH_MODER, `ETH_MODER_TXEN | `ETH_MODER_FULLD | `ETH_MODER_CRCEN | `ETH_MODER_HUGEN,
|
| 9222 |
|
|
4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 9223 |
|
|
// check WB INT signal
|
| 9224 |
|
|
if (wb_int !== 1'b0)
|
| 9225 |
|
|
begin
|
| 9226 |
|
|
test_fail("WB INT signal should not be set");
|
| 9227 |
|
|
fail = fail + 1;
|
| 9228 |
|
|
end
|
| 9229 |
|
|
|
| 9230 |
|
|
// write to phy's control register for 10Mbps
|
| 9231 |
|
|
#Tp eth_phy.control_bit14_10 = 5'b00000; // bit 13 reset - speed 10
|
| 9232 |
|
|
#Tp eth_phy.control_bit8_0 = 9'h1_00; // bit 6 reset - (10/100), bit 8 set - FD
|
| 9233 |
|
|
speed = 10;
|
| 9234 |
|
|
|
| 9235 |
|
|
i_length = (max_tmp - 5); // (max_tmp - 4) is the MAXFL limit
|
| 9236 |
|
|
while (i_length <= (16'hFFFF - 4)) // (16'hFFFF - 4) is the limit
|
| 9237 |
|
|
begin
|
| 9238 |
|
|
$display(" i_length = %0d", i_length);
|
| 9239 |
|
|
// Reset_tx_bd nable interrupt generation
|
| 9240 |
|
|
// unmask interrupts
|
| 9241 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 9242 |
209 |
tadejm |
wbm_write(`ETH_INT_MASK, `ETH_INT_TXB | `ETH_INT_TXE | `ETH_INT_RXB | `ETH_INT_RXE | `ETH_INT_BUSY |
|
| 9243 |
|
|
`ETH_INT_TXC | `ETH_INT_RXC, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 9244 |
|
|
// not detect carrier sense in FD and no collision
|
| 9245 |
|
|
eth_phy.carrier_sense_tx_fd_detect(0);
|
| 9246 |
|
|
eth_phy.collision(0);
|
| 9247 |
|
|
// first destination address on ethernet PHY
|
| 9248 |
|
|
eth_phy.set_tx_mem_addr(0);
|
| 9249 |
|
|
// prepare BDs
|
| 9250 |
|
|
if (num_of_bd == 0)
|
| 9251 |
|
|
begin
|
| 9252 |
|
|
set_tx_bd(0, 0, i_length, 1'b1, 1'b1, 1'b1, `MEMORY_BASE);
|
| 9253 |
|
|
set_tx_bd(1, 1, i_length+1, 1'b1, 1'b1, 1'b1, `MEMORY_BASE);
|
| 9254 |
|
|
set_tx_bd(2, 2, i_length+2, 1'b1, 1'b1, 1'b1, `MEMORY_BASE);
|
| 9255 |
|
|
set_tx_bd(3, 3, (16'hFFFF - 5), 1'b1, 1'b1, 1'b1, `MEMORY_BASE);
|
| 9256 |
|
|
set_tx_bd(4, 4, (16'hFFFF - 4), 1'b1, 1'b1, 1'b1, `MEMORY_BASE);
|
| 9257 |
|
|
set_tx_bd_wrap(4);
|
| 9258 |
|
|
set_tx_bd_ready(0, 0);
|
| 9259 |
|
|
end
|
| 9260 |
|
|
else if (num_of_bd == 1)
|
| 9261 |
|
|
set_tx_bd_ready(1, 1);
|
| 9262 |
|
|
else if (num_of_bd == 2)
|
| 9263 |
|
|
set_tx_bd_ready(2, 2);
|
| 9264 |
|
|
else if (num_of_bd == 3)
|
| 9265 |
|
|
set_tx_bd_ready(3, 3);
|
| 9266 |
|
|
else if (num_of_bd == 4)
|
| 9267 |
|
|
set_tx_bd_ready(4, 4);
|
| 9268 |
|
|
// CHECK END OF TRANSMITION
|
| 9269 |
|
|
check_tx_bd(num_of_bd, data);
|
| 9270 |
|
|
wait (MTxEn === 1'b1); // start transmit
|
| 9271 |
|
|
check_tx_bd(num_of_bd, data);
|
| 9272 |
|
|
if (data[15] !== 1)
|
| 9273 |
|
|
begin
|
| 9274 |
|
|
test_fail("Wrong buffer descriptor's ready bit read out from MAC");
|
| 9275 |
|
|
fail = fail + 1;
|
| 9276 |
|
|
end
|
| 9277 |
|
|
wait (MTxEn === 1'b0); // end transmit
|
| 9278 |
|
|
while (data[15] === 1)
|
| 9279 |
|
|
begin
|
| 9280 |
|
|
check_tx_bd(num_of_bd, data);
|
| 9281 |
|
|
@(posedge wb_clk);
|
| 9282 |
|
|
end
|
| 9283 |
|
|
repeat (1) @(posedge wb_clk);
|
| 9284 |
|
|
// check length of a PACKET
|
| 9285 |
|
|
$display(" eth_phy length = %0d", eth_phy.tx_len);
|
| 9286 |
|
|
tmp_len = eth_phy.tx_len;
|
| 9287 |
|
|
#1;
|
| 9288 |
|
|
if (tmp_len != (i_length + 4))
|
| 9289 |
|
|
begin
|
| 9290 |
|
|
test_fail("Wrong length of the packet out from MAC");
|
| 9291 |
|
|
fail = fail + 1;
|
| 9292 |
|
|
end
|
| 9293 |
|
|
// checking packet
|
| 9294 |
|
|
check_tx_packet(`MEMORY_BASE, 0, i_length, tmp);
|
| 9295 |
|
|
if (tmp > 0)
|
| 9296 |
|
|
begin
|
| 9297 |
|
|
test_fail("Wrong data of the transmitted packet");
|
| 9298 |
|
|
fail = fail + 1;
|
| 9299 |
|
|
end
|
| 9300 |
|
|
// check transmited TX packet CRC
|
| 9301 |
|
|
check_tx_crc(0, i_length, 1'b0, tmp); // length without CRC
|
| 9302 |
|
|
if (tmp > 0)
|
| 9303 |
|
|
begin
|
| 9304 |
|
|
test_fail("Wrong CRC of the transmitted packet");
|
| 9305 |
|
|
fail = fail + 1;
|
| 9306 |
|
|
end
|
| 9307 |
|
|
// check WB INT signal
|
| 9308 |
|
|
if (wb_int !== 1'b1)
|
| 9309 |
|
|
begin
|
| 9310 |
|
|
`TIME; $display("*E WB INT signal should be set");
|
| 9311 |
|
|
test_fail("WB INT signal should be set");
|
| 9312 |
|
|
fail = fail + 1;
|
| 9313 |
|
|
end
|
| 9314 |
|
|
// check TX buffer descriptor of a packet
|
| 9315 |
|
|
check_tx_bd(num_of_bd, data);
|
| 9316 |
|
|
if ( ((data[15:0] !== 16'h7800) && (num_of_bd == 4)) || // wrap bit
|
| 9317 |
|
|
((data[15:0] !== 16'h5800) && (num_of_bd < 4)) ) // without wrap bit
|
| 9318 |
|
|
begin
|
| 9319 |
|
|
`TIME; $display("*E TX buffer descriptor status is not correct: %0h", data[15:0]);
|
| 9320 |
|
|
test_fail("TX buffer descriptor status is not correct");
|
| 9321 |
|
|
fail = fail + 1;
|
| 9322 |
|
|
end
|
| 9323 |
|
|
// check interrupts
|
| 9324 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 9325 |
209 |
tadejm |
wbm_read(`ETH_INT, data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 9326 |
|
|
if ((data & `ETH_INT_TXB) !== 1'b1)
|
| 9327 |
|
|
begin
|
| 9328 |
|
|
`TIME; $display("*E Interrupt Transmit Buffer was not set, interrupt reg: %0h", data);
|
| 9329 |
|
|
test_fail("Interrupt Transmit Buffer was not set");
|
| 9330 |
|
|
fail = fail + 1;
|
| 9331 |
|
|
end
|
| 9332 |
|
|
if ((data & (~`ETH_INT_TXB)) !== 0)
|
| 9333 |
|
|
begin
|
| 9334 |
|
|
`TIME; $display("*E Other interrupts (except Transmit Buffer) were set, interrupt reg: %0h", data);
|
| 9335 |
|
|
test_fail("Other interrupts (except Transmit Buffer) were set");
|
| 9336 |
|
|
fail = fail + 1;
|
| 9337 |
|
|
end
|
| 9338 |
|
|
// clear interrupts
|
| 9339 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 9340 |
209 |
tadejm |
wbm_write(`ETH_INT, data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 9341 |
|
|
// check WB INT signal
|
| 9342 |
|
|
if (wb_int !== 1'b0)
|
| 9343 |
|
|
begin
|
| 9344 |
|
|
test_fail("WB INT signal should not be set");
|
| 9345 |
|
|
fail = fail + 1;
|
| 9346 |
|
|
end
|
| 9347 |
|
|
// INTERMEDIATE DISPLAYS
|
| 9348 |
|
|
$display(" ->packet with length %0d sent", (i_length + 4));
|
| 9349 |
|
|
// set length (loop variable)
|
| 9350 |
|
|
if ((num_of_bd < 2) || (num_of_bd >= 3))
|
| 9351 |
|
|
i_length = i_length + 1;
|
| 9352 |
|
|
else if (num_of_bd == 2)
|
| 9353 |
|
|
i_length = (16'hFFFF - 5);
|
| 9354 |
|
|
// the number of frame transmitted
|
| 9355 |
|
|
num_of_frames = num_of_frames + 1;
|
| 9356 |
|
|
num_of_bd = num_of_bd + 1;
|
| 9357 |
|
|
@(posedge wb_clk);
|
| 9358 |
|
|
end
|
| 9359 |
|
|
// disable TX
|
| 9360 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 9361 |
209 |
tadejm |
wbm_write(`ETH_MODER, `ETH_MODER_FULLD | `ETH_MODER_PAD | `ETH_MODER_CRCEN,
|
| 9362 |
|
|
4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 9363 |
|
|
@(posedge wb_clk);
|
| 9364 |
|
|
if(fail == 0)
|
| 9365 |
|
|
test_ok;
|
| 9366 |
|
|
else
|
| 9367 |
|
|
fail = 0;
|
| 9368 |
|
|
end
|
| 9369 |
|
|
|
| 9370 |
|
|
|
| 9371 |
|
|
////////////////////////////////////////////////////////////////////
|
| 9372 |
|
|
//// ////
|
| 9373 |
|
|
//// Test transmit packets across MAXFL with HUGEN at ////
|
| 9374 |
|
|
//// 19 TX buffer decriptors ( 100Mbps ). ////
|
| 9375 |
|
|
//// ////
|
| 9376 |
|
|
////////////////////////////////////////////////////////////////////
|
| 9377 |
|
|
if (test_num == 17) // without and with padding
|
| 9378 |
|
|
begin
|
| 9379 |
|
|
// TEST 17: TRANSMIT PACKETS ACROSS MAXFL WITH HUGEN AT 19 TX BDs ( 100Mbps )
|
| 9380 |
|
|
test_name = "TEST 17: TRANSMIT PACKETS ACROSS MAXFL WITH HUGEN AT 19 TX BDs ( 100Mbps )";
|
| 9381 |
|
|
`TIME; $display(" TEST 17: TRANSMIT PACKETS ACROSS MAXFL WITH HUGEN AT 19 TX BDs ( 100Mbps )");
|
| 9382 |
|
|
|
| 9383 |
|
|
// reset MAC registers
|
| 9384 |
|
|
hard_reset;
|
| 9385 |
|
|
// reset MAC and MII LOGIC with soft reset
|
| 9386 |
274 |
tadejm |
// reset_mac;
|
| 9387 |
|
|
// reset_mii;
|
| 9388 |
209 |
tadejm |
// set wb slave response
|
| 9389 |
|
|
wb_slave.cycle_response(`ACK_RESPONSE, wbs_waits, wbs_retries);
|
| 9390 |
|
|
|
| 9391 |
|
|
max_tmp = 0;
|
| 9392 |
|
|
min_tmp = 0;
|
| 9393 |
|
|
num_of_frames = 0;
|
| 9394 |
|
|
num_of_bd = 0;
|
| 9395 |
|
|
// set 19 TX buffer descriptors - must be set before TX enable
|
| 9396 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 9397 |
209 |
tadejm |
wbm_write(`ETH_TX_BD_NUM, 32'h13, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 9398 |
|
|
// prepare a packet of 64k - 1 length (16'hFFFF)
|
| 9399 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 9400 |
209 |
tadejm |
wbm_read(`ETH_PACKETLEN, tmp, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 9401 |
|
|
max_tmp = tmp[15:0]; // 18 bytes consists of 6B dest addr, 6B source addr, 2B type/len, 4B CRC
|
| 9402 |
|
|
min_tmp = tmp[31:16];
|
| 9403 |
|
|
st_data = 8'h8D;
|
| 9404 |
|
|
set_tx_packet(`MEMORY_BASE, 16'hFFFF, st_data); // length with CRC
|
| 9405 |
|
|
// enable TX, set full-duplex mode, NO padding, CRC appending and huge enabled
|
| 9406 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 9407 |
209 |
tadejm |
wbm_write(`ETH_MODER, `ETH_MODER_TXEN | `ETH_MODER_FULLD | `ETH_MODER_CRCEN | `ETH_MODER_HUGEN,
|
| 9408 |
|
|
4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 9409 |
|
|
// check WB INT signal
|
| 9410 |
|
|
if (wb_int !== 1'b0)
|
| 9411 |
|
|
begin
|
| 9412 |
|
|
test_fail("WB INT signal should not be set");
|
| 9413 |
|
|
fail = fail + 1;
|
| 9414 |
|
|
end
|
| 9415 |
|
|
|
| 9416 |
|
|
// write to phy's control register for 100Mbps
|
| 9417 |
|
|
#Tp eth_phy.control_bit14_10 = 5'b01000; // bit 13 set - speed 100
|
| 9418 |
|
|
#Tp eth_phy.control_bit8_0 = 9'h1_00; // bit 6 reset - (10/100), bit 8 set - FD
|
| 9419 |
|
|
speed = 100;
|
| 9420 |
|
|
|
| 9421 |
|
|
i_length = (max_tmp - 5); // (max_tmp - 4) is the MAXFL limit
|
| 9422 |
|
|
while (i_length <= (16'hFFFF - 4)) // (16'hFFFF - 4) is the limit
|
| 9423 |
|
|
begin
|
| 9424 |
|
|
$display(" i_length = %0d", i_length);
|
| 9425 |
|
|
// Reset_tx_bd nable interrupt generation
|
| 9426 |
|
|
// unmask interrupts
|
| 9427 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 9428 |
209 |
tadejm |
wbm_write(`ETH_INT_MASK, `ETH_INT_TXB | `ETH_INT_TXE | `ETH_INT_RXB | `ETH_INT_RXE | `ETH_INT_BUSY |
|
| 9429 |
|
|
`ETH_INT_TXC | `ETH_INT_RXC, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 9430 |
|
|
// not detect carrier sense in FD and no collision
|
| 9431 |
|
|
eth_phy.carrier_sense_tx_fd_detect(0);
|
| 9432 |
|
|
eth_phy.collision(0);
|
| 9433 |
|
|
// first destination address on ethernet PHY
|
| 9434 |
|
|
eth_phy.set_tx_mem_addr(0);
|
| 9435 |
|
|
// prepare BDs
|
| 9436 |
|
|
if (num_of_bd == 0)
|
| 9437 |
|
|
begin
|
| 9438 |
|
|
set_tx_bd(0, 0, i_length, 1'b1, 1'b1, 1'b1, `MEMORY_BASE);
|
| 9439 |
|
|
set_tx_bd(1, 1, i_length+1, 1'b1, 1'b1, 1'b1, `MEMORY_BASE);
|
| 9440 |
|
|
set_tx_bd(2, 2, i_length+2, 1'b1, 1'b1, 1'b1, `MEMORY_BASE);
|
| 9441 |
|
|
set_tx_bd(3, 3, (16'hFFFF - 5), 1'b1, 1'b1, 1'b1, `MEMORY_BASE);
|
| 9442 |
|
|
set_tx_bd(4, 4, (16'hFFFF - 4), 1'b1, 1'b1, 1'b1, `MEMORY_BASE);
|
| 9443 |
|
|
set_tx_bd_wrap(4);
|
| 9444 |
|
|
set_tx_bd_ready(0, 0);
|
| 9445 |
|
|
end
|
| 9446 |
|
|
else if (num_of_bd == 1)
|
| 9447 |
|
|
set_tx_bd_ready(1, 1);
|
| 9448 |
|
|
else if (num_of_bd == 2)
|
| 9449 |
|
|
set_tx_bd_ready(2, 2);
|
| 9450 |
|
|
else if (num_of_bd == 3)
|
| 9451 |
|
|
set_tx_bd_ready(3, 3);
|
| 9452 |
|
|
else if (num_of_bd == 4)
|
| 9453 |
|
|
set_tx_bd_ready(4, 4);
|
| 9454 |
|
|
// CHECK END OF TRANSMITION
|
| 9455 |
|
|
check_tx_bd(num_of_bd, data);
|
| 9456 |
|
|
wait (MTxEn === 1'b1); // start transmit
|
| 9457 |
|
|
check_tx_bd(num_of_bd, data);
|
| 9458 |
|
|
if (data[15] !== 1)
|
| 9459 |
|
|
begin
|
| 9460 |
|
|
test_fail("Wrong buffer descriptor's ready bit read out from MAC");
|
| 9461 |
|
|
fail = fail + 1;
|
| 9462 |
|
|
end
|
| 9463 |
|
|
wait (MTxEn === 1'b0); // end transmit
|
| 9464 |
|
|
while (data[15] === 1)
|
| 9465 |
|
|
begin
|
| 9466 |
|
|
check_tx_bd(num_of_bd, data);
|
| 9467 |
|
|
@(posedge wb_clk);
|
| 9468 |
|
|
end
|
| 9469 |
|
|
repeat (1) @(posedge wb_clk);
|
| 9470 |
|
|
// check length of a PACKET
|
| 9471 |
|
|
$display(" eth_phy length = %0d", eth_phy.tx_len);
|
| 9472 |
|
|
tmp_len = eth_phy.tx_len;
|
| 9473 |
|
|
#1;
|
| 9474 |
|
|
if (tmp_len != (i_length + 4))
|
| 9475 |
|
|
begin
|
| 9476 |
|
|
test_fail("Wrong length of the packet out from MAC");
|
| 9477 |
|
|
fail = fail + 1;
|
| 9478 |
|
|
end
|
| 9479 |
|
|
// checking packet
|
| 9480 |
|
|
check_tx_packet(`MEMORY_BASE, 0, i_length, tmp);
|
| 9481 |
|
|
if (tmp > 0)
|
| 9482 |
|
|
begin
|
| 9483 |
|
|
test_fail("Wrong data of the transmitted packet");
|
| 9484 |
|
|
fail = fail + 1;
|
| 9485 |
|
|
end
|
| 9486 |
|
|
// check transmited TX packet CRC
|
| 9487 |
|
|
check_tx_crc(0, i_length, 1'b0, tmp); // length without CRC
|
| 9488 |
|
|
if (tmp > 0)
|
| 9489 |
|
|
begin
|
| 9490 |
|
|
test_fail("Wrong CRC of the transmitted packet");
|
| 9491 |
|
|
fail = fail + 1;
|
| 9492 |
|
|
end
|
| 9493 |
|
|
// check WB INT signal
|
| 9494 |
|
|
if (wb_int !== 1'b1)
|
| 9495 |
|
|
begin
|
| 9496 |
|
|
`TIME; $display("*E WB INT signal should be set");
|
| 9497 |
|
|
test_fail("WB INT signal should be set");
|
| 9498 |
|
|
fail = fail + 1;
|
| 9499 |
|
|
end
|
| 9500 |
|
|
// check TX buffer descriptor of a packet
|
| 9501 |
|
|
check_tx_bd(num_of_bd, data);
|
| 9502 |
|
|
if ( ((data[15:0] !== 16'h7800) && (num_of_bd == 4)) || // wrap bit
|
| 9503 |
|
|
((data[15:0] !== 16'h5800) && (num_of_bd < 4)) ) // without wrap bit
|
| 9504 |
|
|
begin
|
| 9505 |
|
|
`TIME; $display("*E TX buffer descriptor status is not correct: %0h", data[15:0]);
|
| 9506 |
|
|
test_fail("TX buffer descriptor status is not correct");
|
| 9507 |
|
|
fail = fail + 1;
|
| 9508 |
|
|
end
|
| 9509 |
|
|
// check interrupts
|
| 9510 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 9511 |
209 |
tadejm |
wbm_read(`ETH_INT, data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 9512 |
|
|
if ((data & `ETH_INT_TXB) !== 1'b1)
|
| 9513 |
|
|
begin
|
| 9514 |
|
|
`TIME; $display("*E Interrupt Transmit Buffer was not set, interrupt reg: %0h", data);
|
| 9515 |
|
|
test_fail("Interrupt Transmit Buffer was not set");
|
| 9516 |
|
|
fail = fail + 1;
|
| 9517 |
|
|
end
|
| 9518 |
|
|
if ((data & (~`ETH_INT_TXB)) !== 0)
|
| 9519 |
|
|
begin
|
| 9520 |
|
|
`TIME; $display("*E Other interrupts (except Transmit Buffer) were set, interrupt reg: %0h", data);
|
| 9521 |
|
|
test_fail("Other interrupts (except Transmit Buffer) were set");
|
| 9522 |
|
|
fail = fail + 1;
|
| 9523 |
|
|
end
|
| 9524 |
|
|
// clear interrupts
|
| 9525 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 9526 |
209 |
tadejm |
wbm_write(`ETH_INT, data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 9527 |
|
|
// check WB INT signal
|
| 9528 |
|
|
if (wb_int !== 1'b0)
|
| 9529 |
|
|
begin
|
| 9530 |
|
|
test_fail("WB INT signal should not be set");
|
| 9531 |
|
|
fail = fail + 1;
|
| 9532 |
|
|
end
|
| 9533 |
|
|
// INTERMEDIATE DISPLAYS
|
| 9534 |
|
|
$display(" ->packet with length %0d sent", (i_length + 4));
|
| 9535 |
|
|
// set length (loop variable)
|
| 9536 |
|
|
if ((num_of_bd < 2) || (num_of_bd >= 3))
|
| 9537 |
|
|
i_length = i_length + 1;
|
| 9538 |
|
|
else if (num_of_bd == 2)
|
| 9539 |
|
|
i_length = (16'hFFFF - 5);
|
| 9540 |
|
|
// the number of frame transmitted
|
| 9541 |
|
|
num_of_frames = num_of_frames + 1;
|
| 9542 |
|
|
num_of_bd = num_of_bd + 1;
|
| 9543 |
|
|
@(posedge wb_clk);
|
| 9544 |
|
|
end
|
| 9545 |
|
|
// disable TX
|
| 9546 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 9547 |
209 |
tadejm |
wbm_write(`ETH_MODER, `ETH_MODER_FULLD | `ETH_MODER_PAD | `ETH_MODER_CRCEN,
|
| 9548 |
|
|
4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 9549 |
|
|
@(posedge wb_clk);
|
| 9550 |
|
|
if(fail == 0)
|
| 9551 |
|
|
test_ok;
|
| 9552 |
|
|
else
|
| 9553 |
|
|
fail = 0;
|
| 9554 |
|
|
end
|
| 9555 |
|
|
|
| 9556 |
|
|
|
| 9557 |
|
|
////////////////////////////////////////////////////////////////////
|
| 9558 |
|
|
//// ////
|
| 9559 |
|
|
//// Test IPG during Back-to-Back transmit at ////
|
| 9560 |
|
|
//// 88 TX buffer decriptors ( 10Mbps ). ////
|
| 9561 |
|
|
//// ////
|
| 9562 |
|
|
////////////////////////////////////////////////////////////////////
|
| 9563 |
|
|
if (test_num == 18) // without and with padding
|
| 9564 |
|
|
begin
|
| 9565 |
|
|
// TEST 18: IPG DURING BACK-TO-BACK TRANSMIT AT 88 TX BDs ( 10Mbps )
|
| 9566 |
|
|
test_name = "TEST 18: IPG DURING BACK-TO-BACK TRANSMIT AT 88 TX BDs ( 10Mbps )";
|
| 9567 |
|
|
`TIME; $display(" TEST 18: IPG DURING BACK-TO-BACK TRANSMIT AT 88 TX BDs ( 10Mbps )");
|
| 9568 |
|
|
|
| 9569 |
|
|
// reset MAC registers
|
| 9570 |
|
|
hard_reset;
|
| 9571 |
|
|
// reset MAC and MII LOGIC with soft reset
|
| 9572 |
274 |
tadejm |
// reset_mac;
|
| 9573 |
|
|
// reset_mii;
|
| 9574 |
209 |
tadejm |
// set wb slave response
|
| 9575 |
|
|
wb_slave.cycle_response(`ACK_RESPONSE, wbs_waits, wbs_retries);
|
| 9576 |
|
|
|
| 9577 |
|
|
max_tmp = 0;
|
| 9578 |
|
|
min_tmp = 0;
|
| 9579 |
|
|
num_of_frames = 0;
|
| 9580 |
|
|
num_of_bd = 0;
|
| 9581 |
|
|
tmp_ipgt = 0;
|
| 9582 |
|
|
// set 88 TX buffer descriptors - must be set before TX enable
|
| 9583 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 9584 |
209 |
tadejm |
wbm_write(`ETH_TX_BD_NUM, 32'h58, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 9585 |
|
|
// enable TX, set full-duplex mode, NO padding and CRC appending
|
| 9586 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 9587 |
209 |
tadejm |
wbm_write(`ETH_MODER, `ETH_MODER_TXEN | `ETH_MODER_FULLD | `ETH_MODER_CRCEN,
|
| 9588 |
|
|
4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 9589 |
|
|
// prepare two packets of MAXFL length
|
| 9590 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 9591 |
209 |
tadejm |
wbm_read(`ETH_PACKETLEN, tmp, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 9592 |
|
|
max_tmp = tmp[15:0]; // 18 bytes consists of 6B dest addr, 6B source addr, 2B type/len, 4B CRC
|
| 9593 |
|
|
min_tmp = tmp[31:16];
|
| 9594 |
|
|
st_data = 8'h29;
|
| 9595 |
|
|
set_tx_packet(`MEMORY_BASE, (max_tmp - 4), st_data); // length without CRC
|
| 9596 |
|
|
// check WB INT signal
|
| 9597 |
|
|
if (wb_int !== 1'b0)
|
| 9598 |
|
|
begin
|
| 9599 |
|
|
test_fail("WB INT signal should not be set");
|
| 9600 |
|
|
fail = fail + 1;
|
| 9601 |
|
|
end
|
| 9602 |
|
|
|
| 9603 |
|
|
// write to phy's control register for 10Mbps
|
| 9604 |
|
|
#Tp eth_phy.control_bit14_10 = 5'b00000; // bit 13 reset - speed 10
|
| 9605 |
|
|
#Tp eth_phy.control_bit8_0 = 9'h1_00; // bit 6 reset - (10/100), bit 8 set - FD
|
| 9606 |
|
|
speed = 10;
|
| 9607 |
|
|
|
| 9608 |
|
|
i_length = (min_tmp - 4);
|
| 9609 |
|
|
while (i_length < (max_tmp - 4))
|
| 9610 |
|
|
begin
|
| 9611 |
|
|
// disable TX, set full-duplex mode, NO padding and CRC appending
|
| 9612 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 9613 |
209 |
tadejm |
wbm_write(`ETH_MODER, `ETH_MODER_FULLD | `ETH_MODER_CRCEN,
|
| 9614 |
|
|
4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 9615 |
|
|
// set IPGT register
|
| 9616 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 9617 |
209 |
tadejm |
wbm_write(`ETH_IPGT, tmp_ipgt, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 9618 |
|
|
// enable TX, set full-duplex mode, NO padding and CRC appending
|
| 9619 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 9620 |
209 |
tadejm |
wbm_write(`ETH_MODER, `ETH_MODER_TXEN | `ETH_MODER_FULLD | `ETH_MODER_CRCEN,
|
| 9621 |
|
|
4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 9622 |
|
|
// Reset_tx_bd enable interrupt generation
|
| 9623 |
|
|
// unmask interrupts
|
| 9624 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 9625 |
209 |
tadejm |
wbm_write(`ETH_INT_MASK, `ETH_INT_TXB | `ETH_INT_TXE | `ETH_INT_RXB | `ETH_INT_RXE | `ETH_INT_BUSY |
|
| 9626 |
|
|
`ETH_INT_TXC | `ETH_INT_RXC, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 9627 |
|
|
// not detect carrier sense in FD and no collision
|
| 9628 |
|
|
eth_phy.carrier_sense_tx_fd_detect(0);
|
| 9629 |
|
|
eth_phy.collision(0);
|
| 9630 |
|
|
// first destination address on ethernet PHY
|
| 9631 |
|
|
eth_phy.set_tx_mem_addr(0);
|
| 9632 |
|
|
// prepare BDs
|
| 9633 |
|
|
if (num_of_bd == 0)
|
| 9634 |
|
|
begin
|
| 9635 |
|
|
set_tx_bd(0, 0, i_length, 1'b1, 1'b1, 1'b1, `MEMORY_BASE);
|
| 9636 |
|
|
set_tx_bd(1, 1, i_length+1, 1'b1, 1'b1, 1'b1, `MEMORY_BASE);
|
| 9637 |
|
|
set_tx_bd_wrap(1);
|
| 9638 |
|
|
set_tx_bd_ready(0, 0);
|
| 9639 |
|
|
set_tx_bd_ready(1, 1);
|
| 9640 |
|
|
end
|
| 9641 |
|
|
// CHECK END OF TWO TRANSMITIONs
|
| 9642 |
|
|
// wait for first transmit to end
|
| 9643 |
|
|
check_tx_bd(num_of_bd, data);
|
| 9644 |
|
|
wait (MTxEn === 1'b1); // start transmit
|
| 9645 |
|
|
if (data[15] !== 1)
|
| 9646 |
|
|
begin
|
| 9647 |
|
|
test_fail("Wrong buffer descriptor's ready bit read out from MAC");
|
| 9648 |
|
|
fail = fail + 1;
|
| 9649 |
|
|
end
|
| 9650 |
|
|
wait (MTxEn === 1'b0); // end transmit
|
| 9651 |
|
|
num_of_frames = num_of_frames + 1;
|
| 9652 |
|
|
num_of_bd = num_of_bd + 1;
|
| 9653 |
|
|
#Tp;
|
| 9654 |
|
|
// destination address on ethernet PHY
|
| 9655 |
|
|
eth_phy.set_tx_mem_addr(0);
|
| 9656 |
|
|
i1 = 0;
|
| 9657 |
|
|
i2 = 0;
|
| 9658 |
|
|
// count IPG clock periods
|
| 9659 |
|
|
fork
|
| 9660 |
|
|
begin
|
| 9661 |
|
|
wait (MTxEn === 1'b1); // start second transmit
|
| 9662 |
|
|
#Tp;
|
| 9663 |
|
|
disable count_rising;
|
| 9664 |
|
|
disable count_falling;
|
| 9665 |
|
|
end
|
| 9666 |
|
|
begin: count_rising
|
| 9667 |
|
|
forever
|
| 9668 |
|
|
begin
|
| 9669 |
|
|
@(posedge mtx_clk);
|
| 9670 |
|
|
i1 = i1 + 1;
|
| 9671 |
|
|
#Tp;
|
| 9672 |
|
|
end
|
| 9673 |
|
|
end
|
| 9674 |
|
|
begin: count_falling
|
| 9675 |
|
|
forever
|
| 9676 |
|
|
begin
|
| 9677 |
|
|
@(negedge mtx_clk);
|
| 9678 |
|
|
i2 = i2 + 1;
|
| 9679 |
|
|
#Tp;
|
| 9680 |
|
|
end
|
| 9681 |
|
|
end
|
| 9682 |
|
|
join
|
| 9683 |
|
|
// check IPG length - INTERMEDIATE DISPLAYS
|
| 9684 |
|
|
if((i1 == i2) && (i1 >= (tmp_ipgt + 3)))
|
| 9685 |
|
|
begin
|
| 9686 |
|
|
$display(" ->IPG with %0d mtx_clk periods (min %0d) between packets with lengths %0d and %0d checked",
|
| 9687 |
|
|
i1, (tmp_ipgt + 3), (i_length + 4), (i_length + 4 + 1));
|
| 9688 |
|
|
end
|
| 9689 |
|
|
else
|
| 9690 |
|
|
begin
|
| 9691 |
|
|
`TIME; $display("*E IPG is not correct: (%0d + %0d) / 2, requested: %d", i1, i2, (tmp_ipgt + 3));
|
| 9692 |
|
|
fail = fail + 1;
|
| 9693 |
|
|
test_fail("IPG is not correct");
|
| 9694 |
|
|
end
|
| 9695 |
|
|
// wait for second transmit to end
|
| 9696 |
|
|
wait (MTxEn === 1'b0); // end second transmit
|
| 9697 |
|
|
while (data[15] === 1)
|
| 9698 |
|
|
begin
|
| 9699 |
|
|
check_tx_bd(num_of_bd, data);
|
| 9700 |
|
|
@(posedge wb_clk);
|
| 9701 |
|
|
end
|
| 9702 |
|
|
repeat (1) @(posedge wb_clk);
|
| 9703 |
|
|
// check length of a second PACKET
|
| 9704 |
|
|
tmp_len = eth_phy.tx_len;
|
| 9705 |
|
|
#1;
|
| 9706 |
|
|
if (tmp_len != (i_length + 4 + 1))
|
| 9707 |
|
|
begin
|
| 9708 |
|
|
test_fail("Wrong length of second packet out from MAC");
|
| 9709 |
|
|
fail = fail + 1;
|
| 9710 |
|
|
end
|
| 9711 |
|
|
// checking second packet
|
| 9712 |
|
|
check_tx_packet(`MEMORY_BASE, 0, (i_length + 1), tmp);
|
| 9713 |
|
|
if (tmp > 0)
|
| 9714 |
|
|
begin
|
| 9715 |
|
|
test_fail("Wrong data of second transmitted packet");
|
| 9716 |
|
|
fail = fail + 1;
|
| 9717 |
|
|
end
|
| 9718 |
|
|
// check second transmited TX packet CRC
|
| 9719 |
|
|
check_tx_crc(0, (i_length + 1), 1'b0, tmp); // length without CRC
|
| 9720 |
|
|
if (tmp > 0)
|
| 9721 |
|
|
begin
|
| 9722 |
|
|
test_fail("Wrong CRC of second transmitted packet");
|
| 9723 |
|
|
fail = fail + 1;
|
| 9724 |
|
|
end
|
| 9725 |
|
|
// check WB INT signal
|
| 9726 |
|
|
if (wb_int !== 1'b1)
|
| 9727 |
|
|
begin
|
| 9728 |
|
|
`TIME; $display("*E WB INT signal should be set");
|
| 9729 |
|
|
test_fail("WB INT signal should be set");
|
| 9730 |
|
|
fail = fail + 1;
|
| 9731 |
|
|
end
|
| 9732 |
|
|
// check TX buffer descriptor of a packet
|
| 9733 |
|
|
check_tx_bd(num_of_bd, data);
|
| 9734 |
|
|
if ( ((data[15:0] !== 16'h7800) && (num_of_bd == 1)) || // wrap bit
|
| 9735 |
|
|
((data[15:0] !== 16'h5800) && (num_of_bd < 1)) ) // without wrap bit
|
| 9736 |
|
|
begin
|
| 9737 |
|
|
`TIME; $display("*E TX buffer descriptor status is not correct: %0h", data[15:0]);
|
| 9738 |
|
|
test_fail("TX buffer descriptor status is not correct");
|
| 9739 |
|
|
fail = fail + 1;
|
| 9740 |
|
|
end
|
| 9741 |
|
|
// check interrupts
|
| 9742 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 9743 |
209 |
tadejm |
wbm_read(`ETH_INT, data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 9744 |
|
|
if ((data & `ETH_INT_TXB) !== 1'b1)
|
| 9745 |
|
|
begin
|
| 9746 |
|
|
`TIME; $display("*E Interrupt Transmit Buffer was not set, interrupt reg: %0h", data);
|
| 9747 |
|
|
test_fail("Interrupt Transmit Buffer was not set");
|
| 9748 |
|
|
fail = fail + 1;
|
| 9749 |
|
|
end
|
| 9750 |
|
|
if ((data & (~`ETH_INT_TXB)) !== 0)
|
| 9751 |
|
|
begin
|
| 9752 |
|
|
`TIME; $display("*E Other interrupts (except Transmit Buffer) were set, interrupt reg: %0h", data);
|
| 9753 |
|
|
test_fail("Other interrupts (except Transmit Buffer) were set");
|
| 9754 |
|
|
fail = fail + 1;
|
| 9755 |
|
|
end
|
| 9756 |
|
|
// clear interrupts
|
| 9757 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 9758 |
209 |
tadejm |
wbm_write(`ETH_INT, data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 9759 |
|
|
// check WB INT signal
|
| 9760 |
|
|
if (wb_int !== 1'b0)
|
| 9761 |
|
|
begin
|
| 9762 |
|
|
test_fail("WB INT signal should not be set");
|
| 9763 |
|
|
fail = fail + 1;
|
| 9764 |
|
|
end
|
| 9765 |
|
|
// set length (LOOP variable)
|
| 9766 |
|
|
if ((tmp_ipgt + 3) < 130) // tmp_ipgt < 124
|
| 9767 |
|
|
i_length = i_length + 2;
|
| 9768 |
|
|
else
|
| 9769 |
|
|
i_length = (max_tmp - 4);
|
| 9770 |
|
|
// set IPGT
|
| 9771 |
|
|
if ((tmp_ipgt + 3) < 10)
|
| 9772 |
|
|
tmp_ipgt = tmp_ipgt + 1;
|
| 9773 |
|
|
else if ((tmp_ipgt + 3) < 24)
|
| 9774 |
|
|
tmp_ipgt = tmp_ipgt + 7;
|
| 9775 |
|
|
else if ((tmp_ipgt + 3) == 24)
|
| 9776 |
|
|
tmp_ipgt = 38 - 3;
|
| 9777 |
|
|
else if ((tmp_ipgt + 3) == 38)
|
| 9778 |
|
|
tmp_ipgt = 72 - 3;
|
| 9779 |
|
|
else if ((tmp_ipgt + 3) == 72)
|
| 9780 |
|
|
tmp_ipgt = 130 - 3; // 124 - 3
|
| 9781 |
|
|
// the number of frame transmitted
|
| 9782 |
|
|
num_of_frames = num_of_frames + 1;
|
| 9783 |
|
|
num_of_bd = 0;
|
| 9784 |
|
|
@(posedge wb_clk);
|
| 9785 |
|
|
end
|
| 9786 |
|
|
// disable TX
|
| 9787 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 9788 |
209 |
tadejm |
wbm_write(`ETH_MODER, `ETH_MODER_FULLD | `ETH_MODER_PAD | `ETH_MODER_CRCEN,
|
| 9789 |
|
|
4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 9790 |
|
|
@(posedge wb_clk);
|
| 9791 |
|
|
if(fail == 0)
|
| 9792 |
|
|
test_ok;
|
| 9793 |
|
|
else
|
| 9794 |
|
|
fail = 0;
|
| 9795 |
|
|
end
|
| 9796 |
|
|
|
| 9797 |
|
|
|
| 9798 |
|
|
////////////////////////////////////////////////////////////////////
|
| 9799 |
|
|
//// ////
|
| 9800 |
|
|
//// Test IPG during Back-to-Back transmit at ////
|
| 9801 |
|
|
//// 88 TX buffer decriptors ( 100Mbps ). ////
|
| 9802 |
|
|
//// ////
|
| 9803 |
|
|
////////////////////////////////////////////////////////////////////
|
| 9804 |
|
|
if (test_num == 19) // without and with padding
|
| 9805 |
|
|
begin
|
| 9806 |
|
|
// TEST 19: IPG DURING BACK-TO-BACK TRANSMIT AT 88 TX BDs ( 100Mbps )
|
| 9807 |
|
|
test_name = "TEST 19: IPG DURING BACK-TO-BACK TRANSMIT AT 88 TX BDs ( 100Mbps )";
|
| 9808 |
|
|
`TIME; $display(" TEST 19: IPG DURING BACK-TO-BACK TRANSMIT AT 88 TX BDs ( 100Mbps )");
|
| 9809 |
|
|
|
| 9810 |
|
|
// reset MAC registers
|
| 9811 |
|
|
hard_reset;
|
| 9812 |
|
|
// reset MAC and MII LOGIC with soft reset
|
| 9813 |
274 |
tadejm |
// reset_mac;
|
| 9814 |
|
|
// reset_mii;
|
| 9815 |
209 |
tadejm |
// set wb slave response
|
| 9816 |
|
|
wb_slave.cycle_response(`ACK_RESPONSE, wbs_waits, wbs_retries);
|
| 9817 |
|
|
|
| 9818 |
|
|
max_tmp = 0;
|
| 9819 |
|
|
min_tmp = 0;
|
| 9820 |
|
|
num_of_frames = 0;
|
| 9821 |
|
|
num_of_bd = 0;
|
| 9822 |
|
|
tmp_ipgt = 0;
|
| 9823 |
|
|
// set 88 TX buffer descriptors - must be set before TX enable
|
| 9824 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 9825 |
209 |
tadejm |
wbm_write(`ETH_TX_BD_NUM, 32'h58, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 9826 |
|
|
// enable TX, set full-duplex mode, NO padding and CRC appending
|
| 9827 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 9828 |
209 |
tadejm |
wbm_write(`ETH_MODER, `ETH_MODER_TXEN | `ETH_MODER_FULLD | `ETH_MODER_CRCEN,
|
| 9829 |
|
|
4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 9830 |
|
|
// prepare two packets of MAXFL length
|
| 9831 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 9832 |
209 |
tadejm |
wbm_read(`ETH_PACKETLEN, tmp, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 9833 |
|
|
max_tmp = tmp[15:0]; // 18 bytes consists of 6B dest addr, 6B source addr, 2B type/len, 4B CRC
|
| 9834 |
|
|
min_tmp = tmp[31:16];
|
| 9835 |
|
|
st_data = 8'h29;
|
| 9836 |
|
|
set_tx_packet(`MEMORY_BASE, (max_tmp - 4), st_data); // length without CRC
|
| 9837 |
|
|
// check WB INT signal
|
| 9838 |
|
|
if (wb_int !== 1'b0)
|
| 9839 |
|
|
begin
|
| 9840 |
|
|
test_fail("WB INT signal should not be set");
|
| 9841 |
|
|
fail = fail + 1;
|
| 9842 |
|
|
end
|
| 9843 |
|
|
|
| 9844 |
|
|
// write to phy's control register for 100Mbps
|
| 9845 |
|
|
#Tp eth_phy.control_bit14_10 = 5'b01000; // bit 13 set - speed 100
|
| 9846 |
|
|
#Tp eth_phy.control_bit8_0 = 9'h1_00; // bit 6 reset - (10/100), bit 8 set - FD
|
| 9847 |
|
|
speed = 100;
|
| 9848 |
|
|
|
| 9849 |
|
|
i_length = (min_tmp - 4);
|
| 9850 |
|
|
while (i_length < (max_tmp - 4))
|
| 9851 |
|
|
begin
|
| 9852 |
|
|
// disable TX, set full-duplex mode, NO padding and CRC appending
|
| 9853 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 9854 |
209 |
tadejm |
wbm_write(`ETH_MODER, `ETH_MODER_FULLD | `ETH_MODER_CRCEN,
|
| 9855 |
|
|
4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 9856 |
|
|
// set IPGT register
|
| 9857 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 9858 |
209 |
tadejm |
wbm_write(`ETH_IPGT, tmp_ipgt, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 9859 |
|
|
// enable TX, set full-duplex mode, NO padding and CRC appending
|
| 9860 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 9861 |
209 |
tadejm |
wbm_write(`ETH_MODER, `ETH_MODER_TXEN | `ETH_MODER_FULLD | `ETH_MODER_CRCEN,
|
| 9862 |
|
|
4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 9863 |
|
|
// Reset_tx_bd enable interrupt generation
|
| 9864 |
|
|
// unmask interrupts
|
| 9865 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 9866 |
209 |
tadejm |
wbm_write(`ETH_INT_MASK, `ETH_INT_TXB | `ETH_INT_TXE | `ETH_INT_RXB | `ETH_INT_RXE | `ETH_INT_BUSY |
|
| 9867 |
|
|
`ETH_INT_TXC | `ETH_INT_RXC, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 9868 |
|
|
// not detect carrier sense in FD and no collision
|
| 9869 |
|
|
eth_phy.carrier_sense_tx_fd_detect(0);
|
| 9870 |
|
|
eth_phy.collision(0);
|
| 9871 |
|
|
// first destination address on ethernet PHY
|
| 9872 |
|
|
eth_phy.set_tx_mem_addr(0);
|
| 9873 |
|
|
// prepare BDs
|
| 9874 |
|
|
if (num_of_bd == 0)
|
| 9875 |
|
|
begin
|
| 9876 |
|
|
set_tx_bd(0, 0, i_length, 1'b1, 1'b1, 1'b1, `MEMORY_BASE);
|
| 9877 |
|
|
set_tx_bd(1, 1, i_length+1, 1'b1, 1'b1, 1'b1, `MEMORY_BASE);
|
| 9878 |
|
|
set_tx_bd_wrap(1);
|
| 9879 |
|
|
set_tx_bd_ready(0, 0);
|
| 9880 |
|
|
set_tx_bd_ready(1, 1);
|
| 9881 |
|
|
end
|
| 9882 |
|
|
// CHECK END OF TWO TRANSMITIONs
|
| 9883 |
|
|
// wait for first transmit to end
|
| 9884 |
|
|
check_tx_bd(num_of_bd, data);
|
| 9885 |
|
|
wait (MTxEn === 1'b1); // start transmit
|
| 9886 |
|
|
if (data[15] !== 1)
|
| 9887 |
|
|
begin
|
| 9888 |
|
|
test_fail("Wrong buffer descriptor's ready bit read out from MAC");
|
| 9889 |
|
|
fail = fail + 1;
|
| 9890 |
|
|
end
|
| 9891 |
|
|
wait (MTxEn === 1'b0); // end transmit
|
| 9892 |
|
|
num_of_frames = num_of_frames + 1;
|
| 9893 |
|
|
num_of_bd = num_of_bd + 1;
|
| 9894 |
|
|
#Tp;
|
| 9895 |
|
|
// destination address on ethernet PHY
|
| 9896 |
|
|
eth_phy.set_tx_mem_addr(0);
|
| 9897 |
|
|
i1 = 0;
|
| 9898 |
|
|
i2 = 0;
|
| 9899 |
|
|
// count IPG clock periods
|
| 9900 |
|
|
fork
|
| 9901 |
|
|
begin
|
| 9902 |
|
|
wait (MTxEn === 1'b1); // start second transmit
|
| 9903 |
|
|
#Tp;
|
| 9904 |
|
|
disable count_rising1;
|
| 9905 |
|
|
disable count_falling1;
|
| 9906 |
|
|
end
|
| 9907 |
|
|
begin: count_rising1
|
| 9908 |
|
|
forever
|
| 9909 |
|
|
begin
|
| 9910 |
|
|
@(posedge mtx_clk);
|
| 9911 |
|
|
i1 = i1 + 1;
|
| 9912 |
|
|
#Tp;
|
| 9913 |
|
|
end
|
| 9914 |
|
|
end
|
| 9915 |
|
|
begin: count_falling1
|
| 9916 |
|
|
forever
|
| 9917 |
|
|
begin
|
| 9918 |
|
|
@(negedge mtx_clk);
|
| 9919 |
|
|
i2 = i2 + 1;
|
| 9920 |
|
|
#Tp;
|
| 9921 |
|
|
end
|
| 9922 |
|
|
end
|
| 9923 |
|
|
join
|
| 9924 |
|
|
// check IPG length - INTERMEDIATE DISPLAYS
|
| 9925 |
|
|
if((i1 == i2) && (i1 >= (tmp_ipgt + 3)))
|
| 9926 |
|
|
begin
|
| 9927 |
|
|
$display(" ->IPG with %0d mtx_clk periods (min %0d) between packets with lengths %0d and %0d checked",
|
| 9928 |
|
|
i1, (tmp_ipgt + 3), (i_length + 4), (i_length + 4 + 1));
|
| 9929 |
|
|
end
|
| 9930 |
|
|
else
|
| 9931 |
|
|
begin
|
| 9932 |
|
|
`TIME; $display("*E IPG is not correct: (%0d + %0d) / 2, requested: %d", i1, i2, (tmp_ipgt + 3));
|
| 9933 |
|
|
fail = fail + 1;
|
| 9934 |
|
|
test_fail("IPG is not correct");
|
| 9935 |
|
|
end
|
| 9936 |
|
|
// wait for second transmit to end
|
| 9937 |
|
|
wait (MTxEn === 1'b0); // end second transmit
|
| 9938 |
|
|
while (data[15] === 1)
|
| 9939 |
|
|
begin
|
| 9940 |
|
|
check_tx_bd(num_of_bd, data);
|
| 9941 |
|
|
@(posedge wb_clk);
|
| 9942 |
|
|
end
|
| 9943 |
|
|
repeat (1) @(posedge wb_clk);
|
| 9944 |
|
|
// check length of a second PACKET
|
| 9945 |
|
|
tmp_len = eth_phy.tx_len;
|
| 9946 |
|
|
#1;
|
| 9947 |
|
|
if (tmp_len != (i_length + 4 + 1))
|
| 9948 |
|
|
begin
|
| 9949 |
|
|
test_fail("Wrong length of second packet out from MAC");
|
| 9950 |
|
|
fail = fail + 1;
|
| 9951 |
|
|
end
|
| 9952 |
|
|
// checking second packet
|
| 9953 |
|
|
check_tx_packet(`MEMORY_BASE, 0, (i_length + 1), tmp);
|
| 9954 |
|
|
if (tmp > 0)
|
| 9955 |
|
|
begin
|
| 9956 |
|
|
test_fail("Wrong data of second transmitted packet");
|
| 9957 |
|
|
fail = fail + 1;
|
| 9958 |
|
|
end
|
| 9959 |
|
|
// check second transmited TX packet CRC
|
| 9960 |
|
|
check_tx_crc(0, (i_length + 1), 1'b0, tmp); // length without CRC
|
| 9961 |
|
|
if (tmp > 0)
|
| 9962 |
|
|
begin
|
| 9963 |
|
|
test_fail("Wrong CRC of second transmitted packet");
|
| 9964 |
|
|
fail = fail + 1;
|
| 9965 |
|
|
end
|
| 9966 |
|
|
// check WB INT signal
|
| 9967 |
|
|
if (wb_int !== 1'b1)
|
| 9968 |
|
|
begin
|
| 9969 |
|
|
`TIME; $display("*E WB INT signal should be set");
|
| 9970 |
|
|
test_fail("WB INT signal should be set");
|
| 9971 |
|
|
fail = fail + 1;
|
| 9972 |
|
|
end
|
| 9973 |
|
|
// check TX buffer descriptor of a packet
|
| 9974 |
|
|
check_tx_bd(num_of_bd, data);
|
| 9975 |
|
|
if ( ((data[15:0] !== 16'h7800) && (num_of_bd == 1)) || // wrap bit
|
| 9976 |
|
|
((data[15:0] !== 16'h5800) && (num_of_bd < 1)) ) // without wrap bit
|
| 9977 |
|
|
begin
|
| 9978 |
|
|
`TIME; $display("*E TX buffer descriptor status is not correct: %0h", data[15:0]);
|
| 9979 |
|
|
test_fail("TX buffer descriptor status is not correct");
|
| 9980 |
|
|
fail = fail + 1;
|
| 9981 |
|
|
end
|
| 9982 |
|
|
// check interrupts
|
| 9983 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 9984 |
209 |
tadejm |
wbm_read(`ETH_INT, data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 9985 |
|
|
if ((data & `ETH_INT_TXB) !== 1'b1)
|
| 9986 |
|
|
begin
|
| 9987 |
|
|
`TIME; $display("*E Interrupt Transmit Buffer was not set, interrupt reg: %0h", data);
|
| 9988 |
|
|
test_fail("Interrupt Transmit Buffer was not set");
|
| 9989 |
|
|
fail = fail + 1;
|
| 9990 |
|
|
end
|
| 9991 |
|
|
if ((data & (~`ETH_INT_TXB)) !== 0)
|
| 9992 |
|
|
begin
|
| 9993 |
|
|
`TIME; $display("*E Other interrupts (except Transmit Buffer) were set, interrupt reg: %0h", data);
|
| 9994 |
|
|
test_fail("Other interrupts (except Transmit Buffer) were set");
|
| 9995 |
|
|
fail = fail + 1;
|
| 9996 |
|
|
end
|
| 9997 |
|
|
// clear interrupts
|
| 9998 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 9999 |
209 |
tadejm |
wbm_write(`ETH_INT, data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 10000 |
|
|
// check WB INT signal
|
| 10001 |
|
|
if (wb_int !== 1'b0)
|
| 10002 |
|
|
begin
|
| 10003 |
|
|
test_fail("WB INT signal should not be set");
|
| 10004 |
|
|
fail = fail + 1;
|
| 10005 |
|
|
end
|
| 10006 |
|
|
// set length (LOOP variable)
|
| 10007 |
|
|
if ((tmp_ipgt + 3) < 130) // tmp_ipgt < 124
|
| 10008 |
|
|
i_length = i_length + 2;
|
| 10009 |
|
|
else
|
| 10010 |
|
|
i_length = (max_tmp - 4);
|
| 10011 |
|
|
// set IPGT
|
| 10012 |
|
|
if ((tmp_ipgt + 3) < 10)
|
| 10013 |
|
|
tmp_ipgt = tmp_ipgt + 1;
|
| 10014 |
|
|
else if ((tmp_ipgt + 3) < 24)
|
| 10015 |
|
|
tmp_ipgt = tmp_ipgt + 7;
|
| 10016 |
|
|
else if ((tmp_ipgt + 3) == 24)
|
| 10017 |
|
|
tmp_ipgt = 38 - 3;
|
| 10018 |
|
|
else if ((tmp_ipgt + 3) == 38)
|
| 10019 |
|
|
tmp_ipgt = 72 - 3;
|
| 10020 |
|
|
else if ((tmp_ipgt + 3) == 72)
|
| 10021 |
|
|
tmp_ipgt = 130 - 3; // 124 - 3
|
| 10022 |
|
|
// the number of frame transmitted
|
| 10023 |
|
|
num_of_frames = num_of_frames + 1;
|
| 10024 |
|
|
num_of_bd = 0;
|
| 10025 |
|
|
@(posedge wb_clk);
|
| 10026 |
|
|
end
|
| 10027 |
|
|
// disable TX
|
| 10028 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 10029 |
209 |
tadejm |
wbm_write(`ETH_MODER, `ETH_MODER_FULLD | `ETH_MODER_PAD | `ETH_MODER_CRCEN,
|
| 10030 |
|
|
4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 10031 |
|
|
@(posedge wb_clk);
|
| 10032 |
|
|
if(fail == 0)
|
| 10033 |
|
|
test_ok;
|
| 10034 |
|
|
else
|
| 10035 |
|
|
fail = 0;
|
| 10036 |
|
|
end
|
| 10037 |
|
|
|
| 10038 |
|
|
|
| 10039 |
|
|
////////////////////////////////////////////////////////////////////
|
| 10040 |
|
|
//// ////
|
| 10041 |
|
|
//// Test transmit packets after TX under-run on each packet's ////
|
| 10042 |
|
|
//// byte at 2 TX buffer decriptors ( 10Mbps ). ////
|
| 10043 |
|
|
//// ////
|
| 10044 |
|
|
////////////////////////////////////////////////////////////////////
|
| 10045 |
|
|
if (test_num == 20) // without padding
|
| 10046 |
|
|
begin
|
| 10047 |
|
|
// TEST 20: TRANSMIT PACKETS AFTER TX UNDER-RUN ON EACH PACKET's BYTE AT 2 TX BDs ( 10Mbps )
|
| 10048 |
|
|
test_name = "TEST 20: TRANSMIT PACKETS AFTER TX UNDER-RUN ON EACH PACKET's BYTE AT 2 TX BDs ( 10Mbps )";
|
| 10049 |
|
|
`TIME;
|
| 10050 |
|
|
$display(" TEST 20: TRANSMIT PACKETS AFTER TX UNDER-RUN ON EACH PACKET's BYTE AT 2 TX BDs ( 10Mbps )");
|
| 10051 |
|
|
|
| 10052 |
|
|
// reset MAC registers
|
| 10053 |
|
|
hard_reset;
|
| 10054 |
|
|
// reset MAC and MII LOGIC with soft reset
|
| 10055 |
274 |
tadejm |
// reset_mac;
|
| 10056 |
|
|
// reset_mii;
|
| 10057 |
209 |
tadejm |
// set wb slave response
|
| 10058 |
|
|
wb_slave.cycle_response(`ACK_RESPONSE, wbs_waits, wbs_retries);
|
| 10059 |
|
|
|
| 10060 |
|
|
max_tmp = 0;
|
| 10061 |
|
|
min_tmp = 0;
|
| 10062 |
|
|
// set 2 TX buffer descriptors - must be set before TX enable
|
| 10063 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 10064 |
209 |
tadejm |
wbm_write(`ETH_TX_BD_NUM, 32'h2, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 10065 |
|
|
// enable TX, set full-duplex mode, NO padding and CRC appending
|
| 10066 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 10067 |
209 |
tadejm |
wbm_write(`ETH_MODER, `ETH_MODER_TXEN |/* `ETH_MODER_PAD |*/ `ETH_MODER_FULLD | `ETH_MODER_CRCEN,
|
| 10068 |
|
|
4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 10069 |
|
|
// prepare a packet of MAXFL length
|
| 10070 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 10071 |
209 |
tadejm |
wbm_read(`ETH_PACKETLEN, tmp, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 10072 |
|
|
max_tmp = tmp[15:0]; // 18 bytes consists of 6B dest addr, 6B source addr, 2B type/len, 4B CRC
|
| 10073 |
|
|
min_tmp = tmp[31:16];
|
| 10074 |
|
|
st_data = 8'h99;
|
| 10075 |
|
|
set_tx_packet(`MEMORY_BASE, (max_tmp - 4), st_data); // length without CRC
|
| 10076 |
|
|
// read IPG value
|
| 10077 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 10078 |
209 |
tadejm |
wbm_read(`ETH_IPGT, tmp_ipgt, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 10079 |
|
|
// check WB INT signal
|
| 10080 |
|
|
if (wb_int !== 1'b0)
|
| 10081 |
|
|
begin
|
| 10082 |
|
|
test_fail("WB INT signal should not be set");
|
| 10083 |
|
|
fail = fail + 1;
|
| 10084 |
|
|
end
|
| 10085 |
|
|
|
| 10086 |
|
|
// write to phy's control register for 10Mbps
|
| 10087 |
|
|
#Tp eth_phy.control_bit14_10 = 5'b00000; // bit 13 reset - speed 10
|
| 10088 |
|
|
#Tp eth_phy.control_bit8_0 = 9'h1_00; // bit 6 reset - (10/100), bit 8 set - FD
|
| 10089 |
|
|
speed = 10;
|
| 10090 |
|
|
|
| 10091 |
223 |
tadejm |
num_of_frames = 40; // (0..3) => start under-run on first word
|
| 10092 |
209 |
tadejm |
num_of_bd = 0;
|
| 10093 |
|
|
i_data = 3; // (3) => one BYTE read in first word - FIRST byte
|
| 10094 |
|
|
i_length = (min_tmp + 4);
|
| 10095 |
|
|
while (i_length < (max_tmp - 4))
|
| 10096 |
|
|
begin
|
| 10097 |
|
|
// Reset_tx_bd enable interrupt generation
|
| 10098 |
|
|
// unmask interrupts
|
| 10099 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 10100 |
209 |
tadejm |
wbm_write(`ETH_INT_MASK, `ETH_INT_TXB | `ETH_INT_TXE | `ETH_INT_RXB | `ETH_INT_RXE | `ETH_INT_BUSY |
|
| 10101 |
|
|
`ETH_INT_TXC | `ETH_INT_RXC, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 10102 |
|
|
// not detect carrier sense in FD and no collision
|
| 10103 |
|
|
eth_phy.carrier_sense_tx_fd_detect(0);
|
| 10104 |
|
|
eth_phy.collision(0);
|
| 10105 |
|
|
// first destination address on ethernet PHY
|
| 10106 |
|
|
eth_phy.set_tx_mem_addr(0);
|
| 10107 |
|
|
// prepare BDs
|
| 10108 |
|
|
if (num_of_bd == 0)
|
| 10109 |
|
|
begin
|
| 10110 |
|
|
set_tx_bd(0, 0, i_length, 1'b1, 1'b1, 1'b1, (`MEMORY_BASE + i_data[1:0]));
|
| 10111 |
|
|
set_tx_bd(1, 1, i_length, 1'b1, 1'b1, 1'b1, `MEMORY_BASE);
|
| 10112 |
|
|
set_tx_bd_wrap(1);
|
| 10113 |
|
|
// set wb slave response: ACK (response), wbs_waits[2:0] (waits before response),
|
| 10114 |
|
|
// wbs_retries[7:0] (RTYs before ACK if RTY response selected)
|
| 10115 |
223 |
tadejm |
#1 wb_slave.cycle_response(`ACK_RESPONSE, 3'h0, 8'h0);
|
| 10116 |
209 |
tadejm |
set_tx_bd_ready(1, 1);
|
| 10117 |
|
|
set_tx_bd_ready(0, 0);
|
| 10118 |
|
|
end
|
| 10119 |
|
|
// frame under-run checking
|
| 10120 |
|
|
frame_started = 0;
|
| 10121 |
|
|
frame_ended = 0;
|
| 10122 |
|
|
wait_for_frame = 0;
|
| 10123 |
|
|
fork
|
| 10124 |
|
|
begin
|
| 10125 |
|
|
// for every 4 frames bytes 1, 2, 3 and 4 respectively are read in first word => 1 ACK
|
| 10126 |
|
|
// in other words 4 bytes are read, since length is MINFL => num_of_frames[31:2] ACKs
|
| 10127 |
|
|
repeat ((num_of_frames[31:2] + 1'b1)) @(posedge eth_ma_wb_ack_i);
|
| 10128 |
|
|
@(negedge eth_ma_wb_ack_i); // wait for last ACK to finish
|
| 10129 |
|
|
// set wb slave response: ACK (response), wbs_waits[2:0] (waits before response),
|
| 10130 |
|
|
// wbs_retries[7:0] (RTYs before ACK if RTY response selected)
|
| 10131 |
223 |
tadejm |
#1 wb_slave.cycle_response(`NO_RESPONSE, 3'h0, 8'hFF);
|
| 10132 |
209 |
tadejm |
// wait for synchronization and some additional clocks
|
| 10133 |
|
|
wait_for_frame = 1;
|
| 10134 |
|
|
// wait for frame
|
| 10135 |
|
|
wait ((wait_for_frame == 0) || (frame_started == 1))
|
| 10136 |
|
|
if ((wait_for_frame == 0) && (frame_started == 0)) // frame didn't start
|
| 10137 |
|
|
begin
|
| 10138 |
|
|
disable check_fr;
|
| 10139 |
|
|
end
|
| 10140 |
|
|
else if ((wait_for_frame == 1) && (frame_started == 1)) // frame started
|
| 10141 |
|
|
begin
|
| 10142 |
|
|
disable wait_fr;
|
| 10143 |
|
|
wait (frame_ended == 1);
|
| 10144 |
|
|
end
|
| 10145 |
|
|
repeat (2) @(posedge wb_clk);
|
| 10146 |
|
|
// set wb slave response: ACK (response), wbs_waits[2:0] (waits before response),
|
| 10147 |
|
|
// wbs_retries[7:0] (RTYs before ACK if RTY response selected)
|
| 10148 |
223 |
tadejm |
wb_slave.cycle_response(`ACK_RESPONSE, 3'h0, 8'h0);
|
| 10149 |
209 |
tadejm |
end
|
| 10150 |
|
|
begin: wait_fr
|
| 10151 |
|
|
wait (wait_for_frame == 1)
|
| 10152 |
|
|
begin
|
| 10153 |
|
|
// wait for synchronization and some additional clocks
|
| 10154 |
|
|
repeat (3) @(posedge wb_clk);
|
| 10155 |
|
|
repeat (2 * tmp_ipgt) @(posedge mtx_clk);
|
| 10156 |
|
|
repeat (2) @(posedge wb_clk);
|
| 10157 |
|
|
repeat (2) @(posedge mtx_clk);
|
| 10158 |
|
|
wait_for_frame = 0;
|
| 10159 |
|
|
end
|
| 10160 |
|
|
end
|
| 10161 |
|
|
begin: check_fr
|
| 10162 |
|
|
// wait for frame to start
|
| 10163 |
|
|
@(posedge MTxEn);
|
| 10164 |
|
|
frame_started = 1;
|
| 10165 |
223 |
tadejm |
`TIME; $display(" Under-run (on %0d. byte) frame started", (num_of_frames + 1));
|
| 10166 |
209 |
tadejm |
// wait for frame to end due to under-run
|
| 10167 |
|
|
@(negedge MTxEn);
|
| 10168 |
|
|
frame_ended = 1;
|
| 10169 |
223 |
tadejm |
`TIME; $display(" Under-run frame ended");
|
| 10170 |
209 |
tadejm |
end
|
| 10171 |
|
|
join
|
| 10172 |
|
|
// wait for first transmit to end, if under-run didn't happen
|
| 10173 |
|
|
if (frame_ended == 0)
|
| 10174 |
|
|
begin
|
| 10175 |
|
|
// WAIT FOR FIRST TRANSMIT
|
| 10176 |
|
|
check_tx_bd(num_of_bd, data);
|
| 10177 |
|
|
wait (MTxEn === 1'b1); // start first transmit
|
| 10178 |
|
|
if (data[15] !== 1)
|
| 10179 |
|
|
begin
|
| 10180 |
|
|
test_fail("Wrong buffer descriptor's ready bit read out from MAC");
|
| 10181 |
|
|
fail = fail + 1;
|
| 10182 |
|
|
end
|
| 10183 |
|
|
wait (MTxEn === 1'b0); // end first transmit
|
| 10184 |
|
|
while (data[15] === 1)
|
| 10185 |
|
|
begin
|
| 10186 |
|
|
check_tx_bd(num_of_bd, data);
|
| 10187 |
|
|
@(posedge wb_clk);
|
| 10188 |
|
|
end
|
| 10189 |
|
|
repeat (1) @(posedge wb_clk);
|
| 10190 |
|
|
// CHECK FIRST FRAME
|
| 10191 |
|
|
// check length of a first PACKET
|
| 10192 |
|
|
tmp_len = eth_phy.tx_len;
|
| 10193 |
|
|
#1;
|
| 10194 |
|
|
if (tmp_len != (i_length + 4))
|
| 10195 |
|
|
begin
|
| 10196 |
223 |
tadejm |
`TIME; $display("*E Wrong length of first packet out from MAC");
|
| 10197 |
|
|
test_fail("Wrong length of first packet out from MAC");
|
| 10198 |
209 |
tadejm |
fail = fail + 1;
|
| 10199 |
|
|
end
|
| 10200 |
|
|
// checking first packet
|
| 10201 |
|
|
check_tx_packet((`MEMORY_BASE + i_data[1:0]), 0, (i_length), tmp);
|
| 10202 |
|
|
if (tmp > 0)
|
| 10203 |
|
|
begin
|
| 10204 |
223 |
tadejm |
`TIME; $display("*E Wrong data of first transmitted packet");
|
| 10205 |
|
|
test_fail("Wrong data of first transmitted packet");
|
| 10206 |
209 |
tadejm |
fail = fail + 1;
|
| 10207 |
|
|
end
|
| 10208 |
|
|
// check first transmited TX packet CRC
|
| 10209 |
|
|
check_tx_crc(0, (i_length), 1'b0, tmp); // length without CRC
|
| 10210 |
|
|
if (tmp > 0)
|
| 10211 |
|
|
begin
|
| 10212 |
223 |
tadejm |
`TIME; $display("*E Wrong CRC of first transmitted packet");
|
| 10213 |
|
|
test_fail("Wrong CRC of first transmitted packet");
|
| 10214 |
209 |
tadejm |
fail = fail + 1;
|
| 10215 |
|
|
end
|
| 10216 |
|
|
// check WB INT signal
|
| 10217 |
|
|
if (wb_int !== 1'b1)
|
| 10218 |
|
|
begin
|
| 10219 |
|
|
`TIME; $display("*E WB INT signal should be set");
|
| 10220 |
|
|
test_fail("WB INT signal should be set");
|
| 10221 |
|
|
fail = fail + 1;
|
| 10222 |
|
|
end
|
| 10223 |
|
|
// check TX buffer descriptor of a packet
|
| 10224 |
|
|
check_tx_bd(num_of_bd, data);
|
| 10225 |
|
|
if ( ((data[15:0] !== 16'h7800) && (num_of_bd == 1)) || // wrap bit
|
| 10226 |
|
|
((data[15:0] !== 16'h5800) && (num_of_bd < 1)) ) // without wrap bit
|
| 10227 |
|
|
begin
|
| 10228 |
|
|
`TIME; $display("*E TX buffer descriptor status is not correct: %0h", data[15:0]);
|
| 10229 |
|
|
test_fail("TX buffer descriptor status is not correct");
|
| 10230 |
|
|
fail = fail + 1;
|
| 10231 |
|
|
end
|
| 10232 |
|
|
// check interrupts
|
| 10233 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 10234 |
209 |
tadejm |
wbm_read(`ETH_INT, data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 10235 |
|
|
if ((data & `ETH_INT_TXB) !== 1'b1)
|
| 10236 |
|
|
begin
|
| 10237 |
|
|
`TIME; $display("*E Interrupt Transmit Buffer was not set, interrupt reg: %0h", data);
|
| 10238 |
|
|
test_fail("Interrupt Transmit Buffer was not set");
|
| 10239 |
|
|
fail = fail + 1;
|
| 10240 |
|
|
end
|
| 10241 |
|
|
if ((data & (~`ETH_INT_TXB)) !== 0)
|
| 10242 |
|
|
begin
|
| 10243 |
|
|
`TIME; $display("*E Other interrupts (except Transmit Buffer) were set, interrupt reg: %0h", data);
|
| 10244 |
|
|
test_fail("Other interrupts (except Transmit Buffer) were set");
|
| 10245 |
|
|
fail = fail + 1;
|
| 10246 |
|
|
end
|
| 10247 |
|
|
// clear interrupts
|
| 10248 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 10249 |
209 |
tadejm |
wbm_write(`ETH_INT, data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 10250 |
|
|
// check WB INT signal
|
| 10251 |
|
|
if (wb_int !== 1'b0)
|
| 10252 |
|
|
begin
|
| 10253 |
|
|
test_fail("WB INT signal should not be set");
|
| 10254 |
|
|
fail = fail + 1;
|
| 10255 |
|
|
end
|
| 10256 |
|
|
end
|
| 10257 |
223 |
tadejm |
else
|
| 10258 |
|
|
begin
|
| 10259 |
|
|
// CHECK FIRST FRAME
|
| 10260 |
|
|
// check length of a first PACKET
|
| 10261 |
|
|
tmp_len = eth_phy.tx_len_err;
|
| 10262 |
|
|
#1;
|
| 10263 |
|
|
if (tmp_len != (num_of_frames + (4 - i_data)))
|
| 10264 |
|
|
begin
|
| 10265 |
|
|
`TIME; $display("*E Wrong length of first packet out from MAC");
|
| 10266 |
|
|
test_fail("Wrong length of first packet out from MAC");
|
| 10267 |
|
|
fail = fail + 1;
|
| 10268 |
|
|
end
|
| 10269 |
|
|
// checking first packet
|
| 10270 |
|
|
check_tx_packet((`MEMORY_BASE + i_data[1:0]), 0, (num_of_frames), tmp);
|
| 10271 |
|
|
if (tmp > 0)
|
| 10272 |
|
|
begin
|
| 10273 |
|
|
`TIME; $display("*E Wrong data of first transmitted packet");
|
| 10274 |
|
|
test_fail("Wrong data of first transmitted packet");
|
| 10275 |
|
|
fail = fail + 1;
|
| 10276 |
|
|
end
|
| 10277 |
|
|
// check WB INT signal
|
| 10278 |
|
|
if (wb_int !== 1'b1)
|
| 10279 |
|
|
begin
|
| 10280 |
|
|
`TIME; $display("*E WB INT signal should be set");
|
| 10281 |
|
|
test_fail("WB INT signal should be set");
|
| 10282 |
|
|
fail = fail + 1;
|
| 10283 |
|
|
end
|
| 10284 |
|
|
// check TX buffer descriptor of a packet
|
| 10285 |
|
|
check_tx_bd(num_of_bd, data);
|
| 10286 |
|
|
if ( ((data[15:0] !== 16'h7900) && (num_of_bd == 1)) || // under-run, wrap bit
|
| 10287 |
|
|
((data[15:0] !== 16'h5900) && (num_of_bd < 1)) ) // under-run, without wrap bit
|
| 10288 |
|
|
begin
|
| 10289 |
|
|
`TIME; $display("*E TX buffer descriptor status is not correct: %0h", data[15:0]);
|
| 10290 |
|
|
test_fail("TX buffer descriptor status is not correct");
|
| 10291 |
|
|
fail = fail + 1;
|
| 10292 |
|
|
end
|
| 10293 |
|
|
// check interrupts
|
| 10294 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 10295 |
223 |
tadejm |
wbm_read(`ETH_INT, data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 10296 |
|
|
if ((data & `ETH_INT_TXE) !== 2'b10)
|
| 10297 |
|
|
begin
|
| 10298 |
|
|
`TIME; $display("*E Interrupt Transmit Error was not set, interrupt reg: %0h", data);
|
| 10299 |
|
|
test_fail("Interrupt Transmit Buffer was not set");
|
| 10300 |
|
|
fail = fail + 1;
|
| 10301 |
|
|
end
|
| 10302 |
|
|
if ((data & (~`ETH_INT_TXE)) !== 0)
|
| 10303 |
|
|
begin
|
| 10304 |
|
|
`TIME; $display("*E Other interrupts (except Transmit Error) were set, interrupt reg: %0h", data);
|
| 10305 |
|
|
test_fail("Other interrupts (except Transmit Buffer) were set");
|
| 10306 |
|
|
fail = fail + 1;
|
| 10307 |
|
|
end
|
| 10308 |
|
|
// clear interrupts
|
| 10309 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 10310 |
223 |
tadejm |
wbm_write(`ETH_INT, data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 10311 |
|
|
// check WB INT signal
|
| 10312 |
|
|
if (wb_int !== 1'b0)
|
| 10313 |
|
|
begin
|
| 10314 |
|
|
test_fail("WB INT signal should not be set");
|
| 10315 |
|
|
fail = fail + 1;
|
| 10316 |
|
|
end
|
| 10317 |
|
|
end
|
| 10318 |
209 |
tadejm |
num_of_bd = num_of_bd + 1;
|
| 10319 |
|
|
// destination address on ethernet PHY
|
| 10320 |
|
|
eth_phy.set_tx_mem_addr(0);
|
| 10321 |
223 |
tadejm |
// WAIT FOR SECOND TRANSMIT
|
| 10322 |
209 |
tadejm |
check_tx_bd(num_of_bd, data);
|
| 10323 |
|
|
wait (MTxEn === 1'b1); // start first transmit
|
| 10324 |
|
|
if (data[15] !== 1)
|
| 10325 |
|
|
begin
|
| 10326 |
|
|
test_fail("Wrong buffer descriptor's ready bit read out from MAC");
|
| 10327 |
|
|
fail = fail + 1;
|
| 10328 |
|
|
end
|
| 10329 |
|
|
wait (MTxEn === 1'b0); // end first transmit
|
| 10330 |
|
|
while (data[15] === 1)
|
| 10331 |
|
|
begin
|
| 10332 |
|
|
check_tx_bd(num_of_bd, data);
|
| 10333 |
|
|
@(posedge wb_clk);
|
| 10334 |
|
|
end
|
| 10335 |
|
|
repeat (1) @(posedge wb_clk);
|
| 10336 |
|
|
// CHECK SECOND FRAME
|
| 10337 |
|
|
// check length of a second PACKET
|
| 10338 |
223 |
tadejm |
if (frame_ended == 1'b1)
|
| 10339 |
|
|
begin
|
| 10340 |
|
|
`TIME; $display(" Second frame after under-run ended");
|
| 10341 |
|
|
end
|
| 10342 |
209 |
tadejm |
tmp_len = eth_phy.tx_len;
|
| 10343 |
|
|
#1;
|
| 10344 |
|
|
if (tmp_len != (i_length + 4))
|
| 10345 |
|
|
begin
|
| 10346 |
223 |
tadejm |
`TIME; $display("*E Wrong length of second packet out from MAC");
|
| 10347 |
209 |
tadejm |
test_fail("Wrong length of second packet out from MAC");
|
| 10348 |
|
|
fail = fail + 1;
|
| 10349 |
|
|
end
|
| 10350 |
|
|
// checking second packet
|
| 10351 |
|
|
check_tx_packet(`MEMORY_BASE, 0, (i_length), tmp);
|
| 10352 |
|
|
if (tmp > 0)
|
| 10353 |
|
|
begin
|
| 10354 |
223 |
tadejm |
`TIME; $display("*E Wrong data of second transmitted packet");
|
| 10355 |
209 |
tadejm |
test_fail("Wrong data of second transmitted packet");
|
| 10356 |
|
|
fail = fail + 1;
|
| 10357 |
|
|
end
|
| 10358 |
|
|
// check second transmited TX packet CRC
|
| 10359 |
|
|
check_tx_crc(0, (i_length), 1'b0, tmp); // length without CRC
|
| 10360 |
|
|
if (tmp > 0)
|
| 10361 |
|
|
begin
|
| 10362 |
223 |
tadejm |
`TIME; $display("*E Wrong CRC of second transmitted packet");
|
| 10363 |
209 |
tadejm |
test_fail("Wrong CRC of second transmitted packet");
|
| 10364 |
|
|
fail = fail + 1;
|
| 10365 |
|
|
end
|
| 10366 |
|
|
// check WB INT signal
|
| 10367 |
|
|
if (wb_int !== 1'b1)
|
| 10368 |
|
|
begin
|
| 10369 |
|
|
`TIME; $display("*E WB INT signal should be set");
|
| 10370 |
|
|
test_fail("WB INT signal should be set");
|
| 10371 |
|
|
fail = fail + 1;
|
| 10372 |
|
|
end
|
| 10373 |
|
|
// check TX buffer descriptor of a packet
|
| 10374 |
|
|
check_tx_bd(num_of_bd, data);
|
| 10375 |
|
|
if ( ((data[15:0] !== 16'h7800) && (num_of_bd == 1)) || // wrap bit
|
| 10376 |
|
|
((data[15:0] !== 16'h5800) && (num_of_bd < 1)) ) // without wrap bit
|
| 10377 |
|
|
begin
|
| 10378 |
|
|
`TIME; $display("*E TX buffer descriptor status is not correct: %0h", data[15:0]);
|
| 10379 |
|
|
test_fail("TX buffer descriptor status is not correct");
|
| 10380 |
|
|
fail = fail + 1;
|
| 10381 |
|
|
end
|
| 10382 |
|
|
// check interrupts
|
| 10383 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 10384 |
209 |
tadejm |
wbm_read(`ETH_INT, data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 10385 |
|
|
if ((data & `ETH_INT_TXB) !== 1'b1)
|
| 10386 |
|
|
begin
|
| 10387 |
|
|
`TIME; $display("*E Interrupt Transmit Buffer was not set, interrupt reg: %0h", data);
|
| 10388 |
|
|
test_fail("Interrupt Transmit Buffer was not set");
|
| 10389 |
|
|
fail = fail + 1;
|
| 10390 |
|
|
end
|
| 10391 |
|
|
if ((data & (~`ETH_INT_TXB)) !== 0)
|
| 10392 |
|
|
begin
|
| 10393 |
|
|
`TIME; $display("*E Other interrupts (except Transmit Buffer) were set, interrupt reg: %0h", data);
|
| 10394 |
|
|
test_fail("Other interrupts (except Transmit Buffer) were set");
|
| 10395 |
|
|
fail = fail + 1;
|
| 10396 |
|
|
end
|
| 10397 |
|
|
// clear interrupts
|
| 10398 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 10399 |
209 |
tadejm |
wbm_write(`ETH_INT, data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 10400 |
|
|
// check WB INT signal
|
| 10401 |
|
|
if (wb_int !== 1'b0)
|
| 10402 |
|
|
begin
|
| 10403 |
|
|
test_fail("WB INT signal should not be set");
|
| 10404 |
|
|
fail = fail + 1;
|
| 10405 |
|
|
end
|
| 10406 |
|
|
// set initial value
|
| 10407 |
|
|
i_data = i_data - 1;
|
| 10408 |
|
|
// the number of frame transmitted
|
| 10409 |
|
|
num_of_frames = num_of_frames + 1;
|
| 10410 |
|
|
num_of_bd = 0;
|
| 10411 |
|
|
// set length (LOOP variable)
|
| 10412 |
223 |
tadejm |
if (num_of_frames == i_length + 4) // 64 => this was last Byte (1st .. 64th) when i_length = min_tmp - 4
|
| 10413 |
209 |
tadejm |
i_length = (max_tmp - 4);
|
| 10414 |
|
|
@(posedge wb_clk);
|
| 10415 |
|
|
end
|
| 10416 |
|
|
// disable TX
|
| 10417 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 10418 |
209 |
tadejm |
wbm_write(`ETH_MODER, `ETH_MODER_FULLD | `ETH_MODER_PAD | `ETH_MODER_CRCEN,
|
| 10419 |
|
|
4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 10420 |
|
|
@(posedge wb_clk);
|
| 10421 |
|
|
if(fail == 0)
|
| 10422 |
|
|
test_ok;
|
| 10423 |
|
|
else
|
| 10424 |
|
|
fail = 0;
|
| 10425 |
|
|
end
|
| 10426 |
|
|
|
| 10427 |
|
|
|
| 10428 |
|
|
////////////////////////////////////////////////////////////////////
|
| 10429 |
|
|
//// ////
|
| 10430 |
|
|
//// Test transmit packets after TX under-run on each packet's ////
|
| 10431 |
|
|
//// byte at 2 TX buffer decriptors ( 100Mbps ). ////
|
| 10432 |
|
|
//// ////
|
| 10433 |
|
|
////////////////////////////////////////////////////////////////////
|
| 10434 |
|
|
if (test_num == 21) // without padding
|
| 10435 |
|
|
begin
|
| 10436 |
|
|
// TEST 21: TRANSMIT PACKETS AFTER TX UNDER-RUN ON EACH PACKET's BYTE AT 2 TX BDs ( 100Mbps )
|
| 10437 |
|
|
test_name = "TEST 21: TRANSMIT PACKETS AFTER TX UNDER-RUN ON EACH PACKET's BYTE AT 2 TX BDs ( 100Mbps )";
|
| 10438 |
|
|
`TIME;
|
| 10439 |
|
|
$display(" TEST 21: TRANSMIT PACKETS AFTER TX UNDER-RUN ON EACH PACKET's BYTE AT 2 TX BDs ( 100Mbps )");
|
| 10440 |
|
|
|
| 10441 |
|
|
// reset MAC registers
|
| 10442 |
|
|
hard_reset;
|
| 10443 |
|
|
// reset MAC and MII LOGIC with soft reset
|
| 10444 |
274 |
tadejm |
// reset_mac;
|
| 10445 |
|
|
// reset_mii;
|
| 10446 |
209 |
tadejm |
// set wb slave response
|
| 10447 |
|
|
wb_slave.cycle_response(`ACK_RESPONSE, wbs_waits, wbs_retries);
|
| 10448 |
|
|
|
| 10449 |
|
|
max_tmp = 0;
|
| 10450 |
|
|
min_tmp = 0;
|
| 10451 |
|
|
// set 2 TX buffer descriptors - must be set before TX enable
|
| 10452 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 10453 |
209 |
tadejm |
wbm_write(`ETH_TX_BD_NUM, 32'h2, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 10454 |
|
|
// enable TX, set full-duplex mode, NO padding and CRC appending
|
| 10455 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 10456 |
209 |
tadejm |
wbm_write(`ETH_MODER, `ETH_MODER_TXEN |/* `ETH_MODER_PAD |*/ `ETH_MODER_FULLD | `ETH_MODER_CRCEN,
|
| 10457 |
|
|
4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 10458 |
|
|
// prepare a packet of MAXFL length
|
| 10459 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 10460 |
209 |
tadejm |
wbm_read(`ETH_PACKETLEN, tmp, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 10461 |
|
|
max_tmp = tmp[15:0]; // 18 bytes consists of 6B dest addr, 6B source addr, 2B type/len, 4B CRC
|
| 10462 |
|
|
min_tmp = tmp[31:16];
|
| 10463 |
|
|
st_data = 8'h99;
|
| 10464 |
|
|
set_tx_packet(`MEMORY_BASE, (max_tmp - 4), st_data); // length without CRC
|
| 10465 |
|
|
// read IPG value
|
| 10466 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 10467 |
209 |
tadejm |
wbm_read(`ETH_IPGT, tmp_ipgt, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 10468 |
|
|
// check WB INT signal
|
| 10469 |
|
|
if (wb_int !== 1'b0)
|
| 10470 |
|
|
begin
|
| 10471 |
|
|
test_fail("WB INT signal should not be set");
|
| 10472 |
|
|
fail = fail + 1;
|
| 10473 |
|
|
end
|
| 10474 |
|
|
|
| 10475 |
|
|
// write to phy's control register for 100Mbps
|
| 10476 |
|
|
#Tp eth_phy.control_bit14_10 = 5'b01000; // bit 13 set - speed 100
|
| 10477 |
|
|
#Tp eth_phy.control_bit8_0 = 9'h1_00; // bit 6 reset - (10/100), bit 8 set - FD
|
| 10478 |
|
|
speed = 100;
|
| 10479 |
|
|
|
| 10480 |
|
|
num_of_frames = 0; // (0..3) => start under-run on first word
|
| 10481 |
|
|
num_of_bd = 0;
|
| 10482 |
|
|
i_data = 3; // (3) => one BYTE read in first word - FIRST byte
|
| 10483 |
|
|
i_length = (min_tmp + 4);
|
| 10484 |
|
|
while (i_length < (max_tmp - 4))
|
| 10485 |
|
|
begin
|
| 10486 |
|
|
// Reset_tx_bd enable interrupt generation
|
| 10487 |
|
|
// unmask interrupts
|
| 10488 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 10489 |
209 |
tadejm |
wbm_write(`ETH_INT_MASK, `ETH_INT_TXB | `ETH_INT_TXE | `ETH_INT_RXB | `ETH_INT_RXE | `ETH_INT_BUSY |
|
| 10490 |
|
|
`ETH_INT_TXC | `ETH_INT_RXC, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 10491 |
|
|
// not detect carrier sense in FD and no collision
|
| 10492 |
|
|
eth_phy.carrier_sense_tx_fd_detect(0);
|
| 10493 |
|
|
eth_phy.collision(0);
|
| 10494 |
|
|
// first destination address on ethernet PHY
|
| 10495 |
|
|
eth_phy.set_tx_mem_addr(0);
|
| 10496 |
|
|
// prepare BDs
|
| 10497 |
|
|
if (num_of_bd == 0)
|
| 10498 |
|
|
begin
|
| 10499 |
|
|
set_tx_bd(0, 0, i_length, 1'b1, 1'b1, 1'b1, (`MEMORY_BASE + i_data[1:0]));
|
| 10500 |
|
|
set_tx_bd(1, 1, i_length, 1'b1, 1'b1, 1'b1, `MEMORY_BASE);
|
| 10501 |
|
|
set_tx_bd_wrap(1);
|
| 10502 |
|
|
// set wb slave response: ACK (response), wbs_waits[2:0] (waits before response),
|
| 10503 |
|
|
// wbs_retries[7:0] (RTYs before ACK if RTY response selected)
|
| 10504 |
|
|
#1 wb_slave.cycle_response(`ACK_RESPONSE, 3'h2, 8'h0);
|
| 10505 |
|
|
set_tx_bd_ready(1, 1);
|
| 10506 |
|
|
set_tx_bd_ready(0, 0);
|
| 10507 |
|
|
end
|
| 10508 |
|
|
// frame under-run checking
|
| 10509 |
|
|
frame_started = 0;
|
| 10510 |
|
|
frame_ended = 0;
|
| 10511 |
|
|
wait_for_frame = 0;
|
| 10512 |
|
|
fork
|
| 10513 |
|
|
begin
|
| 10514 |
|
|
// for every 4 frames bytes 1, 2, 3 and 4 respectively are read in first word => 1 ACK
|
| 10515 |
|
|
// in other words 4 bytes are read, since length is MINFL => num_of_frames[31:2] ACKs
|
| 10516 |
|
|
repeat ((num_of_frames[31:2] + 1'b1)) @(posedge eth_ma_wb_ack_i);
|
| 10517 |
|
|
@(negedge eth_ma_wb_ack_i); // wait for last ACK to finish
|
| 10518 |
|
|
// set wb slave response: ACK (response), wbs_waits[2:0] (waits before response),
|
| 10519 |
|
|
// wbs_retries[7:0] (RTYs before ACK if RTY response selected)
|
| 10520 |
|
|
#1 wb_slave.cycle_response(`NO_RESPONSE, 3'h7, 8'hFF);
|
| 10521 |
|
|
// wait for synchronization and some additional clocks
|
| 10522 |
|
|
wait_for_frame = 1;
|
| 10523 |
|
|
// wait for frame
|
| 10524 |
|
|
wait ((wait_for_frame == 0) || (frame_started == 1))
|
| 10525 |
|
|
if ((wait_for_frame == 0) && (frame_started == 0)) // frame didn't start
|
| 10526 |
|
|
begin
|
| 10527 |
|
|
disable check_fr1;
|
| 10528 |
|
|
end
|
| 10529 |
|
|
else if ((wait_for_frame == 1) && (frame_started == 1)) // frame started
|
| 10530 |
|
|
begin
|
| 10531 |
|
|
disable wait_fr1;
|
| 10532 |
|
|
wait (frame_ended == 1);
|
| 10533 |
|
|
end
|
| 10534 |
|
|
repeat (2) @(posedge wb_clk);
|
| 10535 |
|
|
// set wb slave response: ACK (response), wbs_waits[2:0] (waits before response),
|
| 10536 |
|
|
// wbs_retries[7:0] (RTYs before ACK if RTY response selected)
|
| 10537 |
|
|
wb_slave.cycle_response(`ACK_RESPONSE, 3'h2, 8'h0);
|
| 10538 |
|
|
end
|
| 10539 |
|
|
begin: wait_fr1
|
| 10540 |
|
|
wait (wait_for_frame == 1)
|
| 10541 |
|
|
begin
|
| 10542 |
|
|
// wait for synchronization and some additional clocks
|
| 10543 |
|
|
repeat (3) @(posedge wb_clk);
|
| 10544 |
|
|
repeat (2 * tmp_ipgt) @(posedge mtx_clk);
|
| 10545 |
|
|
repeat (2) @(posedge wb_clk);
|
| 10546 |
|
|
repeat (2) @(posedge mtx_clk);
|
| 10547 |
|
|
wait_for_frame = 0;
|
| 10548 |
|
|
end
|
| 10549 |
|
|
end
|
| 10550 |
|
|
begin: check_fr1
|
| 10551 |
|
|
// wait for frame to start
|
| 10552 |
|
|
@(posedge MTxEn);
|
| 10553 |
|
|
frame_started = 1;
|
| 10554 |
|
|
$display(" Under-run (on %0d. byte) frame started", (num_of_frames + 1));
|
| 10555 |
|
|
// wait for frame to end due to under-run
|
| 10556 |
|
|
@(negedge MTxEn);
|
| 10557 |
|
|
frame_ended = 1;
|
| 10558 |
|
|
$display(" Under-run frame ended");
|
| 10559 |
|
|
end
|
| 10560 |
|
|
join
|
| 10561 |
|
|
// wait for first transmit to end, if under-run didn't happen
|
| 10562 |
|
|
if (frame_ended == 0)
|
| 10563 |
|
|
begin
|
| 10564 |
|
|
// WAIT FOR FIRST TRANSMIT
|
| 10565 |
|
|
check_tx_bd(num_of_bd, data);
|
| 10566 |
|
|
wait (MTxEn === 1'b1); // start first transmit
|
| 10567 |
|
|
if (data[15] !== 1)
|
| 10568 |
|
|
begin
|
| 10569 |
|
|
test_fail("Wrong buffer descriptor's ready bit read out from MAC");
|
| 10570 |
|
|
fail = fail + 1;
|
| 10571 |
|
|
end
|
| 10572 |
|
|
wait (MTxEn === 1'b0); // end first transmit
|
| 10573 |
|
|
while (data[15] === 1)
|
| 10574 |
|
|
begin
|
| 10575 |
|
|
check_tx_bd(num_of_bd, data);
|
| 10576 |
|
|
@(posedge wb_clk);
|
| 10577 |
|
|
end
|
| 10578 |
|
|
repeat (1) @(posedge wb_clk);
|
| 10579 |
|
|
// CHECK FIRST FRAME
|
| 10580 |
|
|
// check length of a first PACKET
|
| 10581 |
|
|
tmp_len = eth_phy.tx_len;
|
| 10582 |
|
|
#1;
|
| 10583 |
|
|
if (tmp_len != (i_length + 4))
|
| 10584 |
|
|
begin
|
| 10585 |
|
|
test_fail("Wrong length of second packet out from MAC");
|
| 10586 |
|
|
fail = fail + 1;
|
| 10587 |
|
|
end
|
| 10588 |
|
|
// checking first packet
|
| 10589 |
|
|
check_tx_packet((`MEMORY_BASE + i_data[1:0]), 0, (i_length), tmp);
|
| 10590 |
|
|
if (tmp > 0)
|
| 10591 |
|
|
begin
|
| 10592 |
|
|
test_fail("Wrong data of second transmitted packet");
|
| 10593 |
|
|
fail = fail + 1;
|
| 10594 |
|
|
end
|
| 10595 |
|
|
// check first transmited TX packet CRC
|
| 10596 |
|
|
check_tx_crc(0, (i_length), 1'b0, tmp); // length without CRC
|
| 10597 |
|
|
if (tmp > 0)
|
| 10598 |
|
|
begin
|
| 10599 |
|
|
test_fail("Wrong CRC of second transmitted packet");
|
| 10600 |
|
|
fail = fail + 1;
|
| 10601 |
|
|
end
|
| 10602 |
|
|
// check WB INT signal
|
| 10603 |
|
|
if (wb_int !== 1'b1)
|
| 10604 |
|
|
begin
|
| 10605 |
|
|
`TIME; $display("*E WB INT signal should be set");
|
| 10606 |
|
|
test_fail("WB INT signal should be set");
|
| 10607 |
|
|
fail = fail + 1;
|
| 10608 |
|
|
end
|
| 10609 |
|
|
// check TX buffer descriptor of a packet
|
| 10610 |
|
|
check_tx_bd(num_of_bd, data);
|
| 10611 |
|
|
if ( ((data[15:0] !== 16'h7800) && (num_of_bd == 1)) || // wrap bit
|
| 10612 |
|
|
((data[15:0] !== 16'h5800) && (num_of_bd < 1)) ) // without wrap bit
|
| 10613 |
|
|
begin
|
| 10614 |
|
|
`TIME; $display("*E TX buffer descriptor status is not correct: %0h", data[15:0]);
|
| 10615 |
|
|
test_fail("TX buffer descriptor status is not correct");
|
| 10616 |
|
|
fail = fail + 1;
|
| 10617 |
|
|
end
|
| 10618 |
|
|
// check interrupts
|
| 10619 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 10620 |
209 |
tadejm |
wbm_read(`ETH_INT, data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 10621 |
|
|
if ((data & `ETH_INT_TXB) !== 1'b1)
|
| 10622 |
|
|
begin
|
| 10623 |
|
|
`TIME; $display("*E Interrupt Transmit Buffer was not set, interrupt reg: %0h", data);
|
| 10624 |
|
|
test_fail("Interrupt Transmit Buffer was not set");
|
| 10625 |
|
|
fail = fail + 1;
|
| 10626 |
|
|
end
|
| 10627 |
|
|
if ((data & (~`ETH_INT_TXB)) !== 0)
|
| 10628 |
|
|
begin
|
| 10629 |
|
|
`TIME; $display("*E Other interrupts (except Transmit Buffer) were set, interrupt reg: %0h", data);
|
| 10630 |
|
|
test_fail("Other interrupts (except Transmit Buffer) were set");
|
| 10631 |
|
|
fail = fail + 1;
|
| 10632 |
|
|
end
|
| 10633 |
|
|
// clear interrupts
|
| 10634 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 10635 |
209 |
tadejm |
wbm_write(`ETH_INT, data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 10636 |
|
|
// check WB INT signal
|
| 10637 |
|
|
if (wb_int !== 1'b0)
|
| 10638 |
|
|
begin
|
| 10639 |
|
|
test_fail("WB INT signal should not be set");
|
| 10640 |
|
|
fail = fail + 1;
|
| 10641 |
|
|
end
|
| 10642 |
|
|
end
|
| 10643 |
|
|
num_of_bd = num_of_bd + 1;
|
| 10644 |
|
|
// destination address on ethernet PHY
|
| 10645 |
|
|
eth_phy.set_tx_mem_addr(0);
|
| 10646 |
|
|
// WAIT FOR FIRST TRANSMIT
|
| 10647 |
|
|
check_tx_bd(num_of_bd, data);
|
| 10648 |
|
|
wait (MTxEn === 1'b1); // start first transmit
|
| 10649 |
|
|
if (data[15] !== 1)
|
| 10650 |
|
|
begin
|
| 10651 |
|
|
test_fail("Wrong buffer descriptor's ready bit read out from MAC");
|
| 10652 |
|
|
fail = fail + 1;
|
| 10653 |
|
|
end
|
| 10654 |
|
|
wait (MTxEn === 1'b0); // end first transmit
|
| 10655 |
|
|
while (data[15] === 1)
|
| 10656 |
|
|
begin
|
| 10657 |
|
|
check_tx_bd(num_of_bd, data);
|
| 10658 |
|
|
@(posedge wb_clk);
|
| 10659 |
|
|
end
|
| 10660 |
|
|
repeat (1) @(posedge wb_clk);
|
| 10661 |
|
|
// CHECK SECOND FRAME
|
| 10662 |
|
|
// check length of a second PACKET
|
| 10663 |
|
|
tmp_len = eth_phy.tx_len;
|
| 10664 |
|
|
#1;
|
| 10665 |
|
|
if (tmp_len != (i_length + 4))
|
| 10666 |
|
|
begin
|
| 10667 |
|
|
test_fail("Wrong length of second packet out from MAC");
|
| 10668 |
|
|
fail = fail + 1;
|
| 10669 |
|
|
end
|
| 10670 |
|
|
// checking second packet
|
| 10671 |
|
|
check_tx_packet(`MEMORY_BASE, 0, (i_length), tmp);
|
| 10672 |
|
|
if (tmp > 0)
|
| 10673 |
|
|
begin
|
| 10674 |
|
|
test_fail("Wrong data of second transmitted packet");
|
| 10675 |
|
|
fail = fail + 1;
|
| 10676 |
|
|
end
|
| 10677 |
|
|
// check second transmited TX packet CRC
|
| 10678 |
|
|
check_tx_crc(0, (i_length), 1'b0, tmp); // length without CRC
|
| 10679 |
|
|
if (tmp > 0)
|
| 10680 |
|
|
begin
|
| 10681 |
|
|
test_fail("Wrong CRC of second transmitted packet");
|
| 10682 |
|
|
fail = fail + 1;
|
| 10683 |
|
|
end
|
| 10684 |
|
|
// check WB INT signal
|
| 10685 |
|
|
if (wb_int !== 1'b1)
|
| 10686 |
|
|
begin
|
| 10687 |
|
|
`TIME; $display("*E WB INT signal should be set");
|
| 10688 |
|
|
test_fail("WB INT signal should be set");
|
| 10689 |
|
|
fail = fail + 1;
|
| 10690 |
|
|
end
|
| 10691 |
|
|
// check TX buffer descriptor of a packet
|
| 10692 |
|
|
check_tx_bd(num_of_bd, data);
|
| 10693 |
|
|
if ( ((data[15:0] !== 16'h7800) && (num_of_bd == 1)) || // wrap bit
|
| 10694 |
|
|
((data[15:0] !== 16'h5800) && (num_of_bd < 1)) ) // without wrap bit
|
| 10695 |
|
|
begin
|
| 10696 |
|
|
`TIME; $display("*E TX buffer descriptor status is not correct: %0h", data[15:0]);
|
| 10697 |
|
|
test_fail("TX buffer descriptor status is not correct");
|
| 10698 |
|
|
fail = fail + 1;
|
| 10699 |
|
|
end
|
| 10700 |
|
|
// check interrupts
|
| 10701 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 10702 |
209 |
tadejm |
wbm_read(`ETH_INT, data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 10703 |
|
|
if ((data & `ETH_INT_TXB) !== 1'b1)
|
| 10704 |
|
|
begin
|
| 10705 |
|
|
`TIME; $display("*E Interrupt Transmit Buffer was not set, interrupt reg: %0h", data);
|
| 10706 |
|
|
test_fail("Interrupt Transmit Buffer was not set");
|
| 10707 |
|
|
fail = fail + 1;
|
| 10708 |
|
|
end
|
| 10709 |
|
|
if ((data & (~`ETH_INT_TXB)) !== 0)
|
| 10710 |
|
|
begin
|
| 10711 |
|
|
`TIME; $display("*E Other interrupts (except Transmit Buffer) were set, interrupt reg: %0h", data);
|
| 10712 |
|
|
test_fail("Other interrupts (except Transmit Buffer) were set");
|
| 10713 |
|
|
fail = fail + 1;
|
| 10714 |
|
|
end
|
| 10715 |
|
|
// clear interrupts
|
| 10716 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 10717 |
209 |
tadejm |
wbm_write(`ETH_INT, data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 10718 |
|
|
// check WB INT signal
|
| 10719 |
|
|
if (wb_int !== 1'b0)
|
| 10720 |
|
|
begin
|
| 10721 |
|
|
test_fail("WB INT signal should not be set");
|
| 10722 |
|
|
fail = fail + 1;
|
| 10723 |
|
|
end
|
| 10724 |
|
|
// set initial value
|
| 10725 |
|
|
i_data = i_data - 1;
|
| 10726 |
|
|
// the number of frame transmitted
|
| 10727 |
|
|
num_of_frames = num_of_frames + 1;
|
| 10728 |
|
|
num_of_bd = 0;
|
| 10729 |
|
|
// set length (LOOP variable)
|
| 10730 |
|
|
if (num_of_frames == i_length + 4) // 64 => this vas last Byte (1st .. 64th) when i_length = min_tmp - 4
|
| 10731 |
|
|
i_length = (max_tmp - 4);
|
| 10732 |
|
|
@(posedge wb_clk);
|
| 10733 |
|
|
end
|
| 10734 |
|
|
// disable TX
|
| 10735 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 10736 |
209 |
tadejm |
wbm_write(`ETH_MODER, `ETH_MODER_FULLD | `ETH_MODER_PAD | `ETH_MODER_CRCEN,
|
| 10737 |
|
|
4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 10738 |
|
|
@(posedge wb_clk);
|
| 10739 |
|
|
if(fail == 0)
|
| 10740 |
|
|
test_ok;
|
| 10741 |
|
|
else
|
| 10742 |
|
|
fail = 0;
|
| 10743 |
|
|
end
|
| 10744 |
|
|
|
| 10745 |
194 |
tadej |
end // for (test_num=start_task; test_num <= end_task; test_num=test_num+1)
|
| 10746 |
169 |
mohor |
|
| 10747 |
|
|
end
|
| 10748 |
|
|
endtask // test_mac_full_duplex_transmit
|
| 10749 |
|
|
|
| 10750 |
|
|
|
| 10751 |
209 |
tadejm |
task test_mac_full_duplex_receive;
|
| 10752 |
|
|
input [31:0] start_task;
|
| 10753 |
|
|
input [31:0] end_task;
|
| 10754 |
|
|
integer bit_start_1;
|
| 10755 |
|
|
integer bit_end_1;
|
| 10756 |
|
|
integer bit_start_2;
|
| 10757 |
|
|
integer bit_end_2;
|
| 10758 |
|
|
integer num_of_reg;
|
| 10759 |
|
|
integer num_of_frames;
|
| 10760 |
|
|
integer num_of_bd;
|
| 10761 |
|
|
integer i_addr;
|
| 10762 |
|
|
integer i_data;
|
| 10763 |
|
|
integer i_length;
|
| 10764 |
|
|
integer tmp_len;
|
| 10765 |
|
|
integer tmp_bd;
|
| 10766 |
|
|
integer tmp_bd_num;
|
| 10767 |
|
|
integer tmp_data;
|
| 10768 |
|
|
integer tmp_ipgt;
|
| 10769 |
|
|
integer test_num;
|
| 10770 |
|
|
reg [31:0] tx_bd_num;
|
| 10771 |
|
|
reg [((`MAX_BLK_SIZE * 32) - 1):0] burst_data;
|
| 10772 |
|
|
reg [((`MAX_BLK_SIZE * 32) - 1):0] burst_tmp_data;
|
| 10773 |
|
|
integer i;
|
| 10774 |
|
|
integer i1;
|
| 10775 |
|
|
integer i2;
|
| 10776 |
|
|
integer i3;
|
| 10777 |
|
|
integer fail;
|
| 10778 |
|
|
integer speed;
|
| 10779 |
|
|
reg frame_started;
|
| 10780 |
|
|
reg frame_ended;
|
| 10781 |
|
|
reg wait_for_frame;
|
| 10782 |
243 |
tadejm |
reg check_frame;
|
| 10783 |
|
|
reg stop_checking_frame;
|
| 10784 |
|
|
reg first_fr_received;
|
| 10785 |
209 |
tadejm |
reg [31:0] addr;
|
| 10786 |
|
|
reg [31:0] data;
|
| 10787 |
|
|
reg [31:0] tmp;
|
| 10788 |
|
|
reg [ 7:0] st_data;
|
| 10789 |
|
|
reg [15:0] max_tmp;
|
| 10790 |
|
|
reg [15:0] min_tmp;
|
| 10791 |
|
|
begin
|
| 10792 |
|
|
// MAC FULL DUPLEX RECEIVE TEST
|
| 10793 |
|
|
test_heading("MAC FULL DUPLEX RECEIVE TEST");
|
| 10794 |
|
|
$display(" ");
|
| 10795 |
|
|
$display("MAC FULL DUPLEX RECEIVE TEST");
|
| 10796 |
|
|
fail = 0;
|
| 10797 |
|
|
|
| 10798 |
|
|
// reset MAC registers
|
| 10799 |
|
|
hard_reset;
|
| 10800 |
|
|
// reset MAC and MII LOGIC with soft reset
|
| 10801 |
274 |
tadejm |
//reset_mac;
|
| 10802 |
|
|
//reset_mii;
|
| 10803 |
209 |
tadejm |
// set wb slave response
|
| 10804 |
|
|
wb_slave.cycle_response(`ACK_RESPONSE, wbs_waits, wbs_retries);
|
| 10805 |
|
|
|
| 10806 |
|
|
/*
|
| 10807 |
|
|
TASKS for set and control TX buffer descriptors (also send packet - set_tx_bd_ready):
|
| 10808 |
|
|
-------------------------------------------------------------------------------------
|
| 10809 |
|
|
set_tx_bd
|
| 10810 |
|
|
(tx_bd_num_start[6:0], tx_bd_num_end[6:0], len[15:0], irq, pad, crc, txpnt[31:0]);
|
| 10811 |
|
|
set_tx_bd_wrap
|
| 10812 |
|
|
(tx_bd_num_end[6:0]);
|
| 10813 |
|
|
set_tx_bd_ready
|
| 10814 |
|
|
(tx_bd_num_start[6:0], tx_bd_num_end[6:0]);
|
| 10815 |
|
|
check_tx_bd
|
| 10816 |
|
|
(tx_bd_num_start[6:0], tx_bd_status[31:0]);
|
| 10817 |
|
|
clear_tx_bd
|
| 10818 |
|
|
(tx_bd_num_start[6:0], tx_bd_num_end[6:0]);
|
| 10819 |
|
|
|
| 10820 |
|
|
TASKS for set and control RX buffer descriptors:
|
| 10821 |
|
|
------------------------------------------------
|
| 10822 |
|
|
set_rx_bd
|
| 10823 |
|
|
(rx_bd_num_strat[6:0], rx_bd_num_end[6:0], irq, rxpnt[31:0]);
|
| 10824 |
|
|
set_rx_bd_wrap
|
| 10825 |
|
|
(rx_bd_num_end[6:0]);
|
| 10826 |
|
|
set_rx_bd_empty
|
| 10827 |
|
|
(rx_bd_num_strat[6:0], rx_bd_num_end[6:0]);
|
| 10828 |
|
|
check_rx_bd
|
| 10829 |
|
|
(rx_bd_num_end[6:0], rx_bd_status);
|
| 10830 |
|
|
clear_rx_bd
|
| 10831 |
|
|
(rx_bd_num_strat[6:0], rx_bd_num_end[6:0]);
|
| 10832 |
|
|
|
| 10833 |
|
|
TASKS for set and check TX packets:
|
| 10834 |
|
|
-----------------------------------
|
| 10835 |
|
|
set_tx_packet
|
| 10836 |
|
|
(txpnt[31:0], len[15:0], eth_start_data[7:0]);
|
| 10837 |
|
|
check_tx_packet
|
| 10838 |
|
|
(txpnt_wb[31:0], txpnt_phy[31:0], len[15:0], failure[31:0]);
|
| 10839 |
|
|
|
| 10840 |
|
|
TASKS for set and check RX packets:
|
| 10841 |
|
|
-----------------------------------
|
| 10842 |
|
|
set_rx_packet
|
| 10843 |
|
|
(rxpnt[31:0], len[15:0], plus_nibble, d_addr[47:0], s_addr[47:0], type_len[15:0], start_data[7:0]);
|
| 10844 |
|
|
check_rx_packet
|
| 10845 |
|
|
(rxpnt_phy[31:0], rxpnt_wb[31:0], len[15:0], plus_nibble, successful_nibble, failure[31:0]);
|
| 10846 |
|
|
|
| 10847 |
|
|
TASKS for append and check CRC to/of TX packet:
|
| 10848 |
|
|
-----------------------------------------------
|
| 10849 |
|
|
append_tx_crc
|
| 10850 |
|
|
(txpnt_wb[31:0], len[15:0], negated_crc);
|
| 10851 |
|
|
check_tx_crc
|
| 10852 |
|
|
(txpnt_phy[31:0], len[15:0], negated_crc, failure[31:0]);
|
| 10853 |
|
|
|
| 10854 |
|
|
TASK for append CRC to RX packet (CRC is checked together with check_rx_packet):
|
| 10855 |
|
|
--------------------------------------------------------------------------------
|
| 10856 |
|
|
append_rx_crc
|
| 10857 |
|
|
(rxpnt_phy[31:0], len[15:0], plus_nibble, negated_crc);
|
| 10858 |
|
|
*/
|
| 10859 |
|
|
|
| 10860 |
|
|
//////////////////////////////////////////////////////////////////////
|
| 10861 |
|
|
//// ////
|
| 10862 |
|
|
//// test_mac_full_duplex_receive: ////
|
| 10863 |
|
|
//// ////
|
| 10864 |
|
|
//// 0: Test no receive when all buffers are TX ( 10Mbps ). ////
|
| 10865 |
|
|
//// 1: Test no receive when all buffers are TX ( 100Mbps ). ////
|
| 10866 |
243 |
tadejm |
//// 2: Test receive packet synchronization with receive ////
|
| 10867 |
|
|
//// disable/enable ( 10Mbps ). ////
|
| 10868 |
|
|
//// 3: Test receive packet synchronization with receive ////
|
| 10869 |
|
|
//// disable/enable ( 100Mbps ). ////
|
| 10870 |
|
|
//// 4: Test receive packets form MINFL to MAXFL sizes at ////
|
| 10871 |
209 |
tadejm |
//// one RX buffer decriptor ( 10Mbps ). ////
|
| 10872 |
243 |
tadejm |
//// 5: Test receive packets form MINFL to MAXFL sizes at ////
|
| 10873 |
209 |
tadejm |
//// one RX buffer decriptor ( 100Mbps ). ////
|
| 10874 |
|
|
//// ////
|
| 10875 |
|
|
//////////////////////////////////////////////////////////////////////
|
| 10876 |
|
|
for (test_num = start_task; test_num <= end_task; test_num = test_num + 1)
|
| 10877 |
|
|
begin
|
| 10878 |
|
|
|
| 10879 |
|
|
////////////////////////////////////////////////////////////////////
|
| 10880 |
|
|
//// ////
|
| 10881 |
|
|
//// Test no receive when all buffers are TX ( 10Mbps ). ////
|
| 10882 |
|
|
//// ////
|
| 10883 |
|
|
////////////////////////////////////////////////////////////////////
|
| 10884 |
|
|
if (test_num == 0) // Test no receive when all buffers are TX ( 10Mbps ).
|
| 10885 |
|
|
begin
|
| 10886 |
|
|
// TEST 0: NO RECEIVE WHEN ALL BUFFERS ARE TX ( 10Mbps )
|
| 10887 |
|
|
test_name = "TEST 0: NO RECEIVE WHEN ALL BUFFERS ARE TX ( 10Mbps )";
|
| 10888 |
|
|
`TIME; $display(" TEST 0: NO RECEIVE WHEN ALL BUFFERS ARE TX ( 10Mbps )");
|
| 10889 |
|
|
|
| 10890 |
|
|
// unmask interrupts
|
| 10891 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 10892 |
209 |
tadejm |
wbm_write(`ETH_INT_MASK, `ETH_INT_TXB | `ETH_INT_TXE | `ETH_INT_RXB | `ETH_INT_RXE | `ETH_INT_BUSY |
|
| 10893 |
|
|
`ETH_INT_TXC | `ETH_INT_RXC, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 10894 |
|
|
// set all buffer descriptors to TX - must be set before RX enable
|
| 10895 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 10896 |
209 |
tadejm |
wbm_write(`ETH_TX_BD_NUM, 32'h80, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 10897 |
223 |
tadejm |
// enable RX, set full-duplex mode, receive small, NO correct IFG
|
| 10898 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 10899 |
209 |
tadejm |
wbm_write(`ETH_MODER, `ETH_MODER_RXEN | `ETH_MODER_FULLD | `ETH_MODER_RECSMALL | `ETH_MODER_IFG |
|
| 10900 |
|
|
`ETH_MODER_PRO | `ETH_MODER_BRO,
|
| 10901 |
|
|
4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 10902 |
|
|
|
| 10903 |
|
|
// write to phy's control register for 10Mbps
|
| 10904 |
|
|
#Tp eth_phy.control_bit14_10 = 5'b00000; // bit 13 reset - speed 10
|
| 10905 |
|
|
#Tp eth_phy.control_bit8_0 = 9'h1_00; // bit 6 reset - (10/100), bit 8 set - FD
|
| 10906 |
|
|
speed = 10;
|
| 10907 |
|
|
|
| 10908 |
|
|
i = 0;
|
| 10909 |
|
|
while (i < 128)
|
| 10910 |
|
|
begin
|
| 10911 |
|
|
for (i1 = 0; i1 <= i; i1 = i1 + 1)
|
| 10912 |
|
|
begin
|
| 10913 |
|
|
set_rx_packet((i1 * 50), 10, 1'b0, 48'h1234_5678_8765, 48'h0011_2233_4455, 16'h0101, 8'h0);
|
| 10914 |
|
|
append_rx_crc((i1 * 50), 10, 1'b0, 1'b0);
|
| 10915 |
|
|
set_rx_bd(i1, i1, 1'b1, (`MEMORY_BASE + (i1 * 50)));
|
| 10916 |
|
|
end
|
| 10917 |
|
|
set_rx_bd_wrap(i);
|
| 10918 |
|
|
set_rx_bd_empty(0, i);
|
| 10919 |
|
|
for (i1 = 0; i1 <= i; i1 = i1 + 1)
|
| 10920 |
|
|
begin
|
| 10921 |
|
|
#1 eth_phy.send_rx_packet(64'h0055_5555_5555_5555, 4'h7, 8'hD5, (i1 * 50), 14, 1'b0);
|
| 10922 |
|
|
repeat(10) @(posedge mrx_clk);
|
| 10923 |
|
|
end
|
| 10924 |
|
|
@(posedge mrx_clk);
|
| 10925 |
|
|
for (i2 = 0; i2 < 20; i2 = i2 + 1)
|
| 10926 |
|
|
begin
|
| 10927 |
|
|
check_rx_bd(0, tmp);
|
| 10928 |
|
|
#1;
|
| 10929 |
|
|
if (tmp[15] === 1'b0)
|
| 10930 |
|
|
begin
|
| 10931 |
|
|
test_fail("Receive should not start at all");
|
| 10932 |
|
|
fail = fail + 1;
|
| 10933 |
|
|
`TIME; $display("*E Receive of %d packets should not start at all - empty is 0", i);
|
| 10934 |
|
|
end
|
| 10935 |
|
|
if (tmp[7:0] !== 0)
|
| 10936 |
|
|
begin
|
| 10937 |
|
|
test_fail("Receive should not be finished since it should not start at all");
|
| 10938 |
|
|
fail = fail + 1;
|
| 10939 |
|
|
`TIME; $display("*E Receive of should not be finished since it should not start at all");
|
| 10940 |
|
|
end
|
| 10941 |
|
|
@(posedge wb_clk);
|
| 10942 |
|
|
end
|
| 10943 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 10944 |
209 |
tadejm |
wbm_read(`ETH_INT, tmp, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 10945 |
|
|
if (tmp[6:0] !== 0)
|
| 10946 |
|
|
begin
|
| 10947 |
|
|
test_fail("Receive should not get INT since it should not start at all");
|
| 10948 |
|
|
fail = fail + 1;
|
| 10949 |
|
|
`TIME; $display("*E Receive of should not get INT since it should not start at all");
|
| 10950 |
|
|
end
|
| 10951 |
|
|
clear_rx_bd(0, i);
|
| 10952 |
|
|
if ((i < 5) || (i > 124))
|
| 10953 |
|
|
i = i + 1;
|
| 10954 |
|
|
else
|
| 10955 |
|
|
i = i + 120;
|
| 10956 |
|
|
end
|
| 10957 |
|
|
// disable RX
|
| 10958 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 10959 |
209 |
tadejm |
wbm_write(`ETH_MODER, `ETH_MODER_FULLD | `ETH_MODER_RECSMALL | `ETH_MODER_IFG |
|
| 10960 |
|
|
`ETH_MODER_PRO | `ETH_MODER_BRO,
|
| 10961 |
|
|
4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 10962 |
|
|
if(fail == 0)
|
| 10963 |
|
|
test_ok;
|
| 10964 |
|
|
else
|
| 10965 |
|
|
fail = 0;
|
| 10966 |
|
|
end
|
| 10967 |
|
|
|
| 10968 |
|
|
|
| 10969 |
|
|
////////////////////////////////////////////////////////////////////
|
| 10970 |
|
|
//// ////
|
| 10971 |
|
|
//// Test no receive when all buffers are TX ( 100Mbps ). ////
|
| 10972 |
|
|
//// ////
|
| 10973 |
|
|
////////////////////////////////////////////////////////////////////
|
| 10974 |
|
|
if (test_num == 1) // Test no receive when all buffers are TX ( 100Mbps ).
|
| 10975 |
|
|
begin
|
| 10976 |
|
|
// TEST 1: NO RECEIVE WHEN ALL BUFFERS ARE TX ( 100Mbps )
|
| 10977 |
|
|
test_name = "TEST 1: NO RECEIVE WHEN ALL BUFFERS ARE TX ( 100Mbps )";
|
| 10978 |
|
|
`TIME; $display(" TEST 1: NO RECEIVE WHEN ALL BUFFERS ARE TX ( 100Mbps )");
|
| 10979 |
|
|
|
| 10980 |
|
|
// unmask interrupts
|
| 10981 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 10982 |
209 |
tadejm |
wbm_write(`ETH_INT_MASK, `ETH_INT_TXB | `ETH_INT_TXE | `ETH_INT_RXB | `ETH_INT_RXE | `ETH_INT_BUSY |
|
| 10983 |
|
|
`ETH_INT_TXC | `ETH_INT_RXC, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 10984 |
|
|
// set all buffer descriptors to TX - must be set before RX enable
|
| 10985 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 10986 |
209 |
tadejm |
wbm_write(`ETH_TX_BD_NUM, 32'h80, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 10987 |
223 |
tadejm |
// enable RX, set full-duplex mode, receive small, NO correct IFG
|
| 10988 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 10989 |
209 |
tadejm |
wbm_write(`ETH_MODER, `ETH_MODER_RXEN | `ETH_MODER_FULLD | `ETH_MODER_RECSMALL | `ETH_MODER_IFG |
|
| 10990 |
|
|
`ETH_MODER_PRO | `ETH_MODER_BRO,
|
| 10991 |
|
|
4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 10992 |
|
|
|
| 10993 |
|
|
// write to phy's control register for 100Mbps
|
| 10994 |
|
|
#Tp eth_phy.control_bit14_10 = 5'b01000; // bit 13 set - speed 100
|
| 10995 |
|
|
#Tp eth_phy.control_bit8_0 = 9'h1_00; // bit 6 reset - (10/100), bit 8 set - FD
|
| 10996 |
|
|
speed = 100;
|
| 10997 |
|
|
|
| 10998 |
|
|
i = 0;
|
| 10999 |
|
|
while (i < 128)
|
| 11000 |
|
|
begin
|
| 11001 |
|
|
for (i1 = 0; i1 <= i; i1 = i1 + 1)
|
| 11002 |
|
|
begin
|
| 11003 |
|
|
set_rx_packet((i1 * 50), 10, 1'b0, 48'h1234_5678_8765, 48'h0011_2233_4455, 16'h0101, 8'h0);
|
| 11004 |
|
|
append_rx_crc((i1 * 50), 10, 1'b0, 1'b0);
|
| 11005 |
|
|
set_rx_bd(i1, i1, 1'b1, (`MEMORY_BASE + (i1 * 50)));
|
| 11006 |
|
|
end
|
| 11007 |
|
|
set_rx_bd_wrap(i);
|
| 11008 |
|
|
set_rx_bd_empty(0, i);
|
| 11009 |
|
|
for (i1 = 0; i1 <= i; i1 = i1 + 1)
|
| 11010 |
|
|
begin
|
| 11011 |
|
|
#1 eth_phy.send_rx_packet(64'h0055_5555_5555_5555, 4'h7, 8'hD5, (i1 * 50), 14, 1'b0);
|
| 11012 |
|
|
repeat(10) @(posedge mrx_clk);
|
| 11013 |
|
|
end
|
| 11014 |
|
|
@(posedge mrx_clk);
|
| 11015 |
|
|
for (i2 = 0; i2 < 20; i2 = i2 + 1)
|
| 11016 |
|
|
begin
|
| 11017 |
|
|
check_rx_bd(0, tmp);
|
| 11018 |
|
|
#1;
|
| 11019 |
|
|
if (tmp[15] === 1'b0)
|
| 11020 |
|
|
begin
|
| 11021 |
|
|
test_fail("Receive should not start at all");
|
| 11022 |
|
|
fail = fail + 1;
|
| 11023 |
|
|
`TIME; $display("*E Receive of %d packets should not start at all - empty is 0", i);
|
| 11024 |
|
|
end
|
| 11025 |
|
|
if (tmp[7:0] !== 0)
|
| 11026 |
|
|
begin
|
| 11027 |
|
|
test_fail("Receive should not be finished since it should not start at all");
|
| 11028 |
|
|
fail = fail + 1;
|
| 11029 |
|
|
`TIME; $display("*E Receive of should not be finished since it should not start at all");
|
| 11030 |
|
|
end
|
| 11031 |
|
|
@(posedge wb_clk);
|
| 11032 |
|
|
end
|
| 11033 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 11034 |
209 |
tadejm |
wbm_read(`ETH_INT, tmp, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 11035 |
|
|
if (tmp[6:0] !== 0)
|
| 11036 |
|
|
begin
|
| 11037 |
|
|
test_fail("Receive should not get INT since it should not start at all");
|
| 11038 |
|
|
fail = fail + 1;
|
| 11039 |
|
|
`TIME; $display("*E Receive of should not get INT since it should not start at all");
|
| 11040 |
|
|
end
|
| 11041 |
|
|
clear_rx_bd(0, i);
|
| 11042 |
|
|
if ((i < 5) || (i > 124))
|
| 11043 |
|
|
i = i + 1;
|
| 11044 |
|
|
else
|
| 11045 |
|
|
i = i + 120;
|
| 11046 |
|
|
end
|
| 11047 |
|
|
// disable RX
|
| 11048 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 11049 |
209 |
tadejm |
wbm_write(`ETH_MODER, `ETH_MODER_FULLD | `ETH_MODER_RECSMALL | `ETH_MODER_IFG |
|
| 11050 |
|
|
`ETH_MODER_PRO | `ETH_MODER_BRO,
|
| 11051 |
|
|
4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 11052 |
|
|
if(fail == 0)
|
| 11053 |
|
|
test_ok;
|
| 11054 |
|
|
else
|
| 11055 |
|
|
fail = 0;
|
| 11056 |
|
|
end
|
| 11057 |
|
|
|
| 11058 |
|
|
|
| 11059 |
|
|
////////////////////////////////////////////////////////////////////
|
| 11060 |
|
|
//// ////
|
| 11061 |
243 |
tadejm |
//// Test receive packet synchronization with receive ////
|
| 11062 |
|
|
//// disable/enable ( 10Mbps ). ////
|
| 11063 |
|
|
//// ////
|
| 11064 |
|
|
////////////////////////////////////////////////////////////////////
|
| 11065 |
|
|
if (test_num == 2) // Test no receive when all buffers are TX ( 10Mbps ).
|
| 11066 |
|
|
begin
|
| 11067 |
|
|
// TEST 2: RECEIVE PACKET SYNCHRONIZATION WITH RECEIVE DISABLE/ENABLE ( 10Mbps )
|
| 11068 |
|
|
test_name = "TEST 2: RECEIVE PACKET SYNCHRONIZATION WITH RECEIVE DISABLE/ENABLE ( 10Mbps )";
|
| 11069 |
|
|
`TIME; $display(" TEST 2: RECEIVE PACKET SYNCHRONIZATION WITH RECEIVE DISABLE/ENABLE ( 10Mbps )");
|
| 11070 |
|
|
|
| 11071 |
|
|
// unmask interrupts
|
| 11072 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 11073 |
243 |
tadejm |
wbm_write(`ETH_INT_MASK, `ETH_INT_TXB | `ETH_INT_TXE | `ETH_INT_RXB | `ETH_INT_RXE | `ETH_INT_BUSY |
|
| 11074 |
|
|
`ETH_INT_TXC | `ETH_INT_RXC, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 11075 |
|
|
// set 10 RX buffer descriptor (8'h80 - 8'hA) - must be set before RX enable
|
| 11076 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 11077 |
243 |
tadejm |
wbm_write(`ETH_TX_BD_NUM, 32'h76, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 11078 |
|
|
// disable RX, set full-duplex mode, NO receive small, NO correct IFG
|
| 11079 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 11080 |
243 |
tadejm |
wbm_write(`ETH_MODER, `ETH_MODER_FULLD | `ETH_MODER_IFG |
|
| 11081 |
|
|
`ETH_MODER_PRO | `ETH_MODER_BRO,
|
| 11082 |
|
|
4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 11083 |
|
|
// prepare two packets of MAXFL length
|
| 11084 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 11085 |
243 |
tadejm |
wbm_read(`ETH_PACKETLEN, tmp, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 11086 |
|
|
max_tmp = tmp[15:0]; // 18 bytes consists of 6B dest addr, 6B source addr, 2B type/len, 4B CRC
|
| 11087 |
|
|
min_tmp = tmp[31:16];
|
| 11088 |
|
|
st_data = 8'h0F;
|
| 11089 |
|
|
set_rx_packet(0, (min_tmp + 1), 1'b0, 48'h0102_0304_0506, 48'h0708_090A_0B0C, 16'h0D0E, st_data); // length without CRC
|
| 11090 |
|
|
append_rx_crc(0, (min_tmp + 1), 1'b0, 1'b0);
|
| 11091 |
|
|
st_data = 8'h1A;
|
| 11092 |
|
|
set_rx_packet(max_tmp, (min_tmp + 1), 1'b0, 48'h1234_5678_8765, 48'hA1B2_C3D4_E5F6, 16'hE77E, st_data);
|
| 11093 |
|
|
append_rx_crc(max_tmp, (min_tmp + 1), 1'b0, 1'b0);
|
| 11094 |
|
|
// check WB INT signal
|
| 11095 |
|
|
if (wb_int !== 1'b0)
|
| 11096 |
|
|
begin
|
| 11097 |
|
|
test_fail("WB INT signal should not be set");
|
| 11098 |
|
|
fail = fail + 1;
|
| 11099 |
|
|
end
|
| 11100 |
|
|
|
| 11101 |
|
|
// write to phy's control register for 10Mbps
|
| 11102 |
|
|
#Tp eth_phy.control_bit14_10 = 5'b00000; // bit 13 reset - speed 10
|
| 11103 |
|
|
#Tp eth_phy.control_bit8_0 = 9'h1_00; // bit 6 reset - (10/100), bit 8 set - FD
|
| 11104 |
|
|
speed = 10;
|
| 11105 |
|
|
|
| 11106 |
|
|
frame_started = 0;
|
| 11107 |
|
|
frame_ended = 0;
|
| 11108 |
|
|
wait_for_frame = 0;
|
| 11109 |
|
|
check_frame = 0;
|
| 11110 |
|
|
stop_checking_frame = 0;
|
| 11111 |
|
|
first_fr_received = 1; // at the beginning the first frame of each two will be received!
|
| 11112 |
|
|
|
| 11113 |
|
|
num_of_frames = 0; //
|
| 11114 |
|
|
num_of_bd = 0;
|
| 11115 |
|
|
i_length = (min_tmp + 1); // 5 bytes longer than MINFL
|
| 11116 |
|
|
while (i_length < (max_tmp - 4))
|
| 11117 |
|
|
begin
|
| 11118 |
|
|
// choose generating carrier sense and collision
|
| 11119 |
|
|
case (num_of_frames[1:0])
|
| 11120 |
|
|
2'h0: // Interrupt is generated
|
| 11121 |
|
|
begin
|
| 11122 |
|
|
// enable interrupt generation
|
| 11123 |
|
|
set_rx_bd(118, 118, 1'b1, (`MEMORY_BASE + num_of_frames[1:0]));
|
| 11124 |
|
|
// not detect carrier sense in FD and no collision
|
| 11125 |
|
|
eth_phy.no_carrier_sense_rx_fd_detect(0);
|
| 11126 |
|
|
eth_phy.collision(0);
|
| 11127 |
|
|
end
|
| 11128 |
|
|
2'h1: // Interrupt is generated
|
| 11129 |
|
|
begin
|
| 11130 |
|
|
// enable interrupt generation
|
| 11131 |
|
|
set_rx_bd(118, 118, 1'b1, (`MEMORY_BASE + num_of_frames[1:0]));
|
| 11132 |
|
|
// detect carrier sense in FD and no collision
|
| 11133 |
|
|
eth_phy.no_carrier_sense_rx_fd_detect(1);
|
| 11134 |
|
|
eth_phy.collision(0);
|
| 11135 |
|
|
end
|
| 11136 |
|
|
2'h2: // Interrupt is generated
|
| 11137 |
|
|
begin
|
| 11138 |
|
|
// disable interrupt generation
|
| 11139 |
|
|
set_rx_bd(118, 118, 1'b1, (`MEMORY_BASE + num_of_frames[1:0]));
|
| 11140 |
|
|
// not detect carrier sense in FD and set collision
|
| 11141 |
|
|
eth_phy.no_carrier_sense_rx_fd_detect(0);
|
| 11142 |
|
|
eth_phy.collision(1);
|
| 11143 |
|
|
end
|
| 11144 |
|
|
default: // 2'h3: // Interrupt is generated
|
| 11145 |
|
|
begin
|
| 11146 |
|
|
// disable interrupt generation
|
| 11147 |
|
|
set_rx_bd(118, 118, 1'b1, (`MEMORY_BASE + num_of_frames[1:0]));
|
| 11148 |
|
|
// detect carrier sense in FD and set collision
|
| 11149 |
|
|
eth_phy.no_carrier_sense_rx_fd_detect(1);
|
| 11150 |
|
|
eth_phy.collision(1);
|
| 11151 |
|
|
end
|
| 11152 |
|
|
endcase
|
| 11153 |
|
|
// set wrap bit
|
| 11154 |
|
|
set_rx_bd_wrap(118);
|
| 11155 |
|
|
set_rx_bd_empty(118, 118);
|
| 11156 |
|
|
check_frame = 0;
|
| 11157 |
|
|
stop_checking_frame = 0;
|
| 11158 |
|
|
tmp_data = 0;
|
| 11159 |
|
|
fork
|
| 11160 |
|
|
begin // enable RX MAC on first of each two packets - every second should be recived normaly
|
| 11161 |
|
|
if (num_of_frames[0] == 1'b0)
|
| 11162 |
|
|
begin
|
| 11163 |
|
|
repeat(1) @(posedge wb_clk);
|
| 11164 |
|
|
if (num_of_frames[1] == 1'b0)
|
| 11165 |
|
|
begin
|
| 11166 |
|
|
repeat (num_of_frames[31:2]) @(posedge mrx_clk); // for every (second) frame enable receiver one clock later
|
| 11167 |
|
|
end
|
| 11168 |
|
|
else
|
| 11169 |
|
|
begin
|
| 11170 |
|
|
@(posedge mrx_clk);
|
| 11171 |
|
|
repeat (num_of_frames[31:2]) @(negedge mrx_clk); // for every (second) frame enable receiver one clock later
|
| 11172 |
|
|
end
|
| 11173 |
|
|
// enable RX, set full-duplex mode, NO receive small, NO correct IFG
|
| 11174 |
|
|
wbm_init_waits = 4'h0;
|
| 11175 |
|
|
wbm_subseq_waits = 4'h0;
|
| 11176 |
274 |
tadejm |
#1 wait (wbm_working == 0);
|
| 11177 |
|
|
wbm_write(`ETH_MODER, `ETH_MODER_RXEN | `ETH_MODER_FULLD | `ETH_MODER_IFG |
|
| 11178 |
243 |
tadejm |
`ETH_MODER_PRO | `ETH_MODER_BRO,
|
| 11179 |
|
|
4'hF, 1, wbm_init_waits, wbm_subseq_waits); // write ASAP
|
| 11180 |
|
|
end
|
| 11181 |
|
|
end
|
| 11182 |
|
|
begin // send a packet from PHY RX
|
| 11183 |
|
|
repeat(1) @(posedge wb_clk); // wait for WB write when it is without delays
|
| 11184 |
|
|
if (num_of_frames[1] == 1'b0)
|
| 11185 |
|
|
begin
|
| 11186 |
|
|
set_rx_addr_type(0, 48'h0102_0304_0506, 48'h0708_090A_0B0C, 16'h0D0E);
|
| 11187 |
|
|
#1 eth_phy.send_rx_packet(64'h0055_5555_5555_5555, 4'h7, 8'hD5, 0, (i_length + 4), 1'b0);
|
| 11188 |
|
|
end
|
| 11189 |
|
|
else
|
| 11190 |
|
|
begin
|
| 11191 |
|
|
set_rx_addr_type((max_tmp), 48'h1234_5678_8765, 48'hA1B2_C3D4_E5F6, 16'hE77E);
|
| 11192 |
|
|
#1 eth_phy.send_rx_packet(64'h0055_5555_5555_5555, 4'h7, 8'hD5, max_tmp, (i_length + 4), 1'b0);
|
| 11193 |
|
|
end
|
| 11194 |
|
|
end
|
| 11195 |
|
|
begin: send_packet0
|
| 11196 |
|
|
wait (MRxDV === 1'b1); // start transmit
|
| 11197 |
|
|
wait (MRxDV === 1'b0); // end transmit
|
| 11198 |
|
|
check_frame = 1;
|
| 11199 |
|
|
repeat(10) @(posedge mrx_clk);
|
| 11200 |
|
|
repeat(15) @(posedge wb_clk);
|
| 11201 |
|
|
stop_checking_frame = 1;
|
| 11202 |
|
|
end
|
| 11203 |
|
|
begin // count WB clocks between ACK (negedge) and RX_DV (posedge) or vice-versa
|
| 11204 |
|
|
@(posedge eth_sl_wb_ack_o or posedge MRxDV);
|
| 11205 |
|
|
if ((eth_sl_wb_ack_o === 1'b1) && (MRxDV === 1'b1))
|
| 11206 |
|
|
begin
|
| 11207 |
|
|
tmp_data = 32'h8000_0001; // bit[31]==1 => 'posedge MRxDV' was before 'negedge eth_sl_wb_ack_o'
|
| 11208 |
|
|
end
|
| 11209 |
|
|
else if (MRxDV === 1'b1)
|
| 11210 |
|
|
begin
|
| 11211 |
|
|
while (eth_sl_wb_ack_o === 1'b0)
|
| 11212 |
|
|
begin
|
| 11213 |
|
|
@(posedge wb_clk);
|
| 11214 |
|
|
tmp_data = tmp_data + 1;
|
| 11215 |
|
|
end
|
| 11216 |
|
|
tmp_data = tmp_data | 32'h8000_0000; // bit[31]==1 => 'posedge MRxDV' was before 'negedge eth_sl_wb_ack_o'
|
| 11217 |
|
|
end
|
| 11218 |
|
|
else if (eth_sl_wb_ack_o === 1'b1)
|
| 11219 |
|
|
begin
|
| 11220 |
|
|
@(posedge wb_clk); // wait for one clock => tmp_data 'becomes' 0
|
| 11221 |
|
|
while (MRxDV === 1'b0)
|
| 11222 |
|
|
begin
|
| 11223 |
|
|
@(posedge wb_clk);
|
| 11224 |
|
|
tmp_data = tmp_data + 1; // bit[31]==0 => 'negedge eth_sl_wb_ack_o' was equal or before 'posedge MRxDV'
|
| 11225 |
|
|
end
|
| 11226 |
|
|
end
|
| 11227 |
|
|
end
|
| 11228 |
|
|
begin // check packet
|
| 11229 |
|
|
wait (check_frame == 1);
|
| 11230 |
|
|
check_rx_bd(118, tmp_bd);
|
| 11231 |
|
|
while ((tmp_bd[15] === 1) && (stop_checking_frame == 0))
|
| 11232 |
|
|
begin
|
| 11233 |
|
|
#1 check_rx_bd(118, tmp_bd);
|
| 11234 |
|
|
@(posedge wb_clk);
|
| 11235 |
|
|
end
|
| 11236 |
|
|
if (num_of_frames[0] == 1'b0)
|
| 11237 |
|
|
begin
|
| 11238 |
|
|
if (tmp_bd[15] === 1)
|
| 11239 |
|
|
begin
|
| 11240 |
|
|
if (first_fr_received == 1)
|
| 11241 |
|
|
begin
|
| 11242 |
|
|
first_fr_received = 0;
|
| 11243 |
|
|
$display(" %0d packets (without this one) are checked - packets are received by two in a set",
|
| 11244 |
|
|
num_of_frames); // +1 due to start with 0 AND -1 because this packet is excluded
|
| 11245 |
|
|
$display(" From this moment:");
|
| 11246 |
|
|
$display(" first one of two packets (including this one) is not accepted due to late RX enable");
|
| 11247 |
|
|
if (tmp_data[31])
|
| 11248 |
|
|
$display(" ->RX enable set %0d WB clks after RX_DV", tmp_data[30:0]);
|
| 11249 |
|
|
else
|
| 11250 |
|
|
$display(" ->RX enable set %0d WB clks before RX_DV", tmp_data[30:0]);
|
| 11251 |
|
|
end
|
| 11252 |
|
|
end
|
| 11253 |
|
|
end
|
| 11254 |
|
|
if (stop_checking_frame == 0)
|
| 11255 |
|
|
disable send_packet0;
|
| 11256 |
|
|
end
|
| 11257 |
|
|
join
|
| 11258 |
|
|
// ONLY IF packet was received!
|
| 11259 |
|
|
if (tmp_bd[15] === 0)
|
| 11260 |
|
|
begin
|
| 11261 |
|
|
// check length of a PACKET
|
| 11262 |
|
|
if (tmp_bd[31:16] != (i_length + 4))
|
| 11263 |
|
|
begin
|
| 11264 |
|
|
`TIME; $display("*E Wrong length of the packet out from PHY (%0d instead of %0d)",
|
| 11265 |
|
|
tmp_bd[31:16], (i_length + 4));
|
| 11266 |
|
|
test_fail("Wrong length of the packet out from PHY");
|
| 11267 |
|
|
fail = fail + 1;
|
| 11268 |
|
|
end
|
| 11269 |
|
|
// check received RX packet data and CRC
|
| 11270 |
|
|
if (first_fr_received == 0) // if PREVIOUS RX buffer descriptor was not ready, pointer address is -1
|
| 11271 |
|
|
begin
|
| 11272 |
|
|
if (num_of_frames[1] == 1'b0)
|
| 11273 |
|
|
begin
|
| 11274 |
|
|
check_rx_packet(0, (`MEMORY_BASE + num_of_frames[1:0] - 1'b1), (i_length + 4), 1'b0, 1'b0, tmp);
|
| 11275 |
|
|
end
|
| 11276 |
|
|
else
|
| 11277 |
|
|
begin
|
| 11278 |
|
|
check_rx_packet(max_tmp, (`MEMORY_BASE + num_of_frames[1:0] - 1'b1), (i_length + 4), 1'b0, 1'b0, tmp);
|
| 11279 |
|
|
end
|
| 11280 |
|
|
if (tmp > 0)
|
| 11281 |
|
|
begin
|
| 11282 |
|
|
`TIME; $display("*E Wrong data of the received packet");
|
| 11283 |
|
|
test_fail("Wrong data of the received packet");
|
| 11284 |
|
|
fail = fail + 1;
|
| 11285 |
|
|
end
|
| 11286 |
|
|
end
|
| 11287 |
|
|
else // if PREVIOUS RX buffer descriptor was ready
|
| 11288 |
|
|
begin
|
| 11289 |
|
|
if (num_of_frames[1] == 1'b0)
|
| 11290 |
|
|
begin
|
| 11291 |
|
|
check_rx_packet(0, (`MEMORY_BASE + num_of_frames[1:0]), (i_length + 4), 1'b0, 1'b0, tmp);
|
| 11292 |
|
|
end
|
| 11293 |
|
|
else
|
| 11294 |
|
|
begin
|
| 11295 |
|
|
check_rx_packet(max_tmp, (`MEMORY_BASE + num_of_frames[1:0]), (i_length + 4), 1'b0, 1'b0, tmp);
|
| 11296 |
|
|
end
|
| 11297 |
|
|
if (tmp > 0)
|
| 11298 |
|
|
begin
|
| 11299 |
|
|
`TIME; $display("*E Wrong data of the received packet");
|
| 11300 |
|
|
test_fail("Wrong data of the received packet");
|
| 11301 |
|
|
fail = fail + 1;
|
| 11302 |
|
|
end
|
| 11303 |
|
|
end
|
| 11304 |
|
|
end
|
| 11305 |
|
|
// check WB INT signal
|
| 11306 |
|
|
if ((num_of_frames[0] == 1'b0) && (first_fr_received == 0)) // interrupt enabled but no receive
|
| 11307 |
|
|
begin
|
| 11308 |
|
|
if (wb_int !== 1'b0)
|
| 11309 |
|
|
begin
|
| 11310 |
|
|
`TIME; $display("*E WB INT signal should not be set");
|
| 11311 |
|
|
test_fail("WB INT signal should not be set");
|
| 11312 |
|
|
fail = fail + 1;
|
| 11313 |
|
|
end
|
| 11314 |
|
|
end
|
| 11315 |
|
|
else
|
| 11316 |
|
|
begin
|
| 11317 |
|
|
if (wb_int !== 1'b1)
|
| 11318 |
|
|
begin
|
| 11319 |
|
|
`TIME; $display("*E WB INT signal should be set");
|
| 11320 |
|
|
test_fail("WB INT signal should be set");
|
| 11321 |
|
|
fail = fail + 1;
|
| 11322 |
|
|
end
|
| 11323 |
|
|
end
|
| 11324 |
|
|
// check RX buffer descriptor of a packet - only 15 LSBits
|
| 11325 |
|
|
check_rx_bd(118, data);
|
| 11326 |
|
|
if ((num_of_frames[0] == 1'b0) && (first_fr_received == 0)) // interrupt enabled but no receive
|
| 11327 |
|
|
begin
|
| 11328 |
|
|
if (data[15:0] !== 16'hE000)
|
| 11329 |
|
|
begin
|
| 11330 |
|
|
`TIME; $display("*E RX buffer descriptor status is not correct: %0h", data[15:0]);
|
| 11331 |
|
|
test_fail("RX buffer descriptor status is not correct");
|
| 11332 |
|
|
fail = fail + 1;
|
| 11333 |
|
|
end
|
| 11334 |
|
|
end
|
| 11335 |
|
|
else // interrupt enabled
|
| 11336 |
|
|
begin
|
| 11337 |
|
|
if (data[15:0] !== 16'h6000)
|
| 11338 |
|
|
begin
|
| 11339 |
|
|
`TIME; $display("*E RX buffer descriptor status is not correct: %0h", data[15:0]);
|
| 11340 |
|
|
test_fail("RX buffer descriptor status is not correct");
|
| 11341 |
|
|
fail = fail + 1;
|
| 11342 |
|
|
end
|
| 11343 |
|
|
end
|
| 11344 |
|
|
// check interrupts
|
| 11345 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 11346 |
243 |
tadejm |
wbm_read(`ETH_INT, data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 11347 |
|
|
if ((num_of_frames[0] == 1'b0) && (first_fr_received == 0)) // interrupt enabled but no receive
|
| 11348 |
|
|
begin
|
| 11349 |
|
|
if (data !== 0)
|
| 11350 |
|
|
begin
|
| 11351 |
|
|
`TIME; $display("*E Any of interrupts was set, interrupt reg: %0h, len: %0h", data, num_of_frames[1:0]);
|
| 11352 |
|
|
test_fail("Any of interrupts was set");
|
| 11353 |
|
|
fail = fail + 1;
|
| 11354 |
|
|
end
|
| 11355 |
|
|
end
|
| 11356 |
|
|
else
|
| 11357 |
|
|
begin
|
| 11358 |
|
|
if ((data & `ETH_INT_RXB) !== `ETH_INT_RXB)
|
| 11359 |
|
|
begin
|
| 11360 |
|
|
`TIME; $display("*E Interrupt Receive Buffer was not set, interrupt reg: %0h", data);
|
| 11361 |
|
|
test_fail("Interrupt Receive Buffer was not set");
|
| 11362 |
|
|
fail = fail + 1;
|
| 11363 |
|
|
end
|
| 11364 |
|
|
if ((data & (~`ETH_INT_RXB)) !== 0)
|
| 11365 |
|
|
begin
|
| 11366 |
|
|
`TIME; $display("*E Other interrupts (except Receive Buffer) were set, interrupt reg: %0h", data);
|
| 11367 |
|
|
test_fail("Other interrupts (except Receive Buffer) were set");
|
| 11368 |
|
|
fail = fail + 1;
|
| 11369 |
|
|
end
|
| 11370 |
|
|
end
|
| 11371 |
|
|
// clear interrupts
|
| 11372 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 11373 |
243 |
tadejm |
wbm_write(`ETH_INT, data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 11374 |
|
|
// check WB INT signal
|
| 11375 |
|
|
if (wb_int !== 1'b0)
|
| 11376 |
|
|
begin
|
| 11377 |
|
|
test_fail("WB INT signal should not be set");
|
| 11378 |
|
|
fail = fail + 1;
|
| 11379 |
|
|
end
|
| 11380 |
|
|
// disable RX after two packets
|
| 11381 |
|
|
if (num_of_frames[0] == 1'b1)
|
| 11382 |
|
|
begin
|
| 11383 |
|
|
// disable RX, set full-duplex mode, NO receive small, NO correct IFG
|
| 11384 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 11385 |
243 |
tadejm |
wbm_write(`ETH_MODER, `ETH_MODER_FULLD | `ETH_MODER_IFG |
|
| 11386 |
|
|
`ETH_MODER_PRO | `ETH_MODER_BRO,
|
| 11387 |
|
|
4'hF, 1, 4'h0, 4'h0); // write ASAP
|
| 11388 |
|
|
end
|
| 11389 |
|
|
// the number of frame transmitted
|
| 11390 |
|
|
num_of_frames = num_of_frames + 1;
|
| 11391 |
|
|
num_of_bd = 0;
|
| 11392 |
|
|
// set length (LOOP variable)
|
| 11393 |
|
|
if (num_of_frames[31:2] == (i_length * 2 + 16)) // 64 => this vas last Byte (1st .. 64th) when i_length = min_tmp - 4
|
| 11394 |
|
|
i_length = (max_tmp - 4);
|
| 11395 |
|
|
@(posedge wb_clk);
|
| 11396 |
|
|
end
|
| 11397 |
|
|
// disable RX
|
| 11398 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 11399 |
243 |
tadejm |
wbm_write(`ETH_MODER, `ETH_MODER_FULLD | `ETH_MODER_RECSMALL | `ETH_MODER_IFG |
|
| 11400 |
|
|
`ETH_MODER_PRO | `ETH_MODER_BRO,
|
| 11401 |
|
|
4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 11402 |
|
|
if(fail == 0)
|
| 11403 |
|
|
test_ok;
|
| 11404 |
|
|
else
|
| 11405 |
|
|
fail = 0;
|
| 11406 |
|
|
end
|
| 11407 |
|
|
|
| 11408 |
|
|
|
| 11409 |
|
|
////////////////////////////////////////////////////////////////////
|
| 11410 |
|
|
//// ////
|
| 11411 |
|
|
//// Test receive packet synchronization with receive ////
|
| 11412 |
|
|
//// disable/enable ( 100Mbps ). ////
|
| 11413 |
|
|
//// ////
|
| 11414 |
|
|
////////////////////////////////////////////////////////////////////
|
| 11415 |
|
|
if (test_num == 3) // Test no receive when all buffers are TX ( 100Mbps ).
|
| 11416 |
|
|
begin
|
| 11417 |
|
|
// TEST 3: RECEIVE PACKET SYNCHRONIZATION WITH RECEIVE DISABLE/ENABLE ( 100Mbps )
|
| 11418 |
|
|
test_name = "TEST 3: RECEIVE PACKET SYNCHRONIZATION WITH RECEIVE DISABLE/ENABLE ( 100Mbps )";
|
| 11419 |
|
|
`TIME; $display(" TEST 3: RECEIVE PACKET SYNCHRONIZATION WITH RECEIVE DISABLE/ENABLE ( 100Mbps )");
|
| 11420 |
|
|
|
| 11421 |
|
|
// unmask interrupts
|
| 11422 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 11423 |
243 |
tadejm |
wbm_write(`ETH_INT_MASK, `ETH_INT_TXB | `ETH_INT_TXE | `ETH_INT_RXB | `ETH_INT_RXE | `ETH_INT_BUSY |
|
| 11424 |
|
|
`ETH_INT_TXC | `ETH_INT_RXC, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 11425 |
|
|
// set 10 RX buffer descriptor (8'h80 - 8'hA) - must be set before RX enable
|
| 11426 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 11427 |
243 |
tadejm |
wbm_write(`ETH_TX_BD_NUM, 32'h76, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 11428 |
|
|
// disable RX, set full-duplex mode, NO receive small, NO correct IFG
|
| 11429 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 11430 |
243 |
tadejm |
wbm_write(`ETH_MODER, `ETH_MODER_FULLD | `ETH_MODER_IFG |
|
| 11431 |
|
|
`ETH_MODER_PRO | `ETH_MODER_BRO,
|
| 11432 |
|
|
4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 11433 |
|
|
// prepare two packets of MAXFL length
|
| 11434 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 11435 |
243 |
tadejm |
wbm_read(`ETH_PACKETLEN, tmp, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 11436 |
|
|
max_tmp = tmp[15:0]; // 18 bytes consists of 6B dest addr, 6B source addr, 2B type/len, 4B CRC
|
| 11437 |
|
|
min_tmp = tmp[31:16];
|
| 11438 |
|
|
st_data = 8'h0F;
|
| 11439 |
|
|
set_rx_packet(0, (min_tmp + 1), 1'b0, 48'h0102_0304_0506, 48'h0708_090A_0B0C, 16'h0D0E, st_data); // length without CRC
|
| 11440 |
|
|
append_rx_crc(0, (min_tmp + 1), 1'b0, 1'b0);
|
| 11441 |
|
|
st_data = 8'h1A;
|
| 11442 |
|
|
set_rx_packet(max_tmp, (min_tmp + 1), 1'b0, 48'h1234_5678_8765, 48'hA1B2_C3D4_E5F6, 16'hE77E, st_data);
|
| 11443 |
|
|
append_rx_crc(max_tmp, (min_tmp + 1), 1'b0, 1'b0);
|
| 11444 |
|
|
// check WB INT signal
|
| 11445 |
|
|
if (wb_int !== 1'b0)
|
| 11446 |
|
|
begin
|
| 11447 |
|
|
test_fail("WB INT signal should not be set");
|
| 11448 |
|
|
fail = fail + 1;
|
| 11449 |
|
|
end
|
| 11450 |
|
|
|
| 11451 |
|
|
// write to phy's control register for 100Mbps
|
| 11452 |
|
|
#Tp eth_phy.control_bit14_10 = 5'b01000; // bit 13 set - speed 100
|
| 11453 |
|
|
#Tp eth_phy.control_bit8_0 = 9'h1_00; // bit 6 reset - (10/100), bit 8 set - FD
|
| 11454 |
|
|
speed = 100;
|
| 11455 |
|
|
|
| 11456 |
|
|
frame_started = 0;
|
| 11457 |
|
|
frame_ended = 0;
|
| 11458 |
|
|
wait_for_frame = 0;
|
| 11459 |
|
|
check_frame = 0;
|
| 11460 |
|
|
stop_checking_frame = 0;
|
| 11461 |
|
|
first_fr_received = 1; // at the beginning the first frame of each two will be received!
|
| 11462 |
|
|
|
| 11463 |
|
|
num_of_frames = 0; //
|
| 11464 |
|
|
num_of_bd = 0;
|
| 11465 |
|
|
i_length = (min_tmp + 1); // 5 bytes longer than MINFL
|
| 11466 |
|
|
while (i_length < (max_tmp - 4))
|
| 11467 |
|
|
begin
|
| 11468 |
|
|
// choose generating carrier sense and collision
|
| 11469 |
|
|
case (num_of_frames[1:0])
|
| 11470 |
|
|
2'h0: // Interrupt is generated
|
| 11471 |
|
|
begin
|
| 11472 |
|
|
// enable interrupt generation
|
| 11473 |
|
|
set_rx_bd(118, 118, 1'b1, (`MEMORY_BASE + num_of_frames[1:0]));
|
| 11474 |
|
|
// not detect carrier sense in FD and no collision
|
| 11475 |
|
|
eth_phy.no_carrier_sense_rx_fd_detect(0);
|
| 11476 |
|
|
eth_phy.collision(0);
|
| 11477 |
|
|
end
|
| 11478 |
|
|
2'h1: // Interrupt is generated
|
| 11479 |
|
|
begin
|
| 11480 |
|
|
// enable interrupt generation
|
| 11481 |
|
|
set_rx_bd(118, 118, 1'b1, (`MEMORY_BASE + num_of_frames[1:0]));
|
| 11482 |
|
|
// detect carrier sense in FD and no collision
|
| 11483 |
|
|
eth_phy.no_carrier_sense_rx_fd_detect(1);
|
| 11484 |
|
|
eth_phy.collision(0);
|
| 11485 |
|
|
end
|
| 11486 |
|
|
2'h2: // Interrupt is generated
|
| 11487 |
|
|
begin
|
| 11488 |
|
|
// disable interrupt generation
|
| 11489 |
|
|
set_rx_bd(118, 118, 1'b1, (`MEMORY_BASE + num_of_frames[1:0]));
|
| 11490 |
|
|
// not detect carrier sense in FD and set collision
|
| 11491 |
|
|
eth_phy.no_carrier_sense_rx_fd_detect(0);
|
| 11492 |
|
|
eth_phy.collision(1);
|
| 11493 |
|
|
end
|
| 11494 |
|
|
default: // 2'h3: // Interrupt is generated
|
| 11495 |
|
|
begin
|
| 11496 |
|
|
// disable interrupt generation
|
| 11497 |
|
|
set_rx_bd(118, 118, 1'b1, (`MEMORY_BASE + num_of_frames[1:0]));
|
| 11498 |
|
|
// detect carrier sense in FD and set collision
|
| 11499 |
|
|
eth_phy.no_carrier_sense_rx_fd_detect(1);
|
| 11500 |
|
|
eth_phy.collision(1);
|
| 11501 |
|
|
end
|
| 11502 |
|
|
endcase
|
| 11503 |
|
|
//if (first_fr_received == 0)
|
| 11504 |
|
|
//begin
|
| 11505 |
|
|
// check_rx_bd(118, data);
|
| 11506 |
274 |
tadejm |
// wait (wbm_working == 0);
|
| 11507 |
243 |
tadejm |
// wbm_read((`TX_BD_BASE + (118 * 8) + 4), tmp, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 11508 |
|
|
// $display("RX BD set : %h, %h", data, tmp);
|
| 11509 |
|
|
//end
|
| 11510 |
|
|
// set wrap bit
|
| 11511 |
|
|
set_rx_bd_wrap(118);
|
| 11512 |
|
|
set_rx_bd_empty(118, 118);
|
| 11513 |
|
|
check_frame = 0;
|
| 11514 |
|
|
stop_checking_frame = 0;
|
| 11515 |
|
|
tmp_data = 0;
|
| 11516 |
|
|
fork
|
| 11517 |
|
|
begin // enable RX MAC on first of each two packets - every second should be recived normaly
|
| 11518 |
|
|
if (num_of_frames[0] == 1'b0)
|
| 11519 |
|
|
begin
|
| 11520 |
|
|
repeat(1) @(posedge wb_clk);
|
| 11521 |
|
|
if (num_of_frames[1] == 1'b0)
|
| 11522 |
|
|
begin
|
| 11523 |
|
|
repeat (num_of_frames[31:2]) @(posedge mrx_clk); // for every (second) frame enable receiver one clock later
|
| 11524 |
|
|
end
|
| 11525 |
|
|
else
|
| 11526 |
|
|
begin
|
| 11527 |
|
|
@(posedge mrx_clk);
|
| 11528 |
|
|
repeat (num_of_frames[31:2]) @(negedge mrx_clk); // for every (second) frame enable receiver one clock later
|
| 11529 |
|
|
end
|
| 11530 |
|
|
// enable RX, set full-duplex mode, NO receive small, NO correct IFG
|
| 11531 |
|
|
wbm_init_waits = 4'h0;
|
| 11532 |
|
|
wbm_subseq_waits = 4'h0;
|
| 11533 |
274 |
tadejm |
#1 wait (wbm_working == 0);
|
| 11534 |
|
|
wbm_write(`ETH_MODER, `ETH_MODER_RXEN | `ETH_MODER_FULLD | `ETH_MODER_IFG |
|
| 11535 |
243 |
tadejm |
`ETH_MODER_PRO | `ETH_MODER_BRO,
|
| 11536 |
|
|
4'hF, 1, wbm_init_waits, wbm_subseq_waits); // write ASAP
|
| 11537 |
|
|
$display("mama 2, num_of_frames=%0h", num_of_frames);
|
| 11538 |
|
|
end
|
| 11539 |
|
|
end
|
| 11540 |
|
|
begin // send a packet from PHY RX
|
| 11541 |
|
|
repeat(1) @(posedge wb_clk); // wait for WB write when it is without delays
|
| 11542 |
|
|
if (num_of_frames[1] == 1'b0)
|
| 11543 |
|
|
begin
|
| 11544 |
|
|
set_rx_addr_type(0, 48'h0102_0304_0506, 48'h0708_090A_0B0C, 16'h0D0E);
|
| 11545 |
|
|
#1 eth_phy.send_rx_packet(64'h0055_5555_5555_5555, 4'h7, 8'hD5, 0, (i_length + 4), 1'b0);
|
| 11546 |
|
|
end
|
| 11547 |
|
|
else
|
| 11548 |
|
|
begin
|
| 11549 |
|
|
set_rx_addr_type((max_tmp), 48'h1234_5678_8765, 48'hA1B2_C3D4_E5F6, 16'hE77E);
|
| 11550 |
|
|
#1 eth_phy.send_rx_packet(64'h0055_5555_5555_5555, 4'h7, 8'hD5, max_tmp, (i_length + 4), 1'b0);
|
| 11551 |
|
|
end
|
| 11552 |
|
|
end
|
| 11553 |
|
|
begin: send_packet1
|
| 11554 |
|
|
wait (MRxDV === 1'b1); // start transmit
|
| 11555 |
|
|
wait (MRxDV === 1'b0); // end transmit
|
| 11556 |
|
|
check_frame = 1;
|
| 11557 |
|
|
$display("mama 3");
|
| 11558 |
|
|
repeat(10) @(posedge mrx_clk);
|
| 11559 |
|
|
repeat(15) @(posedge wb_clk);
|
| 11560 |
|
|
stop_checking_frame = 1;
|
| 11561 |
|
|
end
|
| 11562 |
|
|
begin // count WB clocks between ACK (negedge) and RX_DV (posedge) or vice-versa
|
| 11563 |
|
|
@(posedge eth_sl_wb_ack_o or posedge MRxDV);
|
| 11564 |
|
|
$display("mama 4");
|
| 11565 |
|
|
if ((eth_sl_wb_ack_o === 1'b1) && (MRxDV === 1'b1))
|
| 11566 |
|
|
begin
|
| 11567 |
|
|
tmp_data = 32'h8000_0001; // bit[31]==1 => 'posedge MRxDV' was before 'negedge eth_sl_wb_ack_o'
|
| 11568 |
|
|
$display("mama 4_1");
|
| 11569 |
|
|
end
|
| 11570 |
|
|
else if (MRxDV === 1'b1)
|
| 11571 |
|
|
begin
|
| 11572 |
|
|
while (eth_sl_wb_ack_o === 1'b0)
|
| 11573 |
|
|
begin
|
| 11574 |
|
|
@(posedge wb_clk);
|
| 11575 |
|
|
tmp_data = tmp_data + 1;
|
| 11576 |
|
|
end
|
| 11577 |
|
|
tmp_data = tmp_data | 32'h8000_0000; // bit[31]==1 => 'posedge MRxDV' was before 'negedge eth_sl_wb_ack_o'
|
| 11578 |
|
|
$display("mama 4_2");
|
| 11579 |
|
|
end
|
| 11580 |
|
|
else if (eth_sl_wb_ack_o === 1'b1)
|
| 11581 |
|
|
begin
|
| 11582 |
|
|
@(posedge wb_clk); // wait for one clock => tmp_data 'becomes' 0
|
| 11583 |
|
|
while (MRxDV === 1'b0)
|
| 11584 |
|
|
begin
|
| 11585 |
|
|
@(posedge wb_clk);
|
| 11586 |
|
|
tmp_data = tmp_data + 1; // bit[31]==0 => 'negedge eth_sl_wb_ack_o' was equal or before 'posedge MRxDV'
|
| 11587 |
|
|
end
|
| 11588 |
|
|
$display("mama 4_3");
|
| 11589 |
|
|
end
|
| 11590 |
|
|
end
|
| 11591 |
|
|
begin // check packet
|
| 11592 |
|
|
wait (check_frame == 1);
|
| 11593 |
|
|
check_rx_bd(118, tmp_bd);
|
| 11594 |
|
|
while ((tmp_bd[15] === 1) && (stop_checking_frame == 0))
|
| 11595 |
|
|
begin
|
| 11596 |
|
|
#1 check_rx_bd(118, tmp_bd);
|
| 11597 |
|
|
@(posedge wb_clk);
|
| 11598 |
|
|
end
|
| 11599 |
|
|
$display("mama 5, tmp_bd=%0h", tmp_bd);
|
| 11600 |
|
|
if (num_of_frames[0] == 1'b0)
|
| 11601 |
|
|
begin
|
| 11602 |
|
|
if (tmp_bd[15] === 1)
|
| 11603 |
|
|
begin
|
| 11604 |
|
|
if (first_fr_received == 1)
|
| 11605 |
|
|
begin
|
| 11606 |
|
|
first_fr_received = 0;
|
| 11607 |
|
|
$display(" %0d packets (without this one) are checked - packets are received by two in a set",
|
| 11608 |
|
|
num_of_frames); // +1 due to start with 0 AND -1 because this packet is excluded
|
| 11609 |
|
|
$display(" From this moment:");
|
| 11610 |
|
|
$display(" first one of two packets (including this one) is not accepted due to late RX enable");
|
| 11611 |
|
|
if (tmp_data[31])
|
| 11612 |
|
|
$display(" ->RX enable set %0d WB clks after RX_DV", tmp_data[30:0]);
|
| 11613 |
|
|
else
|
| 11614 |
|
|
$display(" ->RX enable set %0d WB clks before RX_DV", tmp_data[30:0]);
|
| 11615 |
|
|
end
|
| 11616 |
|
|
// check FB, etc.
|
| 11617 |
|
|
|
| 11618 |
|
|
end
|
| 11619 |
|
|
else // (tmp_bd[15] === 0)
|
| 11620 |
|
|
begin // check FB, packet, etc.
|
| 11621 |
|
|
|
| 11622 |
|
|
end
|
| 11623 |
|
|
$display("mama 5_1");
|
| 11624 |
|
|
end
|
| 11625 |
|
|
else // (num_of_frames[0] == 1'b1)
|
| 11626 |
|
|
begin
|
| 11627 |
|
|
if (tmp_bd[15] === 1) // ERROR, because second packet of each two frames should be received
|
| 11628 |
|
|
begin // check NOTHING
|
| 11629 |
|
|
|
| 11630 |
|
|
end
|
| 11631 |
|
|
else // (tmp_bd[15] === 0)
|
| 11632 |
|
|
begin // check FB, packet, etc.
|
| 11633 |
|
|
|
| 11634 |
|
|
end
|
| 11635 |
|
|
$display("mama 5_2");
|
| 11636 |
|
|
end
|
| 11637 |
|
|
if (stop_checking_frame == 0)
|
| 11638 |
|
|
disable send_packet1;
|
| 11639 |
|
|
end
|
| 11640 |
|
|
join
|
| 11641 |
|
|
// ONLY IF packet was received!
|
| 11642 |
|
|
$display("mama 6");
|
| 11643 |
|
|
if (tmp_bd[15] === 0)
|
| 11644 |
|
|
begin
|
| 11645 |
|
|
// check length of a PACKET
|
| 11646 |
|
|
if (tmp_bd[31:16] != (i_length + 4))
|
| 11647 |
|
|
begin
|
| 11648 |
|
|
`TIME; $display("*E Wrong length of the packet out from PHY (%0d instead of %0d)",
|
| 11649 |
|
|
tmp_bd[31:16], (i_length + 4));
|
| 11650 |
|
|
test_fail("Wrong length of the packet out from PHY");
|
| 11651 |
|
|
fail = fail + 1;
|
| 11652 |
|
|
end
|
| 11653 |
|
|
// check received RX packet data and CRC
|
| 11654 |
|
|
if (first_fr_received == 0) // if PREVIOUS RX buffer descriptor was not ready, pointer address is -1
|
| 11655 |
|
|
begin
|
| 11656 |
|
|
if (num_of_frames[1] == 1'b0)
|
| 11657 |
|
|
begin
|
| 11658 |
|
|
check_rx_packet(0, (`MEMORY_BASE + num_of_frames[1:0] - 1'b1), (i_length + 4), 1'b0, 1'b0, tmp);
|
| 11659 |
|
|
end
|
| 11660 |
|
|
else
|
| 11661 |
|
|
begin
|
| 11662 |
|
|
check_rx_packet(max_tmp, (`MEMORY_BASE + num_of_frames[1:0] - 1'b1), (i_length + 4), 1'b0, 1'b0, tmp);
|
| 11663 |
|
|
end
|
| 11664 |
|
|
if (tmp > 0)
|
| 11665 |
|
|
begin
|
| 11666 |
|
|
`TIME; $display("*E Wrong data of the received packet");
|
| 11667 |
|
|
test_fail("Wrong data of the received packet");
|
| 11668 |
|
|
fail = fail + 1;
|
| 11669 |
|
|
end
|
| 11670 |
|
|
end
|
| 11671 |
|
|
else // if PREVIOUS RX buffer descriptor was ready
|
| 11672 |
|
|
begin
|
| 11673 |
|
|
if (num_of_frames[1] == 1'b0)
|
| 11674 |
|
|
begin
|
| 11675 |
|
|
check_rx_packet(0, (`MEMORY_BASE + num_of_frames[1:0]), (i_length + 4), 1'b0, 1'b0, tmp);
|
| 11676 |
|
|
end
|
| 11677 |
|
|
else
|
| 11678 |
|
|
begin
|
| 11679 |
|
|
check_rx_packet(max_tmp, (`MEMORY_BASE + num_of_frames[1:0]), (i_length + 4), 1'b0, 1'b0, tmp);
|
| 11680 |
|
|
end
|
| 11681 |
|
|
if (tmp > 0)
|
| 11682 |
|
|
begin
|
| 11683 |
|
|
`TIME; $display("*E Wrong data of the received packet");
|
| 11684 |
|
|
test_fail("Wrong data of the received packet");
|
| 11685 |
|
|
fail = fail + 1;
|
| 11686 |
|
|
end
|
| 11687 |
|
|
end
|
| 11688 |
|
|
end
|
| 11689 |
|
|
// check WB INT signal
|
| 11690 |
|
|
if ((num_of_frames[0] == 1'b0) && (first_fr_received == 0)) // interrupt enabled but no receive
|
| 11691 |
|
|
begin
|
| 11692 |
|
|
if (wb_int !== 1'b0)
|
| 11693 |
|
|
begin
|
| 11694 |
|
|
`TIME; $display("*E WB INT signal should not be set");
|
| 11695 |
|
|
test_fail("WB INT signal should not be set");
|
| 11696 |
|
|
fail = fail + 1;
|
| 11697 |
|
|
end
|
| 11698 |
|
|
end
|
| 11699 |
|
|
else
|
| 11700 |
|
|
begin
|
| 11701 |
|
|
if (wb_int !== 1'b1)
|
| 11702 |
|
|
begin
|
| 11703 |
|
|
`TIME; $display("*E WB INT signal should be set");
|
| 11704 |
|
|
test_fail("WB INT signal should be set");
|
| 11705 |
|
|
fail = fail + 1;
|
| 11706 |
|
|
end
|
| 11707 |
|
|
end
|
| 11708 |
|
|
// check RX buffer descriptor of a packet - only 15 LSBits
|
| 11709 |
|
|
check_rx_bd(118, data);
|
| 11710 |
|
|
if ((num_of_frames[0] == 1'b0) && (first_fr_received == 0)) // interrupt enabled but no receive
|
| 11711 |
|
|
begin
|
| 11712 |
|
|
if (data[15:0] !== 16'hE000)
|
| 11713 |
|
|
begin
|
| 11714 |
|
|
`TIME; $display("*E RX buffer descriptor status is not correct: %0h", data[15:0]);
|
| 11715 |
|
|
test_fail("RX buffer descriptor status is not correct");
|
| 11716 |
|
|
fail = fail + 1;
|
| 11717 |
|
|
end
|
| 11718 |
|
|
end
|
| 11719 |
|
|
else // interrupt enabled
|
| 11720 |
|
|
begin
|
| 11721 |
|
|
if (data[15:0] !== 16'h6000)
|
| 11722 |
|
|
begin
|
| 11723 |
|
|
`TIME; $display("*E RX buffer descriptor status is not correct: %0h", data[15:0]);
|
| 11724 |
|
|
test_fail("RX buffer descriptor status is not correct");
|
| 11725 |
|
|
fail = fail + 1;
|
| 11726 |
|
|
end
|
| 11727 |
|
|
end
|
| 11728 |
|
|
// check interrupts
|
| 11729 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 11730 |
243 |
tadejm |
wbm_read(`ETH_INT, data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 11731 |
|
|
if ((num_of_frames[0] == 1'b0) && (first_fr_received == 0)) // interrupt enabled but no receive
|
| 11732 |
|
|
begin
|
| 11733 |
|
|
if (data !== 0)
|
| 11734 |
|
|
begin
|
| 11735 |
|
|
`TIME; $display("*E Any of interrupts was set, interrupt reg: %0h, len: %0h", data, num_of_frames[1:0]);
|
| 11736 |
|
|
test_fail("Any of interrupts was set");
|
| 11737 |
|
|
fail = fail + 1;
|
| 11738 |
|
|
end
|
| 11739 |
|
|
end
|
| 11740 |
|
|
else
|
| 11741 |
|
|
begin
|
| 11742 |
|
|
if ((data & `ETH_INT_RXB) !== `ETH_INT_RXB)
|
| 11743 |
|
|
begin
|
| 11744 |
|
|
`TIME; $display("*E Interrupt Receive Buffer was not set, interrupt reg: %0h", data);
|
| 11745 |
|
|
test_fail("Interrupt Receive Buffer was not set");
|
| 11746 |
|
|
fail = fail + 1;
|
| 11747 |
|
|
end
|
| 11748 |
|
|
if ((data & (~`ETH_INT_RXB)) !== 0)
|
| 11749 |
|
|
begin
|
| 11750 |
|
|
`TIME; $display("*E Other interrupts (except Receive Buffer) were set, interrupt reg: %0h", data);
|
| 11751 |
|
|
test_fail("Other interrupts (except Receive Buffer) were set");
|
| 11752 |
|
|
fail = fail + 1;
|
| 11753 |
|
|
end
|
| 11754 |
|
|
end
|
| 11755 |
|
|
// clear interrupts
|
| 11756 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 11757 |
243 |
tadejm |
wbm_write(`ETH_INT, data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 11758 |
|
|
// check WB INT signal
|
| 11759 |
|
|
if (wb_int !== 1'b0)
|
| 11760 |
|
|
begin
|
| 11761 |
|
|
test_fail("WB INT signal should not be set");
|
| 11762 |
|
|
fail = fail + 1;
|
| 11763 |
|
|
end
|
| 11764 |
|
|
// disable RX after two packets
|
| 11765 |
|
|
if (num_of_frames[0] == 1'b1)
|
| 11766 |
|
|
begin
|
| 11767 |
|
|
// disable RX, set full-duplex mode, NO receive small, NO correct IFG
|
| 11768 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 11769 |
243 |
tadejm |
wbm_write(`ETH_MODER, `ETH_MODER_FULLD | `ETH_MODER_IFG |
|
| 11770 |
|
|
`ETH_MODER_PRO | `ETH_MODER_BRO,
|
| 11771 |
|
|
4'hF, 1, 4'h0, 4'h0); // write ASAP
|
| 11772 |
|
|
end
|
| 11773 |
|
|
// the number of frame transmitted
|
| 11774 |
|
|
num_of_frames = num_of_frames + 1;
|
| 11775 |
|
|
num_of_bd = 0;
|
| 11776 |
|
|
// set length (LOOP variable)
|
| 11777 |
|
|
if (num_of_frames[31:2] == (i_length * 2 + 16)) // 64 => this vas last Byte (1st .. 64th) when i_length = min_tmp - 4
|
| 11778 |
|
|
i_length = (max_tmp - 4);
|
| 11779 |
|
|
@(posedge wb_clk);
|
| 11780 |
|
|
end
|
| 11781 |
|
|
// disable RX
|
| 11782 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 11783 |
243 |
tadejm |
wbm_write(`ETH_MODER, `ETH_MODER_FULLD | `ETH_MODER_RECSMALL | `ETH_MODER_IFG |
|
| 11784 |
|
|
`ETH_MODER_PRO | `ETH_MODER_BRO,
|
| 11785 |
|
|
4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 11786 |
|
|
if(fail == 0)
|
| 11787 |
|
|
test_ok;
|
| 11788 |
|
|
else
|
| 11789 |
|
|
fail = 0;
|
| 11790 |
|
|
end
|
| 11791 |
|
|
|
| 11792 |
|
|
|
| 11793 |
|
|
////////////////////////////////////////////////////////////////////
|
| 11794 |
|
|
//// ////
|
| 11795 |
209 |
tadejm |
//// Test receive packets form MINFL to MAXFL sizes at ////
|
| 11796 |
|
|
//// one RX buffer decriptor ( 10Mbps ). ////
|
| 11797 |
|
|
//// ////
|
| 11798 |
|
|
////////////////////////////////////////////////////////////////////
|
| 11799 |
243 |
tadejm |
if (test_num == 4) //
|
| 11800 |
209 |
tadejm |
begin
|
| 11801 |
243 |
tadejm |
// TEST 4: RECEIVE PACKETS FROM MINFL TO MAXFL SIZES AT ONE RX BD ( 10Mbps )
|
| 11802 |
|
|
test_name = "TEST 4: RECEIVE PACKETS FROM MINFL TO MAXFL SIZES AT ONE RX BD ( 10Mbps )";
|
| 11803 |
|
|
`TIME; $display(" TEST 4: RECEIVE PACKETS FROM MINFL TO MAXFL SIZES AT ONE RX BD ( 10Mbps )");
|
| 11804 |
209 |
tadejm |
|
| 11805 |
|
|
// unmask interrupts
|
| 11806 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 11807 |
209 |
tadejm |
wbm_write(`ETH_INT_MASK, `ETH_INT_TXB | `ETH_INT_TXE | `ETH_INT_RXB | `ETH_INT_RXE | `ETH_INT_BUSY |
|
| 11808 |
|
|
`ETH_INT_TXC | `ETH_INT_RXC, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 11809 |
|
|
// set 1 RX buffer descriptor (8'h80 - 1) - must be set before RX enable
|
| 11810 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 11811 |
209 |
tadejm |
wbm_write(`ETH_TX_BD_NUM, 32'h7F, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 11812 |
|
|
// enable RX, set full-duplex mode, NO receive small, NO correct IFG
|
| 11813 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 11814 |
209 |
tadejm |
wbm_write(`ETH_MODER, `ETH_MODER_RXEN | `ETH_MODER_FULLD | `ETH_MODER_IFG |
|
| 11815 |
|
|
`ETH_MODER_PRO | `ETH_MODER_BRO,
|
| 11816 |
|
|
4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 11817 |
|
|
// prepare two packets of MAXFL length
|
| 11818 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 11819 |
209 |
tadejm |
wbm_read(`ETH_PACKETLEN, tmp, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 11820 |
|
|
max_tmp = tmp[15:0]; // 18 bytes consists of 6B dest addr, 6B source addr, 2B type/len, 4B CRC
|
| 11821 |
|
|
min_tmp = tmp[31:16];
|
| 11822 |
|
|
st_data = 8'h0F;
|
| 11823 |
|
|
set_rx_packet(0, (max_tmp - 4), 1'b0, 48'h0102_0304_0506, 48'h0708_090A_0B0C, 16'h0D0E, st_data); // length without CRC
|
| 11824 |
|
|
st_data = 8'h1A;
|
| 11825 |
|
|
set_rx_packet((max_tmp), (max_tmp - 4), 1'b0, 48'h1234_5678_8765, 48'hA1B2_C3D4_E5F6, 16'hE77E, st_data);
|
| 11826 |
|
|
// check WB INT signal
|
| 11827 |
|
|
if (wb_int !== 1'b0)
|
| 11828 |
|
|
begin
|
| 11829 |
|
|
test_fail("WB INT signal should not be set");
|
| 11830 |
|
|
fail = fail + 1;
|
| 11831 |
|
|
end
|
| 11832 |
|
|
|
| 11833 |
|
|
// write to phy's control register for 10Mbps
|
| 11834 |
|
|
#Tp eth_phy.control_bit14_10 = 5'b00000; // bit 13 reset - speed 10
|
| 11835 |
|
|
#Tp eth_phy.control_bit8_0 = 9'h1_00; // bit 6 reset - (10/100), bit 8 set - FD
|
| 11836 |
|
|
speed = 10;
|
| 11837 |
|
|
|
| 11838 |
|
|
i_length = (min_tmp - 4);
|
| 11839 |
|
|
while (i_length <= (max_tmp - 4))
|
| 11840 |
|
|
begin
|
| 11841 |
|
|
// choose generating carrier sense and collision for first and last 64 lengths of frames
|
| 11842 |
|
|
case (i_length[1:0])
|
| 11843 |
|
|
2'h0: // Interrupt is generated
|
| 11844 |
|
|
begin
|
| 11845 |
|
|
// enable interrupt generation
|
| 11846 |
|
|
set_rx_bd(127, 127, 1'b1, (`MEMORY_BASE + i_length[1:0]));
|
| 11847 |
|
|
// unmask interrupts
|
| 11848 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 11849 |
209 |
tadejm |
wbm_write(`ETH_INT_MASK, `ETH_INT_TXB | `ETH_INT_TXE | `ETH_INT_RXB | `ETH_INT_RXE | `ETH_INT_BUSY |
|
| 11850 |
|
|
`ETH_INT_TXC | `ETH_INT_RXC, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 11851 |
|
|
// not detect carrier sense in FD and no collision
|
| 11852 |
|
|
eth_phy.no_carrier_sense_rx_fd_detect(0);
|
| 11853 |
|
|
eth_phy.collision(0);
|
| 11854 |
|
|
end
|
| 11855 |
|
|
2'h1: // Interrupt is not generated
|
| 11856 |
|
|
begin
|
| 11857 |
|
|
// enable interrupt generation
|
| 11858 |
|
|
set_rx_bd(127, 127, 1'b1, ((`MEMORY_BASE + i_length[1:0]) + max_tmp));
|
| 11859 |
|
|
// mask interrupts
|
| 11860 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 11861 |
209 |
tadejm |
wbm_write(`ETH_INT_MASK, 32'h0, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 11862 |
|
|
// detect carrier sense in FD and no collision
|
| 11863 |
|
|
eth_phy.no_carrier_sense_rx_fd_detect(1);
|
| 11864 |
|
|
eth_phy.collision(0);
|
| 11865 |
|
|
end
|
| 11866 |
|
|
2'h2: // Interrupt is not generated
|
| 11867 |
|
|
begin
|
| 11868 |
|
|
// disable interrupt generation
|
| 11869 |
|
|
set_rx_bd(127, 127, 1'b0, (`MEMORY_BASE + i_length[1:0]));
|
| 11870 |
|
|
// unmask interrupts
|
| 11871 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 11872 |
209 |
tadejm |
wbm_write(`ETH_INT_MASK, `ETH_INT_TXB | `ETH_INT_TXE | `ETH_INT_RXB | `ETH_INT_RXE | `ETH_INT_BUSY |
|
| 11873 |
|
|
`ETH_INT_TXC | `ETH_INT_RXC, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 11874 |
|
|
// not detect carrier sense in FD and set collision
|
| 11875 |
|
|
eth_phy.no_carrier_sense_rx_fd_detect(0);
|
| 11876 |
|
|
eth_phy.collision(1);
|
| 11877 |
|
|
end
|
| 11878 |
|
|
default: // 2'h3: // Interrupt is not generated
|
| 11879 |
|
|
begin
|
| 11880 |
|
|
// disable interrupt generation
|
| 11881 |
|
|
set_rx_bd(127, 127, 1'b0, ((`MEMORY_BASE + i_length[1:0]) + max_tmp));
|
| 11882 |
|
|
// mask interrupts
|
| 11883 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 11884 |
209 |
tadejm |
wbm_write(`ETH_INT_MASK, 32'h0, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 11885 |
|
|
// detect carrier sense in FD and set collision
|
| 11886 |
|
|
eth_phy.no_carrier_sense_rx_fd_detect(1);
|
| 11887 |
|
|
eth_phy.collision(1);
|
| 11888 |
|
|
end
|
| 11889 |
|
|
endcase
|
| 11890 |
|
|
if (i_length[0] == 1'b0)
|
| 11891 |
|
|
append_rx_crc (0, i_length, 1'b0, 1'b0);
|
| 11892 |
|
|
else
|
| 11893 |
|
|
append_rx_crc (max_tmp, i_length, 1'b0, 1'b0);
|
| 11894 |
|
|
// set wrap bit
|
| 11895 |
|
|
set_rx_bd_wrap(127);
|
| 11896 |
|
|
set_rx_bd_empty(127, 127);
|
| 11897 |
|
|
fork
|
| 11898 |
|
|
begin
|
| 11899 |
|
|
if (i_length[0] == 1'b0)
|
| 11900 |
|
|
#1 eth_phy.send_rx_packet(64'h0055_5555_5555_5555, 4'h7, 8'hD5, 0, (i_length + 4), 1'b0);
|
| 11901 |
|
|
else
|
| 11902 |
|
|
#1 eth_phy.send_rx_packet(64'h0055_5555_5555_5555, 4'h7, 8'hD5, max_tmp, (i_length + 4), 1'b0);
|
| 11903 |
|
|
repeat(10) @(posedge mrx_clk);
|
| 11904 |
|
|
end
|
| 11905 |
|
|
begin
|
| 11906 |
|
|
#1 check_rx_bd(127, data);
|
| 11907 |
|
|
if (i_length < min_tmp) // just first four
|
| 11908 |
|
|
begin
|
| 11909 |
|
|
while (data[15] === 1)
|
| 11910 |
|
|
begin
|
| 11911 |
|
|
#1 check_rx_bd(127, data);
|
| 11912 |
|
|
@(posedge wb_clk);
|
| 11913 |
|
|
end
|
| 11914 |
|
|
repeat (1) @(posedge wb_clk);
|
| 11915 |
|
|
end
|
| 11916 |
|
|
else
|
| 11917 |
|
|
begin
|
| 11918 |
|
|
wait (MRxDV === 1'b1); // start transmit
|
| 11919 |
|
|
#1 check_rx_bd(127, data);
|
| 11920 |
|
|
if (data[15] !== 1)
|
| 11921 |
|
|
begin
|
| 11922 |
|
|
test_fail("Wrong buffer descriptor's ready bit read out from MAC");
|
| 11923 |
|
|
fail = fail + 1;
|
| 11924 |
|
|
end
|
| 11925 |
|
|
wait (MRxDV === 1'b0); // end transmit
|
| 11926 |
|
|
while (data[15] === 1)
|
| 11927 |
|
|
begin
|
| 11928 |
|
|
#1 check_rx_bd(127, data);
|
| 11929 |
|
|
@(posedge wb_clk);
|
| 11930 |
|
|
end
|
| 11931 |
|
|
repeat (1) @(posedge wb_clk);
|
| 11932 |
|
|
end
|
| 11933 |
|
|
end
|
| 11934 |
|
|
join
|
| 11935 |
|
|
// check length of a PACKET
|
| 11936 |
|
|
if (data[31:16] != (i_length + 4))
|
| 11937 |
|
|
begin
|
| 11938 |
|
|
`TIME; $display("*E Wrong length of the packet out from PHY (%0d instead of %0d)",
|
| 11939 |
|
|
data[31:16], (i_length + 4));
|
| 11940 |
|
|
test_fail("Wrong length of the packet out from PHY");
|
| 11941 |
|
|
fail = fail + 1;
|
| 11942 |
|
|
end
|
| 11943 |
|
|
// checking in the following if statement is performed only for first and last 64 lengths
|
| 11944 |
|
|
// check received RX packet data and CRC
|
| 11945 |
|
|
if (i_length[0] == 1'b0)
|
| 11946 |
|
|
begin
|
| 11947 |
|
|
check_rx_packet(0, (`MEMORY_BASE + i_length[1:0]), (i_length + 4), 1'b0, 1'b0, tmp);
|
| 11948 |
|
|
end
|
| 11949 |
|
|
else
|
| 11950 |
|
|
begin
|
| 11951 |
|
|
check_rx_packet(max_tmp, ((`MEMORY_BASE + i_length[1:0]) + max_tmp), (i_length + 4), 1'b0, 1'b0, tmp);
|
| 11952 |
|
|
end
|
| 11953 |
|
|
if (tmp > 0)
|
| 11954 |
|
|
begin
|
| 11955 |
|
|
`TIME; $display("*E Wrong data of the received packet");
|
| 11956 |
|
|
test_fail("Wrong data of the received packet");
|
| 11957 |
|
|
fail = fail + 1;
|
| 11958 |
|
|
end
|
| 11959 |
|
|
// check WB INT signal
|
| 11960 |
|
|
if (i_length[1:0] == 2'h0)
|
| 11961 |
|
|
begin
|
| 11962 |
|
|
if (wb_int !== 1'b1)
|
| 11963 |
|
|
begin
|
| 11964 |
|
|
`TIME; $display("*E WB INT signal should be set");
|
| 11965 |
|
|
test_fail("WB INT signal should be set");
|
| 11966 |
|
|
fail = fail + 1;
|
| 11967 |
|
|
end
|
| 11968 |
|
|
end
|
| 11969 |
|
|
else
|
| 11970 |
|
|
begin
|
| 11971 |
|
|
if (wb_int !== 1'b0)
|
| 11972 |
|
|
begin
|
| 11973 |
|
|
`TIME; $display("*E WB INT signal should not be set");
|
| 11974 |
|
|
test_fail("WB INT signal should not be set");
|
| 11975 |
|
|
fail = fail + 1;
|
| 11976 |
|
|
end
|
| 11977 |
|
|
end
|
| 11978 |
|
|
// check RX buffer descriptor of a packet
|
| 11979 |
|
|
check_rx_bd(127, data);
|
| 11980 |
|
|
if (i_length[1] == 1'b0) // interrupt enabled no_carrier_sense_rx_fd_detect
|
| 11981 |
|
|
begin
|
| 11982 |
|
|
if ( ((data[15:0] !== 16'h6000) && (i_length[0] == 1'b0)) ||
|
| 11983 |
|
|
((data[15:0] !== 16'h6000) && (i_length[0] == 1'b1)) )
|
| 11984 |
|
|
begin
|
| 11985 |
|
|
`TIME; $display("*E RX buffer descriptor status is not correct: %0h", data[15:0]);
|
| 11986 |
|
|
test_fail("RX buffer descriptor status is not correct");
|
| 11987 |
|
|
fail = fail + 1;
|
| 11988 |
|
|
end
|
| 11989 |
|
|
end
|
| 11990 |
|
|
else // interrupt not enabled
|
| 11991 |
|
|
begin
|
| 11992 |
|
|
if ( ((data[15:0] !== 16'h2000) && (i_length[0] == 1'b0)) ||
|
| 11993 |
|
|
((data[15:0] !== 16'h2000) && (i_length[0] == 1'b1)) )
|
| 11994 |
|
|
begin
|
| 11995 |
|
|
`TIME; $display("*E RX buffer descriptor status is not correct: %0h", data[15:0]);
|
| 11996 |
|
|
test_fail("RX buffer descriptor status is not correct");
|
| 11997 |
|
|
fail = fail + 1;
|
| 11998 |
|
|
end
|
| 11999 |
|
|
end
|
| 12000 |
|
|
// clear RX buffer descriptor for first 4 frames
|
| 12001 |
|
|
if (i_length < min_tmp)
|
| 12002 |
|
|
clear_rx_bd(127, 127);
|
| 12003 |
|
|
// check interrupts
|
| 12004 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 12005 |
209 |
tadejm |
wbm_read(`ETH_INT, data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 12006 |
|
|
if ((i_length[1:0] == 2'h0) || (i_length[1:0] == 2'h1))
|
| 12007 |
|
|
begin
|
| 12008 |
|
|
if ((data & `ETH_INT_RXB) !== `ETH_INT_RXB)
|
| 12009 |
|
|
begin
|
| 12010 |
|
|
`TIME; $display("*E Interrupt Receive Buffer was not set, interrupt reg: %0h", data);
|
| 12011 |
|
|
test_fail("Interrupt Receive Buffer was not set");
|
| 12012 |
|
|
fail = fail + 1;
|
| 12013 |
|
|
end
|
| 12014 |
|
|
if ((data & (~`ETH_INT_RXB)) !== 0)
|
| 12015 |
|
|
begin
|
| 12016 |
|
|
`TIME; $display("*E Other interrupts (except Receive Buffer) were set, interrupt reg: %0h", data);
|
| 12017 |
|
|
test_fail("Other interrupts (except Receive Buffer) were set");
|
| 12018 |
|
|
fail = fail + 1;
|
| 12019 |
|
|
end
|
| 12020 |
|
|
end
|
| 12021 |
|
|
else
|
| 12022 |
|
|
begin
|
| 12023 |
|
|
if (data !== 0)
|
| 12024 |
|
|
begin
|
| 12025 |
|
|
`TIME; $display("*E Any of interrupts (except Receive Buffer) was set, interrupt reg: %0h, len: %0h", data, i_length[1:0]);
|
| 12026 |
|
|
test_fail("Any of interrupts (except Receive Buffer) was set");
|
| 12027 |
|
|
fail = fail + 1;
|
| 12028 |
|
|
end
|
| 12029 |
|
|
end
|
| 12030 |
|
|
// clear interrupts
|
| 12031 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 12032 |
209 |
tadejm |
wbm_write(`ETH_INT, data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 12033 |
|
|
// check WB INT signal
|
| 12034 |
|
|
if (wb_int !== 1'b0)
|
| 12035 |
|
|
begin
|
| 12036 |
|
|
test_fail("WB INT signal should not be set");
|
| 12037 |
|
|
fail = fail + 1;
|
| 12038 |
|
|
end
|
| 12039 |
|
|
// INTERMEDIATE DISPLAYS
|
| 12040 |
|
|
if ((i_length + 4) == (min_tmp + 64))
|
| 12041 |
|
|
begin
|
| 12042 |
|
|
// starting length is min_tmp, ending length is (min_tmp + 64)
|
| 12043 |
|
|
$display(" receive small packets is NOT selected");
|
| 12044 |
|
|
$display(" ->packets with lengths from %0d (MINFL) to %0d are checked (length increasing by 1 byte)",
|
| 12045 |
|
|
min_tmp, (min_tmp + 64));
|
| 12046 |
|
|
// set receive small, remain the rest
|
| 12047 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 12048 |
209 |
tadejm |
wbm_write(`ETH_MODER, `ETH_MODER_RXEN | `ETH_MODER_FULLD | `ETH_MODER_RECSMALL | `ETH_MODER_IFG |
|
| 12049 |
|
|
`ETH_MODER_PRO | `ETH_MODER_BRO,
|
| 12050 |
|
|
4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 12051 |
|
|
end
|
| 12052 |
|
|
else if ((i_length + 4) == (max_tmp - 16))
|
| 12053 |
|
|
begin
|
| 12054 |
|
|
// starting length is for +128 longer than previous ending length, while ending length is tmp_data
|
| 12055 |
|
|
$display(" receive small packets is selected");
|
| 12056 |
|
|
$display(" ->packets with lengths from %0d to %0d are checked (length increasing by 128 bytes)",
|
| 12057 |
|
|
(min_tmp + 64 + 128), tmp_data);
|
| 12058 |
|
|
// reset receive small, remain the rest
|
| 12059 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 12060 |
209 |
tadejm |
wbm_write(`ETH_MODER, `ETH_MODER_RXEN | `ETH_MODER_FULLD | `ETH_MODER_IFG |
|
| 12061 |
|
|
`ETH_MODER_PRO | `ETH_MODER_BRO,
|
| 12062 |
|
|
4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 12063 |
|
|
end
|
| 12064 |
|
|
else if ((i_length + 4) == max_tmp)
|
| 12065 |
|
|
begin
|
| 12066 |
|
|
$display(" receive small packets is NOT selected");
|
| 12067 |
|
|
$display(" ->packets with lengths from %0d to %0d (MAXFL) are checked (length increasing by 1 byte)",
|
| 12068 |
|
|
(max_tmp - (4 + 16)), max_tmp);
|
| 12069 |
|
|
end
|
| 12070 |
|
|
// set length (loop variable)
|
| 12071 |
|
|
if ((i_length + 4) < (min_tmp + 64))
|
| 12072 |
|
|
i_length = i_length + 1;
|
| 12073 |
|
|
else if ( ((i_length + 4) >= (min_tmp + 64)) && ((i_length + 4) <= (max_tmp - 256)) )
|
| 12074 |
|
|
begin
|
| 12075 |
|
|
i_length = i_length + 128;
|
| 12076 |
|
|
tmp_data = i_length + 4; // last tmp_data is ending length
|
| 12077 |
|
|
end
|
| 12078 |
|
|
else if ( ((i_length + 4) > (max_tmp - 256)) && ((i_length + 4) < (max_tmp - 16)) )
|
| 12079 |
|
|
i_length = max_tmp - (4 + 16);
|
| 12080 |
|
|
else if ((i_length + 4) >= (max_tmp - 16))
|
| 12081 |
|
|
i_length = i_length + 1;
|
| 12082 |
|
|
else
|
| 12083 |
|
|
begin
|
| 12084 |
|
|
$display("*E TESTBENCH ERROR - WRONG PARAMETERS IN TESTBENCH");
|
| 12085 |
|
|
#10 $stop;
|
| 12086 |
|
|
end
|
| 12087 |
|
|
end
|
| 12088 |
|
|
// disable RX
|
| 12089 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 12090 |
209 |
tadejm |
wbm_write(`ETH_MODER, `ETH_MODER_FULLD | `ETH_MODER_RECSMALL | `ETH_MODER_IFG |
|
| 12091 |
|
|
`ETH_MODER_PRO | `ETH_MODER_BRO,
|
| 12092 |
|
|
4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 12093 |
|
|
if(fail == 0)
|
| 12094 |
|
|
test_ok;
|
| 12095 |
|
|
else
|
| 12096 |
|
|
fail = 0;
|
| 12097 |
|
|
end
|
| 12098 |
|
|
|
| 12099 |
|
|
|
| 12100 |
|
|
////////////////////////////////////////////////////////////////////
|
| 12101 |
|
|
//// ////
|
| 12102 |
|
|
//// Test receive packets form MINFL to MAXFL sizes at ////
|
| 12103 |
|
|
//// one RX buffer decriptor ( 100Mbps ). ////
|
| 12104 |
|
|
//// ////
|
| 12105 |
|
|
////////////////////////////////////////////////////////////////////
|
| 12106 |
243 |
tadejm |
if (test_num == 5) // Test no receive when all buffers are TX ( 100Mbps ).
|
| 12107 |
209 |
tadejm |
begin
|
| 12108 |
243 |
tadejm |
// TEST 5: RECEIVE PACKETS FROM MINFL TO MAXFL SIZES AT ONE RX BD ( 100Mbps )
|
| 12109 |
|
|
test_name = "TEST 5: RECEIVE PACKETS FROM MINFL TO MAXFL SIZES AT ONE RX BD ( 100Mbps )";
|
| 12110 |
|
|
`TIME; $display(" TEST 5: RECEIVE PACKETS FROM MINFL TO MAXFL SIZES AT ONE RX BD ( 100Mbps )");
|
| 12111 |
209 |
tadejm |
|
| 12112 |
|
|
// unmask interrupts
|
| 12113 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 12114 |
209 |
tadejm |
wbm_write(`ETH_INT_MASK, `ETH_INT_TXB | `ETH_INT_TXE | `ETH_INT_RXB | `ETH_INT_RXE | `ETH_INT_BUSY |
|
| 12115 |
|
|
`ETH_INT_TXC | `ETH_INT_RXC, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 12116 |
|
|
// set 1 RX buffer descriptor (8'h80 - 1) - must be set before RX enable
|
| 12117 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 12118 |
209 |
tadejm |
wbm_write(`ETH_TX_BD_NUM, 32'h7F, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 12119 |
|
|
// enable RX, set full-duplex mode, NO receive small, NO correct IFG
|
| 12120 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 12121 |
209 |
tadejm |
wbm_write(`ETH_MODER, `ETH_MODER_RXEN | `ETH_MODER_FULLD | `ETH_MODER_IFG |
|
| 12122 |
|
|
`ETH_MODER_PRO | `ETH_MODER_BRO,
|
| 12123 |
|
|
4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 12124 |
|
|
// prepare two packets of MAXFL length
|
| 12125 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 12126 |
209 |
tadejm |
wbm_read(`ETH_PACKETLEN, tmp, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 12127 |
|
|
max_tmp = tmp[15:0]; // 18 bytes consists of 6B dest addr, 6B source addr, 2B type/len, 4B CRC
|
| 12128 |
|
|
min_tmp = tmp[31:16];
|
| 12129 |
|
|
st_data = 8'h0F;
|
| 12130 |
|
|
set_rx_packet(0, (max_tmp - 4), 1'b0, 48'h0102_0304_0506, 48'h0708_090A_0B0C, 16'h0D0E, st_data); // length without CRC
|
| 12131 |
|
|
st_data = 8'h1A;
|
| 12132 |
|
|
set_rx_packet((max_tmp), (max_tmp - 4), 1'b0, 48'h1234_5678_8765, 48'hA1B2_C3D4_E5F6, 16'hE77E, st_data);
|
| 12133 |
|
|
// check WB INT signal
|
| 12134 |
|
|
if (wb_int !== 1'b0)
|
| 12135 |
|
|
begin
|
| 12136 |
|
|
test_fail("WB INT signal should not be set");
|
| 12137 |
|
|
fail = fail + 1;
|
| 12138 |
|
|
end
|
| 12139 |
|
|
|
| 12140 |
|
|
// write to phy's control register for 100Mbps
|
| 12141 |
|
|
#Tp eth_phy.control_bit14_10 = 5'b01000; // bit 13 set - speed 100
|
| 12142 |
|
|
#Tp eth_phy.control_bit8_0 = 9'h1_00; // bit 6 reset - (10/100), bit 8 set - FD
|
| 12143 |
|
|
speed = 100;
|
| 12144 |
|
|
|
| 12145 |
|
|
i_length = (min_tmp - 4);
|
| 12146 |
|
|
while (i_length <= (max_tmp - 4))
|
| 12147 |
|
|
begin
|
| 12148 |
|
|
// choose generating carrier sense and collision for first and last 64 lengths of frames
|
| 12149 |
|
|
case (i_length[1:0])
|
| 12150 |
|
|
2'h0: // Interrupt is generated
|
| 12151 |
|
|
begin
|
| 12152 |
|
|
// enable interrupt generation
|
| 12153 |
|
|
set_rx_bd(127, 127, 1'b1, (`MEMORY_BASE + i_length[1:0]));
|
| 12154 |
|
|
// unmask interrupts
|
| 12155 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 12156 |
209 |
tadejm |
wbm_write(`ETH_INT_MASK, `ETH_INT_TXB | `ETH_INT_TXE | `ETH_INT_RXB | `ETH_INT_RXE | `ETH_INT_BUSY |
|
| 12157 |
|
|
`ETH_INT_TXC | `ETH_INT_RXC, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 12158 |
|
|
// not detect carrier sense in FD and no collision
|
| 12159 |
|
|
eth_phy.no_carrier_sense_rx_fd_detect(0);
|
| 12160 |
|
|
eth_phy.collision(0);
|
| 12161 |
|
|
end
|
| 12162 |
|
|
2'h1: // Interrupt is not generated
|
| 12163 |
|
|
begin
|
| 12164 |
|
|
// enable interrupt generation
|
| 12165 |
|
|
set_rx_bd(127, 127, 1'b1, ((`MEMORY_BASE + i_length[1:0]) + max_tmp));
|
| 12166 |
|
|
// mask interrupts
|
| 12167 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 12168 |
209 |
tadejm |
wbm_write(`ETH_INT_MASK, 32'h0, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 12169 |
|
|
// detect carrier sense in FD and no collision
|
| 12170 |
|
|
eth_phy.no_carrier_sense_rx_fd_detect(1);
|
| 12171 |
|
|
eth_phy.collision(0);
|
| 12172 |
|
|
end
|
| 12173 |
|
|
2'h2: // Interrupt is not generated
|
| 12174 |
|
|
begin
|
| 12175 |
|
|
// disable interrupt generation
|
| 12176 |
|
|
set_rx_bd(127, 127, 1'b0, (`MEMORY_BASE + i_length[1:0]));
|
| 12177 |
|
|
// unmask interrupts
|
| 12178 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 12179 |
209 |
tadejm |
wbm_write(`ETH_INT_MASK, `ETH_INT_TXB | `ETH_INT_TXE | `ETH_INT_RXB | `ETH_INT_RXE | `ETH_INT_BUSY |
|
| 12180 |
|
|
`ETH_INT_TXC | `ETH_INT_RXC, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 12181 |
|
|
// not detect carrier sense in FD and set collision
|
| 12182 |
|
|
eth_phy.no_carrier_sense_rx_fd_detect(0);
|
| 12183 |
|
|
eth_phy.collision(1);
|
| 12184 |
|
|
end
|
| 12185 |
|
|
default: // 2'h3: // Interrupt is not generated
|
| 12186 |
|
|
begin
|
| 12187 |
|
|
// disable interrupt generation
|
| 12188 |
|
|
set_rx_bd(127, 127, 1'b0, ((`MEMORY_BASE + i_length[1:0]) + max_tmp));
|
| 12189 |
|
|
// mask interrupts
|
| 12190 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 12191 |
209 |
tadejm |
wbm_write(`ETH_INT_MASK, 32'h0, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 12192 |
|
|
// detect carrier sense in FD and set collision
|
| 12193 |
|
|
eth_phy.no_carrier_sense_rx_fd_detect(1);
|
| 12194 |
|
|
eth_phy.collision(1);
|
| 12195 |
|
|
end
|
| 12196 |
|
|
endcase
|
| 12197 |
|
|
if (i_length[0] == 1'b0)
|
| 12198 |
|
|
append_rx_crc (0, i_length, 1'b0, 1'b0);
|
| 12199 |
|
|
else
|
| 12200 |
|
|
append_rx_crc (max_tmp, i_length, 1'b0, 1'b0);
|
| 12201 |
|
|
// set wrap bit
|
| 12202 |
|
|
set_rx_bd_wrap(127);
|
| 12203 |
|
|
set_rx_bd_empty(127, 127);
|
| 12204 |
|
|
fork
|
| 12205 |
|
|
begin
|
| 12206 |
|
|
if (i_length[0] == 1'b0)
|
| 12207 |
|
|
#1 eth_phy.send_rx_packet(64'h0055_5555_5555_5555, 4'h7, 8'hD5, 0, (i_length + 4), 1'b0);
|
| 12208 |
|
|
else
|
| 12209 |
|
|
#1 eth_phy.send_rx_packet(64'h0055_5555_5555_5555, 4'h7, 8'hD5, max_tmp, (i_length + 4), 1'b0);
|
| 12210 |
|
|
repeat(10) @(posedge mrx_clk);
|
| 12211 |
|
|
end
|
| 12212 |
|
|
begin
|
| 12213 |
|
|
#1 check_rx_bd(127, data);
|
| 12214 |
|
|
if (i_length < min_tmp) // just first four
|
| 12215 |
|
|
begin
|
| 12216 |
|
|
while (data[15] === 1)
|
| 12217 |
|
|
begin
|
| 12218 |
|
|
#1 check_rx_bd(127, data);
|
| 12219 |
|
|
@(posedge wb_clk);
|
| 12220 |
|
|
end
|
| 12221 |
|
|
repeat (1) @(posedge wb_clk);
|
| 12222 |
|
|
end
|
| 12223 |
|
|
else
|
| 12224 |
|
|
begin
|
| 12225 |
|
|
wait (MRxDV === 1'b1); // start transmit
|
| 12226 |
|
|
#1 check_rx_bd(127, data);
|
| 12227 |
|
|
if (data[15] !== 1)
|
| 12228 |
|
|
begin
|
| 12229 |
|
|
test_fail("Wrong buffer descriptor's ready bit read out from MAC");
|
| 12230 |
|
|
fail = fail + 1;
|
| 12231 |
|
|
end
|
| 12232 |
|
|
wait (MRxDV === 1'b0); // end transmit
|
| 12233 |
|
|
while (data[15] === 1)
|
| 12234 |
|
|
begin
|
| 12235 |
|
|
#1 check_rx_bd(127, data);
|
| 12236 |
|
|
@(posedge wb_clk);
|
| 12237 |
|
|
end
|
| 12238 |
|
|
repeat (1) @(posedge wb_clk);
|
| 12239 |
|
|
end
|
| 12240 |
|
|
end
|
| 12241 |
|
|
join
|
| 12242 |
|
|
// check length of a PACKET
|
| 12243 |
|
|
if (data[31:16] != (i_length + 4))
|
| 12244 |
|
|
begin
|
| 12245 |
|
|
`TIME; $display("*E Wrong length of the packet out from PHY (%0d instead of %0d)",
|
| 12246 |
|
|
data[31:16], (i_length + 4));
|
| 12247 |
|
|
test_fail("Wrong length of the packet out from PHY");
|
| 12248 |
|
|
fail = fail + 1;
|
| 12249 |
|
|
end
|
| 12250 |
|
|
// checking in the following if statement is performed only for first and last 64 lengths
|
| 12251 |
|
|
// check received RX packet data and CRC
|
| 12252 |
|
|
if (i_length[0] == 1'b0)
|
| 12253 |
|
|
begin
|
| 12254 |
|
|
check_rx_packet(0, (`MEMORY_BASE + i_length[1:0]), (i_length + 4), 1'b0, 1'b0, tmp);
|
| 12255 |
|
|
end
|
| 12256 |
|
|
else
|
| 12257 |
|
|
begin
|
| 12258 |
|
|
check_rx_packet(max_tmp, ((`MEMORY_BASE + i_length[1:0]) + max_tmp), (i_length + 4), 1'b0, 1'b0, tmp);
|
| 12259 |
|
|
end
|
| 12260 |
|
|
if (tmp > 0)
|
| 12261 |
|
|
begin
|
| 12262 |
|
|
`TIME; $display("*E Wrong data of the received packet");
|
| 12263 |
|
|
test_fail("Wrong data of the received packet");
|
| 12264 |
|
|
fail = fail + 1;
|
| 12265 |
|
|
end
|
| 12266 |
|
|
// check WB INT signal
|
| 12267 |
|
|
if (i_length[1:0] == 2'h0)
|
| 12268 |
|
|
begin
|
| 12269 |
|
|
if (wb_int !== 1'b1)
|
| 12270 |
|
|
begin
|
| 12271 |
|
|
`TIME; $display("*E WB INT signal should be set");
|
| 12272 |
|
|
test_fail("WB INT signal should be set");
|
| 12273 |
|
|
fail = fail + 1;
|
| 12274 |
|
|
end
|
| 12275 |
|
|
end
|
| 12276 |
|
|
else
|
| 12277 |
|
|
begin
|
| 12278 |
|
|
if (wb_int !== 1'b0)
|
| 12279 |
|
|
begin
|
| 12280 |
|
|
`TIME; $display("*E WB INT signal should not be set");
|
| 12281 |
|
|
test_fail("WB INT signal should not be set");
|
| 12282 |
|
|
fail = fail + 1;
|
| 12283 |
|
|
end
|
| 12284 |
|
|
end
|
| 12285 |
|
|
// check RX buffer descriptor of a packet
|
| 12286 |
|
|
check_rx_bd(127, data);
|
| 12287 |
|
|
if (i_length[1] == 1'b0) // interrupt enabled
|
| 12288 |
|
|
begin
|
| 12289 |
|
|
if ( ((data[15:0] !== 16'h6000) && (i_length[0] == 1'b0)) ||
|
| 12290 |
|
|
((data[15:0] !== 16'h6000) && (i_length[0] == 1'b1)) )
|
| 12291 |
|
|
begin
|
| 12292 |
|
|
`TIME; $display("*E RX buffer descriptor status is not correct: %0h", data[15:0]);
|
| 12293 |
|
|
test_fail("RX buffer descriptor status is not correct");
|
| 12294 |
|
|
fail = fail + 1;
|
| 12295 |
|
|
end
|
| 12296 |
|
|
end
|
| 12297 |
|
|
else // interrupt not enabled
|
| 12298 |
|
|
begin
|
| 12299 |
|
|
if ( ((data[15:0] !== 16'h2000) && (i_length[0] == 1'b0)) ||
|
| 12300 |
|
|
((data[15:0] !== 16'h2000) && (i_length[0] == 1'b1)) )
|
| 12301 |
|
|
begin
|
| 12302 |
|
|
`TIME; $display("*E RX buffer descriptor status is not correct: %0h", data[15:0]);
|
| 12303 |
|
|
test_fail("RX buffer descriptor status is not correct");
|
| 12304 |
|
|
fail = fail + 1;
|
| 12305 |
|
|
end
|
| 12306 |
|
|
end
|
| 12307 |
|
|
// clear RX buffer descriptor for first 4 frames
|
| 12308 |
|
|
if (i_length < min_tmp)
|
| 12309 |
|
|
clear_rx_bd(127, 127);
|
| 12310 |
|
|
// check interrupts
|
| 12311 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 12312 |
209 |
tadejm |
wbm_read(`ETH_INT, data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 12313 |
|
|
if ((i_length[1:0] == 2'h0) || (i_length[1:0] == 2'h1))
|
| 12314 |
|
|
begin
|
| 12315 |
|
|
if ((data & `ETH_INT_RXB) !== `ETH_INT_RXB)
|
| 12316 |
|
|
begin
|
| 12317 |
|
|
`TIME; $display("*E Interrupt Receive Buffer was not set, interrupt reg: %0h", data);
|
| 12318 |
|
|
test_fail("Interrupt Receive Buffer was not set");
|
| 12319 |
|
|
fail = fail + 1;
|
| 12320 |
|
|
end
|
| 12321 |
|
|
if ((data & (~`ETH_INT_RXB)) !== 0)
|
| 12322 |
|
|
begin
|
| 12323 |
|
|
`TIME; $display("*E Other interrupts (except Receive Buffer) were set, interrupt reg: %0h", data);
|
| 12324 |
|
|
test_fail("Other interrupts (except Receive Buffer) were set");
|
| 12325 |
|
|
fail = fail + 1;
|
| 12326 |
|
|
end
|
| 12327 |
|
|
end
|
| 12328 |
|
|
else
|
| 12329 |
|
|
begin
|
| 12330 |
|
|
if (data !== 0)
|
| 12331 |
|
|
begin
|
| 12332 |
|
|
`TIME; $display("*E Any of interrupts (except Receive Buffer) was set, interrupt reg: %0h, len: %0h", data, i_length[1:0]);
|
| 12333 |
|
|
test_fail("Any of interrupts (except Receive Buffer) was set");
|
| 12334 |
|
|
fail = fail + 1;
|
| 12335 |
|
|
end
|
| 12336 |
|
|
end
|
| 12337 |
|
|
// clear interrupts
|
| 12338 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 12339 |
209 |
tadejm |
wbm_write(`ETH_INT, data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 12340 |
|
|
// check WB INT signal
|
| 12341 |
|
|
if (wb_int !== 1'b0)
|
| 12342 |
|
|
begin
|
| 12343 |
|
|
test_fail("WB INT signal should not be set");
|
| 12344 |
|
|
fail = fail + 1;
|
| 12345 |
|
|
end
|
| 12346 |
|
|
// INTERMEDIATE DISPLAYS
|
| 12347 |
|
|
if ((i_length + 4) == (min_tmp + 64))
|
| 12348 |
|
|
begin
|
| 12349 |
|
|
// starting length is min_tmp, ending length is (min_tmp + 64)
|
| 12350 |
|
|
$display(" receive small packets is NOT selected");
|
| 12351 |
|
|
$display(" ->packets with lengths from %0d (MINFL) to %0d are checked (length increasing by 1 byte)",
|
| 12352 |
|
|
min_tmp, (min_tmp + 64));
|
| 12353 |
|
|
// set receive small, remain the rest
|
| 12354 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 12355 |
209 |
tadejm |
wbm_write(`ETH_MODER, `ETH_MODER_RXEN | `ETH_MODER_FULLD | `ETH_MODER_RECSMALL | `ETH_MODER_IFG |
|
| 12356 |
|
|
`ETH_MODER_PRO | `ETH_MODER_BRO,
|
| 12357 |
|
|
4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 12358 |
|
|
end
|
| 12359 |
|
|
else if ((i_length + 4) == (max_tmp - 16))
|
| 12360 |
|
|
begin
|
| 12361 |
|
|
// starting length is for +128 longer than previous ending length, while ending length is tmp_data
|
| 12362 |
|
|
$display(" receive small packets is selected");
|
| 12363 |
|
|
$display(" ->packets with lengths from %0d to %0d are checked (length increasing by 128 bytes)",
|
| 12364 |
|
|
(min_tmp + 64 + 128), tmp_data);
|
| 12365 |
|
|
// reset receive small, remain the rest
|
| 12366 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 12367 |
209 |
tadejm |
wbm_write(`ETH_MODER, `ETH_MODER_RXEN | `ETH_MODER_FULLD | `ETH_MODER_IFG |
|
| 12368 |
|
|
`ETH_MODER_PRO | `ETH_MODER_BRO,
|
| 12369 |
|
|
4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 12370 |
|
|
end
|
| 12371 |
|
|
else if ((i_length + 4) == max_tmp)
|
| 12372 |
|
|
begin
|
| 12373 |
|
|
$display(" receive small packets is NOT selected");
|
| 12374 |
|
|
$display(" ->packets with lengths from %0d to %0d (MAXFL) are checked (length increasing by 1 byte)",
|
| 12375 |
|
|
(max_tmp - (4 + 16)), max_tmp);
|
| 12376 |
|
|
end
|
| 12377 |
|
|
// set length (loop variable)
|
| 12378 |
|
|
if ((i_length + 4) < (min_tmp + 64))
|
| 12379 |
|
|
i_length = i_length + 1;
|
| 12380 |
|
|
else if ( ((i_length + 4) >= (min_tmp + 64)) && ((i_length + 4) <= (max_tmp - 256)) )
|
| 12381 |
|
|
begin
|
| 12382 |
|
|
i_length = i_length + 128;
|
| 12383 |
|
|
tmp_data = i_length + 4; // last tmp_data is ending length
|
| 12384 |
|
|
end
|
| 12385 |
|
|
else if ( ((i_length + 4) > (max_tmp - 256)) && ((i_length + 4) < (max_tmp - 16)) )
|
| 12386 |
|
|
i_length = max_tmp - (4 + 16);
|
| 12387 |
|
|
else if ((i_length + 4) >= (max_tmp - 16))
|
| 12388 |
|
|
i_length = i_length + 1;
|
| 12389 |
|
|
else
|
| 12390 |
|
|
begin
|
| 12391 |
|
|
$display("*E TESTBENCH ERROR - WRONG PARAMETERS IN TESTBENCH");
|
| 12392 |
|
|
#10 $stop;
|
| 12393 |
|
|
end
|
| 12394 |
|
|
end
|
| 12395 |
|
|
// disable RX
|
| 12396 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 12397 |
209 |
tadejm |
wbm_write(`ETH_MODER, `ETH_MODER_FULLD | `ETH_MODER_RECSMALL | `ETH_MODER_IFG |
|
| 12398 |
|
|
`ETH_MODER_PRO | `ETH_MODER_BRO,
|
| 12399 |
|
|
4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 12400 |
|
|
if(fail == 0)
|
| 12401 |
|
|
test_ok;
|
| 12402 |
|
|
else
|
| 12403 |
|
|
fail = 0;
|
| 12404 |
|
|
end
|
| 12405 |
|
|
|
| 12406 |
|
|
|
| 12407 |
|
|
////////////////////////////////////////////////////////////////////
|
| 12408 |
|
|
//// ////
|
| 12409 |
|
|
//// Test receive packets form MINFL to MAXFL sizes at ////
|
| 12410 |
|
|
//// maximum RX buffer decriptors ( 10Mbps ). ////
|
| 12411 |
|
|
//// ////
|
| 12412 |
|
|
////////////////////////////////////////////////////////////////////
|
| 12413 |
243 |
tadejm |
if (test_num == 6) //
|
| 12414 |
209 |
tadejm |
begin
|
| 12415 |
243 |
tadejm |
// TEST 6: RECEIVE PACKETS FROM MINFL TO MAXFL SIZES AT MAX RX BDs ( 10Mbps )
|
| 12416 |
|
|
test_name = "TEST 6: RECEIVE PACKETS FROM MINFL TO MAXFL SIZES AT MAX RX BDs ( 10Mbps )";
|
| 12417 |
|
|
`TIME; $display(" TEST 6: RECEIVE PACKETS FROM MINFL TO MAXFL SIZES AT MAX RX BDs ( 10Mbps )");
|
| 12418 |
209 |
tadejm |
|
| 12419 |
|
|
// reset MAC registers
|
| 12420 |
|
|
hard_reset;
|
| 12421 |
|
|
// reset MAC and MII LOGIC with soft reset
|
| 12422 |
274 |
tadejm |
// reset_mac;
|
| 12423 |
|
|
// reset_mii;
|
| 12424 |
209 |
tadejm |
// set wb slave response
|
| 12425 |
|
|
wb_slave.cycle_response(`ACK_RESPONSE, wbs_waits, wbs_retries);
|
| 12426 |
|
|
|
| 12427 |
|
|
max_tmp = 0;
|
| 12428 |
|
|
min_tmp = 0;
|
| 12429 |
|
|
num_of_frames = 0;
|
| 12430 |
|
|
num_of_bd = 0;
|
| 12431 |
|
|
// set maximum RX buffer descriptors (128) - must be set before RX enable
|
| 12432 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 12433 |
209 |
tadejm |
wbm_write(`ETH_TX_BD_NUM, 32'h0, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 12434 |
|
|
// enable RX, set full-duplex mode, NO receive small, NO correct IFG
|
| 12435 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 12436 |
209 |
tadejm |
wbm_write(`ETH_MODER, `ETH_MODER_RXEN | `ETH_MODER_FULLD | `ETH_MODER_IFG |
|
| 12437 |
|
|
`ETH_MODER_PRO | `ETH_MODER_BRO,
|
| 12438 |
|
|
4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 12439 |
|
|
// prepare two packets of MAXFL length
|
| 12440 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 12441 |
209 |
tadejm |
wbm_read(`ETH_PACKETLEN, tmp, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 12442 |
|
|
max_tmp = tmp[15:0]; // 18 bytes consists of 6B dest addr, 6B source addr, 2B type/len, 4B CRC
|
| 12443 |
|
|
min_tmp = tmp[31:16];
|
| 12444 |
|
|
st_data = 8'hAC;
|
| 12445 |
|
|
set_rx_packet(0, (max_tmp - 4), 1'b0, 48'h0102_0304_0506, 48'h0708_090A_0B0C, 16'h0D0E, st_data); // length without CRC
|
| 12446 |
|
|
st_data = 8'h35;
|
| 12447 |
|
|
set_rx_packet((max_tmp), (max_tmp - 4), 1'b0, 48'h1234_5678_8765, 48'hA1B2_C3D4_E5F6, 16'hE77E, st_data);
|
| 12448 |
|
|
// check WB INT signal
|
| 12449 |
|
|
if (wb_int !== 1'b0)
|
| 12450 |
|
|
begin
|
| 12451 |
|
|
test_fail("WB INT signal should not be set");
|
| 12452 |
|
|
fail = fail + 1;
|
| 12453 |
|
|
end
|
| 12454 |
|
|
|
| 12455 |
|
|
// write to phy's control register for 10Mbps
|
| 12456 |
|
|
#Tp eth_phy.control_bit14_10 = 5'b00000; // bit 13 reset - speed 10
|
| 12457 |
|
|
#Tp eth_phy.control_bit8_0 = 9'h1_00; // bit 6 reset - (10/100), bit 8 set - FD
|
| 12458 |
|
|
speed = 10;
|
| 12459 |
|
|
|
| 12460 |
|
|
i_length = (min_tmp - 4);
|
| 12461 |
|
|
while (i_length <= (max_tmp - 4))
|
| 12462 |
|
|
begin
|
| 12463 |
|
|
// append CRC to packet
|
| 12464 |
|
|
if (i_length[0] == 1'b0)
|
| 12465 |
|
|
append_rx_crc (0, i_length, 1'b0, 1'b0);
|
| 12466 |
|
|
else
|
| 12467 |
|
|
append_rx_crc (max_tmp, i_length, 1'b0, 1'b0);
|
| 12468 |
|
|
// choose generating carrier sense and collision
|
| 12469 |
|
|
case (i_length[1:0])
|
| 12470 |
|
|
2'h0: // Interrupt is generated
|
| 12471 |
|
|
begin
|
| 12472 |
|
|
// Reset_tx_bd nable interrupt generation
|
| 12473 |
|
|
// unmask interrupts
|
| 12474 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 12475 |
209 |
tadejm |
wbm_write(`ETH_INT_MASK, `ETH_INT_TXB | `ETH_INT_TXE | `ETH_INT_RXB | `ETH_INT_RXE | `ETH_INT_BUSY |
|
| 12476 |
|
|
`ETH_INT_TXC | `ETH_INT_RXC, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 12477 |
|
|
// not detect carrier sense in FD and no collision
|
| 12478 |
|
|
eth_phy.no_carrier_sense_rx_fd_detect(0);
|
| 12479 |
|
|
eth_phy.collision(0);
|
| 12480 |
|
|
end
|
| 12481 |
|
|
2'h1: // Interrupt is not generated
|
| 12482 |
|
|
begin
|
| 12483 |
|
|
// set_tx_bd enable interrupt generation
|
| 12484 |
|
|
// mask interrupts
|
| 12485 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 12486 |
209 |
tadejm |
wbm_write(`ETH_INT_MASK, 32'h0, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 12487 |
|
|
// detect carrier sense in FD and no collision
|
| 12488 |
|
|
eth_phy.no_carrier_sense_rx_fd_detect(1);
|
| 12489 |
|
|
eth_phy.collision(0);
|
| 12490 |
|
|
end
|
| 12491 |
|
|
2'h2: // Interrupt is not generated
|
| 12492 |
|
|
begin
|
| 12493 |
|
|
// set_tx_bd disable the interrupt generation
|
| 12494 |
|
|
// unmask interrupts
|
| 12495 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 12496 |
209 |
tadejm |
wbm_write(`ETH_INT_MASK, `ETH_INT_TXB | `ETH_INT_TXE | `ETH_INT_RXB | `ETH_INT_RXE | `ETH_INT_BUSY |
|
| 12497 |
|
|
`ETH_INT_TXC | `ETH_INT_RXC, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 12498 |
|
|
// not detect carrier sense in FD and set collision
|
| 12499 |
|
|
eth_phy.no_carrier_sense_rx_fd_detect(0);
|
| 12500 |
|
|
eth_phy.collision(1);
|
| 12501 |
|
|
end
|
| 12502 |
|
|
default: // 2'h3: // Interrupt is not generated
|
| 12503 |
|
|
begin
|
| 12504 |
|
|
// set_tx_bd disable the interrupt generation
|
| 12505 |
|
|
// mask interrupts
|
| 12506 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 12507 |
209 |
tadejm |
wbm_write(`ETH_INT_MASK, 32'h0, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 12508 |
|
|
// detect carrier sense in FD and set collision
|
| 12509 |
|
|
eth_phy.no_carrier_sense_rx_fd_detect(1);
|
| 12510 |
|
|
eth_phy.collision(1);
|
| 12511 |
|
|
end
|
| 12512 |
|
|
endcase
|
| 12513 |
|
|
// first 8 frames are received with RX BD 0 (wrap bit on RX BD 0)
|
| 12514 |
|
|
// number of all frames is 154 (146 without first 8)
|
| 12515 |
|
|
if (num_of_frames < 8)
|
| 12516 |
|
|
begin
|
| 12517 |
|
|
case (i_length[1:0])
|
| 12518 |
|
|
2'h0: // Interrupt is generated
|
| 12519 |
|
|
begin
|
| 12520 |
|
|
// enable interrupt generation
|
| 12521 |
|
|
set_rx_bd(0, 0, 1'b1, (`MEMORY_BASE + i_length[1:0]));
|
| 12522 |
|
|
// interrupts are unmasked
|
| 12523 |
|
|
end
|
| 12524 |
|
|
2'h1: // Interrupt is not generated
|
| 12525 |
|
|
begin
|
| 12526 |
|
|
// enable interrupt generation
|
| 12527 |
|
|
set_rx_bd(0, 0, 1'b1, ((`MEMORY_BASE + i_length[1:0]) + max_tmp));
|
| 12528 |
|
|
// interrupts are masked
|
| 12529 |
|
|
end
|
| 12530 |
|
|
2'h2: // Interrupt is not generated
|
| 12531 |
|
|
begin
|
| 12532 |
|
|
// disable interrupt generation
|
| 12533 |
|
|
set_rx_bd(0, 0, 1'b0, (`MEMORY_BASE + i_length[1:0]));
|
| 12534 |
|
|
// interrupts are unmasked
|
| 12535 |
|
|
end
|
| 12536 |
|
|
default: // 2'h3: // Interrupt is not generated
|
| 12537 |
|
|
begin
|
| 12538 |
|
|
// disable interrupt generation
|
| 12539 |
|
|
set_rx_bd(0, 0, 1'b0, ((`MEMORY_BASE + i_length[1:0]) + max_tmp));
|
| 12540 |
|
|
// interrupts are masked
|
| 12541 |
|
|
end
|
| 12542 |
|
|
endcase
|
| 12543 |
|
|
// set wrap bit
|
| 12544 |
|
|
set_rx_bd_wrap(0);
|
| 12545 |
|
|
end
|
| 12546 |
|
|
// after first 8 number of frames, 128 frames form RX BD 0 to 127 will be received
|
| 12547 |
|
|
else if ((num_of_frames - 8) == 0)
|
| 12548 |
|
|
begin
|
| 12549 |
|
|
tmp_len = i_length; // length of frame
|
| 12550 |
|
|
tmp_bd_num = 0; // RX BD number
|
| 12551 |
|
|
while (tmp_bd_num < 128) // (tmp_len <= (max_tmp - 4)) - this is the last frame
|
| 12552 |
|
|
begin
|
| 12553 |
|
|
// if i_length[1] == 0 then enable interrupt generation otherwise disable it
|
| 12554 |
|
|
// if i_length[0] == 0 then base address is `MEMORY_BASE otherwise it is `MEMORY_BASE + max_tmp
|
| 12555 |
|
|
if (tmp_len[0] == 0)
|
| 12556 |
|
|
set_rx_bd(tmp_bd_num, tmp_bd_num, !tmp_len[1], (`MEMORY_BASE + tmp_len[1:0]));
|
| 12557 |
|
|
else
|
| 12558 |
|
|
set_rx_bd(tmp_bd_num, tmp_bd_num, !tmp_len[1], ((`MEMORY_BASE + tmp_len[1:0]) + max_tmp));
|
| 12559 |
|
|
// set length (loop variable) - THE SAME AS AT THE END OF THIS TASK !!!
|
| 12560 |
|
|
if ((tmp_len + 4) < (min_tmp + 128))
|
| 12561 |
|
|
tmp_len = tmp_len + 1;
|
| 12562 |
|
|
else if ( ((tmp_len + 4) == (min_tmp + 128)) && ((tmp_len + 4) <= (max_tmp - 256)) )
|
| 12563 |
|
|
tmp_len = 256;
|
| 12564 |
|
|
else if ( ((tmp_len + 4) > (min_tmp + 128)) && ((tmp_len + 4) <= (max_tmp - 256)) )
|
| 12565 |
|
|
tmp_len = tmp_len + 128;
|
| 12566 |
|
|
else if ( ((tmp_len + 4) > (max_tmp - 256)) && ((tmp_len + 4) < (max_tmp - 16)) )
|
| 12567 |
|
|
tmp_len = max_tmp - (4 + 16);
|
| 12568 |
|
|
else if ((tmp_len + 4) >= (max_tmp - 16))
|
| 12569 |
|
|
tmp_len = tmp_len + 1;
|
| 12570 |
|
|
// set RX BD number
|
| 12571 |
|
|
tmp_bd_num = tmp_bd_num + 1;
|
| 12572 |
|
|
end
|
| 12573 |
|
|
// set wrap bit
|
| 12574 |
|
|
set_rx_bd_wrap(127);
|
| 12575 |
|
|
end
|
| 12576 |
|
|
// after 128 + first 8 number of frames, 19 frames form RX BD 0 to 18 will be received
|
| 12577 |
|
|
else if ((num_of_frames - 8) == 20) // 128
|
| 12578 |
|
|
begin
|
| 12579 |
|
|
tmp_len = tmp_len; // length of frame remaines from previous settings
|
| 12580 |
|
|
tmp_bd_num = 0; // TX BD number
|
| 12581 |
|
|
while (tmp_bd_num < 19) // (tmp_len <= (max_tmp - 4)) - this is the last frame
|
| 12582 |
|
|
begin
|
| 12583 |
|
|
// if i_length[1] == 0 then enable interrupt generation otherwise disable it
|
| 12584 |
|
|
// if i_length[0] == 0 then base address is `MEMORY_BASE otherwise it is `MEMORY_BASE + max_tmp
|
| 12585 |
|
|
if (tmp_len[0] == 0)
|
| 12586 |
|
|
set_rx_bd(tmp_bd_num, tmp_bd_num, !tmp_len[1], (`MEMORY_BASE + tmp_len[1:0]));
|
| 12587 |
|
|
else
|
| 12588 |
|
|
set_rx_bd(tmp_bd_num, tmp_bd_num, !tmp_len[1], ((`MEMORY_BASE + tmp_len[1:0]) + max_tmp));
|
| 12589 |
|
|
// set length (loop variable) - THE SAME AS AT THE END OF THIS TASK !!!
|
| 12590 |
|
|
if ((tmp_len + 4) < (min_tmp + 128))
|
| 12591 |
|
|
tmp_len = tmp_len + 1;
|
| 12592 |
|
|
else if ( ((tmp_len + 4) == (min_tmp + 128)) && ((tmp_len + 4) <= (max_tmp - 256)) )
|
| 12593 |
|
|
tmp_len = 256;
|
| 12594 |
|
|
else if ( ((tmp_len + 4) > (min_tmp + 128)) && ((tmp_len + 4) <= (max_tmp - 256)) )
|
| 12595 |
|
|
tmp_len = tmp_len + 128;
|
| 12596 |
|
|
else if ( ((tmp_len + 4) > (max_tmp - 256)) && ((tmp_len + 4) < (max_tmp - 16)) )
|
| 12597 |
|
|
tmp_len = max_tmp - (4 + 16);
|
| 12598 |
|
|
else if ((tmp_len + 4) >= (max_tmp - 16))
|
| 12599 |
|
|
tmp_len = tmp_len + 1;
|
| 12600 |
|
|
// set TX BD number
|
| 12601 |
|
|
tmp_bd_num = tmp_bd_num + 1;
|
| 12602 |
|
|
end
|
| 12603 |
|
|
end
|
| 12604 |
|
|
// set empty bit
|
| 12605 |
|
|
if (num_of_frames < 8)
|
| 12606 |
|
|
set_rx_bd_empty(0, 0);
|
| 12607 |
|
|
else if ((num_of_frames - 8) < 128)
|
| 12608 |
|
|
set_rx_bd_empty((num_of_frames - 8), (num_of_frames - 8));
|
| 12609 |
|
|
else if ((num_of_frames - 136) < 19)
|
| 12610 |
|
|
set_rx_bd_empty((num_of_frames - 136), (num_of_frames - 136));
|
| 12611 |
|
|
// CHECK END OF RECEIVE
|
| 12612 |
|
|
fork
|
| 12613 |
|
|
begin
|
| 12614 |
|
|
if (i_length[0] == 1'b0)
|
| 12615 |
|
|
#1 eth_phy.send_rx_packet(64'h0055_5555_5555_5555, 4'h7, 8'hD5, 0, (i_length + 4), 1'b0);
|
| 12616 |
|
|
else
|
| 12617 |
|
|
#1 eth_phy.send_rx_packet(64'h0055_5555_5555_5555, 4'h7, 8'hD5, max_tmp, (i_length + 4), 1'b0);
|
| 12618 |
|
|
repeat(10) @(posedge mrx_clk);
|
| 12619 |
|
|
end
|
| 12620 |
|
|
begin
|
| 12621 |
|
|
#1 check_rx_bd(num_of_bd, data);
|
| 12622 |
|
|
if (i_length < min_tmp) // just first four
|
| 12623 |
|
|
begin
|
| 12624 |
|
|
while (data[15] === 1)
|
| 12625 |
|
|
begin
|
| 12626 |
|
|
#1 check_rx_bd(num_of_bd, data);
|
| 12627 |
|
|
@(posedge wb_clk);
|
| 12628 |
|
|
end
|
| 12629 |
|
|
repeat (1) @(posedge wb_clk);
|
| 12630 |
|
|
end
|
| 12631 |
|
|
else
|
| 12632 |
|
|
begin
|
| 12633 |
|
|
wait (MRxDV === 1'b1); // start transmit
|
| 12634 |
|
|
#1 check_rx_bd(num_of_bd, data);
|
| 12635 |
|
|
if (data[15] !== 1)
|
| 12636 |
|
|
begin
|
| 12637 |
|
|
test_fail("Wrong buffer descriptor's ready bit read out from MAC");
|
| 12638 |
|
|
fail = fail + 1;
|
| 12639 |
|
|
end
|
| 12640 |
|
|
wait (MRxDV === 1'b0); // end transmit
|
| 12641 |
|
|
while (data[15] === 1)
|
| 12642 |
|
|
begin
|
| 12643 |
|
|
#1 check_rx_bd(num_of_bd, data);
|
| 12644 |
|
|
@(posedge wb_clk);
|
| 12645 |
|
|
end
|
| 12646 |
|
|
repeat (1) @(posedge wb_clk);
|
| 12647 |
|
|
end
|
| 12648 |
|
|
end
|
| 12649 |
|
|
join
|
| 12650 |
|
|
// check length of a PACKET
|
| 12651 |
|
|
if (data[31:16] != (i_length + 4))
|
| 12652 |
|
|
begin
|
| 12653 |
|
|
`TIME; $display("*E Wrong length of the packet out from PHY (%0d instead of %0d)",
|
| 12654 |
|
|
data[31:16], (i_length + 4));
|
| 12655 |
|
|
test_fail("Wrong length of the packet out from PHY");
|
| 12656 |
|
|
fail = fail + 1;
|
| 12657 |
|
|
end
|
| 12658 |
|
|
// checking in the following if statement is performed only for first and last 64 lengths
|
| 12659 |
|
|
// check received RX packet data and CRC
|
| 12660 |
|
|
if (i_length[0] == 1'b0)
|
| 12661 |
|
|
begin
|
| 12662 |
|
|
check_rx_packet(0, (`MEMORY_BASE + i_length[1:0]), (i_length + 4), 1'b0, 1'b0, tmp);
|
| 12663 |
|
|
end
|
| 12664 |
|
|
else
|
| 12665 |
|
|
begin
|
| 12666 |
|
|
check_rx_packet(max_tmp, ((`MEMORY_BASE + i_length[1:0]) + max_tmp), (i_length + 4), 1'b0, 1'b0, tmp);
|
| 12667 |
|
|
end
|
| 12668 |
|
|
if (tmp > 0)
|
| 12669 |
|
|
begin
|
| 12670 |
|
|
`TIME; $display("*E Wrong data of the received packet");
|
| 12671 |
|
|
test_fail("Wrong data of the received packet");
|
| 12672 |
|
|
fail = fail + 1;
|
| 12673 |
|
|
end
|
| 12674 |
|
|
// check WB INT signal
|
| 12675 |
|
|
if (i_length[1:0] == 2'h0)
|
| 12676 |
|
|
begin
|
| 12677 |
|
|
if (wb_int !== 1'b1)
|
| 12678 |
|
|
begin
|
| 12679 |
|
|
`TIME; $display("*E WB INT signal should be set");
|
| 12680 |
|
|
test_fail("WB INT signal should be set");
|
| 12681 |
|
|
fail = fail + 1;
|
| 12682 |
|
|
end
|
| 12683 |
|
|
end
|
| 12684 |
|
|
else
|
| 12685 |
|
|
begin
|
| 12686 |
|
|
if (wb_int !== 1'b0)
|
| 12687 |
|
|
begin
|
| 12688 |
|
|
`TIME; $display("*E WB INT signal should not be set");
|
| 12689 |
|
|
test_fail("WB INT signal should not be set");
|
| 12690 |
|
|
fail = fail + 1;
|
| 12691 |
|
|
end
|
| 12692 |
|
|
end
|
| 12693 |
|
|
// check RX buffer descriptor of a packet
|
| 12694 |
|
|
check_rx_bd(num_of_bd, data);
|
| 12695 |
|
|
if (i_length[1] == 1'b0) // interrupt enabled
|
| 12696 |
|
|
begin
|
| 12697 |
|
|
if ( ((data[15:0] !== 16'h6000) && ((num_of_frames < 8) || ((num_of_frames - 8) == 127))) || // wrap bit
|
| 12698 |
|
|
((data[15:0] !== 16'h4000) && (num_of_frames >= 8) && ((num_of_frames - 8) != 127)) ) // without wrap bit
|
| 12699 |
|
|
begin
|
| 12700 |
|
|
`TIME; $display("*E RX buffer descriptor status is not correct: %0h", data[15:0]);
|
| 12701 |
|
|
test_fail("RX buffer descriptor status is not correct");
|
| 12702 |
|
|
fail = fail + 1;
|
| 12703 |
|
|
end
|
| 12704 |
|
|
end
|
| 12705 |
|
|
else // interrupt not enabled
|
| 12706 |
|
|
begin
|
| 12707 |
|
|
if ( ((data[15:0] !== 16'h2000) && ((num_of_frames < 8) || ((num_of_frames - 8) == 127))) || // wrap bit
|
| 12708 |
|
|
((data[15:0] !== 16'h0000) && (num_of_frames >= 8) && ((num_of_frames - 8) != 127)) ) // without wrap bit
|
| 12709 |
|
|
begin
|
| 12710 |
|
|
`TIME; $display("*E RX buffer descriptor status is not correct: %0h", data[15:0]);
|
| 12711 |
|
|
test_fail("RX buffer descriptor status is not correct");
|
| 12712 |
|
|
fail = fail + 1;
|
| 12713 |
|
|
end
|
| 12714 |
|
|
end
|
| 12715 |
|
|
// clear first half of 8 frames from RX buffer descriptor 0
|
| 12716 |
|
|
if (num_of_frames < 4)
|
| 12717 |
|
|
clear_rx_bd(num_of_bd, num_of_bd);
|
| 12718 |
|
|
// clear BD with wrap bit
|
| 12719 |
|
|
if (num_of_frames == 140)
|
| 12720 |
|
|
clear_rx_bd(127, 127);
|
| 12721 |
|
|
// check interrupts
|
| 12722 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 12723 |
209 |
tadejm |
wbm_read(`ETH_INT, data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 12724 |
|
|
if ((i_length[1:0] == 2'h0) || (i_length[1:0] == 2'h1))
|
| 12725 |
|
|
begin
|
| 12726 |
|
|
if ((data & `ETH_INT_RXB) !== `ETH_INT_RXB)
|
| 12727 |
|
|
begin
|
| 12728 |
|
|
`TIME; $display("*E Interrupt Receive Buffer was not set, interrupt reg: %0h", data);
|
| 12729 |
|
|
test_fail("Interrupt Receive Buffer was not set");
|
| 12730 |
|
|
fail = fail + 1;
|
| 12731 |
|
|
end
|
| 12732 |
|
|
if ((data & (~`ETH_INT_RXB)) !== 0)
|
| 12733 |
|
|
begin
|
| 12734 |
|
|
`TIME; $display("*E Other interrupts (except Receive Buffer) were set, interrupt reg: %0h", data);
|
| 12735 |
|
|
test_fail("Other interrupts (except Receive Buffer) were set");
|
| 12736 |
|
|
fail = fail + 1;
|
| 12737 |
|
|
end
|
| 12738 |
|
|
end
|
| 12739 |
|
|
else
|
| 12740 |
|
|
begin
|
| 12741 |
|
|
if (data !== 0)
|
| 12742 |
|
|
begin
|
| 12743 |
|
|
`TIME; $display("*E Any of interrupts (except Receive Buffer) was set, interrupt reg: %0h, len: %0h", data, i_length[1:0]);
|
| 12744 |
|
|
test_fail("Any of interrupts (except Receive Buffer) was set");
|
| 12745 |
|
|
fail = fail + 1;
|
| 12746 |
|
|
end
|
| 12747 |
|
|
end
|
| 12748 |
|
|
// clear interrupts
|
| 12749 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 12750 |
209 |
tadejm |
wbm_write(`ETH_INT, data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 12751 |
|
|
// check WB INT signal
|
| 12752 |
|
|
if (wb_int !== 1'b0)
|
| 12753 |
|
|
begin
|
| 12754 |
|
|
test_fail("WB INT signal should not be set");
|
| 12755 |
|
|
fail = fail + 1;
|
| 12756 |
|
|
end
|
| 12757 |
|
|
// INTERMEDIATE DISPLAYS
|
| 12758 |
|
|
if ((i_length + 4) == (min_tmp + 7))
|
| 12759 |
|
|
begin
|
| 12760 |
|
|
// starting length is min_tmp, ending length is (min_tmp + 128)
|
| 12761 |
|
|
$display(" receive small packets is NOT selected");
|
| 12762 |
|
|
$display(" using only RX BD 0 out of 128 BDs assigned to RX (wrap at first BD - RX BD 0)");
|
| 12763 |
|
|
$display(" ->packets with lengths from %0d (MINFL) to %0d are checked (length increasing by 1 byte)",
|
| 12764 |
|
|
min_tmp, (min_tmp + 7));
|
| 12765 |
|
|
$display(" ->all packets were received on RX BD 0");
|
| 12766 |
|
|
// reset receive small, remain the rest
|
| 12767 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 12768 |
209 |
tadejm |
wbm_write(`ETH_MODER, `ETH_MODER_RXEN | `ETH_MODER_FULLD | `ETH_MODER_IFG |
|
| 12769 |
|
|
`ETH_MODER_PRO | `ETH_MODER_BRO,
|
| 12770 |
|
|
4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 12771 |
|
|
end
|
| 12772 |
|
|
else if ((i_length + 4) == (min_tmp + 128))
|
| 12773 |
|
|
begin
|
| 12774 |
|
|
// starting length is min_tmp, ending length is (min_tmp + 128)
|
| 12775 |
|
|
$display(" receive small packets is NOT selected");
|
| 12776 |
|
|
$display(" using all 128 BDs assigned to RX (wrap at 128th BD - RX BD 127)");
|
| 12777 |
|
|
$display(" ->packets with lengths from %0d to %0d are checked (length increasing by 1 byte)",
|
| 12778 |
|
|
(min_tmp + 8), (min_tmp + 128));
|
| 12779 |
|
|
$display(" ->packets were received on RX BD %0d to RX BD %0d respectively",
|
| 12780 |
|
|
1'b0, num_of_bd);
|
| 12781 |
|
|
tmp_bd = num_of_bd + 1;
|
| 12782 |
|
|
// set receive small, remain the rest
|
| 12783 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 12784 |
209 |
tadejm |
wbm_write(`ETH_MODER, `ETH_MODER_RXEN | `ETH_MODER_FULLD | `ETH_MODER_RECSMALL | `ETH_MODER_IFG |
|
| 12785 |
|
|
`ETH_MODER_PRO | `ETH_MODER_BRO,
|
| 12786 |
|
|
4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 12787 |
|
|
end
|
| 12788 |
|
|
else if ((i_length + 4) == (max_tmp - 16))
|
| 12789 |
|
|
begin
|
| 12790 |
|
|
// starting length is for +128 longer than previous ending length, while ending length is tmp_data
|
| 12791 |
|
|
$display(" receive small packets is selected");
|
| 12792 |
|
|
$display(" using all 128 BDs assigned to RX (wrap at 128th BD - RX BD 127)");
|
| 12793 |
|
|
$display(" ->packets with lengths from %0d to %0d are checked (length increasing by 128 bytes)",
|
| 12794 |
|
|
(min_tmp + 64 + 128), tmp_data);
|
| 12795 |
|
|
if (tmp_bd > num_of_bd)
|
| 12796 |
|
|
$display(" ->packets were received from RX BD %0d to RX BD 127 and from RX BD 0 to RX BD %0d respectively",
|
| 12797 |
|
|
tmp_bd, num_of_bd);
|
| 12798 |
|
|
else
|
| 12799 |
|
|
$display(" ->packets were received from RX BD %0d to RX BD %0d respectively",
|
| 12800 |
|
|
tmp_bd, num_of_bd);
|
| 12801 |
|
|
tmp_bd = num_of_bd + 1;
|
| 12802 |
|
|
// reset receive small, remain the rest
|
| 12803 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 12804 |
209 |
tadejm |
wbm_write(`ETH_MODER, `ETH_MODER_RXEN | `ETH_MODER_FULLD | `ETH_MODER_IFG |
|
| 12805 |
|
|
`ETH_MODER_PRO | `ETH_MODER_BRO,
|
| 12806 |
|
|
4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 12807 |
|
|
end
|
| 12808 |
|
|
else if ((i_length + 4) == max_tmp)
|
| 12809 |
|
|
begin
|
| 12810 |
|
|
$display(" receive small packets is NOT selected");
|
| 12811 |
|
|
$display(" using all 128 BDs assigned to RX (wrap at 128th BD - RX BD 127)");
|
| 12812 |
|
|
$display(" ->packets with lengths from %0d to %0d (MAXFL) are checked (length increasing by 1 byte)",
|
| 12813 |
|
|
(max_tmp - (4 + 16)), max_tmp);
|
| 12814 |
|
|
if (tmp_bd > num_of_bd)
|
| 12815 |
|
|
$display(" ->packets were received from RX BD %0d to RX BD 127 and from RX BD 0 to RX BD %0d respectively",
|
| 12816 |
|
|
tmp_bd, num_of_bd);
|
| 12817 |
|
|
else
|
| 12818 |
|
|
$display(" ->packets were received from RX BD %0d to RX BD %0d respectively",
|
| 12819 |
|
|
tmp_bd, num_of_bd);
|
| 12820 |
|
|
end
|
| 12821 |
|
|
// set length (loop variable)
|
| 12822 |
|
|
if ((i_length + 4) < (min_tmp + 128))
|
| 12823 |
|
|
i_length = i_length + 1;
|
| 12824 |
|
|
else if ( ((i_length + 4) == (min_tmp + 128)) && ((i_length + 4) <= (max_tmp - 256)) )
|
| 12825 |
|
|
i_length = 256;
|
| 12826 |
|
|
else if ( ((i_length + 4) > (min_tmp + 128)) && ((i_length + 4) <= (max_tmp - 256)) )
|
| 12827 |
|
|
begin
|
| 12828 |
|
|
i_length = i_length + 128;
|
| 12829 |
|
|
tmp_data = i_length + 4; // last tmp_data is ending length
|
| 12830 |
|
|
end
|
| 12831 |
|
|
else if ( ((i_length + 4) > (max_tmp - 256)) && ((i_length + 4) < (max_tmp - 16)) )
|
| 12832 |
|
|
i_length = max_tmp - (4 + 16);
|
| 12833 |
|
|
else if ((i_length + 4) >= (max_tmp - 16))
|
| 12834 |
|
|
i_length = i_length + 1;
|
| 12835 |
|
|
else
|
| 12836 |
|
|
begin
|
| 12837 |
|
|
$display("*E TESTBENCH ERROR - WRONG PARAMETERS IN TESTBENCH");
|
| 12838 |
|
|
#10 $stop;
|
| 12839 |
|
|
end
|
| 12840 |
|
|
// the number of frame transmitted
|
| 12841 |
|
|
num_of_frames = num_of_frames + 1;
|
| 12842 |
|
|
if ((num_of_frames <= 8) || ((num_of_frames - 8) == 128))
|
| 12843 |
|
|
num_of_bd = 0;
|
| 12844 |
|
|
else
|
| 12845 |
|
|
num_of_bd = num_of_bd + 1;
|
| 12846 |
|
|
end
|
| 12847 |
|
|
// disable RX
|
| 12848 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 12849 |
209 |
tadejm |
wbm_write(`ETH_MODER, `ETH_MODER_FULLD | `ETH_MODER_RECSMALL | `ETH_MODER_IFG |
|
| 12850 |
|
|
`ETH_MODER_PRO | `ETH_MODER_BRO,
|
| 12851 |
|
|
4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 12852 |
|
|
@(posedge wb_clk);
|
| 12853 |
|
|
if(fail == 0)
|
| 12854 |
|
|
test_ok;
|
| 12855 |
|
|
else
|
| 12856 |
|
|
fail = 0;
|
| 12857 |
|
|
end
|
| 12858 |
|
|
|
| 12859 |
|
|
|
| 12860 |
|
|
////////////////////////////////////////////////////////////////////
|
| 12861 |
|
|
//// ////
|
| 12862 |
|
|
//// Test receive packets form MINFL to MAXFL sizes at ////
|
| 12863 |
|
|
//// maximum RX buffer decriptors ( 100Mbps ). ////
|
| 12864 |
|
|
//// ////
|
| 12865 |
|
|
////////////////////////////////////////////////////////////////////
|
| 12866 |
243 |
tadejm |
if (test_num == 7) //
|
| 12867 |
209 |
tadejm |
begin
|
| 12868 |
243 |
tadejm |
// TEST 7: RECEIVE PACKETS FROM MINFL TO MAXFL SIZES AT MAX RX BDs ( 100Mbps )
|
| 12869 |
|
|
test_name = "TEST 7: RECEIVE PACKETS FROM MINFL TO MAXFL SIZES AT MAX RX BDs ( 100Mbps )";
|
| 12870 |
|
|
`TIME; $display(" TEST 7: RECEIVE PACKETS FROM MINFL TO MAXFL SIZES AT MAX RX BDs ( 100Mbps )");
|
| 12871 |
209 |
tadejm |
|
| 12872 |
|
|
// reset MAC registers
|
| 12873 |
|
|
hard_reset;
|
| 12874 |
|
|
// reset MAC and MII LOGIC with soft reset
|
| 12875 |
274 |
tadejm |
// reset_mac;
|
| 12876 |
|
|
// reset_mii;
|
| 12877 |
209 |
tadejm |
// set wb slave response
|
| 12878 |
|
|
wb_slave.cycle_response(`ACK_RESPONSE, wbs_waits, wbs_retries);
|
| 12879 |
|
|
|
| 12880 |
|
|
max_tmp = 0;
|
| 12881 |
|
|
min_tmp = 0;
|
| 12882 |
|
|
num_of_frames = 0;
|
| 12883 |
|
|
num_of_bd = 0;
|
| 12884 |
|
|
// set maximum RX buffer descriptors (128) - must be set before RX enable
|
| 12885 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 12886 |
209 |
tadejm |
wbm_write(`ETH_TX_BD_NUM, 32'h0, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 12887 |
|
|
// enable RX, set full-duplex mode, NO receive small, NO correct IFG
|
| 12888 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 12889 |
209 |
tadejm |
wbm_write(`ETH_MODER, `ETH_MODER_RXEN | `ETH_MODER_FULLD | `ETH_MODER_IFG |
|
| 12890 |
|
|
`ETH_MODER_PRO | `ETH_MODER_BRO,
|
| 12891 |
|
|
4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 12892 |
|
|
// prepare two packets of MAXFL length
|
| 12893 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 12894 |
209 |
tadejm |
wbm_read(`ETH_PACKETLEN, tmp, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 12895 |
|
|
max_tmp = tmp[15:0]; // 18 bytes consists of 6B dest addr, 6B source addr, 2B type/len, 4B CRC
|
| 12896 |
|
|
min_tmp = tmp[31:16];
|
| 12897 |
|
|
st_data = 8'hAC;
|
| 12898 |
|
|
set_rx_packet(0, (max_tmp - 4), 1'b0, 48'h0102_0304_0506, 48'h0708_090A_0B0C, 16'h0D0E, st_data); // length without CRC
|
| 12899 |
|
|
st_data = 8'h35;
|
| 12900 |
|
|
set_rx_packet((max_tmp), (max_tmp - 4), 1'b0, 48'h1234_5678_8765, 48'hA1B2_C3D4_E5F6, 16'hE77E, st_data);
|
| 12901 |
|
|
// check WB INT signal
|
| 12902 |
|
|
if (wb_int !== 1'b0)
|
| 12903 |
|
|
begin
|
| 12904 |
|
|
test_fail("WB INT signal should not be set");
|
| 12905 |
|
|
fail = fail + 1;
|
| 12906 |
|
|
end
|
| 12907 |
|
|
|
| 12908 |
|
|
// write to phy's control register for 100Mbps
|
| 12909 |
|
|
#Tp eth_phy.control_bit14_10 = 5'b01000; // bit 13 set - speed 100
|
| 12910 |
|
|
#Tp eth_phy.control_bit8_0 = 9'h1_00; // bit 6 reset - (10/100), bit 8 set - FD
|
| 12911 |
|
|
speed = 100;
|
| 12912 |
|
|
|
| 12913 |
|
|
i_length = (min_tmp - 4);
|
| 12914 |
|
|
while (i_length <= (max_tmp - 4))
|
| 12915 |
|
|
begin
|
| 12916 |
|
|
// append CRC to packet
|
| 12917 |
|
|
if (i_length[0] == 1'b0)
|
| 12918 |
|
|
append_rx_crc (0, i_length, 1'b0, 1'b0);
|
| 12919 |
|
|
else
|
| 12920 |
|
|
append_rx_crc (max_tmp, i_length, 1'b0, 1'b0);
|
| 12921 |
|
|
// choose generating carrier sense and collision
|
| 12922 |
|
|
case (i_length[1:0])
|
| 12923 |
|
|
2'h0: // Interrupt is generated
|
| 12924 |
|
|
begin
|
| 12925 |
|
|
// Reset_tx_bd nable interrupt generation
|
| 12926 |
|
|
// unmask interrupts
|
| 12927 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 12928 |
209 |
tadejm |
wbm_write(`ETH_INT_MASK, `ETH_INT_TXB | `ETH_INT_TXE | `ETH_INT_RXB | `ETH_INT_RXE | `ETH_INT_BUSY |
|
| 12929 |
|
|
`ETH_INT_TXC | `ETH_INT_RXC, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 12930 |
|
|
// not detect carrier sense in FD and no collision
|
| 12931 |
|
|
eth_phy.no_carrier_sense_rx_fd_detect(0);
|
| 12932 |
|
|
eth_phy.collision(0);
|
| 12933 |
|
|
end
|
| 12934 |
|
|
2'h1: // Interrupt is not generated
|
| 12935 |
|
|
begin
|
| 12936 |
|
|
// set_tx_bd enable interrupt generation
|
| 12937 |
|
|
// mask interrupts
|
| 12938 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 12939 |
209 |
tadejm |
wbm_write(`ETH_INT_MASK, 32'h0, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 12940 |
|
|
// detect carrier sense in FD and no collision
|
| 12941 |
|
|
eth_phy.no_carrier_sense_rx_fd_detect(1);
|
| 12942 |
|
|
eth_phy.collision(0);
|
| 12943 |
|
|
end
|
| 12944 |
|
|
2'h2: // Interrupt is not generated
|
| 12945 |
|
|
begin
|
| 12946 |
|
|
// set_tx_bd disable the interrupt generation
|
| 12947 |
|
|
// unmask interrupts
|
| 12948 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 12949 |
209 |
tadejm |
wbm_write(`ETH_INT_MASK, `ETH_INT_TXB | `ETH_INT_TXE | `ETH_INT_RXB | `ETH_INT_RXE | `ETH_INT_BUSY |
|
| 12950 |
|
|
`ETH_INT_TXC | `ETH_INT_RXC, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 12951 |
|
|
// not detect carrier sense in FD and set collision
|
| 12952 |
|
|
eth_phy.no_carrier_sense_rx_fd_detect(0);
|
| 12953 |
|
|
eth_phy.collision(1);
|
| 12954 |
|
|
end
|
| 12955 |
|
|
default: // 2'h3: // Interrupt is not generated
|
| 12956 |
|
|
begin
|
| 12957 |
|
|
// set_tx_bd disable the interrupt generation
|
| 12958 |
|
|
// mask interrupts
|
| 12959 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 12960 |
209 |
tadejm |
wbm_write(`ETH_INT_MASK, 32'h0, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 12961 |
|
|
// detect carrier sense in FD and set collision
|
| 12962 |
|
|
eth_phy.no_carrier_sense_rx_fd_detect(1);
|
| 12963 |
|
|
eth_phy.collision(1);
|
| 12964 |
|
|
end
|
| 12965 |
|
|
endcase
|
| 12966 |
|
|
// first 8 frames are received with RX BD 0 (wrap bit on RX BD 0)
|
| 12967 |
|
|
// number of all frames is 154 (146 without first 8)
|
| 12968 |
|
|
if (num_of_frames < 8)
|
| 12969 |
|
|
begin
|
| 12970 |
|
|
case (i_length[1:0])
|
| 12971 |
|
|
2'h0: // Interrupt is generated
|
| 12972 |
|
|
begin
|
| 12973 |
|
|
// enable interrupt generation
|
| 12974 |
|
|
set_rx_bd(0, 0, 1'b1, (`MEMORY_BASE + i_length[1:0]));
|
| 12975 |
|
|
// interrupts are unmasked
|
| 12976 |
|
|
end
|
| 12977 |
|
|
2'h1: // Interrupt is not generated
|
| 12978 |
|
|
begin
|
| 12979 |
|
|
// enable interrupt generation
|
| 12980 |
|
|
set_rx_bd(0, 0, 1'b1, ((`MEMORY_BASE + i_length[1:0]) + max_tmp));
|
| 12981 |
|
|
// interrupts are masked
|
| 12982 |
|
|
end
|
| 12983 |
|
|
2'h2: // Interrupt is not generated
|
| 12984 |
|
|
begin
|
| 12985 |
|
|
// disable interrupt generation
|
| 12986 |
|
|
set_rx_bd(0, 0, 1'b0, (`MEMORY_BASE + i_length[1:0]));
|
| 12987 |
|
|
// interrupts are unmasked
|
| 12988 |
|
|
end
|
| 12989 |
|
|
default: // 2'h3: // Interrupt is not generated
|
| 12990 |
|
|
begin
|
| 12991 |
|
|
// disable interrupt generation
|
| 12992 |
|
|
set_rx_bd(0, 0, 1'b0, ((`MEMORY_BASE + i_length[1:0]) + max_tmp));
|
| 12993 |
|
|
// interrupts are masked
|
| 12994 |
|
|
end
|
| 12995 |
|
|
endcase
|
| 12996 |
|
|
// set wrap bit
|
| 12997 |
|
|
set_rx_bd_wrap(0);
|
| 12998 |
|
|
end
|
| 12999 |
|
|
// after first 8 number of frames, 128 frames form RX BD 0 to 127 will be received
|
| 13000 |
|
|
else if ((num_of_frames - 8) == 0)
|
| 13001 |
|
|
begin
|
| 13002 |
|
|
tmp_len = i_length; // length of frame
|
| 13003 |
|
|
tmp_bd_num = 0; // RX BD number
|
| 13004 |
|
|
while (tmp_bd_num < 128) // (tmp_len <= (max_tmp - 4)) - this is the last frame
|
| 13005 |
|
|
begin
|
| 13006 |
|
|
// if i_length[1] == 0 then enable interrupt generation otherwise disable it
|
| 13007 |
|
|
// if i_length[0] == 0 then base address is `MEMORY_BASE otherwise it is `MEMORY_BASE + max_tmp
|
| 13008 |
|
|
if (tmp_len[0] == 0)
|
| 13009 |
|
|
set_rx_bd(tmp_bd_num, tmp_bd_num, !tmp_len[1], (`MEMORY_BASE + tmp_len[1:0]));
|
| 13010 |
|
|
else
|
| 13011 |
|
|
set_rx_bd(tmp_bd_num, tmp_bd_num, !tmp_len[1], ((`MEMORY_BASE + tmp_len[1:0]) + max_tmp));
|
| 13012 |
|
|
// set length (loop variable) - THE SAME AS AT THE END OF THIS TASK !!!
|
| 13013 |
|
|
if ((tmp_len + 4) < (min_tmp + 128))
|
| 13014 |
|
|
tmp_len = tmp_len + 1;
|
| 13015 |
|
|
else if ( ((tmp_len + 4) == (min_tmp + 128)) && ((tmp_len + 4) <= (max_tmp - 256)) )
|
| 13016 |
|
|
tmp_len = 256;
|
| 13017 |
|
|
else if ( ((tmp_len + 4) > (min_tmp + 128)) && ((tmp_len + 4) <= (max_tmp - 256)) )
|
| 13018 |
|
|
tmp_len = tmp_len + 128;
|
| 13019 |
|
|
else if ( ((tmp_len + 4) > (max_tmp - 256)) && ((tmp_len + 4) < (max_tmp - 16)) )
|
| 13020 |
|
|
tmp_len = max_tmp - (4 + 16);
|
| 13021 |
|
|
else if ((tmp_len + 4) >= (max_tmp - 16))
|
| 13022 |
|
|
tmp_len = tmp_len + 1;
|
| 13023 |
|
|
// set RX BD number
|
| 13024 |
|
|
tmp_bd_num = tmp_bd_num + 1;
|
| 13025 |
|
|
end
|
| 13026 |
|
|
// set wrap bit
|
| 13027 |
|
|
set_rx_bd_wrap(127);
|
| 13028 |
|
|
end
|
| 13029 |
|
|
// after 128 + first 8 number of frames, 19 frames form RX BD 0 to 18 will be received
|
| 13030 |
|
|
else if ((num_of_frames - 8) == 20) // 128
|
| 13031 |
|
|
begin
|
| 13032 |
|
|
tmp_len = tmp_len; // length of frame remaines from previous settings
|
| 13033 |
|
|
tmp_bd_num = 0; // TX BD number
|
| 13034 |
|
|
while (tmp_bd_num < 19) // (tmp_len <= (max_tmp - 4)) - this is the last frame
|
| 13035 |
|
|
begin
|
| 13036 |
|
|
// if i_length[1] == 0 then enable interrupt generation otherwise disable it
|
| 13037 |
|
|
// if i_length[0] == 0 then base address is `MEMORY_BASE otherwise it is `MEMORY_BASE + max_tmp
|
| 13038 |
|
|
if (tmp_len[0] == 0)
|
| 13039 |
|
|
set_rx_bd(tmp_bd_num, tmp_bd_num, !tmp_len[1], (`MEMORY_BASE + tmp_len[1:0]));
|
| 13040 |
|
|
else
|
| 13041 |
|
|
set_rx_bd(tmp_bd_num, tmp_bd_num, !tmp_len[1], ((`MEMORY_BASE + tmp_len[1:0]) + max_tmp));
|
| 13042 |
|
|
// set length (loop variable) - THE SAME AS AT THE END OF THIS TASK !!!
|
| 13043 |
|
|
if ((tmp_len + 4) < (min_tmp + 128))
|
| 13044 |
|
|
tmp_len = tmp_len + 1;
|
| 13045 |
|
|
else if ( ((tmp_len + 4) == (min_tmp + 128)) && ((tmp_len + 4) <= (max_tmp - 256)) )
|
| 13046 |
|
|
tmp_len = 256;
|
| 13047 |
|
|
else if ( ((tmp_len + 4) > (min_tmp + 128)) && ((tmp_len + 4) <= (max_tmp - 256)) )
|
| 13048 |
|
|
tmp_len = tmp_len + 128;
|
| 13049 |
|
|
else if ( ((tmp_len + 4) > (max_tmp - 256)) && ((tmp_len + 4) < (max_tmp - 16)) )
|
| 13050 |
|
|
tmp_len = max_tmp - (4 + 16);
|
| 13051 |
|
|
else if ((tmp_len + 4) >= (max_tmp - 16))
|
| 13052 |
|
|
tmp_len = tmp_len + 1;
|
| 13053 |
|
|
// set TX BD number
|
| 13054 |
|
|
tmp_bd_num = tmp_bd_num + 1;
|
| 13055 |
|
|
end
|
| 13056 |
|
|
end
|
| 13057 |
|
|
// set empty bit
|
| 13058 |
|
|
if (num_of_frames < 8)
|
| 13059 |
|
|
set_rx_bd_empty(0, 0);
|
| 13060 |
|
|
else if ((num_of_frames - 8) < 128)
|
| 13061 |
|
|
set_rx_bd_empty((num_of_frames - 8), (num_of_frames - 8));
|
| 13062 |
|
|
else if ((num_of_frames - 136) < 19)
|
| 13063 |
|
|
set_rx_bd_empty((num_of_frames - 136), (num_of_frames - 136));
|
| 13064 |
|
|
// CHECK END OF RECEIVE
|
| 13065 |
|
|
fork
|
| 13066 |
|
|
begin
|
| 13067 |
|
|
if (i_length[0] == 1'b0)
|
| 13068 |
|
|
#1 eth_phy.send_rx_packet(64'h0055_5555_5555_5555, 4'h7, 8'hD5, 0, (i_length + 4), 1'b0);
|
| 13069 |
|
|
else
|
| 13070 |
|
|
#1 eth_phy.send_rx_packet(64'h0055_5555_5555_5555, 4'h7, 8'hD5, max_tmp, (i_length + 4), 1'b0);
|
| 13071 |
|
|
repeat(10) @(posedge mrx_clk);
|
| 13072 |
|
|
end
|
| 13073 |
|
|
begin
|
| 13074 |
|
|
#1 check_rx_bd(num_of_bd, data);
|
| 13075 |
|
|
if (i_length < min_tmp) // just first four
|
| 13076 |
|
|
begin
|
| 13077 |
|
|
while (data[15] === 1)
|
| 13078 |
|
|
begin
|
| 13079 |
|
|
#1 check_rx_bd(num_of_bd, data);
|
| 13080 |
|
|
@(posedge wb_clk);
|
| 13081 |
|
|
end
|
| 13082 |
|
|
repeat (1) @(posedge wb_clk);
|
| 13083 |
|
|
end
|
| 13084 |
|
|
else
|
| 13085 |
|
|
begin
|
| 13086 |
|
|
wait (MRxDV === 1'b1); // start transmit
|
| 13087 |
|
|
#1 check_rx_bd(num_of_bd, data);
|
| 13088 |
|
|
if (data[15] !== 1)
|
| 13089 |
|
|
begin
|
| 13090 |
|
|
test_fail("Wrong buffer descriptor's ready bit read out from MAC");
|
| 13091 |
|
|
fail = fail + 1;
|
| 13092 |
|
|
end
|
| 13093 |
|
|
wait (MRxDV === 1'b0); // end transmit
|
| 13094 |
|
|
while (data[15] === 1)
|
| 13095 |
|
|
begin
|
| 13096 |
|
|
#1 check_rx_bd(num_of_bd, data);
|
| 13097 |
|
|
@(posedge wb_clk);
|
| 13098 |
|
|
end
|
| 13099 |
|
|
repeat (1) @(posedge wb_clk);
|
| 13100 |
|
|
end
|
| 13101 |
|
|
end
|
| 13102 |
|
|
join
|
| 13103 |
|
|
// check length of a PACKET
|
| 13104 |
|
|
if (data[31:16] != (i_length + 4))
|
| 13105 |
|
|
begin
|
| 13106 |
|
|
`TIME; $display("*E Wrong length of the packet out from PHY (%0d instead of %0d)",
|
| 13107 |
|
|
data[31:16], (i_length + 4));
|
| 13108 |
|
|
test_fail("Wrong length of the packet out from PHY");
|
| 13109 |
|
|
fail = fail + 1;
|
| 13110 |
|
|
end
|
| 13111 |
|
|
// check received RX packet data and CRC
|
| 13112 |
|
|
if (i_length[0] == 1'b0)
|
| 13113 |
|
|
begin
|
| 13114 |
|
|
check_rx_packet(0, (`MEMORY_BASE + i_length[1:0]), (i_length + 4), 1'b0, 1'b0, tmp);
|
| 13115 |
|
|
end
|
| 13116 |
|
|
else
|
| 13117 |
|
|
begin
|
| 13118 |
|
|
check_rx_packet(max_tmp, ((`MEMORY_BASE + i_length[1:0]) + max_tmp), (i_length + 4), 1'b0, 1'b0, tmp);
|
| 13119 |
|
|
end
|
| 13120 |
|
|
if (tmp > 0)
|
| 13121 |
|
|
begin
|
| 13122 |
|
|
`TIME; $display("*E Wrong data of the received packet");
|
| 13123 |
|
|
test_fail("Wrong data of the received packet");
|
| 13124 |
|
|
fail = fail + 1;
|
| 13125 |
|
|
end
|
| 13126 |
|
|
// check WB INT signal
|
| 13127 |
|
|
if (i_length[1:0] == 2'h0)
|
| 13128 |
|
|
begin
|
| 13129 |
|
|
if (wb_int !== 1'b1)
|
| 13130 |
|
|
begin
|
| 13131 |
|
|
`TIME; $display("*E WB INT signal should be set");
|
| 13132 |
|
|
test_fail("WB INT signal should be set");
|
| 13133 |
|
|
fail = fail + 1;
|
| 13134 |
|
|
end
|
| 13135 |
|
|
end
|
| 13136 |
|
|
else
|
| 13137 |
|
|
begin
|
| 13138 |
|
|
if (wb_int !== 1'b0)
|
| 13139 |
|
|
begin
|
| 13140 |
|
|
`TIME; $display("*E WB INT signal should not be set");
|
| 13141 |
|
|
test_fail("WB INT signal should not be set");
|
| 13142 |
|
|
fail = fail + 1;
|
| 13143 |
|
|
end
|
| 13144 |
|
|
end
|
| 13145 |
|
|
// check RX buffer descriptor of a packet
|
| 13146 |
|
|
check_rx_bd(num_of_bd, data);
|
| 13147 |
|
|
if (i_length[1] == 1'b0) // interrupt enabled
|
| 13148 |
|
|
begin
|
| 13149 |
|
|
if ( ((data[15:0] !== 16'h6000) && ((num_of_frames < 8) || ((num_of_frames - 8) == 127))) || // wrap bit
|
| 13150 |
|
|
((data[15:0] !== 16'h4000) && (num_of_frames >= 8) && ((num_of_frames - 8) != 127)) ) // without wrap bit
|
| 13151 |
|
|
begin
|
| 13152 |
|
|
`TIME; $display("*E RX buffer descriptor status is not correct: %0h", data[15:0]);
|
| 13153 |
|
|
test_fail("RX buffer descriptor status is not correct");
|
| 13154 |
|
|
fail = fail + 1;
|
| 13155 |
|
|
end
|
| 13156 |
|
|
end
|
| 13157 |
|
|
else // interrupt not enabled
|
| 13158 |
|
|
begin
|
| 13159 |
|
|
if ( ((data[15:0] !== 16'h2000) && ((num_of_frames < 8) || ((num_of_frames - 8) == 127))) || // wrap bit
|
| 13160 |
|
|
((data[15:0] !== 16'h0000) && (num_of_frames >= 8) && ((num_of_frames - 8) != 127)) ) // without wrap bit
|
| 13161 |
|
|
begin
|
| 13162 |
|
|
`TIME; $display("*E RX buffer descriptor status is not correct: %0h", data[15:0]);
|
| 13163 |
|
|
test_fail("RX buffer descriptor status is not correct");
|
| 13164 |
|
|
fail = fail + 1;
|
| 13165 |
|
|
end
|
| 13166 |
|
|
end
|
| 13167 |
|
|
// clear first half of 8 frames from RX buffer descriptor 0
|
| 13168 |
|
|
if (num_of_frames < 4)
|
| 13169 |
|
|
clear_rx_bd(num_of_bd, num_of_bd);
|
| 13170 |
|
|
// clear BD with wrap bit
|
| 13171 |
|
|
if (num_of_frames == 140)
|
| 13172 |
|
|
clear_rx_bd(127, 127);
|
| 13173 |
|
|
// check interrupts
|
| 13174 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 13175 |
209 |
tadejm |
wbm_read(`ETH_INT, data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 13176 |
|
|
if ((i_length[1:0] == 2'h0) || (i_length[1:0] == 2'h1))
|
| 13177 |
|
|
begin
|
| 13178 |
|
|
if ((data & `ETH_INT_RXB) !== `ETH_INT_RXB)
|
| 13179 |
|
|
begin
|
| 13180 |
|
|
`TIME; $display("*E Interrupt Receive Buffer was not set, interrupt reg: %0h", data);
|
| 13181 |
|
|
test_fail("Interrupt Receive Buffer was not set");
|
| 13182 |
|
|
fail = fail + 1;
|
| 13183 |
|
|
end
|
| 13184 |
|
|
if ((data & (~`ETH_INT_RXB)) !== 0)
|
| 13185 |
|
|
begin
|
| 13186 |
|
|
`TIME; $display("*E Other interrupts (except Receive Buffer) were set, interrupt reg: %0h", data);
|
| 13187 |
|
|
test_fail("Other interrupts (except Receive Buffer) were set");
|
| 13188 |
|
|
fail = fail + 1;
|
| 13189 |
|
|
end
|
| 13190 |
|
|
end
|
| 13191 |
|
|
else
|
| 13192 |
|
|
begin
|
| 13193 |
|
|
if (data !== 0)
|
| 13194 |
|
|
begin
|
| 13195 |
|
|
`TIME; $display("*E Any of interrupts (except Receive Buffer) was set, interrupt reg: %0h, len: %0h", data, i_length[1:0]);
|
| 13196 |
|
|
test_fail("Any of interrupts (except Receive Buffer) was set");
|
| 13197 |
|
|
fail = fail + 1;
|
| 13198 |
|
|
end
|
| 13199 |
|
|
end
|
| 13200 |
|
|
// clear interrupts
|
| 13201 |
274 |
tadejm |
wait (wbm_working == 0);
|
| 13202 |
209 |
tadejm |
wbm_write(`ETH_INT, data, 4'hF, 1, wbm_init_waits, wbm_subseq_waits);
|
| 13203 |
|
|
// check WB INT signal
|
| 13204 |
|
|
if (wb_int !== 1'b0)
|
| 13205 |
|
|
begin
|
| 13206 |
|
|
test_fail("WB INT signal should not be set");
|
| 13207 |
|
|
fail = fail + 1;
|
| 13208 |
|
|
end
|
| 13209 |
|
|
// INTERMEDIATE DISPLAYS
|
| 13210 |
|
|
if ((i_length + 4) == (min_tmp + 7))
|
| 13211 |
|
|
begin
|
| 13212 |
|
|
// starting length is min_tmp, ending length is (min_tmp + 128)
|
| 13213 |
|
|
$display(" receive small packets is NOT selected");
|
| 13214 |
|
|
$display(" using only RX BD 0 out of 128 BDs assigned to RX (wrap at first BD - RX BD 0)");
|
| 13215 |
|
|
$display(" ->packets with lengths from %0d (MINFL) to %0d are checked (length increasing by 1 byte)",
|
| 13216 |
|
|
min_tmp, (min_tmp + 7));
|
| 13217 |
|
|
$display(" ->all packets were received on RX BD 0");
|
| 13218 |
|
|
// reset receive small, remain the rest
|
| 13219 |
274 |
tadejm |
wait
|