`timescale 1ns / 1ps
|
`timescale 1ns / 1ps
|
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
// Company:
|
// Company:
|
// Engineer:
|
// Engineer:
|
//
|
//
|
// Create Date: 09:59:01 11/21/05
|
// Create Date: 09:59:01 11/21/05
|
// Design Name:
|
// Design Name:
|
// Module Name: rxStateMachine
|
// Module Name: rxStateMachine
|
// Project Name:
|
// Project Name:
|
// Target Device:
|
// Target Device:
|
// Tool versions:
|
// Tool versions:
|
// Description:
|
// Description:
|
//
|
//
|
// Dependencies:
|
// Dependencies:
|
//
|
//
|
// Revision:
|
// Revision:
|
// Revision 0.01 - File Created
|
// Revision 0.01 - File Created
|
// Additional Comments:
|
// Additional Comments:
|
//
|
//
|
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
module rxStateMachine(rxclk, reset, recv_enable, get_sfd, local_invalid, len_invalid, end_data_cnt, end_tagged_cnt,
|
module rxStateMachine(rxclk, reset, recv_enable, get_sfd, local_invalid, len_invalid, end_data_cnt, end_tagged_cnt,
|
tagged_frame, length_error, end_fcs, crc_check_valid, crc_check_invalid, start_da, start_lt, inband_fcs,
|
tagged_frame, length_error, end_fcs, crc_check_valid, crc_check_invalid, start_da, start_lt, inband_fcs,
|
start_data_cnt, start_tagged_cnt, receiving, recv_end, good_frame_get, bad_frame_get, get_error_code, small_frame
|
start_data_cnt, start_tagged_cnt, receiving, recv_end, good_frame_get, bad_frame_get, get_error_code, small_frame
|
, end_small_cnt,receiving_frame);
|
, end_small_cnt,receiving_frame);
|
|
|
input rxclk;
|
input rxclk;
|
input reset;
|
input reset;
|
|
|
input recv_enable;
|
input recv_enable;
|
input inband_fcs;
|
input inband_fcs;
|
|
|
//PRE & SFD
|
//PRE & SFD
|
input get_sfd; // SFD has been received;
|
input get_sfd; // SFD has been received;
|
|
|
//DA field
|
//DA field
|
input local_invalid;// The Frame's DA field is not Local MAC;
|
input local_invalid;// The Frame's DA field is not Local MAC;
|
|
|
//Length/Type field
|
//Length/Type field
|
input len_invalid;// Indicate if Length field is valid;
|
input len_invalid;// Indicate if Length field is valid;
|
input end_data_cnt;// Indicate end of receiving DATA field(not jumbo frame);
|
input end_data_cnt;// Indicate end of receiving DATA field(not jumbo frame);
|
input end_tagged_cnt;// Indicate end of receiving DATA field of tagged Frame;
|
input end_tagged_cnt;// Indicate end of receiving DATA field of tagged Frame;
|
input end_small_cnt; // Indicate end of receiving small data field
|
input end_small_cnt; // Indicate end of receiving small data field
|
input tagged_frame;// Indicate current frame is a jumbo_frame;
|
input tagged_frame;// Indicate current frame is a jumbo_frame;
|
input small_frame; // Indicate current frame is a small frame;
|
input small_frame; // Indicate current frame is a small frame;
|
input length_error;//Indicate Length received is not equal to the Length in LT field;
|
input length_error;//Indicate Length received is not equal to the Length in LT field;
|
|
|
//FCS field
|
//FCS field
|
input end_fcs;//Indicate end of receiving FCS field;
|
input end_fcs;//Indicate end of receiving FCS field;
|
input crc_check_valid;//Indicate the frame passed CRC Check;
|
input crc_check_valid;//Indicate the frame passed CRC Check;
|
input crc_check_invalid;//Indicate the frame failed in CRC Check;
|
input crc_check_invalid;//Indicate the frame failed in CRC Check;
|
input get_error_code;
|
input get_error_code;
|
|
|
//DA field
|
//DA field
|
output start_da;// Start to receive Destination Address;
|
output start_da;// Start to receive Destination Address;
|
|
|
//Length/Type field
|
//Length/Type field
|
output start_lt;// Start to receive Length/Type field;
|
output start_lt;// Start to receive Length/Type field;
|
|
|
//DATA field
|
//DATA field
|
output start_data_cnt;// Start to receive DATA field;
|
output start_data_cnt;// Start to receive DATA field;
|
output start_tagged_cnt;// Start to receive DATA field, but the frame is a tagged frame.
|
output start_tagged_cnt;// Start to receive DATA field, but the frame is a tagged frame.
|
//Receive process control
|
//Receive process control
|
output receiving;// Rx Engine is receiving valid part of frame;
|
output receiving;// Rx Engine is receiving valid part of frame;
|
output receiving_frame; //Rx Engine is working, not in IDLE state and Check state.
|
output receiving_frame; //Rx Engine is working, not in IDLE state and Check state.
|
output recv_end; // Receive process ends, either because formal ending or faults happen;
|
output recv_end; // Receive process ends, either because formal ending or faults happen;
|
output good_frame_get;// A good frame has been received;
|
output good_frame_get;// A good frame has been received;
|
output bad_frame_get; // A bad frame has been received;
|
output bad_frame_get; // A bad frame has been received;
|
|
|
parameter IDLE = 0, rxReceiveDA = 1, rxReceiveLT = 2, rxReceiveData = 3;
|
parameter IDLE = 0, rxReceiveDA = 1, rxReceiveLT = 2, rxReceiveData = 3;
|
parameter rxReceiveFCS = 4, rxWaitCheck = 5;
|
parameter rxReceiveFCS = 4, rxWaitCheck = 5;
|
parameter TP =1;
|
parameter TP =1;
|
|
|
wire start_da;
|
wire start_da;
|
wire start_lt;
|
wire start_lt;
|
wire start_data_cnt;
|
wire start_data_cnt;
|
wire start_tagged_cnt;
|
wire start_tagged_cnt;
|
wire receiving_data;
|
wire receiving_data;
|
wire receiving_frame;
|
wire receiving_frame;
|
wire receiving;
|
wire receiving;
|
wire recv_end;
|
wire recv_end;
|
wire good_frame_get;
|
wire good_frame_get;
|
wire bad_frame_get;
|
wire bad_frame_get;
|
|
|
reg[2:0] rxstate, rxstate_next;
|
reg[2:0] rxstate, rxstate_next;
|
|
|
always@(rxstate, get_sfd, local_invalid, len_invalid, recv_enable,
|
always@(rxstate, get_sfd, local_invalid, len_invalid, recv_enable,
|
tagged_frame, end_data_cnt, end_tagged_cnt, get_error_code,
|
tagged_frame, end_data_cnt, end_tagged_cnt, get_error_code,
|
end_fcs, length_error, crc_check_valid,crc_check_invalid, reset)begin
|
end_fcs, length_error, crc_check_valid,crc_check_invalid, reset)begin
|
if (reset) begin
|
if (reset) begin
|
rxstate_next <=#TP IDLE;
|
rxstate_next <=#TP IDLE;
|
end
|
end
|
else begin
|
else begin
|
case (rxstate)
|
case (rxstate)
|
IDLE: begin
|
IDLE: begin
|
if (get_sfd & recv_enable)
|
if (get_sfd & recv_enable)
|
rxstate_next <=#TP rxReceiveDA;
|
rxstate_next <=#TP rxReceiveDA;
|
end
|
end
|
rxReceiveDA: begin
|
rxReceiveDA: begin
|
rxstate_next <=#TP rxReceiveLT;
|
rxstate_next <=#TP rxReceiveLT;
|
end
|
end
|
rxReceiveLT: begin
|
rxReceiveLT: begin
|
rxstate_next <=#TP rxReceiveData;
|
rxstate_next <=#TP rxReceiveData;
|
end
|
end
|
rxReceiveData: begin
|
rxReceiveData: begin
|
if (local_invalid | len_invalid | get_error_code)
|
if (local_invalid | len_invalid | get_error_code)
|
rxstate_next <=#TP rxWaitCheck;
|
rxstate_next <=#TP rxWaitCheck;
|
else if (end_data_cnt | end_tagged_cnt)
|
else if (end_data_cnt | end_tagged_cnt)
|
rxstate_next <=#TP rxReceiveFCS;
|
rxstate_next <=#TP rxReceiveFCS;
|
|
|
end
|
end
|
rxReceiveFCS: begin //length_error should have high priority to end_fcs
|
rxReceiveFCS: begin //length_error should have high priority to end_fcs
|
if (length_error)
|
if (length_error)
|
rxstate_next <=#TP IDLE;
|
rxstate_next <=#TP IDLE;
|
else if (end_fcs)
|
else if (end_fcs)
|
rxstate_next <=#TP rxWaitCheck;
|
rxstate_next <=#TP rxWaitCheck;
|
end
|
end
|
rxWaitCheck: begin
|
rxWaitCheck: begin
|
if (crc_check_valid)
|
if (crc_check_valid)
|
rxstate_next <=#TP IDLE;
|
rxstate_next <=#TP IDLE;
|
else if (local_invalid | len_invalid | length_error | crc_check_invalid)
|
else if (local_invalid | len_invalid | length_error | crc_check_invalid)
|
rxstate_next <=#TP IDLE;
|
rxstate_next <=#TP IDLE;
|
end
|
end
|
endcase
|
endcase
|
end
|
end
|
end
|
end
|
|
|
always@(posedge rxclk or posedge reset) begin
|
always@(posedge rxclk or posedge reset) begin
|
if (reset)
|
if (reset)
|
rxstate <=#TP IDLE;
|
rxstate <=#TP IDLE;
|
else
|
else
|
rxstate <=#TP rxstate_next;
|
rxstate <=#TP rxstate_next;
|
end
|
end
|
|
|
reg end_small_cnt_d1;
|
reg end_small_cnt_d1;
|
reg end_small_cnt_d2;
|
reg end_small_cnt_d2;
|
always@(posedge rxclk or posedge reset) begin
|
always@(posedge rxclk or posedge reset) begin
|
if (reset)begin
|
if (reset)begin
|
end_small_cnt_d1 <= 0;
|
end_small_cnt_d1 <= 0;
|
end_small_cnt_d2 <= 0;
|
end_small_cnt_d2 <= 0;
|
end
|
end
|
else begin
|
else begin
|
end_small_cnt_d1 <=end_small_cnt;
|
end_small_cnt_d1 <=end_small_cnt;
|
if (end_small_cnt_d1)
|
if (end_small_cnt_d1)
|
end_small_cnt_d2 <= 1'b1;
|
end_small_cnt_d2 <= 1'b1;
|
else
|
else
|
end_small_cnt_d2 <= #TP end_small_cnt_d2;
|
end_small_cnt_d2 <= #TP end_small_cnt_d2;
|
end
|
end
|
end
|
end
|
|
|
assign start_da = (rxstate == rxReceiveDA);
|
assign start_da = (rxstate == rxReceiveDA);
|
assign start_lt = (rxstate == rxReceiveLT);
|
assign start_lt = (rxstate == rxReceiveLT);
|
assign start_data_cnt = (rxstate == rxReceiveData) & (~tagged_frame);
|
assign start_data_cnt = (rxstate == rxReceiveData) & (~tagged_frame);
|
assign start_tagged_cnt = (rxstate == rxReceiveData) & tagged_frame;
|
assign start_tagged_cnt = (rxstate == rxReceiveData) & tagged_frame;
|
assign receiving_data = (~rxstate[2]&(rxstate[0] | rxstate[1])); // in DA,LT,DATA status
|
assign receiving_data = (~rxstate[2]&(rxstate[0] | rxstate[1])); // in DA,LT,DATA status
|
assign receiving_frame = receiving_data |(rxstate[2]&~rxstate[1]&~rxstate[0]); //in DA,LT,Data,FCS status
|
assign receiving_frame = receiving_data |(rxstate[2]&~rxstate[1]&~rxstate[0]); //in DA,LT,Data,FCS status
|
assign receiving_small = start_da | start_lt | ((rxstate == rxReceiveData) & ~end_small_cnt_d2);
|
assign receiving_small = start_da | start_lt | ((rxstate == rxReceiveData) & ~end_small_cnt_d2);
|
assign receiving = inband_fcs? receiving_frame:(small_frame? receiving_small:receiving_data);
|
assign receiving = inband_fcs? receiving_frame:(small_frame? receiving_small:receiving_data);
|
assign recv_end = ~receiving_frame;
|
assign recv_end = ~receiving_frame;
|
assign bad_frame_get = ((rxstate == rxReceiveFCS) & length_error) | ((rxstate == rxWaitCheck) & (local_invalid | len_invalid | length_error | crc_check_invalid));
|
assign bad_frame_get = ((rxstate == rxReceiveFCS) & length_error) | ((rxstate == rxWaitCheck) & (local_invalid | len_invalid | length_error | crc_check_invalid));
|
assign good_frame_get = (rxstate == rxWaitCheck) & crc_check_valid;
|
assign good_frame_get = (rxstate == rxWaitCheck) & crc_check_valid;
|
endmodule
|
endmodule
|
|
|