Verifying Generated Code with Software-in-the-Loop

Overview

Real-Time Workshop Embedded Coder software provides software-in-the-loop (SIL) code verification for subsystems using ERT S-function wrappers, described in Automatic S-Function Wrapper Generation. When processor word sizes differ between host and target platforms (for example, a 32-bit host and a 16-bit target), there are two ways to configure your Simulink model to simulate target behavior on the MATLAB host with SIL:

Select the hardware emulation method if you need to guarantee bit-true agreement for integer and fixed-point operations between the results of simulations run on the MATLAB host computer and the results of generated code executed on the target deployment system. In this case, the code that you generate for simulation on the MATLAB host might contain additional code, such as data type casts, that is necessary to ensure behavior consistent with the target environment.

See also Configuring Optimizations in the Real-Time Workshop documentation for settings in the Code generation subpane of the Optimization pane that affect the generated code. After SIL testing on the MATLAB host, you must select None for Emulation hardware and then regenerate code for the target before deployment.

Select the portable word sizes method if you want to generate code that can be compiled without alteration both for SIL testing on the MATLAB host computer and deployment on the target system. In this case, the code that you generate has conditional processing macros that allow you to first compile for the host platform, using the compiler option -DPORTABLE_WORDSIZES, and then compile for the target platform, omitting the option.

To illustrate both methods of configuring your model to simulate target behavior on the MATLAB host, The MathWorks provides the demo model rtwdemo_sil. The demo allows you to simulate the same model using each method, and to compare model configuration settings and results.

Validating Generated Code on the MATLAB Host Computer Using Hardware Emulation

Real-Time Workshop Embedded Coder software provides Emulation hardware settings that support code generation for host-target configurations in which the processor word sizes differ between host and target platforms (for example, a 32-bit host and a 16-bit target). Selecting MATLAB Host Computer as the Emulation hardware device type allows you to generate model code with any additional code, such as data type casts, that is necessary to ensure behavior on the MATLAB host computer that is consistent with the target environment.

To use this feature, go to the Emulation hardware subpane of the Hardware Implementation pane of the Configuration Parameters dialog box, clear the None option if it is selected, select Generic as the Device vendor if it is not already selected, and select MATLAB Host Computer as the Device type. Also, go to the Interface pane, select Create Simulink (S-Function) block, and make sure that Enable portable word sizes is cleared.

You can then right-click the subsystem that you want to test on the MATLAB host, and select Real-Time Workshop > Build Subsystem to build it. This will generate an S-function wrapper for the generated subsystem code, which can be used on the host to verify that the generated code provides the same result as the original subsystem.

For an example of SIL testing using hardware emulation, see rtwdemo_sil.

Validating ERT Production Code on the MATLAB Host Computer Using Portable Word Sizes

The Real-Time Workshop Embedded Coder software provides a model configuration option, Enable portable word sizes, that supports code generation for host-target configurations in which the processor word sizes differ between host and target platforms (for example, a 32-bit host and a 16-bit target). Selecting the Enable portable word sizes option allows you to generate code with conditional processing macros that allow the same generated source code files to be used both for SIL testing on the host platform and for production deployment on the target platform.

To use this feature, select both Create Simulink (S-Function) block and Enable portable word sizes on the Interface pane of the Configuration Parameters dialog box. Also, make sure that Emulation hardware is set to None on the Hardware Implementation pane.

When you generate code from your model, data type definitions are conditionalized such that tmwtypes.h is included to support SIL testing on the host platform and Real-Time Workshop types are used to support deployment on the target platform. For example, in the generated code below, the first two lines define types for host-based SIL testing and the bold lines define types for target deployment:

#ifdef PORTABLE_WORDSIZES    /* PORTABLE_WORDSIZES defined */
# include "tmwtypes.h"
#else                        /* PORTABLE_WORDSIZES not defined */
#define __TMWTYPES__
#include <limits.h>
...
typedef signed char int8_T;
typedef unsigned char uint8_T;
typedef int int16_T;
typedef unsigned int uint16_T;
typedef long int32_T;
typedef unsigned long uint32_T;
typedef float real32_T;
typedef double real64_T;
...
#endif                       /* PORTABLE_WORDSIZES */

To build the generated code for SIL testing on the host platform, the definition PORTABLE_WORDSIZES should be passed to the compiler, for example by using the compiler option -DPORTABLE_WORDSIZES. To build the same code for target deployment, the code should be compiled without the PORTABLE_WORDSIZES definition.

For an example of SIL testing using portable word sizes, see rtwdemo_sil.

Portable Word Sizes Limitations

The following limitations apply to performing SIL testing using the Enable portable word sizes model configuration parameter.

  


 © 1984-2008- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS