UML and SysML to AUTOSAR Runnable Code - UML Model Allocation to AUTOSAR design

This section describes the UML and SysML model allocation to AUTOSAR design.

This page discusses:

Glossary

Acronym Definition
SPO Software Production Operation
BL Behavior Layer
ML Middleware Layer
BSM Behavior Specific Middleware
TSM Target Specific Middleware

Referenced Documents

Document Internal Reference
UML & SysML to AUTOSAR Runnable Code - Class Code Generator Specification [1]

General Concepts

UML & SysML to AUTOSAR Runnable Code generator is an operation generating C code from AUTOSAR architecture designed following UML and SysML standards.

This specification document is focused on the generation of code resulting on UML model allocation to AUTOSAR design.

Supported Elements

Here is an exhaustive list of elements used by the operation UML & SysML to AUTOSAR Runnable Code to produce the artefacts with a summary of the purpose and impact.

Element Description AUTOSAR specific
Class Element for which a cpp file is generated
Operation There is 2 ways to use the Operation element: - Member of a class representing a method. - Member of an Interface or an Interface Block
Property There is 2 different purposes for the property element: - A property can be a member of a class representing an attribute. Can be public, protected or private. - A property can be a member of an Interface referenced by a port and representing a data transmitted via that port.
Classifier Behavior A behavior can be a State Machine, an Activity or an Opaque Behavior. The behavior can be in a class itself and attached to an operation.
Interface There is 2 different purposes for the interface element: - Element describing elements transmitted through a Port element - Abstract class which can be realized by another class (use the Interface Realization)
SoftwareAtomicComponent An indivisible AUTOSAR software component implementing runnables and ports.
ARSoftwareAtomicComponent AUTOSAR atomic software component with internal behavior. x
ARRunnableEntity Executable unit of functionality within a component. x
AROperationAccess Description of runnable access to a client-server operation. x
ARDataAccess Description of runnable access to sender-receiver or parameter data. x
DataElement Typed unit of data transported through an interface.

Validation Constraints

No validation constraints

Code Generator Specification

This section is divided in 2 parts:

  • The generated files specification
  • The behavior specification

Files Specifications

<ARComponentName>.c

File Naming and Structure

See chapter Code Generator Specification / Files Specifications / <SoftwareAtomicComponentName>.c in [1].

In the following requirements:

  • <ARComponentName> denotes the name of the AUTOSAR software component.

In the context of UML model allocation to the AUTOSAR design, the file <ARComponentName>.c includes at least the following headers:

  • Headers related to UML classes
#include "<UMLClassName>_cls.h"
  • Headers related to UML interfaces
#include "<UMLInterfaceName>_itf.h"
  • Headers related to the Target Abstract Layer (TAL)
#include "Tal_struct.h"
#include "tal_Timer.h"
#include "Tal_Events_Handler.h"
  • Headers related to the Communication Scheduling Environment (CSE)
#include "Cse_cfg.h"
#include "Cse_objects.h"
  • Header related to RTE
#include "Rte_<ARComponentName>.h"

Following standard headers are also included:

#include <stdbool.h>
#include <string.h>

Semantic Code Specifications

In the following requirements:

  • <ARComponentName> denotes the name of the AUTOSAR software component.

Target Abstraction Layer (TAL)

The Target Abstraction Layer (TAL) provides an abstraction of target services, enabling the implementation of behavior independent of any specific target platform. It abstracts a set of services that may be required by the generated code. The generated code relies on a TAL instance local to the atomic component. This TAL manages local timing for the dispatching of timing events and the overall event dispatch mechanism.

The definition of the TAL for the current component is implemented in a dedicated code section.

/**********************************************************************************
 * Target Abstraction Layer Section
 **********************************************************************************/

Variables, macros, and functions related to the TAL are generated within this code section.

Event Triggering Function trigSignal

The generator creates a function that handles incoming events and triggers the targeted RunnableEntities according to the AUTOSAR configuration.

The generated function is named trigSignal.

The function trigSignal is internal to the file <ARComponentName>.c.

The function processes each incoming event in the event pool and triggers the appropriate RunnableEntities according to the AUTOSAR configuration.

/**********************************************************************************
 * Function triggering signals
 **********************************************************************************/
