/****************************************************************************
    +-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+ +-+-+-+-+-+-+-+-+
    |F|u|n|c|t|i|o|n|a|l| |V|e|r|i|f|i|c|a|t|i|o|n| |o|f| |H|a|r|d|w|a|r|e|
    +-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+ +-+-+-+-+-+-+-+-+

    FILE            apb_master_agent.sv

    DESCRIPTION     master agent

 ****************************************************************************/

`ifndef APB_MASTER_AGENT_SV
`define APB_MASTER_AGENT_SV
    
/**
 * Class: apb_master_agent
 */
class apb_master_agent extends uvm_agent;
    
    // configuration object
    apb_config       cfg;

    // components
    apb_master_driver       drv;
    apb_master_sequencer    seqr;
    apb_master_monitor      mon;

    // UVM factory registration
    `uvm_component_utils_begin(apb_master_agent)
        `uvm_field_object(cfg, UVM_DEFAULT | UVM_REFERENCE)
    `uvm_component_utils_end    

    // new - constructor
	function new(string name = "apb_master_agent", uvm_component parent = null);
		super.new(name, parent);
	endfunction : new
    
    // UVM build_phase
    function void build_phase(uvm_phase phase);
        super.build_phase(phase);

        // get configuration object from db
        if(!uvm_config_db#(apb_config)::get(this, "", "apb_config", cfg))
            `uvm_fatal("NOCONFIG",{"Config object must be set for: ",get_full_name(),".cfg"})

        // create driver and sequencer if agent is active
        if(cfg.master_cfg.is_active == UVM_ACTIVE) begin
            seqr = apb_master_sequencer::type_id::create("seqr", this);
            drv = apb_master_driver::type_id::create("drv", this);
        end
        // always create monitor
        mon = apb_master_monitor::type_id::create("mon", this);
    endfunction : build_phase

    // UVM connect_phase
    function void connect_phase(uvm_phase phase);
        super.connect_phase(phase);
        // connect driver and sequencer if agent is active
        if(cfg.master_cfg.is_active == UVM_ACTIVE) begin
            drv.seq_item_port.connect(seqr.seq_item_export);
        end
    endfunction : connect_phase
    
endclass : apb_master_agent

`endif

