aboutsummaryrefslogtreecommitdiffstats
path: root/fpga/usrp3/lib/fifo/axi_fifo_flop2.v
blob: 381253e56628d81bc523a55cbd426ceb92d3ccd4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
//
// Copyright 2015 Ettus Research LLC
// Copyright 2018 Ettus Research, a National Instruments Company
//
// SPDX-License-Identifier: LGPL-3.0-or-later
//
// Single cycle latency, depth of 2 "Flip flop" with no end to end combinatorial paths on
// AXI control signals (such as i_tready depends on o_tready). Breaking the combinatorial
// paths requires an additional register stage.
//
// Note: Once i_tvalid is asserted, it cannot be deasserted without i_tready having asserted
//       indicating i_tdata has been read. This is an AXI stream requirement.

module axi_fifo_flop2 #(
  parameter WIDTH = 32
)(
  input clk,
  input reset,
  input clear,
  input [WIDTH-1:0] i_tdata,
  input i_tvalid,
  output i_tready,
  output reg [WIDTH-1:0] o_tdata = 'h0,
  output reg o_tvalid = 1'b0,
  input o_tready,
  output [1:0] space,
  output [1:0] occupied);

  reg [WIDTH-1:0] i_tdata_temp = 'h0;
  reg             i_tvalid_temp = 1'b0;

  assign i_tready = ~i_tvalid_temp;

  always @(posedge clk) begin
    if (~o_tvalid | o_tready) begin
      if (i_tvalid_temp) begin
        o_tvalid      <= 1'b1;
        o_tdata       <= i_tdata_temp;
      end else begin
        o_tvalid      <= i_tvalid;
        o_tdata       <= i_tdata;
      end
      i_tvalid_temp   <= 1'b0;
    end else begin
      if (~i_tvalid_temp) begin
        i_tvalid_temp <= i_tvalid;
        i_tdata_temp  <= i_tdata;
      end
    end
    if (reset | clear) begin
      o_tvalid      <= 1'b0;
      i_tvalid_temp <= 1'b0;
    end
  end

  assign occupied = i_tvalid_temp + o_tvalid;
  assign space    = 2 - occupied;

endmodule