How to use ApplicationDataTypes in C code

2.5k views Asked by At

For my understanding, the ApplicationDataType was introduced to AUTOSAR Version 4 to design Software-Components that are independent of the underlying platform and are therefore re-usable in different projects and applications. But how about the implementation behind such a SW-C to be platform independent?

Use-case example: You want to design and implement a SW-C that works as a FiFo. You have one Port for Input-Data, an internal buffer and one Port for Output-Data. You could implement this without knowing about the data type of the data by using the “abstract” ApplicationDataType. By using an ApplicationDataType for a variable as part of a PortInterface sooner or later you have to map this ApplicationDataType to an ImplementationDataType for the RTE-Generator.

Finally, the code created by the RTE-Generator only uses the ImplementationDataType. The ApplicationDataType is nowhere to be found in the generated code.

Is this intended behavior or a bug of the RTE-Generator? (Or maybe I'm missing something?)

3

There are 3 answers

6
Uwe Honekamp On

It is intended that ApplicationDataTypes do not directly appear in code, they are represented by their ImplementationDataType counterparts.

The motivation for the definition of data types on different levels of abstraction is explained in the AUTOSAR specifications, namely the TPS Software Component Template.

0
ZzetT On

You will never find an ApplicationDataType in the C code, because it's defined on a physical level with a physical unit and might have a (completly) different representation on the implementation level in C.

Imagine a battery control sensor that measures the voltage. The value can be in range 0.0V and 14.0V with one digit after the decimal point (physical). You could map it to a float in C but floating point operations are expensive. Instead, you use a fixed point arithmetic where you map the phyiscal value 0.0 to 0, 0.1 to 1, 0.2 to 2 and so on. This mapping is described by a so called compuMethod.

The software component will always use the internal representation. So, why do you need the ApplicationDataType then? There are many reasons to use them, some of them are:

  • Methodology: The software component designer doesn't need to worry about the implementation in C. Somebody else can define that in a later stage.
  • Measurement If you measure the value, you have a well defined compuMethod and know the physical interpretation of the value in C.
  • Data conversion: If you connect software component with different units e.g. km/h vs mph, the Rte could automatically convert the internal representation between them.
  • Constant conversion: You can specify an initial value on the physical value (e.g. 10.6V) and the Rte will convert it to the internal representation.
  • Variable Size Arrays: Without dynamic memory allocation, you cannot have a variable size array in C. But you could reserve some (max) memory in an array and store the actual length in a seperate field. On the implementation level you have then a struct with two members (value, length). But on the application level you just have an array.
0
goodman On

from AUTOSAR_TPS_SoftwareComponentTemplate.pdf

ApplicationDataType defines a data type from the application point of view. Especially it should be used whenever something "physical" is at stake.

An ApplicationDataType represents a set of values as seen in the application model, such as measurement units. It does not consider implementation details such as bit-size, endianess, etc.

It should be possible to model the application level aspects of a VFB system by using ApplicationDataTypes only.