Sender receiver communication in autosar

In AUTOSAR port-based sender-receiver (S-R) communication, AUTOSAR software components read and write data to other components or services. To implement S-R communication, AUTOSAR software components define:

In Simulink ® , you can:

  1. Create AUTOSAR S-R interfaces and ports by using the AUTOSAR Dictionary, or if using a Simulink data dictionary, using the Architectural Data Editor .
  2. Model AUTOSAR provide and require ports by using Simulink root-level outports and inports.
  3. Map the outports and inports to AUTOSAR provide and require ports by using the Code Mappings editor.

Note If you are using a Simulink data dictionary to store interfaces, you must configure these interfaces using either the Architectural Data Editor or the relevant programmatic interfaces, Simulink.dictionary.ArchitecturalData .

For an example modeling sender-receiver communication using Simulink bus ports, see Configure AUTOSAR Ports By Using Simulink Bus Ports.

Configure AUTOSAR Sender-Receiver Interface

This procedure outlines the general workflow for modeling AUTOSAR sender and receiver components in Simulink. This example assumes that a Simulink data dictionary is not used to store interfaces. If you are using a Simulink data dictionary to store interfaces, you must configure these interfaces using either the Architectural Data Editor or the relevant programmatic interfaces, Simulink.dictionary.ArchitecturalData .

To create an S-R interface and ports in Simulink:

  1. Open the AUTOSAR Dictionary and select S-R Interfaces. Click the Add button to create a new AUTOSAR S-R data interface. Specify its name and the number of associated S-R data elements.
  2. Select and expand the new S-R interface. Select DataElements, and modify the AUTOSAR data element attributes.

Configure AUTOSAR Provide-Require Port

AUTOSAR Release 4.1 introduced the AUTOSAR provide-require port ( PRPort ). Modeling an AUTOSAR PRPort involves using a Simulink inport and outport pair with matching data type, dimension, and signal type. You can associate a PRPort with a sender-receiver (S-R) interface or a nonvolatile (NV) data interface.

