data/full_repos/permissive/218463548/hardware/hdl/nvme/nvme_io_track.sv
 line:229: before: "]"
1: b'%Error: data/full_repos/permissive/218463548/hardware/hdl/nvme/nvme_io_track.sv:32: Cannot find include file: nvme_defines.sv\n`include "nvme_defines.sv" \n         ^~~~~~~~~~~~~~~~~\n        ... Looked in:\n             data/full_repos/permissive/218463548/hardware/hdl/nvme,data/full_repos/permissive/218463548/nvme_defines.sv\n             data/full_repos/permissive/218463548/hardware/hdl/nvme,data/full_repos/permissive/218463548/nvme_defines.sv.v\n             data/full_repos/permissive/218463548/hardware/hdl/nvme,data/full_repos/permissive/218463548/nvme_defines.sv.sv\n             nvme_defines.sv\n             nvme_defines.sv.v\n             nvme_defines.sv.sv\n             obj_dir/nvme_defines.sv\n             obj_dir/nvme_defines.sv.v\n             obj_dir/nvme_defines.sv.sv\n%Error: data/full_repos/permissive/218463548/hardware/hdl/nvme/nvme_io_track.sv:54: Define or directive not defined: \'`CMD_ACTION_ID_BITS\'\n  input wire [`CMD_ACTION_ID_BITS-1:0]  track_update_id,\n              ^~~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/218463548/hardware/hdl/nvme/nvme_io_track.sv:62: Define or directive not defined: \'`CMD_ACTION_ID_BITS\'\n  output logic[2**`CMD_ACTION_ID_BITS-1:0]  track_status\n                  ^~~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/218463548/hardware/hdl/nvme/nvme_io_track.sv:67: Define or directive not defined: \'`TRACK_NUM\'\n  localparam TRACK_NUM_BITS = $clog2(`TRACK_NUM);\n                                     ^~~~~~~~~~\n%Error: data/full_repos/permissive/218463548/hardware/hdl/nvme/nvme_io_track.sv:67: syntax error, unexpected \')\', expecting TYPE-IDENTIFIER\n  localparam TRACK_NUM_BITS = $clog2(`TRACK_NUM);\n                                               ^\n%Error: data/full_repos/permissive/218463548/hardware/hdl/nvme/nvme_io_track.sv:68: Define or directive not defined: \'`CMD_ACTION_ID_BITS\'\n  localparam TRACK_ADDR_BITS = `CMD_ACTION_ID_BITS + TRACK_NUM_BITS;\n                               ^~~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/218463548/hardware/hdl/nvme/nvme_io_track.sv:79: Define or directive not defined: \'`IO_SQ_NUM\'\n  localparam SQ_BITS = $clog2(`IO_SQ_NUM);\n                              ^~~~~~~~~~\n%Error: data/full_repos/permissive/218463548/hardware/hdl/nvme/nvme_io_track.sv:79: syntax error, unexpected \')\', expecting TYPE-IDENTIFIER\n  localparam SQ_BITS = $clog2(`IO_SQ_NUM);\n                                        ^\n%Error: data/full_repos/permissive/218463548/hardware/hdl/nvme/nvme_io_track.sv:80: Define or directive not defined: \'`TOTAL_NUM_QUEUES\'\n  localparam SQ_INDEX_BITS = $clog2(`TOTAL_NUM_QUEUES);\n                                    ^~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/218463548/hardware/hdl/nvme/nvme_io_track.sv:80: syntax error, unexpected \')\', expecting TYPE-IDENTIFIER\n  localparam SQ_INDEX_BITS = $clog2(`TOTAL_NUM_QUEUES);\n                                                     ^\n%Error: data/full_repos/permissive/218463548/hardware/hdl/nvme/nvme_io_track.sv:83: Define or directive not defined: \'`REQ_ID_BITS\'\n  logic [`REQ_ID_BITS-1:0] track_index_array [2**`CMD_ACTION_ID_BITS];\n         ^~~~~~~~~~~~\n%Error: data/full_repos/permissive/218463548/hardware/hdl/nvme/nvme_io_track.sv:83: Define or directive not defined: \'`CMD_ACTION_ID_BITS\'\n  logic [`REQ_ID_BITS-1:0] track_index_array [2**`CMD_ACTION_ID_BITS];\n                                                 ^~~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/218463548/hardware/hdl/nvme/nvme_io_track.sv:83: syntax error, unexpected \']\', expecting TYPE-IDENTIFIER\n  logic [`REQ_ID_BITS-1:0] track_index_array [2**`CMD_ACTION_ID_BITS];\n                                                                    ^\n%Error: data/full_repos/permissive/218463548/hardware/hdl/nvme/nvme_io_track.sv:86: Define or directive not defined: \'`ADM_CQ_NUM\'\n  localparam DATA_CQ_ADDR = (`ADM_CQ_NUM * 2 + `IO_CQ_NUM * 2);\n                             ^~~~~~~~~~~\n%Error: data/full_repos/permissive/218463548/hardware/hdl/nvme/nvme_io_track.sv:86: syntax error, unexpected \'*\', expecting TYPE-IDENTIFIER\n  localparam DATA_CQ_ADDR = (`ADM_CQ_NUM * 2 + `IO_CQ_NUM * 2);\n                                         ^\n%Error: data/full_repos/permissive/218463548/hardware/hdl/nvme/nvme_io_track.sv:86: Define or directive not defined: \'`IO_CQ_NUM\'\n  localparam DATA_CQ_ADDR = (`ADM_CQ_NUM * 2 + `IO_CQ_NUM * 2);\n                                               ^~~~~~~~~~\n%Error: data/full_repos/permissive/218463548/hardware/hdl/nvme/nvme_io_track.sv:90: Define or directive not defined: \'`CMD_ACTION_ID_BITS\'\n  logic [`CMD_ACTION_ID_BITS-1:0] rx_action_id;\n         ^~~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/218463548/hardware/hdl/nvme/nvme_io_track.sv:91: Define or directive not defined: \'`REQ_ID_BITS\'\n  logic [`REQ_ID_BITS-1:0] rx_req_id;\n         ^~~~~~~~~~~~\n%Error: data/full_repos/permissive/218463548/hardware/hdl/nvme/nvme_io_track.sv:95: Define or directive not defined: \'`CMD_QUEUE_ID_BITS\'\n  assign rx_action_id = rx_wdata[96  + `CMD_QUEUE_ID_BITS +: `CMD_ACTION_ID_BITS];\n                                       ^~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/218463548/hardware/hdl/nvme/nvme_io_track.sv:95: syntax error, unexpected +:, expecting TYPE-IDENTIFIER\n  assign rx_action_id = rx_wdata[96  + `CMD_QUEUE_ID_BITS +: `CMD_ACTION_ID_BITS];\n                                                          ^~\n%Error: data/full_repos/permissive/218463548/hardware/hdl/nvme/nvme_io_track.sv:95: Define or directive not defined: \'`CMD_ACTION_ID_BITS\'\n  assign rx_action_id = rx_wdata[96  + `CMD_QUEUE_ID_BITS +: `CMD_ACTION_ID_BITS];\n                                                             ^~~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/218463548/hardware/hdl/nvme/nvme_io_track.sv:96: Define or directive not defined: \'`CMD_QUEUE_ID_BITS\'\n  assign rx_req_id = rx_wdata[96  + `CMD_QUEUE_ID_BITS + `CMD_ACTION_ID_BITS +: `REQ_ID_BITS];\n                                    ^~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/218463548/hardware/hdl/nvme/nvme_io_track.sv:96: Define or directive not defined: \'`CMD_ACTION_ID_BITS\'\n  assign rx_req_id = rx_wdata[96  + `CMD_QUEUE_ID_BITS + `CMD_ACTION_ID_BITS +: `REQ_ID_BITS];\n                                                         ^~~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/218463548/hardware/hdl/nvme/nvme_io_track.sv:96: syntax error, unexpected +:, expecting TYPE-IDENTIFIER\n  assign rx_req_id = rx_wdata[96  + `CMD_QUEUE_ID_BITS + `CMD_ACTION_ID_BITS +: `REQ_ID_BITS];\n                                                                             ^~\n%Error: data/full_repos/permissive/218463548/hardware/hdl/nvme/nvme_io_track.sv:96: Define or directive not defined: \'`REQ_ID_BITS\'\n  assign rx_req_id = rx_wdata[96  + `CMD_QUEUE_ID_BITS + `CMD_ACTION_ID_BITS +: `REQ_ID_BITS];\n                                                                                ^~~~~~~~~~~~\n%Error: data/full_repos/permissive/218463548/hardware/hdl/nvme/nvme_io_track.sv:137: Define or directive not defined: \'`CMD_ACTION_ID_BITS\'\n      for (int i=0; i<2**`CMD_ACTION_ID_BITS; i++) begin\n                         ^~~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/218463548/hardware/hdl/nvme/nvme_io_track.sv:137: syntax error, unexpected \';\', expecting TYPE-IDENTIFIER\n      for (int i=0; i<2**`CMD_ACTION_ID_BITS; i++) begin\n                                            ^\n%Error: data/full_repos/permissive/218463548/hardware/hdl/nvme/nvme_io_track.sv:137: syntax error, unexpected \')\', expecting \';\'\n      for (int i=0; i<2**`CMD_ACTION_ID_BITS; i++) begin\n                                                 ^\n%Error: data/full_repos/permissive/218463548/hardware/hdl/nvme/nvme_io_track.sv:140: syntax error, unexpected else\n    end else begin\n        ^~~~\n%Error: data/full_repos/permissive/218463548/hardware/hdl/nvme/nvme_io_track.sv:148: syntax error, unexpected <=, expecting IDENTIFIER\n        track_write <= 1\'b1;\n                    ^~\n%Error: data/full_repos/permissive/218463548/hardware/hdl/nvme/nvme_io_track.sv:150: syntax error, unexpected <=, expecting IDENTIFIER\n          track_waddr <= track_waddr + 1;\n                      ^~\n%Error: data/full_repos/permissive/218463548/hardware/hdl/nvme/nvme_io_track.sv:153: syntax error, unexpected <=, expecting IDENTIFIER\n          track_init <= 1\'b1;\n                     ^~\n%Error: data/full_repos/permissive/218463548/hardware/hdl/nvme/nvme_io_track.sv:158: syntax error, unexpected <=, expecting IDENTIFIER\n            track_error <= 1\'b0;\n                        ^~\n%Error: data/full_repos/permissive/218463548/hardware/hdl/nvme/nvme_io_track.sv:165: syntax error, unexpected <=, expecting IDENTIFIER\n            track_update_done <= 1\'b1;\n                              ^~\n%Error: data/full_repos/permissive/218463548/hardware/hdl/nvme/nvme_io_track.sv:169: syntax error, unexpected \'[\', expecting IDENTIFIER\n            track_status[track_update_id] <= 1\'b0;\n                        ^\n%Error: data/full_repos/permissive/218463548/hardware/hdl/nvme/nvme_io_track.sv:174: Define or directive not defined: \'`TRACK_NUM\'\n            if (track_index_array[track_update_id]==`TRACK_NUM-1) begin\n                                                    ^~~~~~~~~~\n%Error: data/full_repos/permissive/218463548/hardware/hdl/nvme/nvme_io_track.sv:175: syntax error, unexpected \'[\', expecting IDENTIFIER\n              track_index_array[track_update_id] <= \'d0;\n                               ^\n%Error: data/full_repos/permissive/218463548/hardware/hdl/nvme/nvme_io_track.sv:177: syntax error, unexpected \'[\', expecting IDENTIFIER\n              track_index_array[track_update_id] <= track_index_array[track_update_id] + 1;\n                               ^\n%Error: data/full_repos/permissive/218463548/hardware/hdl/nvme/nvme_io_track.sv:183: syntax error, unexpected <=, expecting IDENTIFIER\n          track_read <= 1\'b1;\n                     ^~\n%Error: data/full_repos/permissive/218463548/hardware/hdl/nvme/nvme_io_track.sv:188: syntax error, unexpected <=, expecting IDENTIFIER\n          track_update_data <= track_rdata;\n                            ^~\n%Error: data/full_repos/permissive/218463548/hardware/hdl/nvme/nvme_io_track.sv:193: syntax error, unexpected \'[\', expecting IDENTIFIER\n            track_status[track_update_id] <= track_wdata[0];\n                        ^\n%Error: data/full_repos/permissive/218463548/hardware/hdl/nvme/nvme_io_track.sv:196: syntax error, unexpected <=, expecting IDENTIFIER\n            track_read_valid <= 1\'b1;\n                             ^~\n%Error: data/full_repos/permissive/218463548/hardware/hdl/nvme/nvme_io_track.sv:200: syntax error, unexpected <=, expecting IDENTIFIER\n          track_update_done <= 1\'b1;\n                            ^~\n%Error: data/full_repos/permissive/218463548/hardware/hdl/nvme/nvme_io_track.sv:205: syntax error, unexpected \'[\', expecting IDENTIFIER\n            track_status[track_update_id] <= track_wdata[0];\n                        ^\n%Error: data/full_repos/permissive/218463548/hardware/hdl/nvme/nvme_io_track.sv:208: syntax error, unexpected \'[\', expecting IDENTIFIER\n            track_status[track_update_id] <= track_rdata[0];\n                        ^\n%Error: data/full_repos/permissive/218463548/hardware/hdl/nvme/nvme_io_track.sv:214: syntax error, unexpected <=, expecting IDENTIFIER\n            track_error <= 1\'b1;\n                        ^~\n%Error: data/full_repos/permissive/218463548/hardware/hdl/nvme/nvme_io_track.sv:218: Define or directive not defined: \'`CMD_SSD0_Q0\'\n          if (rx_q_index!=`CMD_SSD0_Q0 && rx_q_index!=`CMD_SSD1_Q0) begin\n                          ^~~~~~~~~~~~\n%Error: data/full_repos/permissive/218463548/hardware/hdl/nvme/nvme_io_track.sv:218: syntax error, unexpected &&, expecting TYPE-IDENTIFIER\n          if (rx_q_index!=`CMD_SSD0_Q0 && rx_q_index!=`CMD_SSD1_Q0) begin\n                                       ^~\n%Error: data/full_repos/permissive/218463548/hardware/hdl/nvme/nvme_io_track.sv:218: Define or directive not defined: \'`CMD_SSD1_Q0\'\n          if (rx_q_index!=`CMD_SSD0_Q0 && rx_q_index!=`CMD_SSD1_Q0) begin\n                                                      ^~~~~~~~~~~~\n%Error: data/full_repos/permissive/218463548/hardware/hdl/nvme/nvme_io_track.sv:225: syntax error, unexpected \'[\', expecting IDENTIFIER\n              track_status[rx_action_id] <= 1\'b1;\n                          ^\n%Error: Exiting due to too many errors encountered; --error-limit=50\n'
module nvme_io_track #
(
  parameter integer RX_ADDR_BITS = 10,
  parameter integer TRACK_INFO_BITS = 2
)
(
  input wire axi_aclk,
  input wire axi_aresetn,


  input wire                          rx_write_valid,
  input wire [3:0]                    rx_write,
  input wire [RX_ADDR_BITS-1:0]       rx_waddr,
  input wire [127:0]                  rx_wdata,

  output logic                        track_init,
  output logic                        track_overflow,


  input wire                            track_update,
  input wire [`CMD_ACTION_ID_BITS-1:0]  track_update_id,
  output logic                          track_update_done,
  output logic [TRACK_INFO_BITS-1:0]    track_update_data,


  input logic                               track_error_clear,
  output logic                              track_error,
  output logic [127:0]                      track_error_data,
  output logic[2**`CMD_ACTION_ID_BITS-1:0]  track_status

);


  localparam TRACK_NUM_BITS = $clog2(`TRACK_NUM);
  localparam TRACK_ADDR_BITS = `CMD_ACTION_ID_BITS + TRACK_NUM_BITS;
  logic [TRACK_INFO_BITS-1:0] track_store [2**TRACK_ADDR_BITS];
  logic track_write;
  logic [TRACK_ADDR_BITS-1:0] track_waddr;
  logic [TRACK_INFO_BITS-1:0] track_wdata;
  logic track_rwrite;
  logic track_read;
  logic track_read_valid;
  logic [TRACK_ADDR_BITS-1:0] track_raddr;
  logic [TRACK_INFO_BITS-1:0] track_rdata;

  localparam SQ_BITS = $clog2(`IO_SQ_NUM);
  localparam SQ_INDEX_BITS = $clog2(`TOTAL_NUM_QUEUES);


  logic [`REQ_ID_BITS-1:0] track_index_array [2**`CMD_ACTION_ID_BITS];


  localparam DATA_CQ_ADDR = (`ADM_CQ_NUM * 2 + `IO_CQ_NUM * 2);


  logic [SQ_INDEX_BITS-1:0] rx_q_index;
  logic [`CMD_ACTION_ID_BITS-1:0] rx_action_id;
  logic [`REQ_ID_BITS-1:0] rx_req_id;
  logic [14:0] rx_status_field;

  assign rx_q_index = rx_wdata[96 +: SQ_INDEX_BITS];
  assign rx_action_id = rx_wdata[96  + `CMD_QUEUE_ID_BITS +: `CMD_ACTION_ID_BITS];
  assign rx_req_id = rx_wdata[96  + `CMD_QUEUE_ID_BITS + `CMD_ACTION_ID_BITS +: `REQ_ID_BITS];
  assign rx_status_field = rx_wdata[96+17 +: 15];

  logic renable;
  assign renable = track_read | track_rwrite;

  always @(posedge axi_aclk)
  begin : MEM_A_P
    if (renable) begin
      track_rdata <= track_store[track_raddr];
      if (track_rwrite) begin
        track_store[track_raddr] <= 'd0;
      end
    end
  end

  always @(posedge axi_aclk)
  begin : MEM_B_P
    if (track_write) begin
      track_store[track_waddr] <= track_wdata;
    end
  end

  always @(posedge axi_aclk, negedge axi_aresetn)
  begin : TRACK_P
    if (!axi_aresetn) begin
      track_init <= 1'b0;
      track_overflow <= 1'b0;
      track_write <= 1'b0;
      track_waddr <= 'd0;
      track_wdata <= 'd0;
      track_rwrite <= 1'b0;
      track_read <= 1'b0;
      track_read_valid <= 1'b0;
      track_raddr <= 'd0;

      track_error       <= 1'b0;
      track_error_data  <= 'd0;
      track_status      <= 'd0;
      track_update_done <= 1'b0;
      track_update_data <= 'd0;
      for (int i=0; i<2**`CMD_ACTION_ID_BITS; i++) begin
        track_index_array[i] <= 'd0;
      end
    end else begin
      track_update_done <= 1'b0;
      track_write <= 1'b0;
      track_rwrite <= 1'b0;
      track_read <= 1'b0;
      track_read_valid <= 1'b0;

      if (!track_init) begin
        track_write <= 1'b1;
        if (track_write) begin
          track_waddr <= track_waddr + 1;
        end
        if (track_waddr==2**TRACK_ADDR_BITS-1) begin
          track_init <= 1'b1;
        end
      end else begin

        if (track_error_clear) begin
            track_error <= 1'b0;
            track_error_data <= 'd0;
        end

        if (track_update) begin

          if (!track_status[track_update_id]) begin
            track_update_done <= 1'b1;
            track_update_data <= 'd0;
          end else begin

            track_status[track_update_id] <= 1'b0;

            track_rwrite <= 1'b1;
            track_raddr <= {track_update_id, track_index_array[track_update_id]};

            if (track_index_array[track_update_id]==`TRACK_NUM-1) begin
              track_index_array[track_update_id] <= 'd0;
            end else begin
              track_index_array[track_update_id] <= track_index_array[track_update_id] + 1;
            end
          end

        end else if (track_rwrite) begin

          track_read <= 1'b1;
          track_raddr <= {track_update_id, track_index_array[track_update_id]};

        end else if (track_read) begin

          track_update_data <= track_rdata;

          if (track_write && (track_waddr==track_raddr)) begin


            track_status[track_update_id] <= track_wdata[0];
            track_update_done <= 1'b1;
          end else begin
            track_read_valid <= 1'b1;
          end

        end else if (track_read_valid) begin
          track_update_done <= 1'b1;

          if (track_write && (track_waddr==track_raddr)) begin


            track_status[track_update_id] <= track_wdata[0];
          end else begin

            track_status[track_update_id] <= track_rdata[0];
          end
        end

        if (rx_write_valid && rx_waddr < DATA_CQ_ADDR) begin
          if (!track_error && rx_status_field!=0) begin
            track_error <= 1'b1;
            track_error_data <= rx_wdata;
          end

          if (rx_q_index!=`CMD_SSD0_Q0 && rx_q_index!=`CMD_SSD1_Q0) begin
            track_write <= 1'b1;
            track_wdata[0] <= 1'b1;
            track_wdata[1] <= (rx_status_field==0) ? 1'b0 : 1'b1;
            track_waddr <= {rx_action_id, rx_req_id};

            if (rx_req_id == track_index_array[rx_action_id]) begin
              track_status[rx_action_id] <= 1'b1;

              if (track_status[rx_action_id]) begin
                track_overflow <= 1'b1;
              end
            end
          end
        end
      end
    end
  end


endmodule
module nvme_io_track #
(
  parameter integer RX_ADDR_BITS = 10,
  parameter integer TRACK_INFO_BITS = 2
)
(
  input wire axi_aclk,
  input wire axi_aresetn,


  input wire                          rx_write_valid,
  input wire [3:0]                    rx_write,
  input wire [RX_ADDR_BITS-1:0]       rx_waddr,
  input wire [127:0]                  rx_wdata,

  output logic                        track_init,
  output logic                        track_overflow,


  input wire                            track_update,
  input wire [`CMD_ACTION_ID_BITS-1:0]  track_update_id,
  output logic                          track_update_done,
  output logic [TRACK_INFO_BITS-1:0]    track_update_data,


  input logic                               track_error_clear,
  output logic                              track_error,
  output logic [127:0]                      track_error_data,
  output logic[2**`CMD_ACTION_ID_BITS-1:0]  track_status

);



  localparam TRACK_NUM_BITS = $clog2(`TRACK_NUM);
  localparam TRACK_ADDR_BITS = `CMD_ACTION_ID_BITS + TRACK_NUM_BITS;
  logic [TRACK_INFO_BITS-1:0] track_store [2**TRACK_ADDR_BITS];
  logic track_write;
  logic [TRACK_ADDR_BITS-1:0] track_waddr;
  logic [TRACK_INFO_BITS-1:0] track_wdata;
  logic track_rwrite;
  logic track_read;
  logic track_read_valid;
  logic [TRACK_ADDR_BITS-1:0] track_raddr;
  logic [TRACK_INFO_BITS-1:0] track_rdata;

  localparam SQ_BITS = $clog2(`IO_SQ_NUM);
  localparam SQ_INDEX_BITS = $clog2(`TOTAL_NUM_QUEUES);


  logic [`REQ_ID_BITS-1:0] track_index_array [2**`CMD_ACTION_ID_BITS];


  localparam DATA_CQ_ADDR = (`ADM_CQ_NUM * 2 + `IO_CQ_NUM * 2);


  logic [SQ_INDEX_BITS-1:0] rx_q_index;
  logic [`CMD_ACTION_ID_BITS-1:0] rx_action_id;
  logic [`REQ_ID_BITS-1:0] rx_req_id;
  logic [14:0] rx_status_field;

  assign rx_q_index = rx_wdata[96 +: SQ_INDEX_BITS];
  assign rx_action_id = rx_wdata[96  + `CMD_QUEUE_ID_BITS +: `CMD_ACTION_ID_BITS];
  assign rx_req_id = rx_wdata[96  + `CMD_QUEUE_ID_BITS + `CMD_ACTION_ID_BITS +: `REQ_ID_BITS];
  assign rx_status_field = rx_wdata[96+17 +: 15];

  logic renable;
  assign renable = track_read | track_rwrite;

  always @(posedge axi_aclk)
  begin : MEM_A_P
    if (renable) begin
      track_rdata <= track_store[track_raddr];
      if (track_rwrite) begin
        track_store[track_raddr] <= 'd0;
      end
    end
  end

  always @(posedge axi_aclk)
  begin : MEM_B_P
    if (track_write) begin
      track_store[track_waddr] <= track_wdata;
    end
  end

  always @(posedge axi_aclk, negedge axi_aresetn)
  begin : TRACK_P
    if (!axi_aresetn) begin
      track_init <= 1'b0;
      track_overflow <= 1'b0;
      track_write <= 1'b0;
      track_waddr <= 'd0;
      track_wdata <= 'd0;
      track_rwrite <= 1'b0;
      track_read <= 1'b0;
      track_read_valid <= 1'b0;
      track_raddr <= 'd0;

      track_error       <= 1'b0;
      track_error_data  <= 'd0;
      track_status      <= 'd0;
      track_update_done <= 1'b0;
      track_update_data <= 'd0;
      for (int i=0; i<2**`CMD_ACTION_ID_BITS; i++) begin
        track_index_array[i] <= 'd0;
      end
    end else begin
      track_update_done <= 1'b0;
      track_write <= 1'b0;
      track_rwrite <= 1'b0;
      track_read <= 1'b0;
      track_read_valid <= 1'b0;

      if (!track_init) begin
        track_write <= 1'b1;
        if (track_write) begin
          track_waddr <= track_waddr + 1;
        end
        if (track_waddr==2**TRACK_ADDR_BITS-1) begin
          track_init <= 1'b1;
        end
      end else begin

        if (track_error_clear) begin
            track_error <= 1'b0;
            track_error_data <= 'd0;
        end

        if (track_update) begin

          if (!track_status[track_update_id]) begin
            track_update_done <= 1'b1;
            track_update_data <= 'd0;
          end else begin

            track_status[track_update_id] <= 1'b0;

            track_rwrite <= 1'b1;
            track_raddr <= {track_update_id, track_index_array[track_update_id]};

            if (track_index_array[track_update_id]==`TRACK_NUM-1) begin
              track_index_array[track_update_id] <= 'd0;
            end else begin
              track_index_array[track_update_id] <= track_index_array[track_update_id] + 1;
            end
          end

        end else if (track_rwrite) begin

          track_read <= 1'b1;
          track_raddr <= {track_update_id, track_index_array[track_update_id]};

        end else if (track_read) begin

          track_update_data <= track_rdata;

          if (track_write && (track_waddr==track_raddr)) begin


            track_status[track_update_id] <= track_wdata[0];
            track_update_done <= 1'b1;
          end else begin
            track_read_valid <= 1'b1;
          end

        end else if (track_read_valid) begin
          track_update_done <= 1'b1;

          if (track_write && (track_waddr==track_raddr)) begin


            track_status[track_update_id] <= track_wdata[0];
          end else begin

            track_status[track_update_id] <= track_rdata[0];
          end
        end

        if (rx_write_valid && rx_waddr < DATA_CQ_ADDR) begin
          if (!track_error && rx_status_field!=0) begin
            track_error <= 1'b1;
            track_error_data <= rx_wdata;
          end

          if (rx_q_index!=`CMD_SSD0_Q0 && rx_q_index!=`CMD_SSD1_Q0) begin
            track_write <= 1'b1;
            track_wdata[0] <= 1'b1;
            track_wdata[1] <= (rx_status_field==0) ? 1'b0 : 1'b1;
            track_waddr <= {rx_action_id, rx_req_id};

            if (rx_req_id == track_index_array[rx_action_id]) begin
              track_status[rx_action_id] <= 1'b1;

              if (track_status[rx_action_id]) begin
                track_overflow <= 1'b1;
              end
            end
          end
        end
      end
    end
  end


endmodule