Configure AUTOSAR Sender-Receiver Interface Ports for End-to-End Protection
AUTOSAR end-to-end (E2E) protection for sender and receiver ports is based on the E2E library. E2E is a C library that you use to transmit data securely between AUTOSAR components. E2E protection adds additional information to an outbound data packet. The component receiving the packet can then verify independently that the received data packet matches the sent packet. Potentially, the receiving component can detect errors and take action.
For easier integration of AUTOSAR generated code with AUTOSAR E2E protection, Embedded Coder® supports AUTOSAR E2E protection. In Simulink®, you can:
Import AUTOSAR sender ports and receiver ports that are configured for E2E protection.
Configure an AUTOSAR sender or receiver port for E2E protection.
Generate C and ARXML code for AUTOSAR sender and receiver ports that are configured for E2E protection.
Simulink supports using either the E2E Transformer Error method or the E2E Protection
Wrapper to implement E2E protection in the generated code. You can get the configured E2E
protection method by using the function getDataDefaults
.
You set the E2E protection method by using the function setDataDefaults
.
The E2E Transformer Error method is invoked by the AUTOSAR runtime environment (RTE). By
using the E2E Transformer Error method Rte_Write
and
Rte_Read
calls are created in the generated code that take an additional
transformer error argument, Rte_TransformerError
, to indicate error status.
You can optionally extract the ErrorStatus
codes by changing the data type of
the ErrorStatus
port to uint16
.
Note
The E2E Transformer Error method is supported only for AUTOSAR schema version 4.2 or later.
The E2E Protection Wrapper method inserts a wrapper around the
Rte_Write
and Rte_Read
functions. The body of the E2E
Protection Wrapper that contains the Rte_Write
and
Rte_Read
calls is implemented external to the generated code. The software
defaults to using the E2E Protection Wrapper method if not method is specified.
Configure E2E Protection for individual AUTOSAR sender and receiver ports that use explicit
write and read data access modes. When you change the data access mode of an AUTOSAR port from
ExplicitWrite
to EndToEndWrite
, or from
ExplicitRead
to EndToEndRead
, simulation behavior is
unaffected. Code generation is similar to ExplicitWrite
and
ExplicitRead
data access modes, with these differences:
Generated Item | E2E Protection Wrapper | E2E Transformer Error |
---|---|---|
Generated code for initialization | Calls E2EPW_ReadInit_<Port> or
E2EPW_WriteInit_<Port> | No action |
Generated code for function signature | Uses uint32 E2EPW_Read_<Port>(data*) or (void)
E2EPW_Write_<Port> | When using |
ARXML exporter for receiver and sender COM-SPECs | Generates property USES-END-TO-END-PROTECTION with value
true | Generates property USES-END-TO-END-PROTECTION with value
true |
ARXML exporter for receiver and sender API extensions PORT-API-OPTIONS | No action | Generates property ERROR-HANDLING with value
TRANSFORMER-ERROR-HANDLING |
Configure EndToEndRead
and EndToEndWrite
Using E2E Transformer Error Protection Method
This example shows how to configure an AUTOSAR sender or receiver port using the Transformer Error E2E protection method.
Open example model
autosar_swc_counter
or a model that is configured with an AUTOSAR sender-receiver interface.modelName = "autosar_swc_counter"; openExample(modelName);
In the MATLAB Command Window, set
TransformerError
as the default E2E protection method.slMap = autosar.api.getSimulinkMapping(modelName); setDataDefaults(slMap,"InportsOutports", ... "EndToEndProtectionMethod","TransformerError");
In Simulink, open the Configuration Parameters dialog box. Under Code Generation > AUTOSAR Code Generation verify that the AUTOSAR schema version is 4.2 or later.
In the model, select the input port that enters the
Amplifier
block.Open the Code Mappings Editor, in the Inports tab set the AUTOSAR data access mode of the input block to
EndToEndRead
.In the Outports tab set the AUTOSAR data access mode of the output block to
EndToEndWrite
.To validate the AUTOSAR component configuration, click the Validate button .
Build the model and inspect the generated code.
The generated C code contains
RTE
read and write API calls that pass the transformer error argument.void Runnable(void) { Rte_TransformerError transformerError_Input; float64 tmpRead; … /* Inport: '<Root>/Input' */ (void)Rte_Read_RPort_InData(&tmpRead, &transformerError_Input); /* Outport: '<Root>/Output' incorporates: * Gain: '<S1>/Gain' * * Block description for '<S1>/Gain': * This block references an AUTOSAR calibration parameter, which is * accessed using the AUTOSAR Rte_Calprm function signature. */ (void)Rte_Write_SPort_OutData(Rte_CData_K() * tmpRead, &transformerError_Input); }
The generated header file
Rte_
contains the transformer error declaration.model
.h/* Transformer Classes */ typedef enum { RTE_TRANSFORMER_UNSPECIFIED = 0x00, RTE_TRANSFORMER_SERIALIZER = 0x01, RTE_TRANSFORMER_SAFETY = 0x02, RTE_TRANSFORMER_SECURITY = 0x03, RTE_TRANSFORMER_CUSTOM = 0xff } Rte_TransformerClass; typedef uint8 Rte_TransformerErrorCode; typedef struct { Rte_TransformerErrorCode errorCode; Rte_TransformerClass transformerClass; } Rte_TransformerError;
The exported ARXML code contains the E2E protection settings for the AUTOSAR receiver and sender ports.
<REQUIRED-COM-SPECS> <NONQUEUED-RECEIVER-COM-SPEC> … <USES-END-TO-END-PROTECTION>true</USES-END-TO-END-PROTECTION> … <NONQUEUED-SENDER-COM-SPEC> … <USES-END-TO-END-PROTECTION>true</USES-END-TO-END-PROTECTION> … </REQUIRED-COM-SPECS> … <PORT-API-OPTIONS> <PORT-API-OPTION> <ENABLE-TAKE-ADDRESS>false</ENABLE-TAKE-ADDRESS> <ERROR-HANDLING>TRANSFORMER-ERROR-HANDLING</ERROR-HANDLING> <INDIRECT-API>false</INDIRECT-API> <PORT-REF DEST="R-PORT-PROTOTYPE">/Company/Powertrain/Components/autosar_swc_counter/RPort</PORT-REF> </PORT-API-OPTION> <PORT-API-OPTION> <ENABLE-TAKE-ADDRESS>false</ENABLE-TAKE-ADDRESS> <ERROR-HANDLING>TRANSFORMER-ERROR-HANDLING</ERROR-HANDLING> <INDIRECT-API>false</INDIRECT-API> <PORT-REF DEST="P-PORT-PROTOTYPE">/Company/Powertrain/Components/autosar_swc_counter/SPort</PORT-REF> </PORT-API-OPTION> </PORT-API-OPTIONS>
Configure ErrorStatus
Ports using Transformer Error Protection Method
This example shows how to configure an AUTOSAR sender-receiver
ErrorStatus
port for Transformer Error E2E protection, and optionally
extract ErrorStatus
codes.
Open example model
autosar_swc_counter
or a model that is configured with an AUTOSAR sender-receiver interface.modelName = "autosar_swc_counter"; openExample(modelName);
In the MATLAB Command Window, set
TransformerError
as the default E2E protection method.slMap = autosar.api.getSimulinkMapping(modelName); setDataDefaults(slMap,"InportsOutports", ... "EndToEndProtectionMethod","TransformerError");
Inside the
Amplifier
subsystem add a Signal Conversion block using the Signal Copy configuration. Connect the Signal Copy block to the input fromInput_ErrorStatus
and to the outputOut_ErrorStatus
.Add a new Inport block to the
Amplifier
block and name itInput_ErrorStatus
. Set the data type of the Inport block touint16
. Add an Outport block and name itOut_ErrorStatus
.Return to the top model and open the Code Mappings editor. On the Inports tab, select
Input_ErrorStatus
and change the AUTOSAR data access mode toErrorStatus
. Set Port and Element toRPort
andInData
respectively.On the Outports tab, select
Out_ErrorStatus
and set DataAccessMode toImplicitSend
, Port toOut_ErrorStatus
, and Element toOut_ErrorStatus
.To validate the AUTOSAR component configuration, click the Validate button .
Build the model and inspect the generated code.
The generated C code contains
rtb
calls as well as theRTE
calls that pass the transformer error argument. The complete error status code is returned byrtb_TmpSignalConversionAtInput_
.void Runnable_Step(void) { /* local block i/o variables */ sint32 rtb_TmpSignalConversionAtInputO; uint16 rtb_TmpSignalConversionAtInput_; Rte_TransformerError transformerError_Input; uint8 error_Input; /* SignalConversion generated from: '<Root>/Input' incorporates: * Inport: '<Root>/Input' */ error_Input = Rte_Read_RPort_InData(&rtb_TmpSignalConversionAtInputO, &transformerError_Input); rtb_TmpSignalConversionAtInput_ = (uint16)(transformerError_Input.errorCode << 8 | error_Input);
The generated header file
Rte_
contains the transformer error declaration.model
.h/* Transformer Classes */ typedef enum { RTE_TRANSFORMER_UNSPECIFIED = 0x00, RTE_TRANSFORMER_SERIALIZER = 0x01, RTE_TRANSFORMER_SAFETY = 0x02, RTE_TRANSFORMER_SECURITY = 0x03, RTE_TRANSFORMER_CUSTOM = 0xff } Rte_TransformerClass; typedef uint8 Rte_TransformerErrorCode; typedef struct { Rte_TransformerErrorCode errorCode; Rte_TransformerClass transformerClass; } Rte_TransformerError;
The exported ARXML code contains the E2E protection settings for the AUTOSAR receiver and sender ports.
<REQUIRED-COM-SPECS> <NONQUEUED-RECEIVER-COM-SPEC> … <USES-END-TO-END-PROTECTION>true</USES-END-TO-END-PROTECTION> … <NONQUEUED-SENDER-COM-SPEC> … <USES-END-TO-END-PROTECTION>true</USES-END-TO-END-PROTECTION> … </REQUIRED-COM-SPECS> … <PORT-API-OPTIONS> <PORT-API-OPTION> <ENABLE-TAKE-ADDRESS>false</ENABLE-TAKE-ADDRESS> <ERROR-HANDLING>TRANSFORMER-ERROR-HANDLING</ERROR-HANDLING> <INDIRECT-API>false</INDIRECT-API> <PORT-REF DEST="R-PORT-PROTOTYPE">/Company/Powertrain/Components/autosar_swc_counter/RPort</PORT-REF> </PORT-API-OPTION> <PORT-API-OPTION> <ENABLE-TAKE-ADDRESS>false</ENABLE-TAKE-ADDRESS> <ERROR-HANDLING>TRANSFORMER-ERROR-HANDLING</ERROR-HANDLING> <INDIRECT-API>false</INDIRECT-API> <PORT-REF DEST="P-PORT-PROTOTYPE">/Company/Powertrain/Components/autosar_swc_counter/SPort</PORT-REF> </PORT-API-OPTION> </PORT-API-OPTIONS>
Configure EndToEndRead
and EndToEndWrite
Ports Using E2E Protection Wrapper Method
This example shows how to configure an AUTOSAR sender or receiver port using the E2E Protection Wrapper method.
Open example model
autosar_swc_counter
or a model for which an AUTOSAR sender-receiver interface is configured.modelName = "autosar_swc_counter"; openExample(modelName);
In the MATLAB Command Window, configure
ProtectionWrapper
as the default E2E protection method.slMap = autosar.api.getSimulinkMapping(modelName); setDataDefaults(slMap,"InportsOutports", ... "EndToEndProtectionMethod","ProtectionWrapper");
In the model, select the input port that enters the
Amplifier
block.Open the Code Mappings editor. On the Inports tab set the AUTOSAR data access mode of the input block to
EndToEndRead
.On the Outports tab set the AUTOSAR data access mode of the output block to
EndToEndWrite
.To validate the AUTOSAR component configuration, click the Validate button .
Build the model and inspect the generated code. The generated C code contains
E2E
API calls.void Runnable_Step(void) { … /* Inport: '<Root>/Input' */ (void)E2EPW_Read_RPort_InData(&tmpRead); /* Outport: '<Root>/Output' incorporates: * Gain: '<S1>/Gain' * * Block description for '<S1>/Gain': * This block references an AUTOSAR calibration parameter, which is * accessed using the AUTOSAR Rte_Calprm function signature. */ (void)E2EPW_Write_SPort_OutData(Rte_CData_K() * tmpRead); } … void Runnable_Init(void) { /* End-to-End (E2E) Protection Wrapper initialization */ E2EPW_ReadInit_RPort_InData(); E2EPW_WriteInit_SPort_OutData(); … }
The exported ARXML code contains the E2E settings for the AUTOSAR receiver and sender ports.
<NONQUEUED-RECEIVER-COM-SPEC> … <USES-END-TO-END-PROTECTION>true</USES-END-TO-END-PROTECTION> … <NONQUEUED-SENDER-COM-SPEC> … <USES-END-TO-END-PROTECTION>true</USES-END-TO-END-PROTECTION> …
See Also
Objects
Functions
Related Examples
- Map Inports and Outports to AUTOSAR Sender-Receiver Ports and Data Elements
- Configure AUTOSAR Sender-Receiver Communication
- Programmatically Configure AUTOSAR Sender-Receiver Communication