////////////////////////////////////////////////////////////////////// //// //// //// Ethernet MAC Stimulus //// //// //// //// Description //// //// Ethernet MAC stimulus tasks. Taken from the project //// //// testbench in the ethmac core. //// //// //// //// To Do: //// //// //// //// //// //// Author(s): //// //// - Tadej Markovic, tadej@opencores.org //// //// - Igor Mohor, igorM@opencores.org //// //// - Julius Baxter julius.baxter@orsoc.se //// //// //// //// //// ////////////////////////////////////////////////////////////////////// //// //// //// Copyright (C) 2009 Authors and OPENCORES.ORG //// //// //// //// This source file may be used and distributed without //// //// restriction provided that this copyright statement is not //// //// removed from the file and that any derivative work contains //// //// the original copyright notice and the associated disclaimer. //// //// //// //// This source file is free software; you can redistribute it //// //// and/or modify it under the terms of the GNU Lesser General //// //// Public License as published by the Free Software Foundation; //// //// either version 2.1 of the License, or (at your option) any //// //// later version. //// //// //// //// This source is distributed in the hope that it will be //// //// useful, but WITHOUT ANY WARRANTY; without even the implied //// //// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR //// //// PURPOSE. See the GNU Lesser General Public License for more //// //// details. //// //// //// //// You should have received a copy of the GNU Lesser General //// //// Public License along with this source; if not, download it //// //// from http://www.opencores.org/lgpl.shtml //// //// //// ////////////////////////////////////////////////////////////////////// `define TIME $display("Time: %0t", $time) // Defines for ethernet test to trigger sending/receiving // Is straight forward when using RTL design, but if using netlist then paths to // the RX/TX enabled bits depend on synthesis tool, etc, but ones here appear to // work with design put through Synplify, with hierarchy maintained. `define ETH_TOP dut.ethmac0 `define ETH_BD_RAM_PATH `ETH_TOP.wishbone.bd_ram `define ETH_MODER_PATH `ETH_TOP.ethreg1.MODER_0 `ifdef RTL_SIM `ifdef ethmac_IS_GATELEVEL `define ETH_MODER_TXEN_BIT `ETH_MODER_PATH.r_TxEn; `define ETH_MODER_RXEN_BIT `ETH_MODER_PATH.r_RxEn; `else `define ETH_MODER_TXEN_BIT `ETH_MODER_PATH.DataOut[1]; `define ETH_MODER_RXEN_BIT `ETH_MODER_PATH.DataOut[0]; `endif `endif `ifdef GATE_SIM `define ETH_MODER_TXEN_BIT `ETH_MODER_PATH.r_TxEn; `define ETH_MODER_RXEN_BIT `ETH_MODER_PATH.r_RxEn; `endif reg [15:0] eth_stim_rx_packet_length; reg [7:0] st_data; reg [31:0] lfsr; integer lfsr_last_byte; // Is number of ethernet packets to send if doing the eth-rx test. parameter eth_stim_num_rx_only_num_packets = 500; // Set to 0 for continuous RX parameter eth_stim_num_rx_only_packet_size = 512; parameter eth_stim_num_rx_only_packet_size_change = 2'b01; // 2'b01: Increment parameter eth_stim_num_rx_only_packet_size_change_amount = 1; parameter eth_stim_num_rx_only_IPG = 800000; // ns // Do call/response test reg eth_stim_do_rx_reponse_to_tx; parameter num_tx_bds = 16; parameter num_tx_bds_mask = 4'hf; parameter num_rx_bds = 16; parameter num_rx_bds_mask = 4'hf; parameter max_eth_packet_size = 16'h0600; // If running eth-rxtxbig test (sending and receiving maximum packets), then // set this parameter to the max packet size, otherwise min packet size //parameter rx_while_tx_min_packet_size = max_eth_packet_size; parameter rx_while_tx_min_packet_size = 32; // Use the smallest possible IPG parameter eth_stim_use_min_IPG = 0; parameter eth_stim_IPG_delay_max = 500_000; // Maximum 500uS ga //parameter eth_stim_IPG_delay_max = 100_000_000; // Maximum 100mS between packets parameter eth_stim_IPG_min_10mb = 9600; // 9.6 uS parameter eth_stim_IPG_min_100mb = 800; // 860+~100 = 960 nS 100MBit min IPG parameter eth_stim_check_rx_packet_contents = 1; parameter eth_stim_check_tx_packet_contents = 1; parameter eth_inject_errors = 0; // When running simulations where you don't want to feed packets to the design // like this... parameter eth_stim_disable_rx_stim = 0; // Delay between seeing that the buffer descriptor for an RX packet says it's // been received and ending up in the memory. // For 25MHz sdram controller, use following: //parameter Td_rx_packet_check = (`BOARD_CLOCK_PERIOD * 2000); // For 64MHz sdram controller, use following: parameter Td_rx_packet_check = (`BOARD_CLOCK_PERIOD * 500); integer expected_rxbd;// init to 0 integer expected_txbd; wire ethmac_rxen; wire ethmac_txen; assign ethmac_rxen = eth_stim_disable_rx_stim ? 0 : `ETH_MODER_RXEN_BIT; assign ethmac_txen = `ETH_MODER_TXEN_BIT; integer eth_rx_num_packets_sent = 0; integer eth_rx_num_packets_checked = 0; integer num_tx_packets = 1; integer rx_packet_lengths [0:1023]; // Array of packet lengths integer speed_loop; // When txen is (re)enabled, the tx bd pointer goes back to 0 always @(posedge ethmac_txen) expected_txbd = 0; reg eth_stim_waiting; initial begin #1; //lfsr = 32'h84218421; // Init pseudo lfsr lfsr = 32'h00700001; // Init pseudo lfsr lfsr_last_byte = 0; eth_stim_waiting = 1; expected_rxbd = num_tx_bds; // init this here eth_stim_do_rx_reponse_to_tx = 0; while (eth_stim_waiting) // Loop, waiting for enabling of MAC by software begin #100; // If RX enable and not TX enable... if(ethmac_rxen === 1'b1 & !(ethmac_txen===1'b1)) begin if (eth_inject_errors) begin do_rx_only_stim(16, 64, 0, 0); do_rx_only_stim(128, 64, 1'b1, 8); do_rx_only_stim(256, 64, 1'b1, 4); eth_stim_waiting = 0; end else begin //do_rx_only_stim(eth_stim_num_rx_only_num_packets, //eth_stim_num_rx_only_packet_size, 0, 0); // Call packet send loop directly. No error injection. send_packet_loop(eth_stim_num_rx_only_num_packets, eth_stim_num_rx_only_packet_size, eth_stim_num_rx_only_packet_size_change, eth_stim_num_rx_only_packet_size_change_amount, eth_phy0.eth_speed, // Speed eth_stim_num_rx_only_IPG, // IPG 48'h0012_3456_789a, 48'h0708_090A_0B0C, 1, 0, 0); eth_stim_waiting = 0; end end // if (ethmac_rxen === 1'b1 & !(ethmac_txen===1'b1)) // If both RX and TX enabled else if (ethmac_rxen === 1'b1 & ethmac_txen===1'b1) begin // Both enabled - let's wait for the first packet transmitted // to see what stimulus we should provide while (num_tx_packets==1) #1000; $display("* ethmac RX/TX test request: %x", eth_phy0.tx_mem[0]); // Check the first received byte's value case (eth_phy0.tx_mem[0]) 0: begin // kickoff call/response here eth_stim_do_rx_reponse_to_tx = 1; end default: begin do_rx_while_tx_stim(1400); end endcase // case (eth_phy0.tx_mem[0]) eth_stim_waiting = 0; end end // while (eth_stim_waiting) end // initial begin // Main Ethernet RX testing stimulus task. // Sends a set of packets at both speeds task do_rx_only_stim; input [31:0] num_packets; input [31:0] start_packet_size; input inject_errors; input [31:0] inject_errors_mod; begin for(speed_loop=1;speed_loop<3;speed_loop=speed_loop+1) begin send_packet_loop(num_packets, start_packet_size, 2'b01, 1, speed_loop[0], 10000, 48'h0012_3456_789a, 48'h0708_090A_0B0C, 1, inject_errors, inject_errors_mod); end end endtask // do_rx_stim // Generate RX packets while there's TX going on // Sends a set of packets at both speeds task do_rx_while_tx_stim; input [31:0] num_packets; reg [31:0] IPG; // Inter-packet gap reg [31:0] packet_size; integer j; begin for(j=0;j eth_stim_IPG_delay_max) IPG = IPG / 2; end $display("do_rx_while_tx IPG = %0d", IPG); // Determine size of next packet: if (rx_while_tx_min_packet_size == max_eth_packet_size) // We want to transmit biggest packets possible, easy case packet_size = max_eth_packet_size - 4; else begin // Constrained random sized packets packet_size = $random; while (packet_size > (max_eth_packet_size-4)) packet_size = packet_size / 2; // Now divide by least significant bits of j packet_size = packet_size / {29'd0,j[1:0],1'b1}; if (packet_size < 60) packet_size = packet_size + 60; end $display("do_rx_while_tx packet_size = %0d", packet_size); send_packet_loop(1, packet_size, 2'b01, 1, eth_phy0.eth_speed, IPG, 48'h0012_3456_789a, 48'h0708_090A_0B0C, 1, 1'b0, 0); // If RX enable went low, wait for it go high again if (ethmac_rxen===1'b0) begin while (ethmac_rxen===1'b0) begin @(posedge ethmac_rxen); #10000; end // RX disabled and when re-enabled we reset the buffer descriptor number expected_rxbd = num_tx_bds; end end // for (j=0;j (max_eth_packet_size-4)) packet_size = packet_size / 2; if (packet_size < 60) packet_size = packet_size + 60; end $display("do_rx_response_to_tx packet_size = %0d", packet_size); send_packet_loop(1, packet_size, 2'b01, 1, eth_phy0.eth_speed, IPG, 48'h0012_3456_789a, 48'h0708_090A_0B0C, 1, 1'b0, 0); // If RX enable went low, wait for it go high again if (ethmac_rxen===1'b0) begin while (ethmac_rxen===1'b0) begin @(posedge ethmac_rxen); #10000; end // RX disabled and when re-enabled we reset the buffer // descriptor number expected_rxbd = num_tx_bds; end end endtask // do_rx_response_to_tx // // always@() to check the TX buffer descriptors // always @(posedge ethmac_txen) begin ethmac_last_txbd_lenstat = 0; eth_stim_tx_loop_keep_polling=1; // Wait on the TxBD Ready bit while(eth_stim_tx_loop_keep_polling) begin #10; get_bd_lenstat(expected_txbd, ethmac_txbd_lenstat); // Check if we've finished transmitting this BD if (!ethmac_txbd_lenstat[15] & ethmac_last_txbd_lenstat[15]) // Falling edge of TX BD Ready eth_stim_detected_packet_tx = 1; ethmac_last_txbd_lenstat = ethmac_txbd_lenstat; // If TX en goes low then exit if (!ethmac_txen) eth_stim_tx_loop_keep_polling = 0; else if (eth_stim_detected_packet_tx) begin // Wait until the eth_phy has finished receiving it while (eth_phy0.mtxen_i === 1'b1) #10; $display("(%t) Check TX packet: bd %d: 0x%h",$time, expected_txbd, ethmac_txbd_lenstat); // Check the TXBD, see if the packet transmitted OK if (ethmac_txbd_lenstat[8] | ethmac_txbd_lenstat[3]) begin // Error occured `TIME; $display("*E TX Error of packet %0d detected.", num_tx_packets); $display(" TX BD %0d = 0x%h", expected_txbd, ethmac_txbd_lenstat); if (ethmac_txbd_lenstat[8]) $display(" Underrun in MAC during TX"); if (ethmac_txbd_lenstat[3]) $display(" Retransmission limit hit"); $finish; end else begin // Packet was OK, let's compare the contents we // received with those that were meant to be transmitted if (eth_stim_check_tx_packet_contents) begin check_tx_packet(expected_txbd); expected_txbd = (expected_txbd + 1) & num_tx_bds_mask; num_tx_packets = num_tx_packets + 1; eth_stim_detected_packet_tx = 0; end end end end // while (eth_stim_tx_loop_keep_polling) end // always @ (posedge ethmac_txen) // // Check packet TX'd by MAC was good // task check_tx_packet; input [31:0] tx_bd_num; reg [31:0] tx_bd_addr; reg [7:0] phy_byte; reg [31:0] txpnt_wb; // Pointer in array to where data should be reg [24:0] txpnt_sdram; // Index in array of shorts for data in SDRAM // part reg [21:0] buffer; reg [7:0] sdram_byte; reg [31:0] tx_len_bd; integer i; integer failure; begin failure = 0; get_bd_lenstat(tx_bd_num, tx_len_bd); tx_len_bd = {15'd0,tx_len_bd[31:16]}; // Check, if length didn't have to be padded, that // amount transmitted was correct if ((tx_len_bd > 60)&(tx_len_bd != (eth_phy0.tx_len-4))) begin $display("*E TX packet sent length, %0d != length in TX BD, %0d", eth_phy0.tx_len-4, tx_len_bd); #100; $finish; end get_bd_addr(tx_bd_num, tx_bd_addr); // We're never going to be using more than about 256K of receive buffer // so let's lop off the top bit of the address pointer - we only want // the offset from the base of the memory bank txpnt_wb = {14'd0,tx_bd_addr[17:0]}; txpnt_sdram = tx_bd_addr[24:0]; // Variable we'll use for index in the PHY's TX buffer buffer = 0; // Start of TX data `ifdef VERSATILE_SDRAM for (i=0;i 32)) length = length - length_change_size; // Increment error type if (error_this_time) error_type = error_type + 1; if (error_type > 3) error_type = 0; // Check if we should put in an error this time if (j%random_error_mod == 0) error_this_time = 1; else error_this_time = 0; eth_phy0.rx_err(0); // Now wait to check if we have filled up all the RX BDs and // the this packet would start writing over them. Only really an // issue when doing minimum IPG tests. while(((eth_rx_num_packets_sent+1) - eth_rx_num_packets_checked) == num_rx_bds) #100; end // for (j=0;j [0:3] load_reg[31:24] = eth_phy0.rx_mem[addr_cnt]; addr_cnt = addr_cnt + 1; load_reg[23:16] = eth_phy0.rx_mem[addr_cnt]; addr_cnt = addr_cnt + 1; load_reg[15: 8] = eth_phy0.rx_mem[addr_cnt]; addr_cnt = addr_cnt + 1; load_reg[ 7: 0] = eth_phy0.rx_mem[addr_cnt]; addr_cnt = addr_cnt + 1; while (nibble_cnt > 0) begin // wait for delta time delta_t = !delta_t; // shift data in if(nibble_cnt <= 8) // for additional 8 nibbles shift ZEROs in! data_in[3:0] = 4'h0; else data_in[3:0] = {load_reg[word_cnt], load_reg[word_cnt+1], load_reg[word_cnt+2], load_reg[word_cnt+3]}; crc_next[0] = (data_in[0] ^ crc[28]); crc_next[1] = (data_in[1] ^ data_in[0] ^ crc[28] ^ crc[29]); crc_next[2] = (data_in[2] ^ data_in[1] ^ data_in[0] ^ crc[28] ^ crc[29] ^ crc[30]); crc_next[3] = (data_in[3] ^ data_in[2] ^ data_in[1] ^ crc[29] ^ crc[30] ^ crc[31]); crc_next[4] = (data_in[3] ^ data_in[2] ^ data_in[0] ^ crc[28] ^ crc[30] ^ crc[31]) ^ crc[0]; crc_next[5] = (data_in[3] ^ data_in[1] ^ data_in[0] ^ crc[28] ^ crc[29] ^ crc[31]) ^ crc[1]; crc_next[6] = (data_in[2] ^ data_in[1] ^ crc[29] ^ crc[30]) ^ crc[ 2]; crc_next[7] = (data_in[3] ^ data_in[2] ^ data_in[0] ^ crc[28] ^ crc[30] ^ crc[31]) ^ crc[3]; crc_next[8] = (data_in[3] ^ data_in[1] ^ data_in[0] ^ crc[28] ^ crc[29] ^ crc[31]) ^ crc[4]; crc_next[9] = (data_in[2] ^ data_in[1] ^ crc[29] ^ crc[30]) ^ crc[5]; crc_next[10] = (data_in[3] ^ data_in[2] ^ data_in[0] ^ crc[28] ^ crc[30] ^ crc[31]) ^ crc[6]; crc_next[11] = (data_in[3] ^ data_in[1] ^ data_in[0] ^ crc[28] ^ crc[29] ^ crc[31]) ^ crc[7]; crc_next[12] = (data_in[2] ^ data_in[1] ^ data_in[0] ^ crc[28] ^ crc[29] ^ crc[30]) ^ crc[8]; crc_next[13] = (data_in[3] ^ data_in[2] ^ data_in[1] ^ crc[29] ^ crc[30] ^ crc[31]) ^ crc[9]; crc_next[14] = (data_in[3] ^ data_in[2] ^ crc[30] ^ crc[31]) ^ crc[10]; crc_next[15] = (data_in[3] ^ crc[31]) ^ crc[11]; crc_next[16] = (data_in[0] ^ crc[28]) ^ crc[12]; crc_next[17] = (data_in[1] ^ crc[29]) ^ crc[13]; crc_next[18] = (data_in[2] ^ crc[30]) ^ crc[14]; crc_next[19] = (data_in[3] ^ crc[31]) ^ crc[15]; crc_next[20] = crc[16]; crc_next[21] = crc[17]; crc_next[22] = (data_in[0] ^ crc[28]) ^ crc[18]; crc_next[23] = (data_in[1] ^ data_in[0] ^ crc[29] ^ crc[28]) ^ crc[19]; crc_next[24] = (data_in[2] ^ data_in[1] ^ crc[30] ^ crc[29]) ^ crc[20]; crc_next[25] = (data_in[3] ^ data_in[2] ^ crc[31] ^ crc[30]) ^ crc[21]; crc_next[26] = (data_in[3] ^ data_in[0] ^ crc[31] ^ crc[28]) ^ crc[22]; crc_next[27] = (data_in[1] ^ crc[29]) ^ crc[23]; crc_next[28] = (data_in[2] ^ crc[30]) ^ crc[24]; crc_next[29] = (data_in[3] ^ crc[31]) ^ crc[25]; crc_next[30] = crc[26]; crc_next[31] = crc[27]; crc = crc_next; crc_error = crc[31:0] != 32'hc704dd7b; // CRC not equal to magic number case (nibble_cnt) 9: crc_out = {!crc[24], !crc[25], !crc[26], !crc[27], !crc[28], !crc[29], !crc[30], !crc[31], !crc[16], !crc[17], !crc[18], !crc[19], !crc[20], !crc[21], !crc[22], !crc[23], !crc[ 8], !crc[ 9], !crc[10], !crc[11], !crc[12], !crc[13], !crc[14], !crc[15], !crc[ 0], !crc[ 1], !crc[ 2], !crc[ 3], !crc[ 4], !crc[ 5], !crc[ 6], !crc[ 7]}; default: crc_out = crc_out; endcase // wait for delta time delta_t = !delta_t; // increment address and load new data if ((word_cnt+3) == 7)//4) begin // because of MAGIC NUMBER nibbles are swapped [3:0] -> [0:3] load_reg[31:24] = eth_phy0.rx_mem[addr_cnt]; addr_cnt = addr_cnt + 1; load_reg[23:16] = eth_phy0.rx_mem[addr_cnt]; addr_cnt = addr_cnt + 1; load_reg[15: 8] = eth_phy0.rx_mem[addr_cnt]; addr_cnt = addr_cnt + 1; load_reg[ 7: 0] = eth_phy0.rx_mem[addr_cnt]; addr_cnt = addr_cnt + 1; end // set new load bit position if((word_cnt+3) == 31) word_cnt = 16; else if ((word_cnt+3) == 23) word_cnt = 8; else if ((word_cnt+3) == 15) word_cnt = 0; else if ((word_cnt+3) == 7) word_cnt = 24; else word_cnt = word_cnt + 4;// - 4; // decrement nibble counter nibble_cnt = nibble_cnt - 1; // wait for delta time delta_t = !delta_t; end // while #1; end endtask // paralel_crc_phy_rx

Error running this command: diff -w -U 5 "" "/tmp/j35S5C"

diff: : No such file or directory