1 |
4 |
fisher5090 |
`timescale 1ns / 1ps
|
2 |
|
|
////////////////////////////////////////////////////////////////////////////////
|
3 |
|
|
// Company:
|
4 |
|
|
// Engineer:
|
5 |
|
|
//
|
6 |
|
|
// Create Date: 09:59:01 11/21/05
|
7 |
|
|
// Design Name:
|
8 |
|
|
// Module Name: rxStateMachine
|
9 |
|
|
// Project Name:
|
10 |
|
|
// Target Device:
|
11 |
|
|
// Tool versions:
|
12 |
|
|
// Description:
|
13 |
|
|
//
|
14 |
|
|
// Dependencies:
|
15 |
|
|
//
|
16 |
|
|
// Revision:
|
17 |
|
|
// Revision 0.01 - File Created
|
18 |
|
|
// Additional Comments:
|
19 |
|
|
//
|
20 |
|
|
////////////////////////////////////////////////////////////////////////////////
|
21 |
|
|
module rxStateMachine(rxclk, reset, recv_enable, get_sfd, local_invalid, len_invalid, end_data_cnt, end_tagged_cnt,
|
22 |
|
|
tagged_frame, length_error, end_fcs, crc_check_valid, crc_check_invalid, start_da, start_lt, inband_fcs,
|
23 |
|
|
start_data_cnt, start_tagged_cnt, receiving, recv_end, good_frame_get, bad_frame_get, get_error_code, small_frame
|
24 |
|
|
, end_small_cnt,receiving_frame);
|
25 |
|
|
|
26 |
|
|
input rxclk;
|
27 |
|
|
input reset;
|
28 |
|
|
|
29 |
|
|
input recv_enable;
|
30 |
|
|
input inband_fcs;
|
31 |
|
|
|
32 |
|
|
//PRE & SFD
|
33 |
|
|
input get_sfd; // SFD has been received;
|
34 |
|
|
|
35 |
|
|
//DA field
|
36 |
|
|
input local_invalid;// The Frame's DA field is not Local MAC;
|
37 |
|
|
|
38 |
|
|
//Length/Type field
|
39 |
|
|
input len_invalid;// Indicate if Length field is valid;
|
40 |
|
|
input end_data_cnt;// Indicate end of receiving DATA field(not jumbo frame);
|
41 |
|
|
input end_tagged_cnt;// Indicate end of receiving DATA field of tagged Frame;
|
42 |
|
|
input end_small_cnt; // Indicate end of receiving small data field
|
43 |
|
|
input tagged_frame;// Indicate current frame is a jumbo_frame;
|
44 |
|
|
input small_frame; // Indicate current frame is a small frame;
|
45 |
|
|
input length_error;//Indicate Length received is not equal to the Length in LT field;
|
46 |
|
|
|
47 |
|
|
//FCS field
|
48 |
|
|
input end_fcs;//Indicate end of receiving FCS field;
|
49 |
|
|
input crc_check_valid;//Indicate the frame passed CRC Check;
|
50 |
|
|
input crc_check_invalid;//Indicate the frame failed in CRC Check;
|
51 |
|
|
input get_error_code;
|
52 |
|
|
|
53 |
|
|
//DA field
|
54 |
|
|
output start_da;// Start to receive Destination Address;
|
55 |
|
|
|
56 |
|
|
//Length/Type field
|
57 |
|
|
output start_lt;// Start to receive Length/Type field;
|
58 |
|
|
|
59 |
|
|
//DATA field
|
60 |
|
|
output start_data_cnt;// Start to receive DATA field;
|
61 |
|
|
output start_tagged_cnt;// Start to receive DATA field, but the frame is a tagged frame.
|
62 |
|
|
//Receive process control
|
63 |
|
|
output receiving;// Rx Engine is receiving valid part of frame;
|
64 |
|
|
output receiving_frame; //Rx Engine is working, not in IDLE state and Check state.
|
65 |
|
|
output recv_end; // Receive process ends, either because formal ending or faults happen;
|
66 |
|
|
output good_frame_get;// A good frame has been received;
|
67 |
|
|
output bad_frame_get; // A bad frame has been received;
|
68 |
|
|
|
69 |
|
|
parameter IDLE = 0, rxReceiveDA = 1, rxReceiveLT = 2, rxReceiveData = 3;
|
70 |
|
|
parameter rxReceiveFCS = 4, rxWaitCheck = 5;
|
71 |
|
|
parameter TP =1;
|
72 |
|
|
|
73 |
|
|
wire start_da;
|
74 |
|
|
wire start_lt;
|
75 |
|
|
wire start_data_cnt;
|
76 |
|
|
wire start_tagged_cnt;
|
77 |
|
|
wire receiving_data;
|
78 |
|
|
wire receiving_frame;
|
79 |
|
|
wire receiving;
|
80 |
|
|
wire recv_end;
|
81 |
|
|
wire good_frame_get;
|
82 |
|
|
wire bad_frame_get;
|
83 |
|
|
|
84 |
|
|
reg[2:0] rxstate, rxstate_next;
|
85 |
|
|
|
86 |
|
|
always@(rxstate, get_sfd, local_invalid, len_invalid, recv_enable,
|
87 |
|
|
tagged_frame, end_data_cnt, end_tagged_cnt, get_error_code,
|
88 |
|
|
end_fcs, length_error, crc_check_valid,crc_check_invalid, reset)begin
|
89 |
|
|
if (reset) begin
|
90 |
|
|
rxstate_next <=#TP IDLE;
|
91 |
|
|
end
|
92 |
|
|
else begin
|
93 |
|
|
case (rxstate)
|
94 |
|
|
IDLE: begin
|
95 |
|
|
if (get_sfd & recv_enable)
|
96 |
|
|
rxstate_next <=#TP rxReceiveDA;
|
97 |
|
|
end
|
98 |
|
|
rxReceiveDA: begin
|
99 |
|
|
rxstate_next <=#TP rxReceiveLT;
|
100 |
|
|
end
|
101 |
|
|
rxReceiveLT: begin
|
102 |
|
|
rxstate_next <=#TP rxReceiveData;
|
103 |
|
|
end
|
104 |
|
|
rxReceiveData: begin
|
105 |
|
|
if (local_invalid | len_invalid | get_error_code)
|
106 |
|
|
rxstate_next <=#TP rxWaitCheck;
|
107 |
|
|
else if (end_data_cnt | end_tagged_cnt)
|
108 |
|
|
rxstate_next <=#TP rxReceiveFCS;
|
109 |
|
|
|
110 |
|
|
end
|
111 |
|
|
rxReceiveFCS: begin //length_error should have high priority to end_fcs
|
112 |
|
|
if (length_error)
|
113 |
|
|
rxstate_next <=#TP IDLE;
|
114 |
|
|
else if (end_fcs)
|
115 |
|
|
rxstate_next <=#TP rxWaitCheck;
|
116 |
|
|
end
|
117 |
|
|
rxWaitCheck: begin
|
118 |
|
|
if (crc_check_valid)
|
119 |
|
|
rxstate_next <=#TP IDLE;
|
120 |
|
|
else if (local_invalid | len_invalid | length_error | crc_check_invalid)
|
121 |
|
|
rxstate_next <=#TP IDLE;
|
122 |
|
|
end
|
123 |
|
|
endcase
|
124 |
|
|
end
|
125 |
|
|
end
|
126 |
|
|
|
127 |
|
|
always@(posedge rxclk or posedge reset) begin
|
128 |
|
|
if (reset)
|
129 |
|
|
rxstate <=#TP IDLE;
|
130 |
|
|
else
|
131 |
|
|
rxstate <=#TP rxstate_next;
|
132 |
|
|
end
|
133 |
|
|
|
134 |
|
|
reg end_small_cnt_d1;
|
135 |
|
|
reg end_small_cnt_d2;
|
136 |
|
|
always@(posedge rxclk or posedge reset) begin
|
137 |
|
|
if (reset)begin
|
138 |
|
|
end_small_cnt_d1 <= 0;
|
139 |
|
|
end_small_cnt_d2 <= 0;
|
140 |
|
|
end
|
141 |
|
|
else begin
|
142 |
|
|
end_small_cnt_d1 <=end_small_cnt;
|
143 |
|
|
if (end_small_cnt_d1)
|
144 |
|
|
end_small_cnt_d2 <= 1'b1;
|
145 |
|
|
else
|
146 |
|
|
end_small_cnt_d2 <= #TP end_small_cnt_d2;
|
147 |
|
|
end
|
148 |
|
|
end
|
149 |
|
|
|
150 |
|
|
assign start_da = (rxstate == rxReceiveDA);
|
151 |
|
|
assign start_lt = (rxstate == rxReceiveLT);
|
152 |
|
|
assign start_data_cnt = (rxstate == rxReceiveData) & (~tagged_frame);
|
153 |
|
|
assign start_tagged_cnt = (rxstate == rxReceiveData) & tagged_frame;
|
154 |
|
|
assign receiving_data = (~rxstate[2]&(rxstate[0] | rxstate[1])); // in DA,LT,DATA status
|
155 |
|
|
assign receiving_frame = receiving_data |(rxstate[2]&~rxstate[1]&~rxstate[0]); //in DA,LT,Data,FCS status
|
156 |
|
|
assign receiving_small = start_da | start_lt | ((rxstate == rxReceiveData) & ~end_small_cnt_d2);
|
157 |
|
|
assign receiving = inband_fcs? receiving_frame:(small_frame? receiving_small:receiving_data);
|
158 |
|
|
assign recv_end = ~receiving_frame;
|
159 |
|
|
assign bad_frame_get = ((rxstate == rxReceiveFCS) & length_error) | ((rxstate == rxWaitCheck) & (local_invalid | len_invalid | length_error | crc_check_invalid));
|
160 |
|
|
assign good_frame_get = (rxstate == rxWaitCheck) & crc_check_valid;
|
161 |
|
|
endmodule
|