Main Content

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.

RationaleTo avoid shift operations in the generated code that might be a coding standard violation.
Model Advisor ChecksCheck usage of shift operations for Stateflow data (Simulink Check)
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

Prerequisiteshisl_0060: Configuration parameters that improve MISRA C:2012 compliance
Last ChangedR2021a
Examples

Incorrect

Correct

Perform shift operations within the defined range of input and output signals.

Correct

When shift operations are more than the width of input signals, perform the explicit conversion. Since the output can hold the final value, the conversion prevents the output from being written as 0 during code generation.

hisf_0065: Type cast operations in Stateflow to improve code compliance

ID: Titlehisf_0065: Type cast operations in Stateflow to improve code compliance
DescriptionIn Stateflow charts that use the C action language, use the := notation to protect against Stateflow casting integer and fixed-point calculations to wider data types than the input data types.
Note

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

RationaleTo avoid implicit casts in the generated code that might violate coding standards.
Model Advisor ChecksCheck assignment operations in Stateflow Charts (Simulink Check)
References
  • 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
    MISRA C:2012, Rule 12.2

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

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.

RationaleImprove code compliance of the generated code.
Model Advisor ChecksCheck Stateflow charts for unary operators (Simulink Check)
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