uart验证(2)

2.apb_uvc

reg_to_apb_adapter.sv
class reg_to_apb_adapter extends uvm_reg_adapter;

    `uvm_object_utils(reg_to_apb_adapter)

    function new(string name="reg_to_apb_adapter");
        super.new(name);
    endfunction : new

    function uvm_sequence_item reg2bus(const ref uvm_reg_bus_op rw);
        apb_transfer transfer;
        `uvm_info("adapter","rw",UVM_LOW)
        transfer = apb_transfer::type_id::create("transfer");
        transfer.addr = rw.addr;
        transfer.data = rw.data;
        transfer.direction = (rw.kind == UVM_READ) ? APB_READ : APB_WRITE;
        return (transfer);
    endfunction : reg2bus

    function void bus2reg(uvm_sequence_item bus_item, ref uvm_reg_bus_op rw);
        apb_transfer transfer;
        if (!$cast(transfer, bus_item)) begin
            `uvm_fatal("NOT_REG_TYPE", 
            "Provided bus_item is not of the correct type. Expecting apb_transfer")
            return;
        end
        rw.kind = (transfer.direction == APB_READ) ? UVM_READ : UVM_WRITE;
        rw.addr = transfer.addr;
        rw.data = transfer.data;
        //rw.byte_en = 'h0;  // Set this to -1 or DO NOT SET IT AT ALL -
        rw.status = UVM_IS_OK;
    endfunction : bus2reg

endclass : reg_to_apb_adapter
apb_types.sv
// Copyright 1999-2010 Cadence Design Systems, Inc.
// All Rights Reserved Worldwide
//
// Licensed under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in
// compliance with the License.  You may obtain a copy of
// the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in
// writing, software distributed under the License is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
// CONDITIONS OF ANY KIND, either express or implied.  See
// the License for the specific language governing
// permissions and limitations under the License.
//----------------------------------------------------------------------

`ifndef APB_TYPES_SVH
`define APB_TYPES_SVH

//----------------------------------------------------------------------
// apb transfer enums, parameters, and events
typedef enum { APB_READ = 0, APB_WRITE = 1 } apb_direction_enum;

`endif  // APB_TYPES_SVH
apb_transer.sv
class apb_transfer extends uvm_sequence_item;

    rand bit [31:0]             addr;
    rand apb_direction_enum     direction;
    rand bit [31:0]             data;
    rand int unsigned           transmit_delay = 0;
    string                      master = "";
    string                      slave = "";

    constraint c_direction { direction inside { APB_READ, APB_WRITE }; }

    constraint c_transmit_delay { transmit_delay <= 10 ; }

    `uvm_object_utils_begin(apb_transfer)
        `uvm_field_int(addr, UVM_DEFAULT)
        `uvm_field_enum(apb_direction_enum, direction, UVM_DEFAULT)
        `uvm_field_int(data, UVM_DEFAULT)
        `uvm_field_string(master, UVM_DEFAULT|UVM_NOCOMPARE)
        `uvm_field_string(slave, UVM_DEFAULT|UVM_NOCOMPARE)
    `uvm_object_utils_end

    function new (string name = "apb_transfer");
        super.new(name);
    endfunction

endclass : apb_transfer
apb_pkg.sv

`ifndef APB_PKG_SV
`define APB_PKG_SV
`include "apb_if.sv"
package apb_pkg;

// Import the UVM class library and UVM automation macros
import uvm_pkg::*;
`include "uvm_macros.svh"

`include "apb_config.sv"
`include "apb_types.sv"
`include "apb_transfer.sv"
`include "apb_monitor.sv"
`include "apb_collector.sv"

`include "apb_master_driver.sv"
`include "apb_master_sequencer.sv"
`include "apb_master_agent.sv"

`include "apb_slave_driver.sv"
`include "apb_slave_sequencer.sv"
`include "apb_slave_agent.sv"

`include "apb_master_seq_lib.sv"
`include "apb_slave_seq_lib.sv"

`include "apb_env.sv"

`include "ral_uart_reg.sv"

`include "reg_to_apb_adapter.sv"

endpackage : apb_pkg
`endif // APB_PKG_SV
apb_monitor.sv
`ifndef APB_MONITOR_SV
`define APB_MONITOR_SV

