2015-06-26 09:04:19 +00:00
|
|
|
// ***************************************************************************
|
|
|
|
// ***************************************************************************
|
2017-05-17 08:44:52 +00:00
|
|
|
// Copyright 2014 - 2017 (c) Analog Devices, Inc. All rights reserved.
|
2015-09-23 13:30:31 +00:00
|
|
|
//
|
2017-05-31 15:15:24 +00:00
|
|
|
// In this HDL repository, there are many different and unique modules, consisting
|
|
|
|
// of various HDL (Verilog or VHDL) components. The individual modules are
|
|
|
|
// developed independently, and may be accompanied by separate and unique license
|
|
|
|
// terms.
|
|
|
|
//
|
|
|
|
// The user should read each of these license terms, and understand the
|
2018-03-14 14:45:47 +00:00
|
|
|
// freedoms and responsibilities that he or she has by using this source/core.
|
2017-05-31 15:15:24 +00:00
|
|
|
//
|
|
|
|
// This core is distributed in the hope that it will be useful, but WITHOUT ANY
|
2017-05-29 06:55:41 +00:00
|
|
|
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
|
|
|
// A PARTICULAR PURPOSE.
|
2015-09-23 13:30:31 +00:00
|
|
|
//
|
2017-05-29 06:55:41 +00:00
|
|
|
// Redistribution and use of source or resulting binaries, with or without modification
|
|
|
|
// of this file, are permitted under one of the following two license terms:
|
2015-09-23 13:30:31 +00:00
|
|
|
//
|
2017-05-17 08:44:52 +00:00
|
|
|
// 1. The GNU General Public License version 2 as published by the
|
2017-05-31 15:15:24 +00:00
|
|
|
// Free Software Foundation, which can be found in the top level directory
|
|
|
|
// of this repository (LICENSE_GPL2), and also online at:
|
|
|
|
// <https://www.gnu.org/licenses/old-licenses/gpl-2.0.html>
|
2017-05-17 08:44:52 +00:00
|
|
|
//
|
|
|
|
// OR
|
|
|
|
//
|
2017-05-31 15:15:24 +00:00
|
|
|
// 2. An ADI specific BSD license, which can be found in the top level directory
|
|
|
|
// of this repository (LICENSE_ADIBSD), and also on-line at:
|
2017-05-29 06:55:41 +00:00
|
|
|
// https://github.com/analogdevicesinc/hdl/blob/master/LICENSE_ADIBSD
|
|
|
|
// This will allow to generate bit files and not release the source code,
|
|
|
|
// as long as it attaches to an ADI device.
|
2015-06-26 09:04:19 +00:00
|
|
|
//
|
|
|
|
// ***************************************************************************
|
|
|
|
// ***************************************************************************
|
|
|
|
|
|
|
|
`timescale 1ns/100ps
|
|
|
|
|
2017-04-13 08:45:54 +00:00
|
|
|
module util_wfifo #(
|
|
|
|
|
|
|
|
parameter NUM_OF_CHANNELS = 4,
|
|
|
|
parameter DIN_DATA_WIDTH = 32,
|
|
|
|
parameter DOUT_DATA_WIDTH = 64,
|
2022-04-08 10:21:52 +00:00
|
|
|
parameter DIN_ADDRESS_WIDTH = 8
|
|
|
|
) (
|
2015-06-26 09:04:19 +00:00
|
|
|
|
|
|
|
// d-in interface
|
|
|
|
|
2017-04-13 08:45:54 +00:00
|
|
|
input din_rst,
|
|
|
|
input din_clk,
|
|
|
|
input din_enable_0,
|
|
|
|
input din_valid_0,
|
|
|
|
input [DIN_DATA_WIDTH-1:0] din_data_0,
|
|
|
|
input din_enable_1,
|
|
|
|
input din_valid_1,
|
|
|
|
input [DIN_DATA_WIDTH-1:0] din_data_1,
|
|
|
|
input din_enable_2,
|
|
|
|
input din_valid_2,
|
|
|
|
input [DIN_DATA_WIDTH-1:0] din_data_2,
|
|
|
|
input din_enable_3,
|
|
|
|
input din_valid_3,
|
|
|
|
input [DIN_DATA_WIDTH-1:0] din_data_3,
|
|
|
|
input din_enable_4,
|
|
|
|
input din_valid_4,
|
|
|
|
input [DIN_DATA_WIDTH-1:0] din_data_4,
|
|
|
|
input din_enable_5,
|
|
|
|
input din_valid_5,
|
|
|
|
input [DIN_DATA_WIDTH-1:0] din_data_5,
|
|
|
|
input din_enable_6,
|
|
|
|
input din_valid_6,
|
|
|
|
input [DIN_DATA_WIDTH-1:0] din_data_6,
|
|
|
|
input din_enable_7,
|
|
|
|
input din_valid_7,
|
|
|
|
input [DIN_DATA_WIDTH-1:0] din_data_7,
|
|
|
|
output reg din_ovf,
|
2015-06-26 09:04:19 +00:00
|
|
|
|
|
|
|
// d-out interface
|
|
|
|
|
2017-04-13 08:45:54 +00:00
|
|
|
input dout_rstn,
|
|
|
|
input dout_clk,
|
|
|
|
output dout_enable_0,
|
|
|
|
output dout_valid_0,
|
|
|
|
output [DOUT_DATA_WIDTH-1:0] dout_data_0,
|
|
|
|
output dout_enable_1,
|
|
|
|
output dout_valid_1,
|
|
|
|
output [DOUT_DATA_WIDTH-1:0] dout_data_1,
|
|
|
|
output dout_enable_2,
|
|
|
|
output dout_valid_2,
|
|
|
|
output [DOUT_DATA_WIDTH-1:0] dout_data_2,
|
|
|
|
output dout_enable_3,
|
|
|
|
output dout_valid_3,
|
|
|
|
output [DOUT_DATA_WIDTH-1:0] dout_data_3,
|
|
|
|
output dout_enable_4,
|
|
|
|
output dout_valid_4,
|
|
|
|
output [DOUT_DATA_WIDTH-1:0] dout_data_4,
|
|
|
|
output dout_enable_5,
|
|
|
|
output dout_valid_5,
|
|
|
|
output [DOUT_DATA_WIDTH-1:0] dout_data_5,
|
|
|
|
output dout_enable_6,
|
|
|
|
output dout_valid_6,
|
|
|
|
output [DOUT_DATA_WIDTH-1:0] dout_data_6,
|
|
|
|
output dout_enable_7,
|
|
|
|
output dout_valid_7,
|
|
|
|
output [DOUT_DATA_WIDTH-1:0] dout_data_7,
|
2022-04-08 10:21:52 +00:00
|
|
|
input dout_ovf
|
|
|
|
);
|
2015-06-26 09:04:19 +00:00
|
|
|
|
|
|
|
localparam M_MEM_RATIO = DOUT_DATA_WIDTH/DIN_DATA_WIDTH;
|
2015-08-19 11:11:47 +00:00
|
|
|
localparam ADDRESS_WIDTH = (DIN_ADDRESS_WIDTH > 4) ? DIN_ADDRESS_WIDTH : 4;
|
2015-06-26 09:04:19 +00:00
|
|
|
localparam DATA_WIDTH = DOUT_DATA_WIDTH * NUM_OF_CHANNELS;
|
|
|
|
localparam T_DIN_DATA_WIDTH = DIN_DATA_WIDTH * 8;
|
|
|
|
localparam T_DOUT_DATA_WIDTH = DOUT_DATA_WIDTH * 8;
|
|
|
|
|
|
|
|
// internal registers
|
|
|
|
|
|
|
|
reg [(DATA_WIDTH-1):0] din_wdata = 'd0;
|
|
|
|
reg [ 7:0] din_enable = 'd0;
|
|
|
|
reg din_wr = 'd0;
|
2015-09-23 13:30:31 +00:00
|
|
|
reg [(ADDRESS_WIDTH-1):0] din_waddr = 'd0;
|
2016-05-16 16:12:56 +00:00
|
|
|
reg din_req_t = 'd0;
|
2016-07-11 13:59:31 +00:00
|
|
|
reg [(ADDRESS_WIDTH-4):0] din_rinit = 'd0;
|
2016-05-16 16:12:56 +00:00
|
|
|
reg din_ovf_m1 = 'd0;
|
|
|
|
reg dout_req_t_m1 = 'd0;
|
|
|
|
reg dout_req_t_m2 = 'd0;
|
|
|
|
reg dout_req_t_m3 = 'd0;
|
2016-07-11 13:59:31 +00:00
|
|
|
reg dout_req_t = 'd0;
|
|
|
|
reg [(ADDRESS_WIDTH-4):0] dout_rinit = 'd0;
|
2016-05-18 17:22:38 +00:00
|
|
|
reg dout_ovf_d = 'd0;
|
2016-05-16 16:12:56 +00:00
|
|
|
reg [ 3:0] dout_req_cnt = 'd0;
|
2017-03-20 16:14:13 +00:00
|
|
|
reg [(ADDRESS_WIDTH-1):0] dout_raddr = 'd8;
|
2016-07-11 13:59:31 +00:00
|
|
|
reg dout_rd_d = 'd0;
|
2016-05-16 16:12:56 +00:00
|
|
|
reg dout_valid = 'd0;
|
|
|
|
reg [ 7:0] dout_enable_m1 = 'd0;
|
|
|
|
reg [ 7:0] dout_enable = 'd0;
|
|
|
|
reg [(DATA_WIDTH-1):0] dout_rdata = 'd0;
|
2015-06-26 09:04:19 +00:00
|
|
|
|
|
|
|
// internal signals
|
|
|
|
|
|
|
|
wire [ 7:0] din_enable_s;
|
|
|
|
wire [ 7:0] din_valid_s;
|
|
|
|
wire [(T_DIN_DATA_WIDTH-1):0] din_data_s;
|
2016-05-16 16:12:56 +00:00
|
|
|
wire dout_req_t_s;
|
2015-06-26 09:04:19 +00:00
|
|
|
wire [(DATA_WIDTH-1):0] dout_rdata_s;
|
|
|
|
wire [(T_DOUT_DATA_WIDTH+1):0] dout_data_s;
|
2018-03-06 08:51:21 +00:00
|
|
|
wire [ 2:0] din_dcnt_s;
|
2015-06-26 09:04:19 +00:00
|
|
|
|
|
|
|
// variables
|
|
|
|
|
|
|
|
genvar n;
|
|
|
|
|
|
|
|
// concat signals, valid_0 must always be active
|
|
|
|
|
|
|
|
assign din_enable_s = { din_enable_7, din_enable_6, din_enable_5, din_enable_4,
|
|
|
|
din_enable_3, din_enable_2, din_enable_1, din_enable_0};
|
|
|
|
assign din_valid_s = { din_valid_7, din_valid_6, din_valid_5, din_valid_4,
|
|
|
|
din_valid_3, din_valid_2, din_valid_1, din_valid_0};
|
|
|
|
assign din_data_s = { din_data_7, din_data_6, din_data_5, din_data_4,
|
|
|
|
din_data_3, din_data_2, din_data_1, din_data_0};
|
|
|
|
|
2016-07-11 13:59:31 +00:00
|
|
|
// simple data transfer-- no ovf/unf handling- read-bw > write-bw (equal will NOT work)
|
|
|
|
// dout_width >= din_width only-
|
2015-06-26 09:04:19 +00:00
|
|
|
|
|
|
|
generate
|
|
|
|
for (n = 0; n < NUM_OF_CHANNELS; n = n + 1) begin: g_in
|
|
|
|
if (M_MEM_RATIO == 1) begin
|
|
|
|
always @(posedge din_clk) begin
|
|
|
|
if (din_valid_s[n] == 1'b1) begin
|
|
|
|
din_wdata[((DOUT_DATA_WIDTH*(n+1))-1):(DOUT_DATA_WIDTH*n)] <=
|
|
|
|
din_data_s[((DIN_DATA_WIDTH*(n+1))-1):(DIN_DATA_WIDTH*n)];
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end else begin
|
|
|
|
always @(posedge din_clk) begin
|
|
|
|
if (din_valid_s[n] == 1'b1) begin
|
|
|
|
din_wdata[((DOUT_DATA_WIDTH*(n+1))-1):(DOUT_DATA_WIDTH*n)] <=
|
|
|
|
{din_data_s[((DIN_DATA_WIDTH*(n+1))-1):(DIN_DATA_WIDTH*n)],
|
|
|
|
din_wdata[((DOUT_DATA_WIDTH*(n+1))-1):(DIN_DATA_WIDTH+(DOUT_DATA_WIDTH*n))]};
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
endgenerate
|
|
|
|
|
2018-03-06 08:51:21 +00:00
|
|
|
generate
|
|
|
|
if (M_MEM_RATIO == 1) begin
|
|
|
|
assign din_dcnt_s = 'b0;
|
|
|
|
end else begin
|
|
|
|
reg [ 2:0] din_dcnt = 'd0;
|
|
|
|
|
|
|
|
always @(posedge din_clk)
|
|
|
|
if (din_rst == 1'b1) begin
|
|
|
|
din_dcnt <= 'd0;
|
|
|
|
end else begin
|
|
|
|
if (din_valid_s[0] == 1'b1) begin
|
|
|
|
din_dcnt <= din_dcnt + 1'b1;
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
assign din_dcnt_s = din_dcnt;
|
|
|
|
end
|
|
|
|
endgenerate
|
2015-06-26 09:04:19 +00:00
|
|
|
always @(posedge din_clk) begin
|
|
|
|
if (din_rst == 1'b1) begin
|
|
|
|
din_enable <= 8'd0;
|
|
|
|
din_wr <= 1'd0;
|
2016-05-16 16:12:56 +00:00
|
|
|
din_waddr <= 'd0;
|
|
|
|
din_req_t <= 1'd0;
|
2016-07-11 13:59:31 +00:00
|
|
|
din_rinit <= 'd0;
|
2016-05-16 16:12:56 +00:00
|
|
|
din_ovf_m1 <= 'd0;
|
2015-06-26 09:04:19 +00:00
|
|
|
din_ovf <= 'd0;
|
|
|
|
end else begin
|
|
|
|
din_enable <= din_enable_s;
|
2022-04-08 10:21:52 +00:00
|
|
|
case (M_MEM_RATIO)
|
2018-03-06 08:51:21 +00:00
|
|
|
8: din_wr <= din_valid_s[0] & din_dcnt_s[0] & din_dcnt_s[1] & din_dcnt_s[2];
|
|
|
|
4: din_wr <= din_valid_s[0] & din_dcnt_s[0] & din_dcnt_s[1];
|
|
|
|
2: din_wr <= din_valid_s[0] & din_dcnt_s[0];
|
2015-06-26 09:04:19 +00:00
|
|
|
default: din_wr <= din_valid_s[0];
|
|
|
|
endcase
|
|
|
|
if (din_wr == 1'b1) begin
|
|
|
|
din_waddr <= din_waddr + 1'b1;
|
|
|
|
end
|
2016-07-11 13:59:31 +00:00
|
|
|
if ((din_wr == 1'b1) && (din_waddr[2:0] == 3'd7)) begin
|
2016-05-16 16:12:56 +00:00
|
|
|
din_req_t <= ~din_req_t;
|
2016-07-11 13:59:31 +00:00
|
|
|
din_rinit <= din_waddr[(ADDRESS_WIDTH-1):3];
|
2015-06-26 09:04:19 +00:00
|
|
|
end
|
2016-05-18 17:22:38 +00:00
|
|
|
din_ovf_m1 <= dout_ovf_d;
|
2016-05-16 16:12:56 +00:00
|
|
|
din_ovf <= din_ovf_m1;
|
2015-06-26 09:04:19 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
// read interface (bus expansion and/or clock conversion)
|
|
|
|
|
2016-05-16 16:12:56 +00:00
|
|
|
assign dout_req_t_s = dout_req_t_m3 ^ dout_req_t_m2;
|
2015-06-26 09:04:19 +00:00
|
|
|
|
|
|
|
always @(posedge dout_clk or negedge dout_rstn) begin
|
|
|
|
if (dout_rstn == 1'b0) begin
|
2016-05-16 16:12:56 +00:00
|
|
|
dout_req_t_m1 <= 'd0;
|
|
|
|
dout_req_t_m2 <= 'd0;
|
|
|
|
dout_req_t_m3 <= 'd0;
|
2016-07-11 13:59:31 +00:00
|
|
|
dout_req_t <= 'd0;
|
|
|
|
dout_rinit <= 'd0;
|
2016-05-18 17:22:38 +00:00
|
|
|
dout_ovf_d <= 'd0;
|
2015-06-26 09:04:19 +00:00
|
|
|
end else begin
|
2016-05-16 16:12:56 +00:00
|
|
|
dout_req_t_m1 <= din_req_t;
|
|
|
|
dout_req_t_m2 <= dout_req_t_m1;
|
|
|
|
dout_req_t_m3 <= dout_req_t_m2;
|
2016-07-11 13:59:31 +00:00
|
|
|
dout_req_t <= dout_req_t_s;
|
|
|
|
if (dout_req_t_s == 1'b1) begin
|
|
|
|
dout_rinit <= din_rinit;
|
|
|
|
end
|
2016-05-18 17:22:38 +00:00
|
|
|
dout_ovf_d <= dout_ovf;
|
2015-06-26 09:04:19 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
always @(posedge dout_clk or negedge dout_rstn) begin
|
|
|
|
if (dout_rstn == 1'b0) begin
|
2016-05-16 16:12:56 +00:00
|
|
|
dout_req_cnt <= 'd0;
|
2016-07-11 13:59:31 +00:00
|
|
|
dout_raddr <= 'd8;
|
|
|
|
dout_rd_d <= 'd0;
|
2016-05-16 16:12:56 +00:00
|
|
|
dout_valid <= 'd0;
|
2015-09-16 15:55:47 +00:00
|
|
|
end else begin
|
2016-07-11 13:59:31 +00:00
|
|
|
if (dout_req_t == 1'b1) begin
|
2016-05-16 16:12:56 +00:00
|
|
|
dout_req_cnt <= 4'h8;
|
2016-07-11 13:59:31 +00:00
|
|
|
dout_raddr <= {dout_rinit, 3'd0};
|
2016-05-16 16:12:56 +00:00
|
|
|
end else if (dout_req_cnt[3] == 1'b1) begin
|
|
|
|
dout_req_cnt <= dout_req_cnt + 1'b1;
|
|
|
|
dout_raddr <= dout_raddr + 1'b1;
|
|
|
|
end
|
2016-07-11 13:59:31 +00:00
|
|
|
dout_rd_d <= dout_req_cnt[3];
|
|
|
|
dout_valid <= dout_rd_d;
|
2015-09-16 15:55:47 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-05-16 16:12:56 +00:00
|
|
|
always @(posedge dout_clk or negedge dout_rstn) begin
|
2015-09-16 15:55:47 +00:00
|
|
|
if (dout_rstn == 1'b0) begin
|
2016-05-16 16:12:56 +00:00
|
|
|
dout_enable_m1 <= 'd0;
|
|
|
|
dout_enable <= 'd0;
|
2015-06-26 09:04:19 +00:00
|
|
|
end else begin
|
2016-05-16 16:12:56 +00:00
|
|
|
dout_enable_m1 <= din_enable;
|
|
|
|
dout_enable <= dout_enable_m1;
|
2015-06-26 09:04:19 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-05-16 16:12:56 +00:00
|
|
|
always @(posedge dout_clk) begin
|
|
|
|
dout_rdata <= dout_rdata_s;
|
|
|
|
end
|
|
|
|
|
|
|
|
generate
|
|
|
|
if (NUM_OF_CHANNELS >= 8) begin
|
|
|
|
assign dout_data_s = dout_rdata;
|
|
|
|
end else begin
|
|
|
|
assign dout_data_s[(T_DOUT_DATA_WIDTH+1):DATA_WIDTH] = 'd0;
|
|
|
|
assign dout_data_s[(DATA_WIDTH-1):0] = dout_rdata;
|
|
|
|
end
|
|
|
|
endgenerate
|
|
|
|
|
2015-06-26 09:04:19 +00:00
|
|
|
assign dout_enable_7 = dout_enable[7];
|
2016-05-16 16:12:56 +00:00
|
|
|
assign dout_valid_7 = dout_valid;
|
2015-06-26 09:04:19 +00:00
|
|
|
assign dout_data_7 = dout_data_s[((DOUT_DATA_WIDTH*8)-1):(DOUT_DATA_WIDTH*7)];
|
|
|
|
|
|
|
|
assign dout_enable_6 = dout_enable[6];
|
2016-05-16 16:12:56 +00:00
|
|
|
assign dout_valid_6 = dout_valid;
|
2015-06-26 09:04:19 +00:00
|
|
|
assign dout_data_6 = dout_data_s[((DOUT_DATA_WIDTH*7)-1):(DOUT_DATA_WIDTH*6)];
|
|
|
|
|
|
|
|
assign dout_enable_5 = dout_enable[5];
|
2016-05-16 16:12:56 +00:00
|
|
|
assign dout_valid_5 = dout_valid;
|
2015-06-26 09:04:19 +00:00
|
|
|
assign dout_data_5 = dout_data_s[((DOUT_DATA_WIDTH*6)-1):(DOUT_DATA_WIDTH*5)];
|
|
|
|
|
|
|
|
assign dout_enable_4 = dout_enable[4];
|
2016-05-16 16:12:56 +00:00
|
|
|
assign dout_valid_4 = dout_valid;
|
2015-06-26 09:04:19 +00:00
|
|
|
assign dout_data_4 = dout_data_s[((DOUT_DATA_WIDTH*5)-1):(DOUT_DATA_WIDTH*4)];
|
|
|
|
|
|
|
|
assign dout_enable_3 = dout_enable[3];
|
2016-05-16 16:12:56 +00:00
|
|
|
assign dout_valid_3 = dout_valid;
|
2015-06-26 09:04:19 +00:00
|
|
|
assign dout_data_3 = dout_data_s[((DOUT_DATA_WIDTH*4)-1):(DOUT_DATA_WIDTH*3)];
|
|
|
|
|
|
|
|
assign dout_enable_2 = dout_enable[2];
|
2016-05-16 16:12:56 +00:00
|
|
|
assign dout_valid_2 = dout_valid;
|
2015-06-26 09:04:19 +00:00
|
|
|
assign dout_data_2 = dout_data_s[((DOUT_DATA_WIDTH*3)-1):(DOUT_DATA_WIDTH*2)];
|
|
|
|
|
|
|
|
assign dout_enable_1 = dout_enable[1];
|
2016-05-16 16:12:56 +00:00
|
|
|
assign dout_valid_1 = dout_valid;
|
2015-06-26 09:04:19 +00:00
|
|
|
assign dout_data_1 = dout_data_s[((DOUT_DATA_WIDTH*2)-1):(DOUT_DATA_WIDTH*1)];
|
|
|
|
|
|
|
|
assign dout_enable_0 = dout_enable[0];
|
2016-05-16 16:12:56 +00:00
|
|
|
assign dout_valid_0 = dout_valid;
|
2015-06-26 09:04:19 +00:00
|
|
|
assign dout_data_0 = dout_data_s[((DOUT_DATA_WIDTH*1)-1):(DOUT_DATA_WIDTH*0)];
|
|
|
|
|
|
|
|
// instantiations
|
|
|
|
|
2022-04-08 10:21:52 +00:00
|
|
|
ad_mem #(
|
|
|
|
.ADDRESS_WIDTH(ADDRESS_WIDTH),
|
|
|
|
.DATA_WIDTH(DATA_WIDTH)
|
|
|
|
) i_mem (
|
2015-06-26 09:04:19 +00:00
|
|
|
.clka (din_clk),
|
|
|
|
.wea (din_wr),
|
|
|
|
.addra (din_waddr),
|
|
|
|
.dina (din_wdata),
|
|
|
|
.clkb (dout_clk),
|
2018-03-19 09:34:20 +00:00
|
|
|
.reb (1'b1),
|
2015-06-26 09:04:19 +00:00
|
|
|
.addrb (dout_raddr),
|
|
|
|
.doutb (dout_rdata_s));
|
|
|
|
|
|
|
|
endmodule
|