integer i;

initial begin   
   $display("\n\n#################################################################");
   $display("                        TEST WRAPPER");
   $display("#################################################################");
   
   #100_000;
   sel_in_reg =1'b1;
   vddi2c_detect = 1'b1;   
   #100_000;
   
   $display("\n VIN plug @ 7V");
   $display("// ----------------------------------------------------------------");
   vcore_vin_uvlo.vin_lvl(7000);   
   #100_000;
   
   $display("\nValidate test_mode");
   $display("---------------------------------------------------\n");
   i2c_master.i2cWr(8'd126,8'h17);
   i2c_master.i2cWr(8'd126,8'h51);
   #100;
   i2c_test_mode_sns_fld = 1'b1;
   i2c_read_fields(`TEST_REGISTER0,8'hf8);
   #1_000;
   i2c_test_mode_sns_fld = 1'b1;
   i2c_read_fields(`TEST_REGISTER0,i2c_test_mode_sns_mask);
      
   $display("\nForce test state");
   $display("---------------------------------------------------\n");
   i2c_test_state_fld = 1'b1;
   i2c_write_fields(fnGetAddr("i2c_test_state_fld"));
   i2c_read_fields(fnGetAddr("i2c_test_state_fld"),8'hf8);
   #100_000;
   
   $display("\nEnable output mgt");
   $display("---------------------------------------------------\n");
   i2c_en_output_wrapper_fld = 1'b1;
   i2c_write_fields(fnGetAddr("i2c_en_output_wrapper_fld"));
   i2c_read_fields(fnGetAddr("i2c_en_output_wrapper_fld"),8'hff);
   #100_000;
      
   check_digital_net_id("en_refs",en_refs,1'b1);   //en en_refs is wrapped to 1'b1
   check_digital_net_id("en_vreg",en_vreg,1'b1);   //en en_vreg is wrapped to 1'b1
   
   
   $display("\nCheck test_register8: output_ctrl1");
   $display("---------------------------------------------------\n");
   for (i=0;i<128;i=i+1) begin
      i2c_wrap_en_tsd_fld           = i[6];
      i2c_wrap_clk_12Mhz_en_fld     = i[5];
      i2c_wrap_en_vin_monitor_fld   = i[4];
      i2c_wrap_en_clo_det_fld       = i[3];               
      i2c_wrap_en_vldo_fld          = i[2];
      i2c_wrap_en_vin_meter_fld     = i[1];
      i2c_wrap_en_iin_meter_fld     = i[0];
      i2c_write_fields(`TEST_REGISTER8);
      i2c_read_fields(`TEST_REGISTER8,8'hff);     
      #100;

      check_digital_net({ en_tsd,
                          en_clk_12Mhz,
                          en_vin_monitor ,
                          en_clo_det,
                          en_vldo,
                          en_vin_meter,
                          en_iin_meter },i[6:0]);
      
      #100;
   end
   repeat (1) #1_000_000;
   
   $display("\nCheck test_register9: output_ctrl2");
   $display("---------------------------------------------------\n");
   for (i=0;i<128;i=i+1) begin
      i2c_wrap_cp_pass_thru_fld  = i[6];
      i2c_wrap_cp_wait_fld       = i[5];
      i2c_wrap_cp_div2_fld       = i[4];
      i2c_wrap_cp_tsd_fld        = i[3];
      i2c_wrap_en_cp_fld         = i[2];
      i2c_wrap_cp_en_pmos_fld    = i[1];
      i2c_wrap_en_vin_vcl_fld    = i[0];
      i2c_write_fields(`TEST_REGISTER9);
      i2c_read_fields(`TEST_REGISTER9,8'hff);
      
      #100;
      check_digital_net_id( "cp_pass_thru"   , cp_pass_thru  ,i[6]);
      check_digital_net_id( "cp_wait"        , cp_wait       ,i[5]);
      check_digital_net_id( "cp_div2"        , cp_div2       ,i[4]);
      check_digital_net_id( "cp_tsd"         , cp_tsd        ,i[3]);
      check_digital_net_id( "en_cp"          , en_cp         ,i[2]);
      check_digital_net_id( "cp_en_pmos"     , cp_en_pmos    ,i[1]);
      check_digital_net_id( "en_vin_vcl"     , en_vin_vcl    ,i[0]);
      
      #100;
   end
   repeat (10) #1_000_000;  
   
   
   END_SIM;
end
