Packages provide a mechanism for storing and sharing data, methods, property, parameters that can be re-used in multiple other modules, interfaces or programs. They have explicitly named scopes that exist at the same level as the top-level module. So, all parameters and enumerations can be referenced via this scope. Putting such definitions and declarations inside a package also avoids cluttering the global namescope. Packages can then be imported into the current scope where items in that package can be used.

Note that items within packages cannot have hierarchical references to identifiers except those created within the package or made visible by the import of another package.


All packages have to be enclosed within the package and endpackage keywords.

package my_pkg;
  typedef enum bit [1:0] { RED, YELLOW, GREEN, RSVD } e_signal;
  typedef struct { bit [3:0] signal_id;
                     bit       active;
                     bit [1:0] timeout; 
                   } e_sig_param;
  function common ();
      $display ("Called from somewhere");
    task run ( ... );

Login to your free account to read more ...

Was this article helpful ?