quick.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

   

space.gif

   

space.gif

  ../images/main/bullet_green_ball.gif Hierarchy

Verilog has a simple organization. All data, functions and tasks are in modules except for system tasks and functions, which are global, and can be defined in the PLI. A Verilog module can contain instances of other modules. Any uninstantiated module is at the top level. This does not apply to libraries, which therefore have a different status and a different procedure for analyzing them. A hierarchical name can be used to specify any named object from anywhere in the instance hierarchy. The module hierarchy is often arbitrary and a lot of effort is spent in maintaining port lists.

   

space.gif

An important enhancement in SystemVerilog is the ability to pass any data type through module ports, including nets, and all variable types including reals, arrays, and structures.

   

space.gif

  • Packages containing declarations such as data, types, classes, tasks and functions
  • Nested module declarations, to aid in representing self-contained models and libraries
  • Simplified named port connections, using .name
  • A concept of interfaces to bundle connections between modules
  • Time unit and time precision specifications bound to modules
   

space.gif

   

space.gif

  ../images/main/bulllet_4dots_orange.gif Packages

In Verilog 2001 and 1995, there was no way to share common code (task and function) across modules without using `include compiler directive. Packages provide ways to have common code to be shared across multiple modules. SystemVerilog provides package support to help share following

   

space.gif

  • parameters
  • data
  • type
  • task
  • function
  • sequence
  • property
   

space.gif

Above can be shared across SystemVerilog modules, macromodule interfaces and programs. Few rules that should be followed with packages are.

   

space.gif

  • Packages can not contain any assign statement.
  • Variable declaration assignments within the package shall occur before any initial, always, always_comb, always_latch, or always_ff blocks
  • Items within packages cannot have hierarchical references.
  • Assign statment on any net type is not allowed.
   

space.gif

Accessing data, functions or types in pakages there are two ways.

   

space.gif

  • By class scope resolution operator ::
  • By import statement : The import statement provides direct visibility of identifiers within packages.
   

space.gif

A package is to group a type declaration and a set of tasks or functions that operate on that type. In this scenario, a module could then declare objects of the type and use the package tasks/functions to operate on the object data.

   

space.gif

A package is to define a utility for common use. This sort of package often makes use of persistent state and non-reentrancy in its implementation.

   

space.gif

   

space.gif

Below example shows how to declare a package, how to access members of pakage.

   

space.gif

  ../images/main/bullet_star_pink.gif Example - Package
   

space.gif

   

space.gif


  1 //+++++++++++++++++++++++++++++++++++++++++++++++++
  2 //   Package Declaration
  3 //+++++++++++++++++++++++++++++++++++++++++++++++++
  4 package msgPkg;
  5   integer  errCnt  = 0;
  6   integer  warnCnt = 0;
  7   bit      terminate_on_error = 0;
  8   string   msgName = "NULL";
  9   //=================================================
 10   // Initilizes the messaging
 11   //=================================================
 12   task initMsgPkg (string mName, bit term);
 13     terminate_on_error = term;
 14     msgName = mName;
 15   endtask
 16   //=================================================
 17   // Prints the INFO message
 18   //=================================================
 19   task  msg_info (string msg);
 20     $display ("@%0dns %s INFO : %s",$time,msgName,msg);
 21   endtask 
 22   //=================================================
 23   // Prints the warning message
 24   //=================================================
 25   task  msg_warn (string msg);
 26     $display ("@%0dns %s WARN : %s",$time,msgName,msg);
 27     warnCnt ++;
 28   endtask 
 29   //=================================================
 30   // Prints error message
 31   //=================================================
 32   task  msg_error (string msg);
 33     $display ("@%0dns %s ERROR : %s",$time,msgName,msg);
 34     errCnt ++;
 35     if (terminate_on_error) $finish;
 36   endtask 
 37   //=================================================
 38   // Prints fatal message and terminates simulation
 39   //=================================================
 40   task  msg_fatal (string msg);
 41     $display ("@%0dns %s FATAL : %s",$time,msgName,msg);
 42     $finish;
 43   endtask 
 44   //=================================================
 45   // Returns the error count
 46   //=================================================
 47   function integer getErrCnt();
 48     getErrCnt = errCnt;
 49   endfunction
 50   //=================================================
 51   // Returns the warning count
 52   //=================================================
 53   function integer getWarnCnt();
 54     getWarnCnt = warnCnt;
 55   endfunction
 56 
 57 endpackage
You could download file msgPkg.sv here
   

space.gif


  1 //+++++++++++++++++++++++++++++++++++++++++++++++++
  2 //   Package Declaration
  3 //+++++++++++++++++++++++++++++++++++++++++++++++++
  4 package definesPkg;
  5   //=================================================
  6   // TypeDefs declaration
  7   //=================================================
  8   typedef enum  {FALSE, TRUE} bool;
  9   typedef struct {
 10      bit   [7:0]   addr;
 11      bit   [7:0]   data;
 12      bit           wr;
 13   } mem_s; 
 14 
 15 endpackage
You could download file definesPkg.sv here
   

space.gif

   

space.gif


  1 //=================================================
  2 // Include all the files
  3 //=================================================
  4 `include "msgPkg.sv"
  5 `include "definesPkg.sv"
  6 //=================================================
  7 // Import the Packages
  8 //=================================================
  9 import msgPkg::*;
 10 import definesPkg::bool;
 11 
 12 //+++++++++++++++++++++++++++++++++++++++++++++++++
 13 // DUT Using the package
 14 //+++++++++++++++++++++++++++++++++++++++++++++++++
 15 module simple_package();
 16 
 17 bool   value = definesPkg::FALSE;
 18 
 19 initial begin
 20   msgPkg::initMsgPkg("PACKAGES",0);
 21   msgPkg::msg_info("Testing Packages");
 22    #10  msgPkg::msg_warn("Testing Packages");
 23    #10  msgPkg::msg_error("Testing Packages");
 24   msgPkg::msg_info($psprintf("Warning Count %0d, Error Count %0d",
 25    msgPkg::getWarnCnt(), msgPkg::getErrCnt()));
 26   if (value  ! = definesPkg::TRUE)  
 27      #10  msgPkg::msg_fatal("Value is FALSE");
 28 end
 29 
 30 endmodule
You could download file simple_package.sv here
   

space.gif

  ../images/main/bullet_star_pink.gif Simulation : Package
   

space.gif

 @0ns PACKAGES INFO : Testing Packages
 @10ns PACKAGES WARN : Testing Packages
 @20ns PACKAGES ERROR : Testing Packages
 @20ns PACKAGES INFO : Warning Count 1, Error Count 1
 @30ns PACKAGES FATAL : Value is FALSE
   

space.gif

   

space.gif

   

space.gif

   

space.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

  

Copyright © 1998-2014

Deepak Kumar Tala - All rights reserved

Do you have any Comment? mail me at:deepak@asic-world.com