// Copyright lowRISC contributors.
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
// SPDX-License-Identifier: Apache-2.0
//
module tb;
  // dep packages
  import uvm_pkg::*;
  import dv_utils_pkg::*;
  import sysrst_ctrl_env_pkg::*;
  import sysrst_ctrl_test_pkg::*;

  // macro includes
  `include "uvm_macros.svh"
  `include "dv_macros.svh"

  wire clk, rst_n;
  wire clk_aon, rst_aon_n;

  wire devmode;
  wire [NUM_MAX_INTERRUPTS-1:0] interrupts;
  wire intr_event_detected;

  // interfaces
  clk_rst_if clk_rst_if (
    .clk  (clk),
    .rst_n(rst_n)
  );
  clk_rst_if clk_aon_rst_if (
    .clk  (clk_aon),
    .rst_n(rst_aon_n)
  );
  pins_if #(NUM_MAX_INTERRUPTS) intr_if (interrupts);
  pins_if #(1) devmode_if (devmode);
  tl_if tl_if (
    .clk  (clk),
    .rst_n(rst_n)
  );
  sysrst_ctrl_if sysrst_ctrl_if (
    .clk_i (clk_aon),
    .rst_ni(rst_aon_n)
  );

  `DV_ALERT_IF_CONNECT()

  // dut
  sysrst_ctrl dut (
    .clk_i                 (clk),
    .rst_ni                (rst_n),
    .clk_aon_i             (clk_aon),
    .rst_aon_ni            (rst_aon_n),
    .tl_i                  (tl_if.h2d),
    .tl_o                  (tl_if.d2h),
    .alert_rx_i            (alert_rx),
    .alert_tx_o            (alert_tx),
    // TODO(#14041): wkup_req_o still needs to be checked in the scoreboard.
    .wkup_req_o            (sysrst_ctrl_if.wkup_req),
    .rst_req_o             (sysrst_ctrl_if.rst_req),
    .intr_event_detected_o (intr_event_detected),
    .cio_ac_present_i      (sysrst_ctrl_if.ac_present),
    .cio_ec_rst_l_i        (sysrst_ctrl_if.ec_rst_l_in),
    .cio_flash_wp_l_i      (sysrst_ctrl_if.flash_wp_l_in),
    .cio_key0_in_i         (sysrst_ctrl_if.key0_in),
    .cio_key1_in_i         (sysrst_ctrl_if.key1_in),
    .cio_key2_in_i         (sysrst_ctrl_if.key2_in),
    .cio_pwrb_in_i         (sysrst_ctrl_if.pwrb_in),
    .cio_lid_open_i        (sysrst_ctrl_if.lid_open),
    .cio_bat_disable_o     (sysrst_ctrl_if.bat_disable),
    .cio_flash_wp_l_o      (sysrst_ctrl_if.flash_wp_l),
    .cio_ec_rst_l_o        (sysrst_ctrl_if.ec_rst_l_out),
    .cio_key0_out_o        (sysrst_ctrl_if.key0_out),
    .cio_key1_out_o        (sysrst_ctrl_if.key1_out),
    .cio_key2_out_o        (sysrst_ctrl_if.key2_out),
    .cio_pwrb_out_o        (sysrst_ctrl_if.pwrb_out),
    .cio_z3_wakeup_o       (sysrst_ctrl_if.z3_wakeup),
    // All output enables are statically set to 1.
    // This is checked with assertions inside the IP.
    .cio_bat_disable_en_o  (),
    .cio_flash_wp_l_en_o   (),
    .cio_ec_rst_l_en_o     (),
    .cio_key0_out_en_o     (),
    .cio_key1_out_en_o     (),
    .cio_key2_out_en_o     (),
    .cio_pwrb_out_en_o     (),
    .cio_z3_wakeup_en_o    ()
  );

  assign interrupts[IntrSysrstCtrl] = intr_event_detected;

  initial begin
    // drive clk and rst_n from clk_if
    clk_rst_if.set_active();
    clk_aon_rst_if.set_active();
    uvm_config_db#(virtual clk_rst_if)::set(null, "*.env", "clk_rst_vif", clk_rst_if);
    uvm_config_db#(virtual clk_rst_if)::set(null, "*.env", "clk_aon_rst_vif", clk_aon_rst_if);
    uvm_config_db#(intr_vif)::set(null, "*.env", "intr_vif", intr_if);
    uvm_config_db#(devmode_vif)::set(null, "*.env", "devmode_vif", devmode_if);
    uvm_config_db#(virtual tl_if)::set(null, "*.env.m_tl_agent*", "vif", tl_if);
    uvm_config_db#(virtual sysrst_ctrl_if)::set(null, "*.env", "vif", sysrst_ctrl_if);
    uvm_config_db#(virtual sysrst_ctrl_cov_if)::set(null, "*.env", "sysrst_ctrl_cov_if",
           dut.u_sysrst_ctrl_cov_if);
    $timeformat(-12, 0, " ps", 12);
    run_test();
  end

  `ASSERT(CheckFlashWrProtRst, !rst_aon_n -> sysrst_ctrl_if.flash_wp_l == 0, clk_aon, 0)
  `ASSERT(CheckEcPwrOnRst, !rst_aon_n -> sysrst_ctrl_if.ec_rst_l_out == 0, clk_aon, 0)

endmodule
