2017-02-23 15:32:31 +00:00
|
|
|
// ***************************************************************************
|
|
|
|
// ***************************************************************************
|
2023-07-06 13:54:40 +00:00
|
|
|
// Copyright (C) 2014-2023 Analog Devices, Inc. All rights reserved.
|
2017-02-23 15:32: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.
|
2017-02-23 15:32: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:
|
2017-02-23 15:32: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:
|
2023-12-13 16:03:34 +00:00
|
|
|
// https://github.com/analogdevicesinc/hdl/blob/main/LICENSE_ADIBSD
|
2017-05-29 06:55:41 +00:00
|
|
|
// This will allow to generate bit files and not release the source code,
|
|
|
|
// as long as it attaches to an ADI device.
|
2017-02-23 15:32:31 +00:00
|
|
|
//
|
|
|
|
// ***************************************************************************
|
|
|
|
// ***************************************************************************
|
|
|
|
|
|
|
|
`timescale 1ns/100ps
|
|
|
|
|
2017-04-21 10:23:03 +00:00
|
|
|
module util_dacfifo_bypass #(
|
2017-02-23 15:32:31 +00:00
|
|
|
|
|
|
|
parameter DAC_DATA_WIDTH = 64,
|
2022-04-08 10:21:52 +00:00
|
|
|
parameter DMA_DATA_WIDTH = 64
|
|
|
|
) (
|
2017-02-23 15:32:31 +00:00
|
|
|
|
2018-06-06 11:54:48 +00:00
|
|
|
// DMA FIFO interface
|
2017-02-23 15:32:31 +00:00
|
|
|
|
|
|
|
input dma_clk,
|
|
|
|
input [(DMA_DATA_WIDTH-1):0] dma_data,
|
|
|
|
input dma_ready,
|
|
|
|
output reg dma_ready_out,
|
|
|
|
input dma_valid,
|
|
|
|
|
2018-06-05 09:39:29 +00:00
|
|
|
// request and synchronization
|
2017-02-23 15:32:31 +00:00
|
|
|
|
|
|
|
input dma_xfer_req,
|
|
|
|
|
2018-06-06 11:54:48 +00:00
|
|
|
// DAC FIFO interface
|
2017-02-23 15:32:31 +00:00
|
|
|
|
|
|
|
input dac_clk,
|
|
|
|
input dac_rst,
|
|
|
|
input dac_valid,
|
|
|
|
output reg [(DAC_DATA_WIDTH-1):0] dac_data,
|
|
|
|
output reg dac_dunf
|
|
|
|
);
|
|
|
|
|
2018-06-05 09:39:29 +00:00
|
|
|
// supported ratios: 1:1 / 1:2 / 1:4 / 1:8 / 2:1 / 4:1 / 8:1
|
2017-02-23 15:32:31 +00:00
|
|
|
|
|
|
|
localparam MEM_RATIO = (DMA_DATA_WIDTH > DAC_DATA_WIDTH) ? DMA_DATA_WIDTH/DAC_DATA_WIDTH :
|
|
|
|
DAC_DATA_WIDTH/DMA_DATA_WIDTH;
|
2018-08-21 12:56:15 +00:00
|
|
|
localparam DAC_ADDRESS_WIDTH = 4;
|
2017-02-23 15:32:31 +00:00
|
|
|
localparam DMA_ADDRESS_WIDTH = (MEM_RATIO == 1) ? DAC_ADDRESS_WIDTH :
|
|
|
|
(MEM_RATIO == 2) ? ((DMA_DATA_WIDTH > DAC_DATA_WIDTH) ? (DAC_ADDRESS_WIDTH - 1) : (DAC_ADDRESS_WIDTH + 1)) :
|
|
|
|
(MEM_RATIO == 4) ? ((DMA_DATA_WIDTH > DAC_DATA_WIDTH) ? (DAC_ADDRESS_WIDTH - 2) : (DAC_ADDRESS_WIDTH + 2)) :
|
|
|
|
((DMA_DATA_WIDTH > DAC_DATA_WIDTH) ? (DAC_ADDRESS_WIDTH - 3) : (DAC_ADDRESS_WIDTH + 3));
|
|
|
|
localparam DMA_BUF_THRESHOLD_HI = {(DMA_ADDRESS_WIDTH){1'b1}} - 4;
|
|
|
|
localparam DAC_BUF_THRESHOLD_LO = 4;
|
|
|
|
|
|
|
|
reg [(DMA_ADDRESS_WIDTH-1):0] dma_mem_waddr = 'd0;
|
|
|
|
reg [(DMA_ADDRESS_WIDTH-1):0] dma_mem_waddr_g = 'd0;
|
|
|
|
reg [(DAC_ADDRESS_WIDTH-1):0] dac_mem_raddr = 'd0;
|
|
|
|
reg [(DAC_ADDRESS_WIDTH-1):0] dac_mem_raddr_g = 'd0;
|
2018-06-05 10:28:29 +00:00
|
|
|
reg dac_mem_rea = 1'b0;
|
2017-02-23 15:32:31 +00:00
|
|
|
reg dma_rst_m1 = 1'b0;
|
|
|
|
reg dma_rst = 1'b0;
|
2018-06-05 09:39:29 +00:00
|
|
|
reg [DMA_ADDRESS_WIDTH-1:0] dma_mem_addr_diff = 'd0;
|
|
|
|
reg [(DAC_ADDRESS_WIDTH-1):0] dma_mem_raddr_m1 = 'd0;
|
|
|
|
reg [(DAC_ADDRESS_WIDTH-1):0] dma_mem_raddr_m2 = 'd0;
|
|
|
|
reg [(DAC_ADDRESS_WIDTH-1):0] dma_mem_raddr = 'd0;
|
|
|
|
reg [(DMA_ADDRESS_WIDTH-1):0] dac_mem_waddr_m1 = 'd0;
|
|
|
|
reg [(DMA_ADDRESS_WIDTH-1):0] dac_mem_waddr_m2 = 'd0;
|
|
|
|
reg [(DMA_ADDRESS_WIDTH-1):0] dac_mem_waddr = 'd0;
|
2017-02-23 15:32:31 +00:00
|
|
|
|
|
|
|
// internal signals
|
|
|
|
|
|
|
|
wire [(DMA_ADDRESS_WIDTH-1):0] dma_mem_raddr_s;
|
|
|
|
wire [(DAC_ADDRESS_WIDTH-1):0] dac_mem_waddr_s;
|
|
|
|
wire dma_mem_wea_s;
|
|
|
|
wire dac_mem_rea_s;
|
|
|
|
wire [(DAC_DATA_WIDTH-1):0] dac_mem_rdata_s;
|
|
|
|
wire [DMA_ADDRESS_WIDTH:0] dma_address_diff_s;
|
2018-06-05 10:28:29 +00:00
|
|
|
wire dac_mem_empty_s;
|
2017-02-23 15:32:31 +00:00
|
|
|
|
2018-06-04 06:36:42 +00:00
|
|
|
wire [(DMA_ADDRESS_WIDTH-1):0] dma_mem_waddr_b2g_s;
|
|
|
|
wire [(DAC_ADDRESS_WIDTH-1):0] dac_mem_raddr_b2g_s;
|
|
|
|
wire [(DAC_ADDRESS_WIDTH-1):0] dma_mem_raddr_m2_g2b_s;
|
|
|
|
wire [(DMA_ADDRESS_WIDTH-1):0] dac_mem_waddr_m2_g2b_s;
|
2017-02-23 15:32:31 +00:00
|
|
|
|
2018-06-06 11:54:48 +00:00
|
|
|
// an asymmetric memory, storage element of the FIFO
|
2017-02-23 15:32:31 +00:00
|
|
|
|
|
|
|
ad_mem_asym #(
|
|
|
|
.A_ADDRESS_WIDTH (DMA_ADDRESS_WIDTH),
|
|
|
|
.A_DATA_WIDTH (DMA_DATA_WIDTH),
|
|
|
|
.B_ADDRESS_WIDTH (DAC_ADDRESS_WIDTH),
|
2022-04-08 10:21:52 +00:00
|
|
|
.B_DATA_WIDTH (DAC_DATA_WIDTH)
|
|
|
|
) i_mem_asym (
|
2017-02-23 15:32:31 +00:00
|
|
|
.clka (dma_clk),
|
|
|
|
.wea (dma_mem_wea_s),
|
|
|
|
.addra (dma_mem_waddr),
|
|
|
|
.dina (dma_data),
|
|
|
|
.clkb (dac_clk),
|
2018-07-19 13:44:04 +00:00
|
|
|
.reb (1'b1),
|
2017-02-23 15:32:31 +00:00
|
|
|
.addrb (dac_mem_raddr),
|
|
|
|
.doutb (dac_mem_rdata_s));
|
|
|
|
|
2018-06-06 11:54:48 +00:00
|
|
|
// DMA reset is brought from dac domain
|
2017-02-23 15:32:31 +00:00
|
|
|
|
|
|
|
always @(posedge dma_clk) begin
|
|
|
|
dma_rst_m1 <= dac_rst;
|
|
|
|
dma_rst <= dma_rst_m1;
|
|
|
|
end
|
|
|
|
|
2018-06-06 11:54:48 +00:00
|
|
|
// write address generation for the asymmetric FIFO
|
2017-02-23 15:32:31 +00:00
|
|
|
|
2018-09-05 08:30:49 +00:00
|
|
|
assign dma_mem_wea_s = dma_valid & dma_ready;
|
2017-02-23 15:32:31 +00:00
|
|
|
|
|
|
|
always @(posedge dma_clk) begin
|
|
|
|
if (dma_rst == 1'b1) begin
|
|
|
|
dma_mem_waddr <= 'h0;
|
|
|
|
dma_mem_waddr_g <= 'h0;
|
|
|
|
end else begin
|
|
|
|
if (dma_mem_wea_s == 1'b1) begin
|
2018-06-04 06:36:42 +00:00
|
|
|
dma_mem_waddr <= dma_mem_waddr + 1'b1;
|
2017-02-23 15:32:31 +00:00
|
|
|
end
|
2018-06-04 06:36:42 +00:00
|
|
|
dma_mem_waddr_g <= dma_mem_waddr_b2g_s;
|
2017-02-23 15:32:31 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-06-04 06:36:42 +00:00
|
|
|
ad_b2g #(
|
2022-04-08 10:21:52 +00:00
|
|
|
.DATA_WIDTH (DMA_ADDRESS_WIDTH)
|
|
|
|
) i_dma_mem_waddr_b2g (
|
2018-06-04 06:36:42 +00:00
|
|
|
.din (dma_mem_waddr),
|
|
|
|
.dout (dma_mem_waddr_b2g_s));
|
|
|
|
|
2018-06-06 11:54:48 +00:00
|
|
|
// FIFO request data until reaches the high threshold.
|
2017-02-23 15:32:31 +00:00
|
|
|
|
|
|
|
always @(posedge dma_clk) begin
|
|
|
|
if (dma_rst == 1'b1) begin
|
|
|
|
dma_mem_addr_diff <= 'b0;
|
|
|
|
dma_mem_raddr_m1 <= 'b0;
|
|
|
|
dma_mem_raddr_m2 <= 'b0;
|
|
|
|
dma_mem_raddr <= 'b0;
|
|
|
|
dma_ready_out <= 1'b0;
|
|
|
|
end else begin
|
|
|
|
dma_mem_raddr_m1 <= dac_mem_raddr_g;
|
|
|
|
dma_mem_raddr_m2 <= dma_mem_raddr_m1;
|
2018-06-04 06:36:42 +00:00
|
|
|
dma_mem_raddr <= dma_mem_raddr_m2_g2b_s;
|
2017-02-23 15:32:31 +00:00
|
|
|
dma_mem_addr_diff <= dma_address_diff_s[DMA_ADDRESS_WIDTH-1:0];
|
|
|
|
if (dma_mem_addr_diff >= DMA_BUF_THRESHOLD_HI) begin
|
|
|
|
dma_ready_out <= 1'b0;
|
|
|
|
end else begin
|
|
|
|
dma_ready_out <= 1'b1;
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-06-04 06:36:42 +00:00
|
|
|
ad_g2b #(
|
2022-04-08 10:21:52 +00:00
|
|
|
.DATA_WIDTH (DAC_ADDRESS_WIDTH)
|
|
|
|
) i_dma_mem_raddr_g2b (
|
2018-06-04 06:36:42 +00:00
|
|
|
.din (dma_mem_raddr_m2),
|
|
|
|
.dout (dma_mem_raddr_m2_g2b_s));
|
|
|
|
|
2018-06-06 11:54:48 +00:00
|
|
|
// relative address offset on DMA domain
|
2017-02-23 15:32:31 +00:00
|
|
|
assign dma_address_diff_s = {1'b1, dma_mem_waddr} - dma_mem_raddr_s;
|
|
|
|
assign dma_mem_raddr_s = (DMA_DATA_WIDTH>DAC_DATA_WIDTH) ?
|
|
|
|
((MEM_RATIO == 1) ? (dma_mem_raddr) :
|
|
|
|
(MEM_RATIO == 2) ? (dma_mem_raddr[(DAC_ADDRESS_WIDTH-1):1]) :
|
|
|
|
(MEM_RATIO == 4) ? (dma_mem_raddr[(DAC_ADDRESS_WIDTH-1):2]) : (dma_mem_raddr[(DAC_ADDRESS_WIDTH-1):3])) :
|
|
|
|
((MEM_RATIO == 1) ? (dma_mem_raddr) :
|
|
|
|
(MEM_RATIO == 2) ? ({dma_mem_raddr, 1'b0}) :
|
|
|
|
(MEM_RATIO == 4) ? ({dma_mem_raddr, 2'b0}) : ({dma_mem_raddr, 3'b0}));
|
|
|
|
|
2018-06-05 10:28:29 +00:00
|
|
|
// relative address offset on DAC domain
|
2017-02-23 15:32:31 +00:00
|
|
|
assign dac_mem_waddr_s = (DAC_DATA_WIDTH>DMA_DATA_WIDTH) ?
|
|
|
|
((MEM_RATIO == 1) ? (dac_mem_waddr) :
|
|
|
|
(MEM_RATIO == 2) ? (dac_mem_waddr[(DMA_ADDRESS_WIDTH-1):1]) :
|
|
|
|
(MEM_RATIO == 4) ? (dac_mem_waddr[(DMA_ADDRESS_WIDTH-1):2]) : (dac_mem_waddr[(DMA_ADDRESS_WIDTH-1):3])) :
|
|
|
|
((MEM_RATIO == 1) ? (dac_mem_waddr) :
|
|
|
|
(MEM_RATIO == 2) ? ({dac_mem_waddr, 1'b0}) :
|
|
|
|
(MEM_RATIO == 4) ? ({dac_mem_waddr, 2'b0}) : ({dac_mem_waddr, 3'b0}));
|
|
|
|
|
2018-06-05 10:28:29 +00:00
|
|
|
assign dac_mem_empty_s = (dac_mem_waddr_s == dac_mem_raddr) ? 1'b1 : 1'b0;
|
|
|
|
assign dac_mem_rea_s = dac_valid & !dac_mem_empty_s;
|
2017-02-23 15:32:31 +00:00
|
|
|
|
2017-02-24 13:47:04 +00:00
|
|
|
always @(posedge dac_clk) begin
|
2017-02-23 15:32:31 +00:00
|
|
|
if (dac_rst == 1'b1) begin
|
|
|
|
dac_mem_raddr <= 'h0;
|
|
|
|
dac_mem_raddr_g <= 'h0;
|
|
|
|
end else begin
|
|
|
|
if (dac_mem_rea_s == 1'b1) begin
|
2018-06-05 10:28:29 +00:00
|
|
|
dac_mem_raddr <= dac_mem_raddr + 1'b1;
|
2017-02-23 15:32:31 +00:00
|
|
|
end
|
2018-06-04 06:36:42 +00:00
|
|
|
dac_mem_raddr_g <= dac_mem_raddr_b2g_s;
|
2017-02-23 15:32:31 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-06-05 10:28:29 +00:00
|
|
|
// compensate the read latency of the memory
|
|
|
|
always @(posedge dac_clk) begin
|
|
|
|
dac_mem_rea <= dac_mem_rea_s;
|
|
|
|
end
|
|
|
|
|
2018-06-04 06:36:42 +00:00
|
|
|
ad_b2g #(
|
2022-04-08 10:21:52 +00:00
|
|
|
.DATA_WIDTH (DAC_ADDRESS_WIDTH)
|
|
|
|
) i_dac_mem_raddr_b2g (
|
2018-06-04 06:36:42 +00:00
|
|
|
.din (dac_mem_raddr),
|
|
|
|
.dout (dac_mem_raddr_b2g_s));
|
|
|
|
|
2018-06-06 11:54:48 +00:00
|
|
|
// transfer the write address into the DAC's clock domain
|
2017-02-23 15:32:31 +00:00
|
|
|
|
|
|
|
always @(posedge dac_clk) begin
|
|
|
|
if (dac_rst == 1'b1) begin
|
|
|
|
dac_mem_waddr_m1 <= 'b0;
|
|
|
|
dac_mem_waddr_m2 <= 'b0;
|
|
|
|
dac_mem_waddr <= 'b0;
|
|
|
|
end else begin
|
|
|
|
dac_mem_waddr_m1 <= dma_mem_waddr_g;
|
|
|
|
dac_mem_waddr_m2 <= dac_mem_waddr_m1;
|
2018-06-04 06:36:42 +00:00
|
|
|
dac_mem_waddr <= dac_mem_waddr_m2_g2b_s;
|
2017-02-23 15:32:31 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-06-04 06:36:42 +00:00
|
|
|
ad_g2b #(
|
2022-04-08 10:21:52 +00:00
|
|
|
.DATA_WIDTH (DMA_ADDRESS_WIDTH)
|
|
|
|
) i_dac_mem_waddr_g2b (
|
2018-06-04 06:36:42 +00:00
|
|
|
.din (dac_mem_waddr_m2),
|
|
|
|
.dout (dac_mem_waddr_m2_g2b_s));
|
|
|
|
|
2017-02-23 15:32:31 +00:00
|
|
|
// define underflow
|
|
|
|
|
|
|
|
always @(posedge dac_clk) begin
|
|
|
|
if (dac_rst == 1'b1) begin
|
|
|
|
dac_dunf <= 1'b0;
|
|
|
|
end else begin
|
2018-06-05 10:28:29 +00:00
|
|
|
if (dac_valid == 1'b1) begin
|
|
|
|
dac_dunf <= dac_mem_empty_s;
|
|
|
|
end
|
2017-02-23 15:32:31 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-06-05 10:28:29 +00:00
|
|
|
// DAC data output logic - make sure that the data output is zero between
|
|
|
|
// transfers
|
2017-02-23 15:32:31 +00:00
|
|
|
|
|
|
|
always @(posedge dac_clk) begin
|
2018-06-05 10:28:29 +00:00
|
|
|
if (dac_dunf == 1'b1) begin
|
2017-02-23 15:32:31 +00:00
|
|
|
dac_data <= 0;
|
|
|
|
end else begin
|
|
|
|
dac_data <= dac_mem_rdata_s;
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
endmodule
|