Analysis port connections

Hi,

  I've implemented the following code;

class monitor extends ovm_monitor;
ovm_analysis_port #(transaction) tx_data;

function void build();
tx_data = new(“tx_data”,this);
endfunction
endclass

class agent extends ovm_agent;
monitor tx_monitor;
ovm_analysis_port #(transaction) data_out_tx;

function void build();
tx_monitor = monitor::type_id::create::(“tx_monitor”,this);
data_out_tx = new(“data_out_tx”,this);
endfunction
function void connect();
tx_monitor.tx_data.connect(this.data_out_tx);
endfunction
endclass

While compiling the above setup; I got ERROR:“NULL pointer dereference” pointing the connect method inside the agent class.
Can anyone help me to overcome the above issue?

Hi,

build phase works top down, means while agent build() execute the monitor build() still didn’t execute and tx_data still didn’t instantiate.

to solve it move the connect lines to the connect phase()

function void connect();
  tx_monitor.tx_data.connect(this.data_out_tx);
endfunction : connect

Thanks,
-Nadav

In reply to nyutal:

I didn’t get you.

The code above shows that the connect lines are in connect phase only.

In reply to mahesh_424:

oops,

for some reason i didn’t see its already in connect()…

sorry,
-Nadav

not sure if you showed all code.
All ports connection need to connect to a “imp” port which provides the put/get/write method.
if the AGENT is your final destination, then you need to give ovm_analysis_imp instead of ovm_analysis_port, otherwise you need have
agent.ovm_analysis_port.connect(xxx.ovm_analysis_imp)
hope it helps
andrew

In reply to aming:

Andrew,

All ports connections need NOT connect to “imp” only. Generally it is “exp”. For the final destination, where “write” function is implemented, it is to be “imp”. Please refer

http://www.verificationacademy.com/uvm-ovm/Ovm/AnalysisPort.

Mahesh, if your problem still present, try the following.

class agent extends ovm_agent;
.......
.......
function void connect();
this.data_out_tx = tx_monitor.tx_data;
endfunction
endclass

As shown above, we can just assign the analysis port of monitor to analysis port of agent, thus not having to create the analysis port of agent again.

then the export you mentioned is “imp” style export.
write a test case is always better to see it.
I see below :
a.blocking_put_port.connect(b.blocking_put_export) → fail
a.blocking_put_port.connect(b.blocking_put_imp) → pass

maybe i got wrong.