`define otp_force_uvlob    otp[51]

initial begin
   #100_000;
   vcore_vin_uvlo.VIN_SLEW  = 200;
   
   $display("\n Master and I2C");
   $display("---------------------------------------------------\n");
   sel_in_reg =1'b1;
   vddi2c_detect = 1'b1;

//   force digital_control_top.otp_i2c_add = 2'b00;   
   #100_000;

   $display("\n Check outputs at startup");
   $display("---------------------------------------------------\n");
   check_digital_net_id("en_clk_12Mhz",en_clk_12Mhz,0);
   check_digital_net_id("en_cp",en_cp,0);
   check_digital_net_id("en_vreg",en_vreg,0);
   check_digital_net_id("en_refs",en_refs,0);
   check_digital_net_id("en_vin_monitor",en_vin_monitor,0);
   check_digital_net_id("en_tsd",en_tsd,0);
   check_digital_net_id("en_clo_det",en_clo_det,0);
   check_digital_net_id("cp_en_pmos",cp_en_pmos,0);   
   check_digital_net_id("en_iin_meter",en_iin_meter,0);
   check_digital_net_id("en_vin_meter",en_vin_meter,0); 
   check_digital_net_id("cp_clk_div2",cp_clk_div2,0);    
   check_digital_net_id("cp_clk_pass_thru",cp_clk_pass_thru,0);    
   check_digital_net_id("cp_pass_thru",cp_pass_thru,0);
   check_digital_net_id("cp_tsd",cp_tsd,0);     
   check_digital_net_id("cp_wait",cp_wait,0);   
   check_digital_net_id("cp_div2",cp_div2,0);           
   #100_000;

   $display("\n VIN plug @ 3.1V");
   $display("---------------------------------------------------\n");
   vcore_vin_uvlo.vin_lvl(3100);   
   #500_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);   
   #10_000;
   
   i2c_tb_force_uvlob_fld = 1'b1;
   i2c_write_fields(fnGetAddr("i2c_tb_force_uvlob_fld"));   

//   release digital_control_top.otp_i2c_add;   

   $display("\n LATCH_OTP");
   $display("---------------------------------------------------\n");
   #10;
   check_digital_net_id("en_clk_12Mhz",en_clk_12Mhz,1);
   check_digital_net_id("en_refs",en_refs,1);   
   @(posedge en_vreg);
   @(posedge en_vin_monitor);

   @(posedge en_clo_det);
   $display("\n CLO detection on going");
   $display("---------------------------------------------------\n");

   @(posedge en_cp);
   $display("\n charge pump enabled");
   $display("---------------------------------------------------\n");
   @(posedge cp_en_pmos);
   check_digital_net_id("en_clo_det",en_clo_det,0);
   check_digital_net_id("en_tsd",en_tsd,1);
 
   @(posedge cp_pass_thru);
   i2c_read_fields(fnGetAddr("i2c_tb_force_uvlob_fld"),8'hf8);   
   #10_000;

   i2c_tb_force_uvlob_fld = 1'b0;
   i2c_write_fields(fnGetAddr("i2c_tb_force_uvlob_fld")); 
   i2c_read_fields(fnGetAddr("i2c_tb_force_uvlob_fld"),8'hff);
   #10_000;
   
   $display("\n Check uvlo");
   $display("---------------------------------------------------\n");
   check_digital_net_id("en_clk_12Mhz",en_clk_12Mhz,0);
   check_digital_net_id("en_cp",en_cp,0);
   check_digital_net_id("en_vreg",en_vreg,0);
   check_digital_net_id("en_refs",en_refs,0);
   check_digital_net_id("en_vin_monitor",en_vin_monitor,0);
   check_digital_net_id("en_tsd",en_tsd,0);
   check_digital_net_id("en_clo_det",en_clo_det,0);
   check_digital_net_id("cp_en_pmos",cp_en_pmos,0);   
   check_digital_net_id("en_iin_meter",en_iin_meter,0);
   check_digital_net_id("en_vin_meter",en_vin_meter,0); 
   check_digital_net_id("cp_pass_thru",cp_pass_thru,0);
   check_digital_net_id("cp_tsd",cp_tsd,0);     
   check_digital_net_id("cp_wait",cp_wait,0);   
   check_digital_net_id("cp_div2",cp_div2,0);       
   
   $display("\n// turn off");
   $display("// ----------------------------------------------------------------"); 
   vcore_vin_uvlo.vin_lvl(0);    
   
   repeat (1) #1_000_000;   
// -------------------------------------------------------------------------------
// -------------------------------------------------------------------------------
   $display("\n Master and OWI");
   $display("---------------------------------------------------\n");
   sel_in_reg =1'b0;
   force `otp_force_uvlob = 1'b1;   

   $display("\n Check outputs at startup");
   $display("---------------------------------------------------\n");
   check_digital_net_id("en_clk_12Mhz",en_clk_12Mhz,0);
   check_digital_net_id("en_cp",en_cp,0);
   check_digital_net_id("en_vreg",en_vreg,0);
   check_digital_net_id("en_refs",en_refs,0);
   check_digital_net_id("en_vin_monitor",en_vin_monitor,0);
   check_digital_net_id("en_tsd",en_tsd,0);
   check_digital_net_id("en_clo_det",en_clo_det,0);
   check_digital_net_id("cp_en_pmos",cp_en_pmos,0);   
   check_digital_net_id("en_iin_meter",en_iin_meter,0);
   check_digital_net_id("en_vin_meter",en_vin_meter,0); 
   check_digital_net_id("cp_clk_div2",cp_clk_div2,0);    
   check_digital_net_id("cp_clk_pass_thru",cp_clk_pass_thru,0);    
   check_digital_net_id("cp_pass_thru",cp_pass_thru,0);
   check_digital_net_id("cp_tsd",cp_tsd,0);     
   check_digital_net_id("cp_wait",cp_wait,0);   
   check_digital_net_id("cp_div2",cp_div2,0);           
   #100_000;

   $display("\n VIN plug @ 3.1V");
   $display("---------------------------------------------------\n");
   vcore_vin_uvlo.vin_lvl(3950);       

   @(posedge en_refs);
   $display("\n LATCH_OTP");
   $display("---------------------------------------------------\n");
   #20;
   check_digital_net_id("en_clk_12Mhz",en_clk_12Mhz,1);
   
   @(posedge en_vreg);
   @(posedge en_vin_monitor);

   @(posedge en_clo_det);
   $display("\n CLO detection on going");
   $display("---------------------------------------------------\n");

   @(posedge en_cp);
   $display("\n charge pump enabled");
   $display("---------------------------------------------------\n");
   @(posedge cp_en_pmos);
   check_digital_net_id("en_clo_det",en_clo_det,0);
   check_digital_net_id("en_tsd",en_tsd,1);

   vcore_vin_uvlo.VIN_SLEW  = 100;
   vcore_vin_uvlo.vin_lvl(3100);   

   @(posedge cp_pass_thru);
     
   #500_000; 
   release `otp_force_uvlob;
   #10_000;
   
   $display("\n Check uvlo");
   $display("---------------------------------------------------\n");
   check_digital_net_id("en_clk_12Mhz",en_clk_12Mhz,0);
   check_digital_net_id("en_cp",en_cp,0);
   check_digital_net_id("en_vreg",en_vreg,0);
   check_digital_net_id("en_refs",en_refs,0);
   check_digital_net_id("en_vin_monitor",en_vin_monitor,0);
   check_digital_net_id("en_tsd",en_tsd,0);
   check_digital_net_id("en_clo_det",en_clo_det,0);
   check_digital_net_id("cp_en_pmos",cp_en_pmos,0);   
   check_digital_net_id("en_iin_meter",en_iin_meter,0);
   check_digital_net_id("en_vin_meter",en_vin_meter,0); 
   check_digital_net_id("cp_pass_thru",cp_pass_thru,0);
   check_digital_net_id("cp_tsd",cp_tsd,0);     
   check_digital_net_id("cp_wait",cp_wait,0);   
   check_digital_net_id("cp_div2",cp_div2,0);         
   
   $display("\n// turn off");
   $display("// ----------------------------------------------------------------"); 
   vcore_vin_uvlo.vin_lvl(0);        
   repeat (1) #1_000_000;   
   // End
   // ----------------------------------------------------------------
   END_SIM;
   
end
