Generate SystemVerilog DPI Component

Step 1. Select Target

  1. Open your model, and select Simulation > Model Configuration Parameters.

  2. Select the Code Generation pane.

  3. At System target file, under Target Selection, click Browse. Select systemverilog_dpi_grt.tlc from the list.

    • Alternatively, if you have an Embedded Coder® license, you can select target systemverilog_dpi_ert.tlc. This target enables you to access its additional code generation options on the Code Generation pane of the Model Configuration Parameters dialog box.

Step 2. Select Toolchain

Still on the Code Generation pane, select a Toolchain. To generate a shared library for the same operating system as the host machine, select a compiler from the list of installed compilers or select Automatically locate an installed toolchain. To use the compiler included with the HDL simulator, or to generate a component for a different operating system, or to generate an HDL simulator project rather than a shared library, select an HDL simulator and your target operating system.

For cross-platform generation, select Package code and artifacts to generate a .zip file to port the generated files to the target machine. See Generate Cross-Platform DPI Components.

You can optionally add additional compilation flags. Under Build Configuration, select Specify. To display the current flags, click Show Settings.

Step 3. Enable Test Point Access (Optional)

Complete this step if you designated internal signals in your model as test points and want to access them in the generated DPI component.

  1. In the left pane, select Code Generation > Interface.

  2. In the Generate C API for section, verify that the signals check box is selected.

  3. Select Code Generation > SystemVerilog DPI.

  4. For Generate access function to test point, select One function per Test Point or One function for all Test Points.

See SystemVerilog DPI Component Test Point Access.

Step 4. Configure SystemVerilog Generation Options

  1. In the left pane, select Code Generation > SystemVerilog DPI.

  2. To generate a test bench, select Generate test bench. The test bench checks the generated C component against data vectors from your Simulink® subsystem.

  3. In the SystemVerilog Ports section:

    • Select the SystemVerilog data types. (optional)

    • Specify Port list or Interface for Connection.

    • Select Structure for Composite data types. This option creates SystemVerilog struct data types for any nonvirtual buses or for complex data types. Alternatively, select Flattened to create flattened ports.

  4. Click OK to accept these settings and to close the Configuration Parameters dialog box.

Step 5. Generate SystemVerilog DPI Component

  1. In your model, right-click the block containing the subsystem you want to generate the component from and set the subsystem as atomic:

    1. Click the subsystem.

    2. Select Block Parameters (Subsystem).

    3. Select Treat as atomic unit.

  2. Select Code > C/C++ Code > Build Selected Subsystem.

  3. Click Build.

    The SystemVerilog component is generated as subsystem_build/subsystem_dpi.sv, where subsystem is the name of the subsystem from which you generated the DPI component. This build also results in a generated package file named subsystem_build/subsystem_dpi_pkg.sv, which includes all the function declarations for the component.

If you built the component for the host machine, you can now use the component. To copy the built component to another machine with the same operating system, copy these files:

  • Shared library, subsystem.so, or subsystem.dll

  • Generated SystemVerilog wrapper, subsystem.sv

  • Generated SystemVerilog package file, subsystem_pkg.sv

  • Generated test bench folder, dpi_tb (optional)

To port the component to another machine with a different operating system, follow the instructions in Generate Cross-Platform DPI Components.

Related Topics