integer i;

initial begin
   #100_000;
   sel_in_reg =1'b1;
   vddi2c_detect = 1'b1;   
   #100_000;
         
   $display("\n\n#################################################################");
   $display("                        MEMMAP - TEST");
   $display("#################################################################");
    
   $display("\n VIN plug @ 7V");
   $display("// ----------------------------------------------------------------");
   vcore_vin_uvlo.vin_lvl(7000);   

   @(posedge cp_pass_thru);
   $display("\n enter PT");    
   
   $display("\nDe-activate ADC auto conv");
   $display("---------------------------------------------------\n");
   i2c_adc_manual_fld = 1'b1;
   i2c_write_fields(`CMD3);
   #1_000;
   
   $display("\nValidate test_mode");
   $display("---------------------------------------------------\n");
   i2c_master.i2cWr(8'd126,8'h17);
   i2c_master.i2cWr(8'd126,8'h51);
   #1_000;
   i2c_test_mode_sns_fld = 1'b1;
   i2c_read_fields(`TEST_REGISTER0,i2c_test_mode_sns_mask);
  
   $display("\nTEST REGISTER0 other bits");
   $display("---------------------------------------------------\n");
   for (i=0;i<8;i=i+1) begin
      {i2c_test_state_fld,i2c_fast_clk_fld,i2c_tb_force_uvlob_fld }= i;
      i2c_write_fields(`TEST_REGISTER0);
      i2c_read_fields(`TEST_REGISTER0,8'hf8);
      #100;
      check_digital_net_id("fast_clk",fast_clk,i[1]);
      check_digital_net_id("force_uvlob",force_uvlob,i[0]);
      #100;
   end
  {i2c_test_state_fld,i2c_fast_clk_fld,i2c_tb_force_uvlob_fld }= 0;  
  i2c_write_fields(`TEST_REGISTER0);

   $display("\nTEST_REGISTER1");
   $display("---------------------------------------------------\n");
   for (i=0;i<256;i=i+1) begin
      {i2c_tb_no_wait_state_fld,i2c_tb_tsd_blk_fld,i2c_tb_no_ldo_ishort_fld,i2c_tb_vldo_dischg_dis_fld,i2c_tb_force_clo_in_fld,i2c_tb_clk_div2_fld[1:0],i2c_tb_clk_pt_dis_fld} = i;
      i2c_write_fields(`TEST_REGISTER1);
      i2c_read_fields(`TEST_REGISTER1,8'hff);
      #100;
      check_digital_net_id("tb_no_ldo_ishort",tb_no_ldo_ishort,i[5]);

      #100;
   end
   {i2c_tb_no_wait_state_fld,i2c_tb_tsd_blk_fld,i2c_tb_no_ldo_ishort_fld,i2c_tb_vldo_dischg_dis_fld,i2c_tb_force_clo_in_fld,i2c_tb_clk_div2_fld[1:0],i2c_tb_clk_pt_dis_fld} = 0;
   i2c_write_fields(`TEST_REGISTER1);
   
   $display("\nTEST_REGISTER2");
   $display("---------------------------------------------------\n");
   for (i=0;i<256;i=i+1) begin
      {i2c_tb_refs_fld,i2c_tb_osc_byp_fld,i2c_tb_force_vref_startup_fld,i2c_tb_spare1_fld,i2c_tb_spare2_fld }= i;
      i2c_write_fields(`TEST_REGISTER2);
      i2c_read_fields(`TEST_REGISTER2,8'hff);
      #100;
      check_digital_net_id("tb_refs[2:0]",tb_refs,i[6:4]);
      check_digital_net_id("force_vref_startup",force_vref_startup,i[2]);
      #100;
   end
      {i2c_tb_refs_fld,i2c_tb_osc_byp_fld,i2c_tb_force_vref_startup_fld,i2c_tb_spare1_fld,i2c_tb_spare2_fld }= 0;
      i2c_write_fields(`TEST_REGISTER2);
      

   $display("\nTEST_REGISTER3");
   $display("---------------------------------------------------\n");
   for (i=0;i<128;i=i+1) begin
      {i2c_tb_adc_signed_fld,i2c_tb_adc_dft_config_fld,i2c_tb_adc_channel_fld, i2c_tb_adc_az_dis_fld,i2c_tb_adc_ext_vref_fld}= i;
      i2c_write_fields(`TEST_REGISTER3);
      i2c_read_fields(`TEST_REGISTER3,8'hff);     
      #100;
      check_digital_net_id("adc_signed_conv",adc_signed_conv,i[5]);
      check_digital_net_id("adc_az_dis",adc_az_dis,i[1]);
      check_digital_net_id("adc_ext_vref",adc_ext_vref,i[0]);
      #100;
   end
      {i2c_tb_adc_signed_fld,i2c_tb_adc_dft_config_fld,i2c_tb_adc_channel_fld, i2c_tb_adc_az_dis_fld,i2c_tb_adc_ext_vref_fld}= 0;
      i2c_write_fields(`TEST_REGISTER3);


   $display("\nTEST_REGISTER5");
   $display("---------------------------------------------------\n");
   for (i=0;i<64;i=i+1) begin
      {i2c_tb_adc_hold_delay_fld,i2c_en_fuse_bypass_fld,i2c_tb_en_fuse_curr_sink_fld}= i;
      i2c_write_fields(`TEST_REGISTER5);
      i2c_read_fields(`TEST_REGISTER5,8'hff);     
      #100;
      check_digital_net_id("adc_hold_delay[2:0]",adc_hold_delay,i[4:2]);
      check_digital_net_id("en_fuse_bypass",en_fuse_bypass,i[1]);
      check_digital_net_id("tb_en_fuse_curr_sink",tb_en_fuse_curr_sink,i[0]);
      #100;
   end
      {i2c_tb_adc_hold_delay_fld,i2c_en_fuse_bypass_fld,i2c_tb_en_fuse_curr_sink_fld}= 0;
      i2c_write_fields(`TEST_REGISTER5);

   $display("\nTEST_REGISTER6");
   $display("---------------------------------------------------\n");
   for (i=0;i<256;i=i+1) begin
      {i2c_en_test_mux1_fld,i2c_test_mux1_ctrl_fld,i2c_en_test_mux2_fld,i2c_test_mux2_ctrl_fld}= i;
      i2c_write_fields(`TEST_REGISTER6);
      i2c_read_fields(`TEST_REGISTER6,8'hff);     
      #100;
      check_digital_net_id("en_test_mux1",en_test_mux1,i[7]);
      check_digital_net_id("test_mux1_ctrl[2:0]",test_mux1_ctrl,i[6:4]);
      check_digital_net_id("en_test_mux2",en_test_mux2,i[3]);
      check_digital_net_id("test_mux2_ctrl[2:0]",test_mux2_ctrl,i[2:0]);
      #100;
    end
      {i2c_en_test_mux1_fld,i2c_test_mux1_ctrl_fld,i2c_en_test_mux2_fld,i2c_test_mux2_ctrl_fld}= 0;
      i2c_write_fields(`TEST_REGISTER6);

   $display("\nTEST_REGISTER7");
   $display("---------------------------------------------------\n");
   for (i=0;i<128;i=i+1) begin
      {i2c_dig_mux_fld,i2c_tb_digmux_clo_fld}= i;
      i2c_write_fields(`TEST_REGISTER7);
      i2c_read_fields(`TEST_REGISTER7,8'hff);     
      #100;
    end
      {i2c_dig_mux_fld,i2c_tb_digmux_clo_fld}= 0;
      i2c_write_fields(`TEST_REGISTER7);
     
   repeat (1) #1_000_000;
   END_SIM;
   
end
