data/full_repos/permissive/172201645/src/auxch/hotplug_decode.v
data/verilator_xmls/f585f7cb-0973-44b7-a0d8-97aa0c839da4.xml
module hotplug_decode(
    input  clk,
    input  hpd,
    output reg irq,
    output reg present
);

   reg hpd_meta1;
   reg hpd_meta2;
   reg hpd_synced;
   reg hpd_last;

   reg [17:0] pulse_count;


initial begin
    hpd_meta1    = 1'b0;
    hpd_meta2    = 1'b0;
    hpd_synced   = 1'b0;
    hpd_last     = 1'b1;
    pulse_count  = 18'b0;
    present      = 1'b0;
    irq          = 1'b0;
end 

always @(posedge clk) begin
    irq <= 1'b0;
    if(hpd_last == 1'b0) begin
        if(hpd_synced == 1'b0) begin
            if(pulse_count == 200000) begin




                present <= 1'b0;
            end else begin
                pulse_count <= pulse_count + 1;
            end
        end else begin



            if(pulse_count > 100000) begin




                if(present == 1'b1) begin
                  irq <= present;
                end
            end
            pulse_count = 18'b0;
        end
    end else begin
        if(hpd_synced == 1'b0) begin
            pulse_count = 18'b0;
        end else begin
            if(pulse_count == 220000) begin
                present <= 1'b1;
            end else begin
                pulse_count <= pulse_count + 1;
            end
        end
    end
    hpd_last   <= hpd_synced;
    hpd_synced <= hpd_meta1;
    hpd_meta1  <= hpd_meta2;
    hpd_meta2  <= hpd;
end
endmodule
module hotplug_decode(
    input  clk,
    input  hpd,
    output reg irq,
    output reg present
);


   reg hpd_meta1;
   reg hpd_meta2;
   reg hpd_synced;
   reg hpd_last;

   reg [17:0] pulse_count;


initial begin
    hpd_meta1    = 1'b0;
    hpd_meta2    = 1'b0;
    hpd_synced   = 1'b0;
    hpd_last     = 1'b1;
    pulse_count  = 18'b0;
    present      = 1'b0;
    irq          = 1'b0;
end 

always @(posedge clk) begin
    irq <= 1'b0;
    if(hpd_last == 1'b0) begin
        if(hpd_synced == 1'b0) begin
            if(pulse_count == 200000) begin




                present <= 1'b0;
            end else begin
                pulse_count <= pulse_count + 1;
            end
        end else begin



            if(pulse_count > 100000) begin




                if(present == 1'b1) begin
                  irq <= present;
                end
            end
            pulse_count = 18'b0;
        end
    end else begin
        if(hpd_synced == 1'b0) begin
            pulse_count = 18'b0;
        end else begin
            if(pulse_count == 220000) begin
                present <= 1'b1;
            end else begin
                pulse_count <= pulse_count + 1;
            end
        end
    end
    hpd_last   <= hpd_synced;
    hpd_synced <= hpd_meta1;
    hpd_meta1  <= hpd_meta2;
    hpd_meta2  <= hpd;
end
endmodule