NULL mailbox error

I’ve poked around with mailbox questions and haven’t seen this directly addressed. I’ve inherited a testbench that used a lot of mailboxes to pass data around between verification models and the top level testbench. Upon running this I get a few errors like:

Error (suppressible): (vsim-12457) A mailbox method 'put/try_put' is called on a NULL mailbox.

and

Fatal: (vsim-131) <filename> Null instance encoutnered when dereferencing 'axi_mst_mb'

Is this a case where the mailbox variable has not yet been created, and yet the code is trying to do something with the mailboxes? If so I need to check for that before actions are taken and at the least I imagine I could just wrap some of these in a if (my_mb) <do mailbox action>;.

If it’s something else though, I suppose I’ll have to have a more elaborate fix.

Is this a case where the mailbox variable has not yet been created, and yet the code is trying to do something with the mailboxes?

I believe it is.

Try

if( mb != null ) begin
  // Call Mailbox APIs here
end

For the AXI one I discovered two things. Unlike the other mailboxes, that one did not have an initial value of new(). Typo or oversight I believe. I also added wait (mb); in the process that was using that one (it was an initial block) and between the two all mailbox errors have disappeared. I might take away the wait – I have a sneaking suspicion it was the lack of new().

I also added wait (mb);

An interesting use of wait statement.

I tried using it in my sample code where I observe that the wait unblocks only when I call mb.new(..)

If it’s never created, it ( wait statement ) will remain blocked.

Well that’s what it’s for as far as I know waiting until the expression evaluates as a logical true. Non-null is boolean true so wait will be satisfied.

That said, seems like the new() by itself was the complete solution, the other is just unnecessary waiting in this particular testbench. Onwards to the next issue!

FWIW, a class variable is not a Boolean expression. Better to write.

wait(mb != null)

Which I also think makes the intent clearer.

1 Like