initial begin
   #100_000;

   // Slew
   // ----------------------------------------------------------------
   vcore_vin_uvlo.VIN_SLEW  = 200;
   
   vddi2c_detect = 1'b0;            // No bus on slave IC
   
//    force vcore_vin_uvlo.vout = 0;
   
   repeat (1) #1_000_000;

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

// ----------------------------------------------------------------
// LATCH_OTP
// ----------------------------------------------------------------  
   $display("\n VIN plug @ 4V");
   $display("---------------------------------------------------\n");
   vcore_vin_uvlo.vin_lvl(4000);   
 
   @(posedge slave.vin_uvlo);
   $display("\n LATCH_OTP");
   $display("---------------------------------------------------\n");
   #1000;
   check_digital_net_id("en_clk_12Mhz",slave.en_clk_12Mhz,1);
   check_digital_net_id("en_refs",slave.en_refs,1);   
   @(posedge slave.en_vreg);
   @(posedge slave.en_vin_monitor);
   
// ----------------------------------------------------------------
// CLO_DET
// ----------------------------------------------------------------  
   @(posedge slave.en_clo_det);
   $display("\n CLO detection on going");
   $display("---------------------------------------------------\n");
   #9_000;  

// ----------------------------------------------------------------
// PRECHARGE
// ----------------------------------------------------------------  
   @(posedge slave.en_cp);
   #1000;
   
   $display("\n VOUT precharge @ 4V");
   $display("---------------------------------------------------\n");
   check_digital_net_id("en_tsd",slave.en_tsd,1);
   check_digital_net_id("en_clo_det",slave.en_clo_det,0);
   check_digital_net_id("en_vldo",slave.en_vldo,0);            /// SLAVE
   
   vcore_vin_uvlo.VIN_SLEW  = 5;
   repeat (10) begin
      #5_000;  
      vcore_vin_uvlo.vin_lvl(3590);
      #5_000;  
      vcore_vin_uvlo.vin_lvl(4000);     
   end

   @(posedge vin_uvlo);
   #1000;
   vcore_vin_uvlo.VIN_SLEW  = 200;
   vcore_vin_uvlo.vin_lvl(10000);   

   check_digital_net_id("cp_clk_div2",slave.cp_clk_div2,0);    
   check_digital_net_id("en_cp",       slave.en_cp,         1);
   check_digital_net_id("cp_en_pmos",  slave.cp_en_pmos,    1);
   check_digital_net_id("cp_pass_thru",slave.cp_pass_thru,  0);
   check_digital_net_id("cp_wait",     slave.cp_wait,       0);   
   check_digital_net_id("cp_div2",     slave.cp_div2,       0);      
   check_digital_net_id("cp_tsd",      slave.cp_tsd,        0);     
 
// ----------------------------------------------------------------
// PASSTHROUGH
// ----------------------------------------------------------------     
   @(posedge slave.cp_pass_thru);
   #1000;
   
   $display("\n Check passthru state");
   $display("---------------------------------------------------\n");
   check_digital_net_id("en_clk_12Mhz",slave.en_clk_12Mhz,1);
   check_digital_net_id("en_vreg",slave.en_vreg,1);
   check_digital_net_id("en_refs",slave.en_refs,1);
   check_digital_net_id("en_vin_monitor",slave.en_vin_monitor,1);
   check_digital_net_id("en_tsd",slave.en_tsd,1);
   check_digital_net_id("en_clo_det",slave.en_clo_det,0);
   check_digital_net_id("cp_clk_div2", slave.cp_clk_div2,   0);    


   check_digital_net_id("en_cp",       slave.en_cp,         1);
   check_digital_net_id("cp_en_pmos",  slave.cp_en_pmos,    1);
   check_digital_net_id("cp_pass_thru",slave.cp_pass_thru,  1);
   check_digital_net_id("cp_wait",     slave.cp_wait,       0);   
   check_digital_net_id("cp_div2",     slave.cp_div2,       0);      
   check_digital_net_id("cp_tsd",      slave.cp_tsd,        0);     

