Documentation

Create PIL Target Connectivity Configuration for金宝app

Target Connectivity Configurations for PIL

Use target connectivity configurations and the target connectivity API to customize processor-in-the-loop (PIL) simulation for your target environments.

Through a target connectivity configuration, you specify:

  • A configuration name for a target connectivity API implementation.

  • Settings that define the set of compatible Simulink®models. For example, the set of models that have a particular system target file, template makefile, and hardware implementation.

A PIL simulation requires a target connectivity API implementation that integrates third-party tools for:

  • Cross-compiling generated code, creating the PIL application that runs on the target hardware.

  • Downloading, starting, and stopping the application on the target.

  • Communicating between Simulink and the target.

你可以有许多不同的目标et connectivity configurations for PIL simulation. Register a connectivity configuration with Simulink by creating ansl_customization.mfile and placing it on the MATLAB®search path.

When you run a PIL simulation, the software determines which of the available connectivity configurations to use. The software looks for a connectivity configuration that is compatible with the model under test. If the software finds multiple or no compatible connectivity configurations, the software generates an error message with information about resolving the problem.

Create a Target Connectivity API Implementation

This diagram shows the components of the PIL target connectivity API.

You must provide implementations of the three API components:

  • Build API — Specify theSimulink Coder™toolchain or template makefile approach for building generated code.

  • Launcher API — Control how Simulink starts and stops the PIL executable.

  • Communications API — Customize connectivity between Simulink and the PIL target. Embedded Coder®provides host-side support for TCP/IP and serial communications, which you can adapt for other protocols.

These steps outline how you create a target connectivity API implementation. The example code shown in the steps is taken fromConnectivityConfig.minConfigure Processor-In-The-Loop (PIL) for a Custom Target.

  1. Create a subclass ofrtw.connectivity.Config.

    ConnectivityConfig < rtw.connectivity.Config

  2. In the subclass:

    • Instantiatertw.connectivity.MakefileBuilder, which configures the build process.

      builder = rtw.connectivity.MakefileBuilder(componentArgs, ... targetApplicationFramework, ... exeExtension);

    • Create a subclass ofrtw.connectivity.Launcher, which downloads and executes the application using a third-party tool.

      launcher = mypil.Launcher(componentArgs, builder);

  3. Configure yourrtiostreamAPI implementation of thehost-target communicationschannel.

    • For the target side, you must provide the driver code for communications, for example, TCP/IP or serial communications. To integrate this code into the build process, create a subclass ofrtw.pil.RtIOStreamApplicationFramework.

    • For the host side, you can use a supplied library for TCP/IP or serial communications. Instantiatertw.connectivity.RtIOStreamHostCommunicator, which loads and initializes the library that you specify.

      hostCommunicator = rtw.connectivity.RtIOStreamHostCommunicator(componentArgs, ... launcher, ... rtiostreamLib);

  4. If you require execution-time profiling of generated code, create a timer object that provides details of the hardware-specific timer and associated source files. SeeSpecify Hardware Timer.

Note

Each time you modify a connectivity implementation, close and reopen the models to refresh them.

Register a Connectivity API Implementation

To register a target connectivity API implementation as a target connectivity configuration in Simulink:

  1. Create or update ansl_customization.mfile. In this file:

    • Create a target connectivity configuration object that specifies, for example, the configuration name for a target connectivity API implementation and compatible models.

    • InvokeregisterTargetInfo.

  2. Add the folder containingsl_customization.mto the search path and refresh your customizations.

    addpath(sl_customization_path); sl_refresh_customizations;

For more information, seertw.connectivity.ConfigRegistry.

Verify Target Connectivity Configuration

To verify your target connectivity configuration early on and independently of your model development and code generation, use the suppliedpiltestfunction. With the function, you can run a suite of tests. In the tests, the function runs various normal, SIL, and PIL simulations. The function compares results and produces errors if it detects differences between simulation modes.

Target Connectivity API Examples

For step-by-step examples, see:

  • Configure Processor-In-The-Loop (PIL) for a Custom Target

    This example shows you how to create a custom PIL implementation using the target connectivity APIs. You can examine the code that configures the build process to support PIL, a downloading and execution tool, and a communication channel between host and target. To activate a full host-based PIL configuration, follow the steps in the example.

  • Create a Target Communication Channel for Processor-In-The-Loop (PIL) Simulation

    This example shows you how to implement a communication channel for use with the Embedded Coder product and your embedded target. This communication channel enables exchange of data between different processes. PIL simulation requires exchange of data between the Simulink software running on your development computer and deployed code executing on target hardware.

    Thertiostreaminterface provides a generic communication channel that you can implement in the form of target connectivity drivers for a range of connection types. The example shows how to configure your own target-side driver for TCP/IP, to operate with the default host-side TCP/IP driver. The default TCP/IP communications allow high-bandwidth communication between host and target, which you can use for transferring data such as video.

    Note

    If you customize thertiostreamTCP/IP implementation for your PIL simulations, you must turn off Nagle's algorithm for the server side of the connection. If Nagle's algorithm is not turned off, your PIL simulations can run at a significantly slower speed. Thematlabroot/toolbox/coder/rtiostream/src/rtiostreamtcpip/rtiostream_tcpip.cfile shows how you can turn off Nagle's algorithm:

    /* Disable Nagle's Algorithm*/ option = 1; sockStatus = setsockopt(lFd,IPPROTO_TCP,TCP_NODELAY,(char*)&option,sizeof(option));
    The code for your custom TCP/IP implementation can require modification.

    示例还显示了如何实现自定义焦油get connectivity drivers, for example, using serial, CAN, or USB for both host and target sides of the communication channel.

See Also

||||||

Related Topics