p.v


   ,input                    dbg_sel_pi_incdec
   ,input                    dbg_sel_po_incdec
   ,input [DQS_CNT_WIDTH:0]  dbg_byte_sel
   ,input                    dbg_pi_f_inc
   ,input                    dbg_pi_f_dec
   ,input                    dbg_po_f_inc
   ,input                    dbg_po_f_stg23_sel
   ,input                    dbg_po_f_dec
   ,output [6*DQS_WIDTH*RANKS-1:0] dbg_cpt_tap_cnt
   ,output [5*DQS_WIDTH*RANKS-1:0] dbg_fine_tap_cnt
   ,output                   dbg_rddata_valid
   ,output [5:0]             dbg_pi_counter_read_val
   ,output [8:0]             dbg_po_counter_read_val
   ,output                   ref_dll_lock
   ,input                    rst_phaser_ref
   ,output [255:0]           dbg_phy_init
   ,output psen 
   ,output psincdec
   ,input dbg_pd_off             
   ,input dbg_pd_maintain_off    
   ,input dbg_pd_maintain_0_only 
   ,input dbg_pd_inc_dqs         
   ,input dbg_pd_dec_dqs         
   ,input dbg_pd_byte_sel        
   ,input dbg_inc_rd_fps         
   ,input dbg_dec_rd_fps         
   ,output [255:0]   dbg_phy_pd         

   );
   
  localparam nSLOTS  = 1 + (|SLOT_1_CONFIG ? 1 : 0);
  localparam SLOT_0_CONFIG_MC = (nSLOTS == 2)? 8'b0000_0101 : 8'b0000_1111;
  localparam SLOT_1_CONFIG_MC = (nSLOTS == 2)? 8'b0000_1010 : 8'b0000_0000; 
   
  reg [7:0]               slot_0_present_mc;
  reg [7:0]               slot_1_present_mc; 
   
  reg user_periodic_rd_req = 1'b0;
  reg user_ref_req = 1'b0;
  reg user_zq_req = 1'b0;

  // MC/PHY interface
  wire [2*nCK_PER_CLK*CA_WIDTH-1:0]   mc_ca;
  wire [nCK_PER_CLK-1 :0]             mc_cke ;
  wire [CS_WIDTH*nCS_PER_RANK*nCK_PER_CLK-1:0] mc_cs_n;
  wire [2*nCK_PER_CLK*DQ_WIDTH-1:0]   mc_wrdata;
  wire [2*nCK_PER_CLK*DQ_WIDTH/8-1:0] mc_wrdata_mask;
  wire                                mc_wrdata_en;
  wire                                mc_ref_zq_wip;
  wire                                idle;

  wire                                mc_cmd_wren;
  wire                                mc_ctl_wren;
  wire  [2:0]                         mc_cmd;
  wire  [1:0]                         mc_cas_slot;
  wire  [5:0]                         mc_data_offset;
  wire  [5:0]                         mc_data_offset_1;
  wire  [5:0]                         mc_data_offset_2;
  wire  [3:0]                         mc_aux_out0;
  wire  [3:0]                         mc_aux_out1;
  wire  [1:0]                         mc_rank_cnt;

  wire                                phy_mc_ctl_full;
  wire                                phy_mc_cmd_full;
  wire                                phy_mc_data_full;
  wire  [2*nCK_PER_CLK*DQ_WIDTH-1:0]  phy_rd_data;
  wire                                phy_rddata_valid;
  
  wire                                init_calib_complete_w;
  wire                                mux_rst;
  wire                                mux_calib_complete;
  // assigning CWL = CL -1 for DDR2. DDR2 customers will not know anything
  // about CWL. There is also nCWL parameter. Need to clean it up.
  // localparam CWL_T = (DRAM_TYPE == "DDR3") ? CW