Block Usage

hisl_0020: Blocks not recommended for MISRA C:2012 compliance

ID: Titlehisl_0020: Blocks not recommended for MISRA C:2012 compliance
Description

To improve MISRA C:2012 compliance of the generated code:

A

Use only blocks that support code generation, as documented in the Simulink® Block Support Table.

BDo not use blocks that are listed as “Not recommended for production code” in the Simulink Block Support Table.
C

Do not use Lookup Table blocks using cubic spline interpolation or extrapolation methods. Specific blocks are:

DDo not use deprecated Lookup Table blocks. The deprecated Lookup Table blocks are Lookup and Lookup2D.
EDo not use S-Function Builder blocks in the model or subsystem.
FDo not use From Workspace blocks in the model or subsystem.
G

Do not use these String blocks in the model or subsystem:

Notes

If you follow this and other modeling guidelines, you can eliminate model constructs that are not suitable for C/C++ production code generation, at the same time, increase the likelihood of generating code that complies with the MISRA C:2012 standard.

Use the Block Support Table block to view the Block Support Table. Blocks with the footnote (4) in the Block Support Table are classified as "Not recommended for production code".

RationaleA, B, C, D, E, F, GImprove quality and MISRA C:2012 compliance of the generated code.
Model Advisor Checks

For A,B,C, D, E, F, and G: Check for blocks not recommended for MISRA C:2012 (Simulink Check)

For A and B: Check for blocks not recommended for C/C++ production code deployment (Simulink Check)

References
  • DO-331, Section MB.6.3.2.b ‘Low-level requirements are accurate and consistent’
    DO-331, Section MB.6.3.2.e ‘Low-level requirements conform to standards’
    DO-331, Section MB.6.3.4.d ‘Source code conforms to standards’

  • 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

Last ChangedR2018b

hisl_0101: Avoid invariant comparison operations to improve MISRA C:2012 compliance

ID: Titlehisl_0101: Avoid invariant comparison operations to improve MISRA C:2012 compliance
Description

To improve MISRA C:2012 compliance of generated code, avoid comparison operations with invariant results. Comparison operations are performed by the following blocks:

  • If

  • Logic

  • Relational Operator

  • Switch

  • Switch Case

  • Compare to Constant

Note

You can use the design error detection functionality in Simulink Design Verifier™ to perform the analysis. For more information, see Dead Logic Detection (Simulink Design Verifier). If you have a Simulink Design Verifier license, you can use Model Advisor check Detect Dead Logic (Simulink Design Verifier).

RationaleImprove MISRA C:2012 compliance of the generated code.
Model Advisor ChecksAdherence to this modeling guideline cannot be verified by using a Model Advisor check.
References
  • MISRA C:2012, Rule 14.3

  • MISRA C:2012, Rule 2.1

Last ChangedR2018a
Example

Invariant comparisons can occur in simple or compound comparison operations. In compound comparison operations, the individual components can be variable when the full calculation is invariant.

Simple: A uint8 is always greater than or equal to 0.

Simple: A uint8 cannot have a value greater than 256

Compound: The comparison operations are mutually exclusive

Stateflow® :

hisl_0102: Data type of loop control variables to improve MISRA C:2012 compliance

ID: Titlehisl_0102: Data type of loop control variables to improve MISRA C:2012 compliance
Description

To improve MISRA C:2012 compliance of generated code, use integer data type for variables that are used as loop control counter variables in:

  • For loops constructed in Stateflow and MATLAB®.

  • For Iterator blocks.

RationaleImprove MISRA C:2012 compliance of the generated code.
Model Advisor ChecksCheck data type of loop control variables (Simulink Check)
References
  • ISO 26262-6, Table 1 (1c) - Enforcement of strong typing

  • MISRA C:2012, Rule 14.1

Last ChangedR2018a