|
<< Click to Display Table of Contents >> 6.3 Class Methods |
![]() ![]()
|
Class methods are user-defined functions and tasks that let you add HDL algorithms to the timing diagram or bus-functional model. These methods can be added to individual timing diagrams, project Transaction-Level Models, or user-defined classes. Once a class method is added to an object, it shares the same scoping level as the object. It can be called during simulation to perform activities that are difficult to describe graphically.
Scoping Level and Access to Diagram, Project, and Class level methods
Diagram-level class methods, like diagram-level variables, are local to the timing diagram in which they are created. These methods can be accessed using HDL Code Markers and Sample Actions. They are generated in the diagram transaction source file so they share the same scoping level of other diagram-level objects. The code for the methods is stored in the timing diagram file so that the methods are available for other projects (if the diagram is included in multiple projects).
For TestBencher, class-level class methods can be called from the same scoping level as the variable that instantiates the class. These methods are a part of the class definition and are stored in the respective class library. The methods are generated in the class source code definition.
For TestBencher, project-level class methods can be accessed from the Sequencer Process in the TLM file. These methods are specific to the project for which they are defined. The top-level module of the bus-functional model (generated from the top-level template file for the project) contains these methods.
Open the Class Methods dialog from the object that will own the class method:
The Class Methods dialog is used to create and edit user-defined methods. Open the Class Methods dialog from the object that you want to define the class method for:
|
|
|
|
|
|

Create a Class Method and define its type and return type:
Selecting a different class method name changes the contents of the other sections of the dialog.
|
|
|
|
Specify the Parameters for the Selected Class Method:
The parameters represent data that is passed into the method.
|
|
|
|
Add the Source Code for the selected Class Method
The source code is the actual code that will be placed in the generated method definition. This code is written in the generation language. Class Methods can be specified for every licensed language, allowing diagrams, class definitions, and even the Transaction-Level Model to be language independent. Add the class method source code:
|
|
Using Diagram-level Class Methods
|
Using a Project Level Class Method
|
// User Defined Class Methods function integer GetBurstLength; input [2:0] burst; begin ... the source code body endfunction // End $UserDefinedMethods |
|
// Transaction Sequencer - After this comment .... repeat (5) // number of bursts to perform begin ahb_master0.ApplyRandom_idle; writedata.randomize; // randomize all fields burstLength = GetBurstLength(writedata.burst); .... |