Script_Language_Interface > SystemC
Block Name: TLM_Cosim
Code File Location: VisualSim/interfaces/systemC/TLM_Cosim
Note: The file name and file path for the SystemC file must not contain '_" and numbers.
The TLM_Cosim block is used to import and utilize an existing SystemC TLM 2.0 module in VisualSim. Once the block has been configured, it can connect to any other block in the Block Diagram Editor. The TLM_Cosim blocks can contain timing and wait statements. One instance of the SC_Sim block is required to configure the SystemC model attributes, setup the connection between the VisualSim and SystemC simulator and transfer time/data on the interface.
VisualSim, SystemC and TLM maintain different payload classes. This block supports the seamless transfer of Generic Payload and the VisualSim data structure.
All SystemC and TLM blocks in the model are stored as a single dynamic library (.dll or .so).
The block supports the communication of parameters from the GUI to the SystemC and for mapping fields from the VisualSim data structure to the Generic Payload.
SystemC (sc_in and sc_out) and TLM interfaces (non-blocking sockets) are currently supported and transfered across the graphical wires. Direct Memory Interface is handled directly between the blocks.
Additional model level parameters are provided for information required by the compiler. To look at these parameters, right-click on the white space and select Configure.
Before starting to use the TLM_Cosim block, review the TLM 2.0 example.
The TLM_Cosim block accepts VisualSim packets at a initiator, target or sc_in port and sends it into the TLM code via TLM 2.0 socket connection. Any output from SystemC socket or sc_out is sent to the VisualSim port and links to the rest of the system.
If the socket is a initiator/target then the names must match the specified format. No name restriction exists for the sc_in/sc_out ports. VisualSim communicates between blocks using the ports. The connection between VisualSim ports highlight the connection but do not have timing or power information. Data arriving on the VisualSim graphical port is transfered to TLM 2.0 sockets or SystemC sc_in ports in the VisualSim code. The port names are defined in VisualSim using the Context Menu Configure->Ports of the TLM_Cosim block.
VisualSim and SystemC designs can maintain their own data structures with independent set of fields. The SystemC Generic Payload has full access to the VisualSim data structure that triggered it and can read/write to fields. A pre-built block called the Initiator_TLM is provided in the SystemC library folder. This block is used to construct and destroy the Generic Payload and is typically placed on the interface between a VisualSim source and the SystemC interconnect. This block can be extended to add logic associated with specific return, status and phase combination.
Once the TLM_Cosim block has been configured, the block can be connected up to the full system. Constructor parameters are defined in the SC_Module_Name parameters. If the SystemC module requires access to a field of the VisualSim data structure, a struct is defined at the interface and the value becomes available in the SystemC code.
Methods have been provided for accessing parameters and to read/write to VisualSim data structures.
Once all the SystemC blocks have been placed on the diagram editor and connections are made, the user can generate a Wrapper using the Interface->Generate Wrapper. Next the user can select Interface->Compile Wrapper to compile and link this code to the VisualSim simulator. After this, connections and parameter values can be modified for every simulation without recompiling.
The blocks do not have special identifier to distinguish betwen initiator, interconnect and target.
Before using VisualSim TLM_Cosim block, make sure the following attributes have been :
JAVA_HOME: Make sure the JAVA_HOME variable in VisualSim.sh and VisualSim.bat is set to jdk and not jre. BY default, VisualSim only requires jre.
C++ Compiler: Current support is Visual Studio 2008 and g++ 4.0 and higher. This must be set in $VS/VSconfig.Properties file for Windows and $VS/VSConfig_linux.Properties for Linux.
VS_C_Library: This is located in the VisualSim.bat (Windows) and VisualSim.sh (Unix). This is base directory that is included in the PATH environment variable. All SystemC and TLM source code must be located in directory structures within VS_C_Library/SystemC. The folder structure can have any hierarchy. A folder called blocks is automatically added to this directory. All the dynamic libraries that are used to compile the SystemC code are in this library. One dynamic library is created per model and saved in the blocks directory.
TLM_Home: Value has been preset. The Windows path is $VS\\VisualSim\\simulators\\SystemC\\tlm and the Linux path is $VS/VisualSim/simulators/SystemC/tlm. This is set in $VS/VSconfig.Properties file for Windows and $VS/VSConfig_linux.Properties for Linux.
SystemC Home: Compiled versions are provided for both Windows and Linux. The Windows path is $VS\\VisualSim\\simulators\\SystemC\\Win\\systemc-2.2.0 and the Linux path is $VS/VisualSim/simulators/SystemC/Linux/systemc-2.2.0. This is set in $VS/VSconfig.Properties file for Windows and $VS/VSConfig_linux.Properties for Linux.
LIBPATH_OPTIONS: In <VS 10.2>/VS_AR/bin/buildJNISO.sh, make sure the path to the gcc libraries is set correctly. It is set by default to -L/usr/lib/gcc/x86_64-redhat-linux/4.1.1.
Note: The user can provide an alternate SystemC and TLM library path.
SystemC installation - This must be built the first time you use SystemC so that it is customized to your machine/compiler
The SC_Module name is listed in the SC_Module_Name of the block. The instance name is the name on top of the Icon and defined by Right-click on the block and selecting Configure Name. Each instance must have a unique name irrespective of the Hierarchy it is located in. The SC_Module_Name can be the same for multiple blocks.
Block has two parameters and the block name must be set:
SC_Module_Name: Name of the .h file for the SC_Module
SC_File_Path: Path to the SystemC file location
Customize->Configure Name: Name for this instance of the SC_Module.
Constructor Parameters: Users can add constructor parameters to the SC_Module_Name. For example, bus<2,2>.
Users can add any number of parameters to the blocks. These are run-time parameters. To add a parameter, double-click on the block icon and click Add. Enter the name of the parameter and default value. The value of the parameter can be modified for each execution without recompiling. The following methods have been provided to access the parameter values in the SystemC code. For more details on these methods, refer the Initiator block in the TLM example.
To get the parameter from the block icon:
jobject getParameter(const char* _blockName, const char* _fieldName); //get parameter of a block
To extract a standard data type, use the following functions:
bool getBooleanValue(jobject token, bool defaultValue); //get boolean value from token that has been extracted using the above method.
int getIntValue(jobject token, int defaultValue); //get int value from token that has been extracted using the above method.
long getLongValue(jobject token, long defaultValue); //get long value from token that has been extracted using the above method.
double getDoubleValue(jobject token, double defaultValue); //get double value from token that has been extracted using the above method.
char* getStringValue(jobject token); //get String value from token that has been extracted using the above method.
To extract an array, the following sequence must be followed:
Get the array: jobjectArray array = getArrayValue(token); //get the array from token that has been extracted using the above method.
Get the length: int n = getArrayLength(array); //get the length of the above array
Get each value in a loop:
for (int i = 0; i < n; i++) {
jobject element = getArrayElement(array, i); // i is the default data value. This gets each element from the array.
}
For a string array, it will be:
for (int i = 0; i < n; i++) {
jobject element = getArrayElement(array, i); // i is the default data value. This gets each element from the array.
char* s = getStringValue(element);
}
The TLM_Cosim block supports two types of ports- sockets and sc_in/sc_out. The TLM sockets are non-blocking transports and support both forward and backward paths. Blocking ports are supported but have not been extensively tested for this release. The sc_in and sc_out can have any port name. The ports do not have to define a data type on the VisualSim side. The sockets can only have initiator_fw, initiator_bw, target_fw and target_bw as the names. For an interconnect or other ports that have multiple channels, the name is followed by an array with the port number. The port number must start from 0.
The sockets accept Generic Payload with extensions. The sc_in and sc_out support the following data types on the interfaces:
C++ Types |
VisualSim RemoteTypes |
int |
int |
bool |
boolean |
double |
double |
long |
long |
float |
float |
char |
char |
Table 1. Types and equivalent Remote Types in VisualSim
SystemC Data Types |
VisualSim RemoteTypes |
sc_bit |
sc_bit |
sc_logic |
sc_logic |
sc_int |
sc_int |
sc_uint |
sc_uint |
sc_bigint |
sc_bigint |
sc_biguint |
sc_biguint |
sc_bv |
sc_bv |
sc_lv |
sc_lv |
sc_fixed |
sc_fixed |
sc_ufixed |
sc_ufixed |
sc_fix |
sc_fix |
sc_ufix |
sc_ufix |
user structs |
user-defined data structures |
Table 2. SystemC types and their equivalent Remote Types in VisualSim
This is used to define the attributes of the SystemC simulation including the time resolution and stop time. For more information on this block, view the SC_Sim block documentation.
Functions have been provided to Read from and write to the VisualSim Data Structure. The SystemC TLM 2.0 example shows how to read and write to the VisualSim Data Structure.
Input
Read from VisualSim Data Structure at the input port:
First get the Data Structure using:
jobject inputRecord = getInputRecord2(sc_core::sc_object::basename(), "transaction_data"); where transaction_data is the port name.
To get a scalar value, use
int address = getIntField(inputRecord, "A_Address_Min", 0);
int dataLength = getIntField(inputRecord, "A_Bytes", 0);
To get a string value, use
char* cmd = getStringField(inputRecord, "A_Command");
Update
To update a VisualSim data structure, first get the data structure. The trans is the ID for the data structure
jobject transactionRecord = getTransactionRecord(*trans);
To set a string field called UserString:
setStringField(transactionRecord, "UserString", "Processed by RequestThread");
To set an integer type field called A_Address_Min:
setIntField(transactionRecord, "A_Address_Min", trans->get_address());
Output
To send a VisualSim data structure on a non-socket port:
setIntField(inputRecord, "A_Address_Min", value1); // modified for VS standard fields
setIntField(inputRecord, "A_Bytes", value1); // modified for VS standard fields
putDS_record2(sc_core::sc_object::basename(), "status_out", inputRecord); //Send the data structure
Note: For receiving and sending data structure, it is not required for the modeler to define the specific struct for the port interfaces. The port can be defined to send a general. The interface wrapper takes care of the definitions.
The pointer address to the Generic Payload in the Hashmap, phase and wait information are carried along by the VisualSim data structure in three fields:
transaction_id = 824341072L, /*Address */
transaction_phase = 1, /* Pahgse value */
transaction_time = 0L /* Wait value */
The value can be used by the VisualSim to generate other activities or respond to a request/response.
jobject getParameter(const char* _blockName, const char* _fieldName); //get parameter of a block
bool getBooleanValue(jobject token, bool defaultValue); //get boolean value from token
int getIntValue(jobject token, int defaultValue); //get int value from token
long getLongValue(jobject token, long defaultValue); //get long value from token
double getDoubleValue(jobject token, double defaultValue); //get double value from token
char* getStringValue(jobject token); //get String value from token
jobjectArray getArrayValue(jobject token); //get array of tokens from ArrayToken
int getArrayLength(jobjectArray array); //get length array of tokens
jobject getArrayElement(jobjectArray array, int index); //get element from array of tokens
bool getBooleanField(jobject recordToken, const char* _fieldName, bool defaultValue); // get boolean field value from record
int getIntField(jobject recordToken, const char* _fieldName, int defaultValue); //get int field value from record
long getLongField(jobject recordToken, const char* _fieldName, long defaultValue); //get long field value from record
double getDoubleField(jobject recordToken, const char* _fieldName, double defaultValue); //get double field value from record
char* getStringField(jobject recordToken, const char* _fieldName); //get String field value from record
void setBooleanField(jobject recordToken, const char* _fieldName, bool fieldValue); //set boolean field value to record
void setIntField(jobject recordToken, const char* _fieldName, int fieldValue); //set int field value to record
void setLongField(jobject recordToken, const char* _fieldName, long fieldValue); //set long field value to record
void setDoubleField(jobject recordToken, const char* _fieldName, double fieldValue); //set double field value to record
void setStringField(jobject recordToken, const char* _fieldName, const char* _fieldValue); //set String field value to record
jobject fetchTransactionRecord(const char* _inputPortName); // fetch transaction data from input port
jobject getInputRecord(const char* _fullInputPortName); // get record from input port cache
jobject getInputRecord2(const char* _blockName, const char* _inputPortName); // get record from input port cache
jobject getTransactionRecord(tlm::tlm_generic_payload& _payload); // get transaction record from map
tlm::tlm_sync_enum putTransaction(const char* _outputPortName, const char* _txRecordPortName,
tlm::tlm_generic_payload& _payload, tlm::tlm_phase& _phase, sc_core::sc_time& _time); // send transaction record to output port
void releaseTransaction(tlm::tlm_generic_payload& _payload); // release transacrion record from map
void putDS_record(const char* _outputPortName, jobject value); // put RecordToken to output port
void putDS_record2(const char* _blockName, const char* _outputPortName, jobject value); // put RecordToken to output port
When the Generate Wrapper and Compile Wrapper is selected, it operates on all SystemC, C and Verilog blocks in the model.
These additional parameters can be a part of the model. All these parameters can be added to a model by Right-click on the white space and selecting Configure.
User_Properties: This is a parameter available from the GUI but is not used.
Include_Search_Paths: This is added to the bat or sh that is generated as part of the interface. The list can have any number of items. The first item should not have a -I prefix. All other items must have a -I prefix.
Build_Files: This is added to the bat or sh that is generated as part of the interface. The list can have any number of items. The parameter must be setup for Text preference. Each file name must be on a separate line and must be separated by a carriage return.
Header_Files: This is a list of files. These files are added to the vs_intf.h file. The parameter must be setup for Text preference. Each file name must be on a separate line and must be separated by a carriage return.
Compiler_Options: This is added to the bat or sh that is generated as part of the interface. The list can have any number of items.
Link_Options: This is added to the bat or sh that is generated as part of the interface. The list can have any number of items.
When you create these user defined parameters, you need to modify the third line, class to VisualSim.data.expr.StringParameter. This will treat it as a string. When you set it to string, the tool treats the data as within “”.
To make the parameter window into text as opposed to line, click on Preferences and select Text by the side of the relevant parameter.
The SystemC simulator and include files are set, by default, in vsconf.bat. If you are using a modified a SystemC simulator, you modify the file destinations to incorporate your own and discard the pre-shipped version.
This can be used to include additional information needed for the compiler. To look at these parameters, right-click on the white space and select Configure.
Parameter |
Explanation |
Type |
Example |
SC_Module_Name |
This field is used to enter the name of the SystemC or TLM module. This name will appear as block name. |
String |
"SystemC_Module_Name" |
SC_File_Path |
This is the path to the .cpp or .h that contains the SystemC module code. The path can be an absolute or relative to the VisualSim C Interface library location. For example, the VS_C_Library in the VisualSim.bat points to C:/VisualSim/UserNativeC and the SystemC source code is in SystemC/bitmodel within that VS_C_Library. Then this parameter will contain SystemC/bitmodel/bitmodel.h. |
String |
"SystemC_Module_Source_Path" |
Created with the Personal Edition of HelpNDoc: Free EPub and documentation generator