9. QGen Constraints on Input Models¶
9.1. Simulink Version¶
The QGen toolset is compatible with MATLAB and Simulink versions R2009b and newer.
9.2. Simulink Block Types and Constraints¶
This section lists the Simulink block types supported by QGen and details the constraints under which they are supported. This information is organised in the following sections:
9.2.1. Supported Simulink Block Types (alphabetically)¶
9.2.2. Supported Simulink Block Types (by library)¶
9.2.2.1. Discontinuities¶
Link to MathWorks documentation: Discontinuities
Block Type | Constraints |
---|---|
Backlash | None |
Dead Zone | None |
Hit Crossing | Hit Crossing Constraints |
Rate Limiter | None |
Relay | None |
Saturation | Saturation Constraints |
Saturation Dynamic | None |
Wrap To Zero | Wrap To Zero Constraints |
9.2.2.2. Discrete¶
Link to MathWorks documentation: Discrete
9.2.2.3. Logic and Bit Operations¶
Link to MathWorks documentation: Logic and Bit Operations
9.2.2.4. Lookup Tables¶
Link to MathWorks documentation: Lookup Tables
9.2.2.5. Math Operations¶
Link to MathWorks documentation: Math Operations
Block Type | Constraints |
---|---|
Abs | None |
Assignment | Assignment Constraints |
Bias | None |
Complex to Real-Imag | None |
Gain | None |
Math Function | Math Function Constraints |
Matrix Concatenate | None |
MinMax | None |
Permute Dimensions | None |
Product | Product Constraints |
Real-Imag to Complex | None |
Reshape | None |
Rounding Function | None |
Sign | None |
Sqrt | None |
Sum | Sum Constraints |
Trigonometric Function | Trigonometric Function Constraints |
Unary Minus | None |
Vector Concatenate | None |
9.2.2.6. Model Verification¶
Link to MathWorks documentation: Model Verification
Block Type | Constraints |
---|---|
Assertion | None |
9.2.2.7. Ports and Subsystems¶
Link to MathWorks documentation: Ports and Subsystems
Block Type | Constraints |
---|---|
Action Port | None |
Atomic Subsystem | None |
CodeReuse Subsystem | None |
Enable | None |
Enabled Subsystem | None |
Enabled and Triggered Subsystem | None |
For Each | For Each Constraints |
For Each Subsystem | For Each Subsystem Constraints |
For Iterator | For Iterator Constraints |
For Iterator Subsystem | None |
Function-Call Generator | Function-Call Generator Constraints |
If | None |
If Action Subsystem | None |
Inport | Inport Constraints |
Model | None |
Model Variants | Model Variants Constraints |
Outport | Outport Constraints |
Subsystem | None |
Switch Case | None |
Switch Case Action Subsystem | None |
Trigger | None |
Triggered Subsystem | None |
While Iterator | None |
While Iterator Subsystem | None |
9.2.2.8. Signal Attributes¶
Link to MathWorks documentation: Signal Attributes
Block Type | Constraints |
---|---|
Bus to Vector | None |
Data Type Conversion | Data Type Conversion Constraints |
Data Type Duplicate | Data Type Duplicate Constraints |
IC | None |
Rate Transition | None |
Signal Conversion | None |
Signal Specification | Signal Specification Constraints |
Width | None |
9.2.2.9. Signal Routing¶
Link to MathWorks documentation: Signal Routing
Block Type | Constraints |
---|---|
Bus Assignment | None |
Bus Creator | Bus Creator Constraints |
Bus Selector | None |
Data Store Memory | Data Store Memory Constraints |
Data Store Read | None |
Data Store Write | None |
Demux | Demux Constraints |
From | None |
Goto | None |
Goto Tag Visibility | None |
Merge | Merge Constraints |
Multiport Switch | Multiport Switch Constraints |
Mux | Mux Constraints |
Selector | Selector Constraints |
Switch | None |
Vector Concatenate | None |
9.2.2.10. Sinks¶
Link to MathWorks documentation: Sinks
9.2.2.11. Sources¶
Link to MathWorks documentation: Sources
Block Type | Constraints |
---|---|
Clock | None |
Constant | None |
Digital Clock | None |
Ground | None |
Inport | Inport Constraints |
Uniform Random Number | Uniform Random Number Constraints |
9.2.2.12. User-Defined Functions¶
Link to MathWorks documentation: User-Defined Functions
Block Type | Constraints |
---|---|
Fcn | None |
S-Function | S-Function Constraints |
9.2.2.13. Model-Wide Utilities¶
Link to MathWorks documentation: Model-Wide Utilities
Block Type | Constraints |
---|---|
DocBlock | DocBlock Constraints |
Model Info | Model Info Constraints |
9.2.3. Simulink Block Constraints¶
9.2.3.1. 1-D Lookup Table¶
Links to Mathworks Documentation
Block Type | Library |
---|---|
1-D Lookup Table | Lookup Tables |
QGen Usage Constraints
- Flat and Linear interpolation methods are supported. Nearest and Cubic spline methods are not supported.
- Clip and Linear extrapolation methods are supported. Cubic spline method is not supported.
- Table dimensions higher than 2 are not supported.
- Ceiling, Floor, Simplest and Nearest integer rounding methods are supported. Convergent, Round and Zero are not supported.
9.2.3.2. 2-D Lookup Table¶
Links to Mathworks Documentation
Block Type | Library |
---|---|
2-D Lookup Table | Lookup Tables |
QGen Usage Constraints
- Flat and Linear interpolation methods are supported. Nearest and Cubic spline methods are not supported.
- Clip and Linear extrapolation methods are supported. Cubic spline method is not supported.
- Table dimensions higher than 2 are not supported.
- Ceiling, Floor, Simplest and Nearest integer rounding methods are supported. Convergent, Round and Zero are not supported.
9.2.3.3. Assignment¶
Links to Mathworks Documentation
Block Type | Library |
---|---|
Assignment | Math Operations |
QGen Usage Constraints
- The maximum number of input ports is four
- Higher than 2-dimensional input data is not supported
9.2.3.4. Bus Creator¶
Links to Mathworks Documentation
Block Type | Library |
---|---|
Bus Creator | Signal Routing |
QGen Usage Constraints
- Bus objects are not supported for virtual buses. When creating a virtual bus make sure the BusObject / Output Data Type field is empty.
- Bus objects are mandatory for non-virtual buses and the names of the incoming signals must match the names defined in the bus object.
9.2.3.5. Compare To Zero¶
Links to Mathworks Documentation
Block Type | Library |
---|---|
Compare To Zero | Logic and Bit Operations |
QGen Usage Constraints
- The value of the Enable zero-crossing detection parameter is ignored by QGen as QGen only supports fixed-step solvers.
9.2.3.6. Data Store Memory¶
Links to Mathworks Documentation
Block Type | Library |
---|---|
Data Store Memory | Signal Routing |
QGen Usage Constraints
- No element selection feature, only whole data items can be used.
9.2.3.7. Data Type Conversion¶
Links to Mathworks Documentation
Block Type | Library |
---|---|
Data Type Conversion | Signal Attributes |
QGen Usage Constraints
- Integer rounding mode must be one of: “Ceiling”, “Zero”, “Simplest”, “Round”, “Convergent”.
9.2.3.8. Data Type Duplicate¶
Links to Mathworks Documentation
Block Type | Library |
---|---|
Data Type Duplicate | Signal Attributes |
QGen Usage Constraints
- QGen supports models using this block to provide a seamless experience in Simulink, however no code is generated for this block. The code generated for the model is not affected.
9.2.3.9. Delay¶
Links to Mathworks Documentation
Block Type | Library |
---|---|
Delay | Discrete |
QGen Usage Constraints
- Delay length source must be set to “Dialog”
- External reset is not supported.
9.2.3.10. Demux¶
Links to Mathworks Documentation
Block Type | Library |
---|---|
Demux | Signal Routing |
QGen Usage Constraints
Bus signals should not be used at the input of this block.
Note: Use BusCreator and BusSelector blocks instead of Mux and Demux to process bus signals, as recommended in the Simulink documentation.
9.2.3.11. Detect Change¶
Links to Mathworks Documentation
Block Type | Library |
---|---|
Detect Change | Logic and Bit Operations |
QGen Usage Constraints
- Input processing mode “Columns as channels (frame based)” is not supported.
9.2.3.12. Detect Decrease¶
Links to Mathworks Documentation
Block Type | Library |
---|---|
Detect Decrease | Logic and Bit Operations |
QGen Usage Constraints
- Input processing mode “Columns as channels (frame based)” is not supported.
9.2.3.13. Detect Increase¶
Links to Mathworks Documentation
Block Type | Library |
---|---|
Detect Increase | Logic and Bit Operations |
QGen Usage Constraints
- Input processing mode “Columns as channels (frame based)” is not supported.
9.2.3.14. Direct Lookup Table (n-D)¶
Links to Mathworks Documentation
Block Type | Library |
---|---|
Direct Lookup Table (n-D) | Lookup Tables |
QGen Usage Constraints
- Maximum number of table dimensions is 2.
9.2.3.15. Discrete State-Space¶
Links to Mathworks Documentation
Block Type | Library |
---|---|
Discrete State-Space | Discrete |
QGen Usage Constraints
Parameters cannot be specified empty with []
Note: Use zeros(..) instead of [] to specify an empty parameter
9.2.3.16. Discrete Transfer Fcn¶
Links to Mathworks Documentation
Block Type | Library |
---|---|
Discrete Transfer Fcn | Discrete |
QGen Usage Constraints
- External reset is not supported.
- Supports only scalar input.
9.2.3.17. Discrete-Time Integrator¶
Links to Mathworks Documentation
Block Type | Library |
---|---|
Discrete-Time Integrator | Discrete |
QGen Usage Constraints
- Only the Forward Euler Integration and the Backward Euler Integration methods are supported.
- Show state port is not supported.
- Ignore limit and reset when linearizing is not supported.
- The DTI cannot be called within a conditionally activated subsystem, such as enabled subsystems or function-call triggered subsystems.
- A DTI block cannot be called by multiple callers or multiple times by a single caller in the same time instance within function-call subsystems.
9.2.3.18. Display¶
Links to Mathworks Documentation
Block Type | Library |
---|---|
Display | Sinks |
QGen Usage Constraints
- QGen supports models using this block to provide a seamless experience in Simulink, however no code is generated for this block. The code generated for the model is not affected.
9.2.3.19. DocBlock¶
Links to Mathworks Documentation
Block Type | Library |
---|---|
DocBlock | Model-Wide Utilities |
QGen Usage Constraints
- QGen supports models using this block to provide a seamless experience in Simulink, however no code is generated for this block. The code generated for the model is not affected.
9.2.3.20. Extract Bits¶
Links to Mathworks Documentation
Block Type | Library |
---|---|
Extract Bits | Logic and Bit Operations |
QGen Usage Constraints
- Fixed-point data is not supported in input. As a consequence, only the ‘Treat bit field as an integer’ output scaling mode is supported.
- The supported data types in input are: boolean, unsigned and signed integers of lenght 8, 16 or 32 bits.
- The number of output bits must be 8, 16 or 32 bits, giving the following supported output data types: unsigned and signed integers of length 8, 16, 32 bits.
9.2.3.21. For Each¶
Links to Mathworks Documentation
Block Type | Library |
---|---|
For Each | Ports and Subsystems |
QGen Usage Constraints
- A For Each Subsystem cannot contain blocks with state (e.g. Unit Delay).
9.2.3.22. For Each Subsystem¶
Links to Mathworks Documentation
Block Type | Library |
---|---|
For Each Subsystem | Ports and Subsystems |
QGen Usage Constraints
- A For Each Subsystem cannot contain blocks with state (e.g. Unit Delay).
9.2.3.23. For Iterator¶
Links to Mathworks Documentation
Block Type | Library |
---|---|
For Iterator | Ports and Subsystems |
QGen Usage Constraints
- External Iteration Limit port must be linked to a interface port.
9.2.3.24. Function-Call Generator¶
Links to Mathworks Documentation
Block Type | Library |
---|---|
Function-Call Generator | Ports and Subsystems |
QGen Usage Constraints
- The value in the ‘Number of Iterations’ field must be a scalar
9.2.3.25. Hit Crossing¶
Links to Mathworks Documentation
Block Type | Library |
---|---|
Hit Crossing | Discontinuities |
QGen Usage Constraints
- If the “Hit crossing offset” is non-scalar, it must have the same dimensions as the block’s input.
9.2.3.26. Inport¶
Links to Mathworks Documentation
Block Type | Library |
---|---|
Inport | Sources |
QGen Usage Constraints
“Latch input by delaying outside signal” must be turned off.
“Latch input for feedback signals of function-call subsystem outputs” (“Latch input by copying inside signal” in earlier Simulink versions) must be turned off.
Note: This parameter exists since MATLAB R2011a
“Latch input by copying inside signal” must be turned off.
Note: This parameter exists until MATLAB R2010b
9.2.3.27. Interpolation Using Prelookup¶
Links to Mathworks Documentation
Block Type | Library |
---|---|
Interpolation Using Prelookup | Lookup Tables |
QGen Usage Constraints
- The block supports up to two dimensions. The value of parameter “Table” shall be in either a vector or matrix. “NumberOrTableDimensions” shall be 1 or 2
- The parameter NumSelectionDims shall be empty
- The value of SaturateOnIntegerOverflow parameter shall be either empty or “off”
9.2.3.28. Lookup¶
Links to Mathworks Documentation
Block Type | Library |
---|---|
Lookup | Lookup Tables |
QGen Usage Constraints
- The maximum Simulink version supported for this block is R2010b. Use 1-D Lookup table instead from R2011a.
9.2.3.29. Lookup Table (2-D)¶
Links to Mathworks Documentation
Block Type | Library |
---|---|
Lookup Table (2-D) | Lookup Tables |
QGen Usage Constraints
- Flat and Linear interpolation methods are supported. Nearest and Cubic spline methods are not supported.
- Clip and Linear extrapolation methods are supported. Cubic spline method is not supported.
- Table dimensions higher than 2 are not supported.
- Ceiling, Floor, Simplest and Nearest integer rounding methods are supported. Convergent, Round and Zero are not supported.
9.2.3.30. Lookup Table Dynamic¶
Links to Mathworks Documentation
Block Type | Library |
---|---|
Lookup Table Dynamic | Lookup Tables |
QGen Usage Constraints
- The value of DoSatur parameter shall be either empty or “off”
9.2.3.31. Math Function¶
Links to Mathworks Documentation
Block Type | Library |
---|---|
Math Function | Math Operations |
QGen Usage Constraints
- The complex-valued functions: “magnitude-2”, “conj” and “hermitian” are not supported.
9.2.3.32. Merge¶
Links to Mathworks Documentation
Block Type | Library |
---|---|
Merge | Signal Routing |
QGen Usage Constraints
- The initial output parameter must not be empty ([]).
- The parameter “Allow unequal port widths” must be off.
- In case the block inputs come from the same atomic subsystem, the generated Ada code may not be compilable, and the generated C code may have a different behavior than Simulink semantics. One workaround is to merge the signals inside the atomic subsystem instead of outside. Another workaround is to use the
--full-flattening
QGen option to obtain correct Ada and C code generation.
9.2.3.33. Model Info¶
Links to Mathworks Documentation
Block Type | Library |
---|---|
Model Info | Model-Wide Utilities |
QGen Usage Constraints
- QGen supports models using this block to provide a seamless experience in Simulink, however no code is generated for this block. The code generated for the model is not affected.
9.2.3.34. Model Variants¶
Links to Mathworks Documentation
Block Type | Library |
---|---|
Model Variants | Ports and Subsystems |
QGen Usage Constraints
- Model Variant block must have the ‘Override variant conditions and use following variant’ box checked.
9.2.3.35. Multiport Switch¶
Links to Mathworks Documentation
Block Type | Library |
---|---|
Multiport Switch | Signal Routing |
QGen Usage Constraints
- Variable-size output signal is not supported, so the dimensions of multiple input data ports should match.
9.2.3.36. Mux¶
Links to Mathworks Documentation
Block Type | Library |
---|---|
Mux | Signal Routing |
QGen Usage Constraints
Bus signals are not allowed at the inputs of this block.
Note: Use BusCreator and BusSelector blocks instead of Mux and Demux to process bus signals, as recommended in the Simulink documentation.
9.2.3.37. Outport¶
Links to Mathworks Documentation
Block Type | Library |
---|---|
Outport | Ports and Subsystems |
QGen Usage Constraints
- Parameter ‘Source of initial output value’ must be set to ‘Dialog’.
- If the underspecified initialization mode of the model is ‘Simplified’ then the ‘Initial output parameter’ of all outports of conditionally executed subsystems must not be unspecified ‘[]’.
9.2.3.38. Product¶
Links to Mathworks Documentation
Block Type | Library |
---|---|
Product | Math Operations |
QGen Usage Constraints
- This block cannot have one input with the ‘/’ operator if the multiplication type is Matrix(*)
9.2.3.39. S-Function¶
Links to Mathworks Documentation
Block Type | Library |
---|---|
S-Function | User-Defined Functions |
QGen Usage Constraints
- The only type of supported S-Function is “Legacy function”.
- At minimum the information we need is the name of the header file of the external library and a function signature specifying the mapping to block ports and data types of each argument.
- This option applies when the s-function block in not generated using the legacy code tool (or one did not provide the full prototype specification). When function prototype specification is not found in the block specification then qgenc will generate a module named <modelname>_wrappers which contains a function for each generated block. An appropriate function call must be added manually in each wrapper function.
9.2.3.40. Saturation¶
Links to Mathworks Documentation
Block Type | Library |
---|---|
Saturation | Discontinuities |
QGen Usage Constraints
- The value of the ‘Saturate on integer overflow’ parameter shall be either empty or ‘off’
9.2.3.41. Scope¶
Links to Mathworks Documentation
Block Type | Library |
---|---|
Scope | Sinks |
QGen Usage Constraints
- QGen supports models using this block to provide a seamless experience in Simulink, however no code is generated for this block. The code generated for the model is not affected.
9.2.3.42. Selector¶
Links to Mathworks Documentation
Block Type | Library |
---|---|
Selector | Signal Routing |
QGen Usage Constraints
- Indexing option “Starting and ending indices (port)” is not supported
- The maximum number of input ports is three
- Higher than 2-dimensional input data is not supported
- With the combination of indexing option “Starting index (port)” and “Output sizes” parameter that has a value over 1, an overflow condition may occur. Simulink does not catch the overflow and QGenc cannot catch it either. An “Index check failed” error is given at run time (in generated Ada).
9.2.3.43. Signal Specification¶
Links to Mathworks Documentation
Block Type | Library |
---|---|
Signal Specification | Signal Attributes |
QGen Usage Constraints
- Check against ‘Dimensions’ parameter not supported: all dimensions should be statically known
9.2.3.44. Signal Viewer Scope¶
Links to Mathworks Documentation
Block Type | Library |
---|---|
Signal Viewer Scope | Sinks |
QGen Usage Constraints
- QGen supports models using this block to provide a seamless experience in Simulink, however no code is generated for this block. The code generated for the model is not affected.
9.2.3.45. Sum¶
Links to Mathworks Documentation
Block Type | Library |
---|---|
Sum | Math Operations |
QGen Usage Constraints
- The Sum over specified dimension mode is not supported.
- Base (element) types of all inputs and output must be the same (follows from MISRA AC SLSF 002 Ver 1.0 2009, Section 3.1.2).
- The accumulator data type must be set to either “Inherit: Same as first input” or “Inherit: Inherit via internal rule” or be the same as the common base type of the inputs and outputs (follows from MISRA AC SLSF 002 Ver 1.0 2009, Section 3.1.2).
9.2.3.46. Terminator¶
Links to Mathworks Documentation
Block Type | Library |
---|---|
Terminator | Sinks |
QGen Usage Constraints
- QGen supports models using this block to provide a seamless experience in Simulink but the block does not affect the code generated for the model. No code is generated for this block.
9.2.3.47. To Workspace¶
Links to Mathworks Documentation
Block Type | Library |
---|---|
To Workspace | Sinks |
QGen Usage Constraints
- QGen supports models using this block to provide a seamless experience in Simulink, however no code is generated for this block. The code generated for the model is not affected.
9.2.3.48. Transfer Fcn First Order¶
Links to Mathworks Documentation
Block Type | Library |
---|---|
Transfer Fcn First Order | Discrete |
QGen Usage Constraints
- Input and output signals must have same floating point base type (e.g. ‘double’)
9.2.3.49. Transfer Fcn Lead or Lag¶
Links to Mathworks Documentation
Block Type | Library |
---|---|
Transfer Fcn Lead or Lag | Discrete |
QGen Usage Constraints
- Input and output signals must have same floating point base type (e.g. ‘double’)
9.2.3.50. Transfer Fcn Real Zero¶
Links to Mathworks Documentation
Block Type | Library |
---|---|
Transfer Fcn Real Zero | Discrete |
QGen Usage Constraints
- Input and output signals must have same floating point base type (e.g. ‘double’)
9.2.3.51. Trigonometric Function¶
Links to Mathworks Documentation
Block Type | Library |
---|---|
Trigonometric Function | Math Operations |
QGen Usage Constraints
- Function: “cos + jsin” is not supported (complex-valued operation).
- The “Approximation method” option must be set to “None”.
9.2.3.52. Uniform Random Number¶
Links to Mathworks Documentation
Block Type | Library |
---|---|
Uniform Random Number | Sources |
QGen Usage Constraints
- Parameter “Minimum” must have the same dimensions as parameter “Maximum”.
9.2.3.53. Wrap To Zero¶
Links to Mathworks Documentation
Block Type | Library |
---|---|
Wrap To Zero | Discontinuities |
QGen Usage Constraints
- Parameter “Threshold” must have the same same dimensions as input, except if parameter “Threshold” is a scalar.
9.2.3.54. n-D Lookup Table¶
Links to Mathworks Documentation
Block Type | Library |
---|---|
n-D Lookup Table | Lookup Tables |
QGen Usage Constraints
- Flat and Linear interpolation methods are supported. Nearest and Cubic spline methods are not supported.
- Clip and Linear extrapolation methods are supported. Cubic spline method is not supported.
- Table dimensions higher than 2 are not supported.
- Ceiling, Floor, Simplest and Nearest integer rounding methods are supported. Convergent, Round and Zero are not supported.
9.2.4. Additional Simulink Block Constraints¶
9.2.4.1. S-functions and Legacy Code¶
9.2.4.2. Lookup and Interpolation Blocks¶
The blocks where interpolation or lookup table are given by input port (Lookup Table Dynamic, Prelookup,Interpolation Using Prelookup) can not appear in a model where the table data is received from a top-level input. This includes models referenced by Model Reference block.
9.3. Other Simulink Constraints¶
9.3.1. Model Configuration Parameters¶
9.3.1.1. Solver¶
Solver type should be discrete, fixed-step.
9.3.1.2. Diagnostics¶
Model Initialization must be set to “Simplified” or, if it is set to “Classic”, then “Detect multiple driving blocks executing at the same time step” must be set to “error”.
9.3.2. Blocks Configuration¶
All blocks should have sample time set to “inherited”, except in the case of non-directfeedthrough blocks (UnitDelay, DiscreteTimeIntegrator, ...).
9.3.3. Signal Dimensions¶
Scalar, vectors and two-dimensional matrices are supported. Matrices with more dimensions are not supported.
9.3.4. Custom Data Types¶
It is possible to generate code with externally declared datatypes. See Custom Data Types for the details.
9.3.5. Use of Callback Functions¶
Simulink allows adding callback functions to models, blocks or port. These functions may be there just for documentation purposes. QGenc does not support callbacks functions. It is up to the user to verify they are not present or, if present, they do not affect the model behaviour.
NB! There is an exception in case of masked blocks – if the purpose of a callback function is to transfer mask parameter value from mask to all parameters with same name inside of the masked subsystem, then this is supported by QGen.
9.3.6. Real-valued Computations Only¶
- QGen supports only integer and floating point -valued signals and computations. Complex values are not supported.
- Parameters that control the signal type, e.g. “Output signal type” must have value “real” or “auto”.
9.3.7. Bus Signals¶
- QGen supports both virtual and non-virtual buses.
- Buses are supported at the input-output of following Simulink blocks
- Bus Creator
- Bus Selector
- Bus Assignment
- Signal Conversion
- Inport
- Outport
- Unit Delay
- Switch
9.3.8. Forwarding Tables in Libraries¶
Forwarding Tables can be used in Simulink libraries. There are a few restrictions in their use:
- Transformation Functions are not supported
- The redirection of blocks can only be defined in the library where this block is defined. For example, if we want to map “LibA/BlockA” to “LibB/BlockB”, this redirection can only be defined in “LibA”.
9.3.9. MISRA Simulink Guidelines¶
QGen automatically checks that the input model conforms to selected MISRA Simulink constraints. QGenc should not be used as a MISRA checker tool. The checks are limited to constructs which directly influence the code generation policy. For full check one should use a dedicated MISRA checker.
Via the –no-misra option, qgenc
can cope with models violating the checked
MISRA constraints. However, we suggest to adopt at minimum the following rules:
- Blocks that can be configured to use saturation must have this flag off. The Saturation or Saturation Dynamic blocks should be used, if saturation is needed.
- Blocks other than the Rounding block that can be configured to use different rounding options must be set to round towards zero. The only exception is Data Type Conversion, where the rounding option is also supported.
- Data type conversion of block input and output should be done using the Data Type Conversion block and not by other blocks with block specific type conversion options.
9.3.10. Simulink Coder(TM) Parameters¶
qgenc
respects selected parameters from Signal and Parameter object that do
not influence the model semantics and are intended for tuning the Simulink Coder
behaviour. The semantics may not be necessarily the same as that assumed by the
Simulink coder. Below is the table of supported parameters their values and
impact on the generated code.
Value | Notes | Ada | C |
---|---|---|---|
Auto, Default, Global or SimulinkGlobal | In case of a Signal object, the variable is defined in module corresponding to containing subsystem. A constant corresponding to a Parameter object is defined in <modelname>_params module. | <name> : [constant] <typename> := <value>; | [const] <typename> <name> = <value>; |
ExportedGlobal | A constant (in case of Parameter) or variable (in case of Signal) is defined in <modelname>_params module. | <name> : [constant] <typename> := <value>; | [const] <typename> <name> = <value>; |
ExportToFile | The Header file parameter is obligatory. A constant (in case of Parameter) or variable (in case of Signal) is defined in the module defined in Header file parameter. | <name> : [constant] <typename> := <value>; | [const] <typename> <name> = <value>; |
ImportedExtern | A constant (in case of Parameter) or variable (in case of Signal) is defined with “extern” qualifier. If Header file parameter has value, with/include statement is generated for this module | <name> : [constant] <typename> := <value>; pragma Import (Ada, <name>, “<name>”); | extern [const] <typename> <name> = <value>; |
ImportFromFile | The Header file parameter is obligatory. With/include statement is generated for this module. When generating ada code and the included module has ”.h” extension, an additional import declaration is generates in module <modelname>_params | <name> : [constant] <typename>; pragma Import (C, <name>, “<name>”); | #include “<Header file>” |
Const | Applies to Parameter object only. Adds “const” qualifier to generated variable. Has effect only in case of –const-as-vars, as by default all parameters are treated as constants. | <name> : constant <typename> := <value>; | const <typename> <name> = <value>; |
Volatile | Adds “volatile” qualifier to generated variable/constant and import statement | <name> : [constant] <typename> := <value>; pragma Import (Ada, <name>, “<name>”); pragma Volatile (<name>); | volatile [const] <typename> <name> = <value>; |
ConstVolatile | Applies to Parameter object only. Adds “const” qualifier to generated variable. Has effect only in case of –const-as-vars, as by default all parameters are treated as constants. | <name> : constant <typename> := <value>; pragma Import (Ada, <name>, “<name>”); pragma Volatile (<name>); | volatile const <typename> <name> = <value>; |
Define | Applies to Parameter object only. Adds “const” qualifier to generated variable in case of Ada. In case of c generates a macro definition | <name> : constant <typename> := <value>; | #define <name> = <value>; |
The Header file parameter is supported for some storage classes as described above. The parameter or signal variable is defined in the module specified by the headerfile attribute. Depending on the storage class the module is either generated (ExportToFile) or assumed to exist (ImportFromFile, Volatile, Const, ConstVolatile).
9.4. MATLAB¶
9.4.1. MATLAB .p and .mat Files¶
MATLAB .p and .mat files are not supported.
9.4.2. MATLAB Code for Parameters in .m Files and Block Parameters¶
9.4.2.1. Dimensions of data¶
Scalars, vectors and two-dimensional data (matrices) are supported. Data with more dimensions is not supported.
9.4.2.2. Accepted Constructs¶
Only constant definitions are are accepted in .m files. The supported format is:
<identifier> = [<data type> (] <value> [)];
where
<identifier> := <constant name>[.<structure element name>]
<value> := <literal value> | <expression>
Datastructures are defined implicitly by assigning values for each structure element. There is currently no way to attach explicitly defined data type to a constant.
Values can be composed of literal values, references to other constants and expressions including of arithmetic operators and supported functions (see section “MATLAB functions” below).
Annotation delimiter is “%”.
Examples
% Constant definition, implicit data type
MyIntParam = 15;
% Constant definition, explicit data type
MyDoubleParam = double (100);
% Array with explicit data type
MyArrParam = double ([1 2 3]);
% Definition of a constant structure
MyStructParam.Elem1 = 1;
MyStructParam.Elem2 = [1 2 3];
MyStructParam.Elem3 = MyIntParam;
% Expression using other constants
MyIntParam2 = int8 (MyIntParam + MyDoubleParam);
9.4.2.3. Type Definitions¶
- Type definitions are not supported in parameter .m-files. However, QGen supports several ways of using custom data types. See Custom Data Types for further details.
- The only exception is an implicit type definition of a structure (record) parameter. QGen infers the type definition from the instance definition in the parameter file. See MATLAB Code for Parameters in .m Files and Block Parameters.
9.4.3. MATLAB Operators¶
The following unary operators are supported:
+ - ~
The following binary operators are supported:
+ - * .* / ^ < <= > >= ~= | || & &&
9.4.4. MATLAB Functions¶
The following MATLAB functions are supported in both .m files and Simulink block parameters:
abs, acos, asin, atan, atan2, bin2dec, cos, cosh, exp, hex2dec, log, log10,
min, max, mod, rem, round, sign, sin, sinh, sqrt, tan, tanh, transpose.
Explicit typing/casting expressions are supported for:
int8, int16, int32, uint8, uint16, uint32, single, double, logical
In addition to numeric literals, the following literals are supported as well:
INF, NaN
9.4.5. MATLAB Expressions¶
Expressions containing the colon operator can only be used to get a slice of a vector (without increment value):
mySlice = myVector(3:8);
The following expressions are not supported:
- Matrix partial indexing:
myMatrix(:,1);
myMatrix(1:3);
- Creation of row vector:
MyVector = [10:20];
- Vector slice with increment value:
mySlice = myVector(1:5:20);
In case there is a need for using such subarrays, then you should do the slicing
in MATLAB and feed an appropriate subrarray to qgenc
.
For instance when myMatrix is a two dimensional array and a model contains block parameter with value myMatrix (:,1) (i.e. the parameter is a vector containing the first column from matrix) then:
- the original matrix is
myMatrix = [1 2; 3 4];
- create a vector variable myVector1 in MATLAB
myVector1 = myMatrix(:,1);
- copy the vector value to the .m file that is given as an argument to
qgenc
myVector1 = [1 3];
- replace the expression “myMatrix(:,1)” in model with “myVector1”
- assign to a structure in array:
myVector1(1,2).member = 1;
9.4.6. MATLAB cell arrays¶
Cell arrays in MATLAB workspace are not supported. qgen_export_workspace generates warning and array is not exported. When the array is referenced from Simulink model then code generation fails.
9.5. Stateflow chart modelling rules¶
The following modeling rules for Stateflow Charts are enforced.
9.5.1. Event broadcast for local events shall not to be used¶
Description: Stateflow event broadcast mechanism for Stateflow local events shall not to be used. Dataflow shall be used for controlling the chart’s mode instead.
Note: An exception is broadcasting external events, i.e. events that are received by other parts of the (Simulink) model than the broadcasting chart itself. Such events do not directly affect the behaviour of the chart. The only affect is changing global data. This kind of broadcasting is allowed. Typically the trigger type of the event/port is in such cases “function call”.
Justification: Some forms of event broadcast can lead to non-termination. Broadcasting an event in a transition action is one case that can never lead to non-termination by itself. In other cases static checks could be used to detect potentially looping behaviour.
9.5.2. Input and output events of the chart shall have a “function call” trigger type¶
Description: The trigger type property of input and output events of a chart shall have a “function call” trigger type.
Justification: This ensures the kind of timing of execution that is required by modelling/coding practices by some of the end-users. Output events with edge trigger type can create confusing models, because an event can be triggered several times in Stateflow, but is seen once or not at all in the Simulink part
9.5.3. [REMOVED]¶
This constraint was applicable up to version 2.1.2 of QGen. It was removed in version 17 and is no longer relevant in subsequent versions.
This section is preserved for traceability of constraints across different versions of QGen.
9.5.4. [REMOVED]¶
This constraint was applicable up to version 1.0.1 of QGen. It was removed in version 2.0.1 and is no longer relevant in subsequent versions.
This section is preserved for traceability of constraints across different versions of QGen.
9.5.5. Transition actions shall not be used in graphical functions and pure flow-graph decompositions. Condition actions shall be used instead.¶
Description: Transition actions shall not be used in graphical functions and pure flow-graph decompositions.
Note
This rule applies to pure flow-graphs only. It does not concern OR compositions of states, where transition actions are very appropriate.
Justification: This is a robustness constraint against effectively dead modelling constructs. Transition actions are meaningless in the above-mentioned cases since they are executed only when there is a transition from state to state (some versions of Stateflow allow to specify such actions, but they are never executed). In flow-graph networks condition actions should be used instead.
9.5.6. An OR decomposition must always have an unguarded default transition¶
Description: An OR decomposition must always have an unguarded default transition. Exception: An OR decomposition with only one substate can exist without a default transition. However, when any default transitions are present, then at least one must be unguarded.
Justification: If this condition is not satisfied then a run-time error due to state inconsistency can result, when a decomposition is entered, since it means that a system is in inconsistent state. When the decomposition consists of one substate only, then there is no need for the default transition. However, default transitions might exist, with different transitions specifying different actions. In the last case one of them must be without a guard to avoid confusion reading the model, as in Stateflow the state is nevertheless entered.
9.5.7. [REMOVED]¶
This constraint was applicable up to version 17.1 of QGen. It was removed in version 17.2 and is no longer relevant in subsequent versions.
This section is preserved for traceability of constraints across different versions of QGen.
9.5.8. Boxes shall only be used for grouping functions¶
Description: Boxes shall only be used for grouping functions.
Justification: Justification: Using boxes around states or flow-graph networks creates strange and complex scoping. The logical scoping for executing the chart’s sections and the name scopes introduced by boxes do not match. Boxes are fine for grouping graphical functions and truthtable functions.
9.5.9. Only bounded flow-graph loops should be used¶
Description: Flow-graph loops can cause non-termination of the chart’s execution. The loops should be designed with care and preferrably use a simple for-style pattern.
Note
This rule is currently not checked by QGen.
9.5.10. The transition arc shall not leave its logical parent’s boundary¶
Description: The transition arc shall not leave the boundary of the logical parent of the transition (the lowest common ancestor of the source and destination states).
Warning
Stateflow issues a warning about such transition arcs when simulating the model. This rule is not checked by QGen. In case such arcs exist the behaviour in Stateflow can have some side-effects that are not taken into account by QGen.
Justification: This is an error-prone pattern. The detailed semantics for such transitions is complicated and unintuitive. Identical or similar behaviour can be obtained by more clear and explicit constructs.
9.5.11. Super step semantics shall not be used¶
Description: The Stateflow super step semantics is not supported. This option should be turned off in charts supplied to QGen.
Warning
This rule is currently not checked by QGen. The behaviour of simulation and code generated by QGen can be different.
9.5.12. Variable-size arrays shall not be used¶
Description: The variable-size arrays in Stateflow are not supported. This option should be turned off in charts supplied to QGen.
Note
This rule is currently not checked by QGen.
9.5.13. Only C action language shall be used¶
Description: QGen does not support the MATLAB action language.
9.5.14. Moore charts shall not be used for breaking data loops¶
Description: It is possible in Simulink/Stateflow to use Moore charts for breaking causality of data feedback loops (algebraic loops). This is currently not supported in QGen.
If a Moore chart is used in a data feedback path make sure there is also some non-direct feedthrough block, such as Unit Delay on the same path.
9.5.15. Truth tables shall not be used¶
Description: Truth table functions are currently not supported by QGen. Similar functionality can be modelled with graphical functions.
9.5.16. Simulink functions shall not be used¶
Description: Using Simulink functions in Stateflow charts is currently not supported by QGen. Similar functionality can be modelled with an external Simulink subsystem that has the necessary data inputs-outputs connected to the chart’s io and that is triggered by a function call event from the chart.
9.5.17. History junctions shall not be used¶
Description: History junctions are not supported by QGen. Their use is also deprecated by the MISRA AC SLSF guide (rule 046) as it complicates interpretation of the model’s semantics.
The history can be modelled with an explicit local variable and transitions instead.
9.5.18. [CHANGED] Absolute-time temporal logic shall not be used¶
Description: The Stateflow absolute-time temporal logic operators and events are currently not supported by QGen.
This constraint has been changed in QGen version 18, where the support for event-based temporal logic was added. In earlier versions neither event-based nor absolute-time temporal logic were supported.
9.5.19. Change detection functions shall not be used¶
Description: The Stateflow change detection functions: ‘hasChanged’, ‘hasChangedFrom’ and ‘hasChangedTo’ are currently not supported by QGen.
9.5.20. ‘in <state>’ operator shall not be used¶
Description: The ‘in <state>’ operator is currently not supported by QGen.
9.5.21. Data stores shall only be accessed through chart’s I/O¶
Description: Defining or accessing data stores directly from Stateflow chart is not supported. If referring or modifying a value of a Data Store is needed in Stateflow, create resp. Data Store Read and Write blocks and connect them to the chart’s I/O.
9.6. Target Languages¶
9.6.1. Ada / SPARK¶
QGen generates Ada code compliant with the Ada 83, Ada 95, Ada 2005, Ada 2012 and SPARK 2014 standards.
Generated code might be non-compilable when the source of a Merge block is an atomic subsystem. This limitation will be fixed in a future QGen release.
9.6.2. MISRA-C¶
QGen generates C code compliant with the C89 ANSI standard and MISRA C:2012 guidelines.
9.7. XMI Support¶
The XMI importer has the following limitations:
The
xsi:type
of an object is specified using the fully qualified name:<?xml version="1.0" encoding="ASCII"?> <geneauto.emf.models.gacodemodel:GACodeModel ...> <elements xmi:type="geneauto.emf.models.gacodemodel:Module" ... /> <geneauto.emf.models.gacodemodel:GACodeModel>
The
xmi:id
attribute is used to resolve references to elements and is always required for every node. XPath expressions are not (and will not be) supported. For example, the following XMI is acceptable:<expressions xmi:type="geneauto.emf.models.gacodemodel.expression:VariableExpression" xmi:id="830" ... variable="404"/> ... <variables xmi:type="geneauto.emf.models.common:Variable" xmi:id="404" ... />
Where the
variable
attribute in the first node references thexmi:id
of the second node.If two features are one the eOpposite of the other, the values for both need to be included in the XMI file.
These limitations are not planned to be alleviated.