100%(1)1 out of 1 people found this document helpful
This preview shows page 24 - 29 out of 32 pages.
•hierarchical references to imported identifiers are allowed as if they are defined in the importing scope•Explicit import like a local declaration•multiple identical allowedmodule my_design ();my_global_stuff_pkg::traffic_stop_t my_traffic_stop;module my_design ();import my_global_stuff_pkg::*;Advanced Hardware Design & VerificationSystemVerilog
[Verification] Data-Types(classes_pkg.sv) for a De-BouncerComplete Examplepackage classes_pkg;classPushButton;// Class Propertiesrand bit [31:0] delay;constraintc_delay {delay > 20; // Delay is > than 20 nsdelay < 7000000;} // Delay is < 7 msfunctionnew ( );delay = 0;endfunctionendclass: PushButtonendpackage: classes_pkg[email protected]26module key_bfm (clk, reset, key);outputkey;inputreset, clk;// Import Classesimport classes_pkg::*;// Define local Variablesreg key;PushButton key_obj;task push_button( );time delay;beginkey_obj.randomize ( );delay = key_obj.delay;key = 1'b1;#delay key = 1'b0;endendtaskinitialbeginkey = 1'b0;key_obj = new ( ); endendmodule : key_bfmAdvanced Hardware Design & VerificationSystemVerilog
[Verification] Data-TypesUser-Defined Structuresstructtypedefstruct{inthw_grade_1;inthw_grade_2;inthw_grade_1;inthw_grade_2;inthw_grade_5;} hw_grades_s;Suppose you want to group variables into a block or a structure. you can do so by using a structkeyword. It’s functionality is similar to that of other programming languages. Structure and union declarations follow the C syntax, but without the optional structure tags before the ‘{‘.It is recommended that you start appending your new variables with their associated type. For example, we use the postfix “_s” to indicate a structuredata type.struct{ bit[7:0] opcode; bit[23:0] addr; } IR; // anonymous structure// defines variable IRIR.opcode = 1; // set field in IR.We can define struts' that areuser-defined data-types.We can create a variable structure.[email protected]27Advanced Hardware Design & VerificationSystemVerilog
[Verification] Data-TypesConstantsExample Code and explanation[email protected]28initial beginconstbytecolon = “:”;...endPages:61Aconstformofconstantdiffersfromalocalparamconstant inthatthelocalparammustbesetduringelaboration,whereasaconstcanbesetduringsimulation,suchas in an automatic task.[SVLRM]initial begin...