Products & Services Solutions Academia Support User Community Company

Learn more about Real-Time Workshop Embedded Coder   

Setting Up a Model to Generate Code for Host Simulations and Target Deployment

When configuring a model for SIL simulation with the Real-Time Workshop product and when processor word sizes differ between host and target platforms, you can configure the model to use an emulation hardware option. That option guarantees bit-true agreement for integer and fixed-point operations between host system simulation results and target deployment.

In addition to the emulation hardware option, the Real-Time Workshop Embedded Coder product provides an option for configuring a model to use portable word sizes. Using this second option, you can configure a model to generate code that you can compile without changing it for a platform. You can then use the code for SIL simulation on a host system and for deployment on a target system.

To configure a model to use portable word sizes, set model configuration parameters.

Set...To...
Hardware Implementation > Emulation hardware > NoneSelected
Real-Time Workshop > Interface > Create Simulink (S-Function) blockSelected
Real-Time Workshop > Interface > Enable portable word sizesSelected

When you generate code for a model with the preceding parameter settings, the code generator conditionalizes data type definitions:

For example, in the following generated code, the first two lines define types for SIL simulation on a host system. 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 */

For an example of how to configure a model to maintain bit-true agreement between host simulation and target deployment, and generate code that is portable between the host and target systems, see rtwdemo_sil_pil.

Compiling Generated Code That Supports Portable Word Sizes

When compiling generated code that supports portable word sizes for SIL testing, you need to pass the definition PORTABLE_WORDSIZES to the compiler.

For example:

-DPORTABLE_WORDSIZES

To build the same code for target deployment, compile the code without the PORTABLE_WORDSIZES definition.

Portable Word Sizes Limitation

When performing SIL testing, using the Enable portable word sizes model configuration parameter, numerical results of the S-function simulation on the MATLAB host might differ from results on the actual target. This difference is due to differences in target characteristics, such as:

  


Related Products & Applications

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.

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