UserManual MICROSARAdaptive
UserManual MICROSARAdaptive
User Manual
Version 9.0.0
English
Imprint
Vector reserves the right to modify any information and/or data in this user documentation without notice. This documentation nor any of
its parts may be reproduced in any form or by any means without the prior written consent of Vector. To the maximum extent permitted
under law, all technical data, texts, graphics, images and their design are protected by copyright law, various international treaties and
other applicable law. Any unauthorized use may violate copyright and other applicable laws or regulations.
© Copyright 2024, Vector Informatik GmbH. Printed in Germany.
All rights reserved.
Table of Content
Table of Content
3 Concepts 10
3.1 Introduction 10
3.2 Classic And Adaptive 10
3.3 The Adaptive Concept 11
3.3.1 A Deeper Look In The Adaptive Applications 13
3.3.2 MICROSAR Adaptive Delivery - BSW 15
3.3.3 From Delivery to ECU 16
3.3.4 MICROSAR Adaptive Delivery - DaVinci Developer Adaptive 17
3.3.5 Complete Overview as Summary 18
3.4 MICROSAR Adaptive Clusters 19
3.4.1 Clusters and Modules 20
3.5 General Requirements for MICROSAR Adaptive 22
3.5.1 Customer Code Declarations 22
3.5.2 Only Use Public API in Customer Code 22
3.5.3 C/C++ Compiler Settings 23
3.5.4 Validity of Enums, Pointers and Values 23
3.5.5 Multi-Threaded Execution and Reentrancy 23
3.5.6 Building Libraries and Executables 23
3.5.7 Uniqueness of Model Element Short Names 24
3.5.8 Multiple Processes per Executable Not Supported 24
3.5.9 Support of Suspend-to-RAM 24
3.5.10 Environment Variables of Global Scope 24
3.5.11 Dynamic Memory Allocation 25
3.5.12 Model Extensions 25
3.5.13 Persistent Data Migration During Update 26
3.6 TACO 26
3.6.1 Preface 26
3.6.2 TACO 27
3.6.2.1 CMake Requirements 27
4 StepbyStep 28
4.1 Step By Step Through an Adaptive Application 28
4.1.1 The Template Explains 28
4.2 Steps Using TACO 28
4.2.1 Use the Given Template for TACO 28
4.2.1.1 Models 29
4.2.2 CMake 32
4.2.2.1 HWSRC_APP_OUTPUT_NAME 32
4.2.2.2 add_subdirectory 32
4.2.2.3 taco_target_properties 32
4.2.2.4 app/hello_world/taco.cmake 32
4.2.3 Source Code 33
4.2.3.1 main.cpp 33
4.2.3.2 application.h / application.cpp 33
5 AdvancedTopics 36
5.1 Signal Handling 36
5.2 C++ Exceptions 39
5.2.1 Compilation Without Exception Support 40
5.2.2 Exeption Propagation 40
5.3 C++ Error Handling 40
5.3.1 Result Type 41
5.3.2 Error Propagation 41
5.4 Using Symbolic Links to Start Non-Adaptive Application Outside the Base Directory 42
5.5 Configurable Executable Path for Applications 43
5.6 Integration Non-AUTOSAR Applications 43
5.6.1 Starting Non-AUTOSAR Applications 43
5.6.2 Companion Process 44
5.6.3 Using Diagnostic Tools or Debuggers 46
5.7 Initialization and Shutdown 47
5.8 Orderly Shutdown and Restart of an MICROSAR Adaptive ECU 49
5.8.1 Manual Orderly Shutdown and Restart 49
5.8.2 Automated Orderly Shutdown and Restart Triggered by State Manager 50
5.8.3 Automated Orderly Shutdown and Restart Triggered by SIGTERM 51
5.8.4 Rapid Shutdown and Restart Triggered by State Manager 51
5.9 Disable Execution State Reporting 52
5.10 Additional Restrictions and Exceptions 52
5.10.1 Iterators 53
5.10.2 C-Style Strings 53
5.10.3 Ranges 53
5.11 Abnormal Terminations 53
5.11.1 Detection and Notification 53
5.11.1.1 Execution Manager 54
5.11.1.2 Other Parent Processes 55
5.11.1.2.1 Examples 55
5.11.2 Recovery 55
5.11.3 Application Components and Daemons 55
5.11.4 Library Components 56
5.11.5 Customer Provided Modules 56
5.12 Support of Multiple Adaptive AUTOSAR API Releases 56
5.12.1 C++ Namespace Separation Pattern 57
5.12.2 Build Time Selection of Standard Namespace Mappings 57
6 Additional Information 61
6.1 Cheat Sheets 61
6.2 Service Oriented - a Flexible Communication Concept 62
6.3 Glossary and Abbreviations 63
6.4 Reference Documents 64
It is up to you how to work with this user manual and depends on your knowledge level
about AUTOSAR Adaptive and MICROSAR Adaptive, the idea behind it and its concepts.
The document contains the following main parts:
Introduction
The chapter you are in right now provides general Information about this document,
meaning of icons and styles, etc.
Concepts StepbyStep
Advanced Topics
Collection of different topics.
AdvancedTopics
Additional Information
Supplementary topics.
Additional Information
History Information
For detailed information about what's new, what's changed in current version, refer to
section What's New, What's Changed?
Conventions
Conventions The tables below show the notation and icon conventions used throughout the manual.
Style Use
bold Elements of the user interface, for example, dialog names and menu
items
[OK] Notation for buttons in square brackets
File | Save Notation for menus and menu items
file.xml File names, directory names and source code elements
Source code Source code block
Hyperlink References and hyperlinks
<Ctrl>+<S> Key combinations
Icon Use
Notes and tips
Caution
References
Examples
Multimedia references
Introduction
Basic knowledge
Expert knowledge
Icon Use
Step-by-step instructions
Changes
Editing is prohibited
Certification
Cerfification Vector Informatik GmbH has ISO 9001:2008 certification. The ISO standard is a globally
recognized standard.
Warranty
Warranty We reserve the right to modify the contents of the documentation or the software without
notice. Vector disclaims all liabilities for the completeness or correctness of the contents
and for damages which may result from the use of this documentation.
Support
Support Need support? You can submit your support request in the Vector Customer Portal, via e-
mail or telephone.
> Contact via Vector Customer Portal:
https://portal.vector.com/
> Contact via e-mail or telephone:
https://www.vector.com/int/en/company/contacts/support-contact/
Trademarks
Trademarks All brand names in this documentation are either registered or non-registered trademarks
of their respective owners.
Because of many NDAs with different hardware manufacturers or because we are not
informed about them, we are not able to provide you with information concerning
hardware errata of the hardware manufacturers.
Example Code
All application code in any of the Vector User Manuals is for training purposes only.
They are slightly tested and designed only to understand the basic idea of using a
certain component or set of components. Vector gives consent that you use it as a
basis for developing your own code and modify it (Vector waives its copyright to forbid
you the use), however, with regard to the fact that the code is designed for training
purposes only and not for the use by you, usability of the code is not warranted and
Vector’s liability shall be expressly excluded in cases of normal negligence, to the
extent admissible by law or statute. Of course, you have to test the software developed
on the basis of the code with diligent care before using the software.
Tools provided in the BSW Package as well as DaVinci Developer Adaptive operate
with the folder structure that was used to ship the BSW Package. Changes of the BSW
Package folder structure may result in tool malfunction as the required files cannot be
found as expected. It is therefore not recommended to modify the BSW Package folder
structure
3 Concepts
3.1 Introduction
A chapter for beginners This chapter is meant for those who are new to the topic AUTOSAR Adaptive. Especially
and interested. those, who switch from AUTOSAR Classic projects to AUTOSAR Adaptive projects could
have some struggle to understand the different approach between Classic and Adaptive.
But there are also parallels.
A brief comparison The development of the AUTOSAR Classic Platform focuses on the requirements for the
development of statically configured automotive Electronic Control Units (ECU) with hard
real-time requirements.
The AUTOSAR Adaptive Platform is a software architecture for the creation of ECUs that
have to cope with upcoming requirements of more demanding use cases such as
automated driving or central applications servers and require more computation power
and flexibility in installation and updating software.
Performance The Adaptive Platform supports high-performance microprocessors with different
operating systems (POSIX-based), more complex application functionality and enables
software development cycles that are much shorter than the typical life cycle of vehicle
models.
Dynamic The Adaptive Platform provides more flexibility in how Automotive Applications can be
implemented and in which Automotive Application can be deployed in vehicles. There is
no longer one binary to download to the hardware. The user experience is similar to a
mobile phone or a PC, you can add and update applications dynamically.
A vision: Software One vision is, to build up a software store like an Appstore to be able to install and
Store continuously update or purchase additional software for your vehicle.
Adaptive Platform will The AUTOSAR specification is separated into three parts. There is the Foundation, the
complement Classic Classic Platform and the Adaptive Platform.
Platform The Foundation includes the specification of e.g. the bus protocols to ensure
communication compatibility.
The Adaptive Platform is designed to complement and interact with the classic world.
Communication Traditionally, automotive communication is based on broadcasting signals, which fit very
well for control data of limited size, which has to be communicated cyclically. In
AUTOSAR Classic there is also implemented a static service-based communication
concept.
Due to the possibility to install new applications on the ECU, a static configuration of
communication paths is not suitable. A communication paradigm that enables the
developer to find and establish connections during runtime is needed. The Adaptive
Platform will provide service-oriented communication along with the existing signal-based
paradigm.
The illustration below is a schematic drawing of an Adaptive ECU on the left side and a
Classic ECU on the right that are connected via Ethernet.
They are designed in a very different way to see the differences at a glance. The folder
symbols in the Adaptive Application are chosen to emphasize that its structure is more
like you know it from a personal computer.
Please keep in mind that this is just a conceptual illustration to get an understanding
without claim to completeness or technical correctness.
AUTOSAR Classic In AUTOSAR Classic an ECU is organized via different software components (SWC),
connected to the Basic Software via the runtime environment (Rte). So, there can be
many software components that use one AUTOSAR stack organized by an AUTOSAR
Operating System with predefined tasks, events, alarms, etc.
AUTOSAR Adaptive The organization within adaptive software is different. As there is used a POSIX-OS, the
organization within an ECU is more like a file system you know from PCs or MACs. So,
an Adaptive Application can be physically seen as a folder at a predefined place in a file
system of a POSIX-OS. This folder essentially contains an executable.
Two kinds of Adaptive In Adaptive, you can basically distinguish between two kinds of Applications, that are
Applications marked with blue and red in the illustration above - User Applications and BSW
Application. All Adaptive Applications communicate with each other what is essential for
the function of an ECU.
User Applications (blue)
From the functional point of view, you can compare the User Applications with the
Software Components (SWC) in AUTOSAR Classic. These applications are responsible
for the actual function of the ECU like e.g., Seat Adjustment or Lane Assist. They consist
of the functional customer software and the functional necessary parts of the BSW.
These parts of the BSW either implement a complete functionality or just enable
communication to other User Applications or to other parts of the BSW that are
implemented as BSW Applications.
BSW Applications (red)
In AUTOSAR Classic these are the Basic Software Modules.
In Adaptive, several basic software modules are implemented as Software Components
in their own Applications. These BSW Applications can in turn make use of other BSW
functionality in the same way as already mentioned for the User Applications above.
A good saying!
With MICROSAR Classic you embed the User Application (Software Components) into
the Basic Software.
With MICROSAR Adaptive you embed parts of the Basic Software once into each
individual Adaptive Application, where you need the provided functionality.
main{} has to be Any User Application need to have the function main{} that is also its entry point. This
provided by the function has to be provided by the customer.
customer One of the tasks of the main{} function is to initialize the BSW to be able to use its
services afterwards. During the initialization phase, the BSW reads in its configuration
data that is stored within JSON files (see light blue boxes).
The following illustration gives insight in a real folder structure of an Adaptive Application.
Basically, there are three folders: bin, etc and var.
bin The system expects the executables within the bin folder.
etc All configuration files like above mentioned JSON files are stored in the etc folder.
var In the standard, volatile data of the Adaptive Applications should be stored to the folder
var.
The folder var is just the standard folder. Per configuration you can change this as
necessary for your Adaptive Application.
Basically, a BSW Application follows the same rules as already described for User
Applications. One difference is that the BSW Applications are Adaptive Application that
provided by Vector as part of the MICROSAR Adaptive delivery. This delivery also
contains the actual application logic of the BSW Applications and also necessary parts. In
the case of PhM this is PhM Application Logic and vac.
PhM and vac as The PhM delivery contains a PhM Application file that represents the PhM Application
example Logic and another file that is the PhM lib.
Within the PhM lib the ara::phm is implemented that has to be used by all User
Applications and other BSW Applications that need the functionality of the PhM. The
ara::phm is not only an interface to the Phm, it also contains a part of the functionality of
the PhM. The rest is implemented in the PhM Application Logic.
Another example is the vac. It is an internal supporting component used by all other
components of MICROSAR Adaptive. Therefore, it is used in all applications that make
use of at least one other part of MICROSAR Adaptive.
In many cases, the ARXML is already given, e.g., by the OEM. In this case just leave
out the first step Authoring and continue with step 2 or 3.
According to AUTOSAR, the ARXML contains only necessary parts. There is no chance
to know before, which parts your software will need, so it is up to you to change and
extend the ARXML file.
Generation 3. Generation
This produces the code C++ and configuration files JSON.
Source code and JSON What are Generators?
files Generators take the user configration as an ARXML model. They extract the
configuration information and produce appropriate generated C++ code and runtime
configuration files. This code and runtime configuration instructs the BSW to exhibit the
configured behavior.
This can also be done via DaVinci Developer Adaptive or via command line tool.
IDE 4. User Application Development (IDE)
This step comprises the actual development and programming of your application logic
according to its required functions and is usually the major work for you to do.
As an example, this can be the code for the Lane Assist Application Logic, that reads ins
camera data and transforms this data into steering information.
Compile 5. Compile (and Link)
Your code (step 4), the previously generated files C++ (step 3) and the necessary parts
of the BSW Package are now compiled to an executable.
DaVinci Developer The following screenshot gives an overview of DaVinci Developer Adaptive and its views
Adaptive and functions.
Cluster Overview The illustration below shows an overview of the MICROSAR Adaptive functional clusters.
Cluster Description
COM Communication
SEC Security
DIAG Diagnostics
EXEC Execution Management
LOG Log and Trace
NM Network Management
OS Operating System
PER Persistancy
PHM Platform Health Management
SM Station Management
TSYN Time Synchronization
UCM Update and Configuration Management
There are a few rules you should take care when working with MICROSAR Adaptive.
Do not make any source code declarations: in the ::amsr or ::ara namespace or any
child namespace, unless a customization point is defined explicitly in our documentation
This usage restriction also applies to C++ namespaces configured in ARXML.
Rationale: Additional declaration in the mentioned namespaces may induce unintended
C++ name lookup results, hence leading to malfunction or compilation issues.
Only Use Public API: The API of the MICROSAR Adaptive product is built by public
classes, their methods, free functions, and types. Classes, their accessible methods,
free functions, and other types that are intended to be used by customer are annotated
with the documentation tag \vpublic. These items build the product public API.
Customer software shall just use the public API of MICROSAR Adaptive.
The private part shall not be used!
Make sure that the compiler settings match to the hardware (platform) where the
compiled code is executed.
To ensure binary compatibility, all parts of the MICROSAR Adaptive product, e.g.
platform (daemons) and applications (libraries) must be compiled with
> the same compiler version and
> the same compiler options.
Please make sure to consider the documentation of the MICROSAR Adaptive functions
and only pass valid pointers and enum values at all interfaces to MICROSAR Adaptive
components (see AUTOSAR C++ A7-2-1 for enum values).
Enums, pointers or arguments with invalid values that violate the contract of an API could
lead to immediate termination of the process or undefined behavior.
Except where explicitly specified by the documentation tag \threadsafe TRUE, thread
safety of functions cannot be assumed.
Except where explicitly specified by the documentation tag \reentrant TRUE, a function
shall not be interrupted during its execution and then called again before its previous
invocation has returned.
Vector makes no statement to the question, whether other code like STL, libc, OS
libraries or other third party libraries can be linked dynamically or must be linked
statically. This is up to the customer, possibly in consultation with the provider of the
other code.
If this requirement is not met, such that user processes are missing time intervals of the
clocks mentioned before, premature expiration of platform health manager deadlines can
occur. If the operating system exposes such behavior, it can be worked around by
suppressing supervision during suspend. Refer to using dedicated function group states
[8] for mode dependent supervision.
Local environment variables, that are used by one single component, are documented
in the corresponding Technical Reference.
Global environment variables have AMSR_ as name prefix and are used by multiple
components. They can either be feature switches or configuration options.
All environment variables with prefix AMSR_ are exclusively used by MICROSAR
Adaptive.
Do not define any environment variable with prefix AMSR_.
Modify only those environment variables with prefix AMSR_ that are listed either in the
according technical reference or here in this user manual. Make sure to follow the given
limitations for each environment variable.
You are responsible for the correct setting of environment variables with prefix AMSR_.
Use DaVinci Developer Adaptive to edit MEX parameters the same way as any other
AUTOSAR defined parameter.
Please consult Vector to find out about the current status of persistent data migration
during update.
3.6 TACO
3.6.1 Preface
Vector provides the build tools as example. They are neither intended nor qualified for
use in series production.
The example build tools as well as any of its modifications and/or implementations must
be tested with diligent care and must comply with all quality requirements which are
necessary according to the state of the art before their use.
MICROSAR Adaptive is shipped with the build tool TACO.
3.6.2 TACO
TACO TACO is a collection of tools written for and in CMake, and not a tool of its own. It is
written in CMake and also called from within CMake.
4 StepbyStep
Your workspace and the location may be located outside of <SIPDIR>. In this example
it is located in ~/src/amsr-vector-app-my-example.
Open a terminal session. To build with TACO set the environment variable
AMSR_SRC_DIR to the path of the BSW Package delivery.
$ export AMSR_SRC_DIR=~/src/adaptive-microsar
In the terminal change to the directory of amsr-vector-app-my-example and initialize
the build-cache with CMake:
$ cd ~/src/amsr-vector-app-my-example
$ cmake -S . --preset=gcc7_linux_x86_64 -C ${AMSR_SRC_DIR}/
CMakeConfig/linux_gcc7.cmake
The CMake command will initialize a build-cache in ./build/gcc7_linux_x86_64.
Run the code generators for both amsr and hwsrc prefixed targets and reload the build
cache:
$ cd build/gcc7_linux_x86_64
$ ctest -R '(amsr|hwsrc)_.*\.DvACfg.Generate' --progress --
parallel $(nproc)
$ cmake .
The main CMake target is the executable hwsrc_app. To build it together with its
MICROSAR Adaptive dependencies call the following (in the build-directory):
$ cmake --build . --target hwsrc_app --parallel $(nproc)
4.2.1.1 Models
./model/ All AUTOSAR xml files are located at ./model/
You can also use the DaVinci Adaptive Tool Suite for this.
1. Open your project in
startup config Inside the startup config set the startupconfig is defined. We defined an
option “-c“. This option is not used by the application. If you would like to use this, you
need to implement an argument parser.
4.2.2 CMake
Further information > HWSRC_APP_OUTPUT_NAME
> add_subdirectory
> taco_target_properties
> app/hello_world/taco.cmake
4.2.2.1 HWSRC_APP_OUTPUT_NAME
The variable HWSRC_APP_OUTPUT_NAME defines the name of the executable. TACO
evaluates variables named <target-upper>_OUTPUT_NAME to deduce the executable
name from the target name.
4.2.2.2 add_subdirectory
add_subdirectory("${AMSR_SRC}" "AMSR")
The AMSR stack is included as source sub-project. This means that:
> the AMSR stack and the hello world application share one build-directory
> both projects can be initialized and build with one CMake command
> the hello world application CMake files can directly reference targets from the AMSR
stack, `find_package` is not needed.
4.2.2.3 taco_target_properties
The content in these files includes the hello_world subdirectory and makes sure that the
MICROSAR Adaptive daemons are build and installed together with the hello world
application.
This is for demonstration purposes only. In a real world application you would build your
own daemons and provide your own configuration files.
4.2.2.4 app/hello_world/taco.cmake
The function dvacfg_file_gen() makes sure that the generators for the models are
run.
In this example the keyword argument OUTPUT lists generated CMake files instead of
source and config files. This has the advantage that you do not need to list each
generated file individually. dvacfg_file_gen() also adds the generated files as
dependency to the target sources of hwsrc_app.
4.2.3.1 main.cpp
This is the entry point of the process. This method will return zero if the execution was
successful.
1. The first step of the main method is to block all signals for this thread and all child
threads. It is necessary that only the signalhandler thread can react on signals.
2. The next step is the initialization of logging. This step is basically reading the
configuration files and is configuring the logging settings at runtime.
3. Afterwards the initialization of the logging is supposed to be successfully done. This
is checked by the if statement.
4. The following step is to create the application object and call the run method of it.
SIGTERM or SIGINT Afterwards the destructor is checking if exit was requested by sending SIGTERM or
SIGINT. If not the termination of the signal handler thread is triggered to shut down the
application. Finally, the destructor will wait till all threads have joined (Here just the signal
handler thread). Here you can add the logic to persist some data before shutting down.
StartSignalHandlerThre The method StartSignalHandlerThread is basically just starting the signal handler
ad thread, setting its name, and returning an ara::core::Result object containing either
the process id or the corresponding error.
Run The method Run is the logic of the application. If the application is reaching this point and
the initialization went well it is reporting the application state kRunning to the
Executionmanager. Afterwards the example is printing a log message
“Hello AUTOSAR Adaptive World”.
At the comment seen below you can add your application logic.
/* TODO(xxx) Your application code can be added here.
* TODO(xxx) You should terminate if exit_requested_ is true
*/
Change the output 1. Open the file application.cpp
2. Change the text of the LogInfo
Please ensure like mentioned in the comment that you are going to terminate if the
exit_requested_ member is set to true.
This is an example on how you can use the ErrorDomains in your project. If you are
not interested in just remove it.
5 AdvancedTopics
Signals are one of several IPC mechanisms available on POSIX systems. In contrast to
other IPC mechanisms, the only information that a POSIX Signal can carry is its
occurrence, there is no payload information associated with it. Despite their limited
information content, Signals are an integral part of the operation of a POSIX system (e.g.,
for signaling the request to terminate a process or to signal certain error conditions) and
must therefore be dealt with properly. Due to technical details of the underlying system,
correctly handling POSIX Signals is not trivial, and several approaches exist in the
literature. In the following, one possible approach is detailed that best suits the properties
of Adaptive MICROASR.
A defined signal handling is important as all code of MICROSAR Adaptive must be
protected against concurrently occurring POSIX Signals.
To ensure that POSIX Signals do not interfere with other operations, there shall be one
dedicated thread for signal handling that receives and processes Signals. To route all
Signals to this dedicated thread, all Signals (with few exceptions detailed later) shall be
blocked at the very beginning of a new process by setting an appropriate signal mask.
This shall be done before ara::core::Initalize().
The signal mask, that defines which Signals are blocked, will be inherited by any further
created thread. It has to be ensured that no additional threads are created before the
signal mask is correctly set. Note that there are classes in the ara::* namespace that
spawn threads immediately upon instantiation. Such classes shall not be instantiated as
static objects to prevent creating new threads before main (i.e., before the signal mask
can be set). For more information which ara::* objects create threads please refer to the
respective technical reference documents of the MICROSAR Adaptive components.
The only exception to this rule is the five Signals SIGABRT, SIGBUS, SIGFPE, SIGILL
and SIGSEGV. They shall not be blocked as these Signals are raised when an error
occurs where there is no reasonable way to continue program execution. According to
the POSIX specification, blocking these Signals would lead to undefined behavior. If one
of these Signals occurs, the default signal handling action, as defined by the underlying
POSIX environment, is performed. It is expected by MICROSAR Adaptive code that the
process is terminated immediately. Note that, depending on the configuration of the
POSIX system, a core dump file may be written to persistent storage. Note also that the
two Signals SIGSTOP and SIGKILL cannot be blocked. For any further information
please see the documentation of the underlying operating system.
To implement the dedicated Signal Handling Thread, it is recommended to use a call to
sigwait within a while-loop. This prevents synchronization problems due to the
asynchronous execution of dedicated signal handler functions. Sigwait has a signal set as
parameter that defines the Signals that it waits for. This signal set must contain at least
SIGTERM, as SIGTERM is sent by the Execution Management Cluster of the Adaptive
Platform (see [1] for information about the MICROSAR Adaptive Execution Management)
to initiate process termination. After receiving a Signal, the signal number shall be
queried, and an appropriate action must be executed. For example, after receiving
SIGTERM, an orderly shutdown of the application must be initiated. Note that all signals
specified in the signal set to wait for with sigwait must be blocked in the calling thread and
all other threads. Otherwise there is a race condition between the default processing and
sigwait. If the signal mask is set correctly at the beginning of the process, as described
above, the signals should be blocked.
The code example below shows how to enable an Adaptive Application to handle Signals
received from platform components or other applications, e.g. from the Execution
Management Cluster of the Adaptive Platform. The example Adaptive Application has two
threads, the main thread and one separate thread for signal handling. The sigwait
function is used to wait for the SIGTERM Signal. After receiving SIGTERM the Adaptive
Application shall be stopped in a proper way. Therefore, the other threads must be
notified. In the example this is realized by setting a global “exit requested” flag
(g_exit_requested).
The main function first calls the Init function. Within Init the function SetSigMask is called
where all Signals except SIGABRT, SIGBUS, SIGFPE, SIGILL and SIGSEGV are
blocked by setting a new signal mask. The signal mask, which is set during the call to
SetSigMask, is inherited by any further created thread. (Therefore, the signal mask
should always be set first in the main function.) After setting the signal mask, a new
thread for signal handling is spawned. The main thread then enters its run phase.
The Signal Handler Thread prepares the signal set that specifies the Signals that are
waited for. In the example only SIGTERM is specified. Subsequently, sigwait is called
with the prepared signal set within a while-loop. The function sigwait suspends execution
of the calling thread until at least one Signal specified in the passed signal set becomes
pending. When such a Signal occurs, the sigwait function returns. Thus, the Signal
Handling Thread wakes up and queries the signal number of the received Signal. If
SIGTERM was received, the Adaptive Application global “exit requested” flag is set to
true, and the Signal Handler Thread terminates. The main thread cyclically checks this
global flag. And as soon as the flag is set to true, it stops its run phase and enters the
shutdown phase. The main thread waits until all other threads are terminated and then
also terminates.
The code example below shows the recommended way to handle Signals. But some
parts can be varied:
> The global “exit requested” flag can be replaced by another synchronization primitive.
For example, this could be a pipe that is opened within Init and closed after receiving
SIGTERM.
> The sigwait call to wait for Signals can also be made within the main thread after
everything necessary has been set up, such as starting worker threads. In this case,
the Main thread becomes the dedicated Signal Handler Thread.
> In addition to SIGTERM the SIGINT Signal can be used to initiate process
termination. It is recommended not to use other Signals.
The sigwait function is not the only way to suspend the execution of a thread until a
Signal occurs but using sigwait is highly recommended for its ease of use.
#include <atomic>
#include <csignal>
#include <iostream>
#include <thread>
#include <vector>
#include <unistd.h>
void SignalHandlerThread() {
sigset_t signal_set;
int sig = -1;
if (0 != sigemptyset(&signal_set)) { /*empty the set of
signals*/
/* abort application because emptying signal set failed */
ara::core::Abort("Emptying signal set failed.");
}
if (0 != sigaddset(&signal_set, SIGTERM)) { /* add SIGTERM to
signal set */
/* abort application because adding SIGTERM to signal set
failed */
ara::core::Abort("Adding SIGTERM to signal set failed.");
}
void SetSigMask() {
bool success{true};
/* Block all signals except SIGABRT, SIGBUS, SIGFPE, SIGILL and
SIGSEGV
* because blocking them will lead to undefined behavior. Their
default
* handling shall not be changed (dependent on underlying POSIX
environment,
* usually process is killed and a dump file is written).
* Signal mask will be inherited by subsequent threads. */
sigset_t signals;
success = success && (0 == sigfillset(&signals));
success = success && (0 == sigdelset(&signals, SIGABRT));
success = success && (0 == sigdelset(&signals, SIGBUS));
success = success && (0 == sigdelset(&signals, SIGFPE));
success = success && (0 == sigdelset(&signals, SIGILL));
success = success && (0 == sigdelset(&signals, SIGSEGV));
success = success && (0 == pthread_sigmask(SIG_SETMASK,
&signals, nullptr));
if (!success) {
/* abort application because preparing or setting new signal
mask failed */
ara::core::Abort("SetSigMask failed.");
}
}
void Init() {
/* initialize signal handling by setting the signal mask */
SetSigMask();
void Shutdown() {
/* do application clean-up in here */
/* wait until other threads have joined */
std::cout << "Waiting for my threads." << std::endl;
for (std::vector<std::thread>::iterator it = gThreads.begin();
it != gThreads.end(); it++) {
it->join();
}
std::cout << "Terminating." << std::endl;
}
int main() {
Init();
while (!g_exit_requested) {
/* do some work here */
}
Shutdown();
return 0;
}
The user of MICROSAR Adaptive shall take additional measures to mitigate the
resulting risk of resource leaks and undefined behavior, such as long-term integration
tests while monitoring resource consumption and/or using tools for resource leak
detection.
The basic error handling principles are that no failure condition leads to undefined
behavior and any failure shall be detected as early as possible. In addition, side effects
caused by failed operations must be avoided.
In consequence, the following failure categories and reactions are distinguished see [9].
For possible exit codes, please refer to the subsection Exit Codes of the section Error
Handling in the corresponding Technical Reference document.
Different API may define specific error domains which come with their own set of error
codes. Beyond that the ara::core::ErrorDomain::SupportDataType might
transport additional information like an error subcode and/or a string literal holding
location information where the problem was detected first.
The Execution Manager requires that all application binaries are located within the
application base directory. This constraint can be circumvented by using symbolic links
that point from the application directory to the actual application binary, e. g. to /usr/
bin/strace. The path to the application base directory can be provided via command
line argument at the startup of Execution Manager.
> > ln --symbolic /usr/bin/strace <APPLICATION_BASE_DIRECTORY>/
app_A/bin/app_A
With introduction of chapter Configurable Executable Path for Applications, the usage of
symbolic links is no longer needed.
<PROCESS>
<SHORT-NAME>exampleProc</SHORT-NAME>
<ADMIN-DATA>
<SDGS>
<SDG GID="DvMex:ExecutableLocation">
<SD GID="executableLocation">/usr/bin/top</SD>
</SDG>
</SDGS>
</ADMIN-DATA>
<!-- Other elements omitted from this example. -->
</PROCESS>
<EXECUTABLE>
<SHORT-NAME>app_A_exe</SHORT-NAME>
<CATEGORY>APPLICATION_LEVEL</CATEGORY>
<REPORTING-BEHAVIOR>DOES-NOT-REPORT-EXECUTION-STATE</
REPORTING-BEHAVIOR>
</EXECUTABLE>
After a Non-Adaptive Application is started by the Execution Manager its state is Running
without knowing when it will be in a ready state and e. g. able to accept connection.
Dependencies on Non-Reporting Processes can lead to timing issues and are not
recommended.
Reporting Processes should always be preferred and are the default in Adaptive
AUTOSAR.
availability of a service that is provided by the Non-Reporting Process and reports the
Execution State Running when the service is actually available. The implementation of
the monitoring is user defined and differs for the individual services.
<SDG GID="DvMex:PeerIdentificationDisabled">
<SD GID="peerIdentificationDisabled">TRUE </SD>
</SDG>
</SDGS>
</ADMIN-DATA>
1. Optional: Debugging tools will likely increase the startup time of the process,
therefore you might have to increase the timeout values within the configuration of
the process you want to debug, otherwise Execution Manager's timeout violation
handling will be triggered. The example below defines 20 seconds for the enter and
exit timeout.
<TIMEOUT>
<ENTER-TIMEOUT-VALUE>20</ENTER-TIMEOUT-VALUE>
<EXIT-TIMEOUT-VALUE>20</EXIT-TIMEOUT-VALUE>
</TIMEOUT>
With these steps the Adaptive Application is started by the diagnostic/debugging tool and
in case of strace system calls are printed to the terminal.
This section describes the central (pre-)initialization and shutdown of the MICROSAR
Adaptive (Adaptive Runtime for Applications) framework.
In a nutshell
> The MICROSAR Adaptive API must not be used before
ara::core::Initialize() returned.
> The MICROSAR Adaptive API must not be used after
ara::core::Deinitialize() returned.
> The functions are available via ara/core/initialization.h.
> All calls to ara::core::Initialize() and ara::core::Deinitialize()
have to be done from the main thread when static memory initialization has
completed and before the statically initialized data is destructed.
> ara::core::Initialize() and ara::core::Deinitialize() are generated
for Adaptive Applications dependent to the model (ARXML) and the used
functionality.
> The MICROSAR Adaptive API must not be used while
ara::core::Deinitialize() has been called and is processing.
ara::core::Deinitialize():
// ...
int main() {
// static variables/objects initialized
int result_code {-1};
ara::core::Result<void> init_result
{ara::core::Initialize()};
return result_code;
} // static variables/objects will be deinitialized
The function ara::core::Initialize() coordinates the start-up of the MICROSAR
Adaptive framework. This includes e.g. the initialization of MICROSAR Adaptive
framework-specific data structures and spanning of background threads. Prior to this call,
no interaction with the ARA is allowed. Exceptions are documented. Prerequisite for this
call is that static memory initialization is completed (e.g. inside of function main()).
The function ara::core::Deinitialize() coordinates the shutdown of the
MICROSAR Adaptive framework. For a proper shutdown, it is expected that
ara::core::Deinitialize() is called before the statically initialized data is
destructed.
An error returned by ara::core::Deinitialize() is the only way for MICROSAR
Adaptive to report an error that is guaranteed to be available, e.g., in case ara::log has
already been deinitialized. The user is not expected to be able to recover from such an
error.
A call to an MICROSAR Adaptive API that depends on initialization is treated as a
violation, if the runtime is currently not initialized (i.e. before ara::core::Initialize() has
returned with success, or after ara::core::Deinitialize() was called).
For more details see [4].
This chapter presents the customer with existing possibilities to orderly shutdown AMSR
stack and then optionally to restart the stack or the whole MICROSAR Adaptive ECU.
Orderly Shutdown in contrast to an abrupt termination allows to switch off the MICROSAR
Adaptive stack while maintaining a defined state throughout the whole procedure. Being
in a well-defined Shutdown state is a necessary condition for the next smooth and
successful start of the MICROSAR Adaptive stack.
> The remaining processes of Execution Management and State Management are
terminated by the OS during shutdown or restart. If the intended behavior is to shut
down the Adaptive instance without shutting down the ECU, the shutdown application
must instead send SIGKILL to these processes and terminate afterwards.
> Upon Execution Manager termination OS informs its parent process, so it can take
actions, be it starting AMSR stack anew or switching off the rest of the ECU.
Automated Restart/
Shutdown procedure of
an Adaptive ECU
Figure 17: Automated Orderly Shutdown and Restart Triggered by State Manager
Automated Shutdown becomes particularly useful if there is a need to switch off or restart
AMSR stack without shutting down the Operating System or the entire ECU. Examples of
such scenarios include:
> Restart after AMSR stack update.
> Restart due to some problem occurred in AMSR stack. It is anticipated in this case
that some Function Groups won’t switch to state Off smoothly. Use of Automated
Shutdown that independently handles such irregularities, is likely to reduce State
Management error handling complexity.
From this moment Rapid Shutdown progresses in the same manner as in the case of
Automated Orderly Shutdown.
It’s important to note that the applications are killed in the most plain and unconditional
manner: there is not any particular order in which SIGKILL is sent; Execution
Dependencies and Exit Timeouts are not respected as well.
Rapid Shutdown is most appropriate for the situations when MICROSAR Adaptive stack
should be brought down as quickly as possible and the inter-dependencies between the
Function Groups or processes are not a concern.
For details, please refer to the Integration chapter of the corresponding Technical
Reference document.
This chapter describes additional restrictions and expectations regarding the use of
iterators, C-style strings and ranges when using MICROSAR Adaptive.
5.10.1 Iterators
> The ISO C++ definition of a valid range ([§24.2.1.7] see [3]) is insufficient to prevent
out-of-bounds access.
> Therefore, make sure that a pair of iterators, which are supposed to define a valid
range, are created from the same object.
> In addition, make sure that no type defines its iterators in a way, which would cause
out-of-bounds access.
5.10.3 Ranges
In APIs which accept multiple ranges in form of iterator or pointer pairs, make sure that
the ranges do not overlap.
exit system call. Abnormal terminations in a POSIX system (see [2]), for example process
aborts triggered by unhandled exceptions, illegal arithmetic operations or machine
statements, null pointer dereferences, are raised using signals.
The operating system kernel promotes both information to the calling parent process in
the exit status word.
Process Termination
Data Flow in a POSIX
System
In the figure above the green arrows represent normal termination while red arrows are
examples for abnormal terminations.
of all child process terminations. This includes both normal and abnormal terminations. It
allows a user provided error handler application to extract the termination conditions
using POSIX defined macros, e.g. WIFEXITED, WEXITSTATUS, WIFSIGNALED,
WTERMSIG.
Termination Notification
Performed by the
Execution Manager
In the figure above processes with blue boundaries are examples of user provided
applications. Processes with red boundaries are examples of MICROSAR Adaptive base
software components.
5.11.1.2.1 Examples
In case of systemd using on-failure or on-abnormal as arguments of restart or
watchdog options include abnormal terminations.
When starting applications from shell or shell scripts using bash, ksh, or zsh, command
lists with elements linked with && and || operators will detect both non-zero return values
and abnormal terminations.
5.11.2 Recovery
Recovery from unexpected errors must be handled by a user provided failure handling
application.
Vector recommends resetting the ECU or the ECU partition, respectively, in response to
abnormal terminations. Unexpected errors usually indicate that an application could not
return to an operable state for unknown reasons. It cannot be guaranteed, that restarting
only specific processes would return the entire stack into an operational state.
Unrecoverable error conditions raised directly by the operating system kernel, not
involving the C++ runtime environment, will be reported using their corresponding signals,
e.g. SIGSEGV, SIGFPE, SIGILL.
AUTOSAR is publishing new API definitions for functional clusters with every AUTOSAR
AP release. These are neither separated into release-specific namespaces, nor required
to retain backward compatibility.
In the MICROSAR Adaptive implementation, public APIs are based on a specific release,
and are extended on demand according to AUTOSAR updates, if compatibility can be
retained. Once the standard definition changes in an incompatible way, MICROSAR
Adaptive must separate implementations and provide a user choice, which AUTOSAR AP
to use in functional cluster standard namespaces.
Please refer to the section Supported AUTOSAP API Releases in the individual
technical references of MICROSAR Adaptive API components, if available.
ARXML snippet selecting the ara::com API from AUTOSAR AP release 20-11:
<EXECUTABLE>
<ADMIN-DATA>
<SDGS>
<SDG GID="DvMex:BswVersionedApi">
<SD GID="amsrAraComApi">r20_11</SD>
</SDG>
</SDGS>
</ADMIN-DATA>
The corresponding model extension schema read by the DaVinci Developer Adaptive for
presenting and validating selections is provided in the ApplicationBase component in
amsr-vector-fs-applicationbase/mex/MexDefBswVersionedApi.arxml.
For the integration of versioned API components into an application CMake build
configuration refer to the appropriate technical references in your TechnicalReference
folder of your delivery
Please refer to chapter Module|Find Modules and the description of Function
dvacfg_file_gen in the TechnicalReference_TACO.pdf.
Each MICROSAR Adaptive API component providing selectable versions will also
define a default version used in absence of an explicit user selection. Despite this,
CMake code in the application build configuration still needs to be prepared to make
use of that.
--genArgUniversal "enableMultiTarget=true"
Initial built time is not improved. Target-independent object files need to be cached for
subsequent linking of executables.
The achievable improvement in the overall rebuild time depends on the configured
caching mechanism in the build system.
When the file classification is enabled, following compile dependencies should be applied
to prevent a recompilation of application code upon deployment changes:
Multiple Processes per Executable in a single ARXML model are still not supported
(see Multiple Processes per Executable Not Supported). To handle the deployment
configuration of multiple machines, these specific model parts must be split to different
model files and used as input for different generator runs.
Generation of non- MICROSAR Adaptive supports generation of non-deployed services through the boolean
deployed services generator argument generateNonDeployedServices. A service is considered non-
deployed if the configuration model only contains design information for that service. If
DaVinci Configurator Adaptive Command Line Tool is used to run the generators, then
the argument can either be set individually for each generator or for all of them at once.
--genArgUniversal "generateNonDeployedServices=true"
For more information, please refer to the technical references for the respective models.
Generation of non-deployed services has a negative impact on the initial build time due
to the compilation of additional files.
A software component may contain parts of source code of lower quality than originally
specified in the component scope.
These parts are disabled by default but can be enabled if necessary.
The reason that a component may contain low lower graded source code is, for example,
that new developed code should be made available for beta testing or to provide an ASIL
component with additional functionality when used in a QM context.
However, it is essential that beta code does not enter production and that QM code is
never used in an ASIL context.
Therefore, these pieces of code must be explicitly activated via configuration.
The configuration is not done per feature, but at the application/executable level, usually
via the ARXML model, i.e. H. when Beta is enabled for a component, all included beta
code can be used.
For details on how to enable the downgraded source code of a specific component, see
the component's corresponding BETA ESCAN and Technical Reference.
When enabled, the status information is passed to the compiler via the build system as a
flag: AMSR_LG_BETA_ENABLED and/or AMSR_LG_QM_ENABLED.
Attempting to access the lower quality code, even if it is not enabled, will result in
deprecation warnings and/or unresolved symbols in the linking phase.
6 Additional Information
Find the Cheat Sheets in the DaVinci Adaptive Tool Suite via: Help|Cheat Sheets…
Every machine has one Some/IP Daemon or better said, every instance of AUTOSAR
Adaptive software has one Some/IP Daemon. An instance can e.g. also be a partition
on a hypervisor.
Service Discovery To make sure that a client knows which services are currently available, Some/IP-SD
(Service Discovery) provides two mechanisms that allow the dynamic discovery of
services.
> An Offer Service enables the server to offer all services it offers in the Network.
> The Find Services allows the Clients to ask for available service instead.
If you are familiar with AUTOSAR Classic, knowing and understanding of the signal-
based data transmission approach is key for understanding a main part of the
AUTOSAR Adaptive concept and key for understanding the following content.
Abbreviation Description
AA Adaptive Application
API Application Programming Interface
ARA AUTOSAR Runtime for Adaptive
Applications
ARXML AUTOSAR XML
AUTOSAR Automotive Open System Architecture
BSW Basis Software
CPU Central Processing Unit
DCM Diagnostic Communication Manager
DEM Diagnostic Event Manager
DET Development Error Tracer
DID Data Identifier
DLT Diagnostic Log and Trace
DM Diagnostic Manager
DTC Diagnostic Trouble Code
ECU Electronic Control Unit
GB Giga Byte
GHz Giga Hertz
ICAS In Car Application Server
IP Internet Protocol
IPC Inter Process Communication
MB Mega Byte
MHz Mega Hertz
NRC Negative Response Code
OEM Original Equipment Manufacturer
OS Operating System
POSIX Portable Operating System Interface
PSE POSIX System Environment Profile
Abbreviation Description
REST Representational State Transfer
RTE Run Time Environment (Classic
AUTOSAR context)
SOME/IP Scalable service-Oriented MiddlewarE
over IP
SRS Software Requirement Specification
SWC Software Component
SWS Software Specification
TLV Tag-Length-Value
UDS Unified Diagnostic Services
The following table lists the documents that are referenced within this User Manual.
www.vector.com