Skip to main content

SystemVerilog: Mailboxes and Queues

Mailboxes and queues are couple of basic data constructs of system verilog language.
Lets get to the definition of them:

Queue:

A Queue in system verilog function as the name suggests. But with a twist.
Queue in system verilog is a list of similar elements. Queue is built on top of an array.

Delcaration of a queue.
<TYPE> <que_name>[$];
Default Behaviour:
The default size of the queue in system verilog is "Infinite". The above declaration will create a que of infinite length. You can add elements to the que until your simulator crashes :)
What if you want to create a queue of finite length. Just look at the declaration below:
<TYPE> <que_name>[$:<LIMIT>];
The above declaration will create a queue of size "LIMIT+1"

Initializing queue with elements

Accessing elements of a queue

Methods in queue

Inserting elements into queue

Reoving elements from queue

http://www.project-veripage.com/queue_1.php Now some points to ponder
Q. What happens when you pop from empty queue.
Ans. When you pop an empty queue, the result depends on type of the queue.
* When you pop from a queue of prebuilt data types, like integer, bit, real... The return value is '0'.
* When you pop from queue of some class, the result is null object.
Q. What happens when you push into queue which is finite and full.

Comments

Post a Comment

Popular posts from this blog

Verdi Uses - I

COVERAGE While going through some of the blog posts, i found that the Verdi supports even coverage right out of the box, but from the 2014 Version. Well till now, we relied on the URG reports and the DVE to review the coverage and apply waivers and create exclusion files. Looks verdi supports all the features.. I did not get any hands on the features of this option, soon i will find some time to play around with this option of coverage in Verdi. How to launch the verdi with coverage. $> verdi -cov -covdir <PATH_TO_TB>.simv.vdb -covdir <PATH_TO_TEST1>.simv.vdb -covdir <PATH_TO_TEST2>.simv.vdb...  You can pass multiple covdirs, where in all the results will be merged. References: SYNOPSYS SITE Think Verification  

Sequence Layering in UVM

What is Sequence Layering? Sequence layering is refered to as running sequences inside sequences.  So whats the big deal. There are virtual sequences we will use to run multiple sequences. A generic example of sequence layering. you have two sequences  Interrupt sequence register read write sequence. Generally when you have interrupt, we generally enter into interrupt service routine, which can be implemented as an interrupt sequence. So when you run an interrupt sequence, you might end up running register read /write sequence like polling or clearing interrupts. Well thats easy, just run one sequence in another. class top_seq extends uvm_sequence#(txn_item); //Two sequencers say.. sub sequences. sub_seq1 seq1; sub_seq2 seq2; ... task body(); seq1.start(some_seqr); seq2.start(some_seqr2); endtask endclass Killing sequences: That was great you are running nested sequences. But how to kill them when needed. UVM provides m...

Virtual Sequence and Virtual Sequencer in UVM

Virtual sequences and sequencers in UVM are just virtual containers of multiple sequences and sequencers. Using virtual sequencers and sequences can be done in these three ways: Using only virtual Sequence and handles of sequencers inside the virtual sequence. Using Virtual sequencer to hold the sequencers Same as step 2, by using uvm_declare_p_sequencer. Virtual Sequencer does not create any sequencer objects, rather it points to other physical sequencers in different agents.  Virtual Sequencer extends from uvm_sequencer. Virtual sequence will create its sequences and start them. Running sequences can be controlled by user in the body() task. virtual sequence extends from uvm_sequence. METHOD-1: In this method, we will have one base virtual sequence which will hold the handles to different sequencers. Here we dont use any virtual sequencer. We just use the nested seqeunces with handles ot sequencers inside sequence itself. //This is the base virtual se...