1 |
39 |
fisher5090 |
//////////////////////////////////////////////////////////////////////
|
2 |
|
|
//// ////
|
3 |
|
|
//// MODULE NAME: rxNumCounter ////
|
4 |
|
|
//// ////
|
5 |
|
|
//// DESCRIPTION: To count bytes have been received. ////
|
6 |
|
|
//// ////
|
7 |
|
|
//// ////
|
8 |
|
|
//// This file is part of the 10 Gigabit Ethernet IP core project ////
|
9 |
|
|
//// http://www.opencores.org/projects/ethmac10g/ ////
|
10 |
|
|
//// ////
|
11 |
|
|
//// AUTHOR(S): ////
|
12 |
|
|
//// Zheng Cao ////
|
13 |
|
|
//// ////
|
14 |
|
|
//////////////////////////////////////////////////////////////////////
|
15 |
|
|
//// ////
|
16 |
|
|
//// Copyright (c) 2005 AUTHORS. All rights reserved. ////
|
17 |
|
|
//// ////
|
18 |
|
|
//// This source file may be used and distributed without ////
|
19 |
|
|
//// restriction provided that this copyright statement is not ////
|
20 |
|
|
//// removed from the file and that any derivative work contains ////
|
21 |
|
|
//// the original copyright notice and the associated disclaimer. ////
|
22 |
|
|
//// ////
|
23 |
|
|
//// This source file is free software; you can redistribute it ////
|
24 |
|
|
//// and/or modify it under the terms of the GNU Lesser General ////
|
25 |
|
|
//// Public License as published by the Free Software Foundation; ////
|
26 |
|
|
//// either version 2.1 of the License, or (at your option) any ////
|
27 |
|
|
//// later version. ////
|
28 |
|
|
//// ////
|
29 |
|
|
//// This source is distributed in the hope that it will be ////
|
30 |
|
|
//// useful, but WITHOUT ANY WARRANTY; without even the implied ////
|
31 |
|
|
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ////
|
32 |
|
|
//// PURPOSE. See the GNU Lesser General Public License for more ////
|
33 |
|
|
//// details. ////
|
34 |
|
|
//// ////
|
35 |
|
|
//// You should have received a copy of the GNU Lesser General ////
|
36 |
|
|
//// Public License along with this source; if not, download it ////
|
37 |
|
|
//// from http://www.opencores.org/lgpl.shtml ////
|
38 |
|
|
//// ////
|
39 |
|
|
//////////////////////////////////////////////////////////////////////
|
40 |
|
|
//
|
41 |
|
|
// CVS REVISION HISTORY:
|
42 |
|
|
//
|
43 |
|
|
// $Log: not supported by cvs2svn $
|
44 |
|
|
// Revision 1.1 2005/12/25 16:43:10 Zheng Cao
|
45 |
|
|
//
|
46 |
|
|
//
|
47 |
|
|
//
|
48 |
|
|
//////////////////////////////////////////////////////////////////////
|
49 |
|
|
|
50 |
|
|
`include "timescale.v"
|
51 |
|
|
`include "xgiga_define.v"
|
52 |
|
|
|
53 |
|
|
module rxStateMachine(rxclk, reset, recv_enable, get_sfd, local_invalid, length_error, crc_check_valid, crc_check_invalid,
|
54 |
|
|
start_da, start_lt, receiving, receiving_d1, good_frame_get, bad_frame_get, get_error_code, wait_crc_check,
|
55 |
|
|
get_terminator,check_reset);
|
56 |
|
|
|
57 |
|
|
input rxclk;
|
58 |
|
|
input reset;
|
59 |
|
|
|
60 |
|
|
input recv_enable;
|
61 |
|
|
|
62 |
|
|
//PRE & SFD
|
63 |
|
|
input get_sfd; // SFD has been received;
|
64 |
|
|
|
65 |
|
|
//DA field
|
66 |
|
|
input local_invalid;// The Frame's DA field is not Local MAC;
|
67 |
|
|
|
68 |
|
|
//Length/Type field
|
69 |
|
|
input length_error;//
|
70 |
|
|
|
71 |
|
|
//FCS field
|
72 |
|
|
input get_terminator;//Indicate end of receiving FCS field;
|
73 |
|
|
input crc_check_valid;//Indicate the frame passed CRC Check;
|
74 |
|
|
input crc_check_invalid;//Indicate the frame failed in CRC Check;
|
75 |
|
|
input get_error_code;
|
76 |
|
|
|
77 |
|
|
input check_reset;
|
78 |
|
|
|
79 |
|
|
//DA field
|
80 |
|
|
output start_da;// Start to receive Destination Address;
|
81 |
|
|
|
82 |
|
|
//Length/Type field
|
83 |
|
|
output start_lt;// Start to receive Length/Type field;
|
84 |
|
|
|
85 |
|
|
//Receive process control
|
86 |
|
|
output receiving; //Rx Engine is working, not in IDLE state and Check state.
|
87 |
|
|
output receiving_d1;
|
88 |
|
|
output good_frame_get;// A good frame has been received;
|
89 |
|
|
output bad_frame_get; // A bad frame has been received;
|
90 |
|
|
output wait_crc_check;//
|
91 |
|
|
|
92 |
|
|
parameter IDLE = 0, rxReceiveDA = 1, rxReceiveLT = 2, rxReceiveData = 4;
|
93 |
|
|
parameter rxGetError = 8, rxIFGWait = 16;
|
94 |
|
|
parameter TP =1;
|
95 |
|
|
|
96 |
|
|
wire start_da;
|
97 |
|
|
wire start_lt;
|
98 |
|
|
wire receiving;
|
99 |
|
|
reg good_frame_get;
|
100 |
|
|
reg bad_frame_get;
|
101 |
|
|
|
102 |
|
|
reg[4:0] rxstate, rxstate_next;
|
103 |
|
|
|
104 |
|
|
always@(rxstate, get_sfd, local_invalid, recv_enable,
|
105 |
|
|
get_error_code, length_error, get_terminator, reset)begin
|
106 |
|
|
if (reset) begin
|
107 |
|
|
rxstate_next <=#TP IDLE;
|
108 |
|
|
end
|
109 |
|
|
else begin
|
110 |
|
|
case (rxstate)
|
111 |
|
|
IDLE: begin //5'b00000;
|
112 |
|
|
if (get_sfd && recv_enable)
|
113 |
|
|
rxstate_next <=#TP rxReceiveDA;
|
114 |
|
|
else
|
115 |
|
|
rxstate_next <=#TP IDLE;
|
116 |
|
|
end
|
117 |
|
|
rxReceiveDA: begin //5'b00001
|
118 |
|
|
rxstate_next <=#TP rxReceiveLT;
|
119 |
|
|
end
|
120 |
|
|
rxReceiveLT: begin //5'b00010
|
121 |
|
|
rxstate_next <=#TP rxReceiveData;
|
122 |
|
|
end
|
123 |
|
|
rxReceiveData: begin //5'b00100
|
124 |
|
|
if (local_invalid |length_error| get_error_code)
|
125 |
|
|
rxstate_next <=#TP rxGetError;
|
126 |
|
|
else if (get_terminator)
|
127 |
|
|
rxstate_next <=#TP rxIFGWait;
|
128 |
|
|
else
|
129 |
|
|
rxstate_next <=#TP rxReceiveData;
|
130 |
|
|
end
|
131 |
|
|
rxGetError: begin //5'b01000
|
132 |
|
|
if (get_sfd && recv_enable)
|
133 |
|
|
rxstate_next <=#TP rxReceiveDA;
|
134 |
|
|
else
|
135 |
|
|
rxstate_next <=#TP IDLE;
|
136 |
|
|
end
|
137 |
|
|
rxIFGWait : begin //5'b10000;
|
138 |
|
|
if (get_sfd && recv_enable)
|
139 |
|
|
rxstate_next <=#TP rxReceiveDA;
|
140 |
|
|
else
|
141 |
|
|
rxstate_next <=#TP IDLE;
|
142 |
|
|
end
|
143 |
|
|
endcase
|
144 |
|
|
end
|
145 |
|
|
end
|
146 |
|
|
|
147 |
|
|
always@(posedge rxclk or posedge reset) begin
|
148 |
|
|
if (reset)
|
149 |
|
|
rxstate <=#TP IDLE;
|
150 |
|
|
else
|
151 |
|
|
rxstate <=#TP rxstate_next;
|
152 |
|
|
end
|
153 |
|
|
|
154 |
|
|
assign start_da = rxstate[0];
|
155 |
|
|
assign start_lt = rxstate[1];
|
156 |
|
|
assign receiving = rxstate[2] | rxstate[1] | rxstate[0]; // in DA,LT,DATA status
|
157 |
|
|
|
158 |
|
|
reg receiving_d1;
|
159 |
|
|
always@(posedge rxclk or posedge reset) begin
|
160 |
|
|
if (reset) begin
|
161 |
|
|
receiving_d1<=#TP 0;
|
162 |
|
|
end
|
163 |
|
|
else begin
|
164 |
|
|
receiving_d1<=#TP receiving;
|
165 |
|
|
end
|
166 |
|
|
end
|
167 |
|
|
|
168 |
|
|
reg wait_crc_check;
|
169 |
|
|
always@(posedge rxclk or posedge reset) begin
|
170 |
|
|
if (reset)
|
171 |
|
|
wait_crc_check <=#TP 0;
|
172 |
|
|
else if (rxstate[4])
|
173 |
|
|
wait_crc_check <=#TP 1'b1;
|
174 |
|
|
else if (crc_check_valid || crc_check_invalid||length_error)
|
175 |
|
|
wait_crc_check <=#TP 1'b0;
|
176 |
|
|
else
|
177 |
|
|
wait_crc_check <=#TP wait_crc_check;
|
178 |
|
|
end
|
179 |
|
|
|
180 |
|
|
always@(posedge rxclk or posedge reset)begin
|
181 |
|
|
if (reset) begin
|
182 |
|
|
bad_frame_get <=#TP 0;
|
183 |
|
|
good_frame_get <=#TP 0;
|
184 |
|
|
end
|
185 |
|
|
else if(rxstate[3] || crc_check_invalid || length_error)begin
|
186 |
|
|
bad_frame_get <=#TP 1'b1;
|
187 |
|
|
good_frame_get <=#TP 1'b0;
|
188 |
|
|
end
|
189 |
|
|
else if (crc_check_valid)begin
|
190 |
|
|
good_frame_get <=#TP 1'b1;
|
191 |
|
|
bad_frame_get <=#TP 1'b0;
|
192 |
|
|
end
|
193 |
|
|
else if (check_reset)begin
|
194 |
|
|
good_frame_get <=#TP 1'b0;
|
195 |
|
|
bad_frame_get <=#TP 1'b0;
|
196 |
|
|
end
|
197 |
|
|
end
|
198 |
|
|
endmodule
|