Why do the ImportedEx​tern/Impor​tFromFile storage classes generate different initialization code depending on the initial value settings in Real-Time Workshop Embedded Coder 5.3 (R2009a)?

5 views (last 30 days)
When I use an mpt.Signal object with the ImportedExtern/ImportFromFile storage classes, different initialization code is generated depending on the initial value settings.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 8 Jul 2009
When a user defines a storage class as ImportedExtern or ImportFromFile, an external *.h file is required to declare and initialize the signal/parameter. Initialization code is being generated for states with ImportedExtern storage class and nonzero initial values, because we want to ensure the semantics of simulation regardless of the storage class setting. The reason for this is that the user may accidentally initialize values that are different from what the simulation uses, so the behavior of the code might not match the simulation. Initialization code is not required for states with ImportedExtern storage class and zero initial values, because during simulation of the model and the code all signals/states that don’t have an initial value defined are by default initialized to zero.
If the platform that the code is running on initializes uninitialized data to something other than zero, there are a few methods that the customer can use to control the initialization:
1. Set the storage class to ImportedExtern/ImportFromFile, declare and initialize the signal/parameter in the header file, and specify the header file name in the appropriate data object field.
2. Set the storage class to ExportedGlobal and uncheck the Configuration Parameters / Optimization / Data Initialization / Remove internal data zero initialization option
a. If checked, it will not initialize internal data with initial values of zero
b. If unchecked, it will initialize internal data with values of zero
3. Create a custom storage class and use the data initialization field to control the initialization (See Data Initialization section of the Designing Custom Storage Classes and Memory Sections :: Using Custom Storage Classes (Real-TimeWorkshop Embedded Coder) Help documentation)

More Answers (0)

Products


Release

R2009a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!