data/full_repos/permissive/435108851/openlane/user_proj/src/timer_wb.v
data/verilator_xmls/a9a4d0eb-4c0e-4a54-b992-74062c76c3ae.xml
module timer_wb(
`ifdef USE_POWER_PINS
  inout vccd1,
  inout vssd1,
`endif

  input wire i_clk,
  input wire i_reset,

  output wire o_timer_trigger,

  input  wire [31:0] i_wb_adr,
  input  wire [31:0] i_wb_dat,
  input  wire  [3:0] i_wb_sel,
  input  wire        i_wb_we,
  input  wire        i_wb_cyc,
  input  wire        i_wb_stb,
  output reg  [31:0] o_wb_dat,
  output reg         o_wb_ack
);


parameter DEFAULT_PRESCALER = 32'hFFFF_FFFF;


reg [31:0] prescaler = DEFAULT_PRESCALER;


reg [31:0] downcounter = DEFAULT_PRESCALER;


reg timer_trigger = 0;
assign o_timer_trigger = timer_trigger;


localparam wb_r_FLAGS__TRIGGER = 0;


wire [31:0] flags;
assign flags[wb_r_FLAGS__TRIGGER] = timer_trigger;
assign flags[31:1] = 0;



localparam
    wb_r_PRESCALER  = 1'b0,
    wb_r_FLAGS      = 1'b1,
    wb_r_MAX        = 1'b1;



localparam reg_sel_bits = $clog2(wb_r_MAX + 1);
wire [reg_sel_bits-1:0] register_index = i_wb_adr[reg_sel_bits+1:2];

always @(posedge i_clk) begin
  if (i_reset) begin
    o_wb_ack <= 0;
    prescaler <= DEFAULT_PRESCALER;
    downcounter <= DEFAULT_PRESCALER;
    timer_trigger <= 1'b0;
  end else begin

    if (downcounter > 0) begin
      downcounter <= downcounter - 1;
    end else begin
      downcounter <= prescaler;
      timer_trigger <= 1'b1;
    end


    o_wb_ack <= 1'b0;
    if (i_wb_cyc && i_wb_stb && !o_wb_ack) begin
      o_wb_ack <= 1'b1;


      case (register_index)
        wb_r_PRESCALER: o_wb_dat <= prescaler;
        wb_r_FLAGS:     o_wb_dat <= flags;
      endcase


      if (i_wb_we) begin
        case (register_index)
          wb_r_PRESCALER: begin

            prescaler <= i_wb_dat;
            downcounter <= i_wb_dat;
          end
          wb_r_FLAGS: begin

            if (i_wb_dat[wb_r_FLAGS__TRIGGER])
              timer_trigger <= 1'b0;
            end
        endcase
      end
    end
  end
end

endmodule
module timer_wb(
`ifdef USE_POWER_PINS
  inout vccd1,
  inout vssd1,
`endif

  input wire i_clk,
  input wire i_reset,

  output wire o_timer_trigger,

  input  wire [31:0] i_wb_adr,
  input  wire [31:0] i_wb_dat,
  input  wire  [3:0] i_wb_sel,
  input  wire        i_wb_we,
  input  wire        i_wb_cyc,
  input  wire        i_wb_stb,
  output reg  [31:0] o_wb_dat,
  output reg         o_wb_ack
);



parameter DEFAULT_PRESCALER = 32'hFFFF_FFFF;


reg [31:0] prescaler = DEFAULT_PRESCALER;


reg [31:0] downcounter = DEFAULT_PRESCALER;


reg timer_trigger = 0;
assign o_timer_trigger = timer_trigger;


localparam wb_r_FLAGS__TRIGGER = 0;


wire [31:0] flags;
assign flags[wb_r_FLAGS__TRIGGER] = timer_trigger;
assign flags[31:1] = 0;



localparam
    wb_r_PRESCALER  = 1'b0,
    wb_r_FLAGS      = 1'b1,
    wb_r_MAX        = 1'b1;



localparam reg_sel_bits = $clog2(wb_r_MAX + 1);
wire [reg_sel_bits-1:0] register_index = i_wb_adr[reg_sel_bits+1:2];

always @(posedge i_clk) begin
  if (i_reset) begin
    o_wb_ack <= 0;
    prescaler <= DEFAULT_PRESCALER;
    downcounter <= DEFAULT_PRESCALER;
    timer_trigger <= 1'b0;
  end else begin

    if (downcounter > 0) begin
      downcounter <= downcounter - 1;
    end else begin
      downcounter <= prescaler;
      timer_trigger <= 1'b1;
    end


    o_wb_ack <= 1'b0;
    if (i_wb_cyc && i_wb_stb && !o_wb_ack) begin
      o_wb_ack <= 1'b1;


      case (register_index)
        wb_r_PRESCALER: o_wb_dat <= prescaler;
        wb_r_FLAGS:     o_wb_dat <= flags;
      endcase


      if (i_wb_we) begin
        case (register_index)
          wb_r_PRESCALER: begin

            prescaler <= i_wb_dat;
            downcounter <= i_wb_dat;
          end
          wb_r_FLAGS: begin

            if (i_wb_dat[wb_r_FLAGS__TRIGGER])
              timer_trigger <= 1'b0;
            end
        endcase
      end
    end
  end
end

endmodule