1 |
2 |
peteralieb |
//------------------------------------------------------------------------------
|
2 |
|
|
// Title : FCS Block for the MII Physical Interface
|
3 |
|
|
// Project : Virtex-4 Embedded Tri-Mode Ethernet MAC Wrapper
|
4 |
|
|
// File : emac0_fcs_blk_mii.v
|
5 |
|
|
// Version : 4.8
|
6 |
|
|
//-----------------------------------------------------------------------------
|
7 |
|
|
//
|
8 |
|
|
// (c) Copyright 2004-2010 Xilinx, Inc. All rights reserved.
|
9 |
|
|
//
|
10 |
|
|
// This file contains confidential and proprietary information
|
11 |
|
|
// of Xilinx, Inc. and is protected under U.S. and
|
12 |
|
|
// international copyright and other intellectual property
|
13 |
|
|
// laws.
|
14 |
|
|
//
|
15 |
|
|
// DISCLAIMER
|
16 |
|
|
// This disclaimer is not a license and does not grant any
|
17 |
|
|
// rights to the materials distributed herewith. Except as
|
18 |
|
|
// otherwise provided in a valid license issued to you by
|
19 |
|
|
// Xilinx, and to the maximum extent permitted by applicable
|
20 |
|
|
// law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND
|
21 |
|
|
// WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES
|
22 |
|
|
// AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING
|
23 |
|
|
// BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON-
|
24 |
|
|
// INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and
|
25 |
|
|
// (2) Xilinx shall not be liable (whether in contract or tort,
|
26 |
|
|
// including negligence, or under any other theory of
|
27 |
|
|
// liability) for any loss or damage of any kind or nature
|
28 |
|
|
// related to, arising under or in connection with these
|
29 |
|
|
// materials, including for any direct, or any indirect,
|
30 |
|
|
// special, incidental, or consequential loss or damage
|
31 |
|
|
// (including loss of data, profits, goodwill, or any type of
|
32 |
|
|
// loss or damage suffered as a result of any action brought
|
33 |
|
|
// by a third party) even if such damage or loss was
|
34 |
|
|
// reasonably foreseeable or Xilinx had been advised of the
|
35 |
|
|
// possibility of the same.
|
36 |
|
|
//
|
37 |
|
|
// CRITICAL APPLICATIONS
|
38 |
|
|
// Xilinx products are not designed or intended to be fail-
|
39 |
|
|
// safe, or for use in any application requiring fail-safe
|
40 |
|
|
// performance, such as life-support or safety devices or
|
41 |
|
|
// systems, Class III medical devices, nuclear facilities,
|
42 |
|
|
// applications related to the deployment of airbags, or any
|
43 |
|
|
// other applications that could lead to death, personal
|
44 |
|
|
// injury, or severe property or environmental damage
|
45 |
|
|
// (individually and collectively, "Critical
|
46 |
|
|
// Applications"). Customer assumes the sole risk and
|
47 |
|
|
// liability of any use of Xilinx products in Critical
|
48 |
|
|
// Applications, subject only to applicable laws and
|
49 |
|
|
// regulations governing limitations on product liability.
|
50 |
|
|
//
|
51 |
|
|
// THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS
|
52 |
|
|
// PART OF THIS FILE AT ALL TIMES.
|
53 |
|
|
//
|
54 |
|
|
//------------------------------------------------------------------------------
|
55 |
|
|
// Description: This file assures proper frame transmission by suppressing
|
56 |
|
|
// duplicate FCS bytes should they occur.
|
57 |
|
|
// This file operates with the MII physical interface and the
|
58 |
|
|
// standard clocking scheme only.
|
59 |
|
|
//------------------------------------------------------------------------------
|
60 |
|
|
|
61 |
|
|
`timescale 1 ps / 1 ps
|
62 |
|
|
|
63 |
|
|
module emac0_fcs_blk_mii (
|
64 |
|
|
|
65 |
|
|
// Global signals
|
66 |
|
|
input reset,
|
67 |
|
|
|
68 |
|
|
// PHY-side input signals
|
69 |
|
|
input tx_phy_clk,
|
70 |
|
|
input [3:0] txd_from_mac,
|
71 |
|
|
input tx_en_from_mac,
|
72 |
|
|
input tx_er_from_mac,
|
73 |
|
|
|
74 |
|
|
// Client-side signals
|
75 |
|
|
input tx_client_clk,
|
76 |
|
|
input tx_stats_byte_valid,
|
77 |
|
|
input tx_collision,
|
78 |
|
|
input speed_is_10_100,
|
79 |
|
|
|
80 |
|
|
// PHY outputs
|
81 |
|
|
output [3:0] txd,
|
82 |
|
|
output tx_en,
|
83 |
|
|
output tx_er
|
84 |
|
|
);
|
85 |
|
|
|
86 |
|
|
// Pipeline registers
|
87 |
|
|
reg [3:0] txd_r1;
|
88 |
|
|
reg [3:0] txd_r2;
|
89 |
|
|
reg tx_en_r1;
|
90 |
|
|
reg tx_en_r2;
|
91 |
|
|
reg tx_er_r1;
|
92 |
|
|
reg tx_er_r2;
|
93 |
|
|
|
94 |
|
|
// For detecting frame end
|
95 |
|
|
reg tx_stats_byte_valid_r;
|
96 |
|
|
|
97 |
|
|
// Counters
|
98 |
|
|
reg [2:0] tx_en_count;
|
99 |
|
|
reg [1:0] tx_byte_count;
|
100 |
|
|
reg [1:0] tx_byte_count_r;
|
101 |
|
|
|
102 |
|
|
// Suppression control signals
|
103 |
|
|
(* ASYNC_REG = "TRUE" *)
|
104 |
|
|
reg collision_r;
|
105 |
|
|
wire tx_en_suppress;
|
106 |
|
|
reg tx_en_suppress_r;
|
107 |
|
|
(* ASYNC_REG = "TRUE" *)
|
108 |
|
|
reg speed_is_10_100_r;
|
109 |
|
|
|
110 |
|
|
// Create a two-stage pipeline of PHY output signals in preparation for extra
|
111 |
|
|
// FCS byte determination and TX_EN suppression if one is present.
|
112 |
|
|
always @(posedge tx_phy_clk, posedge reset)
|
113 |
|
|
begin
|
114 |
|
|
if (reset == 1'b1)
|
115 |
|
|
begin
|
116 |
|
|
txd_r1 <= 4'b0;
|
117 |
|
|
txd_r2 <= 4'b0;
|
118 |
|
|
tx_en_r1 <= 1'b0;
|
119 |
|
|
tx_en_r2 <= 1'b0;
|
120 |
|
|
tx_er_r1 <= 1'b0;
|
121 |
|
|
tx_er_r2 <= 1'b0;
|
122 |
|
|
end
|
123 |
|
|
else
|
124 |
|
|
begin
|
125 |
|
|
txd_r1 <= txd_from_mac;
|
126 |
|
|
txd_r2 <= txd_r1;
|
127 |
|
|
tx_en_r1 <= tx_en_from_mac;
|
128 |
|
|
tx_en_r2 <= tx_en_r1;
|
129 |
|
|
tx_er_r1 <= tx_er_from_mac;
|
130 |
|
|
tx_er_r2 <= tx_er_r1;
|
131 |
|
|
end
|
132 |
|
|
end
|
133 |
|
|
|
134 |
|
|
// On the PHY-side clock, count the number of cycles that TX_EN remains
|
135 |
|
|
// asserted for. Only 3 bits are needed for comparison.
|
136 |
|
|
always @(posedge tx_phy_clk)
|
137 |
|
|
begin
|
138 |
|
|
if (tx_en_from_mac == 1'b1)
|
139 |
|
|
tx_en_count <= tx_en_count + 3'b1;
|
140 |
|
|
else
|
141 |
|
|
tx_en_count <= 3'b0;
|
142 |
|
|
end
|
143 |
|
|
|
144 |
|
|
// On the client-side clock, count the number of cycles that the stats byte
|
145 |
|
|
// valid signal remains asserted for. Only 2 bits are needed for comparison.
|
146 |
|
|
always @(posedge tx_client_clk)
|
147 |
|
|
begin
|
148 |
|
|
tx_stats_byte_valid_r <= tx_stats_byte_valid;
|
149 |
|
|
speed_is_10_100_r <= speed_is_10_100;
|
150 |
|
|
if (tx_stats_byte_valid == 1'b1)
|
151 |
|
|
tx_byte_count <= tx_byte_count + 2'b1;
|
152 |
|
|
else
|
153 |
|
|
tx_byte_count <= 2'b0;
|
154 |
|
|
end
|
155 |
|
|
|
156 |
|
|
// Capture the final stats byte valid count for the frame.
|
157 |
|
|
always @(posedge tx_client_clk)
|
158 |
|
|
begin
|
159 |
|
|
if ((tx_stats_byte_valid_r == 1'b1) && (tx_stats_byte_valid == 1'b0))
|
160 |
|
|
tx_byte_count_r <= tx_byte_count;
|
161 |
|
|
end
|
162 |
|
|
|
163 |
|
|
// Generate a signal to suppress TX_EN if the two counts don't match.
|
164 |
|
|
// (Both counters will be stable when this comparison happens, so clock
|
165 |
|
|
// domain crossing is not a concern.)
|
166 |
|
|
// Since the standard clocking scheme is in use, the PHY counter is twice the
|
167 |
|
|
// frequency of the client counter, so use bits 2 and 1 to divide it by two.
|
168 |
|
|
assign tx_en_suppress = (((tx_en_from_mac == 1'b0) && (tx_en_r1 == 1'b1)) &&
|
169 |
|
|
(tx_en_count[2:1] != tx_byte_count_r)) ? 1'b1 : 1'b0;
|
170 |
|
|
|
171 |
|
|
// Register the signal as TX_EN needs to be suppressed over two nibbles. Also
|
172 |
|
|
// register tx_collision for use in the suppression logic.
|
173 |
|
|
always @(posedge tx_phy_clk)
|
174 |
|
|
begin
|
175 |
|
|
tx_en_suppress_r <= tx_en_suppress;
|
176 |
|
|
if (tx_collision == 1'b1)
|
177 |
|
|
collision_r <= 1'b1;
|
178 |
|
|
else
|
179 |
|
|
begin
|
180 |
|
|
if (tx_en_r2 == 1'b0)
|
181 |
|
|
collision_r <= 1'b0;
|
182 |
|
|
end
|
183 |
|
|
end
|
184 |
|
|
|
185 |
|
|
// Multiplex output signals. When operating at 1 Gbps, bypass this logic
|
186 |
|
|
// entirely. Otherwise, assign TXD and TX_ER to their pipelined outputs.
|
187 |
|
|
// If a collision has occurred, assign TX_EN directly so as to maintain a
|
188 |
|
|
// jam sequence of 32 bits. Suppress TX_EN if an extra FCS byte is present.
|
189 |
|
|
assign txd = (speed_is_10_100_r == 1'b0) ? txd_from_mac : txd_r2;
|
190 |
|
|
assign tx_er = (speed_is_10_100_r == 1'b0) ? tx_er_from_mac : tx_er_r2;
|
191 |
|
|
assign tx_en = ((speed_is_10_100_r == 1'b0) || (collision_r == 1'b1)) ?
|
192 |
|
|
tx_en_from_mac : (tx_en_r2 && ~(tx_en_suppress || tx_en_suppress_r));
|
193 |
|
|
|
194 |
|
|
endmodule
|
195 |
|
|
|