//----------------------------------------------------------------------
// CLASS: apb_monitor
//----------------------------------------------------------------------
class apb_monitor extends uvm_monitor;

    // Property indicating the number of transactions occuring on the apb.
    protected int unsigned num_transactions = 0;
    // FOR UVM_ACCEL
    //protected uvm_abstraction_level_t abstraction_level = RTL;
    //protected uvma_output_pipe_proxy#(apb_transfer) m_op;

    //APB Configuration Class
    apb_config cfg;

    // The following two bits are used to control whether checks and coverage are
    // done both in the monitor class and the interface.
    bit checks_enable = 1;
    bit coverage_enable = 1;

    // TLM PORT for sending transaction OUT to scoreboard, register database, etc
    uvm_analysis_port #(apb_transfer) item_collected_port;

    // TLM Connection to the Collector - look for a write() task implementation
    uvm_analysis_imp  #(apb_transfer, apb_monitor) coll_mon_port;

    // Allows the sequencer to look at monitored data for responses
    uvm_blocking_peek_imp#(apb_transfer,apb_monitor) addr_trans_export;

    // Allows monitor to look at collector for address information
    uvm_blocking_peek_port#(apb_transfer) addr_trans_port;

    event trans_addr_grabbed;

    // The current apb_transfer
    protected apb_transfer trans_collected;

    // Provide implementations of virtual methods such as get_type_name and create
    `uvm_component_utils_begin(apb_monitor)
        `uvm_field_object(cfg, UVM_DEFAULT|UVM_REFERENCE)
        `uvm_field_int(checks_enable, UVM_DEFAULT)
        `uvm_field_int(coverage_enable, UVM_DEFAULT)
        `uvm_field_int(num_transactions, UVM_DEFAULT)
    `uvm_component_utils_end

    covergroup apb_transfer_cg;
        TRANS_ADDR : coverpoint trans_collected.addr {
            bins ZERO = {0};
            bins NON_ZERO = {[1:8'h7f]};
        }
        TRANS_DIRECTION : coverpoint trans_collected.direction {
            bins READ = {0};
            bins WRITE = {1};
        }
        TRANS_DATA : coverpoint trans_collected.data {
            bins ZERO     = {0};
            bins NON_ZERO = {[1:8'hfe]};
            bins ALL_ONES = {8'hff};
        }
        TRANS_ADDR_X_TRANS_DIRECTION: cross TRANS_ADDR, TRANS_DIRECTION;
    endgroup

    // Constructor - required syntax for UVM automation and utilities
    function new (string name, uvm_component parent);
        super.new(name, parent);
        trans_collected = new();
        // Create covergroup only if coverage is enabled
        void'(uvm_config_int::get(this, "", "coverage_enable", coverage_enable));
        if (coverage_enable) begin
            apb_transfer_cg = new();
            apb_transfer_cg.set_inst_name({get_full_name(), ".apb_transfer_cg"});
        end

        // Create TLM ports
        item_collected_port = new("item_collected_port", this);/////////connected
        coll_mon_port = new("coll_mon_port", this);
        addr_trans_export = new("addr_trans_export", this);
        addr_trans_port   = new("addr_trans_port", this);
    endfunction : new

    // Additional class methods
    extern virtual function void build_phase(uvm_phase phase);
    extern virtual task run_phase(uvm_phase phase);
    extern task peek (output apb_transfer trans); // Interface to the sequencer
    // Receives transfers from the collector
    extern virtual function void write(apb_transfer trans);
    extern protected function void perform_checks();
    extern virtual protected function void perform_coverage();
    extern virtual function void report_phase(uvm_phase phase);

endclass : apb_monitor


// UVM build_phase
function void apb_monitor::build_phase(uvm_phase phase);
    super.build_phase(phase);
    if (cfg == null)
        if (!uvm_config_db#(apb_config)::get(this, "", "cfg", cfg))
            `uvm_warning("NOCONFIG", "apb_config not set for this component")
endfunction : build_phase


// UVM run_phase
task apb_monitor::run_phase(uvm_phase phase);
    forever begin
        addr_trans_port.peek(trans_collected);
        `uvm_info(get_type_name(), $sprintf("Address Phase Complete: %h[%s]", trans_collected.addr, trans_collected.direction.name()), UVM_HIGH)
        -> trans_addr_grabbed;
    end
endtask : run_phase


// FUNCTION: peek - Allows the sequencer to peek at monitor for responses
task apb_monitor::peek(output apb_transfer trans);
    @trans_addr_grabbed;
    trans = trans_collected;
endtask


// FUNCTION: write - transaction interface to the collector
function void apb_monitor::write(apb_transfer trans);
    // Make a copy of the transaction (may not be necessary!)
    $cast(trans_collected, trans.clone());
    num_transactions++;
    `uvm_info(get_type_name(), {"Transaction Collected:\n", trans_collected.sprint()}, UVM_HIGH)
    if (checks_enable) perform_checks();
    if (coverage_enable) perform_coverage();
    // Broadcast transaction to the rest of the environment (module UVC)
    item_collected_port.write(trans_collected);/////////
endfunction : write


// FUNCTION: perform_checks()
function void apb_monitor::perform_checks();
    // Add checks here
endfunction : perform_checks


// FUNCTION : perform_coverage()
function void apb_monitor::perform_coverage();
    apb_transfer_cg.sample();
endfunction : perform_coverage


// FUNCTION: UVM report() phase
function void apb_monitor::report_phase(uvm_phase phase);
    `uvm_info(get_type_name(), $sprintf("Report: APB monitor collected %0d transfers", num_transactions), UVM_LOW);
endfunction : report_phase

`endif // APB_MONITOR_SV
apb_if.sv
//所有的断言(Assertions)代码都被包裹在块注释中
interface apb_if (input pclock, input preset);

    parameter   PADDR_WIDTH  = 32;
    parameter   PWDATA_WIDTH = 32;
    parameter   PRDATA_WIDTH = 32;

    // Actual Signals
    logic [PADDR_WIDTH-1:0]  paddr;
    logic                    prwd;
    logic [PWDATA_WIDTH-1:0] pwdata;
    logic                    penable;
    logic [15:0]             psel;
    logic [PRDATA_WIDTH-1:0] prdata;
    logic                    pslverr;
    logic                    pready;
    
    // UART Interrupt signal
    //logic        ua_int;

    // Control flags
    bit                      has_checks = 1;
    bit                      has_coverage = 1;

    // Coverage and assertions to be implemented here.
	//开始断言
    /* KAM: needs update to concurrent assertions syntax
    always @(posedge pclock)
    begin
        // PADDR must not be X or Z when PSEL is asserted
        assertPAddrUnknown:assert property (
            disable iff(!has_checks)
            (psel == 0 or !$isunknown(paddr)))
        else
            $error("ERR_APB001_PADDR_XZ\n PADDR went to X or Z \
                when PSEL is asserted");

        // PRWD must not be X or Z when PSEL is asserted
        assertPPrwdUnknown:assert property (
            disable iff(!has_checks)
            (psel == 0 or !$isunknown(prwd)))
        else
            $error("ERR_APB002_PRWD_XZ\n PRWD went to X or Z \
                when PSEL is asserted");

        // PWDATA must not be X or Z during a data transfer
        assertPWdataUnknown:assert property (
            disable iff(!has_checks)
            (psel == 0 or prwd == 0 or !$isunknown(pwdata)))
        else
            $error("ERR_APB003_PWDATA_XZ\n PWDATA went to X or Z \
                during a write transfer");

        // PENABLE must not be X or Z
        assertPEnableUnknown:assert property (
            disable iff(!has_checks)
            (!$isunknown(penable)))
        else
            $error("ERR_APB004_PENABLE_XZ\n PENABLE went to X or Z");

        // PSEL must not be X or Z
        assertPSelUnknown:assert property (
            disable iff(!has_checks)
            (!$isunknown(psel)))
        else
            $error("ERR_APB005_PSEL_XZ\n PSEL went to X or Z");

        // Pslverr must not be X or Z
        assertPslverrUnknown:assert property (
            disable iff(!has_checks)
            ((psel[0] == 1'b0 or pready == 1'b0 or !($isunknown(pslverr)))))
        else
            $error("ERR_APB101_PSLVERR_XZ\n Pslverr went to X or Z when responding");

        // Prdata must not be X or Z
        assertPrdataUnknown:assert property (
            disable iff(!has_checks)
            ((psel[0] == 1'b0 or pready == 0 or prwd == 0 or !($isunknown(prdata)))))
        else
            $error("ERR_APB102_XZ\n Prdata went to X or Z when responding to a read transfer");

    end // always @ (posedge pclock)
	//结束断言
    */

endinterface : apb_if
apb_env.sv
`ifndef APB_ENV_SV
`define APB_ENV_SV

//----------------------------------------------------------------------
// CLASS: apb_env
//----------------------------------------------------------------------

class apb_env extends uvm_env;

    // Virtual interface for this environment. This should only be done if the
    // same interface is used for all masters/slaves in the environment. Otherwise,
    // Each agent should have its interface independently set.
    protected virtual interface apb_if vif;

    uvm_analysis_port #(apb_transfer) item_collected_port;

    // Environment Configuration Parameters
    apb_config cfg;      // APB configuration object

    // The following two bits are used to control whether checks and coverage are
    // done both in the bus monitor class and the interface.
    bit checks_enable = 1;
    bit coverage_enable = 1;

    // Components of the environment
    apb_monitor bus_monitor;
    apb_collector bus_collector;
    apb_master_agent master;
    apb_slave_agent slaves[];

    // Provide implementations of virtual methods such as get_type_name and create
    `uvm_component_utils_begin(apb_env)
        `uvm_field_object(cfg, UVM_DEFAULT)
        `uvm_field_int(checks_enable, UVM_DEFAULT)
        `uvm_field_int(coverage_enable, UVM_DEFAULT)
    `uvm_component_utils_end

    // Constructor - Required UVM syntax
    function new(string name, uvm_component parent);
        super.new(name, parent);
    endfunction : new

    // Additional class methods
    extern virtual function void build_phase(uvm_phase phase);
    extern virtual function void connect_phase(uvm_phase phase);
    extern virtual function void start_of_simulation_phase(uvm_phase phase);
    extern virtual function void update_config(apb_config cfg);
    extern virtual task run_phase(uvm_phase phase);
    extern virtual task update_vif_enables();

endclass : apb_env


// UVM build_phase
function void apb_env::build_phase(uvm_phase phase);
    super.build_phase(phase);
    // Create the APB UVC configuration class if it has not been set
    if(cfg == null) begin
        if (!uvm_config_db#(apb_config)::get(this, "", "cfg", cfg)) begin
            `uvm_info("NOCONFIG", "Using default_apb_config", UVM_MEDIUM)
            //$cast(cfg, factory.create_object_by_name("default_apb_config","cfg"));
            $cast(cfg, create_object("default_apb_config","cfg")); // limuzi_tbd
        end
    end
    // set the master config
    uvm_config_object::set(this, "*", "cfg", cfg);
    // set the slave configs
    foreach(cfg.slave_configs[i]) begin
        string sname;
        sname = $sprintf("slave[%0d]*", i);
        uvm_config_object::set(this, sname, "cfg", cfg.slave_configs[i]);
    end

    bus_monitor = apb_monitor::type_id::create("bus_monitor",this);
    bus_collector = apb_collector::type_id::create("bus_collector",this);
    master = apb_master_agent::type_id::create(cfg.master_config.name,this);
    slaves = new[cfg.slave_configs.size()];
    for(int i = 0; i < cfg.slave_configs.size(); i++) begin
        slaves[i] = apb_slave_agent::type_id::create($sprintf("slave[%0d]", i), this);
    end
endfunction : build_phase


// UVM connect_phase
function void apb_env::connect_phase(uvm_phase phase);
    super.connect_phase(phase);
    // Get the virtual interface if set via get_config
    if (!uvm_config_db#(virtual apb_if)::get(this, "", "vif", vif))
        `uvm_error("NOVIF",{"virtual interface must be set for: ",get_full_name(),".vif"})
    bus_collector.item_collected_port.connect(bus_monitor.coll_mon_port);
    bus_monitor.addr_trans_port.connect(bus_collector.addr_trans_export);

    master.monitor = bus_monitor;
    master.collector = bus_collector;

    foreach(slaves[i]) begin
        slaves[i].monitor = bus_monitor;
        slaves[i].collector = bus_collector;
        if (slaves[i].is_active == UVM_ACTIVE)
            slaves[i].sequencer.addr_trans_port.connect(bus_monitor.addr_trans_export);
    end
endfunction : connect_phase


// UVM start_of_simulation_phase
function void apb_env::start_of_simulation_phase(uvm_phase phase);
    set_report_id_action_hier("CFGOVR", UVM_DISPLAY);
    set_report_id_action_hier("CFGSET", UVM_DISPLAY);
    check_config_usage();
endfunction : start_of_simulation_phase


// update_config() method
function void apb_env::update_config(apb_config cfg);
    bus_monitor.cfg = cfg;
    bus_collector.cfg = cfg;
    master.update_config(cfg);
    foreach(slaves[i])
        slaves[i].update_config(cfg.slave_configs[i]);
endfunction : update_config


// update_vif_enables
task apb_env::update_vif_enables();
    vif.has_checks <= checks_enable;
    vif.has_coverage <= coverage_enable;
    forever begin
        @(checks_enable || coverage_enable);
        vif.has_checks <= checks_enable;
        vif.has_coverage <= coverage_enable;
    end
endtask : update_vif_enables


//UVM run_phase()
task apb_env::run_phase(uvm_phase phase);
    fork
        update_vif_enables();
    join
endtask : run_phase

`endif // APB_ENV_SV
apb_config.sv
`ifndef APB_CONFIG_SV
`define APB_CONFIG_SV

// APB Slave Configuration Information
class apb_slave_config extends uvm_object;
    string name;
    rand uvm_active_passive_enum is_active = UVM_ACTIVE;
    rand int start_address;
    rand int end_address;
    rand int psel_index;

    constraint addr_cst { start_address <= end_address; }
    constraint psel_cst { psel_index inside {[0:15]}; }

    `uvm_object_utils_begin(apb_slave_config)
        `uvm_field_string(name, UVM_DEFAULT)
        `uvm_field_enum(uvm_active_passive_enum, is_active, UVM_DEFAULT)
        `uvm_field_int(start_address, UVM_DEFAULT)
        `uvm_field_int(end_address, UVM_DEFAULT)
        `uvm_field_int(psel_index, UVM_DEFAULT)
    `uvm_object_utils_end

    // Constructor - UVM required syntax
    function new (string name = "apb_slave_config");
        super.new(name);
    endfunction

    // Checks to see if an address is in the configured range
    function bit check_address_range(int unsigned addr);
        return (!((start_address > addr) || (end_address < addr)));
    endfunction

endclass : apb_slave_config

// APB Master Configuration Information
class apb_master_config extends uvm_object;

    string name;
    uvm_active_passive_enum is_active = UVM_ACTIVE;

    function new (string name = "unnamed-apb_master_config");
        super.new(name);
    endfunction

    `uvm_object_utils_begin(apb_master_config)
        `uvm_field_string(name, UVM_DEFAULT)
        `uvm_field_enum(uvm_active_passive_enum, is_active, UVM_DEFAULT)
    `uvm_object_utils_end

endclass : apb_master_config

// APB Configuration Information
class apb_config extends uvm_object;

    // APB has one master and N slaves
    apb_master_config master_config;
    apb_slave_config slave_configs[$];
    int num_slaves;

    `uvm_object_utils_begin(apb_config)
        `uvm_field_queue_object(slave_configs, UVM_DEFAULT)
        `uvm_field_object(master_config, UVM_DEFAULT)
    `uvm_object_utils_end

    function new (string name = "unnamed-apb_config");
        super.new(name);
    endfunction

    // Additional class methods
    extern function void add_slave(string name, int start_addr, int end_addr,
                                   int psel_indx, uvm_active_passive_enum is_active = UVM_ACTIVE);
    extern function void add_master(string name,
                                    uvm_active_passive_enum is_active = UVM_ACTIVE);
    extern function int get_slave_psel_by_addr(int addr);
    extern function string get_slave_name_by_addr(int addr);
endclass : apb_config


// apb_config - Creates and configures a slave agent config and adds to a queue
function void apb_config::add_slave(string name, int start_addr, int end_addr,
                                    int psel_indx, uvm_active_passive_enum is_active = UVM_ACTIVE);
    apb_slave_config tmp_slave_cfg;
    num_slaves++;
    tmp_slave_cfg = apb_slave_config::type_id::create("slave_config");
    tmp_slave_cfg.name = name;
    tmp_slave_cfg.start_address = start_addr;
    tmp_slave_cfg.end_address = end_addr;
    tmp_slave_cfg.psel_index = psel_indx;
    tmp_slave_cfg.is_active = is_active;

    slave_configs.push_back(tmp_slave_cfg);
endfunction : add_slave


// apb_config - Creates and configures a master agent configuration
function void apb_config::add_master(string name, uvm_active_passive_enum is_active = UVM_ACTIVE);
    master_config = apb_master_config::type_id::create("master_config");
    master_config.name = name;
    master_config.is_active = is_active;
endfunction : add_master


// apb_config - Returns the slave psel index
function int apb_config::get_slave_psel_by_addr(int addr);
    for (int i = 0; i < slave_configs.size(); i++)
        if(slave_configs[i].check_address_range(addr)) begin
            return slave_configs[i].psel_index;
        end
endfunction : get_slave_psel_by_addr


// apb_config - Return the name of the slave
function string apb_config::get_slave_name_by_addr(int addr);
    for (int i = 0; i < slave_configs.size(); i++)
        if(slave_configs[i].check_address_range(addr)) begin
            return slave_configs[i].name;
        end
endfunction : get_slave_name_by_addr


//====================================================================
// Default APB configuration - One Master, Two slaves
//====================================================================
class default_apb_config extends apb_config;

    `uvm_object_utils(default_apb_config)

    function new(string name = "default_apb_config-S0S1-master");
        super.new(name);
        add_slave("slave0", 32'h0000_0000, 32'h7FFF_FFFF, 0, UVM_ACTIVE);
        add_slave("slave1", 32'h8000_0000, 32'hFFFF_FFFF, 1, UVM_ACTIVE);
        add_master("master", UVM_ACTIVE);
    endfunction

endclass : default_apb_config

`endif // APB_CONFIG_SV
apb_collector.sv
`ifndef APB_COLLECTOR_SV
`define APB_COLLECTOR_SV

//----------------------------------------------------------------------
// CLASS: apb_collector
//----------------------------------------------------------------------
class apb_collector extends uvm_component;

    // The virtual interface used to view HDL signals.
    virtual apb_if vif;

    // APB configuration information
    apb_config cfg;

    // Property indicating the number of transactions occuring on the apb.
    protected int unsigned num_transactions = 0;

    // The following two bits are used to control whether checks and coverage are
    // done both in the collector class and the interface.
    bit checks_enable = 1;
    bit coverage_enable = 1;

    // TLM Ports - transfer collected for monitor other components
    uvm_analysis_port #(apb_transfer) item_collected_port;

    // TLM Port - Allows sequencer access to transfer during address phase
    uvm_blocking_peek_imp#(apb_transfer,apb_collector) addr_trans_export;
    event addr_trans_grabbed;

    // The following property holds the transaction information currently
    // being captured (by the collect_address_phase and data_phase methods).
    apb_transfer trans_collected;

    //Adding pseudo-memory leakage for heap analysis lab
    `ifdef HEAP
    static apb_transfer runq[$];
    `endif

    // Provide implementations of virtual methods such as get_type_name and create
    `uvm_component_utils_begin(apb_collector)
        `uvm_field_object(cfg, UVM_DEFAULT|UVM_REFERENCE)
        `uvm_field_int(checks_enable, UVM_DEFAULT)
        `uvm_field_int(coverage_enable, UVM_DEFAULT)
        `uvm_field_int(num_transactions, UVM_DEFAULT)
    `uvm_component_utils_end

    // new - constructor
    function new (string name, uvm_component parent);
        super.new(name, parent);
        trans_collected = apb_transfer::type_id::create("trans_collected");
        // TLM ports are created here
        item_collected_port = new("item_collected_port", this);
        addr_trans_export = new("addr_trans_export", this);
    endfunction : new

    // Additional class methods
    extern virtual function void build_phase(uvm_phase phase);
    extern virtual function void connect_phase(uvm_phase phase);
    extern task run_phase(uvm_phase phase);
    extern virtual protected task collect_transactions();
    extern task peek(output apb_transfer trans);
    extern virtual function void report_phase(uvm_phase phase);

endclass : apb_collector


// UVM build_phase
function void apb_collector::build_phase(uvm_phase phase);
    super.build_phase(phase);
    if (cfg == null)
        if (!uvm_config_db#(apb_config)::get(this, "", "cfg", cfg))
            `uvm_error("NOCONFIG", "apb_config not set for this component")
endfunction : build_phase


// UVM connect_phase
function void apb_collector::connect_phase(uvm_phase phase);
    super.connect_phase(phase);
    if (!uvm_config_db#(virtual apb_if)::get(this, "", "vif", vif))
        `uvm_error("NOVIF", {"virtual interface must be set for: ", get_full_name(), ".vif"})
endfunction : connect_phase


// UVM run_phase()
task apb_collector::run_phase(uvm_phase phase);
    @(posedge vif.preset);
    `uvm_info(get_type_name(), "Detected Reset Done", UVM_LOW)
    collect_transactions();
endtask : run_phase


// collect_transactions
task apb_collector::collect_transactions();
    forever begin
        @(posedge vif.pclock iff (vif.psel != 0));
        void'(this.begin_tr(trans_collected,"apb_collector","UVM Debug","APB collector transaction inside collect_transactions()"));
        trans_collected.addr = vif.paddr;
        trans_collected.master = cfg.master_config.name;
        trans_collected.slave = cfg.get_slave_name_by_addr(trans_collected.addr);
        case (vif.prwd)
            1'b0 : trans_collected.direction = APB_READ;
            1'b1 : trans_collected.direction = APB_WRITE;
        endcase
        @(posedge vif.pclock);
        if(trans_collected.direction == APB_READ)
            trans_collected.data = vif.prdata;
        if (trans_collected.direction == APB_WRITE)
            trans_collected.data = vif.pwdata;
        -> addr_trans_grabbed;
        @(posedge vif.pclock);
        if(trans_collected.direction == APB_READ) begin
            if(vif.pready != 1'b1)
                @(posedge vif.pclock);
            trans_collected.data = vif.prdata;
        end
        this.end_tr(trans_collected);
        item_collected_port.write(trans_collected);
        `uvm_info(get_type_name(), $sprintf("Transfer collected :\n%s",
                  trans_collected.sprint()), UVM_MEDIUM)
        `ifdef HEAP
        runq.push_back(trans_collected);
        `endif
        num_transactions++;
    end
endtask : collect_transactions


task apb_collector::peek(output apb_transfer trans);
    @addr_trans_grabbed;
    trans = trans_collected;
endtask : peek


function void apb_collector::report_phase(uvm_phase phase);
    `uvm_info(get_type_name(), $sprintf("Report: APB collector collected %0d transfers", num_transactions), UVM_LOW);
endfunction : report_phase

`endif // APB_COLLECTOR_SV
apb_checker.sv
`ifdef ABV_OFF
// compiler directive, Use +define+ABV_OFF or -define ABV_OFF.
`else // Checking on by default

    //--------------------------------
    // Initialize simulation
    //--------------------------------
    initial
    begin
        // Format for time reporting
        //$timeformat(-9, 2, " ns", 10);
        $display("CHECKER_APB_INFO: Running checker_apb (SVA implementation)");
    end

    //-----------------------------------------------
    // Internal signals for data integrity checks
    //-----------------------------------------------
    logic [PADDR_WIDTH-1:0]  paddr_sv;
    logic                    pwrite_s;
    logic [PWDATA_WIDTH-1:0] pwdata_sv;
    logic [PRDATA_WIDTH-1:0] prdata_sv;

    assign paddr_sv  = paddr;
    assign pwrite_s  = prwd; //pwrite
    assign pwdata_sv = pwdata;
    assign prdata_sv = prdata;

    //-----------------------------------------------
    // Internal signals for APB operational activity
    //-----------------------------------------------
    `define IDLE   (!psel & !penable)
    `define SETUP  ( psel & !penable)
    `define ENABLE ( psel &  penable)

    //<<<<<<<<<<<<<<<<<<<<<<<<<<
    // PROTOCOL_CHECKS_BEGIN
    //<<<<<<<<<<<<<<<<<<<<<<<<<<

    // Rule : IDLE - the default state for the peripheral bus.
    property p_001_master_idle_on_reset;
        @(posedge pclock)
            not (!preset && !(`IDLE));
    endproperty

    assert_001_master_idle_on_reset : assert property (p_001_master_idle_on_reset);

    // Rule : State diagram does not allow PENABLE=1 with PSELx=0 //only valid in single psel systems !
    property p_002_master_never_penable_without_psel;
        @(posedge pclock)
            not (!psel && penable);
    endproperty

    //only valid in single psel systems
    assert_002_master_never_penable_without_psel : assert property (p_002_master_never_penable_without_psel);

    // Rule : IDLE - When a transfer is required the bus moves into the SETUP state, where the appropriate PSELx is asserted.
    property p_003_master_state_idle_then_idle_or_setup;
        @(posedge pclock) disable iff (!preset)
            (!psel |=> !penable);
    endproperty

    assert_003_master_state_idle_then_idle_or_setup : assert property (p_003_master_state_idle_then_idle_or_setup);

    // Rule : SETUP - The bus only remains in the SETUP state for one clock cycle and will always move to the ENABLE state on the next rising edge of the clock.
    property p_004_master_state_setup_then_access_on_next_cycle;
        @(posedge pclock) disable iff (!preset)
            ((`SETUP) |=> (`ENABLE));
    endproperty

    assert_004_master_state_setup_then_access_on_next_cycle : assert property (p_004_master_state_setup_then_access_on_next_cycle);

    // Rule : The address, write and select signals all remain stable during the transition from the SETUP to ENABLE state."
    // NOTE : psel stablity is already covered by master_state_setup_then_access_on_next_cycle
    property p_006_master_state_paddr_stable_between_setup_and_access;
        @(posedge pclock) disable iff (!preset)
            ((`SETUP) |=> $stable(paddr));
    endproperty

    assert_006_master_state_paddr_stable_between_setup_and_access : assert property (p_006_master_state_paddr_stable_between_setup_and_access);

    property p_007_master_state_pwrite_stable_between_setup_and_access;
        @(posedge pclock) disable iff (!preset)
            ((`SETUP) |=> $stable(prwd));
    endproperty

    assert_007_master_state_pwrite_stable_between_setup_and_access : assert property (p_007_master_state_pwrite_stable_between_setup_and_access);

    // Rule : The write transfer starts with the address, write data and write signals,
    //        The address, data and control signals all remaing valid throughout the ENABLE cycle. The transfer completes at the end of this cycle.
    property p_008_master_pwdata_stable_throughout_access;
        @(posedge pclock) disable iff (!preset)
            (((`SETUP) && prwd) || ((`ENABLE) && prwd && !pready) |=> $stable(pwdata));
    endproperty

    assert_008_master_pwdata_stable_throughout_access : assert property (p_008_master_pwdata_stable_throughout_access);

    // Validity of APB signals during transfers : Another way to check X on the bus

    // Rule : Write transfer - The write transfer starts with the
    //        address, write data and write signals all changing after the
    //        rising edge of the clock. The address, data and write
    //        signals remain valid throughout the ENABLE cycle. The
    //        transfer completes at the end of this cycle."
    property p_009_master_paddr_valid_throughout_access_cycle;
        @(posedge pclock) disable iff (!preset)
            (psel |-> (!(paddr ^ paddr_sv)));
    endproperty

    assert_009_master_paddr_valid_throughout_access_cycle : assert property (p_009_master_paddr_valid_throughout_access_cycle);

    property p_010_master_pwrite_valid_throughout_access_cycle;
        @(posedge pclock) disable iff (!preset)
            (psel |-> (!(prwd ^ pwrite_s)));
    endproperty

    assert_010_master_pwrite_valid_throughout_access_cycle : assert property (p_010_master_pwrite_valid_throughout_access_cycle);

    property p_011_master_pwdata_valid_throughout_access_cycle;
        @(posedge pclock) disable iff (!preset)
            ((psel & prwd) |-> (!(pwdata ^ pwdata_sv)));
    endproperty

    assert_011_master_pwdata_valid_throughout_access_cycle : assert property (p_011_master_pwdata_valid_throughout_access_cycle);

    // Rule : Read transfer -
    //        "In the case of a read, the slave must provide the data during the
    //        ENABLE cycle. The data is sampled on the rising edge of the clock
    //        at the end of the ENABLE cycle."

    property p_012_slave_prdata_valid_on_access_cycle; // Valid for APB Version-2.0
        @(posedge pclock) disable iff (!preset)
            ((psel & !prwd & penable) |-> (!(prdata ^ prdata_sv)));
    endproperty

    assert_012_slave_prdata_valid_on_access_cycle : assert property (p_012_slave_prdata_valid_on_access_cycle);


    //>>>>>>>>>>>>>>>>>>>>>>>>>>>
    // PROTOCOL_CHECKS_END
    //>>>>>>>>>>>>>>>>>>>>>>>>>>>


    //<<<<<<<<<<<<<<<<<<<<<<<<<<
    // COVERAGE_CHECKS_BEGIN
    //<<<<<<<<<<<<<<<<<<<<<<<<<<

    `ifdef COVERAGE_OFF // compiler directive, Use +define+COVERAGE_OFF or -define COVERAGE_OFF.
    `else // Checking on by default
        cover_101_wr_transfer_with_no_wait : cover property (@(posedge pclock) disable iff (!preset) (`IDLE) ##1 ((`SETUP) & prwd) ##1 (`ENABLE));
        cover_102_wr_transfer_with_wait    : cover property (@(posedge pclock) disable iff (!preset) (`IDLE) ##1 ((`SETUP) & prwd) ##[1:$] (`ENABLE));
        cover_103_rd_transfer_with_no_wait : cover property (@(posedge pclock) disable iff (!preset) (`IDLE) ##1 ((`SETUP) & !prwd) ##1 (`ENABLE));
        cover_104_rd_transfer_with_wait    : cover property (@(posedge pclock) disable iff (!preset) (`IDLE) ##1 ((`SETUP) & !prwd) ##[1:$] (`ENABLE));
        cover_105_consecutive_transfer     : cover property (@(posedge pclock) disable iff (!preset) (`ENABLE) ##1 (`SETUP) ##1 (`ENABLE));
        cover_106_end_transfer             : cover property (@(posedge pclock) disable iff (!preset) (`ENABLE) ##1 (`IDLE));
    `endif // COVERAGE_OFF

    //>>>>>>>>>>>>>>>>>>>>>>>>>>>
    // COVERAGE_CHECKS_END
    //>>>>>>>>>>>>>>>>>>>>>>>>>>>


    //<<<<<<<<<<<<<<<<<<<<<<<<<<
    // SANITY_CHECKS_BEGIN
    //<<<<<<<<<<<<<<<<<<<<<<<<<<

    `ifdef SANITY_OFF // compiler directive, Use +define+SANITY_OFF or -define SANITY_OFF .
    `else // Checking on by default
        cover_201_psel_goes_high    : cover property (@(posedge pclock) disable iff (!preset) (!psel ##1 psel));
        cover_202_psel_goes_low     : cover property (@(posedge pclock) disable iff (!preset) (psel ##1 !psel));
        cover_203_penable_goes_high : cover property (@(posedge pclock) disable iff (!preset) (!penable ##1 penable));
        cover_204_penable_goes_low  : cover property (@(posedge pclock) disable iff (!preset) (penable ##1 !penable));
        cover_205_pwrite_goes_high  : cover property (@(posedge pclock) disable iff (!preset) (!prwd ##1 prwd));
        cover_206_pwrite_goes_low   : cover property (@(posedge pclock) disable iff (!preset) (prwd ##1 !prwd));
    `endif // SANITY_OFF

    //>>>>>>>>>>>>>>>>>>>>>>>>>>>
    // SANITY_CHECKS_END
    //>>>>>>>>>>>>>>>>>>>>>>>>>>>

`endif // ABV_OFF
apb_master_if.sv
interface apb_master_if (input pclock,
                         input preset);

    parameter   PADDR_WIDTH  = 32;
    parameter   PWDATA_WIDTH = 32;
    parameter   PRDATA_WIDTH = 32;

    // Actual Signals
    logic [PADDR_WIDTH-1:0]  paddr;
    logic                    prwd;
    logic [PWDATA_WIDTH-1:0] pwdata;
    logic                    penable;
    logic                    pready;
    logic [15:0]             psel;
    logic [PRDATA_WIDTH-1:0] prdata;
    wire logic               pslverr;

    // UART Interrupt signal
    logic        ua_int;

    logic [31:0] gp_int;

    // Control flags
    bit                      has_checks = 1;
    bit                      has_coverage = 1;

    // Coverage and assertions to be implemented here.

    /* NEEDS TO BE UPDATED TO CONCURRENT ASSERTIONS
    always @(posedge pclock)
    begin
        // PADDR must not be X or Z when PSEL is asserted
        assertPAddrUnknown:assert property (
            disable iff(!has_checks || !preset)
            (psel == 0 or !$isunknown(paddr)))
        else
            $error("ERR_APB001_PADDR_XZ\n PADDR went to X or Z \
                when PSEL is asserted");

        // PRWD must not be X or Z when PSEL is asserted
        assertPPrwdUnknown:assert property (
            disable iff(!has_checks || !preset)
            (psel == 0 or !$isunknown(prwd)))
        else
            $error("ERR_APB002_PRWD_XZ\n PRWD went to X or Z \
                when PSEL is asserted");

        // PWDATA must not be X or Z during a data transfer
        assertPWdataUnknown:assert property (
            disable iff(!has_checks || !preset)
            (psel == 0 or prwd == 0 or !$isunknown(pwdata)))
        else
            $error("ERR_APB003_PWDATA_XZ\n PWDATA went to X or Z \
                during a write transfer");

        // PENABLE must not be X or Z
        assertPEnableUnknown:assert property (
            disable iff(!has_checks || !preset)
            (!$isunknown(penable)))
        else
            $error("ERR_APB004_PENABLE_XZ\n PENABLE went to X or Z");

        // PSEL must not be X or Z
        assertPSelUnknown:assert property (
            disable iff(!has_checks || !preset)
            (!$isunknown(psel)))
        else
            $error("ERR_APB005_PSEL_XZ\n PSEL went to X or Z");

    end // always @ (posedge pclock)
    */

endinterface : apb_master_if
apb_master_agent.sv
`ifndef APB_MASTER_AGENT_SV
`define APB_MASTER_AGENT_SV

//----------------------------------------------------------------------
// CLASS: apb_master_agent
//----------------------------------------------------------------------
class apb_master_agent extends uvm_agent;

    // This field determines whether an agent is active or passive.
    //uvm_active_passive_enum is_active = UVM_ACTIVE;

    // Configuration information: (master_config: name, is_active)
    apb_config cfg;

    apb_monitor          monitor;
    apb_collector        collector;
    apb_master_sequencer sequencer;
    apb_master_driver    driver;

    // Provide implementations of virtual methods such as get_type_name and create
    `uvm_component_utils_begin(apb_master_agent)
        `uvm_field_object(monitor, UVM_DEFAULT | UVM_REFERENCE)
        `uvm_field_object(collector, UVM_DEFAULT | UVM_REFERENCE)
        `uvm_field_enum(uvm_active_passive_enum, is_active, UVM_DEFAULT)
        `uvm_field_object(cfg, UVM_DEFAULT | UVM_REFERENCE)
    `uvm_component_utils_end

    // new - constructor
    function new (string name, uvm_component parent);
        super.new(name, parent);
    endfunction : new

    // Additional class methods
    extern virtual function void build_phase(uvm_phase phase);
    extern virtual function void connect_phase(uvm_phase phase);
    extern virtual function void update_config(input apb_config cfg);

endclass : apb_master_agent


// UVM build_phase
function void apb_master_agent::build_phase(uvm_phase phase);
    uvm_object config_obj;
    super.build_phase(phase);
    if (cfg == null) begin
        if (!uvm_config_db#(apb_config)::get(this, "", "cfg", cfg))
            `uvm_warning("NOCONFIG",
                "Config not set for master agent, using default is_active field")
    end
    else is_active = cfg.master_config.is_active;

    if(is_active == UVM_ACTIVE) begin
        sequencer = apb_master_sequencer::type_id::create("sequencer",this);
        driver = apb_master_driver::type_id::create("driver",this);
    end
endfunction : build_phase


// UVM connect_phase
function void apb_master_agent::connect_phase(uvm_phase phase);
    super.connect_phase(phase);
    if (is_active == UVM_ACTIVE) begin
        // Connect the driver to the sequencer using TLM interface
        driver.seq_item_port.connect(sequencer.seq_item_export);
    end
endfunction : connect_phase


// update_config()
function void apb_master_agent::update_config(input apb_config cfg);
    if (is_active == UVM_ACTIVE) begin
        sequencer.cfg = cfg;
        driver.cfg = cfg;
    end
endfunction : update_config

`endif // APB_MASTER_AGENT_SV
apb_master_driver.sv
`ifndef APB_MASTER_DRIVER_SV
`define APB_MASTER_DRIVER_SV

//----------------------------------------------------------------------
// CLASS: apb_master_driver declaration
//----------------------------------------------------------------------
class apb_master_driver extends uvm_driver #(apb_transfer);

    // The virtual interface used to drive and view HDL signals.
    virtual apb_if vif;

    // A pointer to the configuration unit of the agent
    apb_config cfg;

    // Provide implementations of virtual methods such as get_type_name and create
    `uvm_component_utils_begin(apb_master_driver)
        `uvm_field_object(cfg, UVM_DEFAULT|UVM_REFERENCE)
    `uvm_component_utils_end

    // Constructor which calls super.new() with appropriate parameters.
    function new (string name, uvm_component parent);
        super.new(name, parent);
    endfunction : new

    // Additional class methods
    extern virtual function void build_phase(uvm_phase phase);
    extern virtual function void connect_phase(uvm_phase phase);
    extern virtual task run_phase(uvm_phase phase);
    extern virtual protected task get_and_drive();
    extern virtual protected task reset();
    extern virtual protected task drive_transfer (apb_transfer trans);
    extern virtual protected task drive_address_phase (apb_transfer trans);
    extern virtual protected task drive_data_phase (apb_transfer trans);

endclass : apb_master_driver


// UVM build_phase
function void apb_master_driver::build_phase(uvm_phase phase);
    super.build_phase(phase);
    if (cfg == null)
        if (!uvm_config_db#(apb_config)::get(this, "", "cfg", cfg))
            `uvm_error("NOCONFIG", "apb_config not set for this component")
endfunction : build_phase


// UVM connect_phase - gets the vif as a config property
function void apb_master_driver::connect_phase(uvm_phase phase);
    super.connect_phase(phase);
    if (!uvm_config_db#(virtual apb_if)::get(this, "", "vif", vif))
        `uvm_error("NOVIF",{"virtual interface must be set for: ",get_full_name(),".vif"})
endfunction : connect_phase


// Declaration of the UVM run_phase method.
task apb_master_driver::run_phase(uvm_phase phase);
    get_and_drive();
endtask : run_phase


// This task manages the interaction between the sequencer and driver
task apb_master_driver::get_and_drive();
    while (1) begin
        reset();
        fork
            @(negedge vif.preset)
            // APB_MASTER_DRIVER tag required for Debug Labs
            `uvm_info("APB_MASTER_DRIVER", "get_and_drive: Reset dropped", UVM_MEDIUM)
            
            begin
                // This thread will be killed at reset
                forever begin
                    @(posedge vif.pclock iff (vif.preset))
                    seq_item_port.get_next_item(req);
                    drive_transfer(req);
                    seq_item_port.item_done(req);
                end
            end
        join_any
        disable fork;
        //If we are in the middle of a transfer, need to end the tx. Also,
        //do any reset cleanup here. The only way we got to this point is via
        //a reset.
        if(req.is_active()) this.end_tr(req);
    end
endtask : get_and_drive


// Drive all signals to reset state
task apb_master_driver::reset();
    // If the reset is not active, then wait for it to become active before
    // resetting the interface.
    wait(!vif.preset);
    // APB_MASTER_DRIVER tag required for Debug Labs
    `uvm_info("APB_MASTER_DRIVER", $sprintf("Reset observed"), UVM_MEDIUM)
    vif.paddr    <= 'h0;
    vif.pwdata   <= 'h0;
    vif.prwd     <= 'b0;
    vif.psel     <= 'b0;
    vif.penable  <= 'b0;
endtask : reset


// Drives a transfer when an item is ready to be sent.
task apb_master_driver::drive_transfer (apb_transfer trans);
    void'(this.begin_tr(trans, "apb master driver", "UVM Debug", 
                        "APB master driver transaction from get_and_drive"));
    
    if (trans.transmit_delay > 0) begin
        repeat(trans.transmit_delay) @(posedge vif.pclock);
    end
    drive_address_phase(trans);
    drive_data_phase(trans);
    // APB_MASTER_DRIVER_TR tag required for Debug Labs
    `uvm_info("APB_MASTER_DRIVER_TR", $sprintf("APB Finished Driving Transfer\n%s",
                trans.sprint()), UVM_HIGH)
    this.end_tr(trans);
endtask : drive_transfer


// Drive the address phase of the transfer
task apb_master_driver::drive_address_phase (apb_transfer trans);
    int slave_index;
    slave_index = cfg.get_slave_psel_by_addr(trans.addr);
    vif.paddr    <= trans.addr;
    vif.psel     <= (1<<slave_index);
    vif.penable  <= 0;
    if (trans.direction == APB_READ) begin
        vif.prwd   <= 1'b0;
    end
    else begin
        vif.prwd   <= 1'b1;
        vif.pwdata <= trans.data;
    end
    @(posedge vif.pclock);
endtask : drive_address_phase


// Drive the data phase of the transfer
task apb_master_driver::drive_data_phase (apb_transfer trans);
    vif.penable <= 1;
    @(posedge vif.pclock iff vif.pready);
    if (trans.direction == APB_READ) begin
        trans.data = vif.prdata;
    end
    vif.penable <= 0;
    vif.psel    <= 0;
endtask : drive_data_phase

`endif // APB_MASTER_DRIVER_SV
apb_master_sequencer.sv
`ifndef APB_MASTER_SEQUENCER_SV
`define APB_MASTER_SEQUENCER_SV

//----------------------------------------------------------------------
// CLASS: apb_master_sequencer declaration
//----------------------------------------------------------------------
class apb_master_sequencer extends uvm_sequencer #(apb_transfer);

    // Config in case it is needed by the sequencer
    apb_config cfg;

    bit tful;    //KATHLEEN_REMOVE THIS LATER
    // Provide implementations of virtual methods such as get_type_name and create
    `uvm_component_utils_begin(apb_master_sequencer)
        `uvm_field_object(cfg, UVM_DEFAULT|UVM_REFERENCE)
    `uvm_component_utils_end

    // Constructor
    function new (string name, uvm_component parent);
        super.new(name, parent);
    endfunction : new

    // UVM build_phase
    virtual function void build_phase(uvm_phase phase);
        super.build_phase(phase);
        if (cfg == null)
            if (!uvm_config_db#(apb_config)::get(this, "", "cfg", cfg))
                `uvm_warning("NOCONFIG", "apb_config not set for this component")
    endfunction : build_phase

endclass : apb_master_sequencer

`endif // APB_MASTER_SEQUENCER_SV
apb_master_seq_lib.sv
`ifndef APB_MASTER_SEQ_LIB_SV
`define APB_MASTER_SEQ_LIB_SV

//----------------------------------------------------------------------
// SEQUENCE: read_byte_seq
//----------------------------------------------------------------------
class apb_master_base_seq extends uvm_sequence #(apb_transfer);
    // NOTE: KATHLEEN - ALSO NEED TO HANDLE KILL HERE??

    function new(string name="apb_master_base_seq");
        super.new(name);
    endfunction

    `uvm_object_utils(apb_master_base_seq)
    `uvm_declare_p_sequencer(apb_master_sequencer)

    // Use a base sequence to raise/drop objections if this is a default sequence
    virtual task pre_body();
        if (starting_phase != null)
            starting_phase.raise_objection(this, {"Running sequence '",
                                           get_full_name(), "'"});
    endtask

    virtual task post_body();
        if (starting_phase != null)
            starting_phase.drop_objection(this, {"Completed sequence '",
                                           get_full_name(), "'"});
    endtask
endclass : apb_master_base_seq


//----------------------------------------------------------------------
// SEQUENCE: read_byte_seq
//----------------------------------------------------------------------
class read_byte_seq extends apb_master_base_seq;
    rand bit [31:0] start_addr;
    rand int unsigned transmit_del;

    function new(string name="read_byte_seq");
        super.new(name);
    endfunction

    `uvm_object_utils(read_byte_seq)

    constraint transmit_del_ct { (transmit_del <= 10); }

    virtual task body();
        `uvm_info(get_type_name(), "Starting...", UVM_HIGH)
        `uvm_do_with(req,
            { req.addr == start_addr;
              req.direction == APB_READ;
              req.transmit_delay == transmit_del; } )
        get_response(rsp);
        `uvm_info(get_type_name(), $sprintf("req_addr = 'h%0h, req_data = 'h%0h",
                  req.addr, req.data), UVM_HIGH)
        `uvm_info(get_type_name(), $sprintf("rsp_addr = 'h%0h, rsp_data = 'h%0h",
                  rsp.addr, rsp.data), UVM_HIGH)
    endtask
endclass : read_byte_seq


// SEQUENCE: write_byte_seq
class write_byte_seq extends apb_master_base_seq;
    rand bit [31:0] start_addr;
    rand bit [7:0] write_data;
    rand int unsigned transmit_del;

    function new(string name="write_byte_seq");
        super.new(name);
    endfunction

    `uvm_object_utils(write_byte_seq)

    constraint transmit_del_ct { (transmit_del <= 10); }

    virtual task body();
        `uvm_info(get_type_name(), "Starting...", UVM_HIGH)
        `uvm_do_with(req,
            { req.addr == start_addr;
              req.direction == APB_WRITE;
              req.data == write_data;
              req.transmit_delay == transmit_del; } )
        `uvm_info(get_type_name(), $sprintf("addr = 'h%0h, data = 'h%0h",
                  req.addr, req.data), UVM_HIGH)
    endtask
endclass : write_byte_seq


//----------------------------------------------------------------------
// SEQUENCE: read_word_seq
//----------------------------------------------------------------------
class read_word_seq extends apb_master_base_seq;
    rand bit [31:0] start_addr;
    rand int unsigned transmit_del;

    function new(string name="read_word_seq");
        super.new(name);
    endfunction

    `uvm_object_utils(read_word_seq)

    constraint transmit_del_ct { (transmit_del <= 10); }
    constraint addr_ct {(start_addr[1:0] == 0); }

    virtual task body();
        `uvm_info(get_type_name(), "Starting...", UVM_HIGH)
        `uvm_do_with(req,
            { req.addr == start_addr;
              req.direction == APB_READ;
              req.transmit_delay == transmit_del; } )
        get_response(rsp);
        `uvm_info(get_type_name(), $sprintf("req_addr = 'h%0h, req_data = 'h%0h",
                  req.addr, req.data), UVM_HIGH)
        `uvm_info(get_type_name(), $sprintf("rsp_addr = 'h%0h, rsp_data = 'h%0h",
                  rsp.addr, rsp.data), UVM_HIGH)
    endtask
endclass : read_word_seq


// SEQUENCE: write_word_seq
class write_word_seq extends apb_master_base_seq;
    rand bit [31:0] start_addr;
    rand bit [31:0] write_data;
    rand int unsigned transmit_del;

    function new(string name="write_word_seq");
        super.new(name);
    endfunction

    `uvm_object_utils(write_word_seq)

    constraint transmit_del_ct { (transmit_del <= 10); }
    constraint addr_ct {(start_addr[1:0] == 0); }

    virtual task body();
        `uvm_info(get_type_name(), "Starting...", UVM_HIGH)
        `uvm_do_with(req,
            { req.addr == start_addr;
              req.direction == APB_WRITE;
              req.data == write_data;
              req.transmit_delay == transmit_del; } )
        `uvm_info(get_type_name(), $sprintf("addr = 'h%0h, data = 'h%0h",
                  req.addr, req.data), UVM_HIGH)
    endtask
endclass : write_word_seq


// SEQUENCE: read_after_write_seq
class read_after_write_seq extends apb_master_base_seq;

    rand bit [31:0] start_addr;
    rand bit [31:0] write_data;
    rand int unsigned transmit_del;

    function new(string name="read_after_write_seq");
        super.new(name);
    endfunction

    `uvm_object_utils(read_after_write_seq)

    constraint transmit_del_ct { (transmit_del <= 10); }
    constraint addr_ct {(start_addr[1:0] == 0); }

    virtual task body();
        `uvm_info(get_type_name(), "Starting...", UVM_MEDIUM)
        `uvm_do_with(req,
            { req.addr == start_addr;
              req.direction == APB_WRITE;
              req.data == write_data;
              req.transmit_delay == transmit_del; } )
        `uvm_info(get_type_name(), $sprintf("addr = 'h%0h, data = 'h%0h",
                  req.addr, req.data), UVM_HIGH)
    endtask
endclass : read_after_write_seq


// SEQUENCE: multiple_read_after_write_seq
class multiple_read_after_write_seq extends apb_master_base_seq;

    read_after_write_seq raw_seq;
    write_byte_seq w_seq;
    read_byte_seq r_seq;
    rand int unsigned num_of_seq;

    function new(string name="multiple_read_after_write_seq");
        super.new(name);
    endfunction

    `uvm_object_utils(multiple_read_after_write_seq)

    constraint num_of_seq_c { num_of_seq <= 10; num_of_seq >= 5; }

    virtual task body();
        `uvm_info(get_type_name(), "Starting...", UVM_MEDIUM)
        for (int i = 0; i < num_of_seq; i++) begin
            `uvm_info(get_type_name(), $sprintf("Executing sequence # %0d", i),
                      UVM_HIGH)
            `uvm_do(raw_seq)
        end
        repeat (3) `uvm_do_with(w_seq, {transmit_del == 1;})
        repeat (3) `uvm_do_with(r_seq, {transmit_del == 1;})
    endtask
endclass : multiple_read_after_write_seq

`endif // APB_MASTER_SEQ_LIB_SV
apb_slave_if.sv
interface apb_slave_if(input pclock, preset);
    // Actual Signals
    parameter   PADDR_WIDTH  = 32;
    parameter   PWDATA_WIDTH = 32;
    parameter   PRDATA_WIDTH = 32;

    // Control flags
    bit                      has_checks = 1;
    bit                      has_coverage = 1;

    // Actual Signals
    //wire logic             pclock;
    //wire logic             preset;
    wire logic [PADDR_WIDTH-1:0]  paddr;
    wire logic                    prwd;
    wire logic [PWDATA_WIDTH-1:0] pwdata;
    wire logic                    psel;
    wire logic                    penable;

    logic      [PRDATA_WIDTH-1:0] prdata;
    logic                         pslverr;
    logic                         pready;

    // Coverage and assertions to be implemented here.

    /* fix to make concurrent assertions
    always @(posedge pclock)
    begin
        // Pready must not be X or Z
        assertPreadyUnknown:assert property (
            disable iff(!has_checks)
            (!($isunknown(pready))))
        else
            $error("ERR_APB100_PREADY_XZ\n Pready went to X or Z");

        // Pslverr must not be X or Z
        assertPslverrUnknown:assert property (
            disable iff(!has_checks)
            ((psel == 1'b0 or pready == 1'b0 or !($isunknown(pslverr)))))
        else
            $error("ERR_APB101_PSLVERR_XZ\n Pslverr went to X or Z when responding");

        // Prdata must not be X or Z
        assertPrdataUnknown:assert property (
            disable iff(!has_checks)
            ((psel == 1'b0 or pready == 0 or prwd == 0 or !($isunknown(prdata)))))
        else
            $error("ERR_APB102_XZ\n Prdata went to X or Z when responding to a read transfer");
    end
    */

endinterface : apb_slave_if
apb_slave_agent.sv
`ifndef APB_SLAVE_AGENT_SV
`define APB_SLAVE_AGENT_SV

//----------------------------------------------------------------------
// CLASS: apb_slave_agent
//----------------------------------------------------------------------
class apb_slave_agent extends uvm_agent;

    // Virtual interface for this set components. The virtual interface can
    // be set from the agent, or set via config to each component.
    virtual apb_if vif;

    // This field determines whether an agent is active or passive.
    //uvm_active_passive_enum is_active = UVM_ACTIVE;

    // Slave Configuration Information:  name, is_active, psel_index,
    //                                   start_address, end_address
    apb_slave_config cfg;

    apb_slave_driver      driver;
    apb_slave_sequencer   sequencer;
    apb_monitor           monitor;
    apb_collector         collector;

    // Provide implementations of virtual methods such as get_type_name and create
    `uvm_component_utils_begin(apb_slave_agent)
        `uvm_field_object(monitor, UVM_DEFAULT | UVM_REFERENCE)
        `uvm_field_object(collector, UVM_DEFAULT | UVM_REFERENCE)
        `uvm_field_enum(uvm_active_passive_enum, is_active, UVM_DEFAULT)
        `uvm_field_object(cfg, UVM_DEFAULT | UVM_REFERENCE)
    `uvm_component_utils_end

    // new - constructor
    function new (string name, uvm_component parent);
        super.new(name, parent);
    endfunction : new

    // Additional class methods
    extern virtual function void build_phase(uvm_phase phase);
    extern virtual function void connect_phase(uvm_phase phase);
    extern virtual function void update_config(input apb_slave_config cfg);

endclass : apb_slave_agent


// UVM build_phase
function void apb_slave_agent::build_phase(uvm_phase phase);
    uvm_object config_obj;
    super.build_phase(phase);
    // Get the configuration information for this component
    if (cfg == null) begin
        if (!uvm_config_db#(apb_slave_config)::get(this, "", "cfg", cfg))
            `uvm_warning("NOCONFIG",
                "Config not set for slave agent using default is_active")
    end
    else is_active = cfg.is_active;
    // Create the sequencer and driver only if ACTIVE
    if (is_active == UVM_ACTIVE) begin
        sequencer = apb_slave_sequencer::type_id::create("sequencer",this);
        driver = apb_slave_driver::type_id::create("driver",this);
    end
endfunction : build_phase


// update_config()
function void apb_slave_agent::update_config(input apb_slave_config cfg);
    if (is_active == UVM_ACTIVE) begin
        sequencer.cfg = cfg;
    end
endfunction : update_config


// UVM connect_phase
function void apb_slave_agent::connect_phase(uvm_phase phase);
    // Get the agents virtual interface if set via get_config
    if (!uvm_config_db#(virtual apb_if)::get(this, "", "vif", vif))
        `uvm_error("NOVIF",{"virtual interface must be set for: ",get_full_name(),".vif"})
    // If the vif was set to the agent, apply it to its children
    uvm_config_db#(virtual apb_if)::set(this, "*", "vif", vif);

    if (is_active == UVM_ACTIVE) begin
        // Connect the driver to the sequencer using TLM interface
        driver.seq_item_port.connect(sequencer.seq_item_export);
    end
endfunction : connect_phase

`endif // APB_SLAVE_AGENT_SV
apb_slave_driver.sv
`ifndef APB_SLAVE_DRIVER_SV
`define APB_SLAVE_DRIVER_SV

//----------------------------------------------------------------------
// CLASS: apb_slave_driver declaration
//----------------------------------------------------------------------
class apb_slave_driver extends uvm_driver #(apb_transfer);

    // The virtual interface used to drive and view HDL signals.
    virtual apb_if vif;

    // Provide implementations of virtual methods such as get_type_name and create
    `uvm_component_utils(apb_slave_driver)

    // Constructor
    function new (string name, uvm_component parent);
        super.new(name, parent);
    endfunction : new

    // Additional class methods
    extern virtual function void connect_phase(uvm_phase phase);
    extern virtual task run_phase(uvm_phase phase);
    extern virtual task get_and_drive();
    extern virtual task reset_signals();
    extern virtual task respond_to_transfer(apb_transfer resp);

endclass : apb_slave_driver


// UVM connect_phase - gets the vif as a config property
function void apb_slave_driver::connect_phase(uvm_phase phase);
    super.connect_phase(phase);
    if (!uvm_config_db#(virtual apb_if)::get(this, "", "vif", vif))
        `uvm_error("NOVIF",{"virtual interface must be set for: ",get_full_name(),".vif"})
endfunction : connect_phase


// Externed virtual declaration of the run_phase method.  This method
// fork/join_none's the get_and_drive() and reset_signals() methods.
task apb_slave_driver::run_phase(uvm_phase phase);
    fork
        get_and_drive();
        reset_signals();
    join
endtask : run_phase


// Function that manages the interaction between the slave
// sequence sequencer and this slave driver.
task apb_slave_driver::get_and_drive();
    @(posedge vif.preset);
    `uvm_info(get_type_name(), "Reset dropped", UVM_MEDIUM)
    forever begin
        seq_item_port.get_next_item(req);
        respond_to_transfer(req);
        seq_item_port.item_done();
    end
endtask : get_and_drive


// Process task that assigns signals to reset state when reset signal set
task apb_slave_driver::reset_signals();
    forever begin
        @(negedge vif.preset);
        `uvm_info(get_type_name(), "Reset observed", UVM_MEDIUM)
        vif.prdata <= 32'hzzzz_zzzz;
        vif.pready <= 0;
        vif.pslverr <= 0;
    end
endtask : reset_signals

// 注意:图片中未提供 respond_to_transfer 的实现代码,
// 在实际工程中,此处应包含响应 APB 读/写操作的驱动逻辑。
// 例如:
// task apb_slave_driver::respond_to_transfer(apb_transfer resp);
//     ...
// endtask : respond_to_transfer

`endif // APB_SLAVE_DRIVER_SV
apb_slave_sequencer.sv
`ifndef APB_SLAVE_SEQUENCER_SV
`define APB_SLAVE_SEQUENCER_SV

//----------------------------------------------------------------------
// CLASS: apb_slave_sequencer declaration
//----------------------------------------------------------------------

class apb_slave_sequencer extends uvm_sequencer #(apb_transfer);

    uvm_blocking_peek_port#(apb_transfer) addr_trans_port;

    apb_slave_config cfg;

    // Provide implementations of virtual methods such as get_type_name and create
    `uvm_component_utils_begin(apb_slave_sequencer)
        `uvm_field_object(cfg, UVM_DEFAULT|UVM_REFERENCE)
    `uvm_component_utils_end

    // Constructor
    function new (string name, uvm_component parent);
        super.new(name, parent);
        addr_trans_port = new("addr_trans_port", this);
    endfunction : new

    virtual function void build_phase(uvm_phase phase);
        super.build_phase(phase);
        if(cfg == null)
            if (!uvm_config_db#(apb_slave_config)::get(this, "", "cfg", cfg))
                `uvm_error("NOCONFIG", "No configuration set")
    endfunction : build_phase

endclass : apb_slave_sequencer

`endif // APB_SLAVE_SEQUENCER_SV
apb_slave_seq_lib.sv
`ifndef APB_SLAVE_SEQ_LIB_SV
`define APB_SLAVE_SEQ_LIB_SV

//----------------------------------------------------------------------
// SEQUENCE: simple_response_seq
//----------------------------------------------------------------------
class simple_response_seq extends uvm_sequence #(apb_transfer);

    function new(string name="simple_response_seq");
        super.new(name);
    endfunction

    `uvm_object_utils(simple_response_seq)
    `uvm_declare_p_sequencer(apb_slave_sequencer)

    apb_transfer req;
    apb_transfer util_transfer;

    virtual task body();
        `uvm_info(get_type_name(), "Starting...", UVM_MEDIUM)
        forever begin
            p_sequencer.addr_trans_port.peek(util_transfer);
            if((util_transfer.direction == APB_READ) && 
               (p_sequencer.cfg.check_address_range(util_transfer.addr) == 1)) begin
                
                `uvm_info(get_type_name(), $sprintf("Address:%h Range Matching read Responding...", util_transfer.addr), UVM_MEDIUM);
                `uvm_do_with(req, { req.direction == APB_READ; } )
            end
        end
    endtask : body

endclass : simple_response_seq


//----------------------------------------------------------------------
// SEQUENCE: mem_response_seq
//----------------------------------------------------------------------
class mem_response_seq extends uvm_sequence #(apb_transfer);

    function new(string name="mem_response_seq");
        super.new(name);
    endfunction

    rand logic [31:0] mem_data;

    `uvm_object_utils(mem_response_seq)
    `uvm_declare_p_sequencer(apb_slave_sequencer)

    //simple assoc array to hold values
    logic [31:0] slave_mem[int];

    apb_transfer req;
    apb_transfer util_transfer;

    virtual task body();
        `uvm_info(get_type_name(), "Starting...", UVM_MEDIUM)
        forever begin
            p_sequencer.addr_trans_port.peek(util_transfer);
            if((util_transfer.direction == APB_READ) && 
               (p_sequencer.cfg.check_address_range(util_transfer.addr) == 1)) begin
                
                `uvm_info(get_type_name(), $sprintf("Address:%h Range Matching APB READ. Responding...", util_transfer.addr), UVM_MEDIUM);
                
                if (slave_mem.exists(util_transfer.addr))
                    `uvm_do_with(req, { req.direction == APB_READ;
                                        req.addr == util_transfer.addr;
                                        req.data == slave_mem[util_transfer.addr]; } )
                else begin
                    `uvm_do_with(req, { req.direction == APB_READ;
                                        req.addr == util_transfer.addr;
                                        req.data == mem_data; } )
                    mem_data++;
                end
            end
            else begin
                if (p_sequencer.cfg.check_address_range(util_transfer.addr) == 1) begin
                    
                    slave_mem[util_transfer.addr] = util_transfer.data;
                    // DUMMY response with same information
                    `uvm_do_with(req, { req.direction == APB_WRITE;
                                        req.addr == util_transfer.addr;
                                        req.data == util_transfer.data; } )
                end
            end
        end
    endtask : body

endclass : mem_response_seq

`endif // APB_SLAVE_SEQ_LIB_SV
ral_uart_reg.sv
//----------------------------------------------------------------------
// uart_reg_UARTTDR
//----------------------------------------------------------------------
class uart_reg_UARTTDR extends uvm_reg;
    `uvm_object_utils(uart_reg_UARTTDR);
    rand uvm_reg_field reserved_1;
    rand uvm_reg_field OE;
    rand uvm_reg_field BE;
    rand uvm_reg_field PE;
    rand uvm_reg_field FE;
    rand uvm_reg_field DATA;

    virtual function void build();
        reserved_1 = uvm_reg_field::type_id::create("reserved_1");
        reserved_1.configure(this, 4, 12, "RO", 0, 'h0, 1, 1, 1);

        OE = uvm_reg_field::type_id::create("OE");
        OE.configure(this, 1, 11, "RW", 0, 'h0, 1, 1, 1);

        BE = uvm_reg_field::type_id::create("BE");
        BE.configure(this, 1, 10, "RW", 0, 'h0, 1, 1, 1);

        PE = uvm_reg_field::type_id::create("PE");
        PE.configure(this, 1, 9, "RW", 0, 'h0, 1, 1, 1);

        FE = uvm_reg_field::type_id::create("FE");
        FE.configure(this, 1, 8, "RW", 0, 'h0, 1, 1, 1);

        DATA = uvm_reg_field::type_id::create("DATA");
        DATA.configure(this, 8, 0, "RW", 0, 'h0, 1, 1, 1);
    endfunction

    function new(input string name="uart_reg_UARTTDR");
        super.new(name, 32, UVM_NO_COVERAGE);
    endfunction
endclass


//----------------------------------------------------------------------
// uart_reg_UARTSR
//----------------------------------------------------------------------
class uart_reg_UARTSR extends uvm_reg;
    `uvm_object_utils(uart_reg_UARTSR);
    rand uvm_reg_field reserved_7;
    rand uvm_reg_field OE;
    rand uvm_reg_field BE;
    rand uvm_reg_field PE;
    rand uvm_reg_field FE;

    virtual function void build();
        reserved_7 = uvm_reg_field::type_id::create("reserved_7");
        reserved_7.configure(this, 12, 4, "RO", 0, 'h0, 1, 1, 1);

        OE = uvm_reg_field::type_id::create("OE");
        OE.configure(this, 1, 3, "RW", 0, 'h0, 1, 1, 1);

        BE = uvm_reg_field::type_id::create("BE");
        BE.configure(this, 1, 2, "RW", 0, 'h0, 1, 1, 1);

        PE = uvm_reg_field::type_id::create("PE");
        PE.configure(this, 1, 1, "RW", 0, 'h0, 1, 1, 1);

        FE = uvm_reg_field::type_id::create("FE");
        FE.configure(this, 1, 0, "RW", 0, 'h0, 1, 1, 1);
    endfunction

    function new(input string name="uart_reg_UARTSR");
        super.new(name, 32, UVM_NO_COVERAGE);
    endfunction
endclass


//----------------------------------------------------------------------
// uart_reg_UARTFR
//----------------------------------------------------------------------
class uart_reg_UARTFR extends uvm_reg;
    `uvm_object_utils(uart_reg_UARTFR);
    rand uvm_reg_field reserved_12;
    rand uvm_reg_field RI;
    rand uvm_reg_field TXFE;
    rand uvm_reg_field RXFE;
    rand uvm_reg_field TXFF;
    rand uvm_reg_field RXFF;
    rand uvm_reg_field BUSY;
    rand uvm_reg_field DCD;
    rand uvm_reg_field DSR;
    rand uvm_reg_field CTS;

    virtual function void build();
        reserved_12 = uvm_reg_field::type_id::create("reserved_12");
        reserved_12.configure(this, 7, 9, "RO", 0, 'h0, 1, 1, 1);

        RI = uvm_reg_field::type_id::create("RI");
        RI.configure(this, 1, 8, "RO", 0, 'h0, 1, 1, 1);

        TXFE = uvm_reg_field::type_id::create("TXFE");
        TXFE.configure(this, 1, 7, "RO", 0, 'h0, 1, 1, 1);

        RXFE = uvm_reg_field::type_id::create("RXFE");
        RXFE.configure(this, 1, 6, "RO", 0, 'h0, 1, 1, 1);

        TXFF = uvm_reg_field::type_id::create("TXFF");
        TXFF.configure(this, 1, 5, "RO", 0, 'h0, 1, 1, 1);

        RXFF = uvm_reg_field::type_id::create("RXFF");
        RXFF.configure(this, 1, 4, "RO", 0, 'h0, 1, 1, 1);

        BUSY = uvm_reg_field::type_id::create("BUSY");
        BUSY.configure(this, 1, 3, "RO", 0, 'h0, 1, 1, 1);

        DCD = uvm_reg_field::type_id::create("DCD");
        DCD.configure(this, 1, 2, "RO", 0, 'h0, 1, 1, 1);

        DSR = uvm_reg_field::type_id::create("DSR");
        DSR.configure(this, 1, 1, "RO", 0, 'h0, 1, 1, 1);

        CTS = uvm_reg_field::type_id::create("CTS");
        CTS.configure(this, 1, 0, "RO", 0, 'h0, 1, 1, 1);
    endfunction

    function new(input string name="uart_reg_UARTFR");
        super.new(name, 32, UVM_NO_COVERAGE);
    endfunction
endclass


//----------------------------------------------------------------------
// uart_reg_UARTIBRD
//----------------------------------------------------------------------
class uart_reg_UARTIBRD extends uvm_reg;
    `uvm_object_utils(uart_reg_UARTIBRD);
    rand uvm_reg_field BAUD_DIVINT;

    virtual function void build();
        BAUD_DIVINT = uvm_reg_field::type_id::create("BAUD_DIVINT");
        BAUD_DIVINT.configure(this, 16, 0, "RW", 0, 'h0, 1, 1, 1);
    endfunction

    function new(input string name="uart_reg_UARTIBRD");
        super.new(name, 32, UVM_NO_COVERAGE);
    endfunction
endclass


//----------------------------------------------------------------------
// uart_reg_UARTFBRD
//----------------------------------------------------------------------
class uart_reg_UARTFBRD extends uvm_reg;
    `uvm_object_utils(uart_reg_UARTFBRD);
    rand uvm_reg_field BAUD_DIVFRAC;

    virtual function void build();
        BAUD_DIVFRAC = uvm_reg_field::type_id::create("BAUD_DIVFRAC");
        BAUD_DIVFRAC.configure(this, 16, 0, "RW", 0, 'h0, 1, 1, 1);
    endfunction

    function new(input string name="uart_reg_UARTFBRD");
        super.new(name, 32, UVM_NO_COVERAGE);
    endfunction
endclass


//----------------------------------------------------------------------
// uart_reg_UARTLCR_H
//----------------------------------------------------------------------
class uart_reg_UARTLCR_H extends uvm_reg;
    `uvm_object_utils(uart_reg_UARTLCR_H);
    rand uvm_reg_field reserved_24;
    rand uvm_reg_field SPS;
    rand uvm_reg_field WLEN;
    rand uvm_reg_field FEN;
    rand uvm_reg_field STP2;
    rand uvm_reg_field EPS;
    rand uvm_reg_field PEN;
    rand uvm_reg_field BRK;

    virtual function void build();
        reserved_24 = uvm_reg_field::type_id::create("reserved_24");
        reserved_24.configure(this, 8, 8, "RO", 0, 'h0, 1, 1, 1);

        SPS = uvm_reg_field::type_id::create("SPS");
        SPS.configure(this, 1, 7, "RW", 0, 'h0, 1, 1, 1);

        WLEN = uvm_reg_field::type_id::create("WLEN");
        WLEN.configure(this, 2, 5, "RW", 0, 'h0, 1, 1, 1);

        FEN = uvm_reg_field::type_id::create("FEN");
        FEN.configure(this, 1, 4, "RW", 0, 'h0, 1, 1, 1);

        STP2 = uvm_reg_field::type_id::create("STP2");
        STP2.configure(this, 1, 3, "RW", 0, 'h0, 1, 1, 1);

        EPS = uvm_reg_field::type_id::create("EPS");
        EPS.configure(this, 1, 2, "RW", 0, 'h0, 1, 1, 1);

        PEN = uvm_reg_field::type_id::create("PEN");
        PEN.configure(this, 1, 1, "RW", 0, 'h0, 1, 1, 1);

        BRK = uvm_reg_field::type_id::create("BRK");
        BRK.configure(this, 1, 0, "RW", 0, 'h0, 1, 1, 1);
    endfunction

    function new(input string name="uart_reg_UARTLCR_H");
        super.new(name, 32, UVM_NO_COVERAGE);
    endfunction
endclass


//----------------------------------------------------------------------
// uart_reg_UARTCR
//----------------------------------------------------------------------
class uart_reg_UARTCR extends uvm_reg;
    `uvm_object_utils(uart_reg_UARTCR);
    rand uvm_reg_field CTSEn;
    rand uvm_reg_field RTSEn;
    rand uvm_reg_field Out2;
    rand uvm_reg_field Out1;
    rand uvm_reg_field RTS;
    rand uvm_reg_field DTR;
    rand uvm_reg_field RXE;
    rand uvm_reg_field TXE;
    rand uvm_reg_field LBE;
    rand uvm_reg_field reserved_41;
    rand uvm_reg_field SIRLP;
    rand uvm_reg_field SIREN;
    rand uvm_reg_field UARTEN;

    virtual function void build();
        CTSEn = uvm_reg_field::type_id::create("CTSEn");
        CTSEn.configure(this, 1, 15, "RW", 0, 'h0, 1, 1, 1);

        RTSEn = uvm_reg_field::type_id::create("RTSEn");
        RTSEn.configure(this, 1, 14, "RW", 0, 'h0, 1, 1, 1);

        Out2 = uvm_reg_field::type_id::create("Out2");
        Out2.configure(this, 1, 13, "RW", 0, 'h0, 1, 1, 1);

        Out1 = uvm_reg_field::type_id::create("Out1");
        Out1.configure(this, 1, 12, "RW", 0, 'h0, 1, 1, 1);

        RTS = uvm_reg_field::type_id::create("RTS");
        RTS.configure(this, 1, 11, "RW", 0, 'h0, 1, 1, 1);

        DTR = uvm_reg_field::type_id::create("DTR");
        DTR.configure(this, 1, 10, "RW", 0, 'h0, 1, 1, 1);

        RXE = uvm_reg_field::type_id::create("RXE");
        RXE.configure(this, 1, 9, "RW", 0, 'h1, 1, 1, 1);

        TXE = uvm_reg_field::type_id::create("TXE");
        TXE.configure(this, 1, 8, "RW", 0, 'h1, 1, 1, 1);

        LBE = uvm_reg_field::type_id::create("LBE");
        LBE.configure(this, 1, 7, "RW", 0, 'h0, 1, 1, 1);

        reserved_41 = uvm_reg_field::type_id::create("reserved_41");
        reserved_41.configure(this, 4, 3, "RO", 0, 'h0, 1, 1, 1);

        SIRLP = uvm_reg_field::type_id::create("SIRLP");
        SIRLP.configure(this, 1, 2, "RW", 0, 'h0, 1, 1, 1);

        SIREN = uvm_reg_field::type_id::create("SIREN");
        SIREN.configure(this, 1, 1, "RW", 0, 'h0, 1, 1, 1);

        UARTEN = uvm_reg_field::type_id::create("UARTEN");
        UARTEN.configure(this, 1, 0, "RW", 0, 'h0, 1, 1, 1);
    endfunction

    function new(input string name="uart_reg_UARTCR");
        super.new(name, 32, UVM_NO_COVERAGE);
    endfunction
endclass


//----------------------------------------------------------------------
// uart_reg_UARTIFLS
//----------------------------------------------------------------------
class uart_reg_UARTIFLS extends uvm_reg;
    `uvm_object_utils(uart_reg_UARTIFLS);
    rand uvm_reg_field reserved_45;
    rand uvm_reg_field RXIFLSEL;
    rand uvm_reg_field TXIFLSEL;

    virtual function void build();
        reserved_45 = uvm_reg_field::type_id::create("reserved_45");
        reserved_45.configure(this, 10, 6, "RO", 0, 'h0, 1, 1, 1);

        RXIFLSEL = uvm_reg_field::type_id::create("RXIFLSEL");
        RXIFLSEL.configure(this, 3, 3, "RW", 0, 'h2, 1, 1, 1);

        TXIFLSEL = uvm_reg_field::type_id::create("TXIFLSEL");
        TXIFLSEL.configure(this, 3, 0, "RW", 0, 'h2, 1, 1, 1);
    endfunction

    function new(input string name="uart_reg_UARTIFLS");
        super.new(name, 32, UVM_NO_COVERAGE);
    endfunction
endclass


//----------------------------------------------------------------------
// uart_reg_UARTIMSC
//----------------------------------------------------------------------
class uart_reg_UARTIMSC extends uvm_reg;
    `uvm_object_utils(uart_reg_UARTIMSC);
    rand uvm_reg_field reserved_48;
    rand uvm_reg_field OEIM;
    rand uvm_reg_field BEIM;
    rand uvm_reg_field PEIM;
    rand uvm_reg_field FEIM;
    rand uvm_reg_field RTIM;
    rand uvm_reg_field TXIM;
    rand uvm_reg_field RXIM;
    rand uvm_reg_field DSRMIM;
    rand uvm_reg_field DCDMIM;
    rand uvm_reg_field CTSRMIM;
    rand uvm_reg_field RIRMIM;

    virtual function void build();
        reserved_48 = uvm_reg_field::type_id::create("reserved_48");
        reserved_48.configure(this, 5, 11, "RO", 0, 'h0, 1, 1, 1);

        OEIM = uvm_reg_field::type_id::create("OEIM");
        OEIM.configure(this, 1, 10, "RW", 0, 'h0, 1, 1, 1);

        BEIM = uvm_reg_field::type_id::create("BEIM");
        BEIM.configure(this, 1, 9, "RW", 0, 'h0, 1, 1, 1);

        PEIM = uvm_reg_field::type_id::create("PEIM");
        PEIM.configure(this, 1, 8, "RW", 0, 'h0, 1, 1, 1);

        FEIM = uvm_reg_field::type_id::create("FEIM");
        FEIM.configure(this, 1, 7, "RW", 0, 'h0, 1, 1, 1);

        RTIM = uvm_reg_field::type_id::create("RTIM");
        RTIM.configure(this, 1, 6, "RW", 0, 'h0, 1, 1, 1);

        TXIM = uvm_reg_field::type_id::create("TXIM");
        TXIM.configure(this, 1, 5, "RW", 0, 'h0, 1, 1, 1);

        RXIM = uvm_reg_field::type_id::create("RXIM");
        RXIM.configure(this, 1, 4, "RW", 0, 'h0, 1, 1, 1);

        DSRMIM = uvm_reg_field::type_id::create("DSRMIM");
        DSRMIM.configure(this, 1, 3, "RW", 0, 'h0, 1, 1, 1);

        DCDMIM = uvm_reg_field::type_id::create("DCDMIM");
        DCDMIM.configure(this, 1, 2, "RW", 0, 'h0, 1, 1, 1);

        CTSRMIM = uvm_reg_field::type_id::create("CTSRMIM");
        CTSRMIM.configure(this, 1, 1, "RW", 0, 'h0, 1, 1, 1);

        RIRMIM = uvm_reg_field::type_id::create("RIRMIM");
        RIRMIM.configure(this, 1, 0, "RW", 0, 'h0, 1, 1, 1);
    endfunction

    function new(input string name="uart_reg_UARTIMSC");
        super.new(name, 32, UVM_NO_COVERAGE);
    endfunction
endclass


//----------------------------------------------------------------------
// uart_reg_UARTRIS
//----------------------------------------------------------------------
class uart_reg_UARTRIS extends uvm_reg;
    `uvm_object_utils(uart_reg_UARTRIS);
    rand uvm_reg_field reserved_60;
    rand uvm_reg_field OERIS;
    rand uvm_reg_field BERIS;
    rand uvm_reg_field PERIS;
    rand uvm_reg_field FERIS;
    rand uvm_reg_field RTRIS;
    rand uvm_reg_field TXRIS;
    rand uvm_reg_field RXRIS;
    rand uvm_reg_field DSRRMIS;
    rand uvm_reg_field DCDRMIS;
    rand uvm_reg_field CTSRMIS;
    rand uvm_reg_field RIRMIS;

    virtual function void build();
        reserved_60 = uvm_reg_field::type_id::create("reserved_60");
        reserved_60.configure(this, 5, 11, "RO", 0, 'h0, 1, 1, 1);

        OERIS = uvm_reg_field::type_id::create("OERIS");
        OERIS.configure(this, 1, 10, "RO", 0, 'h0, 1, 1, 1);

        BERIS = uvm_reg_field::type_id::create("BERIS");
        BERIS.configure(this, 1, 9, "RO", 0, 'h0, 1, 1, 1);

        PERIS = uvm_reg_field::type_id::create("PERIS");
        PERIS.configure(this, 1, 8, "RO", 0, 'h0, 1, 1, 1);

        FERIS = uvm_reg_field::type_id::create("FERIS");
        FERIS.configure(this, 1, 7, "RO", 0, 'h0, 1, 1, 1);

        RTRIS = uvm_reg_field::type_id::create("RTRIS");
        RTRIS.configure(this, 1, 6, "RO", 0, 'h0, 1, 1, 1);

        TXRIS = uvm_reg_field::type_id::create("TXRIS");
        TXRIS.configure(this, 1, 5, "RO", 0, 'h0, 1, 1, 1);

        RXRIS = uvm_reg_field::type_id::create("RXRIS");
        RXRIS.configure(this, 1, 4, "RO", 0, 'h0, 1, 1, 1);

        DSRRMIS = uvm_reg_field::type_id::create("DSRRMIS");
        DSRRMIS.configure(this, 1, 3, "RO", 0, 'h0, 1, 1, 1);

        DCDRMIS = uvm_reg_field::type_id::create("DCDRMIS");
        DCDRMIS.configure(this, 1, 2, "RO", 0, 'h0, 1, 1, 1);

        CTSRMIS = uvm_reg_field::type_id::create("CTSRMIS");
        CTSRMIS.configure(this, 1, 1, "RO", 0, 'h0, 1, 1, 1);

        RIRMIS = uvm_reg_field::type_id::create("RIRMIS");
        RIRMIS.configure(this, 1, 0, "RO", 0, 'h1, 1, 1, 1);
    endfunction

    function new(input string name="uart_reg_UARTRIS");
        super.new(name, 32, UVM_NO_COVERAGE);
    endfunction
endclass


//----------------------------------------------------------------------
// uart_reg_UARTMIS
//----------------------------------------------------------------------
class uart_reg_UARTMIS extends uvm_reg;
    `uvm_object_utils(uart_reg_UARTMIS);
    rand uvm_reg_field reserved_72;
    rand uvm_reg_field OEMIS;
    rand uvm_reg_field BEMIS;
    rand uvm_reg_field PEMIS;
    rand uvm_reg_field FEMIS;
    rand uvm_reg_field RTMIS;
    rand uvm_reg_field TXMIS;
    rand uvm_reg_field RXMIS;
    rand uvm_reg_field DSRMMIS;
    rand uvm_reg_field DCDMMIS;
    rand uvm_reg_field CTSMMIS;
    rand uvm_reg_field RIMMIS;

    virtual function void build();
        reserved_72 = uvm_reg_field::type_id::create("reserved_72");
        reserved_72.configure(this, 5, 11, "RO", 0, 'h0, 1, 1, 1);

        OEMIS = uvm_reg_field::type_id::create("OEMIS");
        OEMIS.configure(this, 1, 10, "RO", 0, 'h0, 1, 1, 1);

        BEMIS = uvm_reg_field::type_id::create("BEMIS");
        BEMIS.configure(this, 1, 9, "RO", 0, 'h0, 1, 1, 1);

        PEMIS = uvm_reg_field::type_id::create("PEMIS");
        PEMIS.configure(this, 1, 8, "RO", 0, 'h0, 1, 1, 1);

        FEMIS = uvm_reg_field::type_id::create("FEMIS");
        FEMIS.configure(this, 1, 7, "RO", 0, 'h0, 1, 1, 1);

        RTMIS = uvm_reg_field::type_id::create("RTMIS");
        RTMIS.configure(this, 1, 6, "RO", 0, 'h0, 1, 1, 1);

        TXMIS = uvm_reg_field::type_id::create("TXMIS");
        TXMIS.configure(this, 1, 5, "RO", 0, 'h0, 1, 1, 1);

        RXMIS = uvm_reg_field::type_id::create("RXMIS");
        RXMIS.configure(this, 1, 4, "RO", 0, 'h0, 1, 1, 1);

        DSRMMIS = uvm_reg_field::type_id::create("DSRMMIS");
        DSRMMIS.configure(this, 1, 3, "RO", 0, 'h0, 1, 1, 1);

        DCDMMIS = uvm_reg_field::type_id::create("DCDMMIS");
        DCDMMIS.configure(this, 1, 2, "RO", 0, 'h0, 1, 1, 1);

        CTSMMIS = uvm_reg_field::type_id::create("CTSMMIS");
        CTSMMIS.configure(this, 1, 1, "RO", 0, 'h1, 1, 1, 1);

        RIMMIS = uvm_reg_field::type_id::create("RIMMIS");
        RIMMIS.configure(this, 1, 0, "RO", 0, 'h0, 1, 1, 1);
    endfunction

    function new(input string name="uart_reg_UARTMIS");
        super.new(name, 32, UVM_NO_COVERAGE);
    endfunction
endclass


//----------------------------------------------------------------------
// uart_reg_UARTICR
//----------------------------------------------------------------------
class uart_reg_UARTICR extends uvm_reg;
    `uvm_object_utils(uart_reg_UARTICR);
    rand uvm_reg_field reserved_84;
    rand uvm_reg_field OEIC;
    rand uvm_reg_field BEIC;
    rand uvm_reg_field PEIC;
    rand uvm_reg_field FEIC;
    rand uvm_reg_field RTIC;
    rand uvm_reg_field TXIC;
    rand uvm_reg_field RXIC;
    rand uvm_reg_field DSRMIC;
    rand uvm_reg_field DCDMIC;
    rand uvm_reg_field CTSMIC;
    rand uvm_reg_field RIMIC;

    virtual function void build();
        reserved_84 = uvm_reg_field::type_id::create("reserved_84");
        reserved_84.configure(this, 5, 11, "RO", 0, 'h0, 1, 1, 1);

        OEIC = uvm_reg_field::type_id::create("OEIC");
        OEIC.configure(this, 1, 10, "WO", 0, 'h0, 1, 1, 1);

        BEIC = uvm_reg_field::type_id::create("BEIC");
        BEIC.configure(this, 1, 9, "WO", 0, 'h0, 1, 1, 1);

        PEIC = uvm_reg_field::type_id::create("PEIC");
        PEIC.configure(this, 1, 8, "WO", 0, 'h0, 1, 1, 1);

        FEIC = uvm_reg_field::type_id::create("FEIC");
        FEIC.configure(this, 1, 7, "WO", 0, 'h0, 1, 1, 1);

        RTIC = uvm_reg_field::type_id::create("RTIC");
        RTIC.configure(this, 1, 6, "WO", 0, 'h0, 1, 1, 1);

        TXIC = uvm_reg_field::type_id::create("TXIC");
        TXIC.configure(this, 1, 5, "WO", 0, 'h0, 1, 1, 1);

        RXIC = uvm_reg_field::type_id::create("RXIC");
        RXIC.configure(this, 1, 4, "WO", 0, 'h0, 1, 1, 1);

        DSRMIC = uvm_reg_field::type_id::create("DSRMIC");
        DSRMIC.configure(this, 1, 3, "WO", 0, 'h0, 1, 1, 1);

        DCDMIC = uvm_reg_field::type_id::create("DCDMIC");
        DCDMIC.configure(this, 1, 2, "WO", 0, 'h0, 1, 1, 1);

        CTSMIC = uvm_reg_field::type_id::create("CTSMIC");
        CTSMIC.configure(this, 1, 1, "WO", 0, 'h1, 1, 1, 1);

        RIMIC = uvm_reg_field::type_id::create("RIMIC");
        RIMIC.configure(this, 1, 0, "WO", 0, 'h1, 1, 1, 1);
    endfunction

    function new(input string name="uart_reg_UARTICR");
        super.new(name, 32, UVM_NO_COVERAGE);
    endfunction
endclass


//----------------------------------------------------------------------
// rb_uart_reg
//----------------------------------------------------------------------
class rb_uart_reg extends uvm_reg_block;
    rand uart_reg_UARTTDR  UARTTDR;
    rand uart_reg_UARTSR   UARTSR;
    rand uart_reg_UARTFR   UARTFR;
    rand uart_reg_UARTIBRD UARTIBRD;
    rand uart_reg_UARTFBRD UARTFBRD;
    rand uart_reg_UARTLCR_H UARTLCR_H;
    rand uart_reg_UARTCR   UARTCR;
    rand uart_reg_UARTIFLS UARTIFLS;
    rand uart_reg_UARTIMSC UARTIMSC;
    rand uart_reg_UARTRIS  UARTRIS;
    rand uart_reg_UARTMIS  UARTMIS;
    rand uart_reg_UARTICR  UARTICR;

    `uvm_object_utils(rb_uart_reg)

    function new(input string name="rb_uart_reg");
        super.new(name, UVM_NO_COVERAGE);
    endfunction

    virtual function void build();
        default_map = create_map("default_map", 0, 4, UVM_BIG_ENDIAN, 1);

        UARTTDR = uart_reg_UARTTDR::type_id::create("UARTTDR", ,get_full_name());
        UARTTDR.configure(this, null, "");
        UARTTDR.build();
        default_map.add_reg(UARTTDR, 'h000, "RW");

        UARTSR = uart_reg_UARTSR::type_id::create("UARTSR", ,get_full_name());
        UARTSR.configure(this, null, "");
        UARTSR.build();
        default_map.add_reg(UARTSR, 'h004, "RW");

        UARTFR = uart_reg_UARTFR::type_id::create("UARTFR", ,get_full_name());
        UARTFR.configure(this, null, "");
        UARTFR.build();
        default_map.add_reg(UARTFR, 'h018, "RW");

        UARTIBRD = uart_reg_UARTIBRD::type_id::create("UARTIBRD", ,get_full_name());
        UARTIBRD.configure(this, null, "");
        UARTIBRD.build();
        default_map.add_reg(UARTIBRD, 'h024, "RW");

        UARTFBRD = uart_reg_UARTFBRD::type_id::create("UARTFBRD", ,get_full_name());
        UARTFBRD.configure(this, null, "");
        UARTFBRD.build();
        default_map.add_reg(UARTFBRD, 'h028, "RW");

        UARTLCR_H = uart_reg_UARTLCR_H::type_id::create("UARTLCR_H", ,get_full_name());
        UARTLCR_H.configure(this, null, "");
        UARTLCR_H.build();
        default_map.add_reg(UARTLCR_H, 'h02c, "RW");

        UARTCR = uart_reg_UARTCR::type_id::create("UARTCR", ,get_full_name());
        UARTCR.configure(this, null, "");
        UARTCR.build();
        default_map.add_reg(UARTCR, 'h030, "RW");

        UARTIFLS = uart_reg_UARTIFLS::type_id::create("UARTIFLS", ,get_full_name());
        UARTIFLS.configure(this, null, "");
        UARTIFLS.build();
        default_map.add_reg(UARTIFLS, 'h034, "RW");

        UARTIMSC = uart_reg_UARTIMSC::type_id::create("UARTIMSC", ,get_full_name());
        UARTIMSC.configure(this, null, "");
        UARTIMSC.build();
        default_map.add_reg(UARTIMSC, 'h038, "RW");

        UARTRIS = uart_reg_UARTRIS::type_id::create("UARTRIS", ,get_full_name());
        UARTRIS.configure(this, null, "");
        UARTRIS.build();
        default_map.add_reg(UARTRIS, 'h03c, "RW");

        UARTMIS = uart_reg_UARTMIS::type_id::create("UARTMIS", ,get_full_name());
        UARTMIS.configure(this, null, "");
        UARTMIS.build();
        default_map.add_reg(UARTMIS, 'h040, "RW");

        UARTICR = uart_reg_UARTICR::type_id::create("UARTICR", ,get_full_name());
        UARTICR.configure(this, null, "");
        UARTICR.build();
        default_map.add_reg(UARTICR, 'h044, "RW");
    endfunction
endclass

posted on 2026-11-14 22:05  tuck0603  阅读(8)  评论(0)    收藏  举报

导航