data/full_repos/permissive/498471995/sume/felix/simple_sume_switch/test/ip_repo/std/cores/axis_sim_record_v1_0_0/hdl/axis_sim_record.v
data/verilator_xmls/afd161ba-febc-422a-b760-bf11ba6671c7.xml
module axis_sim_record
#(

    parameter C_S_AXIS_DATA_WIDTH = 256,
    parameter C_S_AXIS_TUSER_WIDTH = 128,
    parameter OUTPUT_FILE = "../../stream_data_out.axi",
    parameter READY_COUNT = 2,
    parameter NOT_READY_COUNT = 8
)
(


    input axi_aclk,


    input [C_S_AXIS_DATA_WIDTH - 1:0] s_axis_tdata,
    input [((C_S_AXIS_DATA_WIDTH / 8)) - 1:0] s_axis_tkeep,
    input [C_S_AXIS_TUSER_WIDTH-1:0] s_axis_tuser,
    input s_axis_tvalid,
    output reg s_axis_tready,
    input s_axis_tlast,

    output reg [10:0] counter,
    output reg activity_rec
);

    integer f;
    integer bubble_count = 0;
    reg [8*2-1:0] terminal_flag;
    
    initial begin
        f = $fopen(OUTPUT_FILE, "w");
        counter = 0;

        state = READY;
        ready_count = 0;
        not_ready_count = 0;
    end

    reg [1:0] state;
    reg [1:0] state_next;

    localparam READY = 0;
    localparam NOT_READY = 1;

    reg [31:0] ready_count;
    reg [31:0] ready_count_next;
    reg [31:0] not_ready_count;
    reg [31:0] not_ready_count_next;
     
    always@(*) begin
        state_next = state;
        s_axis_tready = 0;
        ready_count_next = ready_count;
        not_ready_count_next = not_ready_count;

        case(state)
            READY: begin
                s_axis_tready = 1;
                if (ready_count == READY_COUNT-1) begin
                    state_next = NOT_READY;
                    ready_count_next = 0;
                end
                else if (s_axis_tvalid) begin
                    ready_count_next = ready_count + 1;
                end
            end

            NOT_READY: begin
                s_axis_tready = 0;
                if (not_ready_count == NOT_READY_COUNT-1) begin
                    state_next = READY;
                    not_ready_count_next = 0;
                end
                else begin
                    not_ready_count_next = not_ready_count + 1;
                end
            end
        endcase

    end

    always @(posedge axi_aclk) begin
        state <= state_next;
        ready_count <= ready_count_next;
        not_ready_count <= not_ready_count_next;
    end


    always @(posedge axi_aclk) begin
        if (s_axis_tvalid == 1'b1) begin
            if (s_axis_tready == 1'b1) begin
                if (bubble_count != 0) begin
                    $fwrite(f, "*%0d\n", bubble_count);
                    bubble_count <= 0;
                end
                if (s_axis_tlast == 1'b1) begin
                    terminal_flag = ".";
	            counter <= counter + 1;
	            activity_rec <= 1;
                end
                else begin
                    terminal_flag = ",";
	            activity_rec <= 1;
                end
                
                $fwrite(f, "%x, %x, %x%0s # %0d ns\n",
                                  s_axis_tdata,
                                  s_axis_tkeep,
                                  s_axis_tuser,
                                  terminal_flag,
                                  $time
                                  ); 
            end
        end
        else begin
            bubble_count <= bubble_count + 1;
	    activity_rec <= 0;
        end
    end
endmodule
module axis_sim_record
#(

    parameter C_S_AXIS_DATA_WIDTH = 256,
    parameter C_S_AXIS_TUSER_WIDTH = 128,
    parameter OUTPUT_FILE = "../../stream_data_out.axi",
    parameter READY_COUNT = 2,
    parameter NOT_READY_COUNT = 8
)
(


    input axi_aclk,


    input [C_S_AXIS_DATA_WIDTH - 1:0] s_axis_tdata,
    input [((C_S_AXIS_DATA_WIDTH / 8)) - 1:0] s_axis_tkeep,
    input [C_S_AXIS_TUSER_WIDTH-1:0] s_axis_tuser,
    input s_axis_tvalid,
    output reg s_axis_tready,
    input s_axis_tlast,

    output reg [10:0] counter,
    output reg activity_rec
);


    integer f;
    integer bubble_count = 0;
    reg [8*2-1:0] terminal_flag;
    
    initial begin
        f = $fopen(OUTPUT_FILE, "w");
        counter = 0;

        state = READY;
        ready_count = 0;
        not_ready_count = 0;
    end

    reg [1:0] state;
    reg [1:0] state_next;

    localparam READY = 0;
    localparam NOT_READY = 1;

    reg [31:0] ready_count;
    reg [31:0] ready_count_next;
    reg [31:0] not_ready_count;
    reg [31:0] not_ready_count_next;
     
    always@(*) begin
        state_next = state;
        s_axis_tready = 0;
        ready_count_next = ready_count;
        not_ready_count_next = not_ready_count;

        case(state)
            READY: begin
                s_axis_tready = 1;
                if (ready_count == READY_COUNT-1) begin
                    state_next = NOT_READY;
                    ready_count_next = 0;
                end
                else if (s_axis_tvalid) begin
                    ready_count_next = ready_count + 1;
                end
            end

            NOT_READY: begin
                s_axis_tready = 0;
                if (not_ready_count == NOT_READY_COUNT-1) begin
                    state_next = READY;
                    not_ready_count_next = 0;
                end
                else begin
                    not_ready_count_next = not_ready_count + 1;
                end
            end
        endcase

    end

    always @(posedge axi_aclk) begin
        state <= state_next;
        ready_count <= ready_count_next;
        not_ready_count <= not_ready_count_next;
    end


    always @(posedge axi_aclk) begin
        if (s_axis_tvalid == 1'b1) begin
            if (s_axis_tready == 1'b1) begin
                if (bubble_count != 0) begin
                    $fwrite(f, "*%0d\n", bubble_count);
                    bubble_count <= 0;
                end
                if (s_axis_tlast == 1'b1) begin
                    terminal_flag = ".";
	            counter <= counter + 1;
	            activity_rec <= 1;
                end
                else begin
                    terminal_flag = ",";
	            activity_rec <= 1;
                end
                
                $fwrite(f, "%x, %x, %x%0s # %0d ns\n",
                                  s_axis_tdata,
                                  s_axis_tkeep,
                                  s_axis_tuser,
                                  terminal_flag,
                                  $time
                                  ); 
            end
        end
        else begin
            bubble_count <= bubble_count + 1;
	    activity_rec <= 0;
        end
    end
endmodule