/****************************************************************************
    +-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+ +-+-+-+-+-+-+-+-+
    |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            i2c_master_agent.sv

    DESCRIPTION     master agent

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

`ifndef I2C_MASTER_AGENT_SV
`define I2C_MASTER_AGENT_SV

typedef uvm_sequencer #(i2c_transaction) i2c_master_sequencer;

/*
 * Class: i2c_master_agent
 */
class i2c_master_agent extends uvm_agent;
    
    // configuration object
    i2c_master_config cfg;

    // components
    i2c_monitor          mon;
    i2c_master_driver    drv;
    i2c_master_sequencer seqr;
    
    // UVM factory registration
    `uvm_component_utils_begin(i2c_master_agent)
        `uvm_field_object(cfg, UVM_DEFAULT)
    `uvm_component_utils_end

    // new - constructor
    function new(string name = "i2c_master_agent", uvm_component parent);
        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#(i2c_master_config)::get(this, "", "i2c_master_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.is_active == UVM_ACTIVE) begin
            seqr = i2c_master_sequencer::type_id::create("seqr", this);
            drv = i2c_master_driver::type_id::create("drv", this);
        end
        // always create monitor
        mon = i2c_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.is_active == UVM_ACTIVE) begin
            drv.seq_item_port.connect(seqr.seq_item_export);
        end
    endfunction : connect_phase

endclass : i2c_master_agent

`endif

