Documentation

Stateflow Chart Considerations

hisf_0064: Shift operations for Stateflow data to improve code compliance

ID: Titlehisf_0064: Shift operations for Stateflow® data to improve code compliance
DescriptionTo improve code compliance of the generated code with Stateflow bit-shifting operations, do not perform:
A

Right-shift operations greater than the bit-width of the input type, or by a negative value.

B

Left-shift operations greater than the bit-width of the output type, or by a negative value.

Note

If you follow this and other modeling guidelines, you increase the likelihood of generating code that complies with the coding standards.

RationaleA,BTo avoid shift operations in the generated code that might be a coding standard violation.
Model Advisor Checks
  • By Task > Modeling Standards for DO-178C/DO-331 > Check usage of shift operations for Stateflow data

  • By Task > Modeling Standards for IEC 61508 > Check usage of shift operations for Stateflow data

  • By Task > Modeling Standards for IEC 62304 > Check usage of shift operations for Stateflow data

  • By Task > Modeling Standards for EN 50128 > Check usage of shift operations for Stateflow data

  • By Task > Modeling Standards for ISO 26262 > Check usage of shift operations for Stateflow data

For DO-178C/DO-331 check details, see Check usage of shift operations for Stateflow data.

For IEC 61508, IEC 62304, EN 50128, and ISO 26262 check details, see Check usage of shift operations for Stateflow data.

References
  • DO-331 Section MB.6.3.1.b 'High-level requirements are accurate and consistent'
    DO-331 Section MB.6.3.2.b 'Low-level requirements are accurate and consistent'

  • IEC 61508–3, Table A.3 (2) Strongly typed programming language
    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 (1c) Enforcement of strong typing
    ISO 26262-6, Table 1 (1d) Use of defensive implementation techniques

  • EN 50128, Table A.4 (8) Strongly Typed Programming Language
    EN 50128, Table A.3 (1) Defensive Programming

Prerequisiteshisl_0060: Configuration parameters that improve MISRA C:2012 compliance
Last ChangedR2017b

hisf_0065: Type cast operations in Stateflow to improve code compliance

ID: Titlehisf_0065: Type cast operations in Stateflow to improve code compliance
DescriptionTo improve code compliance of the generated code, protect against Stateflow casting integer and fixed-point calculations to wider data types than the input data types by:
A

Using the := notation in Stateflow charts that use the C action language

Note

If you follow this and other modeling guidelines, you increase the likelihood of generating code that complies with the coding standards.

RationaleATo avoid implicit casts in the generated code that might be a coding standards violation.
Model Advisor Checks
  • By Task > Modeling Standards for DO-178C/DO-331 > Check type cast operations in Stateflow

  • By Task > Modeling Standards for IEC 61508 > CCheck type cast operations in Stateflow

  • By Task > Modeling Standards for IEC 62304 > Check type cast operations in Stateflow

  • By Task > Modeling Standards for EN 50128 > Check type cast operations in Stateflow

  • By Task > Modeling Standards for ISO 26262 > Check type cast operations in Stateflow

For DO-178C/DO-331 check details, see Check assignment operations in Stateflow charts.

For IEC 61508, IEC 62304, EN 50128, and ISO 26262 check details, see Check assignment operations in Stateflow charts.

References
  • DO-331 Section MB.6.3.1.b 'High-level requirements are accurate and consistent'
    DO-331 Section MB.6.3.2.b 'Low-level requirements are accurate and consistent'

  • IEC 61508–3, Table A.3 (2) Strongly typed programming language
    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 (1c) Enforcement of strong typing
    ISO 26262-6, Table 1 (1d) Use of defensive implementation techniques

  • EN 50128, Table A.4 (8) Strongly Typed Programming Language
    EN 50128, Table A.3 (1) Defensive Programming

Prerequisiteshisl_0060: Configuration parameters that improve MISRA C:2012 compliance
Last ChangedR2017b

hisf_0211: Protect against use of unary operators in Stateflow Charts to improve code compliance

ID: Titlehisf_0211: Protect against use of unary operators in Stateflow Charts to improve code compliance
DescriptionTo improve code compliance of the generated code:
A

Do not use unary minus operators on unsigned data types

Note

The MATLAB® and C action languages do not restrict the use of unary minus operators on unsigned expressions.

RationaleAImprove code compliance of the generated code.
Model Advisor Checks
  • By Task > Modeling Standards for DO-178C/DO-331 > Check type cast operations in Stateflow

  • By Task > Modeling Standards for IEC 61508 > CCheck type cast operations in Stateflow

  • By Task > Modeling Standards for IEC 62304 > Check type cast operations in Stateflow

  • By Task > Modeling Standards for EN 50128 > Check type cast operations in Stateflow

  • By Task > Modeling Standards for ISO 26262 > Check type cast operations in Stateflow

For DO-178C/DO-331 check details, see Check Stateflow charts for unary operators.

For IEC 61508, IEC 62304, EN 50128, and ISO 26262 check details, see Check Stateflow charts for unary operators.

References
  • DO-331 Section MB.6.3.1.b 'High-level requirements are accurate and consistent'
    DO-331 Section MB.6.3.2.b 'Low-level requirements are accurate and consistent'

  • IEC 61508–3, Table A.3 (2) Strongly typed programming language
    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 (1c) Enforcement of strong typing
    ISO 26262-6, Table 1 (1d) Use of defensive implementation techniques

  • EN 50128, Table A.4 (8) Strongly Typed Programming Language
    EN 50128, Table A.3 (1) Defensive Programming

  • MISRA C:2012, Rule 10.1

Last ChangedR2017b

hisf_0213: Protect against divide-by-zero calculations in Stateflow charts to improve MISRA C:2012 compliance

ID: Titlehisf_0213: Protect against divide-by-zero calculations in Stateflow charts to improve MISRA C:2012 compliance
DescriptionTo improve MISRA C:2012 compliance of the generated code for floating point and integer-based operations, do one of the following:
A

Perform static analysis of the model to prove that division by zero is not possible

B

Provide run-time error checking in the generated C code by explicitly modeling the error checking in Stateflow

C

Modify the code generation process using Code Replacement Libraries (CRLs) to protect against division by zero

D

For integer-based operations, in the Configuration Parameters dialog box, on the Optimization pane, clear Remove code that protects against division arithmetic exceptions

Note

Using run-time error checking introduces additional computational and memory overhead in the generated code. It is preferable to use static analysis tools to limit errors in the generated code. You can use Simulink® Design Verifier™ or Polyspace® Code Prover™ to perform the static analysis.

If static analysis determines that sections of the code can have a division by zero, then add run-time protection into that section of the model (see example). Using a modified CRL or selecting the parameter Remove code that protects against division arithmetic exceptions protects division operations against divide-by-zero operations. However, this action does introduce additional computational and memory overhead.

Use only one of the run-time protections (B, C or D) in a model. Using more than one option can result in redundant protection operations.

RationaleA,B,
C,D
Improve MISRA C:2012 compliance of the generated code
References
  • MISRA C:2012, Dir 4.1

See Also
Last ChangedR2015b
Example

Run-time divide by zero protection can be realized using a graphical function. Unique functions should be provided for each data type.

Was this topic helpful?