Main Content

Code Generation

hisl_0052: Configuration Parameters > Code Generation > Optimization > Data initialization

ID: Titlehisl_0052: Configuration Parameters > Code Generation > Optimization > Data initialization
Description

Explicitly initialize variables for models that are configured with these model configuration parameter settings:

  • System target file set to an ERT-based system target file other than autosar.tlc

  • Code interface packaging is set to Nonreusable function or Reusable function.

For these models, you can configure code generation that completely defines data and initializes internal and external data to zero by clearing these model configuration parameters:

  • Remove root level I/O zero initialization

  • Remove internal data zero initialization

Notes
  • If the target environment provides mechanisms to initialize I/O and state variables, consider using the target environment initialization mechanism instead of clearing the Remove root level I/O zero initialization and Remove internal data zero initialization parameters.

  • If a model is configured with a data code interface:

    • For data that is mapped to a storage class that has imported data scope, Simulink selects Remove root level I/O zero initialization parameter. Imported data is not defined by the generated code and zero initialization of such data is the responsibility of the target environment.

    • For data that is mapped to a storage class with exported data scope, clear the Remove root level I/O zero initialization parameter.

  • If a model is configured to use a service code interface, Simulink selects the Remove root level I/O zero initialization parameter for root-level inports and outports that are mapped to a service interface configured with the outside-execution or during-execution data communication method. The target environment defines the data for communication and is responsible for initialization. If a service interface is configured to use direct access the data communication method, the code generator applies storage classes, which results in data interface behavior.

RationaleSupport fully defined data in generated code.
Model Advisor ChecksCheck safety-related optimization settings for data initialization (Simulink Check)
References
  • DO-331, Section MB.6.3.3.b 'Software architecture is consistent’

  • IEC 61508-3, Table A.4 (3) 'Defensive Programming’

  • IEC 62304, 5.5.3 - Software Unit acceptance criteria

  • ISO 26262-6, Table 1 (1d) 'Use of defensive implementation techniques'


    Table 6 (1c) 'Initialization of variables'

  • EN 50128, Table A.3 (1) 'Defensive Programming'

See Also

Information about these parameters in the Simulink® documentation:

Last ChangedR2024a

hisl_0053: Configuration Parameters > Code Generation > Optimization > Remove code from floating-point to integer conversions that wraps out-of-range values

ID: Titlehisl_0053: Configuration Parameters > Code Generation > Optimization > Remove code from floating-point to integer conversions that wraps out-of-range values
Description

To support verifiable code, select configuration parameter Remove code from floating-point to integer conversions that wraps out-of-range values

Notes

Avoid overflows as opposed to handling them with wrapper code.

For blocks whose Saturate on integer overflow configuration parameter is cleared, deselecting Remove code from floating-point to integer conversions that wraps out-of-range values can add code that wraps out of range values, resulting in unreachable code that cannot be tested.

RationaleSupport generation of code that can be verified.
Model Advisor ChecksCheck safety-related optimization settings for data type conversions (Simulink Check)
References
  • DO-331, Section MB.6.3.1.g 'Algorithms are accurate’
    DO-331, Section MB.6.3.2.g 'Algorithms are accurate’

  • IEC 61508-3, Table A.4 (3) 'Defensive Programming’

  • IEC 62304, 5.5.3 - Software Unit acceptance criteria

  • ISO 26262-6, Table 1 (1d) 'Use of defensive implementation techniques'

  • EN 50128, Table A.3 (1) 'Defensive Programming'

  • MISRA C:2012, Rule 2.1

  • INT32-C. Ensure that operations on signed integers do not result in overflow

See AlsoRemove code from floating-point to integer conversions that wraps out-of-range values (Simulink Coder) in the Simulink documentation
Last ChangedR2021b

hisl_0054: Configuration Parameters > Code Generation > Optimization > Remove code that protects against division arithmetic exceptions

ID: Titlehisl_0054: Configuration Parameters > Code Generation > Optimization > Remove code that protects against division arithmetic exceptions
Description

To support the robustness of the operations, clear configuration parameter Remove code that protects against division arithmetic exceptions.

Note

Avoid division-by-zero exceptions. If you clear Remove code that protects against division arithmetic exceptions, the code generator produces code that guards against division by zero for fixed-point data.

This configuration parameter is applicable only when the System target file is an ERT-based target.

RationaleProtect against divide-by-zero exceptions for fixed-point code.
Model Advisor ChecksCheck safety-related optimization settings for division arithmetic exceptions (Simulink Check)
References
  • DO-331, Section MB.6.3.1.g 'Algorithms are accurate’
    DO-331, Section MB.6.3.2.g 'Algorithms are accurate’

  • IEC 61508-3, Table A.3 (3) 'Language Subset’
    IEC 61508-3 Table A.4 (3) 'Defensive Programming’

  • IEC 62304, 5.5.3 - Software Unit acceptance criteria

  • ISO 26262-6, Table 1(1b) 'Use of language subsets'
    ISO 26262-6, Table 1(1d) 'Use of defensive implementation techniques'

  • EN 50128, Table A.4 (11) 'Language Subset'
    EN 50128, Table A.3 (1) 'Defensive Programming'

  • MISRA C:2012, Dir 4.1

  • INT33-C. Ensure that division and remainder operations do not result in divide-by-zero errors