To configure an AUTOSAR PRPort for S-R communication in Simulink:

  1. Open a model that is configured for AUTOSAR, and in which a runnable has an inport and an outport suitable for pairing into an AUTOSAR PRPort . In this example, the RPort_DE1 inport and PPort_DE1 outport both use data type int8 , port dimension 1, and signal type real .
  2. Open the AUTOSAR Dictionary and navigate to the SenderReceiverPorts view. (To configure a PRPort for NV communication, use the NvSenderReceiverPorts view instead.)
  3. To add a sender-receiver port, click the Add button . In the Add Ports dialog box, specify Name as PRPort and select an Interface from the list of available S-R interfaces. Click Add.

  • Click the Validate button to validate the updated AUTOSAR component configuration. If errors are reported, address them and then retry validation. A common error flagged by validation is mismatched properties between the inport and outport that are mapped to the AUTOSAR PRPort .
  • Alternatively , you can programmatically add and map a PRPort port using AUTOSAR property and map functions. The following example adds an AUTOSAR PRPort (sender-receiver port) and then maps it to a Simulink inport and outport pair.

    hModel = 'my_autosar_expfcns'; open_system(hModel) arProps = autosar.api.getAUTOSARProperties(hModel); swcPath = find(arProps,[],'AtomicComponent')
    swcPath = 'ASWC
    add(arProps,'ASWC','SenderReceiverPorts','PRPort','Interface','Interface1') prportPath = find(arProps,[],'DataSenderReceiverPort')
    prportPath = 'ASWC/PRPort'
    slMap = autosar.api.getSimulinkMapping(hModel); mapInport(slMap,'RPort_DE1','PRPort','DE1','ImplicitReceive') mapOutport(slMap,'PPort_DE1','PRPort','DE1','ImplicitSend') [arPortName,arDataElementName,arDataAccessMode] = getOutport(slMap,'PPort_DE1')
    arPortName = PRPort arDataElementName = DE1 arDataAccessMode = ImplicitSend

    Configure AUTOSAR Receiver Port for IsUpdated Service

    AUTOSAR defines quality-of-service attributes, such as ErrorStatus and IsUpdated , for sender-receiver interfaces. The IsUpdated attribute allows an AUTOSAR explicit receiver to detect whether a receiver port data element has received data since the last read occurred. When data is idle, the receiver can save computational resources.

    For the sender, the AUTOSAR Runtime Environment (RTE) sets the status of an update flag, indicating whether the data element has been written. The receiver calls the Rte_IsUpdated_ Port _ Element API, which reads the update flag and returns a value indicating whether the data element has been updated since the last read.

    In Simulink, you can:

    To model IsUpdated service in Simulink, you pair an inport that is configured for ExplicitReceive data access with a new inport configured for IsUpdated data access. To configure an AUTOSAR receiver port for IsUpdated service:

    1. Open a model for which an AUTOSAR sender-receiver interface is configured.
    2. Identify the inport that corresponds to the AUTOSAR receiver port for which IsUpdated service is required. Create a second inport, set its data type to boolean , and connect it to the same block. For example:

    1. If the data inport is not already configured, set DataAccessMode to ExplicitReceive . Select Port and Element values that map the inport to the AUTOSAR receiver port and data element for which IsUpdated service is required.
    2. For the quality-of-service inport, set DataAccessMode to IsUpdated . Select Port and Element values that exactly match the data inport.

  • To validate the AUTOSAR component configuration, click the Validate button .
  • Build the model and inspect the generated code. The generated C code contains an Rte_IsUpdated API call.

    if (Rte_IsUpdated_Input_DE1()) < … Rte_Read_Input_DE1(&tmp); … >
    The exported ARXML code contains the ENABLE-UPDATE setting true for the AUTOSAR receiver port.
     Input  /pkg/if/Input/DE1 true  

    Configure AUTOSAR Sender-Receiver Data Invalidation

    The AUTOSAR standard defines an invalidation mechanism for AUTOSAR data elements used in sender-receiver (S-R) communication. A sender component can notify a downstream receiver component that data in a sender port is invalid. Each S-R data element can have an invalidation policy. In Simulink, you can:

    For each S-R data element, you can set the Signal Invalidation block parameter Signal invalidation policy to Keep , Replace , or DontInvalidate . If an input data value is invalid (invalidation control flag is true ), the resulting action is determined by the value of Signal invalidation policy:

    To configure an invalidation policy for an AUTOSAR S-R data element in Simulink:

    1. Open a model for which an AUTOSAR sender-receiver interface is configured. For example, suppose that:

    1. The block must be connected directly to a root outport block. Connect the block to root outport Out .
    2. Connect the first block input, a data value, to the data path from root inport In1 .
    3. For the second block input, an invalidation control flag, add a root inport named In2 to the model. Set its data type to scalar boolean . Map the new inport to a second AUTOSAR receiver port. If a second AUTOSAR receiver port does not exist, use the AUTOSAR Dictionary to create the AUTOSAR port, S-R interface, and data element. In this example, Simulink inport In2 is mapped to AUTOSAR receiver port RPort2 and data element InElem2 . In the AUTOSAR Dictionary, AUTOSAR receiver port RPort2 selects S-R interface In2 , which contains the data element InElem2 . Connect the second block input to root inport In2 .

  • To validate the AUTOSAR component configuration, open the Code Mappings editor and click the Validate button .
  • Build the model and inspect the generated code. When the signal is valid, the generated C code calls Rte_Write_ Port _ Element . When the signal is invalid, the C code calls Rte_Invalidate_ Port _ Element .

    /* SignalInvalidation: '/Signal Invalidation' incorporates: * Inport: '/In2' */ if (!Rte_IRead_Runnable_Step_RPort2_InElem2()) < /* Outport: '/Out' */ (void) Rte_Write_PPort_OutElem(mSignalInvalidation_B.Gain); > else < Rte_Invalidate_PPort_OutElem(); >
    The exported ARXML code contains the invalidation setting for the data element.
     /pkg/if/Out/OutElem KEEP  

    Configure AUTOSAR S-R Interface Port 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. End-to-end 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 solutions, Embedded Coder ® supports AUTOSAR E2E protection. In Simulink, you can:

    Simulink supports using either the E2E Transformer method or the E2E Protection Wrapper to implement end-to-end protection in the generated code. You can retrieve which end-to-end protection method is configured by using the function getDataDefaults . You set the end-to-end protection method by using the function setDataDefaults .

    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 explicit write to end-to-end write, or from explicit read to end-to-end read.

    Generated ItemE2E Protection WrapperE2E Transformer
    Generated Code for InitializationCalls E2EPW_ReadInit_ or E2EPW_WriteInit_ None
    Generated Code for Function SignatureUses uint32 E2EPW_Read_(data*) or (void) E2EPW_Write_ Uses uint8 Rte_Read_(data*, Rte_TransformerError*) or (void)Rte_Write_(data, Rte_TransformerError*)
    ARXML Exporter for Receiver and Sender COM-SPECsGenerates property USES-END-TO-END-PROTECTION with value trueGenerates property USES-END-TO-END-PROTECTION with value true
    ARXML Exporter for Receiver and Sender API Extensions PORT-API-OPTIONSNoneGenerates property ERROR-HANDLING with value TRANSFORMER-ERROR-HANDLING

    To configure an AUTOSAR sender or receiver port for E2E transformer protection:

    1. Open a model for which an AUTOSAR sender-receiver interface is configured.
    2. In the MATLAB Command Window, configure TransformerError as the default E2E protection method.
    slMap = autosar.api.getSimulinkMapping(modelName); setDataDefaults(slMap, 'InportsOutports', . 'EndToEndProtectionMethod', 'TransformerError');

  • 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: '/Input' */ Rte_Read_RPort_InputDE(&tmpRead, &transformerError_Input); … /* Outport: '/Output'. */ (void) Rte_Write_PPort_OutputDE(data, &transformerError_Input); … >
    The generated header file Rte_ model .h contains the transformer error declaration.
    /* 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 settings for the AUTOSAR receiver and sender ports.
     true … … trueTRANSFORMER-ERROR-HANDLING /pkg/swc/ASWC/RPort TRANSFORMER-ERROR-HANDLING /pkg/swc/ASWC/PPort 

    To configure an AUTOSAR sender or receiver port for E2E wrapper protection:

    1. Open a model for which an AUTOSAR sender-receiver interface is configured.
    2. In the MATLAB Command Window, configure ProtectionWrapper as the default E2E protection method.
    slMap = autosar.api.getSimulinkMapping(modelName); setDataDefaults(slMap, 'InportsOutports', . 'EndToEndProtectionMethod', 'ProtectionWrapper');

  • 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: '/Input' */ E2EPW_Read_RPort_InputDE(…); … /* Outport: '/Output'. */ (void) E2EPW_Write_PPort_OutputDE(…); … > … void Runnable_Init(void) < … /* End-to-End (E2E) initialization */ E2EPW_ReadInit_RPort_InputDE(); E2EPW_WriteInit_PPort_OutputDE(); … >
    The exported ARXML code contains the E2E settings for the AUTOSAR receiver and sender ports.
    true … … true

    Configure AUTOSAR Receiver Port for DataReceiveErrorEvent

    In AUTOSAR sender-receiver communication between software components, the Runtime Environment (RTE) raises a DataReceiveErrorEvent when the communication layer reports an error in data reception by the receiver component. For example. the event can indicate that the sender component failed to reply within an AliveTimeout limit, or that the sender component sent invalid data.

    Embedded Coder supports creating DataReceiveErrorEvent s in AUTOSAR receiver components. In Simulink, you can:

    You should configure a DataReceiveErrorEvent for an AUTOSAR receiver port that uses ImplicitReceive , ExplicitReceive , or EndToEndRead data access mode.

    To configure an AUTOSAR receiver port for a DataReceiveErrorEvent :

    1. Open a model for which the receiver side of an AUTOSAR sender-receiver interface is configured.
    2. Open the Code Mappings editor. Select the Inports tab. Select the data inport that is mapped to the AUTOSAR receiver port for which you want to configure a DataReceiveErrorEvent . Set its AUTOSAR data access mode to ImplicitReceive , ExplicitReceive , or EndToEndRead . Here are two examples, without and with a coupled ErrorStatus port.

    1. Click the Add button to add a runnable entry.
    2. Select the new runnable entry to configure its name and other properties.
    3. Go to the Events pane, and configure a DataReceiveErrorEvent for the runnable. Click Add Event, select type DataReceiveErrorEvent , and enter an event name.
    4. Under Event Properties, select the trigger for the event. The selected trigger value indicates the AUTOSAR receiver port and the data element for which the runnable is handling DataReceiveErrorEvent s.

    Alternatively, you can programmatically create a DataReceiveErrorEvent .
    arProps = autosar.api.getAUTOSARProperties(mdlname); add(arProps,ibQName,'Events','DRE_Evt'. 'Category','DataReceiveErrorEvent','Trigger','rPort.DE1'. 'StartOnEvent',runnableQName);
      DRE_Evt /Root/mDemoModel_swc/ReceivingASWC/IB/Run_ErrorHandling  /Root/mDemoModel_swc/ReceivingASWC/rPort /Root/Interfaces/In/DE    . . Run_ErrorHandling 0 false . Run_ErrorHandling  

    Configure AUTOSAR Sender-Receiver Port ComSpecs

    In AUTOSAR software components, a sender or receiver port optionally can specify a communication specification (ComSpec). ComSpecs describe additional communication requirements for port data.

    To model AUTOSAR sender and receiver ComSpecs in Simulink, you can:

    For example, if you create an AUTOSAR receiver port in Simulink, you use the Code Mappings editor to map a Simulink inport to the AUTOSAR receiver port and an S-R data element. You can then select the port and specify its ComSpec attributes.

    Here are the properties for a queued receiver port.

    If you import or create an AUTOSAR receiver port, you can use the AUTOSAR Dictionary to view and edit the ComSpec attributes of the mapped S-R data elements in the AUTOSAR port.

    To programmatically modify ComSpec attributes of an AUTOSAR port, use the AUTOSAR property function set . For example:

    hModel = 'autosar_swc'; openExample(hModel); arProps = autosar.api.getAUTOSARProperties(hModel); % Find ComSpec path portPath = find(arProps,[],'DataReceiverPort','PathType','FullyQualified'); ifPath = find(arProps,[],'SenderReceiverInterface','Name','Input_If','PathType','FullyQualified'); dataElementPath = find(arProps,ifPath,'FlowData','Name','In1','PathType','FullyQualified'); infoPath = find(arProps,portPath,'PortInfo'. 'PathType','FullyQualified','DataElements',dataElementPath); comSpecPath = find(arProps,infoPath,'PortComSpec','PathType','FullyQualified'); % Set ComSpec attributes set(arProps,comSpecPath,'AliveTimeout',30,'HandleNeverReceived',true,'InitValue',1); get(arProps,comSpecPath,'AliveTimeout') get(arProps,comSpecPath,'HandleNeverReceived') get(arProps,comSpecPath,'InitValue')

    To set the QueueLength attribute for a queued receiver port:

    set(arProps,comSpecPath,'QueueLength',10);

    When you generate code for an AUTOSAR model that specifies ComSpec attributes, the exported ARXML port descriptions include the ComSpec attribute values.

      ReceivePort   /Company/Powertrain/Interfaces/Input_If/In1 . 30 true .  DefaultInitValue_Double_1 /Company/Powertrain/Constants/DefaultInitValue_Double_1       . DefaultInitValue_Double_1  DefaultInitValue_Double_1 1   

    See Also

    Related Examples

    More About