Main Content

Check configuration parameters for MISRA C:2012

mathworks.misra.CodeGenSettings

Dependencies: Embedded Coder® and Simulink® Check™

Usage: C/C++ Code Generation and High-Integrity System Modeling

Guideline: hisl_0060: Configuration parameters that improve MISRA C:2012 compliance

Description

Use this check to identify configuration parameters that can impact MISRA C:2012 compliant code generation. Following the recommendations of this check increases the likelihood of generating MISRA C:2012 compliant code for embedded applications.

Recommended Actions and Results

Review the violations that are flagged by the check and the recommended action for fixing the issue. After applying the changes, save the model and rerun the check analysis.

You can use the Fix button to allow the Model Advisor to fix all flagged violations. For this check, the Model Advisor changes the parameter values to the recommended values.

Note

For models with a GRT-based target, the Model Advisor does not update the System target file configuration parameter to an ERT-based system.

The tables list recommended parameter settings based on their location in the Configuration Parameters dialog box.

Math and Data Types

Modeling ConditionRecommended Action

Model configuration parameter Use division for fixed-point net slope computation is not set to On or Use division for reciprocals of integers only.

Set model configuration parameter Use division for fixed-point net slope computation to On or Use division for reciprocals of integers only.

Model configuration parameter Inf or NaN block output is set to None or error and Support: non-finite numbers is set to on.

Model configuration parameter Inf or NaN block output is set to None and Support: non-finite numbers is set to off.

When Support: non-finite numbers (Simulink Coder) is set to on, set Inf or NaN block output to warning.

When Support: non-finite numbers (Simulink Coder) is set to off, set Inf or NaN block output to warning or error.

Model configuration parameter Model Verification block enabling is set to Use local settings or Enable All.Set model configuration parameter Model Verification block enabling to Disable All.
Model configuration parameter Undirected event broadcasts is set to none or warning.Set model configuration parameter Undirected event broadcasts to error.
Model configuration parameter Wrap on overflow is set to None.Set model configuration parameter Wrap on overflow to warning or error.

Hardware Implementation

Modeling ConditionRecommended Action
Model configuration parameter Signed integer division rounds to is set to Undefined.Set model configuration parameter Signed integer division rounds to to Zero or Floor.
Model configuration parameter Shift right on a signed integer as arithmetic shift is selected.Clear model configuration parameter Shift right on a signed integer as arithmetic shift.

Simulation Target

Modeling ConditionRecommended Action
Model configuration parameter Compile-time recursion limit for MATLAB functions is set to a value other than 0.Set model configuration parameter Compile-time recursion limit for MATLAB functions to 0.
Model configuration parameter Dynamic memory allocation in MATLAB functions is selected.Clear model configuration parameter Dynamic memory allocation in MATLAB functions.
Model configuration parameter Enable run-time recursion for MATLAB functions is selected.Clear model configuration parameter Enable run-time recursion for MATLAB functions.

Code Generation

Modeling ConditionRecommended Action

Model configuration parameter Bitfield declarator type specifier is set to uchar_T when any of these parameters are selected:

  • Pack Boolean data into bitfields

  • Use bitsets for storing state configuration

  • Use bitsets for storing Boolean data

Set model configuration parameter Bitfield declarator type specifier (Embedded Coder) to uint_T.
Model configuration parameter Casting modes is not set to Standards Compliant.Set model configuration parameter Casting modes (Embedded Coder) to Standards Compliant.
Model configuration parameter Code replacement library is not set to None or AUTOSAR 4.x.

Set model configuration parameter Code replacement library (Simulink Coder) to None or AUTOSAR 4.x

Model configuration parameter External mode is selected.Clear model configuration parameter External mode (Simulink Coder).
Model configuration parameter Generate shared constants is selected.Clear model configuration parameter Generate shared constants. For more information, see GenerateSharedConstants in Model Configuration Parameters: Code Generation Interface (Simulink Coder).

Model configuration parameter Include comments is cleared.

Select model configuration parameter Include comments (Simulink Coder).
Model configuration parameter MAT-file logging is selected.

Clear model configuration parameter MAT-file logging (Simulink Coder).

For ERT-based target systems, configuration parameter MATLAB user comments is cleared.Select model configuration parameter MATLAB user comments (Embedded Coder).
A value for configuration parameter Maximum identifier length is not provided.Set the value of model configuration parameter Maximum identifier length (Simulink Coder) based on the limits for your implementation. The default value is 31.
Model configuration parameter Parentheses level is not set to Standards (Parentheses for Standards Compliance) or Maximum (Specify precedence with parentheses).Set model configuration parameter Parentheses level (Embedded Coder) to Standards (Parentheses for Standards Compliance) or Maximum (Specify precedence with parentheses).

For ERT-based target systems, configuration parameter Preserve static keyword in function declarations is cleared when File packaging format is set to Compact or Compact (with separate data file).

Select model configuration parameter Preserve static keyword in function declarations (Embedded Coder).
Model configuration parameter Replace multiplications by powers of two with signed bitwise shifts is selected.Clear model configuration parameter Replace multiplications by powers of two with signed bitwise shifts (Embedded Coder).
Model configuration parameter Shared code placement is set to Auto.

Set model configuration parameter Shared code placement (Simulink Coder) to Shared location.

For ERT-based target systems, configuration parameter Support: continuous time is selected.Clear model configuration parameter Support: continuous time (Embedded Coder).
For ERT-based target systems, configuration parameter Support non-inlined S-functions is selected.Clear model configuration parameter Support non-inlined S-functions (Embedded Coder).
Model configuration parameter Suppress generation of default cases for switch statements if unreachable is selected.Clear model configuration parameter Suppress generation of default cases for Stateflow switch statements if unreachable (Embedded Coder).
Model configuration parameter System-generated identifiers is set to Classic.Set model configuration parameter System-generated identifiers (Embedded Coder) to Shortened.
Model configuration parameter System target file is set to a GRT-based target.Set model configuration parameter System target file (Simulink Coder) to an ERT-based target.
Model configuration parameter Use dynamic memory allocation for model initialization is selected when Code Interface Packaging is set to Reusable Function.

Clear model configuration parameter Use dynamic memory allocation for model initialization (Embedded Coder).

Parameter subchecks depend on the results of the parameter noted with D in the results table. When the result status is D-Warning, the Current Value column in the results table reads Prerequisite constraint not met for the subchecks. After you change the parameter, rerun the check.

Note

Some subchecks are specific to configuration parameters for ERT-based systems. These parameters are not updated when you use the Fix button unless you change the model to an ERT-based system.

Capabilities and Limitations

  • Does not review referenced models

  • Does not require model compilation

Version History

Introduced in R2017b