Monday, November 24, 2014

Learn System Verilog Through Examples - 2: Functions

Here is a small code snippet to understand how functions work in System Verilog. There are multiple ways of calling a function and we can even pass an entire array to the function and process it. Since it passed through reference, no need to do copy business once processing is done inside the function.


int g=100; //this is variable is global in scope with static life time

module test;
  int value1;
  int abc[10] = {0,1,2,3,4,5,6,7,8,9};
  int i;
 
  initial begin;
    f1(); //calls function with the default input value of 10 as per func definition
    f1(5);
   
    value1 = f2();
    $display("Returned value from Function f2 -- Global Value value1: %d",value1);
   
    //Discard the return value
    //Interested in printing or the sub calls from this function
    void'(f2());
   
    //Passing an array to the function
    f3(abc);
    
    foreach (abc[i])
      $display("After updating array abc from function Item: %d is %d",i,abc[i]);
   
    f3(abc);
   
  end
endmodule

function f1(int a=10);//another way of clear declaration is function void f1(int a=10)
  static int b;
  $display("From Function f1 -- This is a function printing passed input: %d",a);
  $display("From Function f1 -- Value of static variable b is %d",b);
  b++;
endfunction

function int f2();
  return (++g);
endfunction

//function has to be declared automatic for passing array through reference
function automatic void f3(ref int a[10]);
  static int i;
 
  $display("From Automatic function f3 - Value of static variable i is %d",i);
 
  i=0;
 
  foreach (a[i])
    begin
      $display("From Automatic function f3 array a at location: %d is %d",i,a[i]);
      a[i] = a[i]+1;
    end
  i = 10;

endfunction

Thursday, November 20, 2014

Learn System Verilog Through Examples - 1: Use of enum


Examples always help to understand the concept, especially end to end cases that one can go through. Let's start with the first example on the enum. In the below example especially note the casting command...


typedef enum {RED,BLUE,GREEN} COLOR;
enum {MON,TUE=5,WED} DAY;

module test;
  string message = "Hello !";
  COLOR in_color,out_color;

                initial begin
      DAY = TUE;
      $display("OUT1: %s",message);
      $display("OUT2: %s",in_color.name);
      $display("OUT3: %d",DAY);

      in_color++;
      out_color = in_color;
      $display("OUT4: %s %d",out_color.name,out_color);

      //Following assignment is wrong
      //COMPILER ERROR: Assignment to enum variable from expression of different type.
      //in_color = 2;

      $cast(in_color,2);
      $display("OUT5: %s",in_color.name);

    end
endmodule

# KERNEL: OUT1: Hello !
# KERNEL: OUT2: RED
# KERNEL: OUT3:           5
# KERNEL: OUT4: BLUE           1

# KERNEL: OUT5: GREEN

Monday, November 10, 2014

Verification resources - edaplayground is an addition to it

It is a world of sharing and support. People are contributing and benefiting from forums and communities. Platforms are open to help each other and all these always help to learn and clear doubts easily&quickly.  It is not different for the VLSI verification community too. The important resources available online are,

https://verificationacademy.com/
www.verificationguild.com/
www.specman-verification.com/
www.asic-world.com/
http://digitalverification.blogspot.in/
http://www.coolverification.com/
http://whatisverification.blogspot.in/

But VLSI industry is always expensive, with the costly tools. There are some basic freewares and evaluation versions of softwares available, but they always lack in supporting important features that we always wanted to try. But recently there is a big relief to this problem, there is a new and easy way to quickly try your solution or play with code snippets, just by editing from a web browser.
www.edaplayground.com gives you a GUI to edit your code, compile, run, dump wave forms (EPWave )and save the whole setup for sharing or future reference. EDA play ground support verilog, SV, OVM and UVM. 

Documentation for edaplayground is available at http://edaplayground.readthedocs.org/en/latest/intro.html