void trigSignal(Tal_EventPool *pool, Tal_Event* ev) {
    // Trigger signals transmitted to other behaviors
    if(pool == &pmyButton->button_cls_btn_stm_eventPool){
        switch(ev->eventId) {
                default: {
                    /* default */
                    break;
                }
            }
        }
    if(pool == &pmyController->controller_cls_ctl_stm_eventPool){
        switch(ev->eventId) {
                case CONTROLLER_CLS_EVENT_T_evPushPressedAndReleased: {
                    Rte_IrTrigger_Flashlight_button_run_itp_ctl_stm_se_evPushPressedAndReleased();
                    break;
                }
                case CONTROLLER_CLS_EVENT_T_TE_controller_cls_ctl_stm_1: {
                    Rte_IrTrigger_Flashlight_controller_run_itp_ctl_stm_te_5000ms();
                    break;
                }
                case CONTROLLER_CLS_EVENT_T_TE_controller_cls_ctl_stm_3: {
                    Rte_IrTrigger_Flashlight_controller_run_itp_ctl_stm_te_500ms();
                    break;
                }
                default: {
                    /* default */
                    break;
                }
            }
        }
}

Example: Definition of <ARComponentName>_trigSignal function

TAL_Handler_<ARComponentName>

The TAL Handler Runnable Entity is an extra periodic runnable added by the generator and required by the TAL.

The Runnable Entity function is named: TAL_Handler_<ARComponentName>

The function TAL_Handler_<ARComponentName> initializes the TAL environment, manage the local time of the TAL aligned with the system, and dispatch events, such as Change Events or Timing Events, to the relevant behaviors (e.g., state machines).

FUNC(void, <ARComponentName>_CODE) TAL_Handler_<ARComponentName>(void){

    /* Instantiate the Target Abstraction Layer */
    initRun();

    /* Timer Service */
    tal_incrementTick();

    /* Events Handler Service */
    tal_dispatchEvents();

}

Example: Definition of TAL_Handler_<ARComponentName>

Component initialization

The generator creates a function for invoking the initialization of:

  • the Target Abstraction Layer (TAL) related to the component, and
  • the Communication Scheduling Environment (CSE).

The generated function is named <ARComponentName>_init.

The initialization performed by <ARComponentName>_init is executed only once, implying that the function is not reentrant.

The definition of <ARComponentName>_init is placed before any RunnableEntity definition in the file <ARComponentName>.c.

/**********************************************************************************
 * Component Initialization
 **********************************************************************************/
 static void initRun(void){
    static bool initDone = false;
    if(!initDone){
        // Instantiate the Target Abstraction Layer
        Tal_init(&TAL_NAME);
        // Initialize the Communication Scheduling Environment
        Cse_component_instances_init();
        Cse_component_relations_init();
        Cse_components_init();
         initDone=true;
    }
}

where:

  • Tal_init: Function for initializing TAL for the current component.

  • TAL_NAME: TAL instance for the current component.

  • Cse_component_instances_init: Function building the component instances (allocation, construction, default values).

  • Cse_component_relations_init: Function configuring the relations between the component instances, then mapping the communication APIs to them.

  • Cse_components_init: Function calling all the initialization functions as configured in the model.

The function initRun() is called by every RunnableEntity function.

The call to initRun() occurs after the declaration of variables related to RTE APIs and before the invocation of input RTE APIs.

FUNC(void, <ARComponentName>_CODE) <RunnableName>(void)
{
    /* Local data declaration */
    VAR(<TypeName>, AUTOMATIC) data_<RteApiRootName>_<PortName>_<DataName>;

    /* Runnable Initialization */
    initRun();

    /********************************************************************************/
    /* BEG_USER_CODE(user_data_declaration_<RunnableId>) do not remove */
    /* Add your data declarations here */
    /* END_USER_CODE(user_data_declaration_<RunnableId>) do not remove */
    /********************************************************************************/

    data_<RteApiRootName>_<PortName>_<DataName> = Rte_IRead_<PortName>_<DataName>();

    ...
}

Example: Call of initRun in the body of RunnableEntity

Properties or Operations allocation to AUTOSAR Access Points

The following figure illustrates how a Property or an Operation can be allocated in CATIA Magic.

Allocation of properties and operations to AUTOSAR access points UMLandSysMLtoARAllocation_Properties_Operations_to_AUTOSAR_Access_Points The allocation of a class instance to an AUTOSAR software component is represented in the CATIA Magic model by a UML Software Mapping relation between the class instance and the AUTOSAR software component. A Software Mapping relation is derived from Abstraction relation, with two additional parameters: - context: refers to a class instance which classifier must be class which owns property/operation - orderId: sets order in which mapping information is handled in runnable entity

Properties allocation

If the allocation fulfills the following conditions:

  • the property is allocated to an AUTOSAR Data Access corresponding either to
    • an Inter-Runnable Variable Access, or
    • a Shared/Per Instance Variable Access, or
    • a Parameter Access, or
    • a Sender Receiver Access, and
  • the AUTOSAR Data Access corresponds to a data reception (input property), and
  • the variable representing the Data Element is declared as a value object of type T (VAR(T, ...)),

then the property is assigned as follows:

VAR(<TypeName>, AUTOMATIC) data_<DataName>;
data_<DataName> = Rte_<RteApiName>();
<PointerNameToClassInstance>-><Property> = data_<DataName>;

where:

  • <TypeName> is the type of the Data Element
  • <DataName> is the name of the Data Element (see document [1])
  • <RteApiName> is the name of the corresponding RTE API (see document [1])
  • <PointerNameToClassInstance> denotes the name of the pointer referring to the class instance.
  • <Property> denotes the allocated property

If the allocation fulfills the following conditions:

  • the property is allocated to an AUTOSAR Data Access corresponding either to
    • an Inter-Runnable Variable Access, or
    • a Shared/Per Instance Variable Access, or
    • a Parameter Access, or
    • a Sender Receiver Access, and
  • the AUTOSAR Data Access corresponds to a data reception (input property), and
  • the variable representing the Data Element is declared as a pointer to constant Data Element data (P2CONST(T, ...)),

then the property is assigned as follows:

P2CONST(<TypeName>, AUTOMATIC, RTE_APPL_DATA) data_<DataName>;
data_<DataName> = Rte_<RteApiName>();
<PointerNameToClassInstance>-><Property> = *data_<DataName>;

where:

  • <TypeName> is the type of the Data Element
  • <DataName> is the name of the Data Element (see document [1])
  • <RteApiName> is the name of the corresponding RTE API (see document [1])
  • <PointerNameToClassInstance> denotes the name of the pointer referring to the class instance.
  • <Property> denotes the allocated property

If the allocation fulfills the following conditions:

  • the property is allocated to an AUTOSAR Data Access corresponding either to
    • an Inter-Runnable Variable Access, or
    • a Shared/Per Instance Variable Access, or
    • a Parameter Access, or
    • a Sender Receiver Access, and
  • the variable representing the Data Element is declared as a value object of type T (VAR(T, ...)), and
  • the variable representing the Data Element is passed by pointer to the corresponding RTE API,

then the assignment is performed according to the direction of the AUTOSAR Data Access as follows:

  • for an AUTOSAR Data Access corresponding to an input property:
    VAR(<TypeName>, AUTOMATIC) data_<DataName>;
    Std_ReturnType retdata_<RteApiName> = RTE_E_OK;
    retdata_<RteApiName> = Rte_<RteApiName>(&data_<DataName>);
    <PointerNameToClassInstance>-><Property> = data_<DataName>;
    
  • for an AUTOSAR Data Access corresponding to an output property:
    VAR(<TypeName>, AUTOMATIC) data_<DataName>;
    Std_ReturnType retdata_<RteApiName> = RTE_E_OK;
    data_<DataName> = <PointerNameToClassInstance>-><Property>;
    retdata_<RteApiName> = Rte_<RteApiName>(&data_<DataName>);
    

where:

  • <TypeName> is the type of the Data Element
  • <DataName> is the name of the Data Element (see document [1])
  • <RteApiName> is the name of the corresponding RTE API (see document [1])
  • <PointerNameToClassInstance> denotes the name of the pointer referring to the class instance.
  • <Property> denotes the allocated property

If the allocation fulfills the following conditions:

  • the property is allocated to an AUTOSAR Data Access corresponding either to
    • an Inter-Runnable Variable Access, or
    • a Shared/Per Instance Variable Access, or
    • a Parameter Access, or
    • a Sender Receiver Access, and
  • the variable representing the Data Element is declared as a value object of type T (VAR(T, ...)), and
  • the variable representing the Data Element is passed by value to the corresponding RTE API,

then the assignment is performed according to the direction of the AUTOSAR Data Access as follows:

  • for an AUTOSAR Data Access corresponding to an input property:
    VAR(<TypeName>, AUTOMATIC) data_<DataName>;
    Std_ReturnType retdata_<RteApiName> = RTE_E_OK;
    retdata_<RteApiName> = Rte_<RteApiName>(data_<DataName>);
    <PointerNameToClassInstance>-><Property> = data_<DataName>;
    
  • for an AUTOSAR Data Access corresponding to an output property:
    VAR(<TypeName>, AUTOMATIC) data_<DataName>;
    Std_ReturnType retdata_<RteApiName> = RTE_E_OK;
    data_<DataName> = <PointerNameToClassInstance>-><Property>;
    retdata_<RteApiName> = Rte_<RteApiName>(data_<DataName>);
    

