1 Simulink coder target for automotive rapid prototyping platform
6 %!style(xhtmls): media/themes/Clean Presentation/style.css
7 %!postproc(xhtmls): '->' '→'
8 %!nested(xhtmls): --libs jquery
9 %!nested(tex): --docclass {article}
13 %xhtmls% ''' <div style="margin-top: 10%; text-align: center; font-size: 1.3em;">
14 Simulink Coder^^(TM)^^ target for automotive rapid prototyping platform
30 - Simulink Coder Target.
36 = Background =[background]
38 Back in the beginning of 2012 a leading automotive company (Porsche) requested the Czech Technical
39 University to develop a Engine Control Unit (ECU) for automotive applications.
41 Real-Time Systems group at the Department of Control Engineering from the Faculty of Electrical
42 Engineering (a.k.a //next door//) developed a hardware and Software platform to the needs of this
43 industry (a.k.a //RPP// for Rapid Prototyping Platform).
45 The hardware uses Texas Instruments TMS570LS3137 (pretty nifty CPU for automotive applications) and
46 is built with automotive standards and interfaces in mind.
48 It uses a real-time operating system and is (was) directly programmed in C.
50 = Background (cont.) =[background_cont]
54 = Background (cont. I) =[background_cont_i]
56 Nevertheless, hand written C code is:
58 - Hard to produce, sometimes very low-level.
59 - Hard to debug. Yes, 1 bit took us 4 hours.
60 - Requires good knowledge of the underlying hardware.
61 - Most of the time is non-portable or hard to port between platforms.
62 - Hard to audit and certify.
66 = Background (cont. II) =[background_cont_ii]
68 Because of this the company has the policy to implement the Software for their system using
69 **Model-Based Design**, which is a way to address these problems:
71 %xhtmls% ''' <div style=" text-align: center; font-style: italic;margin: 0 10% 0 10%;">
72 "Model-Based Design (MBD) is a mathematical and visual method of addressing problems associated
73 with designing complex control, signal processing and communication systems. It is used in many
74 motion control, industrial equipment, aerospace, and automotive applications. Model-based design
75 is a methodology applied in designing embedded software."
79 Or in other words, they use the Software **Simulink** for implementing their systems.
81 = About Simulink =[about_simulink]
83 %xhtmls% ''' <div style=" text-align: center; font-style: italic;margin: 0 10% 0 10%;">
84 "Simulink, developed by MathWorks, is a data flow graphical programming language tool for modeling,
85 simulating and analyzing multidomain dynamic systems. Simulink is part of Matlab."
89 In other words, Simulink is a Software that allows to you create algorithms (systems) by connecting
90 boxes. Each box is like a function, with inputs and outputs (with data type and arity).
94 = About Simulink (cont.) =[about_simulink_cont]
96 Oversimplifying, it is composed by two things:
98 - **Diagramming environment**: Were you draw your algorithm. No more different that UML or
99 standard diagramming tools.
101 - **Block libraries**: a library with lots of blocks that do something:
103 - //Operations//: for example logical operations (OR, NOT, AND, etc), data type conversion,
104 integration, sum, product (remember arity), etc.
106 - //Sources//: generate data for the model, like and pulse generator, signal repeater, wave
109 - //Skins//: blocks that outputs the results of the model. Few examples, like oscilloscope or
114 = About Simulink (cont. I) =[about_simulink_cont_i]
116 [800-simulink_gui.png]
118 = About Simulink (cont. II) =[about_simulink_cont_ii]
120 The program or system developed with Simulink is referred as a **model**.
122 The models can be "compiled" to C code (code generation) using the //Simulink Coder// product.
124 = Things developed =[things_developed]
126 - **C Support Library**: @@
127 Define the API to communicate with the board. Include drivers and operating system.
129 - **Simulink Coder Target**: @@
130 Allows Simulink model's code generation, compilation and download for the board.
132 - **Simulink Block Set**: @@
133 Set of blocks that allows Simulink models to use board IO and communication peripherals.
136 Just a bunch of examples of control application in form of Simulink models.
139 == C Support Library ==[c_support_library]
143 - Include drivers and operating system (FreeRTOS).
144 - Exposes a high-level user-oriented API for controlling the board.
145 - Static library, as part of the compilation each Simulink model link against this.
148 === Library - Layers ===[library___layers]
152 === Library - Modules ===[library___modules]
156 === Library - Modules implemented ===[library___modules_implemented]
158 Modules in the scope of this project:
160 - **DIN** : Digital Input.
161 - **LOUT**: Digital Output.
162 - **AIN**: Analog Input.
163 - **AOUT**: Analog Output.
165 - **MOUT**: Power outputs (2A).
166 - **SCI**: SD-RAM logging.
167 - **SCI**: Serial Communication Interface.
169 == Simulink Target ==[simulink_target]
171 Allows Simulink model's code generation, compilation and download to the board.
175 - Installation script.
177 - Template to generate a Makefile for source compilation.
178 - Template to generate the C //main// file (entry point).
179 - Script to download the compiled model binary to the board.
180 - Other minor control and support files.
183 Simulink generates code for almost all the standard blocks. But the model needs a way to output
184 the results or input data so new blocks for board IO needed to be implemented.
186 == Simulink Block Set ==[simulink_block_set]
188 [600-block_library.png]
190 === Simulink Block Set - Anatomy ===[simulink_block_set___anatomy]
192 Each block is composed by:
194 - C-MEX S-Function. Fancy way to say:
195 - C : Implemented in C language. Other options are Fortran and Matlab language itself.
196 - MEX: Matlab Executable. Yes, it can be executed in Matlab, that's all. They are compiled by
197 Matlab GCC wrapper called MEX.
198 - S-Function: System Function, as opposed to standard functions, or user functions.
200 - TLC (Target Language Compiler) file for code generation for that block.
203 === Simulink Block Set - C-MEX S-Function ===[simulink_block_set___c_mex_s_function]
205 C file that uses the S-Function API to describe what the block does:
207 - Number of inputs and outputs. Just like a function.
208 - Datatype of each input and output. Can be static or dynamic (block context).
209 - Arity of each input and output. Scalar (single value), 1-D (array), 2-D (matrix). @@
210 Matlab supports crazy things as dynamic n-dimensional dynamically typed matrices :O.
211 - Number of parameters (different from inputs), used to configure the block.
212 - Validation of parameters (things like range and datatype).
215 It can be used also for the block to do something within Simulink. Right now they are just
218 === Simulink Block Set - TLC file ===[simulink_block_set___tlc_file]
220 File that defines how to generate code for that block (term is //inline//).
222 Defines template C code and rules that will be used on code generation for:
224 - Initialization of the block (required headers, calls to initialization functions, etc).
225 - The step function, the one that is called at each step to update the model. @@
226 "The function that is called in the main loop".
227 - Model termination. Like free manually allocated memory. Not used in our context.
230 TLC files can be viewed as wrappers for the C library API.
233 === Simulink Block Set - Process ===[simulink_block_set___process]
239 12 demos for things like:
241 - Control analog output using analog input. Same for digital.
242 - Control H-Bridge (motor speed and direction) using analog input.
243 - Print a message. Echo all bytes received via SCI.
244 - Software generate a nice sinewave of analog outputs.
245 - Log each second the data read on one analog input.
248 === Demos - H-Bridge Analog Control ===[demos___h_bridge_analog_control]
250 [demo_hbridge_analog_control.png]
252 = Questions? =[questions]
254 %xhtmls% ''' <div style="margin-top: 10%; text-align: center; font-size: 1.3em;">