UML and SysML to C++ - Assembly Code Generator Specification

This section describes the UML and SysML to C++ assembly code generation.

This page discusses:

Glossary

Acronym Definition
SPO Software Production Operation
TAL Target Abstraction Layer

Referenced Documents

Document Internal Reference
Targeted Application Concept [1]
C++ Code Architecture Specification [2]
UML and SysML to C++ - Operation Specification [3]
UML and SysML To Code Concepts [4]
UML and SysML to C++ - Interface Code Generation Specifications [5]

General Concepts

Assembly generation is part of the components layer generation as presented in [1]. It is invoked during execution of UML to C++ operation as presented in [3] and [4].

This document focuses on the C++ code generation for the assembly and the generation of the communication and scheduling component.

The generated code is composed of two parts. The first is managing the scheduling of the behaviors and the communication between the components.

The second part is related to the hooks mechanism. Hooks are a mechanism to allow user-specific implementation on any kind of communication points. When a data or an operation is invoked from a component to another one, it is possible to customize the behavior to read or a write a data. This mechanism is also used in the context of the FMU to exchange data between the executed model and the FMU interfaces.

The hooks mechanism relies on one start function and one return function for each communication point.

The start function is called at the beginning of the communication function and the return function is implemented at the end of the function. Functions are enabled by a declaration mechanism, which relies on a system of declaration.

Supported Elements

Here is an exhaustive list of elements used by the code generator to produce the code with a summary of the purpose and impact.

Element Description
UML Class SysML Block The root elements of the generation. It contains classes which compute behavior and exchange data. An Instance is automatically generated for each root element and aggregated / associated elements.
UML Instance Specification Instance Specification can be used as root elements of generation. Purpose is to create predefined instances of objects.
UML link In case of Instance Specification, links are used to define relations between instances.
UML Port SysML Flow Port SysML Proxy Port A port is used to declare communication elements exchanged by a class.
UML Interface SysML Interface Block -
Connection A connection is used to connect 2 ports.
Property A property is used in the context of 2 objects: - In an Interface to define data transmitted through a port - In a class to instantiate another class
SysML Flow Property A flow property is used in the context of an Interface Block to define data transmitted through a port
Classifier Behavior Behavior that is automatically scheduled depending on the schedule information that is configured for it. The behavior can be a statemachine, an activity, or an opaque behavior.
Signal
UML Component When applicable, this element is considered as an UML class

Code Generator Specification

This section is divided in 2 parts:

  • The generated files specification
  • The behavior specification

Files Specifications

The generated code is composed of 2 files for the scheduling of behaviors and the communication between components:

  • Cse_cfg.h
  • Cse.cpp
  • Dedicated section in <ClassName>.h

The generated code is also composed of 3 files implementing the hooks mechanism:

  • Cse_hook.h
  • Cse_hook_cfg.h
  • Cse_hook_usr.cpp

The general requirements related to file content are described in [2].

Cse_cfg.h

Cse_cfg.h header file has a fixed name. This file is indeed included from the target abstraction layer.

This header file includes files defining types used at interface, declares the predefined tasks IDs, and the behaviors IDs.

A macro is generated to read the content of the file as a C++ declaration if it is included directly or indirectly from a C++ file.

Rationale: During compilation, information of this file must be treated as C++ information.

