Showing posts with label from_name. Show all posts
Showing posts with label from_name. Show all posts

Friday, 9 November 2018

Pass enum value from command line in UVM


In verification activity, many times the requirement comes to choose specific value of enum variable from command line in either randomization of transaction class or configuring agent.

System Verilog provides support to pass value of variable of type int/bit/logic/string from command line using $value$plusargs function but it does not direct support to pass value of enum variable from command line.

In earlier version of UVM (uvm 1.1d and prior), we can achieve this by passing string value from command line and manually converting it into enum by writing code in TB.

Let’s go through example how we can achieve this,
-------------------------------------------------------------------------
-------------------------------------------------------------------------


In UVM 1.2 provides inbuilt facility to convert string into enumerated value.
In UVM 1.2 library contains uvm_enum_wrapper#(T) class and this class contains from_name() function.
from_name() function try to convert any string passed as argument into enumerated value.
If any matching enumerated value found then this function returns 1 else it returns 0.
-------------------------------------------------------------------------
-------------------------------------------------------------------------

Let’s go through example,
-------------------------------------------------------------------------
-------------------------------------------------------------------------


In above approach from_name() function can convert only one string at a time.
Now think about scenario where to randomize variable of enum user wants to select from multiple values. But above approach works fine only with one string value.

UVM provides uvm_split_string() function which splits the string based on a delimiter and returns a queue with sub string.
-------------------------------------------------------------------------
-------------------------------------------------------------------------

Now after getting queue of substring from uvm_split_string() function, user can pass one one element of substring queue to from_name() function in some loop and convert it into enumerated value.
Let’s go through example to understand this better,
-------------------------------------------------------------------------
-------------------------------------------------------------------------

Reference: