4 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
5 <html xmlns="http://www.w3.org/1999/xhtml">
7 <title>Simulink coder target for automotive rapid prototyping platform</title>
8 <meta name="generator" content="http://nestededitor.sourceforge.net/" />
9 <meta http-equiv="Content-type" content="text/html; charset=UTF-8" />
10 <link rel="stylesheet" type="text/css" href="media/themes/Clean Presentation/style.css" />
11 <script type="text/javascript" src="media/libraries/jquery/jquery.min.js"></script>
12 <link rel="stylesheet" type="text/css" href="media/themes/Clean Presentation/style.css" />
13 <script type="text/javascript" src="media/themes/Clean Presentation/scripts.js"></script>
17 <div class="header" id="header">
18 <h1>Simulink coder target for automotive rapid prototyping platform</h1>
19 <h2>Carlos Jenkins</h2>
23 <div class="body" id="body">
25 <div id="section1" class="section">
26 <div style="margin-top: 10%; text-align: center; font-size: 1.3em;">
28 Simulink Coder<sup>(TM)</sup> target for automotive rapid prototyping platform
32 <img style="display: block;margin: 0 auto 0 auto;" width="400" src="media/images/logos.png" alt=""/>
36 <div id="section2" class="section">
38 <h1 id="agenda">Agenda</h1>
50 <li>C Support Library.
52 <li>Simulink Coder Target.
54 <li>Simulink Block Set.
67 <div id="section3" class="section">
69 <h1 id="background">Background</h1>
72 Back in the beginning of 2012 a leading automotive company (Porsche) requested the Czech Technical
73 University to develop a Engine Control Unit (ECU) for automotive applications.
76 Real-Time Systems group at the Department of Control Engineering from the Faculty of Electrical
77 Engineering (a.k.a <em>next door</em>) developed a hardware and Software platform to the needs of this
78 industry (a.k.a <em>RPP</em> for Rapid Prototyping Platform).
81 The hardware uses Texas Instruments TMS570LS3137 (pretty nifty CPU for automotive applications) and
82 is built with automotive standards and interfaces in mind.
85 It uses a real-time operating system and is (was) directly programmed in C.
89 <div id="section4" class="section">
91 <h1 id="background_cont">Background (cont.)</h1>
94 <img style="display: block;margin: 0 auto 0 auto;" width="400" src="media/images/board.png" alt=""/>
98 <div id="section5" class="section">
100 <h1 id="background_cont_i">Background (cont. I)</h1>
103 Nevertheless, hand written C code is:
107 <li>Hard to produce, sometimes very low-level.
109 <li>Hard to debug. Yes, 1 bit took us 4 hours.
111 <li>Requires good knowledge of the underlying hardware.
113 <li>Most of the time is non-portable or hard to port between platforms.
115 <li>Hard to audit and certify.
121 <div id="section6" class="section">
123 <h1 id="background_cont_ii">Background (cont. II)</h1>
126 Because of this the company has the policy to implement the Software for their system using
127 <strong>Model-Based Design</strong>, which is a way to address these problems:
129 <div style=" text-align: center; font-style: italic;margin: 0 10% 0 10%;">
131 "Model-Based Design (MBD) is a mathematical and visual method of addressing problems associated
132 with designing complex control, signal processing and communication systems. It is used in many
133 motion control, industrial equipment, aerospace, and automotive applications. Model-based design
134 is a methodology applied in designing embedded software."
138 Or in other words, they use the Software <strong>Simulink</strong> for implementing their systems.
142 <div id="section7" class="section">
144 <h1 id="about_simulink">About Simulink</h1>
146 <div style=" text-align: center; font-style: italic;margin: 0 10% 0 10%;">
148 "Simulink, developed by MathWorks, is a data flow graphical programming language tool for modeling,
149 simulating and analyzing multidomain dynamic systems. Simulink is part of Matlab."
153 In other words, Simulink is a Software that allows to you create algorithms (systems) by connecting
154 boxes. Each box is like a function, with inputs and outputs (with data type and arity).
158 <div id="section8" class="section">
160 <h1 id="about_simulink_cont">About Simulink (cont.)</h1>
163 Oversimplifying, it is composed by two things:
167 <li><strong>Diagramming environment</strong>: Were you draw your algorithm. No more different that UML or
168 standard diagramming tools.
171 <li><strong>Block libraries</strong>: a library with lots of blocks that do something:
174 <li><em>Operations</em>: for example logical operations (OR, NOT, AND, etc), data type conversion,
175 integration, sum, product (remember arity), etc.
178 <li><em>Sources</em>: generate data for the model, like and pulse generator, signal repeater, wave
182 <li><em>Skins</em>: blocks that outputs the results of the model. Few examples, like oscilloscope or
191 <div id="section9" class="section">
193 <h1 id="about_simulink_cont_i">About Simulink (cont. I)</h1>
196 <img style="display: block;margin: 0 auto 0 auto;" width="800" src="media/images/simulink_gui.png" alt=""/>
200 <div id="section10" class="section">
202 <h1 id="about_simulink_cont_ii">About Simulink (cont. II)</h1>
205 The program or system developed with Simulink is referred as a <strong>model</strong>.
208 The models can be "compiled" to C code (code generation) using the <em>Simulink Coder</em> product.
212 <div id="section11" class="section">
214 <h1 id="things_developed">Things developed</h1>
217 <li><strong>C Support Library</strong>: <br />
218 Define the API to communicate with the board. Include drivers and operating system.
221 <li><strong>Simulink Coder Target</strong>: <br />
222 Allows Simulink model's code generation, compilation and download for the board.
225 <li><strong>Simulink Block Set</strong>: <br />
226 Set of blocks that allows Simulink models to use board IO and communication peripherals.
229 <li><strong>Demos</strong>: <br />
230 Just a bunch of examples of control application in form of Simulink models.
236 <div id="section12" class="section">
238 <h2 id="c_support_library">C Support Library</h2>
245 <li>Include drivers and operating system (FreeRTOS).
247 <li>Exposes a high-level user-oriented API for controlling the board.
249 <li>Static library, as part of the compilation each Simulink model link against this.
255 <div id="section13" class="section">
257 <h3 id="library___layers">Library - Layers</h3>
260 <img style="display: block;margin: 0 auto 0 auto;" width="500" src="media/images/layers.png" alt=""/>
264 <div id="section14" class="section">
266 <h3 id="library___modules">Library - Modules</h3>
269 <img style="display: block;margin: 0 auto 0 auto;" width="500" src="media/images/blocks.png" alt=""/>
273 <div id="section15" class="section">
275 <h3 id="library___modules_implemented">Library - Modules implemented</h3>
278 Modules in the scope of this project:
282 <li><strong>DIN</strong> : Digital Input.
284 <li><strong>LOUT</strong>: Digital Output.
286 <li><strong>AIN</strong>: Analog Input.
288 <li><strong>AOUT</strong>: Analog Output.
290 <li><strong>HBR</strong>: H-Bridge.
292 <li><strong>MOUT</strong>: Power outputs (2A).
294 <li><strong>SCI</strong>: SD-RAM logging.
296 <li><strong>SCI</strong>: Serial Communication Interface.
302 <div id="section16" class="section">
304 <h2 id="simulink_target">Simulink Target</h2>
307 Allows Simulink model's code generation, compilation and download to the board.
314 <li>Installation script.
316 <li>Target descriptor.
318 <li>Template to generate a Makefile for source compilation.
320 <li>Template to generate the C <em>main</em> file (entry point).
322 <li>Script to download the compiled model binary to the board.
324 <li>Other minor control and support files.
329 Simulink generates code for almost all the standard blocks. But the model needs a way to output
330 the results or input data so new blocks for board IO needed to be implemented.
334 <div id="section17" class="section">
336 <h2 id="simulink_block_set">Simulink Block Set</h2>
339 <img style="display: block;margin: 0 auto 0 auto;" width="600" src="media/images/block_library.png" alt=""/>
343 <div id="section18" class="section">
345 <h3 id="simulink_block_set___anatomy">Simulink Block Set - Anatomy</h3>
348 Each block is composed by:
352 <li>C-MEX S-Function. Fancy way to say:
354 <li>C : Implemented in C language. Other options are Fortran and Matlab language itself.
356 <li>MEX: Matlab Executable. Yes, it can be executed in Matlab, that's all. They are compiled by
357 Matlab GCC wrapper called MEX.
359 <li>S-Function: System Function, as opposed to standard functions, or user functions.
364 <li>TLC (Target Language Compiler) file for code generation for that block.
370 <div id="section19" class="section">
372 <h3 id="simulink_block_set___c_mex_s_function">Simulink Block Set - C-MEX S-Function</h3>
375 C file that uses the S-Function API to describe what the block does:
379 <li>Number of inputs and outputs. Just like a function.
381 <li>Datatype of each input and output. Can be static or dynamic (block context).
383 <li>Arity of each input and output. Scalar (single value), 1-D (array), 2-D (matrix). <br />
384 Matlab supports crazy things as dynamic n-dimensional dynamically typed matrices :O.
386 <li>Number of parameters (different from inputs), used to configure the block.
388 <li>Validation of parameters (things like range and datatype).
393 It can be used also for the block to do something within Simulink. Right now they are just
398 <div id="section20" class="section">
400 <h3 id="simulink_block_set___tlc_file">Simulink Block Set - TLC file</h3>
403 File that defines how to generate code for that block (term is <em>inline</em>).
406 Defines template C code and rules that will be used on code generation for:
410 <li>Initialization of the block (required headers, calls to initialization functions, etc).
412 <li>The step function, the one that is called at each step to update the model. <br />
413 "The function that is called in the main loop".
415 <li>Model termination. Like free manually allocated memory. Not used in our context.
420 TLC files can be viewed as wrappers for the C library API.
424 <div id="section21" class="section">
426 <h3 id="simulink_block_set___process">Simulink Block Set - Process</h3>
429 <img style="display: block;margin: 0 auto 0 auto;" src="media/images/tlc_process.png" alt=""/>
433 <div id="section22" class="section">
435 <h2 id="demos">Demos</h2>
438 12 demos for things like:
442 <li>Control analog output using analog input. Same for digital.
444 <li>Control H-Bridge (motor speed and direction) using analog input.
446 <li>Print a message. Echo all bytes received via SCI.
448 <li>Software generate a nice sinewave of analog outputs.
450 <li>Log each second the data read on one analog input.
458 <div id="section23" class="section">
460 <h3 id="demos___h_bridge_analog_control">Demos - H-Bridge Analog Control</h3>
463 <img style="display: block;margin: 0 auto 0 auto;" src="media/images/demo_hbridge_analog_control.png" alt=""/>
467 <div id="section24" class="section">
469 <h1 id="questions">Questions?</h1>
471 <div style="margin-top: 10%; text-align: center; font-size: 1.3em;">