Frequently Asked Question

AUTOSAR: How can I change return values of functions from my SUT?
Last Updated 11 months ago

It have to be considered different cases when it comes to make the return values of functions available in TPT.


1.
For Client_Server functions (RTE_Call) that are calling TPT (which means they are unconnected), the return values can be set in TPT. Such functions can be
found in TPT by clicking View->Show View->Functions. The return values of the server functions there can be edited in TPT.
To do so, you can enter a channel name as return value for the server function. To do so, create a channel with the mode „LOCAL“ in the declaration editor and simply enter it there.
An image to highlight where to enter the channel name is attached.


2.For all functions implemented by TPT via C-Code the generated C-Code needs to be patched to make the return values modifiable from TPT. The code samples are based on the basic AUTOSAR example delivered with any TPT installation.

We are attempting to modify the return value for Rte_Write_LightsControlAtomic_P_headlight_headlight, which is the function that is used to write the headlight output. We will create a channel

LightsControlAtomic_P_headlight_headlight_return to be used to set the return value.


To patch this, generate the testframe again and add variables for the return values in the file testframe.c.

Add those entries between „// %%--- begin custom user code for init.“ and „// %%--- end custom user code for init.“
For this example it should look like

„// %%--- begin custom user code for init. Manual changes within this block will be retained. Do not remove or edit this line! ---
unsigned char LightsControlAtomic_P_headlight_headlight_return;
// %%--- end custom user code for init. Manual changes within this block will be retained. Do not remove or edit this line! ---"

We are using „unsigned int“ instead of Std_ReturnType here because „Std_Return_Type“ is not available here.


In the next step we bind this C-variable to TPT by adding

„tpt_vmapi_bindSignal_v2(vm, "LightsControlAtomic_P_headlight_headlight_return", tpt_type_uint8, tpt_type_uint8, 1, 0, 0, 1, (void*)&LightsControlAtomic_P_headlight_headlight_return,1);“
between „// %%--- begin custom user code for bindinterface.“ And „// %%--- end custom user code for bindinterface.“.

To make this channel the return value of a function we need to patch the generated analogon by TPT, in this case this is tpt_LightsControlAtomic.c.

We can search for Rte_Write_LightsControlAtomic_P_headlight_headlight in this file. The function returns 0 by default. This „0“ can be replaced by return LightsControlAtomic_P_headlight_headlight_return;

To make this variable known to the C compiler, we need to add an „extern Std_ReturnType LightsControlAtomic_P_headlight_headlight_return;“ on top of the code for Rte_Write_LightsControlAtomic_P_headlight_headlight. Afterwards run the make.bat file in the TPT output folder:

A click on „Generate & Compile“ will remove the changes in tpt_LightsControlAtomic.c as that file is generated again. The other changes are permanent when the code is recreated.

As the last step an output channel „LightsControlAtomic_P_headlight_headlight_return“ must be created in the TPT declaration editor. This channel can then be set in TPT to modify those return values.

Please Wait!

Please wait... it will take a second!