Jump to content

Hierachical configuration class


Recommended Posts

Hi,

I'm trying to implement my VIP by using configuration classes for the agent and the environment. What is the recommended way of doing this, if I want to override both the agent and its configuration with an extended child definition?

Below is an example of how I think i should be written, but unfortunately, the configuration is not set for the extended agent: (Sorry for the bad increment)

package pkg;

import uvm_pkg::*;

`include "uvm_macros.svh"

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

/* configuration that will be used in my base agent

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

class BaseConfig extends uvm_object;

`uvm_object_utils(BaseConfig)

rand int baseconfig_item;

function new (string name = "");

super.new(name);

baseconfig_item = 0;

endfunction

// Standard utility method for a config object or transaction

function string convert2string;

return $sformatf("baseconfig_item = %0d\n", baseconfig_item);

endfunction

endclass: BaseConfig

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

/* configuration that will be used in my extended agent

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

class ExtendedConfig extends BaseConfig;

`uvm_object_utils(ExtendedConfig)

rand int extconfig_item;

function new (string name = "");

super.new(name);

extconfig_item = 1;

endfunction

// Standard utility method for a config object or transaction

function string convert2string;

return $sformatf("extconfig_item = %0d, baseconfig_item = %0d\n", extconfig_item, baseconfig_item);

endfunction

endclass: ExtendedConfig

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

/* configuration that will be used in my environment,

/* instantiates basically one agent_config per agent,

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

class EnvConfig extends uvm_object;

`uvm_object_utils(EnvConfig)

rand int env_item;

BaseConfig cfg;

function new (string name = "");

super.new(name);

cfg = new();

cfg = BaseConfig::type_id::create("cfg");

env_item = 2;

endfunction

// Standard utility method for a config object or transaction

function string convert2string;

return $sformatf("env_item = %0d, cfg: %s\n", env_item, cfg.convert2string);

endfunction

endclass: EnvConfig

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

/* Agent and enviromnent definitions

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

class BaseAgent extends uvm_agent;

`uvm_component_utils(BaseAgent)

// new - constructor

function new (string name, uvm_component parent);

super.new(name, parent);

endfunction : new

function void build_phase(uvm_phase phase);

super.build_phase(phase);

endfunction: build_phase

task run_phase(uvm_phase phase);

phase.raise_objection(this);

`uvm_info("Component A", "hello out there!", UVM_MEDIUM)

phase.drop_objection(this);

endtask

endclass: BaseAgent

class ExtendedAgent extends BaseAgent;

`uvm_component_utils(ExtendedAgent)

ExtendedConfig my_ext_cfg;

// new - constructor

function new (string name, uvm_component parent);

super.new(name, parent);

endfunction : new

function void build_phase(uvm_phase phase);

super.build_phase(phase);

// Get config

if (!uvm_config_db #(ExtendedConfig)::get(this, "", "cfg", my_ext_cfg) )

`uvm_fatal("NOCFG",{"config must be set for: ",get_full_name(),".my_ext_cfg"});

endfunction: build_phase

task run_phase(uvm_phase phase);

phase.raise_objection(this);

`uvm_info("Component B", "hello out there!", UVM_MEDIUM)

`uvm_info("Component B", my_ext_cfg.convert2string, UVM_MEDIUM)

phase.drop_objection(this);

endtask

endclass: ExtendedAgent

class BaseEnv extends uvm_env;

`uvm_component_utils(BaseEnv)

EnvConfig env_cfg;

BaseAgent my_base_agent;

// new - constructor

function new(string name, uvm_component parent);

super.new(name, parent);

endfunction : new

// build

function void build_phase(uvm_phase phase);

super.build_phase(phase);

if(!uvm_config_db#(EnvConfig)::get(this, "", "env_config", env_cfg))

`uvm_fatal("NOCFG",{"config must be set for: ",get_full_name(),".env_cfg"});

// update some baseAgent params

env_cfg.cfg.baseconfig_item = 5;

// forward config to lower component

uvm_config_db #(BaseConfig)::set(this, "cfg", "config", env_cfg.cfg);

my_base_agent = new("agent", null);

my_base_agent = BaseAgent::type_id::create("agent", this);

endfunction : build_phase

endclass: BaseEnv

endpackage

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

/* Top module with overrides

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

module test;

import uvm_pkg::*;

import pkg::*;

BaseEnv my_base_env;

EnvConfig env_cfg;

initial begin

// Override my base class with extended functionality

factory.set_type_override_by_type(BaseAgent::get_type(), ExtendedAgent::get_type());

factory.set_type_override_by_type(BaseConfig::get_type(), ExtendedConfig::get_type());

env_cfg = new();

uvm_config_db #(EnvConfig)::set(my_base_env, "*", "env_config", env_cfg);

my_base_env = new("env", null);

run_test();

end

endmodule // test

Link to comment
Share on other sites

Thank you for the quick answer. I'm not sure I understood correctly, but here are my changes

1. In the class BaseAgent, I instantiate a base_cfg and run a uvm_config_db #(BaseConfig)::get(this, "", "config", my_cfg)

2. in the class ExtendedAgent, I declare an ExtendedConfig and assign it using $cast(my_ext_cfg, my_cfg);

It seems to work :). Any comments?

See Code Below:

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

/ Agent and environment definitions

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

class BaseAgent extends uvm_agent;

`uvm_component_utils(BaseAgent)

BaseConfig my_cfg;

// new - constructor

function new (string name, uvm_component parent);

super.new(name, parent);

endfunction : new

function void build_phase(uvm_phase phase);

super.build_phase(phase);

// Get config

if (!uvm_config_db #(BaseConfig)::get(this, "", "config", my_cfg) )

`uvm_fatal("NOCFG",{"config must be set for: ",get_full_name(),".my_cfg"});

endfunction: build_phase

task run_phase(uvm_phase phase);

phase.raise_objection(this);

`uvm_info("Component A", "hello out there!", UVM_MEDIUM)

// `uvm_info("Component A", my_cfg.convert2string, UVM_MEDIUM)

phase.drop_objection(this);

endtask

endclass: BaseAgent

class ExtendedAgent extends BaseAgent;

`uvm_component_utils(ExtendedAgent)

ExtendedConfig my_ext_cfg;

// new - constructor

function new (string name, uvm_component parent);

super.new(name, parent);

endfunction : new

function void build_phase(uvm_phase phase);

super.build_phase(phase);

$cast(my_ext_cfg, my_cfg);

endfunction: build_phase

task run_phase(uvm_phase phase);

phase.raise_objection(this);

`uvm_info("Component B", "hello out there!", UVM_MEDIUM)

`uvm_info("Component B", my_ext_cfg.convert2string, UVM_MEDIUM)

phase.drop_objection(this);

endtask

endclass: ExtendedAgent

A last issue is when I try to assign the extconfig_item from the top module (see code below). Not really sure, how I should do this...

module test;

import uvm_pkg::*;

import pkg::*;

BaseEnv my_base_env;

EnvConfig env_cfg;

initial begin

// Override my base class with extended functionality

factory.set_type_override_by_type(BaseAgent::get_type(), ExtendedAgent::get_type());

factory.set_type_override_by_type(BaseConfig::get_type(), ExtendedConfig::get_type());

env_cfg = new();

env_cfg.env_item = 0; // Ok

env_cfg.cfg.baseconfig_item = 10; // Ok

env_cfg.cfg.extconfig_item = 11; // Error, Could not find member 'extconfig_item' in class 'BaseConfig'

uvm_config_db #(EnvConfig)::set(my_base_env, "*", "env_config", env_cfg);

my_base_env = new("env", null);

run_test();

end

endmodule // test

Link to comment
Share on other sites

  • 2 weeks later...

By creating the env_cfg and the extended agent_cfg in the top, one will be able to assign the extconfig items:

[...]

// Configurations

EnvConfig env_cfg;

ExtendedConfig agent_cfg;

initial begin

// Override my base class with extended functionality

factory.set_type_override_by_type(BaseAgent::get_t ype(), ExtendedAgent::get_type());

agent_cfg = ext_audio_config::type_id::create("agent_cfg");

agent_cfg.baseconfig_item = 20;

agent_cfg.extconfig_item = 10;

env_cfg = EnvConfig::type_id::create("env_cfg");

env_cfg.env_item = 15;

env_cfg.cfg = agent_cfg;

uvm_config_db #(EnvConfig)::set(this, "*", "env_config", env_cfg);

[...]

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...