{"id":9920,"date":"2020-12-22T09:33:06","date_gmt":"2020-12-22T14:33:06","guid":{"rendered":"https:\/\/blogs.mathworks.com\/simulink\/?p=9920"},"modified":"2021-01-21T11:22:39","modified_gmt":"2021-01-21T16:22:39","slug":"configuring-a-simulink-model-for-autosar","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/simulink\/2020\/12\/22\/configuring-a-simulink-model-for-autosar\/","title":{"rendered":"Configuring a Simulink Model for AUTOSAR"},"content":{"rendered":"<p><em>Today I am happy to welcome guest blogger <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/profile\/authors\/17518382\/\">Sai Ram Anumula<\/a> to give an introduction on how to configure Simulink models to generate AUTOSAR compliant code.<\/em><\/p>\n<p>Some time ago, my colleague <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/profile\/authors\/6273071\">Shwetha<\/a> published a <a href=\"https:\/\/blogs.mathworks.com\/simulink\/2020\/02\/11\/introduction-to-autosar\">Introduction to AUTOSAR<\/a> post, where she gave a overview of the AUTOSAR Standard and the capabilities of the  Simulink <a href=\"https:\/\/www.mathworks.com\/products\/autosar.html\">AUTOSAR Blockset<\/a> to develop AUTOSAR Classic applications. Today, we will step through the details of translating, or converting, a simple Simulink model into an AUTOSAR model to generate AUTOSAR compliant code.<\/p>\n<p>For this process of translation or conversion, AUTOSAR Blockset can do the magic for you in two ways:<\/p>\n<ul>\n<li><strong>Top-down workflow:<\/strong> You start with a software component or composition descriptions stored in an AUTOSAR XML files and import it as Simulink AUTOSAR components\/composition models or <a href=\"https:\/\/www.mathworks.com\/help\/autosar\/ug\/create-architecture-models.html\">architecture models<\/a>.<\/li>\n<li><strong>Bottom-up workflow:<\/strong> You start with a Simulink model or an architecture model (implemented using <a href=\"https:\/\/www.mathworks.com\/products\/system-composer.html\">System Composer<\/a>, see <a href=\"https:\/\/www.mathworks.com\/help\/autosar\/ug\/example-author-autosar-compositions-in-architecture-model.html\">this example<\/a>), configure it for AUTOSAR and then export ARXML files to be used in the rest of your AUTOSAR toolchain.<\/li>\n<\/ul>\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/simulink\/2020Q4\/autosar_big_picture.png\" alt=\"AUTOSAR workflows\" \/><\/p>\n<p>In this post, we are demonstrating the bottom-up workflow.<\/p>\n<p><strong>Quick start using AUTOSAR Component Designer<\/strong><\/p>\n<p>To begin, you can start by opening the <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2020b\/autosar\/ref\/autosarcomponentdesigner-app.html\">AUTOSAR Component Designer App<\/a> and follow the steps to map your Simulink model to an AUTOSAR Software Component. Here is a short animation going through those steps:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/simulink\/2020Q4\/AUTOSAR_intro_large.gif\" alt=\"AUTOSAR Quick Start\" \/><br \/>\n<em><a href=\"https:\/\/blogs.mathworks.com\/images\/simulink\/2020Q4\/AUTOSAR_intro_large.gif\">Click here for larger version<\/a><\/em><\/p>\n<p>Once all the options are configured in the Quick Start menu, the <a title=\"https:\/\/www.mathworks.com\/help\/ecoder\/ref\/codemappingseditor.html (link no longer works)\">Code Mappings Editor<\/a> and <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2020b\/simulink\/ug\/block-properties-dialog-box.html\">Property Inspector<\/a> will open, providing an AUTOSAR perspective of the model and allowing you to further configure the Software Component.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/simulink\/2020Q4\/autosarStep1.png\" alt=\"Configuring a Simulink mdel for AUTOSAR\" \/><\/p>\n<p><strong>Configuring Simulink-AUTOSAR Code Mappings<\/strong><\/p>\n<p>The Code Mappings Editor helps to configure the model as an AUTOSAR Software Component. Here is a list of mappings between Simulink features and AUTOSAR elements:<\/p>\n<ul>\n<li>Entry-point functions <-> AUTOSAR runnables<\/li>\n<li>Inports and Outports <-> AUTOSAR Sender-Receiver Ports<\/li>\n<li>Model Workspace Parameters <-> AUTOSAR Component Parameters<\/li>\n<li>Data Stores <-> AUTOSAR variables<\/li>\n<li>Block Signals\/States <-> AUTOSAR variables<\/li>\n<li>Data Transfers <-> AUTOSAR Inter-Runnable Variables<\/li>\n<li>Function Callers <-> AUTOSAR Client-Server Ports and Operations<\/li>\n<\/ul>\n<p>Here is an example showing a Rate Transition block being mapped to an implicit Inter-Runnable Variable:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/simulink\/2020Q4\/CodeMappingEditor.png\" alt=\"Code Mapping Editor\" \/><\/p>\n<p>Further you can leverage the blocks corresponding to Basic Software Services which are readily configured for you as per the AUTOSAR standard for code generation and emulation of these services. For example, You may use <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2020b\/autosar\/ref\/nvmservicecaller.html\">NvMServiceCaller<\/a> block to call the AUTOSAR NvM service interface and generate code out of it. You can also use <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2020b\/autosar\/ref\/nvramservicecomponent.html\">NVRAM Service Component<\/a> block to emulate the AUTOSAR NvM service calls in a system-level and composition-levels simulations.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/simulink\/2020Q4\/AUTOSAR_library.png\" alt=\"AUTOSAR Library\" \/><\/p>\n<p>Once you have a Software Component fully developed, it\u2019s time to validate the AUTOSAR properties and mappings before attempting code generation:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/simulink\/2020Q4\/autosar_validation.png\" alt=\"AUTOSAR validation\" \/><\/p>\n<p><strong>Inspecting generated AUTOSAR Code<\/strong><\/p>\n<p>Upon successful validation, you can generate code and inspect the C code and XML software descriptions to confirm that they comply with the AUTOSAR specification:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/simulink\/2020Q4\/Autosar_inspect_code.png\" alt=\"AUTOSAR generated code\" \/><\/p>\n<p><strong>Now it's your turn<\/strong><\/p>\n<p>Explore the <a href=\"https:\/\/www.mathworks.com\/products\/autosar.html\">AUTOSAR Blockset landing page<\/a> to learn more how it could help you generating an AUTOSAR compliant C\/C++ code from Simulink models in just a few steps.<\/p>\n<p>If you have the blockset installed, I recommend going through the various examples located <a href=\"https:\/\/www.mathworks.com\/help\/autosar\/examples.html\">here<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img decoding=\"async\"  class=\"img-responsive\" src=\"https:\/\/blogs.mathworks.com\/images\/simulink\/2020Q4\/Autosar_inspect_code.png\" onError=\"this.style.display ='none';\" \/><\/div>\n<p>Today I am happy to welcome guest blogger Sai Ram Anumula to give an introduction on how to configure Simulink models to generate AUTOSAR compliant code.<br \/>\nSome time ago, my colleague Shwetha published... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/simulink\/2020\/12\/22\/configuring-a-simulink-model-for-autosar\/\">read more >><\/a><\/p>\n","protected":false},"author":41,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[609,21,16],"tags":[587],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/9920"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/users\/41"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/comments?post=9920"}],"version-history":[{"count":44,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/9920\/revisions"}],"predecessor-version":[{"id":10062,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/9920\/revisions\/10062"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/media?parent=9920"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/categories?post=9920"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/tags?post=9920"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}