// ----------------------------------------------------------------
// WAIT
// ----------------------------------------------------------------  
   @(posedge slave.mode_in);
   #1000;
   check_digital_net_id("cp_clk_div2",slave.cp_clk_div2,0);    
   check_digital_net_id("en_cp",       slave.en_cp,         1);
   check_digital_net_id("cp_en_pmos",  slave.cp_en_pmos,    0);
   check_digital_net_id("cp_pass_thru",slave.cp_pass_thru,  0);
   check_digital_net_id("cp_wait",     slave.cp_wait,       1);   
   check_digital_net_id("cp_div2",     slave.cp_div2,       0);      
   check_digital_net_id("cp_tsd",      slave.cp_tsd,        0);     

   $display("\n VOUT falling @ VIN/2");
   $display("---------------------------------------------------\n");

// ----------------------------------------------------------------
// DIV2
// ----------------------------------------------------------------  
   @(posedge cp_div2);
   #10;
   check_digital_net_id("en_cp",       slave.en_cp,         1);
   check_digital_net_id("cp_en_pmos",  slave.cp_en_pmos,    0);
   check_digital_net_id("cp_pass_thru",slave.cp_pass_thru,  0);
   check_digital_net_id("cp_wait",     slave.cp_wait,       1);   
   check_digital_net_id("cp_div2",     slave.cp_div2,       0);      
   check_digital_net_id("cp_tsd",      slave.cp_tsd,        0);     
   @(posedge slave.cp_div2);
   #1000;
   check_digital_net_id("en_cp",       slave.en_cp,         1);
   check_digital_net_id("cp_en_pmos",  slave.cp_en_pmos,    0);
   check_digital_net_id("cp_pass_thru",slave.cp_pass_thru,  0);
   check_digital_net_id("cp_wait",     slave.cp_wait,       0);   
   check_digital_net_id("cp_div2",     slave.cp_div2,       1);      
   check_digital_net_id("cp_tsd",      slave.cp_tsd,        0);   
     
    
   repeat (1) #1_000_000;
   $display("\n VIN falling < Vth");
   $display("---------------------------------------------------\n");
   vcore_vin_uvlo.VIN_SLEW  = 300;
   vcore_vin_uvlo.vin_lvl(8000);   

// ----------------------------------------------------------------
// PASSTHROUGH
// ----------------------------------------------------------------     
   @(negedge slave.mode_in);
   $display("\n MODE pin low");
   $display("---------------------------------------------------\n");
   #1000;
   check_digital_net_id("en_cp",       slave.en_cp,         1);
   check_digital_net_id("cp_en_pmos",  slave.cp_en_pmos,    0);
   check_digital_net_id("cp_pass_thru",slave.cp_pass_thru,  0);
   check_digital_net_id("cp_wait",     slave.cp_wait,       0);   
   check_digital_net_id("cp_div2",     slave.cp_div2,       1);      
   check_digital_net_id("cp_tsd",      slave.cp_tsd,        0);   
   
   @(posedge slave.cp_pass_thru);
   $display("\n PT entered");
   $display("---------------------------------------------------\n");
   #1000;
   check_digital_net_id("en_cp",       slave.en_cp,         1);
   check_digital_net_id("cp_en_pmos",  slave.cp_en_pmos,    1);
   check_digital_net_id("cp_pass_thru",slave.cp_pass_thru,  1);
   check_digital_net_id("cp_wait",     slave.cp_wait,       0);   
   check_digital_net_id("cp_div2",     slave.cp_div2,       0);      
   check_digital_net_id("cp_tsd",      slave.cp_tsd,        0);   
   

// ----------------------------------------------------------------
// OFF
// ----------------------------------------------------------------  
   vcore_vin_uvlo.VIN_SLEW  = 100;
   vcore_vin_uvlo.vin_lvl(2400);   

   @(negedge slave.vin_uvlo);
   $display("\n UVLO");
   $display("---------------------------------------------------\n");
   #1000;
   check_digital_net_id("en_cp",       slave.en_cp,         0);
   check_digital_net_id("cp_en_pmos",  slave.cp_en_pmos,    0);
   check_digital_net_id("cp_pass_thru",slave.cp_pass_thru,  0);
   check_digital_net_id("cp_wait",     slave.cp_wait,       0);   
   check_digital_net_id("cp_div2",     slave.cp_div2,       0);      
   check_digital_net_id("cp_tsd",      slave.cp_tsd,        0);   
   


   repeat (1) #1_000_000;

   // End
   // ----------------------------------------------------------------
   END_SIM;
   
end

