Configure AUTOSAR Client-Server Communication
®
In Simulink , you can model AUTOSAR client-server communication for simulation and code
generation. For information about the Simulink blocks you use and the high-level workflow, see Client-
Server Interface.
To model AUTOSAR servers and clients, you can do either or both of the following:
•
•
Import AUTOSAR servers and clients from arxml code into a model.
Configure AUTOSAR servers and clients from Simulink blocks.
This topic provides examples of AUTOSAR server and client configuration that start from Simulink
blocks.
•
•
•
•
•
Configure AUTOSAR Server
Configure AUTOSAR Client
Configure AUTOSAR Client-Server Error Handling
Concurrency Constraints for AUTOSAR Server Runnables
Configure and Map AUTOSAR Server and Client Programmatically
Configure AUTOSAR Server
This example shows how to configure a Simulink Function block as an AUTOSAR server. The example
uses these files in the folder matlabroot/help/toolbox/ecoder/examples/autosar (open):
•
•
mControllerWithInterface_server.slx
ExampleApplicationErrorType.m
If you copy the files to a working folder, collocate the MATLAB file with the model file.
®
1.
2.
Open a model in which you want to create and configure an AUTOSAR server, or open the example
model mControllerWithInterface_server.slx.
Add a Simulink Function block to the model. In the Simulink Library Browser, the Simulink Function
block is in User-Defined Functions.
The example model provides two Simulink Function blocks, doOverride and readData.
第1页 共22页
3.
Configure the Simulink Function block to implement a server function. Configure a function
prototype and implement the server function algorithm.
In the example model, the contents of the Simulink Function block named readData implement a
server function named readData.
The contents include:
•
Trigger block readData, representing a trigger port for the server function. In the Trigger block
properties, Trigger type is set to Function call. Also, the option Treat as Simulink function is
selected.
Argument Inport block Op and Argument Outport blocks Data, ERR, and NegCode, corresponding
to the function prototype [Data,ERR,NegCode]=readData(Op).
•
Note
When configuring server function arguments, you must specify signal data type, port
dimensions, and signal type on the Signal Attributes tab of the inport and outport
blocks. The AUTOSAR configuration fails validation if signal attributes are absent for
server function arguments.
•
Blocks implementing the readData function algorithm. In this example, a few simple blocks
provide Data, ERR, and NegCode output values with minimal manipulation. A Constant block
represents the value of an application error defined for the server function. The value of Op
第2页 共22页
passed by the caller is ignored. In a real-world application, the algorithm could perform a more
complex manipulation, for example, selecting an execution path based on the passed value of
Op, producing output data required by the application, and checking for error conditions.
4.
When the server function is working in Simulink, set up the Simulink Function block in a model
configured for AUTOSAR. For example, configure the current model for AUTOSAR or copy the block
into an AUTOSAR model.
The example model is an AUTOSAR model, into which the Simulink Function block readData has
been copied. In place of a meaningful Op input value for the readData function, Simulink data
transfer line CurVal provides an input value that is used in the function algorithm.
第3页 共22页
5.
The required elements to configure an AUTOSAR server, in the general order they are created, are:
•
•
•
•
AUTOSAR client-server (C-S) interface
One or more AUTOSAR operations for which the C-S interface handles client requests
AUTOSAR server port to receive client requests for a server operation
For each server operation, an AUTOSAR server runnable to execute client requests
Open AUTOSAR Dictionary. To view AUTOSAR C-S interfaces in the model, go to the C-S Interfaces
view. The example model already contains client-server interfaces.
If a C-S interface does not yet exist in your model, create one.
a.
b.
In the C-S interfaces view, click the Add button
box.
In the dialog box, name the new C-S Interface, and specify the number of operations you intend
to associate with the interface. Leave other parameters at their defaults. Click Add. The new
interface appears in the C-S interfaces view.
. This action opens the Add Interfaces dialog
第4页 共22页
6.
Under C-S Interfaces, create one or more AUTOSAR server operations for which the C-S interface
handles client requests. Each operation corresponds to a Simulink server function in the model.
Expand C-S Interfaces and expand the individual C-S interface to which you want to add a server
operation. (In the example model, expand CsIf1.) To view operations for the interface, select
Operations. The example model already contains AUTOSAR server operations named doOverride
and readData.
If a server operation does not yet exist in your model, create one. (If your C-S interface contains a
placeholder operation named Operation1, you can safely delete it.)
a.
In the operations view, click the Add button
box.
In the dialog box, enter the Operation Name. Specify the name of the corresponding Simulink
server function.
If the corresponding Simulink server function has arguments, select the function in the Simulink
Function list. This action causes AUTOSAR operation arguments to be automatically created
based on the Simulink server function arguments. Click OK. The operation and its arguments
appear in the operations view.
. This action opens the Add Operation dialog
b.
c.
第5页 共22页
7.
Examine the arguments listed for the AUTOSAR server operation. Expand Operations, expand the
individual operation (for example, readData), and select Arguments. The listed arguments
correspond to the Simulink server function prototype.
8.
To view AUTOSAR server ports in the model, go to the server ports view. Expand
AtomicComponents, expand the individual component that you are configuring, and select
ServerPorts. The example model already contains an AUTOSAR server port named sPort.
第6页 共22页
If a server port does not yet exist in your model, create one.
a.
b.
In the server ports view, click the Add button
In the dialog box, name the new server port, and select the C-S interface for which you
configured a server operation. Click Add. The new port appears in the server ports view.
. This action opens the Add Ports dialog box.
9.
For each AUTOSAR server operation, configure an AUTOSAR server runnable to execute client
requests. To view AUTOSAR runnables in the model, select Runnables. The example model already
contains a server runnable for readData, named Runnable_readData.
If a suitable server runnable does not yet exist in your model, create one.
a.
In the runnables view, click the Add button
runnable.
Select the new runnable and configure its name and symbol. The symbol name specified for the
runnable must match the Simulink server function name. (In the example model, the symbol
name for Runnable_readData is the function name readData.)
Create an operation-invoked event to trigger the server runnable. (The example model defines
event event_readData for server runnable Runnable_readData.)
. This action adds a table entry for a new
b.
c.
i.
ii.
iii.
iv.
Under Events, click Add Event. Select the new event.
For Event Type, select OperationInvokedEvent.
Enter the Event Name.
Under Event Properties, select a Trigger value that corresponds to the server port and C-S
operation previously created for the server function. (In the example model, the Trigger
value selected for Runnable_readData is sPort.readData, combining server port sPort with
第7页 共22页
operation readData.) Click Apply.
10.
This step completes the configuration of an AUTOSAR server in the AUTOSAR Dictionary view of
the configuration.
Switch to the Code Mapping Editor view of the configuration and map the Simulink server function
to the AUTOSAR server runnable.
a.
b.
Open Code Mapping Editor. Select the Entry-Point Functions tab.
Select the Simulink server function. To map the function to an AUTOSAR runnable, click on the
Runnable field and select the corresponding runnable from the list of available server
runnables. In the example model, the Simulink function readData is mapped to AUTOSAR
runnable Runnable_readData.
第8页 共22页