2017-05-17 17:28:50 +00:00
|
|
|
//
|
|
|
|
// The ADI JESD204 Core is released under the following license, which is
|
|
|
|
// different than all other HDL cores in this repository.
|
|
|
|
//
|
|
|
|
// Please read this, and understand the freedoms and responsibilities you have
|
|
|
|
// by using this source code/core.
|
|
|
|
//
|
|
|
|
// The JESD204 HDL, is copyright © 2016-2017 Analog Devices Inc.
|
|
|
|
//
|
|
|
|
// This core is free software, you can use run, copy, study, change, ask
|
|
|
|
// questions about and improve this core. Distribution of source, or resulting
|
|
|
|
// binaries (including those inside an FPGA or ASIC) require you to release the
|
|
|
|
// source of the entire project (excluding the system libraries provide by the
|
|
|
|
// tools/compiler/FPGA vendor). These are the terms of the GNU General Public
|
|
|
|
// License version 2 as published by the Free Software Foundation.
|
|
|
|
//
|
|
|
|
// This core is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
|
|
|
// A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License version 2
|
|
|
|
// along with this source code, and binary. If not, see
|
|
|
|
// <http://www.gnu.org/licenses/>.
|
|
|
|
//
|
|
|
|
// Commercial licenses (with commercial support) of this JESD204 core are also
|
|
|
|
// available under terms different than the General Public License. (e.g. they
|
|
|
|
// do not require you to accompany any image (FPGA or ASIC) using the JESD204
|
|
|
|
// core with any corresponding source code.) For these alternate terms you must
|
|
|
|
// purchase a license from Analog Devices Technology Licensing Office. Users
|
|
|
|
// interested in such a license should contact jesd204-licensing@analog.com for
|
|
|
|
// more information. This commercial license is sub-licensable (if you purchase
|
|
|
|
// chips from Analog Devices, incorporate them into your PCB level product, and
|
|
|
|
// purchase a JESD204 license, end users of your product will also have a
|
|
|
|
// license to use this core in a commercial setting without releasing their
|
|
|
|
// source code).
|
|
|
|
//
|
|
|
|
// In addition, we kindly ask you to acknowledge ADI in any program, application
|
|
|
|
// or publication in which you use this JESD204 HDL core. (You are not required
|
|
|
|
// to do so; it is up to your common sense to decide whether you want to comply
|
|
|
|
// with this request or not.) For general publications, we suggest referencing :
|
|
|
|
// “The design and implementation of the JESD204 HDL Core used in this project
|
|
|
|
// is copyright © 2016-2017, Analog Devices, Inc.”
|
|
|
|
//
|
|
|
|
|
2018-08-27 07:14:54 +00:00
|
|
|
`timescale 1ns/100ps
|
|
|
|
|
2017-05-17 17:28:50 +00:00
|
|
|
module jesd204_rx_ctrl #(
|
2018-03-27 14:45:46 +00:00
|
|
|
parameter NUM_LANES = 1,
|
|
|
|
parameter NUM_LINKS = 1
|
2017-05-17 17:28:50 +00:00
|
|
|
) (
|
|
|
|
input clk,
|
|
|
|
input reset,
|
|
|
|
|
|
|
|
input [NUM_LANES-1:0] cfg_lanes_disable,
|
2018-03-27 14:45:46 +00:00
|
|
|
input [NUM_LINKS-1:0] cfg_links_disable,
|
2017-05-17 17:28:50 +00:00
|
|
|
|
|
|
|
input phy_ready,
|
|
|
|
|
|
|
|
output phy_en_char_align,
|
|
|
|
|
|
|
|
output [NUM_LANES-1:0] cgs_reset,
|
|
|
|
input [NUM_LANES-1:0] cgs_ready,
|
|
|
|
|
|
|
|
output [NUM_LANES-1:0] ifs_reset,
|
|
|
|
|
|
|
|
input lmfc_edge,
|
|
|
|
|
2018-03-27 14:45:46 +00:00
|
|
|
output [NUM_LINKS-1:0] sync,
|
2017-05-17 17:28:50 +00:00
|
|
|
output reg latency_monitor_reset,
|
|
|
|
|
2017-08-22 13:06:34 +00:00
|
|
|
output reg [1:0] status_state
|
2017-05-17 17:28:50 +00:00
|
|
|
);
|
|
|
|
|
2017-08-22 13:06:34 +00:00
|
|
|
localparam STATUS_STATE_RESET = 2'h1;
|
|
|
|
localparam STATUS_STATE_WAIT_FOR_PHY = 2'h1;
|
|
|
|
localparam STATUS_STATE_CGS = 2'h2;
|
|
|
|
localparam STATUS_STATE_SYNCHRONIZED = 2'h3;
|
|
|
|
|
2017-05-17 17:28:50 +00:00
|
|
|
localparam STATE_RESET = 0;
|
|
|
|
localparam STATE_WAIT_FOR_PHY = 1;
|
|
|
|
localparam STATE_CGS = 2;
|
|
|
|
localparam STATE_DEGLITCH = 3;
|
|
|
|
localparam STATE_SYNCHRONIZED = 4;
|
|
|
|
|
|
|
|
reg [2:0] state = STATE_RESET;
|
|
|
|
reg [2:0] next_state = STATE_RESET;
|
|
|
|
|
|
|
|
reg [NUM_LANES-1:0] cgs_rst = {NUM_LANES{1'b1}};
|
|
|
|
reg [NUM_LANES-1:0] ifs_rst = {NUM_LANES{1'b1}};
|
2018-03-27 14:45:46 +00:00
|
|
|
reg [NUM_LINKS-1:0] sync_n = {NUM_LINKS{1'b1}};
|
2017-05-17 17:28:50 +00:00
|
|
|
reg en_align = 1'b0;
|
|
|
|
reg state_good = 1'b0;
|
|
|
|
|
|
|
|
reg [2:0] good_counter = 'h00;
|
|
|
|
reg [9:0] deglitch_counter = 'h3ff;
|
|
|
|
|
|
|
|
assign cgs_reset = cgs_rst;
|
|
|
|
assign ifs_reset = ifs_rst;
|
|
|
|
assign sync = sync_n;
|
|
|
|
assign phy_en_char_align = en_align;
|
|
|
|
|
2017-08-22 13:06:34 +00:00
|
|
|
always @(posedge clk) begin
|
|
|
|
case (state)
|
|
|
|
STATE_RESET: status_state <= STATUS_STATE_RESET;
|
|
|
|
STATE_WAIT_FOR_PHY: status_state <= STATUS_STATE_WAIT_FOR_PHY;
|
|
|
|
STATE_CGS: status_state <= STATUS_STATE_CGS;
|
|
|
|
STATE_DEGLITCH: status_state <= STATUS_STATE_CGS;
|
|
|
|
STATE_SYNCHRONIZED: status_state <= STATUS_STATE_SYNCHRONIZED;
|
2017-08-28 14:10:12 +00:00
|
|
|
default: status_state <= STATUS_STATE_RESET;
|
2017-08-22 13:06:34 +00:00
|
|
|
endcase
|
|
|
|
end
|
2017-05-17 17:28:50 +00:00
|
|
|
|
|
|
|
always @(posedge clk) begin
|
|
|
|
case (state)
|
|
|
|
STATE_RESET: begin
|
|
|
|
cgs_rst <= {NUM_LANES{1'b1}};
|
|
|
|
ifs_rst <= {NUM_LANES{1'b1}};
|
2018-03-27 14:45:46 +00:00
|
|
|
sync_n <= {NUM_LINKS{1'b1}};
|
2017-05-17 17:28:50 +00:00
|
|
|
latency_monitor_reset <= 1'b1;
|
|
|
|
end
|
|
|
|
STATE_CGS: begin
|
2018-04-04 11:55:57 +00:00
|
|
|
sync_n <= cfg_links_disable;
|
2017-05-17 17:28:50 +00:00
|
|
|
cgs_rst <= cfg_lanes_disable;
|
|
|
|
end
|
|
|
|
STATE_SYNCHRONIZED: begin
|
|
|
|
if (lmfc_edge == 1'b1) begin
|
2018-03-27 14:45:46 +00:00
|
|
|
sync_n <= {NUM_LINKS{1'b1}};
|
2017-05-17 17:28:50 +00:00
|
|
|
ifs_rst <= cfg_lanes_disable;
|
|
|
|
latency_monitor_reset <= 1'b0;
|
|
|
|
end
|
|
|
|
end
|
|
|
|
endcase
|
|
|
|
end
|
|
|
|
|
|
|
|
always @(posedge clk) begin
|
|
|
|
case (state)
|
|
|
|
STATE_DEGLITCH: begin
|
|
|
|
if (deglitch_counter != 'h00) begin
|
|
|
|
deglitch_counter <= deglitch_counter - 1'b1;
|
|
|
|
end
|
|
|
|
end
|
|
|
|
default: begin
|
|
|
|
deglitch_counter <= 'h3f;
|
|
|
|
end
|
|
|
|
endcase
|
|
|
|
end
|
|
|
|
|
|
|
|
always @(*) begin
|
|
|
|
case (state)
|
|
|
|
STATE_RESET: state_good <= 1'b1;
|
|
|
|
STATE_WAIT_FOR_PHY: state_good <= phy_ready;
|
|
|
|
STATE_CGS: state_good <= &(cgs_ready | cfg_lanes_disable);
|
|
|
|
STATE_DEGLITCH: state_good <= deglitch_counter == 'h00;
|
|
|
|
STATE_SYNCHRONIZED: state_good <= 1'b1;
|
|
|
|
default: state_good <= 1'b0;
|
|
|
|
endcase
|
|
|
|
end
|
|
|
|
|
|
|
|
always @(posedge clk) begin
|
|
|
|
if (state_good == 1'b1) begin
|
|
|
|
good_counter <= good_counter + 1'b1;
|
|
|
|
end else begin
|
|
|
|
good_counter <= 'h00;
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
always @(posedge clk) begin
|
|
|
|
case (state)
|
|
|
|
STATE_CGS: en_align <= 1'b1;
|
|
|
|
default: en_align <= 1'b0;
|
|
|
|
endcase
|
|
|
|
end
|
|
|
|
|
|
|
|
always @(*) begin
|
|
|
|
case (state)
|
|
|
|
STATE_RESET: next_state <= STATE_WAIT_FOR_PHY;
|
|
|
|
STATE_WAIT_FOR_PHY: next_state <= STATE_CGS;
|
|
|
|
STATE_CGS: next_state <= STATE_DEGLITCH;
|
|
|
|
STATE_DEGLITCH: next_state <= STATE_SYNCHRONIZED;
|
|
|
|
default: next_state <= state_good ? state : STATE_RESET;
|
|
|
|
endcase
|
|
|
|
end
|
|
|
|
|
|
|
|
always @(posedge clk) begin
|
|
|
|
if (reset == 1'b1) begin
|
|
|
|
state <= STATE_RESET;
|
|
|
|
end else begin
|
|
|
|
if (good_counter == 'h7) begin
|
|
|
|
state <= next_state;
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
endmodule
|