2015-04-07 19:35:47 +00:00
|
|
|
// ***************************************************************************
|
|
|
|
// ***************************************************************************
|
2017-05-17 08:44:52 +00:00
|
|
|
// Copyright 2014 - 2017 (c) Analog Devices, Inc. All rights reserved.
|
|
|
|
//
|
|
|
|
// Each core or library found in this collection may have its own licensing terms.
|
|
|
|
// The user should keep this in in mind while exploring these cores.
|
|
|
|
//
|
|
|
|
// Redistribution and use in source and binary forms,
|
|
|
|
// with or without modification of this file, are permitted under the terms of either
|
|
|
|
// (at the option of the user):
|
|
|
|
//
|
|
|
|
// 1. The GNU General Public License version 2 as published by the
|
|
|
|
// Free Software Foundation, which can be found in the top level directory, or at:
|
|
|
|
// https://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html
|
|
|
|
//
|
|
|
|
// OR
|
|
|
|
//
|
|
|
|
// 2. An ADI specific BSD license as noted in the top level directory, or on-line at:
|
|
|
|
// https://github.com/analogdevicesinc/hdl/blob/dev/LICENSE
|
2015-04-07 19:35:47 +00:00
|
|
|
//
|
|
|
|
// ***************************************************************************
|
|
|
|
// ***************************************************************************
|
|
|
|
|
2015-04-09 12:30:29 +00:00
|
|
|
module util_axis_fifo (
|
2016-10-01 15:13:42 +00:00
|
|
|
input m_axis_aclk,
|
|
|
|
input m_axis_aresetn,
|
|
|
|
input m_axis_ready,
|
|
|
|
output m_axis_valid,
|
|
|
|
output [DATA_WIDTH-1:0] m_axis_data,
|
|
|
|
output [ADDRESS_WIDTH:0] m_axis_level,
|
|
|
|
|
|
|
|
input s_axis_aclk,
|
|
|
|
input s_axis_aresetn,
|
|
|
|
output s_axis_ready,
|
|
|
|
input s_axis_valid,
|
|
|
|
input [DATA_WIDTH-1:0] s_axis_data,
|
|
|
|
output s_axis_empty,
|
|
|
|
output [ADDRESS_WIDTH:0] s_axis_room
|
2015-04-07 19:35:47 +00:00
|
|
|
);
|
|
|
|
|
2015-08-19 11:11:47 +00:00
|
|
|
parameter DATA_WIDTH = 64;
|
|
|
|
parameter ASYNC_CLK = 1;
|
|
|
|
parameter ADDRESS_WIDTH = 4;
|
|
|
|
parameter S_AXIS_REGISTERED = 1;
|
2015-04-07 19:35:47 +00:00
|
|
|
|
2015-08-19 11:11:47 +00:00
|
|
|
generate if (ADDRESS_WIDTH == 0) begin
|
2015-04-07 19:35:47 +00:00
|
|
|
|
2015-08-19 11:11:47 +00:00
|
|
|
reg [DATA_WIDTH-1:0] cdc_sync_fifo_ram;
|
2015-04-07 19:35:47 +00:00
|
|
|
reg s_axis_waddr = 1'b0;
|
|
|
|
reg m_axis_raddr = 1'b0;
|
|
|
|
|
|
|
|
wire m_axis_waddr;
|
|
|
|
wire s_axis_raddr;
|
|
|
|
|
|
|
|
sync_bits #(
|
2016-10-01 15:13:42 +00:00
|
|
|
.NUM_OF_BITS(1),
|
|
|
|
.ASYNC_CLK(ASYNC_CLK)
|
2015-04-07 19:35:47 +00:00
|
|
|
) i_waddr_sync (
|
2016-10-01 15:13:42 +00:00
|
|
|
.out_clk(m_axis_aclk),
|
|
|
|
.out_resetn(m_axis_aresetn),
|
|
|
|
.in(s_axis_waddr),
|
|
|
|
.out(m_axis_waddr)
|
2015-04-07 19:35:47 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
sync_bits #(
|
2016-10-01 15:13:42 +00:00
|
|
|
.NUM_OF_BITS(1),
|
|
|
|
.ASYNC_CLK(ASYNC_CLK)
|
2015-04-07 19:35:47 +00:00
|
|
|
) i_raddr_sync (
|
2016-10-01 15:13:42 +00:00
|
|
|
.out_clk(s_axis_aclk),
|
|
|
|
.out_resetn(s_axis_aresetn),
|
|
|
|
.in(m_axis_raddr),
|
|
|
|
.out(s_axis_raddr)
|
2015-04-07 19:35:47 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
assign m_axis_valid = m_axis_raddr != m_axis_waddr;
|
2015-04-09 12:32:44 +00:00
|
|
|
assign m_axis_level = m_axis_valid;
|
2015-04-07 19:35:47 +00:00
|
|
|
assign s_axis_ready = s_axis_raddr == s_axis_waddr;
|
2015-04-09 12:32:44 +00:00
|
|
|
assign s_axis_empty = s_axis_ready;
|
|
|
|
assign s_axis_room = s_axis_ready;
|
2015-04-07 19:35:47 +00:00
|
|
|
|
|
|
|
always @(posedge s_axis_aclk) begin
|
2017-03-27 14:56:46 +00:00
|
|
|
if (s_axis_ready == 1'b1 && s_axis_valid == 1'b1)
|
2016-10-01 15:13:42 +00:00
|
|
|
cdc_sync_fifo_ram <= s_axis_data;
|
2015-04-07 19:35:47 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
always @(posedge s_axis_aclk) begin
|
2016-10-01 15:13:42 +00:00
|
|
|
if (s_axis_aresetn == 1'b0) begin
|
|
|
|
s_axis_waddr <= 1'b0;
|
|
|
|
end else begin
|
|
|
|
if (s_axis_ready & s_axis_valid) begin
|
|
|
|
s_axis_waddr <= s_axis_waddr + 1'b1;
|
|
|
|
end
|
|
|
|
end
|
2015-04-07 19:35:47 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
always @(posedge m_axis_aclk) begin
|
2016-10-01 15:13:42 +00:00
|
|
|
if (m_axis_aresetn == 1'b0) begin
|
|
|
|
m_axis_raddr <= 1'b0;
|
|
|
|
end else begin
|
|
|
|
if (m_axis_valid & m_axis_ready)
|
|
|
|
m_axis_raddr <= m_axis_raddr + 1'b1;
|
|
|
|
end
|
2015-04-07 19:35:47 +00:00
|
|
|
end
|
|
|
|
|
2015-04-14 16:54:26 +00:00
|
|
|
assign m_axis_data = cdc_sync_fifo_ram;
|
2015-04-07 19:35:47 +00:00
|
|
|
|
|
|
|
end else begin
|
|
|
|
|
2015-08-19 11:11:47 +00:00
|
|
|
reg [DATA_WIDTH-1:0] ram[0:2**ADDRESS_WIDTH-1];
|
2015-04-07 19:35:47 +00:00
|
|
|
|
2015-08-19 11:11:47 +00:00
|
|
|
wire [ADDRESS_WIDTH-1:0] s_axis_waddr;
|
|
|
|
wire [ADDRESS_WIDTH-1:0] m_axis_raddr;
|
2015-04-07 19:35:47 +00:00
|
|
|
wire _m_axis_ready;
|
|
|
|
wire _m_axis_valid;
|
|
|
|
|
2015-08-19 11:11:47 +00:00
|
|
|
if (ASYNC_CLK == 1) begin
|
2015-04-07 19:35:47 +00:00
|
|
|
|
|
|
|
fifo_address_gray_pipelined #(
|
2016-10-01 15:13:42 +00:00
|
|
|
.ADDRESS_WIDTH(ADDRESS_WIDTH)
|
2015-04-07 19:35:47 +00:00
|
|
|
) i_address_gray (
|
2016-10-01 15:13:42 +00:00
|
|
|
.m_axis_aclk(m_axis_aclk),
|
|
|
|
.m_axis_aresetn(m_axis_aresetn),
|
|
|
|
.m_axis_ready(_m_axis_ready),
|
|
|
|
.m_axis_valid(_m_axis_valid),
|
|
|
|
.m_axis_raddr(m_axis_raddr),
|
|
|
|
.m_axis_level(m_axis_level),
|
|
|
|
|
|
|
|
.s_axis_aclk(s_axis_aclk),
|
|
|
|
.s_axis_aresetn(s_axis_aresetn),
|
|
|
|
.s_axis_ready(s_axis_ready),
|
|
|
|
.s_axis_valid(s_axis_valid),
|
|
|
|
.s_axis_empty(s_axis_empty),
|
|
|
|
.s_axis_waddr(s_axis_waddr),
|
|
|
|
.s_axis_room(s_axis_room)
|
2015-04-07 19:35:47 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
end else begin
|
|
|
|
|
|
|
|
fifo_address_sync #(
|
2016-10-01 15:13:42 +00:00
|
|
|
.ADDRESS_WIDTH(ADDRESS_WIDTH)
|
2015-04-07 19:35:47 +00:00
|
|
|
) i_address_sync (
|
2016-10-01 15:13:42 +00:00
|
|
|
.clk(m_axis_aclk),
|
|
|
|
.resetn(m_axis_aresetn),
|
|
|
|
.m_axis_ready(_m_axis_ready),
|
|
|
|
.m_axis_valid(_m_axis_valid),
|
|
|
|
.m_axis_raddr(m_axis_raddr),
|
|
|
|
.m_axis_level(m_axis_level),
|
|
|
|
|
|
|
|
.s_axis_ready(s_axis_ready),
|
|
|
|
.s_axis_valid(s_axis_valid),
|
|
|
|
.s_axis_empty(s_axis_empty),
|
|
|
|
.s_axis_waddr(s_axis_waddr),
|
|
|
|
.s_axis_room(s_axis_room)
|
2015-04-07 19:35:47 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
always @(posedge s_axis_aclk) begin
|
2017-03-27 14:56:46 +00:00
|
|
|
if (s_axis_ready == 1'b1 && s_axis_valid == 1'b1)
|
2016-10-01 15:13:42 +00:00
|
|
|
ram[s_axis_waddr] <= s_axis_data;
|
2015-04-07 19:35:47 +00:00
|
|
|
end
|
|
|
|
|
2015-08-19 11:11:47 +00:00
|
|
|
if (S_AXIS_REGISTERED == 1) begin
|
2015-04-10 07:43:16 +00:00
|
|
|
|
2015-08-19 11:11:47 +00:00
|
|
|
reg [DATA_WIDTH-1:0] data;
|
2015-04-07 19:35:47 +00:00
|
|
|
reg valid;
|
|
|
|
|
|
|
|
always @(posedge m_axis_aclk) begin
|
2016-10-01 15:13:42 +00:00
|
|
|
if (m_axis_aresetn == 1'b0) begin
|
|
|
|
valid <= 1'b0;
|
|
|
|
end else begin
|
|
|
|
if (_m_axis_valid)
|
|
|
|
valid <= 1'b1;
|
|
|
|
else if (m_axis_ready)
|
|
|
|
valid <= 1'b0;
|
|
|
|
end
|
2015-04-07 19:35:47 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
always @(posedge m_axis_aclk) begin
|
2017-03-27 14:56:46 +00:00
|
|
|
if ((~valid || m_axis_ready) && _m_axis_valid)
|
2016-10-01 15:13:42 +00:00
|
|
|
data <= ram[m_axis_raddr];
|
2015-04-07 19:35:47 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
assign _m_axis_ready = ~valid || m_axis_ready;
|
|
|
|
assign m_axis_data = data;
|
|
|
|
assign m_axis_valid = valid;
|
|
|
|
|
2015-04-10 07:43:16 +00:00
|
|
|
end else begin
|
|
|
|
|
|
|
|
assign _m_axis_ready = m_axis_ready;
|
|
|
|
assign m_axis_valid = _m_axis_valid;
|
|
|
|
assign m_axis_data = ram[m_axis_raddr];
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2015-04-07 19:35:47 +00:00
|
|
|
end endgenerate
|
|
|
|
|
|
|
|
endmodule
|