UML and SysML to C - Activity Code Generator Specification

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

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
Targeted Application Concepts [1]
C Code Architecture Specification [2]
UML and SysML to C - Software Production Operation Specification [3]

General Concepts

Activity code generation is part of the Components generation as presented in [1] is invoked during execution of UML to C operation as presented in [3].

This document focuses on the C code generation for the activity.

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.

Diagram Symbol UML element Description
Accept Event Action [ACTION] Accept Event Action Action to let Activity waiting for an Event
Accept Event Action.Trigger [ACTION] Accept Event Action.Trigger Element associating an Event to an Accept Event Action to define its validation criteria.
Accept Event Action.Trigger.AnyReceiveEvent [ACTION] Accept Event Action.Trigger.AnyReceiveEvent Not supported
Accept Event Action.Trigger.SignalEvent [ACTION] Accept Event Action.Trigger.SignalEvent Event referencing a Signal which is expected to validate the action. It is possible to specify the port transmitting the Signal or not.
Accept Event Action.Trigger.CallEvent [ACTION] Accept Event Action.Trigger.CallEvent Not supported
Accept Event Action.Trigger.ChangeEvent [ACTION] Accept Event Action.Trigger.ChangeEvent Not supported
Accept Event Action.Trigger.TimeEvent [ACTION] Accept Event Action.Trigger.TimeEvent Event definition a relative or absolute timeout value.
- [ACTION] Add Structural Feature Value Action Action setting a value to a structural feature. A structural feature can be a Property of the Class. Note: - Insert At pin is not supported. - Result pin is not supported.
- [ACTION] Call Behavior Action Call another Behavior. Note: Only Activities are supported.
- [ACTION] Call Operation Action Invoke an external Operation
- [ACTION] Create Object Action Create a new instance of an object specify as Context. Note: Supported object type is a class/block
- [ACTION] Read Structural Feature Action Action reading a value of a structural feature. A structural feature can be a Property of the Class.
Send Signal Action [ACTION] Send Signal Action Action sending a signal on a port
- [ACTION] Value Specification Action A ValueSpecificationAction is an Action that evaluates a Value and provides a result on result pin. Note: The value specification can be of different types. See following sections for each case.
- [ACTION] Value Specification Action.ElementValue Not supported
- [ACTION] Value Specification Action.Expression Not supported
- [ACTION] Value Specification Action.Instance Value
- [ACTION] Value Specification Action.Literal Boolean The boolean value is transmitted on result pin.
- [ACTION] Value Specification Action.Literal Integer The integer value is transmitted on result pin.
- [ACTION] Value Specification Action.Literal Nul Not supported
- [ACTION] Value Specification Action.Literal Real The real value will be transmitted on result pin.
- [ACTION] Value Specification Action.Literal String The string value will be transmitted on result pin.
- [ACTION] Value Specification Action.Literal Unlimited Natural Not supported
- [ACTION] Value Specification Action.Opaque Expression The Opaque Expression will be evaluated in the Value Specification Action and transmitted on result pin.
- [ACTION] Clear Variable Action Not supported
- [ACTION] Read Variable Action Not supported
- [ACTION] Add Variable Value Action Not supported
- [ACTION] Remove Variable Value Action Not supported
- Action Input Pin Not supported
- Activity Root element of an Activity
Activity Final Node Activity Final Node Node ending the process of the Activity
Control Flow Control Flow Flow of type control
Decision Node Decision Node Decision nodes allow you to separate the Activity Edges based on a condition.
- Exception Handler Not supported
- Expansion Region Not supported
Flow Final Flow Final Node declaring the end of a specific flow.
Fork Node Fork Node Used to send a control flow or an object flow to multiple actions.
Initial Node Initial Node First node of an Activity
Input Pin Input Pin Pin describing a required data of an Action. Note: only cardinality 1 is supported.
- Interruptible Activity Region Not supported
Join Node Join Node Used to receive a control flow from multiple actions. All input control flows must be valid to validate the join.
Merge Node Merge Node Used to merge Activity Edges together. At least one must be valid to validate the merge.
- [NODE] Sequence Node Not supported
- [NODE] Conditionnal Node Not supported
- [NODE] Loop Node Not supported
Object Flow Object Flow Flow transmitting an object
- Opaque Action Action used to execute an Opaque Behavior.
Output Pin Output Pin Pin describing a data provided as output of an Action. Note: only cardinality 1 is supported.
- Structured Activity Node Structured Activity Node is a node containing an activity inside.
Swimlane Swimlane No impact on code generation
Time Event Time Event Generate an event after a certain delay or at a specific time.
- Value Pin Not supported

Note: An activity is expected to be executed via a PeriodicExecution. So neither a ChangeEvent, nor a TimeEvent, nor a SignalEvent can be used to wakeup the activity. Instead during the periodic execution, the activity pools the events fired between execution 2 cycles.

Code Generator Specification

This section is divided in 2 parts:

  • The generated files specification
  • The behavior specification

Files Specifications

The activity code is composed of 2 files:

  • <Behavior>.c
  • <Behavior>.h

General requirements releated to file content are described in [2].

<Behavior>.c

<Behavior>.c file implements the activity structure. This structure is implemented via a function mainly containing a switch block. Each case represents a state. Transitions are manages via if conditions at end of case. Opaque behavior associated to each state or transition is implemented in the separated <Behavior>_usr.c.

File <Behavior>.c is generated for each statemachine which is either the classifier behavior or is a behavior called directly or indirectly by the classifier behavior.

Name of File <Behavior>.c is described in [1].

3 basic functions are generated as following:

  • void _basic_<Behavior>_main(STATEMACHINE *instance): This function contains the global switch managing the statemachine.
  • void _basic_<Behavior>_init(STATEMACHINE *instance): This function initializes the clock and the default state.
  • void _basic_<Behavior>_end(STATEMACHINE *instance): This function ends the statemachine.

<Behavior>.h

<Behavior>.h file implements the statemachine opaque behaviors. The opaque behavior of each state or transition is generated in a dedicated function.

File <Behavior>.h is generated for each statemachine which is either the classifier behavior or is a behavior called directly or indirectly by the classifier behavior.

Name of File <Behavior>.h is described in [1].

Behavior Code Specifications

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

Pseudo State Initial

Example: The pseudo state initial is the entry point of a statemachine.

One initial state is mandatory in a statemachine.

Call Operation Action

A Call Operation Action is used to invoke a Operation from an Action.

A node is generated for each Call Operation Action part of the Activity.

Local variables are declared for each input and output parameter of the node.

For input parameters, local variables are assigned with the value transmitted by the flows.

The operation referenced the call operation action is invoked with the variables declared previously. Parameters having a Type Modifier * are transmitted via their address.

For output parameters, output flows are assigned with the value of the local variables. Return type can be part of the output parameters, in this case, this parameter does not have any name.

/* node CallOperationAction */
/* @generated_from _2024x_2_16600ad_1719502041513_429240_19001 */
if(12u == (instance->flow[0] & 12u)) { /* TST_FLOW<-s1 & result */
    {
        Integer in1 = instance->data0;
        Integer in2 = instance->data1;

        Integer retVal = add(in1, in2);

        instance->data2 = retVal;
    }
    instance->flow[0] ^= 12u; /* CLR_FLOW<-s1,result */
    instance->flow[0] |= 16u; /* SET_FLOW->s1 : Integer */
}

Example: Node for a call operation action