SYSTEM VERILOG LABS # WEEK1
DAY#1
- GVIM
- Install GVIM
- What is GVIM, how is it different from Microsoft Word, Notepad?
- How to open a file using GVIM?
- How to enable syntax in GVIM for Verilog and SV files?
- https://www.vim.org/scripts/script.php?script_id=1586
- Download verilog_systemverilog.tar.gz
- $HOME below will be C:/Program files/VIM (similar path)
- Untar the package verilog_systemverilog.tar.gz
Copy verilog_systemverilog/ftdetect/verilog_systemverilog.vim to your $HOME/.vim/ftdetect directory.
Copy verilog_systemverilog/syntax/verilog_systemverilog.vim to your $HOME/.vim/syntax directory.
Copy verilog_systemverilog/indent/* to your $HOME/.vim/indent directory
- How to work with GVIM effectively?
- https://www.youtube.com/watch?v=TWBgScnFurw (Starts from 49th min)
- https://www.youtube.com/watch?v=NPtLV_hqomI (Advanced GVIM usage)
- GVIM Labs
- https://www.vlsiguru.com/unix-labs/
- Step#6, Step#11,12,13,14,15
- www.edaplayground.com
- https://www.youtube.com/watch?v=A1qhavaVlnw
- EDA Playground Labs
- www.edaplayground.com
- Make note : design.sv, testbench.sv
- What are those windows?
- What is + symbol for?
- Lab
- Develop mux2x1 Verilog code in design.sv
- Develop TB for mux2x1 in testbench.sv with different inputs at various times
- Run the same using edaplayground
- Now observe the waveforms
- How to enable waveforms in edaplayground?
- System Verilog Basics
- How System Verilog differs from Verilog?
- What are the new language constructs added?
- What is Object Oriented Programming?
- Why it is important concept in Testbench setup
- Modularity and reusablity
- What is design?
- What is testbench?
- What is the code written in to testbench?
- Design & Testbench example
- Implement 2X1 Mux using Gates
- Write the testbench for 2X1 Mux
- Apply various inputs and notice the waveform
DAY2. (Trainer will cover all below topics in further sessions, we are covering this as basic lab session before OOP based labs)
This session will introduce you to basic data types that will be used in OOP sessions. These topics will be covered by the trainer in depth during main theory sessions(around 6th session of the course)
- Before starting this lab session, you should be comfortable with using edaplayground.com or Questasim tool.
- How to declare various Arrays (this will be used in next set of questions)
- Fixed size array; int intA[fixed_number];
- Dynamic array; int intDA[]; //no number passed
- intDA= new[size_we_want];
- Queue; int intQ[$];
- Mailbox mbox;
- packed array of logic : logic [3:0] logicVec; //dimension on LHS is packed array
- Unpacked array of logic: logic logicArr[3:0]; //dimension on RHS
- Data types
- Integer, int, byte, bit, logic
- Integer: signed, 4 state variable (0,1,x,z)
- Int: signed, 2 state variable (used for quicker simulation performance)
- Byte : signed 8 bit, 2 state
- Bit : unsigned, 2 state
- Logic: unsigned, 4 state
- Arrays (based on when memory is allocated)
- Packed arrays
- Memory is allocated in to single address location
- Ex: bit [3:0] bitvar; //4 bits stored in 1 address location
- Unpacked arrays
- Memory is allocated in to multiple address locations
- Ex: integer intArr[4:0]; //5 address locations
- Arrays (based on how memory is allocated)
- Fixed size arrays
- Memory allocation is fixed at compile time
- Ex: integer intArr[4:0]; //5 locations are allocated at compile time
- Dynamic arrays
- Memory allocation happens at run time
- Ex: integer intDA[]; //memory is not allocated at compile time, it is allocated at run time using intDA = new[5] or new[10], etc, 5/10 being the size to allocate.
LABS:
- Data types
- Understand the difference between integer and
int
- Integer is 4 state, int is 2 state
- Display integer will give ‘x’, int will ‘0’
- Understand the difference between byte and bit
- Byte can store negative values
- Bit can only store unsigned (+) numbers
- Understand the difference between logic and bit
- Logic is 4 state 1bit
- Logic variables can store x,z
- Bit is 2 state 1 bit
- Bit variables can only store 0,1
- For all above declare some variables of above
data types, print their default values and assigned some x & z based
values, print those values.
Arrays
- Declare integer a ,b
- Assign a and b with random values between
10,20 display both the a,b
- Use $urandom_range min,max.
- Declare packed array of bit, array name as c of
size 5-bits
- Assign c with mix of x and z values (ex: 5’b01x0z )
- Display c value
- Notice that bit vector does not store x and z
- Declare packed array of logic, array name as d of
size 5-bits
- Assign d with mix of x and z values (ex: 5’b01x0z )
- Display d value
- Notice that logic vector does not store x and z
- Compare c and d(bit and logic), display the comparison
output
- Difference between integer and int
- Assign integer with x and z values
- Assign int variables with x and z value
- Display both the variables
- Notice int variable will be store x and z as 0.
- Assign a random negative number between -50 or
-70.
- Display both the value
- Notice both the value printed negatively
- int is a 2 state signed variable and integer is
a 4-state signed variable
- Unpacked arrays
- Declare int unpacked array
- Declare fixed size array of int data type int
size is 5.
- Initialize all the random values between 50 ,100
- Display all the values
- Display all using %p to, display packed format
- Used %d to display all the value use foreach
- Using for loop to display
- Declare one more integer array of size 5 int
data type, assign random value between 10,20 for each element
- Compare both the array using foreach
- Compare both the array using for loop
- Copy first array content to second array using
for loop
- Compare first array content to second array
using for loop
- Declare bit unpacked array compare and print
assign a random value of 2bit variables
- Dynamic arrays
- To create dynamic array use array=new[size]
- Declare int dynamic array, int data type
- Initialize all the random values between 50 ,100
- Display all the values
- Display all using %p to, display packed format
- Used %d to display all the value use foreach
- Using for loop to display
- Declare one more dynamic array of size 5 int
data type, assign random value between 10,20 for each element
- Compare both the array using foreach
- Compare both the array using for loop
- Copy first array content to second array using
for loop
- Compare first array content to second array
using for loop
- Resize the
first array to 10 elemeet , while
retaining the existing 5 elements
- intDA = new[10] (intDA); //this is why it is called dynamic array
- it retains existing 5 elements
- Now print array contents using %p
- Queues
- Declare a Queue of integer data type
- Integer intQ[$];
- intQ does not indicate Q, $ is what indicates it
is a Queue
- Fill Queue with the random values between 50
,100
- Display all the values
- Display all using %p to, display packed format
- Used %d to display all the value use foreach
- Using for loop to display
- Declare one more Queue of size 5 int data type, assign
random values between 10,20
- Integer intQ[$:4]; //this is a Queue of maximum size 5
- Compare both the queue elements using foreach
- Compare both the queue elements using for loop
- Copy first queue elements to second Queue using for
loop
- Compare first queue elements to second queue
elements using for loop
- Mailbox
- Declare a mailbox of int data type
- Allocate memory to mailbox
- Fill 5 integers in to mailbox using put method
- Get above integers using get method
- Print the values
- Summary
- Arrays
- Fixed size array; int intA[fixed_number];
- Dynamic array; int intDA[]; //no number passed
- intDA= new[size_we_want];
- Queue; int intQ[$];
- Mailbox mbox;
DAY3
Revision:
- Different data types
- Logic, Bit, reg, wire
- Int, Integer
- Different arrays
- Based on how memory is allocated
- Packed arrays
- Unpacked arrays
- Based on when memory is allocated
- Fixed size arrays
- Dynamic arrays
Questions:
- Where do we use Dynamic arrays?
- Hint: when packet size is variable, ex: ethernet
- Where do we use logic?
- Where do we use bit?
- When the variable will not require to take 4
state values, bit improves simulation performance.
- How packed arrays are different from unpacked
arrays?
- What are the various in-built methods
implemented for Queues?
- What are the various in-built methods
implemented for Dynamic arrays?
- What are the various in-built methods for
mailbox?
- When we use mailbox with allocated memory to its
handle, what will happen
- Declare queue of byte data type with maximum
size of 15
- Tool related questions
- What is compilation?
- What is elaboration?
- What is library in tool?
- What is significance of work library?
LABS:
- Declare a Queue of integers, Dynamic array of integers,
copy the elements of dynamic array to Queue. Print both the elements to confirm
if copy is done properly
- How to print all elements: $display(“intQ=%p”,intQ);
- Declare a Dynamic array of integer data type
- Integer intDA[];
- Try to put random number in to intDA without
doing new to array
- What error do you get?
- Declare a mailbox
- Try to put a number in to mailbox without doing
memory allocation to mailbox handle
- Notice the error
- Declare a Queue of integer data type
- Try to push back a number in to Queue without
doing memory allocation to Queue handle
- Do you get any error?
- Hint: Queue does not require to use new, it is
automatically allocated
- Function
- Declare a function (with output argument)
- Name: sum
- Input: 2 integers
- Output: integer (sum of above 2 numbers)
- Output is returned as function argument
- Declare an array of integers (size 5) : intA1
- Declare another array of integers (size 5) : intA2
- Use above sum function to add integers from 2
arrays and put in to 3rd array : intA3
- Declare a function (with return value of
function)
- Implement above example, with function sum
returning value as a function return (not as output argument)
- Write a function to print fabanicy series
- Implementing FIFO using Queue(DO NOT USE CLASS
FOR FIFO IMPLEMENTATION)
- Declare a module FIFO
- Declare a Queue of integers of size 10
- Implement two methods: put, get
- Put : push_back integer in to Queue
- Get: pop_front integers from Queue
- This module FIFO can be now used as a FIFO
- Instantiate FIFO module in to module top
- Put 10 random numbers in to FIFO(using put
method) and get those numbers from FIFO(using get method), print those.
- Implementing Stack using Queue
- How stack is different from FIFO?
- Declare a module FIFO
- Declare a Queue of integers of size 10
- Implement two methods: put, get
- Put : push_back integer in to Queue
- Get: pop_back integers from Queue
- This module FIFO can be now used as a FIFO
- Instantiate FIFO module in to module top
- Put 10 random numbers in to FIFO(using put
method) and get those numbers from FIFO(using get method), print those.
Class, OOP
- Different stages of class usage
- Definition: Defining class
- Instantiation: Instantiate object of the class
- Creation: allocating memory
- Declaring a class named eth_pkt
- Fields: count, len, payload, crc
- Declare module top
- Declare an object of eth_pkt
- In initial block, assign a value to pkt.count
- You will get error, what does it indicate? How to
fix this?
- Print all the pkt fields using %p
- Notice all fields are printed in Decimal format
DAY4
- Revision
- How to working with different types arrays,
mailbox and queues
- Declaring function and calling the function
- Declare implementing FIFO and stack using queue
- Various queue dynamic array methods
- Questions
- What is function new in class
- What is %p in $display
- Class is a dynamic constraints or static
constraints
- What is the difference between FIFO and stack
- What is the difference between function in Verilog
and system Verilog
- What is the default function argument (int:
function sum (int a,int b))
- Agenda
- Class
- Object
- Fields
- New
- Constraints
- Print
- Copy
- Compare
- Pack
- Unpack
LABS
- Four stages of class definition, initialization,
creation, randomization
- Different types of methods (copy, compare, print,
pack, unpack)
- Implement print function
- Function print implementation
- Declare function print
- Print all the fields
- In different radix formats
- Notice payload is printed empty
- Function new
- Constraints
- Compare method
- Copy method
- Pack method
- Unpack method
- Pack and unpack examples
- Unpack byteQ to another packet
- Compare packet1 and packet2
- Array of ethernet packets