]> rtime.felk.cvut.cz Git - jenkicar/rpp-simulink.git/blob - doc/reports/report2/publish/tex/report2.tex
adc5f65f216b2be4a982c98b9bfaa20415a960f9
[jenkicar/rpp-simulink.git] / doc / reports / report2 / publish / tex / report2.tex
1 \newcommand{\superscript}[1]{\ensuremath{^{\textrm{\small#1}}}}
2 \newcommand{\subscript}[1]{\ensuremath{_{\textrm{\small#1}}}}
3
4 \documentclass{article}
5
6 \usepackage{graphicx} % images and graphics
7 \usepackage{paralist} % needed for compact lists
8 \usepackage[normalem]{ulem} % needed by strike
9 \usepackage{listings} % required for code blocks
10 \usepackage[urlcolor=blue,colorlinks=true,hyperfootnotes=false]{hyperref} % links
11 \usepackage[utf8]{inputenc}  % char encoding
12 \usepackage[bottom]{footmisc} % footnotes
13
14 % header
15 \usepackage[top=2.5cm, bottom=2.5cm, left=2.5cm, right=2.5cm]{geometry}
16 \usepackage{float} % To fix images position
17
18 % Prettify code documentation
19 \usepackage{color}
20 \definecolor{gray97}{gray}{.97}
21 \definecolor{gray75}{gray}{.75}
22 \definecolor{gray45}{gray}{.45}
23 \lstset{ frame=Ltb,
24      framerule=0pt,
25      aboveskip=0.5cm,
26      framextopmargin=3pt,
27      framexbottommargin=3pt,
28      framexleftmargin=0.4cm,
29      framesep=0pt,
30      rulesep=.4pt,
31      backgroundcolor=\color{gray97},
32      rulesepcolor=\color{black},
33      %
34      stringstyle=\ttfamily,
35      showstringspaces = false,
36      basicstyle=\small\ttfamily,
37      commentstyle=\color{gray45},
38      keywordstyle=\bfseries,
39      %
40      numbers=left,
41      numbersep=15pt,
42      numberstyle=\tiny,
43      numberfirstline = false,
44      breaklines=true,
45      xleftmargin=20px,
46    }
47
48 % Spacing
49 \addtolength{\parskip}{\baselineskip} % Paragraph spacing
50 \linespread{1.15} % Lines spacing
51 \setlength{\plitemsep}{0.5\baselineskip} % List items spacing
52 \definecolor{deepblue}{RGB}{0,0,61}
53 \hypersetup{linkcolor=deepblue,}
54
55 % Table of content depth
56 \setcounter{tocdepth}{4}
57
58 % Landscape pages
59 \usepackage{lscape}
60 \usepackage{pdflscape}
61
62 % Change page
63 \usepackage{changepage}
64
65 % Font options
66 % Sans-serif
67 % \renewcommand{\familydefault}{\sfdefault}
68 % Better PDF font
69 \usepackage{lmodern}
70
71 % Multiple columns
72 \usepackage{multicol}
73
74 \begin{document}
75
76 % Title
77 \newcommand{\HRule}{\rule{\linewidth}{0.5mm}}
78
79 \begin{titlepage}
80 \begin{center}
81
82 % Upper part of the page
83 \includegraphics[width=0.70\textwidth]{media/images/logos.png}\\[1cm]
84 \textsc{\LARGE Costa Rica Institute of Technology}\\[0.5cm]
85 \textsc{\LARGE Czech Technical University in Prague}\\[1.5cm]
86 \textsc{\Large Undergraduate project}\\[0.5cm]
87
88
89 % Document title
90 \HRule \\[0.4cm]
91 { \huge \bfseries Progress report 2}\\[0.4cm]
92 \HRule \\[1.5cm]
93
94
95 % Author
96 \emph{Author:}\\
97 Carlos \textsc{Jenkins}\\
98
99 \vfill
100
101 % Bottom of the page
102 {\large \today}
103
104 \end{center}
105 \end{titlepage}
106 % Title end
107
108 \tableofcontents
109
110 \newpage
111
112 \hypertarget{introduction}{}
113 \section{Introduction}
114
115 This document describes the second progress report for the project ``Code generation for automotive 
116 rapid prototyping platform using Matlab/Simulink" executed on the first semester of 2013 at the 
117 Department of Control Engineering, Faculty of Electrical Engineering, Czech Technical University, 
118 as part of the specialty practice for applying for the Computer Engineering Bachelor degree at the 
119 Costa Rica Institute of Technology.
120
121 This report aims to outline the design of the system to develop.
122
123 \hypertarget{design_model}{}
124 \section{Design model}
125
126 This section describes the architecture of the system to be built. Please note that this project
127 target C embedded development and Simulink code generation (no user graphical interface, no 
128 database management system, etc) and thus traditional UML based design methodologies does not 
129 apply.
130
131 \newpage
132
133 \hypertarget{c_support_library}{}
134 \subsection{C Support Library}
135
136 The RPP C Support Library define the API to communicate with the board. It include drivers and
137 operating system. This section documents the design of this library.
138
139 \hypertarget{architecture}{}
140 \subsubsection{Architecture}
141
142 The RPP library is structured into 5 layers with the following guidelines:
143
144 \begin{compactitem}
145 \item Top-down dependency only. No lower layer depends on anything from upper layers.
146 \item 1-1 layer dependency only. The top layer depends exclusively on the bottom layer, not on any
147   lower level layer (except for a couple of exceptions).
148 \item Each layer should provide a unified layer interface (\texttt{rpp.h}, \texttt{drv.h}, \texttt{hal.h}, \texttt{sys.h}
149   and \texttt{os.h}), so top layers depends on that layer interface and not on individual elements from
150   that layer.
151 \end{compactitem}
152
153 \begin{figure}[H]\begin{center}
154
155 \noindent\includegraphics[width=250px]{media/images/layers.pdf}
156 \caption{The RPP library layers.}\end{center}\end{figure}
157
158 As a consequence of this division the source code files and interface files will be placed on
159 private directories so the previous prefix based inclusion \texttt{drv\_din.h} will be replaced by
160 \texttt{drv/din.h}. With this organization user applications will only need to include the top layer
161 interface file (\texttt{rpp/rpp.h}) to be able to use the library API.
162
163 \hypertarget{rpp_layer_modules}{}
164 \subsubsection{RPP Layer Modules}
165
166 The RPP Layer is structured into 14 different modules from 4 different categories that match the
167 hardware modules on the board:
168
169 \begin{center}\begin{tabular}{lll}
170 \textbf{Category} & \textbf{Description} & \textbf{MNEMONIC} \\
171 Logic IO & Digital Input & \texttt{[DIN ]} \\
172  & Digital (Logic) Output & \texttt{[LOUT]} \\
173  & Analog Input & \texttt{[AIN ]} \\
174  & Analog Output & \texttt{[AOUT]} \\
175 Power output & H-Bridge output & \texttt{[HBR ]} \\
176  & Power output (12V, 2A) & \texttt{[MOUT]} \\
177  & High-Power output (12V, 10A) & \texttt{[HOUT]} \\
178 Communication & CAN Bus & \texttt{[CAN ]} \\
179  & LIN (Local Interconnect Network) & \texttt{[LIN ]} \\
180  & FlexRay & \texttt{[FR  ]} \\
181  & Serial Communication Interface & \texttt{[SCI ]} \\
182  & Ethernet & \texttt{[ETH ]} \\
183 Logging & SD Card & \texttt{[SDC ]} \\
184  & SD-RAM & \texttt{[SDR ]} \\
185 \end{tabular}\end{center}
186
187 Please note the mnemonic of each module, as they will be constantly used on the Software and
188 documentation. Also note that only the following modules will be implemented as part of this 
189 project:
190
191 \begin{multicols}{2}
192
193 \begin{compactitem}
194 \item DIN.
195 \item LOUT.
196 \item AIN.
197 \item AOUT.
198 \item HBR.
199 \item MOUT.
200 \item SCI.
201 \item SDR.
202 \end{compactitem}
203
204 \end{multicols}
205
206 Modules for which there is a low-level API available on the library but no high-level module will 
207 be implemented:
208
209 \begin{multicols}{2}
210
211 \begin{compactitem}
212 \item CAN.
213 \item LIN.
214 \item FR.
215 \end{compactitem}
216
217 \end{multicols}
218
219 Modules that are not yet available on the library at all:
220
221 \begin{multicols}{2}
222
223 \begin{compactitem}
224 \item ETH (in the works).
225 \item SDC.
226 \item HOUT (partial).
227 \end{compactitem}
228
229 \end{multicols}
230
231 The following graphic shows the library modules and the connectors on the hardware they map to.
232
233 \begin{figure}[H]\advance\leftskip-1cm
234
235 \noindent\includegraphics[width=500px]{media/images/blocks.pdf}
236 \caption{The RPP Library modules.}\end{figure}
237
238 \newpage
239
240 \hypertarget{os_interchangeable_layer}{}
241 \subsubsection{OS interchangeable layer}
242
243 The OS Layer is composed by the FreeRTOS source code files. Because the FreeRTOS exposes an stable
244 API the OS layer can be changed in order to upgrade the Operating System or use a different port of
245 the OS, without changing the upper layers source code. The OS Layers currently available for the
246 RPP Library at \texttt{$<$repo$>$/rpp/lib/os/} at the time of this writing are:
247
248 \begin{compactitem}
249 \item Version 6.0.4 using POSIX port. This layer is the one that should be used when compiling a
250   program for x86(\_64) simulation. The port uses the \texttt{pthread} library and because of this the
251   port is not true real time and this is considered a simulator.
252 \item Version 7.0.2 using HalCoGen port for TMS570. This layer is the one currently supported and
253   tested. It was originally included in the testing application and was generated by an older
254   version of TI code generation tool HalCoGen.
255 \item Version 7.4.0 using HalCoGen port for TMS570. This layer was extracted from a newly generated
256   project using a newer version of HalCoGen. This layer is untested but \textit{should} work out of the
257   box.
258 \item Version 7.4.2 using ARM Cortex R4 official port for CCS. This layer was created from vanilla
259   FreeRTOS 7.4.2 release. It is tested but non-working. Ticks are proved to be executed in time but
260   applications using this kernel runs at full-speed. The reason if this is currently unknown.
261 \end{compactitem}
262
263 The general layout of all the layers are as following:
264
265 \begin{itemize}
266 \item Common source code (kernel):
267
268 \begin{verbatim}
269     src/os/croutine.c (Optional)
270     src/os/list.c
271     src/os/queue.c
272     src/os/tasks.c
273     src/os/timers.c (Optional)
274 \end{verbatim}
275
276
277 Originally found in vanilla distribution in: \texttt{$<$FreeRTOSRoot$>$/FreeRTOS/Source}
278
279 \item Common interface files:
280
281 \begin{verbatim}
282     include/os/croutine.h
283     include/os/FreeRTOS.h
284     include/os/list.h
285     include/os/mpu_wrappers.h
286     include/os/portable.h (with minor editions)
287     include/os/projdefs.h
288     include/os/queue.h
289     include/os/semphr.h
290     include/os/StackMacros.h
291     include/os/task.h
292     include/os/timers.h
293 \end{verbatim}
294
295
296 Originally found in vanilla distribution in: \texttt{$<$FreeRTOSRoot$>$/FreeRTOS/Source/include}
297
298 \item Memory management file:
299
300 \begin{verbatim}
301     src/os/heap.c (One of 4 version available, see Appendix A).
302 \end{verbatim}
303
304
305 Originally found in vanilla distribution in: \texttt{$<$FreeRTOSRoot$>$/FreeRTOS/Source/portable/MemMang}
306
307 \item Port specific files:
308
309 \begin{verbatim}
310     src/os/port.c
311     src/os/portASM.asm
312     include/os/portmacro.h
313     include/os/FreeRTOSConfig.h
314 \end{verbatim}
315
316
317 This depend of the port. In the case of the 7.4.2 TMS570 / ARM Cortex R4 for CCS port:
318
319  \begin{compactitem}
320  \item First three files can be found in vanilla distribution in \newline{}
321    \texttt{$<$FreeRTOSRoot$>$/FreeRTOS/Source/portable/CCS/ARM\_Cortex-R4}.
322  \item Last file in \texttt{$<$FreeRTOSRoot$>$/FreeRTOS/Demo/CORTEX\_R4\_RM48\_TMS570\_CCS5}.
323  \end{compactitem}
324 \end{itemize}
325
326 In general, the following changes were applied to the source code base of all kernels:
327
328 \begin{itemize}
329 \item Replaced include directives to adapt to RPP library standard:
330
331 \texttt{\#include "} with \texttt{\#include "os/}
332
333 \item Line ending character set to UNIX '$\backslash$n' and tabs replaced by 4 spaces.
334 \end{itemize}
335
336 \newpage
337
338 \hypertarget{api_development_guidelines}{}
339 \subsubsection{API development guidelines}
340
341 \vspace{-0.40cm}
342
343 The following are the development guidelines that will be used for developing the RPP API:
344
345 \begin{compactitem}
346 \item User documentation should be placed in header files, not in source code, and should be Doxygen
347   formatted using autobrief. Documentation for each function present is mandatory.
348 \item Function declarations on the headers files is for public functions only. Do not declare
349   local/static/private functions on the header.
350 \item Documentation on source code files should be non-doxygen formatted and intended for developers,
351   not users. Documentation here is optional and at the discretion of the developer.
352 \item Always use standard data types for IO when possible. Use custom structs as very last resort.
353 \item Use prefix based functions names to avoid clash. The prefix is of the form \texttt{[layer]\_[module]\_},
354   for example \texttt{rpp\_din\_update()} for the update function of the DIN module in the RPP Layer.
355 \item To be very careful about symbol export. Because it is used as a static library the modules should
356   not export any symbol that is not intended to be used (function) or \texttt{extern}'ed (variable) from
357   application. As a rule of thumb declare all global variables as static.
358 \item Only the RPP Layer symbols are available to user applications. All information related to lower
359   layers is hidden for the application. This is accomplished by conditionally including the layers
360   elements on the implementations files only and never on the interface files. Never expose any
361   other layer to the application or the the whole system below that layer will be exposed. In other
362   words, never \texttt{\#include "foo/foo.h"} in any RPP Layer interface file.
363 \item Any module is conditionally included by using \texttt{rppCONFIG\_INCLUDE\_\{MNEMONIC\}} directive on the
364   \texttt{RppConfig.h} configuration file.
365 \end{compactitem}
366
367 \vspace{-0.40cm}
368
369 \hypertarget{simulink_coder_target}{}
370 \subsection{Simulink Coder Target}
371
372 The Simulink Coder Target is the deliverable that will allow Simulink model's code generation, 
373 compilation and download for the board.
374
375 The Simulink RPP Target will provide support for C source code generation from Simulink models and
376 compilation of that code on top of the RPP library and the FreeRTOS operating system. This target
377 will use Texas Instrument ARM compiler (armcl) included in the Code Generation Tools available with
378 Code Composer Studio.
379
380 This library will also provide support for automatically download the compiled machine code to the 
381 RPP board.
382
383 \hypertarget{code_generation_process}{}
384 \subsubsection{Code generation process}
385
386 \begin{figure}[H]\begin{center}
387
388 \noindent\includegraphics[width=400px]{media/images/tlc_process.png}
389 \caption{TLC code generation process.}\end{center}\end{figure}
390
391 \hypertarget{simulink_block_library}{}
392 \subsection{Simulink Block Library}
393
394 \vspace{-0.25cm}
395
396 The Simulink Block Library will be a set of blocks that allows Simulink models to use board IO and 
397 communication peripherals.
398
399 \vspace{-0.5cm}
400
401 \hypertarget{c_mex_s_functions}{}
402 \subsubsection{C MEX S-Functions}
403
404 All of the blocks will be implemented as a C Mex S-Function coded by hand. In the this section the 
405 approach that will be taken is explained.
406
407 C-MEX S-Function:
408
409  \begin{compactitem}
410  \item C : Implemented in C language. Other options are Fortran and Matlab language itself.
411  \item MEX: Matlab Executable. They are compiled by Matlab GCC wrapper called MEX.
412  \item S-Function: System Function, as opposed to standard functions, or user functions.
413  \end{compactitem}
414
415 A C-MEX S-Function is a structured C file that includes the following mandatory callbacks:
416
417 \begin{compactenum}
418 \item \texttt{mdlInitializeSizes}: \newline{}
419   Specify the number of inputs, outputs, states, parameters, and other characteristics of the C 
420   MEX S-function.
421 \item \texttt{mdlInitializeSampleTimes}: \newline{}
422   Specify the sample rates at which this C MEX S-function operates.
423 \item \texttt{mdlOutputs}: \newline{}
424   Compute the signals that this block emits.
425 \item \texttt{mdlTerminate}: \newline{}
426   Perform any actions required at termination of the simulation.
427 \end{compactenum}
428
429 Plus many more optional callbacks. Relevant optional callbacks are:
430
431 \begin{compactenum}
432 \item \texttt{mdlCheckParameters}: \newline{}
433   Check the validity of a C MEX S-function's parameters.
434 \item \texttt{mdlRTW}: \newline{}
435   Generate code generation data for a C MEX S-function.
436 \item \texttt{mdlSetWorkWidths}: \newline{}
437   Specify the sizes of the work vectors and create the run-time parameters required by the C MEX 
438   S-function.
439 \item \texttt{mdlStart}: \newline{}
440   Initialize the state vectors of the C MEX S-function.
441 \end{compactenum}
442
443 A complete list of callbacks can be found in:
444
445         \begin{quotation}
446 \htmladdnormallink{http://www.mathworks.com/help/simulink/create-cc-s-functions.html}{http://www.mathworks.com/help/simulink/create-cc-s-functions.html}
447         \end{quotation}
448
449 \newpage
450 The way a C-MEX S-Function participates in a Simulink simulation is shown by the following diagram:
451
452 \begin{figure}[H]\begin{center}
453
454 \noindent\includegraphics[width=250px]{media/images/sfunctions_process.png}
455 \caption{Simulation cycle of a S-Function.}\end{center}\end{figure}
456
457 In general, a S-Function can perform calculations and inputs and outputs for simulation. Because 
458 the blocks that will be implemented for this project are for hardware peripherals control and IO 
459 the blocks will be implemented as pure sink or pure source. That is, the S-Function will be a 
460 descriptor of the block but will not do any calculation or input or output for simulation. 
461
462 The S-Functions required could be implemented in several ways:
463
464 \begin{compactenum}
465 \item Writing the S-Function. \newline{}
466   Using this method, the user hand write a new C S-Function and associated TLC file. This method 
467   requires the most knowledge about the structure of a C S-Function.
468 \item Using an S-Function Builder block. \newline{}
469   Using this method, the user enter the characteristics of the S-function into a block dialog. This 
470   method does not require any knowledge about writing S-Functions. However, a basic understanding 
471   of the structure of an S-Function can make the S-Function Builder dialog box easier to use.
472 \item Using the Legacy Code Tool (LCT). \newline{}
473   Using this command line method, the user define the characteristics of your S-function in a data 
474   structure in the MATLAB workspace. This method requires the least amount of knowledge about 
475   S-Functions.
476 \end{compactenum}
477
478 From the above, the LCT is a tool that can be called within Matlab workshop that allows to generate 
479 source code for S-Functions given the descriptor of a C function call. This approach is used by
480 most of the other targets reviewed for this project. The descriptor is a Matlab file with 
481 definitions like the following:
482
483 \newpage
484 \lstset{language=}
485 \begin{lstlisting}
486 %% GPIO Write
487 % Populate legacy_code structure with information
488 GPIOWrite = legacy_code('initialize');
489 GPIOWrite.SFunctionName = 'sfun_GPIOWrite';
490 GPIOWrite.HeaderFiles = {'gpiolct.h'};
491 GPIOWrite.SourceFiles = {'gpiolct.c'};
492 GPIOWrite.OutputFcnSpec = 'GPIOWrite(uint32 p1, uint8 u1, uint8 u2)';
493 % Support calling from within For-Each subsystem
494 GPIOWrite.Options.supportsMultipleExecInstances = true;
495 \end{lstlisting}
496
497 The interface and implementation files specified should hold the declaration and implementation of
498 the \texttt{OutputFcnSpec} function. This tool will generate a simple S-Function that will input and 
499 output the values required by that function. This approach will \textbf{not} be used for this project, 
500 mainly because:
501
502 \begin{itemize}
503 \item The RPP Library requires that after some actions (like setting one LOUT output) the changes are 
504   committed to the hardware, or before some other actions (like getting the value from DIN using 
505   the fixed threshold) the values cached are updated. And the implementation of a wrapper function
506   that would update or commit the changes wasn't considered because of the efficiency impact it
507   would have.
508
509 \item Furthermore, the error handling of the function call is not considered, and for some blocks 
510   (like MOUT and HOUT) the diagnostic handling is mandatory.
511
512 \item Also, the dialog parameters of the S-Function cannot be validated otherwise than data type 
513   (cannot validate range, for example). 
514
515 \item For future improvements the LCT cannot generate code for simulation, and a lot of S-Function 
516   options cannot not be fine tuned. 
517
518 \item Finally, the generated code is very obscure, hard to read and to maintain in case the above 
519   functionality had to be implemented on top of the generated code.
520 \end{itemize}
521
522 Similarly hand written S-Functions share a large amount of code like parameters scalar, data 
523 type and range validation, standard options for this kind of blocks, unused functions, among other. 
524 Because of this a mini framework for writing S-Functions for RPP will be implemented in the form of 
525 two files that are directly included at the beginning and end of the S-Function implementation: 
526 \texttt{header.c} and  \texttt{trailer.c}. 
527
528 This mini-framework will reduce the amount of required code for each S-Function considerably, 
529 making easier to maintain and adapt. Because each S-Function is a program by itself there is no 
530 need to use interface files and the files are directly included.
531
532 \newpage
533 The final form of the S-Function will be a C file of around 100 lines of code with the following 
534 layout:
535
536 \begin{itemize}
537 \item Define S-Function name \texttt{S\_FUNCTION\_NAME}.
538
539 \item Include header file \texttt{header.c}.
540
541 \item In \texttt{mdlInitializeSizes} define:
542  \begin{itemize}
543  \item Number of \textit{dialog} parameter.
544  \item Number of input ports.
545   \begin{compactitem}
546   \item Data type of each input port.
547   \end{compactitem}
548  \item Number of output ports.
549   \begin{compactitem}
550   \item Data type of each output port.
551   \end{compactitem}
552  \item Standard options for driver blocks.
553
554  \end{itemize}
555 \item In \texttt{mdlCheckParameters}:
556  \begin{itemize}
557  \item Check data type of each parameter.
558  \item Check range, if applicable, of each parameter.
559
560  \end{itemize}
561 \item In \texttt{mdlSetWorkWidths}:
562  \begin{compactitem}
563  \item Map \textit{dialog} parameter to \textit{runtime} parameters.
564   \begin{itemize}
565   \item Data type of each \textit{runtime} parameter.
566
567   \end{itemize}
568  \end{compactitem}
569 \item Define symbols for unused functions.
570
571 \item Include trailer file \texttt{trailer.c}.
572 \end{itemize}
573
574 The C-MEX S-Function implemented will compile with the following command:
575
576 \lstset{language=bash}
577 \begin{lstlisting}
578 <matlabroot>/bin/mex sfunction_{mnemonic}.c
579 \end{lstlisting}
580
581 As noted the standard is to always prefix S-Function with \texttt{sfunction\_} and use lower case 
582 mnemonic of the block.
583
584 Also a script called \texttt{compile\_blocks.m} will be included that will allows all \texttt{sfunctions\_*.c} 
585 to be fed to the \texttt{mex} compiler so all S-Functions are compiled at once.
586
587 \newpage
588
589 \hypertarget{target_language_compiler_files}{}
590 \subsubsection{Target Language Compiler files}
591
592 C code generated from a Simulink model will be placed on a file called \texttt{$<$modelname$>$.c} along with 
593 other support files in a folder called \texttt{$<$modelname$>$\_$<$target$>$/}. For example, the source code
594 generated for model \texttt{foobar} will be placed in current Matlab directory \texttt{foobar\_rpp/foobar.c}.
595
596 The file \texttt{$<$modelname$>$.c} has 3 main functions:
597
598 \begin{compactitem}
599 \item \texttt{void $<$modelname$>$\_step(void)}: \newline{}
600   This function recalculates all the outputs of the blocks and should be called once per step. This
601   is the main working function.
602 \item \texttt{void $<$modelname$>$\_initialize(void)}: \newline{}
603   This function is called only once before the first step is issued. Default values for blocks IOs
604   should be placed here.
605 \item \texttt{void $<$modelname$>$\_terminate(void)}: \newline{}
606   This function is called when terminating the model. This should be used to free memory of revert 
607   other operations made on the initialization function. With current implementation this function
608   should never be called unless an errors is detected and in most models it is empty.
609 \end{compactitem}
610
611 In order to generate code for each one of those functions each S-Function will implement a TLC file
612 for \textit{inlining} the S-Function on the generated code. The TLC files are files that describe how to 
613 generate code for a specific C-MEX S-Function block. They are programmed using TLC own language and 
614 include C code within TLC instructions, just like LaTeX files include normal text in between LaTeX 
615 macros.
616
617 TLC files will be located under \texttt{$<$repo$>$/rpp/blocks/tlc\_c/} directory. For a diagram on how TLC 
618 files work see \htmladdnormallink{Code generation process}{\#code\_generation\_process} section.
619
620 The standard for a TLC file is to be located under the \texttt{tlc\_c} subfolder from where the 
621 S-Function is located and to use the very exact file name as the S-Function but with the \texttt{.tlc}
622 extension:
623
624 \texttt{sfunction\_foo.c} \noindent$\rightarrow$ \texttt{tlc\_c/sfunction\_foo.tlc}
625
626 The TLC files that will be implemented for this project use 3 hook functions in particular (other 
627 are available, see TLC reference documentation):
628
629 \begin{itemize}
630 \item \texttt{BlockTypeSetup}: \newline{}
631   BlockTypeSetup executes once per block type before code generation begins.
632   This function can be used to include elements required by this block type, like includes or
633   definitions.
634
635 \item \texttt{Start}: \newline{}
636   Code here will be placed in the \texttt{void $<$modelname$>$\_initialize(void)}. Code placed here will
637   execute only once.
638
639 \item \texttt{Outputs}: \newline{}
640   Code here will be placed in the \texttt{void $<$modelname$>$\_step(void)} function. Should be used to 
641   get the inputs o a block and/or to set the outputs of that block.
642 \end{itemize}
643
644 The general layout of the TLC files that will be implemented for this project are:
645
646 \begin{itemize}
647 \item In \texttt{BlockTypeSetup}: \newline{}
648   Call common function \texttt{\%$<$RppCommonBlockTypeSetup(block, system)$>$} that will include the 
649   \texttt{rpp/rpp.h} header file (can be called multiple times but header is included only once).
650
651 \item \texttt{Start}: \newline{}
652   Call setup routines from RPP Layer for the specific block type, like HBR enable, DIN pin setup, 
653   AOUT value initialization, SCI baud rate setup, among others.
654
655 \item \texttt{Outputs}: \newline{}
656   Call common IO routines from RPP Layer, like DIN read, AOUT set, etc. Success of this functions
657   is checked and in case of failure error is reported to the block using ErrFlag.
658 \end{itemize}
659
660 \hypertarget{simulink_demos_library}{}
661 \subsection{Simulink Demos Library}
662
663 The Simulink RPP Demo Library will be a set of Simulink models that use blocks from the 
664 Simulink RPP Block Library and generates code using the Simulink RPP Target.
665
666 The demos library will be used as a test suite for the Simulink RPP Block Library but it is also
667 intended to show basic programs built using it. Because of this, the demos will try to use more 
668 than one type of block and more than one block per block type.
669
670 The following table shows the specification and status of the demos:
671
672 \begin{center}\begin{tabular}{|l|l|l|}
673 \hline \textbf{Name} & \textbf{Implemented} & \textbf{Tested} \\
674 \hline analog\_passthrough & \multicolumn{1}{|c|}{NO} & \multicolumn{1}{|c|}{NO YET} \\
675 \hline analog\_sinewave & \multicolumn{1}{|c|}{NO} & \multicolumn{1}{|c|}{NO YET} \\
676 \hline digital\_passthrough & \multicolumn{1}{|c|}{NO} & \multicolumn{1}{|c|}{NO YET} \\
677 \hline echo\_char & \multicolumn{1}{|c|}{NO} & \multicolumn{1}{|c|}{NO YET} \\
678 \hline hbridge\_analog\_control & \multicolumn{1}{|c|}{NO} & \multicolumn{1}{|c|}{NO YET} \\
679 \hline hbridge\_digital\_control & \multicolumn{1}{|c|}{NO} & \multicolumn{1}{|c|}{NO YET} \\
680 \hline hbridge\_sinewave\_control & \multicolumn{1}{|c|}{NO} & \multicolumn{1}{|c|}{NO YET} \\
681 \hline hello\_world & \multicolumn{1}{|c|}{NO} & \multicolumn{1}{|c|}{NO YET} \\
682 \hline led\_blink\_all & \multicolumn{1}{|c|}{NO} & \multicolumn{1}{|c|}{NO YET} \\
683 \hline led\_blink & \multicolumn{1}{|c|}{NO} & \multicolumn{1}{|c|}{NO YET} \\
684 \hline log\_analog\_input & \multicolumn{1}{|c|}{NO} & \multicolumn{1}{|c|}{NO YET} \\
685 \hline power\_toggle & \multicolumn{1}{|c|}{NO} & \multicolumn{1}{|c|}{NO YET} \\
686 \hline \end{tabular}\end{center}
687
688 \newpage
689
690 \hypertarget{work_schedule}{}
691 \section{Work schedule}
692
693 \begin{center}\begin{tabular}{|c|c|l|}
694 \hline \textbf{Date} & \textbf{Deliverable} & \textbf{Priority} \\
695 \hline \multicolumn{1}{|l|}{15.4.2013} & \multicolumn{1}{|l|}{C support library and test suite.} & \multicolumn{1}{|c|}{1} \\
696 \hline \multicolumn{1}{|l|}{01.5.2013} & \multicolumn{1}{|l|}{Simulink Coder target for RPP board.} & \multicolumn{1}{|c|}{2} \\
697 \hline \multicolumn{1}{|l|}{01.6.2013} & \multicolumn{1}{|l|}{Simulink Block library. S-Functions and TLC files.} & \multicolumn{1}{|c|}{3} \\
698 \hline \multicolumn{1}{|l|}{07.6.2013} & \multicolumn{1}{|l|}{Simulink Demo  library.} & \multicolumn{1}{|c|}{4} \\
699 \hline \multicolumn{1}{|l|}{21.6.2013} & \multicolumn{1}{|l|}{Finish documentation of the developed product.} & \multicolumn{1}{|c|}{5} \\
700 \hline \end{tabular}\end{center}
701
702 \end{document}