data/full_repos/permissive/447976230/fpga/usrp3/top/x400/dboards/ctrlport_byte_serializer.v
1: b'%Error: data/full_repos/permissive/447976230/fpga/usrp3/top/x400/dboards/ctrlport_byte_serializer.v:70: Cannot find include file: ../../../lib/rfnoc/core/ctrlport.vh\n  `include "../../../lib/rfnoc/core/ctrlport.vh" \n           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n        ... Looked in:\n             data/full_repos/permissive/447976230/fpga/usrp3/top/x400/dboards,data/full_repos/permissive/447976230/../../../lib/rfnoc/core/ctrlport.vh\n             data/full_repos/permissive/447976230/fpga/usrp3/top/x400/dboards,data/full_repos/permissive/447976230/../../../lib/rfnoc/core/ctrlport.vh.v\n             data/full_repos/permissive/447976230/fpga/usrp3/top/x400/dboards,data/full_repos/permissive/447976230/../../../lib/rfnoc/core/ctrlport.vh.sv\n             ../../../lib/rfnoc/core/ctrlport.vh\n             ../../../lib/rfnoc/core/ctrlport.vh.v\n             ../../../lib/rfnoc/core/ctrlport.vh.sv\n             obj_dir/../../../lib/rfnoc/core/ctrlport.vh\n             obj_dir/../../../lib/rfnoc/core/ctrlport.vh.v\n             obj_dir/../../../lib/rfnoc/core/ctrlport.vh.sv\n%Error: Exiting due to 1 error(s)\n'
module ctrlport_byte_serializer (

  input wire ctrlport_clk,
  input wire ctrlport_rst,


  input  wire        s_ctrlport_req_wr,
  input  wire        s_ctrlport_req_rd,
  input  wire [19:0] s_ctrlport_req_addr,
  input  wire [31:0] s_ctrlport_req_data,


  output reg         s_ctrlport_resp_ack = 1'b0,
  output reg  [ 1:0] s_ctrlport_resp_status = 2'b0,
  output reg  [31:0] s_ctrlport_resp_data = 32'b0,


  input  wire [ 7:0] bytestream_data_in,
  input  wire        bytestream_valid_in,
  output reg  [ 7:0] bytestream_data_out = 8'b0,
  output reg         bytestream_valid_out = 1'b0,
  output reg         bytestream_direction = 1'b0,
  output reg         bytestream_output_enable = 1'b1
);

  `include "../../../lib/rfnoc/core/ctrlport.vh"





  localparam NUM_BYTES_TX_READ = 2;
  localparam NUM_BYTES_RX_READ = 5;
  localparam NUM_BYTES_TX_WRITE = 6;
  localparam NUM_BYTES_RX_WRITE = 1;

  localparam TIMEOUT_COUNTER_WIDTH = 6;




  localparam IDLE           = 3'd0;
  localparam SENDING        = 3'd1;
  localparam INIT_RX        = 3'd2;
  localparam DIR_SWITCH     = 3'd3;
  localparam DIR_SWITCH_DLY = 3'd4;
  localparam RECEIVING      = 3'd5;
  localparam ACK            = 3'd6;
  localparam TIMEOUT        = 3'd7;


  reg [7:0] bytestream_data_in_reg = 8'b0;
  reg       bytestream_valid_in_reg = 1'b0;
  always @ (posedge ctrlport_clk) begin
    bytestream_data_in_reg <= bytestream_data_in;
    bytestream_valid_in_reg <= bytestream_valid_in;
  end


  reg                      [ 2:0] state           = IDLE;
  reg  [NUM_BYTES_TX_WRITE*8-1:0] request_cache   = {NUM_BYTES_TX_WRITE*8{1'b0}};
  reg  [ NUM_BYTES_RX_READ*8-1:0] response_cache  = {NUM_BYTES_RX_READ*8{1'b0}};
  reg                      [ 2:0] byte_counter    = 3'b0;
  reg                             write_transfer  = 1'b0;
  reg [TIMEOUT_COUNTER_WIDTH-1:0] timeout_counter = {TIMEOUT_COUNTER_WIDTH {1'b0}};

  always @ (posedge ctrlport_clk) begin
    if (ctrlport_rst) begin
      state <= IDLE;

      bytestream_valid_out     <= 1'b0;
      byte_counter             <= 3'b0;
      bytestream_direction     <= 1'b0;
      bytestream_output_enable <= 1'b1;

      s_ctrlport_resp_ack      <= 1'b0;
    end else begin
      case (state)
        IDLE: begin

          s_ctrlport_resp_ack      <= 1'b0;
          bytestream_valid_out     <= 1'b0;
          bytestream_output_enable <= 1'b1;
          byte_counter             <= 3'b0;
          timeout_counter          <= {TIMEOUT_COUNTER_WIDTH {1'b0}};


          if (s_ctrlport_req_rd || s_ctrlport_req_wr) begin
            state <= SENDING;
            request_cache  <= {s_ctrlport_req_wr, s_ctrlport_req_addr[14:0], s_ctrlport_req_data};
            write_transfer <= s_ctrlport_req_wr;
          end
        end


        SENDING: begin
          bytestream_data_out  <= request_cache[NUM_BYTES_TX_WRITE*8-8+:8];
          request_cache        <= {request_cache[NUM_BYTES_TX_WRITE*8-9:0], 8'b0};
          bytestream_valid_out <= 1'b1;
          byte_counter         <= byte_counter + 1'b1;

          if ((write_transfer && byte_counter == NUM_BYTES_TX_WRITE-1) ||
               (~write_transfer && byte_counter == NUM_BYTES_TX_READ-1)) begin
            state <= INIT_RX;
          end
        end



        INIT_RX: begin
          state <= DIR_SWITCH;

          bytestream_direction     <= 1'b1;
          bytestream_output_enable <= 1'b0;
          bytestream_valid_out     <= 1'b0;

          byte_counter <= 3'b0;
        end


        DIR_SWITCH: begin
          state <= DIR_SWITCH_DLY;
        end


        DIR_SWITCH_DLY: begin
          state <= RECEIVING;
        end




        RECEIVING: begin
          timeout_counter <= timeout_counter + 1;

          if (bytestream_valid_in_reg) begin
            byte_counter <= byte_counter + 1'b1;
            response_cache = {response_cache[NUM_BYTES_RX_READ*8-9:0], bytestream_data_in_reg};

            if ((write_transfer && byte_counter == NUM_BYTES_RX_WRITE-1) ||
               (~write_transfer && byte_counter == NUM_BYTES_RX_READ-1)) begin
              state                <= ACK;
              bytestream_direction <= 1'b0;
            end
          end

          if (timeout_counter == {TIMEOUT_COUNTER_WIDTH {1'b1}}) begin
            state                <= TIMEOUT;
            bytestream_direction <= 1'b0;
          end
        end


        ACK: begin
          state <= IDLE;

          s_ctrlport_resp_ack    <= 1'b1;

          s_ctrlport_resp_status <= response_cache[2] ? response_cache[1:0] : CTRL_STS_CMDERR;
          if (write_transfer) begin
            s_ctrlport_resp_data <= 32'b0;
          end else begin
            s_ctrlport_resp_data <= response_cache[39:8];
          end
        end

        TIMEOUT: begin
          state <= IDLE;

          s_ctrlport_resp_ack    <= 1'b1;
          s_ctrlport_resp_status <= CTRL_STS_CMDERR;
          s_ctrlport_resp_data   <= 32'b0;
        end

        default: begin
          state <= IDLE;
        end
      endcase
    end
  end

endmodule
module ctrlport_byte_serializer (

  input wire ctrlport_clk,
  input wire ctrlport_rst,


  input  wire        s_ctrlport_req_wr,
  input  wire        s_ctrlport_req_rd,
  input  wire [19:0] s_ctrlport_req_addr,
  input  wire [31:0] s_ctrlport_req_data,


  output reg         s_ctrlport_resp_ack = 1'b0,
  output reg  [ 1:0] s_ctrlport_resp_status = 2'b0,
  output reg  [31:0] s_ctrlport_resp_data = 32'b0,


  input  wire [ 7:0] bytestream_data_in,
  input  wire        bytestream_valid_in,
  output reg  [ 7:0] bytestream_data_out = 8'b0,
  output reg         bytestream_valid_out = 1'b0,
  output reg         bytestream_direction = 1'b0,
  output reg         bytestream_output_enable = 1'b1
);


  `include "../../../lib/rfnoc/core/ctrlport.vh"





  localparam NUM_BYTES_TX_READ = 2;
  localparam NUM_BYTES_RX_READ = 5;
  localparam NUM_BYTES_TX_WRITE = 6;
  localparam NUM_BYTES_RX_WRITE = 1;

  localparam TIMEOUT_COUNTER_WIDTH = 6;




  localparam IDLE           = 3'd0;
  localparam SENDING        = 3'd1;
  localparam INIT_RX        = 3'd2;
  localparam DIR_SWITCH     = 3'd3;
  localparam DIR_SWITCH_DLY = 3'd4;
  localparam RECEIVING      = 3'd5;
  localparam ACK            = 3'd6;
  localparam TIMEOUT        = 3'd7;


  reg [7:0] bytestream_data_in_reg = 8'b0;
  reg       bytestream_valid_in_reg = 1'b0;
  always @ (posedge ctrlport_clk) begin
    bytestream_data_in_reg <= bytestream_data_in;
    bytestream_valid_in_reg <= bytestream_valid_in;
  end


  reg                      [ 2:0] state           = IDLE;
  reg  [NUM_BYTES_TX_WRITE*8-1:0] request_cache   = {NUM_BYTES_TX_WRITE*8{1'b0}};
  reg  [ NUM_BYTES_RX_READ*8-1:0] response_cache  = {NUM_BYTES_RX_READ*8{1'b0}};
  reg                      [ 2:0] byte_counter    = 3'b0;
  reg                             write_transfer  = 1'b0;
  reg [TIMEOUT_COUNTER_WIDTH-1:0] timeout_counter = {TIMEOUT_COUNTER_WIDTH {1'b0}};

  always @ (posedge ctrlport_clk) begin
    if (ctrlport_rst) begin
      state <= IDLE;

      bytestream_valid_out     <= 1'b0;
      byte_counter             <= 3'b0;
      bytestream_direction     <= 1'b0;
      bytestream_output_enable <= 1'b1;

      s_ctrlport_resp_ack      <= 1'b0;
    end else begin
      case (state)
        IDLE: begin

          s_ctrlport_resp_ack      <= 1'b0;
          bytestream_valid_out     <= 1'b0;
          bytestream_output_enable <= 1'b1;
          byte_counter             <= 3'b0;
          timeout_counter          <= {TIMEOUT_COUNTER_WIDTH {1'b0}};


          if (s_ctrlport_req_rd || s_ctrlport_req_wr) begin
            state <= SENDING;
            request_cache  <= {s_ctrlport_req_wr, s_ctrlport_req_addr[14:0], s_ctrlport_req_data};
            write_transfer <= s_ctrlport_req_wr;
          end
        end


        SENDING: begin
          bytestream_data_out  <= request_cache[NUM_BYTES_TX_WRITE*8-8+:8];
          request_cache        <= {request_cache[NUM_BYTES_TX_WRITE*8-9:0], 8'b0};
          bytestream_valid_out <= 1'b1;
          byte_counter         <= byte_counter + 1'b1;

          if ((write_transfer && byte_counter == NUM_BYTES_TX_WRITE-1) ||
               (~write_transfer && byte_counter == NUM_BYTES_TX_READ-1)) begin
            state <= INIT_RX;
          end
        end



        INIT_RX: begin
          state <= DIR_SWITCH;

          bytestream_direction     <= 1'b1;
          bytestream_output_enable <= 1'b0;
          bytestream_valid_out     <= 1'b0;

          byte_counter <= 3'b0;
        end


        DIR_SWITCH: begin
          state <= DIR_SWITCH_DLY;
        end


        DIR_SWITCH_DLY: begin
          state <= RECEIVING;
        end




        RECEIVING: begin
          timeout_counter <= timeout_counter + 1;

          if (bytestream_valid_in_reg) begin
            byte_counter <= byte_counter + 1'b1;
            response_cache = {response_cache[NUM_BYTES_RX_READ*8-9:0], bytestream_data_in_reg};

            if ((write_transfer && byte_counter == NUM_BYTES_RX_WRITE-1) ||
               (~write_transfer && byte_counter == NUM_BYTES_RX_READ-1)) begin
              state                <= ACK;
              bytestream_direction <= 1'b0;
            end
          end

          if (timeout_counter == {TIMEOUT_COUNTER_WIDTH {1'b1}}) begin
            state                <= TIMEOUT;
            bytestream_direction <= 1'b0;
          end
        end


        ACK: begin
          state <= IDLE;

          s_ctrlport_resp_ack    <= 1'b1;

          s_ctrlport_resp_status <= response_cache[2] ? response_cache[1:0] : CTRL_STS_CMDERR;
          if (write_transfer) begin
            s_ctrlport_resp_data <= 32'b0;
          end else begin
            s_ctrlport_resp_data <= response_cache[39:8];
          end
        end

        TIMEOUT: begin
          state <= IDLE;

          s_ctrlport_resp_ack    <= 1'b1;
          s_ctrlport_resp_status <= CTRL_STS_CMDERR;
          s_ctrlport_resp_data   <= 32'b0;
        end

        default: begin
          state <= IDLE;
        end
      endcase
    end
  end

endmodule