Safety-Critical Software Development Using Automatic Production Code Generation
Safety-Critical Software Development Using Automatic Production Code Generation
Safety-Critical Software Development Using Automatic Production Code Generation
net/publication/228749528
CITATIONS READS
15 935
2 authors, including:
Mirko Conrad
samoconsult GmbH
81 PUBLICATIONS 875 CITATIONS
SEE PROFILE
All content following this page was uploaded by Mirko Conrad on 12 April 2016.
Mirko Conrad
The MathWorks GmbH
The Guidelines for the use of the C language in critical Therefore the software safety integrity tables from the
systems, compiled by MISRA, describe a subset of the standard are extended by an additional column labeled
programming language C, which is applicable for the ‘Applicable Tools / Processes for Model-Based Design’.
use in safety-critical applications. The MISRA-C The entries in the column describe how the particular
guidelines are adopted frequently in order to fulfill safety measure or technique can be supported by products or
standard’s requirements for a suitable programming solutions for Model-Based Design; see Tables 1 and 2
language on the code level. for exemplary sections of commented IEC61508-3
tables.
MAAB Controller Style Guidelines for Production Intent
Development Using MATLAB®, Simulink®, and Table 1: Example of a generic, annotated software
Stateflow® safety integrity table (see IEC 61508-3 Table A.3)
Model Analysis Reports: Another useful report comes Furthermore, the different types of reports can be used
from the Model Advisor. This tool examines your model to document the individual development and V&V
based on default or customized checks (see section on activities as well as to contribute evidence for the safety
‘Model Analyses and Checks’) and produces an output case.
that is displayed within the Simulink environment.
However, it is also possible to export this output as an CODE-LEVEL V&V ACTIVITIES
HTML report that can be viewed outside of Simulink,
either standalone or incorporated within a Code Analysis and Checks
documentation system.
It is useful to employ analysis tools for examining C code
The MATLAB command sequence to export the Model deployed on production ECUs. Over the years,
Advisor report to a file name ecu_prj.htm based on your automotive organizations have incorporated a wide
current model is as follows. range of code analysis tools into their verification and
validation process including in-house tools, commercial
>>Obj = Simulink.ModelAdvisor.getModelAdvisor(gcs) off-the shelf (COTS) tools, or customized version of
>>Obj.exportReport('ecu_prj.htm') COTS tools.
An example standalone Model Advisor report viewed With automatic code generation, it is straightforward to
from a desktop browser is in Figure 8. invoke a code analysis utility. There are documented
entry points, or “hooks”, during the code generation and
Model Documentation Reports: The Simulink Report build process that allow external tools to act on the
Generator allows engineers to create custom reports artifacts (e.g., code), while they are being produced.
containing models, data, and analysis results. It also
integrates reports from other products and features Recent improvements for the code generation build
including requirements traceability tables. processes makes it easy for end users to obtain the
static files, libraries, and paths that the generated code
The model documentation reports facilitate reviews and is dependent on. In one improvement example, a
walk-throughs on model level (see IEC 61508-3, Table packNGo utility provided by Real-Time Workshop
B.8, Technique/Measure 2: 9 Walk-throughs/design Embedded Coder that contains the generated code
reviews). dependency files in a single zip file that can be
packaged, moved, and deployed into a separate
environment for code analysis and inspection using Lint
or other analysis tools.
MISRA-C Checking: As outlined above, adherence to
the MISRA-C guidelines should be enforced by using
appropriate tools.
• Imported legacy code may violate a rule(s) Figure 9: Tracing requirements in code back to models
• Conscious or accidental changes to built-in code
generation setting may occur Tests derived from the requirements, and applied to the
model, can be reused on the code. To do this, it is
For these reasons and to check the code generation possible export the test cases in the Signal Builder to the
output, it makes sense to add a code-based checker to MATLAB workspace so that one can add them to a
your Model-Based Design environment, which can be particular code test environment.
done by using a variety of tools. One example of this,
using Splint, can be found in [8]. Building integration like Another option for test case reuse is to perform
this is possible using open APIs and hook points within Software-in-Loop (SIL) or Processor-in-Loop (PIL)
the build process described above. testing using built-in Simulink capabilities. One example
of PIL testing is provided by Link for TASKING®, see
Another option is to use tools which have built Figure 10.
integrations with Simulink and the code generation
process. One example integration is from Polyspace Figure 10 shows that a Simulink model can interact or
[13]. co-simulate with automatically generated code running
in an instruction set simulator (Altium TASKING). The
Besides supporting the MISRA guidelines directly, data and execution control exchange is bidirectional and
MISRA-C checking facilitates the IEC 61508-3 makes for a seamless integration. Developers and test
requirements on language subsets and coding engineers can, in this way, run the same test cases or
standards on model level (see IEC 61508-3, Table A.3, plant model used on the algorithm model with the actual
Technique/Measure 3: Language subset and Table A.4, object code generated and compiled for a particular
Technique/Measure 5 Design and coding standards). target. This type of Processor-in-Loop test is a non-real-
time test environment.
More information about generating code for MISRA-C
can be found in Real-Time Workshop Embedded Coder The functional code testing capabilities described above
User’s Guide [14]. can be used to support an IEC 61508 conformant
software module testing (see IEC 61508-3, Table A.5,
Code Testing Capabilities Techniques/Measures 2: Dynamic analysis and testing
and 4: Functional and black-box testing as well as
Requirements-Based Testing: It is possible to have detailed Tables B.2 and B.3).
model traceability information and tags appear in the
code if the model contains traceability links to high level Code Coverage Analysis: Code structural coverage
requirements. Hyperlinks from the code, back to the analysis can be reported in several ways. In one
model, then back to the requirement source, makes it example, Link for TASKING can run a PIL test and
easy to determine if the generated code implements the return the structural code coverage analysis reported by
stated high level requirements. See Figure 9. the TASKING toolchain.
Model provides algorithm, tests, plant
REFERENCES
Mirko Conrad, Team Lead Model Safety Package, The *The MathWorks, Inc. retains all copyrights in the figures and excerpts of
code provided in this article. These figures and excerpts of code are used with
MathWorks GmbH. permission from The MathWorks, Inc. All rights reserved.
Mirko leads MathWork’s activities to support safety-
related automotive projects. Before joining The ©1994-2007 by The MathWorks, Inc.
MathWorks, he worked at DaimlerChrysler on method MATLAB, Simulink, Stateflow, Handle Graphics, Real-Time Workshop, and
and tool support for different Model-Based Design xPC TargetBox are registered trademarks and SimBiology, SimEvents, and
activities including code generation and testing. Mirko SimHydraulics are trademarks of The MathWorks, Inc. Other product or brand
holds a PhD in engineering (Dr.-Ing.) and a M.Sc degree names are trademarks or registered trademarks of their respective holders.
in computer science (Dipl.-Inform.) from Technical