|
@@ -30,11 +30,13 @@ module frame_rx #(
|
|
|
localparam [3:0] ST_CRC_LOW = 4'd8;
|
|
localparam [3:0] ST_CRC_LOW = 4'd8;
|
|
|
localparam [3:0] ST_CRC_HIGH = 4'd9;
|
|
localparam [3:0] ST_CRC_HIGH = 4'd9;
|
|
|
localparam [3:0] ST_HOLD = 4'd10;
|
|
localparam [3:0] ST_HOLD = 4'd10;
|
|
|
|
|
+ localparam integer GAP_BITS = (INTER_BYTE_TIMEOUT_CYCLES <= 1) ? 1 : $clog2(INTER_BYTE_TIMEOUT_CYCLES + 1);
|
|
|
|
|
+ localparam integer PAYLOAD_IDX_BITS = (MAX_PAYLOAD <= 1) ? 1 : $clog2(MAX_PAYLOAD + 1);
|
|
|
|
|
|
|
|
reg [3:0] state;
|
|
reg [3:0] state;
|
|
|
- reg [7:0] payload_index;
|
|
|
|
|
|
|
+ reg [PAYLOAD_IDX_BITS-1:0] payload_index;
|
|
|
reg [7:0] received_crc_low;
|
|
reg [7:0] received_crc_low;
|
|
|
- reg [31:0] gap_counter;
|
|
|
|
|
|
|
+ reg [GAP_BITS-1:0] gap_counter;
|
|
|
|
|
|
|
|
wire crc_busy;
|
|
wire crc_busy;
|
|
|
wire crc_data_done;
|
|
wire crc_data_done;
|
|
@@ -55,9 +57,9 @@ module frame_rx #(
|
|
|
frame_valid <= 1'b0;
|
|
frame_valid <= 1'b0;
|
|
|
frame_type <= 8'd0;
|
|
frame_type <= 8'd0;
|
|
|
frame_length <= 8'd0;
|
|
frame_length <= 8'd0;
|
|
|
- payload_index <= 8'd0;
|
|
|
|
|
|
|
+ payload_index <= {PAYLOAD_IDX_BITS{1'b0}};
|
|
|
received_crc_low <= 8'd0;
|
|
received_crc_low <= 8'd0;
|
|
|
- gap_counter <= 32'd0;
|
|
|
|
|
|
|
+ gap_counter <= {GAP_BITS{1'b0}};
|
|
|
payload_wr_en <= 1'b0;
|
|
payload_wr_en <= 1'b0;
|
|
|
payload_wr_addr <= 8'd0;
|
|
payload_wr_addr <= 8'd0;
|
|
|
payload_wr_data <= 8'd0;
|
|
payload_wr_data <= 8'd0;
|
|
@@ -77,13 +79,13 @@ module frame_rx #(
|
|
|
if (state != ST_WAIT_A5 && state != ST_WAIT_5A && !byte_valid) begin
|
|
if (state != ST_WAIT_A5 && state != ST_WAIT_5A && !byte_valid) begin
|
|
|
if (INTER_BYTE_TIMEOUT_CYCLES <= 1 || gap_counter >= INTER_BYTE_TIMEOUT_CYCLES - 1) begin
|
|
if (INTER_BYTE_TIMEOUT_CYCLES <= 1 || gap_counter >= INTER_BYTE_TIMEOUT_CYCLES - 1) begin
|
|
|
state <= ST_WAIT_A5;
|
|
state <= ST_WAIT_A5;
|
|
|
- gap_counter <= 32'd0;
|
|
|
|
|
|
|
+ gap_counter <= {GAP_BITS{1'b0}};
|
|
|
end else begin
|
|
end else begin
|
|
|
gap_counter <= gap_counter + 1'b1;
|
|
gap_counter <= gap_counter + 1'b1;
|
|
|
end
|
|
end
|
|
|
end
|
|
end
|
|
|
if (byte_valid) begin
|
|
if (byte_valid) begin
|
|
|
- gap_counter <= 32'd0;
|
|
|
|
|
|
|
+ gap_counter <= {GAP_BITS{1'b0}};
|
|
|
case (state)
|
|
case (state)
|
|
|
ST_WAIT_A5: begin
|
|
ST_WAIT_A5: begin
|
|
|
if (byte_data == 8'hA5) state <= ST_WAIT_5A;
|
|
if (byte_data == 8'hA5) state <= ST_WAIT_5A;
|
|
@@ -137,7 +139,7 @@ module frame_rx #(
|
|
|
if (frame_length > MAX_PAYLOAD) state <= ST_WAIT_A5;
|
|
if (frame_length > MAX_PAYLOAD) state <= ST_WAIT_A5;
|
|
|
else if (frame_length == 0) state <= ST_CRC_LOW;
|
|
else if (frame_length == 0) state <= ST_CRC_LOW;
|
|
|
else begin
|
|
else begin
|
|
|
- payload_index <= 8'd0;
|
|
|
|
|
|
|
+ payload_index <= {PAYLOAD_IDX_BITS{1'b0}};
|
|
|
state <= ST_PAYLOAD;
|
|
state <= ST_PAYLOAD;
|
|
|
end
|
|
end
|
|
|
end
|
|
end
|