Main Content

Check configuration parameters for MISRA C:2012

Check ID: mathworks.misra.CodeGenSettings

Identify configuration parameters that can impact MISRA C:2012 compliant code generation.

Description

Following the recommendations of this check increases the likelihood of generating MISRA C:2012 compliant code for embedded applications.

Available with Embedded Coder® and Simulink® Check™.

Results and Recommended Actions

ConditionRecommended Action
Math and Data Types
Configuration parameter Use division for fixed-point net slope computation is not set to On or Use division for reciprocals of integers only.Set Use division for fixed-point net slope computation to On or Use division for reciprocals of integers only.

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

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 is:

  • on, set Inf or NaN block output to warning

  • off, set Inf or NaN block output to warning or error

Configuration parameter Model Verification block enabling is set to Use local settings or Enable All.Set Model Verification block enabling to Disable All.
Configuration parameter Undirected event broadcasts is set to none or warning.Set Undirected event broadcasts to error.
Configuration parameter Wrap on overflow is set to NoneSet configuration parameter Wrap on overflow to warning or error.
Hardware Implementation
Configuration parameter Production hardware signed integer division rounds to is set to UndefinedSet Production hardware signed integer division rounds to to Zero or Floor.
Configuration parameter Shift right on a signed integer as arithmetic shift is selected.Clear Shift right on a signed integer as arithmetic shift.
Simulation Target
Configuration parameter Compile-time recursion limit for MATLAB functions is set to a value other than 0.Set Compile-time recursion limit for MATLAB functions to 0.
Configuration parameter Dynamic memory allocation in MATLAB functions is selected.Clear Dynamic memory allocation in MATLAB functions.
Configuration parameter Enable run-time recursion for MATLAB functions is selected.Clear Enable run-time recursion for MATLAB functions.
Code Generation

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 Bitfield declarator type specifier to uint_T.
Configuration parameter Casting Modes is not set to Standards Compliant.Set Casting Modes to Standards Compliant.
Configuration parameter Code replacement library is not set to None or AUTOSAR 4.0.

Set Code replacement library to None or AUTOSAR 4.0

Configuration parameter External mode is selected.Clear External mode.
Configuration parameter Generate shared constants is selected.Clear Generate shared constants.

Configuration parameter Include comments is cleared.

Select Include comments.
Configuration parameter MAT-file logging is selected.

Clear MAT-file logging

For ERT-based target systems, configuration parameter MATLAB user comments is cleared.Select MATLAB user comments.
A value for configuration parameter Maximum identifier length is not provided.Set the value to the implementation-dependent limit. The default is 31.
Configuration parameter Parentheses level is not set to Standards(Parentheses for Standards Compliance) or Maximum(Specify precedence with parentheses).Set Parentheses level 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 Preserve static keyword in function declarations.
Configuration parameter Replace multiplications by powers of two with signed bitwise shifts is selected.Clear Replace multiplications by powers of two with signed bitwise shifts.
Configuration parameter Shared code placement is set to Auto.

Set Shared code placement to Shared location

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

Clear Use dynamic memory allocation for model initialization.

Note

Select only when Code Interface Packaging is set to Reusable Function.

Action Results

Clicking Modify All changes the parameter values to the recommended values.

Note

When you click Modify All for models with a GRT-based target, the Model Advisor does not update the System target file configuration parameter to an ERT-based system.

Parameter subchecks depend on the results of the parameter noted with D in the results table. When the result is D-Warning, the Current Value column in the results table states 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 click Modify All unless you change the model to an ERT-based system.

Capabilities and Limitations

Following parameters setting is informational in the check:

  • BooleansAsBitfields

  • CodeInterfacePackaging

  • ERTFilePackagingFormat

  • SupportNonFinite

This check does not review referenced models.

See Also