This example shows how to use an imported IP-XACT specification with memory map when you generate a SystemC™/TLM component from a Simulink® model with the tlmgenerator target. You can use the tlmgenerator target for either Simulink Coder or Embedded Coder™.
In Simulink, each block input or output is bound point-to-point to another block. In SystemC/TLM, each component communicates through a TLM socket. This socket handles all the incoming and outgoing communication formatted inside TLM transactions. Because each system handles communication differently, you must define a communication interface for the SystemC/TLM component when it is generated from a Simulink model. Depending on the intended use of this SystemC/TLM component, this communication interface could require building a memory map (or address) for each input/output in the component. This memory map may be simple, detailed, or imported from an IP-XACT specification file.
The import IP-XACT option generates a TLM component according to an IP-XACT specification file. In this particular example, the IP-XACT file specified one tlm socket with memory map for the Simulink model inputs, one tlm socket with memory map for the Simulink model outputs, and one tlm socket with memory map for the tunable parameters. Each Simulink model input is bound to its corresponding write register in the first socket. Each output is bound to its corresponding read register in the second tlm socket. Each tunable parameter is bound to its corresponding read/write register in the third tlm socket. When created with this option, the generated TLM component can be used in a virtual platform (VP) as a standalone component in a test bench or it could be attached to a communication channel.
For this example, we use a Simulink model of a FIR filter as the basis for SystemC/TLM generation.
Requirements to run this example:
SystemC 2.3.1 (includes the TLM library)
Note: The example includes a code generation build procedure. Simulink does not permit you to build programs in the MATLAB® installation area. If necessary, change to a working directory that is not in the MATLAB installation area prior to starting any build.
Open the FIR Filter model with imported IPXact (with memory map). Alternatively, execute the following command in the MATLAB command window:
The following model opens in Simulink.
Open the IP-XACT file used by this example in the MATLAB Editor. Alternatively, execute the following command in the MATLAB command window:
The IP-XACT file opens in the MATLAB editor.
With the MATLAB Editor, find the following lines of code (MWMap). These lines indicate that the bus interface Input is to be map on a TLM socket and its memory map contains input, output or parameter mapping information.
The following lines of code (MWMapInput) represent the FIR Filter input_1 mapping on individual register INPUT_REG_1.
Similarly, the following lines of code (MWMapOutput) represent the FIR Filter output_1 mapping on individual register OUTPUT_REG_1.
Similarly, the following lines of code (MWMapParam) represent the FIR Filter parameter coef_11 mapping on individual register COEF_REG_1.
a. In the Configuration Parameters dialog box, select the TLM Generator view in the left-hand pane.
b. In the TLM Mapping tab, under Socket Mapping, select Defined by imported IP-XACT file.
c. Under Import IP-XACT File, browse to the location of the IP-XACT file, as shown in the following image.
Set the remaining TLM Generation options according to your preferences (or leave the default values as they are) and click OK to apply these settings and exit the Configuration Parameters dialog box.
In the model window, right-click on the DualFilter block and select C/C++ Code > Generate Code for this Subsystem. This option starts the TLM component generation. Alternatively you can execute the following command in the MATLAB command window:
TLM generation is completed when the following message appears in the MATLAB command window:
### Starting Simulink Coder build procedure for model: DualFilter ### Successful completion of Simulink Coder build procedure for model: DualFilter
Open the following file in the MATLAB Editor:
Using MATLAB Editor, find the following lines of code. These lines represent the input and output definitions of the FIR Filter when generated as a TLM component with no memory map.
To provide a set of input to the generated TLM component, a TLM initiator should send two write TLM transactions at the Input socket:
one with a payload containing a data of type INPUT_REG_1_T at the address INPUT_REG_1_ADDR.
one with a payload containing a data of type INPUT_REG_2_T at the address INPUT_REG_2_ADDR.
To obtain a set of output from the generated TLM component, an TLM initiator should send three read TLM transactions at the Output socket::
one with a payload containing a data of type OUTPUT_REG_1_T at the address OUTPUT_REG_1_ADDR.
one with a payload containing a data of type OUTPUT_REG_2_T at the address OUTPUT_REG_2_ADDR.
To modify the generated TLM component tunable parameter coef_11, a TLM initiator should send a write TLM transaction with no address at the Config socket and with a payload containing a datum of type COEF_REG_1_T at the address COEF_REG_1_ADDR.