2023-08-18 07:55:04 +00:00
|
|
|
// ***************************************************************************
|
|
|
|
// ***************************************************************************
|
|
|
|
// Copyright (C) 2017, 2018, 2022 Analog Devices, Inc. All rights reserved.
|
|
|
|
// SPDX short identifier: ADIJESD204
|
|
|
|
// ***************************************************************************
|
|
|
|
// ***************************************************************************
|
2017-05-17 17:28:50 +00:00
|
|
|
|
2018-08-27 07:14:54 +00:00
|
|
|
`timescale 1ns/100ps
|
|
|
|
|
2017-05-17 17:28:50 +00:00
|
|
|
module jesd204_rx_cgs #(
|
|
|
|
parameter DATA_PATH_WIDTH = 4
|
|
|
|
) (
|
|
|
|
input clk,
|
|
|
|
input reset,
|
|
|
|
|
|
|
|
input [DATA_PATH_WIDTH-1:0] char_is_cgs,
|
|
|
|
input [DATA_PATH_WIDTH-1:0] char_is_error,
|
|
|
|
|
|
|
|
output ready,
|
|
|
|
|
|
|
|
output [1:0] status_state
|
|
|
|
);
|
|
|
|
|
2022-04-08 10:21:52 +00:00
|
|
|
localparam CGS_STATE_INIT = 2'b00;
|
|
|
|
localparam CGS_STATE_CHECK = 2'b01;
|
|
|
|
localparam CGS_STATE_DATA = 2'b10;
|
2017-05-17 17:28:50 +00:00
|
|
|
|
2022-04-08 10:21:52 +00:00
|
|
|
reg [1:0] state = CGS_STATE_INIT;
|
|
|
|
reg rdy = 1'b0;
|
|
|
|
reg [1:0] beat_error_count = 'h00;
|
2017-05-17 17:28:50 +00:00
|
|
|
|
2022-04-08 10:21:52 +00:00
|
|
|
wire beat_is_cgs = &char_is_cgs;
|
|
|
|
wire beat_has_error = |char_is_error;
|
|
|
|
wire beat_is_all_error = &char_is_error;
|
2017-05-17 17:28:50 +00:00
|
|
|
|
2022-04-08 10:21:52 +00:00
|
|
|
assign ready = rdy;
|
|
|
|
assign status_state = state;
|
2017-05-17 17:28:50 +00:00
|
|
|
|
2022-04-08 10:21:52 +00:00
|
|
|
always @(posedge clk) begin
|
|
|
|
if (state == CGS_STATE_INIT) begin
|
2017-05-17 17:28:50 +00:00
|
|
|
beat_error_count <= 'h00;
|
2022-04-08 10:21:52 +00:00
|
|
|
end else begin
|
|
|
|
if (beat_has_error == 1'b1) begin
|
|
|
|
beat_error_count <= beat_error_count + 1'b1;
|
|
|
|
end else begin
|
|
|
|
beat_error_count <= 'h00;
|
|
|
|
end
|
2017-05-17 17:28:50 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-04-08 10:21:52 +00:00
|
|
|
always @(posedge clk) begin
|
|
|
|
if (reset == 1'b1) begin
|
|
|
|
state <= CGS_STATE_INIT;
|
|
|
|
end else begin
|
|
|
|
case (state)
|
|
|
|
CGS_STATE_INIT: begin
|
|
|
|
if (beat_is_cgs == 1'b1) begin
|
|
|
|
state <= CGS_STATE_CHECK;
|
|
|
|
end
|
2017-05-17 17:28:50 +00:00
|
|
|
end
|
2022-04-08 10:21:52 +00:00
|
|
|
CGS_STATE_CHECK: begin
|
|
|
|
if (beat_has_error == 1'b1) begin
|
|
|
|
if (beat_error_count == 'h3 ||
|
|
|
|
beat_is_all_error == 1'b1) begin
|
|
|
|
state <= CGS_STATE_INIT;
|
|
|
|
end
|
|
|
|
end else begin
|
|
|
|
state <= CGS_STATE_DATA;
|
2017-05-17 17:28:50 +00:00
|
|
|
end
|
|
|
|
end
|
2022-04-08 10:21:52 +00:00
|
|
|
CGS_STATE_DATA: begin
|
|
|
|
if (beat_has_error == 1'b1) begin
|
|
|
|
state <= CGS_STATE_CHECK;
|
|
|
|
end
|
2017-05-17 17:28:50 +00:00
|
|
|
end
|
2022-04-08 10:21:52 +00:00
|
|
|
endcase
|
2017-05-17 17:28:50 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-04-08 10:21:52 +00:00
|
|
|
always @(posedge clk) begin
|
|
|
|
case (state)
|
|
|
|
CGS_STATE_INIT: rdy <= 1'b0;
|
|
|
|
CGS_STATE_DATA: rdy <= 1'b1;
|
|
|
|
default: rdy <= rdy;
|
|
|
|
endcase
|
|
|
|
end
|
2017-05-17 17:28:50 +00:00
|
|
|
|
|
|
|
endmodule
|