See AlsoRemove code that protects against division arithmetic exceptions (Embedded Coder) in the Simulink documentation
Last ChangedR2024a

hisl_0056: Configuration Parameters > Code Generation > Optimization > Optimize using the specified minimum and maximum values

ID: Titlehisl_0056: Configuration Parameters > Code Generation > Optimization > Optimize using the specified minimum and maximum values
DescriptionTo support verifiable code, clear configuration parameter Optimize using the specified minimum and maximum values.
NotesSelecting Optimize using the specified minimum and maximum values can result in requirements without associated code and violates traceability objectives.
RationaleSupport traceability between a model and generated code.
Model Advisor ChecksCheck safety-related optimization settings for specified minimum and maximum values (Simulink Check)
References
  • DO-331 Section MB.MB.6.3.4.e 'Source code is traceable to low-level requirements’'

  • IEC 61508-3, Table A.4 (3) 'Defensive Programming’

  • IEC 62304, 5.5.3 - Software Unit acceptance criteria

  • ISO 26262-6, Table 1 (1d) 'Use of defensive implementation techniques

  • EN 50128, Table A.3 (1) 'Defensive Programming'

See also
Last ChangedR2018b

hisl_0038: Configuration Parameters > Code Generation > Comments

ID: Titlehisl_0038: Configuration Parameters > Code Generation > Comments
Description

In the Configuration Parameters dialog box, on the Code Generation > Comments pane, select these parameters:

A

Include comments (Simulink Coder).

B

Simulink block comments (Simulink Coder).

C

Show eliminated blocks (Simulink Coder).

D

Verbose comments for 'Model default' storage class (Simulink Coder).

E

Requirements in block comments (Embedded Coder).

F

Stateflow object comments (Simulink Coder)

G

MATLAB source code as comments (Simulink Coder)

RationaleA

Including comments provides good traceability between the code and the model.

B

Including comments that describe the code for blocks provides good traceability between the code and the model.

C

Including comments that describe the code for blocks eliminated from a model provides good traceability between the code and the model.

D

Including the names of parameter variables and source blocks as comments in the model parameter structure declaration in model_prm.h provides good traceability between the code and the model.

E

Including requirement descriptions assigned to Simulink blocks as comments provides good traceability between the code and the model.

F

Including Stateflow® object comments provides good traceability between the code and the model.

GIncluding MATLAB® source code as comments provides good traceability between the code and the model.
Model Advisor ChecksCheck safety-related code generation settings for comments (Simulink Check)
References
  • DO-331, Section MB.6.3.4.e 'Source code is traceable to low-level requirements‘

  • IEC 61508-3, Table A.3 (3) 'Language subset’

  • IEC 62304, 5.5.3 - Software Unit acceptance criteria

  • ISO 26262-6, Table 1 (1e) 'Use of well-trusted design principles'

  • EN 50128, Table A.4 (11) 'Language Subset'

See AlsoModel Configuration Parameters: Comments (Embedded Coder)
Last ChangedR2024a - Added configuration parameters Stateflow object comments (Simulink Coder) and MATLAB source code as comments (Simulink Coder).

hisl_0039: Configuration Parameters > Code Generation > Interface

ID: Titlehisl_0039: Configuration Parameters > Code Generation > Interface
Description

For models used to develop high-integrity systems, in the Configuration Parameters dialog box, on the Code Generation > Interface pane, set the Software environment, Code interface, and Data exchange interface parameters as follows:

A

Clear Support: non-finite numbers.

B

Clear Support: continuous time.

C

Clear Support: non-inlined S-functions.

D

Clear Classic call interface.

E

Select Single output / update function.

F

Clear Terminate function required.

G

Select Remove error status field in real-time model data structure.

H

Clear MAT-file logging.

RationaleA

Support for non-finite numbers is not recommended for real-time safety-related systems.

B

Support for continuous time is not recommended for real-time safety-related systems.

C

Support for non-inlined S-functions requires support of non-finite numbers, which is not recommended for real-time safety-related systems.

D

To eliminate model function calls compatible with the main program module of the pre-2012a GRT target that is not recommended for real-time safety-related systems; use an ERT based target instead.

E

To simplify the interface to the real-time operating system (RTOS) and simplify verification of the generated code by creating a single call to both the output and update functions.

F

To eliminate model_terminate function, which is not recommended for real-time safety-related systems.

G

To eliminate extra code for logging and monitoring error status that might not be reachable for testing.

H

To eliminate extra code for logging test points to a MAT file that is not supported by embedded targets.

Model Advisor ChecksCheck safety-related code generation interface settings (Simulink Check)
References
  • DO-331, Section MB.6.3.1.c 'High-level requirements are compatible with target computer’
    DO-331, Section MB.6.3.2.c ‘Low-level requirements are compatible with target computer

  • IEC 61508-3, Table A.3 (3) 'Language subset’

  • IEC 62304, 5.5.3 - Software Unit acceptance criteria

  • ISO 26262-6, Table 1 (1b) 'Use of language subsets'

  • EN 50128, Table A.4 (11) 'Language Subset'

