An AUTOSAR architecture model provides resources and a canvas for developing AUTOSAR composition and component models. You develop the software architecture by using graphical user interfaces, equivalent architecture modeling functions, or both. AUTOSAR Blockset provides these functions for developing AUTOSAR architecture models.
Tasks | Functions |
---|---|
Create, load, open, save, or close an AUTOSAR architecture model | autosar.arch.createModel autosar.arch.loadModel close open save |
Add, connect, or remove AUTOSAR components, composition, and ports | addComponent addComposition addPort connect destroy layout |
Find AUTOSAR elements and modify properties | find get set |
Define component behavior by creating or linking Simulink® models | createModel linkToModel |
Add Basic Software (BSW) service component blocks for simulating BSW service calls | addBSWService |
Export composition and component ARXML descriptions and generate component code (requires Embedded Coder®) | export getXmlOptions setXmlOptions |
This example script:
Creates and opens an AUTOSAR architecture model.
Adds a composition and components.
Adds architecture, composition, and component ports.
Connects architecture, composition, and component ports.
Creates and links Simulink implementation models for components.
Arranges architecture model layout based on heuristics.
Sets component and port properties.
Removes a component.
Searches for elements at different levels of the architecture model hierarchy.
Lists property values for composition ports.
To run the script, either copy commands from this MATLAB® code to the MATLAB command window, or copy the file
configAutosarArchModel.m
from
(matlabroot
/help/toolbox/autosar/examplescd
to folder) to a working folder.
% configAutosarArchModel.m % % Configure AUTOSAR architecture model. % This script creates models Controller1.slx and Actuator.slx. % To rerun the script, remove the models from the working folder. % Create and open AUTOSAR architecture model modelName = 'myArchModel'; archModel = autosar.arch.createModel(modelName,true); % Add a composition composition = addComposition(archModel,'Sensors'); % Add 2 components inside Sensors names = {'PedalSnsr','ThrottleSnsr'}; sensorSWCs = addComponent(composition,names,'Kind','SensorActuator'); layout(composition); % Auto-arrange layout % Add components at architecture model top level (call layout to arrange blocks) addComponent(archModel,'Controller1'); actuator = addComponent(archModel,'Actuator'); set(actuator,'Kind','SensorActuator'); % Add architecture ports addPort(archModel,'Receiver',{'TPS_Hw','APP_Hw'}); addPort(archModel,'Sender','ThrCmd_Hw'); % Add composition ports addPort(composition,'Receiver',{'TPS_Hw','APP_Hw'}); addPort(composition,'Sender',{'TPS_Perc','APP_Perc'}); % Add component ports controller = find(archModel,'Component','Name','Controller1'); addPort(controller,'Receiver',{'TPS_Perc','APP_Perc'}); addPort(controller,'Sender','ThrCmd_Perc'); addPort(actuator,'Receiver','ThrCmd_Perc'); addPort(actuator,'Sender','ThrCmd_Hw'); % Connect composition and components based on matching port names connect(archModel,composition,controller); connect(archModel,controller,actuator); % Connect specified architecture ports to specified composition and component ports connect(archModel,archModel.Ports(1),composition.Ports(1)); % Instead of connect(archModel,archModel.Ports(2),composition.Ports(2)), use find connect(archModel,... find(archModel,'Port','Name','APP_Hw'),... find(composition,'Port','Name','APP_Hw')); connect(archModel,actuator.Ports(2),archModel.Ports(3)); % Create implementation models for controller and actuator createModel(controller); createModel(actuator); % Link implementation model to PedalSnsr component inside Sensors pedalSnsr = find(composition,'Component','Name','PedalSnsr'); % Add path to implementation model addpath(fullfile(matlabroot,'/examples/autosarblockset/main')); linkToModel(pedalSnsr,'autosar_tpc_pedal_sensor'); layout(archModel); % Auto-arrange layout % Set properties set(composition.Ports(1),'Name','NewPortName1'); % Names for Sensors composition ports set(composition.Ports(3),'Name','NewPortName2'); set(find(controller,'Port','Name','TPS_Perc'),... 'Name','NewPortName3'); % Port name for Controller1 component & implementation set(controller,'Kind','ServiceProxy'); % Component type for Controller1 component set(controller,'Name','Instance1'); % Name for Controller1 component % Destroy component ThrottleSensor inside Sensors throttleSnsr = find(composition,'Component','Name','ThrottleSnsr'); destroy(throttleSnsr); % Find components in architecture model top level only components_in_arch_top_level = find(archModel,'Component') % Find components in all hierarchy components_in_all_hierarchy = find(archModel,'Component','AllLevels',true) % Find ports for composition block only composition_ports = find(composition,'Port') % List Kind and Name property values for composition ports for ii=1:length(composition_ports) Port = composition_ports(ii); portName = get(Port,'Name'); portKind = get(Port,'Kind'); fprintf('%s port %s\n',portKind,portName); end
components_in_arch_top_level = 2×1 Component array with properties: Name Kind Ports ReferenceName Parent SimulinkHandle components_in_all_hierarchy = 3×1 Component array with properties: Name Kind Ports ReferenceName Parent SimulinkHandle ports_in_composition = 4×1 CompPort array with properties: Kind Connected Name Parent SimulinkHandle Receiver port NewPortName1 Receiver port APP_Hw Sender port NewPortName2 Sender port APP_Perc
Component | Composition | Diagnostic Service Component | NVRAM Service Component