|
<< Click to Display Table of Contents >> 7.1 Template, Sequencer, and Transaction Calls |
![]() ![]()
|
The template file is a language-specific source code file where both the user and TestBencher insert source code for the Transaction-Level Model. TestBencher generates the Transaction-Level Model code and puts it into macros contained in the template file. The file also contains the Transaction Sequencer which is where transaction Apply and Post calls and most of the other user-written code for the test bench will be added by the user.
Open the Template file to edit the Transaction-Level Model and the Sequencer Process
|
|
Don't write code inside Macro Statements
Source code can be added anywhere in the template file, except for between two macro statements. The macro statements are the locations where TestBencher will place generated code. Each time the bus-functional model is generated, any code within the macro lines is overwritten. An example of a macro keyword pair is:
-- $ComponentInstantiationsForAllDiagrams
-- End $ComponentInstantiationsForAllDiagrams
Writing Code for the Transaction Sequencer
The most common place to add source code is in the sequencer process. This process is the area where diagram calls are placed. You can also write source to define variables, call randomize functions on variables, and define loops and other control structures. You can also write code to place conditions on whether or not a diagram call is made based on information returned from previous transaction calls.
|
//***********************************************************
// Transaction Sequencer - After this comment, define how to
// apply transactions to the model under test using:
Since the sequencer process is outside of any macro statements, code added here will be preserved during the code generation process.
Use the Insert Diagram Subroutine Call dialog to make Transaction Calls:
The fastest way to write Transaction Call statements is to use the Insert Diagram Calls dialog as described in Step 5: Define a Sequencer Process. This dialog will generate diagram apply calls so you do not need to memorize the function syntax. Chapter 11: Language Specific Details has all of the language specific call details.
|

|
Each timing diagram generates the following tasks to run or schedule transactions for that diagram:
|
Master and Slave Transactors
The Master/Slave setting in the Diagram Settings dialog determines how many times a transaction executes (see Section 9.8 Diagram Settings Dialog). Master Transactors run once and stop. Master transactors display as an icon with waveforms in the Insert Diagram dialog. Slave transactors (e.g. a clock generator diagram) run in a looping mode. Slave transactors display as an icon with waveforms and a loop-back arrow to indicate they run repeatedly.
Example of Transaction Sequencer code
The following is a Verilog example of a sequencer process that performs a sweep test on an SRAM. The variable delay0 is defined to be a counter for a For loop. Each time the loop executes, a different delay is passed into the Write and Read cycles of the SRAM. This delay controls the timing of a waveform edge in the Write and Read transaction. Variables could have been defined for the transactions, but we chose to pass in values. The transaction apply calls were written using the Insert Diagram Calls dialog as described above. The user wrote all of the other code in this example.
// Sequencer Process
real delay0; // delay0 will serve as the index and the delay value
initial
begin
for (delay0 = 32.0; delay0 > 5.0; delay0 = delay0 - 5.0)
begin
// Apply_Tbwrite( addr , data , $realtobits(delay0_min) );
Apply_Tbwrite( 'hF0 , 'hAE , $realtobits(delay0) );
// Apply_tbread( addr , data , $realtobits(delay0_min) );
Apply_tbread( 'hF0 , 'hAE , $realtobits(delay0));
end
Abort_tbglobal_clock;
$fclose(logfile);
end
Switching Languages and Template Files
Since the template file is language-specific, if you need to change the generation language for a project after the project has already been created, the template file must also be changed using the technique described in Section 7.8: Changing a Project Template File.
Creating new Template Files
The template file is a copy of a file that was specified in the Project Wizard when the project is first created (Section 9.9: Project Menu and New Project Wizard). Normally you will use the default TestBencher template file, but you can also develop your own templates (this is not generally necessary). When developing your own templates, it is important to copy all of the Macros so that TestBencher will know where to put the generated code.