File: axis_packet_flush.v

package info (click to toggle)
uhd 3.13.1.0-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 207,120 kB
  • sloc: cpp: 167,245; ansic: 86,841; vhdl: 53,420; python: 40,839; xml: 13,167; tcl: 5,688; makefile: 2,167; sh: 1,719; pascal: 230; csh: 94; asm: 20; perl: 11
file content (58 lines) | stat: -rw-r--r-- 1,838 bytes parent folder | download | duplicates (2)
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
//
// Copyright 2018 Ettus Research, a National Instruments Company
//
// SPDX-License-Identifier: LGPL-3.0-or-later
//
// Description:
//   When this module is inserted in an AXI-Stream link, it allows
//   the client to flip a bit to make the stream lossy. When enable=1
//   all data coming through the input is dropped. This module can
//   start and stop flushing at packet boundaries to ensure no partial
//   packets are introduces into the stream. Set FLUSH_PARTIAL_PKTS = 1
//   to disable that behavior.

module axis_packet_flush #(
  parameter WIDTH               = 64,
  parameter FLUSH_PARTIAL_PKTS  = 0
)(
  input  wire             clk,
  input  wire             reset,
  input  wire             enable,
  output wire             flushing,
  input  wire [WIDTH-1:0] s_axis_tdata,
  input  wire             s_axis_tlast,
  input  wire             s_axis_tvalid,
  output wire             s_axis_tready,
  output wire [WIDTH-1:0] m_axis_tdata,
  output wire             m_axis_tlast,
  output wire             m_axis_tvalid,
  input  wire             m_axis_tready
);

  reg mid_pkt = 1'b0;
  reg active  = 1'b0;

  always @(posedge clk) begin
    if (reset) begin
      mid_pkt <= 1'b0;
      active <= 1'b0;
    end else begin
      if (s_axis_tvalid & s_axis_tready) begin
        mid_pkt <= ~s_axis_tlast;
      end
      if (enable & ((s_axis_tvalid & s_axis_tready & s_axis_tlast) | (~mid_pkt & (~s_axis_tvalid | ~s_axis_tready)))) begin
        active <= 1'b1;
      end else if (~enable) begin
        active <= 1'b0;
      end
    end
  end

  assign flushing      = (FLUSH_PARTIAL_PKTS == 0) ? active : enable;

  assign m_axis_tdata  = s_axis_tdata;
  assign m_axis_tlast  = s_axis_tlast;
  assign m_axis_tvalid = flushing ? 1'b0 : s_axis_tvalid;
  assign s_axis_tready = flushing ? 1'b1 : m_axis_tready;

endmodule