
initial begin
   #100_000;

   // Slew
   // ----------------------------------------------------------------
   vcore_vin_uvlo.VIN_SLEW  = 100;
   
   sel_in_reg =1'b1;
   vddi2c_detect = 1'b1;           
   #100_000;

   $display("\n VIN plug @ 10V");
   $display("---------------------------------------------------\n");
   vcore_vin_uvlo.vin_lvl(10000);    
   @(posedge vin_uvlo);
   $display("\n enter precharge");   
   @(posedge en_clo_det);
   $display("\n CLO detection on going");      
   @(posedge en_cp);
   $display("\n enter precharge");
   @(posedge cp_div2);
   $display("\n enter div2");    
   i2c_vth_stat_fld = 1'b1;
   i2c_vth_sns_fld = 1'b1;
   i2c_vth_int_fld = 1'b1;

   $display("\n// clear interrupts");
   $display("// ----------------------------------------------------------------");   
   i2c_read_fields(`INTERRUPTS,8'hff);
   #5_000;   
   i2c_vth_int_fld = 1'b0;
   i2c_vth_stat_fld = 1'b0;
   
   $display("\n// read status");
   $display("// ----------------------------------------------------------------");   
   i2c_read_fields(`STATUS,8'hff);
   #5_000;   
            
   $display(" over current according to ADC conversion: posedge interrupt");
   $display("// ----------------------------------------------------------------");          
   data1 = $random;
   data2 = 11'b011_1111_1100;
   data3 = $random;
   data4 = $random;    

   @(posedge adc_eoc);   // waiting for periodic conversion
   i2c_adc_eoc_sns_fld  = 1'b1;
   i2c_adc_eoc_int_fld  = 1'b1;
   i2c_adc_eoc_stat_fld = 1'b1;  
   @(posedge adc_eoc);   // i conv
   i2c_oca_stat_fld = 1'b1;
   i2c_oca_sns_fld  = 1'b1;
   i2c_oca_int_fld  = 1'b1;
   
   $display("Check int status high and sense high");
   i2c_read_fields(`SNS1,8'hff);  
   i2c_read_fields(`STATUS,8'hff);
   #1_000;   

   $display("Check interrupt high,clear interrupt");
   i2c_read_fields(`INTERRUPTS,8'hff);    
   i2c_oca_int_fld      = 1'b0;
   i2c_oca_stat_fld     = 1'b0;
   i2c_vth_int_fld      = 1'b0;
   i2c_adc_eoc_sns_fld  = 1'b0;
   i2c_adc_eoc_int_fld  = 1'b0;
   i2c_adc_eoc_stat_fld = 1'b0;     
   #1_000;     
   
   $display("Check int cleared");
   i2c_read_fields(`INTERRUPTS,8'hff);    
   #1_000;   

   $display("Check int status low");
   i2c_read_fields(`STATUS,8'hff);

   $display("Check sense still high");
   i2c_read_fields(`SNS1,8'hff);  
   #1_000;   

   #10_000;       
   $display("\n// over voltage end: no interrupt");
   $display("// ----------------------------------------------------------------");      
   data1 = $random;
   data2 = 11'b011_1111_1000;
   data3 = $random;
   data4 = $random;    

   @(posedge adc_eoc);   // waiting for periodic conversion   
   i2c_adc_eoc_sns_fld  = 1'b1;
   i2c_adc_eoc_int_fld  = 1'b1;
   i2c_adc_eoc_stat_fld = 1'b1;  
   @(posedge adc_eoc);   // i conv
   i2c_oca_sns_fld  = 1'b0;
      
   $display("Check int status and sense");
   i2c_read_fields(`SNS1,8'hff);  
   i2c_read_fields(`STATUS,8'hff);
   #1_000;   
   
   $display("Check and clear interrupts");
   i2c_read_fields(`INTERRUPTS,8'hff);    
   i2c_vth_int_fld      = 1'b0;
   i2c_adc_eoc_sns_fld  = 1'b0;
   i2c_adc_eoc_int_fld  = 1'b0;
   i2c_adc_eoc_stat_fld = 1'b0; 
   #1_000;   
   
   $display("Check int status low");
   i2c_read_fields(`STATUS,8'hff);
   #1_000;   

   $display("Check int cleared");
   i2c_read_fields(`INTERRUPTS,8'hff);    
   #1_000;   
   
   $display("Check sense still low");
   i2c_read_fields(`SNS1,8'hff);  
   #1_000;   
   
   repeat (1) #1_000_000;
// ----------------------------------------------------------------

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