See AlsoModel Configuration Parameters: Code Generation Interface (Embedded Coder)
Last ChangedR2023b

hisl_0047: Configuration Parameters > Code Generation > Code Style

ID: Titlehisl_0047: Configuration Parameters > Code Generation > Code Style
Description

In the Configuration Parameters dialog box, on the Code Generation > Code Style pane, set these parameters:

A

Set Parentheses level (Embedded Coder) to Standards(Parentheses for Standards Compliance) or Maximum(Specify precedence with parentheses).

B

Select Preserve operand order in expression (Embedded Coder).

NoteThese configuration parameters are available when configuration parameter System target file (Simulink Coder) is set to ert.tlc.
RationaleA

To prevent unexpected results.

B

To improve traceability of the generated code.

Model Advisor ChecksCheck safety-related code generation settings for code style (Simulink Check)
References
  • DO-331, Section MB.6.3.1.c 'High-level requirements are compatible with target computer’
    DO-331, Section MB.6.3.2.c ‘Low-level requirements are compatible with target computer
    DO-331, Section MB.6.3.4.e ‘Source code is traceable to low-level requirements’

  • IEC 61508-3, Table A.3 (3) 'Language subset’

  • IEC 62304, 5.5.3 - Software Unit acceptance criteria

  • ISO 26262-6, Table 1 (1b) 'Use of language subsets'

  • EN 50128, Table A.4 (11) 'Language Subset'

  • MISRA C:2012, Rule 12.1

See AlsoModel Configuration Parameters: Code Style (Embedded Coder)
Last ChangedR2019b

hisl_0049: Configuration Parameters > Code Generation > Identifiers

ID: Titlehisl_0049: Configuration Parameters > Code Generation > Identifiers
DescriptionTo minimize the likelihood that parameter and signal names will change during code generation when the model changes, set configuration parameter Minimum mangle length to 4 or greater.
Rationale

Decrease the effort to perform code review.

Model Advisor ChecksCheck safety-related code generation identifier settings (Simulink Check)
References
  • DO-331, Section MB.6.3.4.e ‘Source code is traceable to low-level requirements’

  • IEC 61508-3, Table A.3 (3) 'Language subset’

  • IEC 62304, 5.5.3 - Software Unit acceptance criteria

  • ISO 26262-6, Table 1 (1b) 'Use of language subsets'

  • EN 50128, Table A.4 (11) 'Language Subset'

See AlsoModel Configuration Parameters: Code Generation Identifiers (Embedded Coder)
Last ChangedR2021a

hisl_0074: Configuration Parameters > Diagnostics > Modeling issues related to variants

ID: Titlehisl_0074: Configuration Parameters > Diagnostics > Modeling issues related to variants
DescriptionSet these configuration parameters to error:
  • Arithmetic operations in variant conditions

  • Variant condition mismatch at signal source and destination

RationaleTo maintain a consistent behavior between the simulation and generated code and to prevent the creation of unused variables in generated code.
Model Advisor ChecksCheck safety-related diagnostic settings for variants (Simulink Check)
References
  • DO-331, Section MB.6.3.2.b 'Low-level requirements are accurate and consistent'

  • IEC 61508–3, Table A.4 (7) 'Use of trusted / verified software modules and components'

  • MISRA C:2012, Rule 2.2

  • ISO 26262-6, Table 1 (1c) 'Enforcement of strong typing'

    ISO 26262-6, Table 1 (1f) 'Use of unambiguous graphical representation'

    ISO 26262-6, Table 1 (1e) 'Use of well-trusted design principles'

See Also
Last ChangedR2021b

hisl_0075: Usage of library links

ID: Titlehisl_0075: Usage of library links
DescriptionTo maintain a consistent behavior between the simulation and generated code, avoid Disabled library links and Parameterized library links in the model.
RationaleTo avoid unintended simulation results.
Model Advisor ChecksCheck for disabled and parameterized library links (Simulink Check)
References
  • DO-331, Section MB.6.3.2.b 'Low-level requirements are accurate and consistent'

  • DO-331, Section MB.6.3.3.b ‘Software architecture is consistent’

  • IEC 61508-3, Table A.3 (3) 'Language subset'

  • IEC 62304, 5.5.3 - Software Unit acceptance criteria

  • ISO 26262-6, Table 1 (1b) 'Use of language subsets'

  • ISO 26262-6, Table 1 (1f) 'Use of unambiguous graphical representation'

  • EN 50128, Table A.4 (11) 'Language Subset'

Last ChangedR2022a
Examples

Recommended:

It is recommended to use masked library links to change the parameter values inside the library blocks instead of creating the parameterized library links.

Changing the gain value on masked parameter in the model doesn’t create the parameterized links.

Not Recommended:

Changing the gain value using set_param in the command window cause parameterized library link. This would cause unintended behavior.