/* Macro to prevent error if file is included from a C++ file */
#ifdef __cplusplus
extern "C" {
#endif

Example: Cpp macro

#include to the file task_descriptor.h describing the structure defining a task. This definition depends on the target and is delivered by the target abstraction layer.

#include directives are generated for all class-type files that are instantiated, either directly or indirectly, by the root class.

/**********************************************************************
 * Includes declaration
 **********************************************************************/
#include "task_descriptor.h" /* task_descriptor declaration */

#include "Class1_type.h"
#include "Class2_type.h"

Example: Includes

Macro is defined to identify the number of predefined tasks depending on the configuration of the model.

A predefined task is a task precalculated by the code generator to execute behaviors.

A collection of macros is defined to identify a unique ID for each task.

A collection of macros is defined to identify the position of each behavior in tasks.

/**********************************************************************
 * Macros declaration
 **********************************************************************/
/*
 * Number of predefined tasks
 */
#define NUMBER_OF_TASKS 1

/*
 * Tasks ids definition
 */
#define TASK_0 0
#define TASK_1 1

/*
 * Behaviors in tasks position index definition
 */
#define TASK_0_UC1_p1_beh 0
#define TASK_1_UC1_p2_beh 0

Example: Task and behaviors definition

4 functions are declared with the purpose of being invoked by the TAL layer.

/*
 * Build the component instances: allocation, construction and default values.
 * Relations between instances and mapping of the communication APIs are configured apart,
 * by Cse_component_relations_init.
 * First function to call before Cse_component_relations_init, Cse_task_descriptors_init & Cse_components_init
 */
void Cse_component_instances_init(void);

/*
 * Function configuring the relations between the component instances, then mapping the
 * communication APIs to them.
 * Function to call just after Cse_component_instances_init and before Cse_task_descriptors_init & Cse_components_init
 */
void Cse_component_relations_init(void);

/*
 * Function configuring each task.
 * Function to call just after Cse_component_instances_init & Cse_component_relations_init
 */
void Cse_task_descriptors_init(void);

/*
 * Function calling all the init functions as configured in the model.
 * To be called after Cse_component_instances_init, Cse_component_relations_init & Cse_task_descriptors_init
 */
void Cse_components_init(void);

External declaration to task_descriptors variable to access it from the TAL layer.

/*
 * Extern declaration of task_descriptors variable for its access from the TAL.
 */
extern task_descriptor task_descriptors[NUMBER_OF_TASKS];

Cse.cpp

Cse.cpp contains the mapping of behaviors on tasks and the implementation of the communication between the components.

#include to the file Tal.h is generated to tal_allocate() function implemented by TAL layer.

#include to the file Cse_cfg.h is generated to access to macros related to system configuration.

#include to the file Cse_hook.h is generated to configure hooks.

An <INCLUDES> section is generated containing includes to the required class definitions.

To get more information on <INCLUDES>, see the dedicated section in chapter 9.2.

/**********************************************************************
 * Includes declaration
 **********************************************************************/
#include "Tal.h" // tal_allocate
#include "Cse_cfg.h"
#include "Cse_hook.h"
#define CSE_C /* Macro to include only some specific parts of include files */

<INCLUDES – See chapter 9.2>

Example: Includes

An INSTANCES DECLARATION SECTION section is generated for variables declaration.

To get more information on INSTANCES DECLARATION SECTION, see the dedicated section in chapter 9.2.

The variable containing the description of the predefined tasks task_descriptors is declared as a table. The size of the table is equivalent to the number of predefined tasks in the application.

/*******************************************************************************
 * Local Members Declaration 
 *******************************************************************************/
<INSTANCES DECLARATION SECTION – See chapter 9.2>

task_descriptor task_descriptors[NUMBER_OF_TASKS];

Example: task elements definition

In case no realtime configuration is provided for task mapping, a generic one is generated from model: A unique task contains all handles to functions which call classifier behaviors per instance. ![[Pasted image 20260706151712.png]]

/* Behaviors to task mapping */

const Tal_Static_Task_Function task0_functions[2] = {
    (Tal_Static_Task_Function)&ClassA_sm_main,
};

Example: task definition in default mode

In case a realtime configuration is provided for task mapping, tasks contents are set according to it.

![[Pasted image 20260706152956.png]]

/* Behaviors to task mapping */
const Tal_Static_Task_Function taskPeriodic_Task1_functions[2] = {
    (Tal_Static_Task_Function)&ClassA_sm_main,
    (Tal_Static_Task_Function)&ClassA_op,
};

const Tal_Static_Task_Function taskEvt_Task1_functions[2] = {
    (Tal_Static_Task_Function)&ClassA_op,
    (Tal_Static_Task_Function)&ClassA_sm_main,
};

Example of task declaration

In case a realtime configuration is provided, functions called by tasks are ordered accordingly

In case a realtime configuration is provided, instances are set accordingly

Realtime configuration accepts classifier behaviors (state machine/activity/opaque), and operation with this signature: void <functionName>(); When used, a wrapper function is declared :

![[Pasted image 20260707111413.png]]

/** Wrappers for called operations by tasks */
void ClassA_op_wrapper(void* instance)
{
    ClassA* self = static_cast<ClassA*>(instance);
    self->op();
}

...

const Tal_Static_Task_Function taskPeriodic_Task1_functions[...] = {
    ...
    (Tal_Static_Task_Function)&ClassA_op_wrapper,
};

The implementation of the communication API is then generated in the following order:

  • Cse_Trigger functions,
  • Cse_Write functions,
  • Cse_Read functions,
  • Cse_Call functions.

To get more information on the implementation of these functions, see the dedicated section in chapter 9.2.

Each communication function is described by a specific header containing a brief and the uuid of the port and the data/operation associated.

/**********************************************************************
 * Function to read <?DATA_NAME?> value on <?PORT_NAME?> port
 * @generated_from <?PORT_ID?>
 * @generated_from <?DATA_ID?>
 **********************************************************************/
<COMMUNCATION FUNCTIONS IMPLEMENTATION – See chapter 9.2>

Example: communication functions implementation

Function Cse_component_instances_init() is generated.

This function builds the instances: each instance is created with the new operator.

To get more information, see the dedicated section in chapter 9.2.

/**********************************************************************
 * Function building the component instances: allocation, construction and default values.
 * Relations between instances and mapping of the communication APIs are configured apart,
 * by Cse_component_relations_init.
 * First function to call before Cse_component_relations_init, Cse_task_descriptors_init & Cse_components_init
 **********************************************************************/
void Cse_component_instances_init(void){

    <INSTANCES INITIALISATION SECTION – See chapter 9.2>

}

Example: Cse_component_instances_init function with dynamic objects allocation

Function Cse_component_relations_init() is generated.

This function configures the relations between the component instances by calling the <ClassName>_cseInit() friend function of each class, then maps the communication APIs. Isolating it from Cse_component_instances_init() allows the instances to be built without being connected to each other.

Function Cse_component_relations_init() initializes the interface of the component instances with the pointers of the communication functions generated above in INSTANCES INITIALIZATION SECTION.

The access path to the interface of an instance walks the relations of the assembly, so this mapping is generated after the relations configuration.

To get more information, see the dedicated section in chapter 9.2.

/**********************************************************************
 * Function configuring the relations between the component instances, then mapping the
 * communication APIs to them.
 * Instances are expected to be already built by Cse_component_instances_init.
 * Function to call just after Cse_component_instances_init and before Cse_task_descriptors_init & Cse_components_init
 **********************************************************************/
void Cse_component_relations_init(void){

    <INSTANCES RELATIONS CONFIGURATION – See chapter 9.2>

    /* BEG: Add Communication Interface Configuration */
    /* Write functions */
    /* Trigger functions */
    pModel->inst1.cse_itf.Trigger_output_Signal = &Cse_Trigger_Model_inst1_output_Signal;
    /* Read functions */
    pModel->inst1.cse_itf.Read_input_Signal = &Cse_Read_Model_inst1_input_Signal;
    /* Server call functions */
    /* END: Add Cmmunication Interface Configuration */

    /* BEG: Add Communication Interface Configuration */
    /* Write functions */
    /* Trigger functions */
    pModel->inst2.cse_itf.Trigger_output_Signal = &Cse_Trigger_Model_inst2_output_Signal;
    /* Read functions */
    pModel->inst2.cse_itf.Read_input_Signal = &Cse_Read_Model_inst2_input_Signal;
    /* Server call functions */
    /* END: Add Cmmunication Interface Configuration */

}

Example: Cse_component_relations_init function

Function Cse_task_descriptors_init() is generated.

This function configures the predefined tasks.

Function Cse_task_descriptors_init() associates the entry point function of each behavior to tasks.

Function Cse_task_descriptors_init() associates the interface of each component instance to tasks.

Function Cse_task_descriptors_init() initializes the tasks with all the parameters.

For each task, a static variable task<task_index>_functions containing the function pointer for each behavior is created. This variable is an array with the size corresponding to the number of functions allocated to the current task.

For each task, a static variable task<task_index>_cseInstances containing the cse instance associated with each behavior is created. This variable is an array with the size corresponding to the number of functions allocated to the current task.

The cse instance is the component instance to be transmitted as a parameter during behavior invoke.

/**********************************************************************
 * Function configuring pre-defined tasks.
 * Function to call just after Cse_component_instances_init & Cse_component_relations_init
 **********************************************************************/
void Cse_task_descriptors_init(void){
  static function_ptr task0_functions[2];
  static Cse_instance_ptr task0_cseInstances[2];

  /* Runnable to task mapping */
  task0_functions[0] = (function_ptr)Add_Add;
  task0_cseInstances[0] = &pModel->inst1.cse_itf;
  /* Runnable to task mapping */
  task0_functions[1] = (function_ptr)Add_Add;
  task0_cseInstances[1] = &pModel->inst2.cse_itf;

  /* Periodic task task0 configuration */
  task_descriptors[0].type = PERIODIC;
  task_descriptors[0].period = 50;
  task_descriptors[0].functions = task0_functions;
  task_descriptors[0].cse_instances = task0_cseInstances;
  task_descriptors[0].nfunctions = 2;
}

Example: Cse_task_descriptors_init function

Function Cse_components_init() is generated.

This function executes the init functions of behaviors.

Each init function of behaviors is invoked with the interface of each component instance.

/**********************************************************************
 * Function calling all the init functions as configured in the model.
 * To be called after Cse_component_instances_init, Cse_component_relations_init & Cse_task_descriptors_init
 **********************************************************************/
void Cse_components_init(void) {
    Add_Add_init(&pModel->inst1.cse_itf);
    Add_Add_init(&pModel->inst2.cse_itf);
}

Example: Cse_components_init function

Dedicated Section in <ClassName>.h

The section BUFFERS DECLARATION SECTION is generated in <ClassName>.h for variables used as communication buffers. This section contains all the variables used as communication buffers between the components.

If the root objects are classes or class instance specifications. If these classes are composed (via a composition relation) of classes containing ports, a shared variable is expected to be generated.

Buffer variables are generated in BUFFERS DECLARATION SECTION section. To get more information on the declaration, see the dedicated section in chapter 9.2.

    /**********************************************************************
     * Communication & Scheduling Environment - Shared variables declaration
     **********************************************************************/
    <BUFFERS DECLARATION SECTION - see chapter 9.2>

Example: Buffer variables section

The section ACCESSORS DECLARATION SECTION section is generated in <ClassName>.h to declare accessors to classes containing behaviors to be invoked from the CSE.

If the root objects are classes or instance specifications of classes. If these classes are composed (via a composition relation) of classes containing behaviors, depending on the visibility of the relation, an accessor may be required (typically for protected and private visibility) to allow access from functions of the CSE.

An accessor is generated for in ACCESSORS DECLARATION SECTION section when required. To get more information on the declaration, see the dedicated section in chapter 9.2.

    /**********************************************************************
     * Communication & Scheduling Environment - Accessors declaration
     **********************************************************************/
    <ACCESSORS DECLARATION SECTION - see chapter 9.2>

Example: Accessors section

The section FRIEND FUNCTIONS DECLARATION SECTION is generated in <ClassName>.h to declare the friend functions, which require an access to the private and protected fields of the current class.

A friend function is generated in the FRIEND FUNCTIONS DECLARATION SECTION section when required. To get more information on the declaration, see the dedicated section in chapter 9.2.

    /**********************************************************************
     * Friend functions section
     **********************************************************************/
    <FRIEND FUNCTIONS DECLARATION SECTION - see chapter 9.2>

Example: Friend functions section

Cse_hook.h

Cse_hook.h contains the declaration of the possible hooks for every communication point.

This file relies on the Cse_hook_cfg.h to enable or not each hook.

#include to the file Cse_hook_cfg.h is generated.

A start hook function is declared with the suffix _Start.

A return hook function is declared with a suffix _Return.

Start and Return hook functions are enabled via a macro declaration mechanism. If a macro is declared in Cse_hook_cfg.h.

Hook functions are declared in HOOKS DECLARATION SECTION section. To get more information on the declaration, see the dedicated section in chapter 9.2.

#include "Cse_UC1_hook_cfg.h"

<HOOKS DECLARATION SECTION – See chapter 9.2>

Example: Hook file content

Start and Return hook functions are enabled by the following mechanism:

#if defined(Cse_<Read/Write/Trigger>Hook_<Component_inst>_<port>_<data>)
extern void Cse_<Read/Write/Trigger>Hook_<Component_inst>_<port>_<data>_Start(<data_type>* pData);
extern void Cse_<Read/Write/Trigger>Hook_<Component_inst>_<port>_<data>_Return(<data_type>* pData);
#else
#define Cse_<Read/Write/Trigger>Hook_<Component_inst>_<port>_<data>_Start(value)  ((void) (0))
#define Cse_<Read/Write/Trigger>Hook_<Component_inst>_<port>_<data>_Return(value)  ((void) (0))
#endif /* Cse_<Read/Write/Trigger>Hook__<Component_inst>_<port>_<data> */

Example: Hooks declaration

Cse_hook_cfg.h

Cse_hook_cfg.h contains a collection of macros declaring the hooks to enable. This file is only included by Cse_hook.h.

The first element is the definition of condition ENABLE_HOOKS macro to control enablement all hook functions.

Hook functions are enabled when the corresponding macro is declared.

The macros used to enable hooks are declared in HOOKS ACTIVATION SECTION section. To get more information on the declaration, see the dedicated section in chapter 9.2.

/* 
 * Define symbol ENABLE_HOOKS to enable the mechanism of hooks 
 * Enabled by default
 */
#define ENABLE_HOOKS
#ifdef ENABLE_HOOKS

<HOOKS ACTIVATION SECTION – See chapter 9.2>

#endif /* ENABLE_HOOKS */

Example: File content

Cse_hook_usr.cpp

Cse_hook_usr.cpp contains the skeleton of hook functions to let you implement your own behavior.

The first element is the definition of condition USER_HOOKS macro to control enablement of implementation contained in that file.

The purpose of macro USER_HOOKS is to disable the implementation of hooks in that file with the intention of delegating the implementation of these functions outside: for example: the FMU generator.

Macro USER_HOOKS can be defined in the file or on the compiler command line and can be used with macro ENABLE_HOOKS.

#include to the file Cse_cfg.h is generated.

A user-specific section is generated to allow insertion of additional includes or code.

Hook function skeletons are generated in HOOKS SKELETON SECTION section. To get more information on the declaration, see the dedicated section in chapter 9.2.

/* 
 * Define symbol ENABLE_HOOKS to enable the mechanism of hooks 
 * Enabled by default
 */
#define ENABLE_HOOKS
#ifdef ENABLE_HOOKS

<HOOKS ACTIVATION SECTION – See chapter 9.2>

#endif /* ENABLE_HOOKS */

Example: File content

Semantic Code Specifications

This section describes the behavior of the code generator depending on the UML/SysML element.

Before detailing each UML and SysML entities, let’s clarify the concept of component.

A component instance represents a unique representation of a component. A component instance exists each time the component appears in a model based on the multiple properties, which reference it or its parents recursively.

A component instance is uniquely represented by a name composed with the name of the parent’s instances.

For example, if the component A is referenced by a property a in a parent IBD B itself referenced by a property b in a root IBD C, the corresponding name for the instance of A is C_b_a.

Flow Port

A flow port is a SysML object used to consume a data or provide a data. This is an element contributing to the interface definition of a SysML block. A communication API is expected to be generated for each flow port in the context of each component instance.

BUFFERS DECLARATION SECTION

For each flow port with a direction OUT, a buffer variable is generated with the type referenced by the flow port as following: from_<instance_name>_<port>_data;

For each flow port with a direction IN that is not connected to any flow port with a direction OUT, a buffer variable is generated with the type referenced by the flow port as following: from_UNCONNECTED_<port>_data;

    /* @generated_from _19_0_3_16600ad_1651051212713_567116_42036 */
    /* @generated_from _2022x_16600ad_1671186992420_842512_17171 */
    /* @generated_from _19_0_3_16600ad_1651051504899_846935_42372 */
    myBoolean from_i2_OUT_data;

Example: Buffer variable declaration

COMMUNICATION FUNCTIONS IMPLEMENTATION

For each flow port with a direction IN of a component instance, a communication API is generated with the prefix Cse_Read_.

For each flow port with a direction OUT of a component instance, a communication API is generated with the prefix Cse_Write_.

Communication function is declared as a static function with the following naming convention: <prefix><component_inst_name>_<port_name>_data

Communication function parameter is a pointer to the type of the flow property.

Read function

Read function body starts with calling the Start hook function.

Read function copies the data contained in the buffer variable to the data variable provided as a parameter.

/**********************************************************************
 * Function to read data value on IN port
 * @generated_from _19_0_3_16600ad_1651049381870_524563_41980
 * @generated_from _19_0_3_16600ad_1651047151880_632775_41875
 **********************************************************************/
static void Cse_Read_c1_IN_data(myInt* data){
   unsigned int byteIdx;

   Cse_ReadHook_c1_IN_data_Start(data);
   for(byteIdx=0; byteIdx < sizeof(myInt); byteIdx++){
      ((char*) data)[byteIdx] = ((char*) &pc1->from_UNCONNECTED_IN_data)[byteIdx];
   }
   Cse_ReadHook_c1_IN_data_Return(&pc1->from_UNCONNECTED_IN_data);
}

Example: Read communication function

Write function

Write function body starts with calling the Start hook function.

Write function copies the data contained in the data variable provided as a parameter to the buffer variable.

Write function finishes with calling the Return hook function.

/**********************************************************************
 * Function to send data value on OUT port
 * @generated_from _19_0_3_16600ad_1651047431103_271450_41909
 * @generated_from _19_0_3_16600ad_1651047151880_632775_41875
 **********************************************************************/
static void Cse_Write_c1_OUT_data(myInt* data){
   Cse_WriteHook_c1_OUT_data_Start(data);

   for(unsigned int byteIdx=0; byteIdx < sizeof(myInt); byteIdx++){
      ((char*) &pc1->from_UNCONNECTED_OUT_data)[byteIdx] = ((char*) data)[byteIdx];
   }

   Cse_WriteHook_c1_OUT_data_Return(data);
}

Example: Write a communication function.

HOOKS DECLARATION SECTION

Prefix of hook functions is Cse_ReadHook_ for flow port with a direction IN.

Prefix of hook functions is Cse_WriteHook_ for flow port with a direction OUT.

A hook function with the suffix Start is generated.

A hook function with the suffix Return is generated.

Hook function is declared as following: <prefix><component_inst_name>_<port_name>_data_<suffix>

Hook function parameter is a pointer to the type of the flow property.

void Cse_ReadHook_UC1_p2_p4_data_Start(Integer\* pData)

Example: Hook declaration

Start and Return hook functions are declared for each flow port. These functions are generated for each instance of the component.

#if defined(Cse_ReadHook_UC1_p2_p4_data)
#undef ReadHook_UC1_p2_p4_prop3
extern void Cse_ReadHook_UC1_p2_p4_data_Start(Integer* pData);
extern void Cse_ReadHook_UC1_p2_p4_data_Return(Integer* pData);
#else
#define Cse_ReadHook_UC1_p2_p4_data_Start(value)  ((void) (0))
#define Cse_ReadHook_UC1_p2_p4_data_Return(value)  ((void) (0))
#endif /* ReadHook_UC1_p2_p4_data */

Example: Start and Return hooks declaration

HOOKS ACTIVATION SECTION

Hooks are activated by macro declared as the following: <prefix><component_inst_name>_<port_name>_data

HOOKS SKELETON SECTION

Start and Return hook function skeletons are generated for each property part of an interface and referenced by a port. These functions are generated for each instance of the component.

/**
 * Function Cse_ReadHook_UC1_p2_p4_data_Start
 * Start Hook to be overwritten to read prop3 value on p4 port
 * @generated_from <UUID>
 * @generated_from <UUID>
*/
void Cse_ReadHook_UC1_p2_p4_data_Start(Integer* pData){
   /* BEG_USER_CODE(<UUID>) do not remove */
   /* Add your includes here */
   /* END_USER_CODE(<UUID>) do not remove */
}

/**
 * Function Cse_ReadHook_UC1_p2_p4_data_Return
 * Return Hook to be overwritten to read prop3 value on p4 port
 * @generated_from <UUID>
 * @generated_from <UUID>
*/
void Cse_ReadHook_UC1_p2_p4_data_Return(Integer* pData){
   /* BEG_USER_CODE(<UUID>) do not remove */
   /* Add your includes here */
   /* END_USER_CODE(<UUID>) do not remove */
}

Example: Start and return Hooks skeleton.

Proxy Port/Interface Block/Flow Property and Port/Interface/Property

Proxy port/interface block/flow/property and port/interface/property are grouped into one section because they are supported in the same way.

Proxy port, interface block, flow property are SysML objects.

Port, interface, property are UML objects.

SysML: A proxy port is a SysML object used to consume a data or provide a data. This is an element contributing to the interface definition of a SysML block. A proxy port references an interface block that contains elements transmitted through the proxy port referencing this interface.

UML: A port is a UML object used to exchange data. This is an element contributing to the interface definition of an UML class. A port references an interface that contains elements transmitted through the port referencing this interface.

A communication API is expected to be generated for each flow property / property contained in an interface block / interface referenced by a proxy port / port in the context of each component instance.

BUFFERS DECLARATION SECTION

For each flow property / property with a direction OUT in an interface block / interface referenced (NOT conjugated) by a proxy port / port in the context of each component instance, a buffer variable is generated with the type referenced by the flow property / property: from_<instance_name>_<port>_<property_name>;

For each flow property / property with a direction IN in an Interface block / interface referenced (conjugated) by a proxy port / port in the context of each component instance, a buffer variable is generated with the type referenced by the flow property / property: from_<instance_name>_<port>_<property_name>;

For each flow property / property with a direction IN in an Interface block / interface referenced (NOT conjugated) by a proxy port / port in the context of each component instance that is not connected to any data provider, a buffer variable is generated with the type referenced by the flow property / property: from_UNCONNECTED_<port>_<property_name>;

For each flow property / property with a direction OUT in an interface block / interface referenced (conjugated) by a proxy port / port in the context of each component instance that is not connected to any data provider, a buffer variable is generated with the type referenced by the flow property / property: from_UNCONNECTED_<port>_<property_name>;

    /* @generated_from _19_0_3_16600ad_1651051212713_567116_42036 */
    /* @generated_from _2022x_16600ad_1671186992420_842512_17171 */
    /* @generated_from _19_0_3_16600ad_1651051504899_846935_42372 */
    myBoolean from_i2_OUT_data2;

Example: Buffer variable declaration

COMMUNCATION FUNCTIONS IMPLEMENTATION

For each flow property contained in an interface block referenced by a proxy port of a component instance, a communication API (static function) is generated with the prefix Cse_Read_ for flow property with a direction IN as following: Cse_Read_<component_inst_name>_<port_name>_<flow_property_name>

For each flow property contained in an interface block referenced by a proxy port of a component instance, a communication API (static function) is generated with the prefix Cse_Write_ for flow property with a direction OUT as following: Cse_Write_<component_inst_name>_<port_name>_<flow_property_name>

Communication function parameter is a pointer to the type of the flow property.

Read function

Read function body starts with calling the Start hook function.

Read function copies the data contained in the buffer variable to the data variable provided as a parameter.

Read function finishes with calling the Return hook function. (NOT SUPPORTED YET)

/**********************************************************************
 * Function to read data value on IN port
 * @generated_from _19_0_3_16600ad_1651049381870_524563_41980
 * @generated_from _19_0_3_16600ad_1651047151880_632775_41875
 **********************************************************************/
static void Cse_Read_c1_IN_flow(myInt* data){
    unsigned int byteIdx;

    Cse_ReadHook_c1_IN_flow_Start(data);
    for(byteIdx=0; byteIdx < sizeof(myInt); byteIdx++){
        ((char*) data)[byteIdx] = ((char*) &pc1->from_UNCONNECTED_IN_data)[byteIdx];
    }
    Cse_ReadHook_c1_IN_flow_Return(&pc1->from_UNCONNECTED_IN_data);
}

Example: Read communication function.

Write function

Write function body starts with calling the Start hook function.

Write function copies the data contained in the data variable provided as a parameter to the buffer variable.

Write function finishes with calling the return hook function.

/**********************************************************************
 * Function to send data value on OUT port
 * @generated_from _19_0_3_16600ad_1651047431103_271450_41909
 * @generated_from _19_0_3_16600ad_1651047151880_632775_41875
 **********************************************************************/
static void Cse_Write_c1_OUT_flow(myInt* data){
   Cse_WriteHook_c1_OUT_flow_Start(data);

   for(unsigned int byteIdx=0; byteIdx < sizeof(myInt); byteIdx++){
      ((char*) &pc1->from_UNCONNECTED_OUT_data)[byteIdx] = ((char*) data)[byteIdx];
   }

   Cse_WriteHook_c1_OUT_flow_Return(data);
}

Example: Write communication function.

Prefix of hook functions is Cse_ReadHook_ for flow properties with a direction IN and interface block is directly referenced or direction is OUT and Interface is conjugated when referenced.

Prefix of hook functions is Cse_WriteHook_ for flow properties with a direction OUT and interface block is directly referenced or direction is IN and interface is conjugated when referenced.

A hook function with the suffix Start is generated.

A hook function with the suffix Return is generated.

Hook function is declared as following: <prefix><component_inst_name>_<port_name>_<flow_property_name><suffix>

Hook function parameter is a pointer to the type of the flow property.

void Cse_ReadHook_UC1_p2_p4_prop3_Start(Integer* pData)

Example: Hook declaration

Start and Return hook functions are declared for each flow property contained in an interface block referenced by a proxy port. These functions are generated for each instance of the component.

#if defined(Cse_ReadHook_UC1_p2_p4_prop3)
#undef ReadHook_UC1_p2_p4_prop3
extern void Cse_ReadHook_UC1_p2_p4_prop3_Start(Integer* pData);
extern void Cse_ReadHook_UC1_p2_p4_prop3_Return(Integer* pData);
#else
#define Cse_ReadHook_UC1_p2_p4_prop3_Start(value)  ((void) (0))
#define Cse_ReadHook_UC1_p2_p4_prop3_Return(value)  ((void) (0))
#endif /* ReadHook_UC1_p2_p4_prop3 */

Example: Start and Return hooks declaration

HOOKS ACTIVATION SECTION

Hooks are activated by macro declared as the following: <prefix><component_inst_name>_<port_name>_<flow_property_name>

HOOKS SKELETON SECTION

Start and Return hook function skeletons are generated for each property part of an interface and referenced by a port. These functions are generated for each instance of the component.

/**
 * Function Cse_ReadHook_UC1_p2_p4_prop3_Start
 * Start Hook to be overwritten to read prop3 value on p4 port
 * @generated_from <UUID>
 * @generated_from <UUID>
*/
void Cse_ReadHook_UC1_p2_p4_prop3_Start(Integer* pData){
   /* BEG_USER_CODE(<UUID>) do not remove */
   /* Add your includes here */
   /* END_USER_CODE(<UUID>) do not remove */
}

/**
 * Function Cse_ReadHook_UC1_p2_p4_prop3_Return
 * Return Hook to be overwritten to read prop3 value on p4 port
 * @generated_from <UUID>
 * @generated_from <UUID>
*/
void Cse_ReadHook_UC1_p2_p4_prop3_Return(Integer* pData){
   /* BEG_USER_CODE(<UUID>) do not remove */
   /* Add your includes here */
   /* END_USER_CODE(<UUID>) do not remove */
}

Example: Start and Return Hooks skeleton.

Signal

In the following rules, state machine and activity are considered as behaviors of the class. They can be the classifier behavior of the class or a behavior called directly or indirectly by the classifier behavior.

A signal is considered as an input signal according to the following rules:

  • Statemachine: The signal is referenced by a SignalEvent in a trigger in a transition,
  • Activity: The signal is referenced by a SignalEvent in a trigger of an AcceptEventAction.

A signal is considered as an output signal according to the following rule:

  • Activity: The signal is referenced by a SendSignalAction.

A signal is considered as an output external signal when it satisfies both rules:

  • This signal satisfies the criteria for an output signal,
  • This signal does not satisfy the criteria for an input signal.

A signal is considered as an input external signal when it satisfies both rules:

  • This signal satisfies the criteria for an input signal.
  • This signal does not satisfy the criteria of an output signal. It is fired by a behavior belonging to another class.

A signal is transmitted through a UML port or a SysML port as soon as it is an external signal. In the following section, port can be replaced by UML port or SysML proxy port.

BUFFERS DECLARATION SECTION

For each input external signal transmitted by a port in the context of each component instance, a buffer variable is generated with the type referenced by the flow property / property: SignalEvent_<signal_name>_type to_<instance_name>_<port>_<signal_name>;

For each output external signal transmitted by a port in the context of each component instance that is not connected to any signal consumer, a buffer variable is generated with a specific type generated: SignalEvent\_\<signal_name\>\_type to_UNCONNECTED\_\<port\>\_\<signal_name\>;

    /* @generated_from _19_0_3_16600ad_1651051212713_567116_42036 */
    /* @generated_from _2022x_16600ad_1671186992420_842512_17171 */
    /* @generated_from _19_0_3_16600ad_1651051504899_846935_42372 */
    SignalEvent_Signal_type to_i2_OUT_Signal;

Example: Buffer variable declaration

COMMUNICATION FUNCTIONS IMPLEMENTATION

A Cse_Read static function is declared for each input external signals transmitted by a port in the context of each component instance as following: Cse_Read_<component_inst_name>_<port_name>_<signal_name>

A Cse_Trigger static function is declared for each output external signal transmitted by a port in the context of each component instance as following: Cse_Trigger_<component_inst_name>_<port_name>_<signal_name>

Communication function as a parameter if the signal contains properties. This parameter is a pointer to a structure containing a variable for each property.

Read function

Read function body starts with calling the Start hook function.

Read function copies the data contained in the buffer variable to the data variable provided as a parameter.

Read function resets the trigger of buffer variable meaning that the signal is consumed.

Read function finishes with calling the Return hook function.

/**********************************************************************
 * Function to read Signal value on input port
 * @generated_from _19_0_3_16600ad_1654593351733_128986_42726
 * @generated_from _2021x_2_16600ad_1654616863603_741017_18059
 **********************************************************************/
static void Cse_Read_Model_inst1_input_Signal(SignalEvent_Signal_type* data){
    unsigned int byteIdx;

    Cse_ReadHook_Model_inst1_input_Signal_Start(data);
    for(byteIdx=0; byteIdx < sizeof(SignalEvent_Signal_type); byteIdx++){
        ((char*) data)[byteIdx] = ((char*) &pModel->to_inst1_input_Signal)[byteIdx];
    }
    pModel->to_inst1_input_Signal.trigger = false;
    Cse_ReadHook_Model_inst1_input_Signal_Return(data);
}

Example: Read communication function.

Trigger function

trigger function body starts with declaring a trigger variable.

If a signal contains a property, data transmitted as the parameter is copied in the trigger variable.

trigger function body calls the Start hook function.

For each port reading this signal, the trigger function copies the trigger variable to a dedicated buffer variable.

Write function finishes with calling the Return hook function.

/**********************************************************************
 * Function to Trigger Signal on output port
 * @generated_from _19_0_3_16600ad_1654593483063_231459_42802
 * @generated_from _2021x_2_16600ad_1654616863603_741017_18059
 **********************************************************************/
static void Cse_Trigger_Model_inst1_output_Signal(Signal* data){
    SignalEvent_Signal_type trigger;
    trigger.trigger = 1;
    for(unsigned int byteIdx=0; byteIdx < sizeof(*data); byteIdx++){
        ((char*) &trigger.data)[byteIdx] = ((char*) data)[byteIdx];
    }

    Cse_TriggerHook_Model_inst1_output_Signal_Start(&trigger);
    for(unsigned int byteIdx=0; byteIdx < sizeof(SignalEvent_Signal_type); byteIdx++){
        ((char*) &pModel->to_inst2_input_Signal)[byteIdx] = ((char*) &trigger)[byteIdx];
    }
    Cse_TriggerHook_Model_inst1_output_Signal_Return(&trigger);
}

Example: Trigger communication function.

HOOKS DECLARATION SECTION

Prefix of hook functions is Cse_ReadHook_ for required ports receiving a signal.

Prefix of hook functions is Cse_TriggerHook_ for provided ports transmitting a signal.

A hook function with the suffix Start is generated.

A hook function with the suffix Return is generated.

Hook function is declared as the following: <prefix><component_inst_name>_<port_name>_<signal_name><suffix>

Hook function parameter is a pointer to the type used to describe the signal named SignalEvent_<signal_name>_type.

void Cse_ReadHook_Model_inst1_input_Signal_Start(SignalEvent_Signal_type* pData)

Example: Hook declaration

See [5] for more information on signal datatype.

Start and Return hook functions are declared for each signal that are transmitted or received by a port. These functions are generated for each instance of the component.

#if defined(Cse_ReadHook_Model_inst1_input_Signal)
#undef ReadHook_Model_inst1_input_Signal
extern void Cse_ReadHook_Model_inst1_input_Signal_Start(SignalEvent_Signal_type* pData);
extern void Cse_ReadHook_Model_inst1_input_Signal_Return(SignalEvent_Signal_type* pData);
#else
#define Cse_ReadHook_Model_inst1_input_Signal_Start(value)  ((void) (0))
#define Cse_ReadHook_Model_inst1_input_Signal_Return(value)  ((void) (0))
#endif /* ReadHook_Model_inst1_input_Signal */

Example: Start and Return hooks declaration

HOOKS ACTIVATION SECTION

Hooks are activated by macro declared as the following: <prefix><component_inst_name>_<port_name>_<signal_name>

HOOKS SKELETON SECTION

Start and Return hook function skeletons are generated for each signal that are transmitted or received by a port. These functions are generated for each instance of the component.

/**
 * Function Cse_ReadHook_Model_inst1_input_Signal_Start
 * Start Hook to be overwritten to read Signal value on input port
 * @generated_from <UUID>
 * @generated_from <UUID>
*/
void Cse_ReadHook_Model_inst1_input_Signal_Start(SignalEvent_Signal_type* to_Model_inst1_input_Signal){
    /* BEG_USER_CODE(<UUID>) do not remove */
    /* Add your includes here */
    /* END_USER_CODE(<UUID>) do not remove */
}

/**
 * Function Cse_ReadHook_Model_inst1_input_Signal_Return
 * Return Hook to be overwritten to read Signal value on input port
 * @generated_from <UUID>
 * @generated_from <UUID>
*/
void Cse_ReadHook_Model_inst1_input_Signal_Return(SignalEvent_Signal_type* to_Model_inst1_input_Signal){
    /* BEG_USER_CODE(<UUID>) do not remove */
    /* Add your includes here */
    /* END_USER_CODE(<UUID>) do not remove */
}

Example: Start and Return Hooks skeleton.

Proxy Port/Interface Block/Operation and Port/Interface/Operation

Proxy Port/Interface Block/Operation and Port/Interface/Operation are grouped into one section because they are supported in the same way.

Proxy port, interface block, and operation are used in a context of a model designed in SysML.

Port, interface, operation are UML objects used in a context of a model designed in UML.

SysML: A proxy port is a SysML object used to consume a data or provide a data. This is an element contributing to the interface definition of a SysML block. A proxy port references an interface block that contains which can contain operations. These operations can be called by a client or implemented by a server depending.

UML: A port is a UML object used to exchange data. This is an element contributing to the interface definition of an UML class. A port references an interface that can contain operations. These operations can be called by a client or implemented by a server depending.

In SysML, a client is a block containing a proxy port referencing an interface block with an output direction (it contains at least a flow property with the IN direction or it contains at least a flow property with the OUT direction and interface is conjugated).

In UML, a client is a class containing a port referencing a required interface containing operations and with a required role.

Port specification

A communication API is expected to be for each client operation in the context of each component instance.

COMMUNICATION FUNCTIONS IMPLEMENTATION

For each operation defined on the client side of a component instance, a communication API is generated with the prefix Cse_Call_.

Communication function is declared as a static function with the following naming convention: Cse_Call_<component_inst_name>_<port_name>_<operation_name>

Communication function parameters are the parameter of the UML operation.

Function calls the server operation implemented on the server side.

/**********************************************************************
 * Function to call server myOp operation on IN port
 * @generated_from _19_0_3_16600ad_1651051325597_240913_42076
 * @generated_from _2022x_16600ad_1671186267445_105670_17070
 **********************************************************************/
static void Cse_Call_Controller_i2_IN_myOp(myInt* data, myReal* data1, myBoolean* data2){
    Cse_CallHook_Controller_i2_IN_myOp_Start(data, data1, data2);
    server_myOp(&pController->i1, data, data1, data2);
    Cse_CallHook_Controller_i2_IN_myOp_Return(data, data1, data2);
}

Example: Client operation implementation

Class

If the root objects selected by the user contain classes (or SysML block), instances must be automatically computed from relations between classes.

Class diagram

Instances are computed based on the following rules:

No instance is created for an interface, an abstract class, or a global class.

An instance is created for each root class with the name “<class name>_inst".

If a class contains an aggregation relation to another class, an instance is created for the target class with the name of the aggregation end point.

If a class contains an association relation to another class, an instance is created for the target class with the name of the association end point.

INCLUDES

An #include to file <ClassName>.h is generated for computed instance to access to the definition of the associated class.

INSTANCES DECLARATION SECTION

See INSTANCES DECLARATION SECTION of chapter 9.2.2 Instance Specification.

INSTANCES INITIALIZATION SECTION

See INSTANCES INITIALISATION SECTION of chapter 9.2.2 Instance Specification

ACCESSORS DECLARATION SECTION

For each class containing a classifier behavior, an accessor is expected to be generated.

For each class that is a SysML constraint block an accessor is expected to be generated.

For each class that contains operations an accessor is expected to be generated.

For each class composed of classes (by a composition relation) respecting the previous requirement, an accessor is expected to be generated.

    /**
     * Getter for Timer:timer generated for accessing attribute from CSE
     * @generated_from _2022x_1ad00ce_1659678985350_593051_3321
     * @reverse_ignore
     */
    Timer* getTimer(void);

Example: Accessor

FRIEND FUNCTIONS DECLARATION SECTION

The CSE requires access to the current class when it contains private or protected associations. This declaration allows the CSE to init the association relations at the init phase; the association relations themselves are assigned by the <ClassName>_cseInit() friend function, called from Cse_component_relations_init().

Function void Cse_component_instances_init(void) is declared as friend function to the current class when it contains private or protected attributes corresponding to associations.

If the current class contains a statemachine as behavior and contains private or protected attributes, all the functions of the statemachine must be declared as friend to access the fields.

   /* @reverse_ignore */
   void Cse_component_instances_init(void)”        
   /* @reverse_ignore */
   friend void basic_controller_cls(controller_cls_struct*);

Example: Friend functions

Instance Specification

If the root objects selected by the user contain instance specifications, these elements are used for variables declaration.

Instance specification

Instance specifications can be connected by links that represent an instantiation of a relation. A relation can be an aggregation or an association.

Depending on relation cardinalities, instances can be declared as a single variable or an array of instances.

INCLUDES

An #include to file <ClassName>.h is generated for each instance to access to the definition of the associated class.

INSTANCES DECLARATION

If no relation targeting this instance has a cardinality higher than 1, a pointer to a variable representing the instance is generated with the name of the instance specification element prefixed with p.

If a relation targeting this instance has a cardinality higher than 1, an array of pointers to a variable representing the instance is generated with the name of the instance specification element prefixed with p.

Add* pAddUserInstance;
Model* pModelUserInstance;

Example: unique instance pointer

INSTANCES INITIALIZATION

For each instance, the function Cse_component_instances_init() calls the constructor implemented by the corresponding class <ClassName>.

   /* Call the constructor to initialize relations */
   pAddUserInstance = new Add();
   pModelUserInstance = new Model();

Example: instance initialization with a constructor.

For each association relation connecting classes, depending on the cardinality of the association end roles, instance of the classes must be assigned.

    pmyButton->myBL = pmyController;

Example: association configuration for unique instance

For each association relation connecting classes, if the cardinality of the relation end is higher than 1, the initialization mechanism is encapsulated into a for loop.

   for(int i = 0; i < 5; i++){
      pmyButton->myBL[i] = pmyController[i];
   }

Example: instance initialization with dynamic allocation, for example, with a size above 1