where:

  • <TypeName> is the type of the Data Element
  • <DataName> is the name of the Data Element (see document [1])
  • <RteApiName> is the name of the corresponding RTE API (see document [1])
  • <PointerNameToClassInstance> denotes the name of the pointer referring to the class instance.
  • <Property> denotes the allocated property
Operations allocation

In the following requirements:

  • <ARComponentName> denotes the name of the AUTOSAR Software Component.
  • <UMLOperationName> denotes the name of the UML Operation allocated to an AUTOSAR Operation Access.
  • <UMLOperationNotARName> denotes the name of a UML Operation not allocated to any AUTOSAR Operation Access (i.e., not depending on AUTOSAR).
  • <UMLClassInterfaceName> denotes the name of the UML Class or UML Interface owning the operation allocated to the AUTOSAR Operation Access.
  • <AUTOSAROperationName> denotes the name of the AUTOSAR Operation referenced by the AUTOSAR Operation Access to which the UML Operation is allocated.

Function pointers to <UMLOperationName> and <UMLOperationNotARName> are added to the virtual tables of the UML Class/Interface:

  • in the file <UMLClassInterfaceName>_itf.h:
typedef struct {
    void (*<UMLOperationName>_)(struct <UMLClassInterfaceName>_itf_* self);
    void (*<UMLOperationNotARName>_)(struct <UMLClassInterfaceName>_itf_* self);
    ...
} <UMLClassInterfaceName>_vtable;
  • in the file <UMLClassInterfaceName>.h:
typedef struct {
    void (*<UMLOperationName>_)(struct <UMLClassInterfaceName>_* self); 
    void (*<UMLOperationNotARName>_)(struct <UMLClassInterfaceName>_* self); 
} Led_vtable;

Both functions <UMLOperationName> and <UMLOperationNotARName> are declared in file <UMLClassInterfaceName>.h.

void <UMLOperationName>(struct <UMLClassInterfaceName>_* self);
void <UMLOperationNotARName>(struct <UMLClassInterfaceName>_* self);

Both functions <UMLOperationName> and <UMLOperationNotARName> are added in the Virtual Table of the UML Class/Interface in file <UMLClassInterfaceName>.c.

<UMLOperationNotARName> does not depend on AUTOSAR. Its definition is done in file <UMLClassInterfaceName>.c.

If a UML Operation is allocated to an AUTOSAR Operation Access (and therefore depends on AUTOSAR), then the definition of the UML Operation <UMLOperationName> is provided in the file <ARComponentName>.c. The purpose is to separate functions that depend on AUTOSAR from those that do not.

void <UMLOperationName>(struct <UMLClassInterfaceName>_* self)
{
    Rte_Call_<AUTOSAROperationName>();
    Rte_Result_<AUTOSAROperationName>();
}

Example: Definition of AUTOSAR dependent function

If a UML Operation is allocated to an AUTOSAR Operation Access (and therefore depends on AUTOSAR), then the UML Operation <UMLOperationName> is declared as extern in the file <UMLClassInterfaceName>.c.

extern void <UMLOperationName>(struct <UMLClassInterfaceName>_* self);

Behaviors allocation to Runnable Entities

Allocation of behaviors to AUTOSAR runnable entities

The allocation of a behavior to an AUTOSAR runnable entity is represented in the CATIA Magic model by a UML Abstraction relation between the behavior and the corresponding AUTOSAR runnable entity.

If a UML Statemachine is allocated to an AUTOSAR runnable entity, its main function <StatemachineName>_main is called after the invocation of input RTE APIs and before the invocation of output RTE APIs.

FUNC(void, <ARComponentName>_CODE) <ARRunnableEntityName>(void)
{
    ...

    // Invocation of input RTE APIs
    data_<DataName1> = Rte_<RteApiName1>();
    <PointerNameToClassInstance>-><Property1> = data_<DataName1>;

    // appel statemachine button
    <StatemachineName>_main(<PointerNameToClassInstance>);

    // Invocation of output RTE APIs
    data_<DataName2> = <PointerNameToClassInstance>-><Property2>;
    retdata_<RteApiName2> = Rte_<RteApiName2>(data_<DataName2>);

}

where:

  • <ARComponentName> denotes the name of the AUTOSAR software component.
  • <ARRunnableEntityName> denotes the name of the AUTOSAR runnable entity.
  • <StatemachineName>_main denotes the main function of the statemachine
  • <PointerNameToClassInstance> denotes the identifier of the pointer referencing the class instance.
  • <RteApiName#> denotes the name of the RTE API
  • <Property#> denotes the name of a property allocated to <DataName#>