]> rtime.felk.cvut.cz Git - jenkicar/rpp-simulink.git/blob - doc/rpp_simulink.tex
doc: small fix
[jenkicar/rpp-simulink.git] / doc / rpp_simulink.tex
1 \newcommand{\superscript}[1]{\ensuremath{^{\textrm{\small#1}}}}
2 \newcommand{\subscript}[1]{\ensuremath{_{\textrm{\small#1}}}}
3
4 \documentclass{scrreprt}
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[utf8x]{inputenc}  % char encoding
12 \usepackage[bottom]{footmisc} % footnotes
13 \usepackage{todonotes}
14
15 % header
16 \usepackage[top=2.5cm, bottom=2.5cm, left=2.5cm, right=2.5cm]{geometry}
17 \usepackage{float} % To fix images position
18
19 % Prettify code documentation
20 \usepackage{color}
21 \definecolor{gray97}{gray}{.97}
22 \definecolor{gray75}{gray}{.75}
23 \definecolor{gray45}{gray}{.45}
24 \lstset{ frame=Ltb,
25      framerule=0pt,
26      aboveskip=0.5cm,
27      framextopmargin=3pt,
28      framexbottommargin=3pt,
29      framexleftmargin=0.4cm,
30      framesep=0pt,
31      rulesep=.4pt,
32      backgroundcolor=\color{gray97},
33      rulesepcolor=\color{black},
34      %
35      stringstyle=\ttfamily,
36      showstringspaces = false,
37      basicstyle=\small\ttfamily,
38      commentstyle=\color{gray45},
39      keywordstyle=\bfseries,
40      %
41      numbers=left,
42      numbersep=15pt,
43      numberstyle=\tiny,
44      numberfirstline = false,
45      breaklines=true,
46      xleftmargin=20px,
47    }
48
49 % Spacing
50 \linespread{1.15} % Lines spacing
51 \setlength{\plitemsep}{0.5\baselineskip} % List items spacing
52 \definecolor{deepblue}{RGB}{0,0,61}
53 \definecolor{deepgreen}{RGB}{0,80,0}
54 \hypersetup{linkcolor=deepblue,citecolor=deepgreen,}
55
56 % Table of content depth
57 \setcounter{tocdepth}{2}
58
59 % Landscape pages
60 \usepackage{lscape}
61 \usepackage{pdflscape}
62
63 % Change page
64 \usepackage{changepage}
65
66 % Font options
67 % Sans-serif
68 % \renewcommand{\familydefault}{\sfdefault}
69 % Better PDF font
70 \usepackage{lmodern}
71
72 % Multiple columns
73 \usepackage{multicol}
74 \usepackage{caption}
75
76 \newcommand{\repo}{$\langle$repo$\rangle$}
77
78 \begin{document}
79
80 % Title
81 \newcommand{\HRule}{\rule{\linewidth}{0.5mm}}
82
83 \begin{titlepage}
84 \begin{center}
85
86 % Upper part of the page
87 \includegraphics[width=0.70\textwidth]{images/logos.png}\\[1cm]
88 \textsc{\LARGE Costa Rica Institute of Technology}\\[0.5cm]
89 \textsc{\LARGE Czech Technical University in Prague}\\[1.5cm]
90
91
92 % Document title
93 \HRule \\[0.4cm]
94 { \huge \bfseries Code generation for automotive rapid prototyping platform using Matlab/Simulink}\\[0.4cm]
95 \HRule \\[1.5cm]
96
97
98 % Author
99 \emph{Authors:}\\
100 Carlos \textsc{Jenkins}\\
101 Michal \textsc{Horn}\\
102 Michal \textsc{Sojka}\\[\baselineskip]
103
104 \vfill
105
106 \emph{Version:}
107 \input{version.tex}
108
109 % Bottom of the page
110 {\large \today}
111
112 \end{center}
113 \end{titlepage}
114 % Title end
115
116 \tableofcontents
117
118 \newpage
119
120 \listoffigures
121
122 \newpage
123
124 %\addtolength{\parskip}{\baselineskip} % Paragraph spacing
125
126 \chapter{Introduction}
127 \label{chap-introduction}
128
129 This text is a documentation for a Rapid Prototyping Platform (RPP) project. It
130 may serve as a guideline for development tools installation, Simulink Coder
131 configuration, creation of new models as well as downloading the resulting
132 firmware to the hardware. It can also be used as a reference for a testing tool,
133 Matlab Simulink blocks and RPP Matlab Simulink Code generator. The document also
134 provides an overall description of the hardware design and architecture of its
135 control software.
136
137 \section{Background}
138 \label{sec-background}
139
140 The Rapid Prototyping Platform is an ECU (Electronic Control Unit) designed for
141 use in Automotive, thus requirements for Automotive communication interfaces,
142 durable IO ports and analog-digital converters were applied.
143
144 The ECU is controlled by TMS570LS5137ZWT MCU, which is an ARM Cortex R4 based
145 microcontroller developed by Texas Instruments. This MCU contains several
146 protective mechanisms (two cores in lockstep, error correction mechanisms for
147 SRAM and Flash memory, voltage monitoring, etc.) to fulfill the requirements for
148 safety critical applications. See~\cite{tms570ls31xtechnicalreferencemanual2012}
149 for details.
150
151 In order to develop non-trivial applications for the RPP, an operating
152 system is necessary. The RPP is based on FreeRTOS -- an opensource operating
153 system real-time kernel, aimed not only at embedded systems. The FreeRTOS
154 provides an API for creating and managing multiple tasks, scheduler, memory
155 manager, semaphores, queues, mutexes, timers and lots of other features which can
156 be used in the applications. See~\cite{usingthefreertos2009} for more details.
157
158 Even with the operating system it is quite hard and non-intuitive to
159 control the hardware directly. That is the point when abstraction
160 comes into the play. The RPP software is made of several layers
161 implementing, from the bottom to the top, low-level device drivers,
162 hardware abstraction for common functionality on different hardware
163 and an API which is easy to use in applications. The operating
164 system and the control software, can be compiled as a library and
165 easily used in any project. More details about the library can be
166 found in Chapter~\ref{chap-c-support-library} and in~\cite{michalhorn2013}.
167
168 Because humans make mistakes and in safety critical applications any mistake can
169 cause damage, looses of money or in the worst case even death of other people,
170 the area for making mistakes has to be as small as possible. An approach called
171 Model--based \cite{modelbasedwiki2013} development has been introduced. In
172 Simulink  the application is developed as a model made of interconnected blocks. 
173 Every block implements some functionality. For example one block
174 receives a voltage from an analog--digital converter, provides the value as an
175 input to another block which implements some clever algorithm and the product is
176 passed as an input to another block, which sends the value as a CAN message to
177 some other MCU. The final model can be simulated and tested even before the real
178 hardware exists. Finally a C code is generated from the model by a Simulink Code
179 Generator. The code can be compiled by the MCU compatible compiler and
180 downloaded to the MCU Flash memory on the device. Because every block and code
181 generated from the block has to pass a series of tests during their development,
182 the area for making mistakes during the application development has
183 been significantly reduced and developers can focus on the application instead of
184 the hardware and control software implementation. More information about Code
185 generation can be found in Chapter \ref{chap-simulink-coder-target}. For a
186 reference about Matlab Simulink, Embedded Coder and Simulink Coder,
187 refer to
188 \cite{embeddedcoderreference2013, ebmeddedcoderusersguide2013,
189   simulinkcoderreference2013, targetlanguagecompiler2013,
190   simulinkcoderusersguide2013, simulinkdevelopingsfunctions2013}.
191
192 \section{Software architecture}
193 \label{sec-software-architecture}
194 The basic RPP software, also called the RPP Library, is structured
195 into 5 layers, depicted in Figure~\ref{fig-layers}. The architecture
196 design was driven by the following guidelines:
197
198 \begin{compactitem}
199         \item Top-down dependency only. No lower layer depends on anything from
200 upper layers.
201         \item 1-1 layer dependency only. The top layer depends
202 exclusively on the bottom layer, not on any lower level layer (except for a
203 couple of exceptions).
204         \item Each layer should provide a unified layer interface
205 (\textsc{rpp.h}, \textsc{drv.h}, \textsc {hal.h}, \textsc{sys.h} and
206 \textsc{os.h}), so top layers depends on that layer  interface and not on
207 individual elements from that layer.  \end{compactitem}
208
209 \begin{figure}[H]
210 \begin{center}
211 \noindent
212 \includegraphics[width=250px]{images/layers.pdf}
213 \caption{The RPP library layers.}
214 \label{fig-layers}
215 \end{center}
216 \end{figure}
217
218 As a consequence of this division the source code files and interface files are
219 placed in private directories like \textsc{drv/din.h}. With this organization
220 user applications only needs to include the top layer interface files (for
221 example \textsc{rpp/rpp\_can.h}) to be able to use the selected library API.
222
223 The rest of the section provides basic description of each layer.
224
225 \subsection{Operating System layer}
226 \label{sec-operating-system-layer}
227 This is an operating system interchangeable layer, containing the FreeRTOS
228 source files. The system can be easily replaced by another version thanks to
229 this layer. For example it is possible to compile the library for Linux (using
230 POSIX version of the FreeRTOS), which can be desirable for some testing. The
231 source files can be found in the \textsc{$\langle$rpp\_lib$\rangle$/os}
232 folder.
233
234 The following FreeRTOS versions are distributed:
235 \begin{description}
236         \item[6.0.4\_posix] POSIX version, usable for compilation of the library
237 for Linux system.
238         \item[7.0.2] Prefered version of the FreeRTOS, distributed by
239 Texas Instruments. This version has been tested and is used in the current
240 version of the library.
241         \item[7.4.0] Newest version distributed by the Texas Instruments.
242         \item[7.4.2] Newer version available from FreeRTOS pages. Slightly
243 modified to run on TMS570 MCU.
244 \end{description}
245
246 \subsection{System Layer} 
247 \label{sec-system-layer}
248 This layer contains system files with data types definitions, clock definitions,
249 interrupts mapping, MCU startup sequence, MCU selftests, and other low level
250 code for controlling some of the MCU peripherals. The source files can be found
251 in \textsc{$\langle$rpp\_lib$\rangle$/rpp/src/sys}, the header files can
252 be found in \textsc{$\langle$rpp\_lib$\rangle$/rpp/include/sys}
253 folder.
254
255 Large part of this layer was generated by the HalCoGen tool \ref{sec-halcogen}.
256
257 \subsection{HAL abstraction layer}
258 \label{sec-hal-abstraction-layer}
259 Hardware Abstraction Layer (HAL) creates an abstraction over the real hardware.
260 For example imagine an IO port with 8 pins. First four pins are connected to the
261 MCU directly to GPIO pins, another four pins are connected to an external
262 integrated circuit, communicating with the MCU via SPI. It would be annoying to
263 have to remember which group is which and to have two sets of control functions
264 for one peripheral. This layer maps every pin of the port to a control function
265 from the System Layer, groups the pins together, names them in a unified style
266 and provides common read, write and configure functions.
267
268 As a result, the higher layers do not have to know anything about the wiring of
269 the peripherals, they can just call read, write or configure function with a pin
270 name as a parameter and the HAL handles all the details.
271
272 The source files can be found in
273 \textsc{$\langle$rpp\_lib$\rangle$/rpp/src/hal} and the header files can
274 be found in \textsc{$\langle$rpp\_lib$\rangle$/rpp/include/hal} folder.
275
276 \subsection{Drivers layer} 
277 \label{sec-drivers-layer}
278 The Drivers layer contains code for controlling the RPP peripherals. The layer
279 benefits from the lower layers thus it is not too low level, but still there are
280 some peripherals like ADC or H-bridge, which needs some special procedure for
281 initialization and running, that would not be very intuitive for the user. For
282 example the H-bridge needs a watchdog reset task to be started before the bridge
283 is enabled.
284
285 The source files can be found in
286 \textsc{$\langle$rpp\_lib$\rangle$/rpp/src/drv} and the header files can
287 be found in \textsc{$\langle$rpp\_lib$\rangle$/rpp/include/drv} folder.
288
289 \subsection{RPP Layer}
290 \label{sec-rpp-layer} 
291 The RPP Layer is the highest layer of the control software. This layer provides
292 an easy to use set of functions for every peripheral and requires only basic
293 knowledge about them. For example, to control the H-bridge,
294 the user can  just call  \textsc{rpp\_hbr\_init()} function to enable the H-bridge
295 and the function calls a sequence of Drivers layer functions to start the
296 Watchdog and configure the peripheral.
297
298 The source files can be found in
299 \textsc{$\langle$rpp\_lib$\rangle$/rpp/src/rpp} and the header files can
300 be found in \textsc{$\langle$rpp\_lib$\rangle$/rpp/include/rpp}.
301
302 \section{Hardware description}
303 \label{sec-hardware-description}
304
305 This section provides reference documentation for the RPP board:
306
307 %%TODO: operating conditions as a reference to the Ti documentation
308
309 \begin{compactitem}
310         \item Layout description.
311         \item Connectors pinout.
312         \item Modules capabilities and features.
313 \end{compactitem}
314
315 \subsection{Layout description}
316 \label{sec-layout-description}
317 The RPP board has been designed with strict Automotive standards and safety in
318 mind. The components and pins are placed in sections and wires are routed in a
319 way to avoid any significant electromagnetic interference.
320
321 As can be seen on Figure \ref{board_photo}, the high power output logic is
322 placed in the top left corner, the low power output logic is placed on the
323 bottom left corner, while the communication logic is placed on the top right
324 corner.  In the middle there is the only one button available, the reset button
325 and below it is placed the TMS570 MCU itself. In the bottom right corner there
326 are components of analog inputs.
327
328 \begin{figure}[H]\begin{center}
329 \noindent
330 \includegraphics[width=300px]{images/board-photo.png}
331 \caption{The RPP board (signal connector missing).}
332 \label{board_photo}
333 \end{center}\end{figure}
334
335
336 \subsection{Connectors pinout}
337 \label{sec-connector-pinout}
338 The pinout of the board, described by the Figure \ref{pinout}, follows the
339 layout described in the previous section. The side connectors for communication
340 (24 pins), signals (56 pins) and power (24 pins) are automotive approved
341 humidity resistant connectors.
342
343 \begin{figure}[H]
344 \advance\leftskip-1cm
345 \noindent
346 \includegraphics[width=530px]{images/pinout.pdf}
347 \caption{The RPP connectors pinout.}
348 \label{pinout}
349 \end{figure}
350
351 \subsection{Modules description}
352 \label{sec-modules-description}
353 This section enumerates the capabilities of the hardware modules from Software
354 perspective. The block diagram of the modules can be seen in Figure
355 \ref{blocks}.
356
357 \begin{figure}[H]
358 \advance
359 \leftskip-1cm
360 \noindent
361 \includegraphics[width=500px]{images/blocks.pdf}
362 \caption{The RPP layer modules.}
363 \label{blocks}
364 \end{figure}
365
366 \subsubsection{Logic IO}
367 \label{sec-logic-io}
368
369 \paragraph{Digital Inputs (DIN)}
370 \label{par-digital-inputs}
371 \begin{compactitem}
372         \item 16 pins available on Signal Connector.
373         \item Pins 8-15 status can be read via GPIO using configurable
374 threshold.  \newline{} Pins 8-11 use variable threshold B and pins 12-15 use
375 variable threshold A.
376         \item Variable threshold is a DAC chip MCP4922.
377         \item All pins are read at once via SPI (fixed threshold) using chip
378 MC33972.
379         \item 0-7 are programmable pins and can be set to pull-up or
380 pull-down. 8-15 are pull-down only.
381         \item All pins can be set to be active or tri-stated.
382         \item All pins can be set to trigger interrupt.
383         \item On-line diagnostic of broken wire.
384 \end{compactitem}
385
386 \paragraph{Digital Outputs (LOUT)}
387 \label{par-digital-outputs}
388 \begin{compactitem}
389         \item 8 pins available on Signal Connector.
390         \item Pins for logic output only, up to 100mA.
391         \item All pins are set at once using a chip through SPI.
392 \end{compactitem}
393
394 \paragraph{Analog Input (ADC)}
395 \label{par-analog-input}
396 \begin{compactitem}
397         \item 12 channels available.
398         \item Differential inputs, thus 24 pins available on Signal Connector.
399         \item Range for 0-20 volts.
400         \item 12 bits resolution.
401         \item Using CPU ADC.
402 \end{compactitem}
403
404 \paragraph{Analog Output (DAC)}
405 \label{par-analog-output}
406 \begin{compactitem}
407         \item 4 pins available on Signal Connector.
408         \item Output range is 0-12 volts.
409         \item Using 2 x MCP4922 DACs controlled using SPI.
410         \item Resolution is 12 bits. But because of amplification and voltage
411 reference not all range is used.
412 \end{compactitem}
413
414 \subsubsection{Power Output}
415 \label{sec-power-output}
416 \paragraph{H-Bridge (HBR)}
417 \label{par-hbr}
418 \begin{compactitem}
419         \item 1 port (2 pins) available on Power Connector.
420         \item Communication is done through SPI.
421         \item H-Bridge can be enabled or disabled.
422         \item Current direction can be set.
423         \item PWM control with 1\% resolution change of the duty cycle.
424         \item Port can drive load up to 10A.
425 \end{compactitem}
426
427 \paragraph{Power Output (MOUT)}
428 \label{par-power-output}
429 \begin{compactitem}
430         \item 6 pins available on Power Connector.
431         \item Pins can drive a load up to 2A. Push/Pull.
432         \item Pins are set using 6 CPU output GPIOs. Diagnostic are read using 6
433 externally pulled-up open-drain input GPIOs.
434         \item On-line diagnostics. Driver chip will pull-down the corresponding
435 diagnostic pin on the CPU.  
436 \end{compactitem}
437
438 \paragraph{High-Power Output (HOUT)}
439 \label{par-high-power-output}
440 \begin{compactitem}
441         \item 6 pins available on Power Connector.
442         \item Pins can be set ON/OFF.
443         \item Pins can drive a load up to 10A with PWM.
444         \item System can read analog values of current flowing (IFBK).
445         \item System can read diagnostics values (DIAG). Detection of a fault
446 condition.  
447 \end{compactitem}
448
449 \subsubsection{Communication}
450 \label{sec-communication}
451 \paragraph{CAN bus (CAN)}
452 \label{par-can}
453 \begin{compactitem}
454         \item 3 ports available (CAN uses differential signaling) thus 6 pins
455 are available on Communication connector.
456         \item High speed.
457         \item Recover from error.
458         \item Detection of network errors.
459 \end{compactitem}
460
461 \paragraph{Local Interconnect Network (LIN)}
462 \label{par-lin}
463 \begin{compactitem}
464         \item 2 ports/pins available on Communication Connector.
465         \item Only first port can be used when using the SCI. Second port is
466 shared with SCI.  
467 \end{compactitem}
468
469 \paragraph{FlexRay (FR)}
470 \label{par-flexray}
471 \begin{compactitem}
472         \item 2 ports available. FlexRay uses differential signaling thus 4 pins
473 are available on Communication Connector.
474 \end{compactitem}
475
476 \paragraph{Serial Comm. Interface (SCI)}
477 \label{par-sci}
478 \begin{compactitem}
479         \item 1 port available inside the box on SCI connector (4 pins).
480         \item Variable baud rate. Tested on 9600 and 115200.
481         \item RS232 standard compatible.
482 \end{compactitem}
483
484 \paragraph{Ethernet (ETH)}
485 \label{par-eth}
486 \begin{compactitem}
487         \item 1 port available. Standard Ethernet connector available inside box.
488 \end{compactitem}
489
490 \subsubsection{Data storage/logging}
491 \label{sec-data-storage}
492 \paragraph{External Memory SD-RAM (SDR)}
493 \label{par-external-memory}
494 \begin{compactitem}
495         \item 64MB (currently installed) external RAM used for logging. Maximal
496 supported capacity is 256MB.
497         \item Memory test routine available with test
498 Software.
499 \end{compactitem}
500
501 \paragraph{SD Card (SDC)}
502 \label{par-sd-card}
503 \begin{compactitem}
504         \item Standard SD-Card connector or microSD connector available inside box.
505         \item Communication done using SPI.
506 \end{compactitem}
507
508 \section{Document structure}
509 \label{sec-document-structure}
510 The structure of this document is as follows:
511 Chapter~\ref{chap-getting-started} gets you started using the RPP.
512 Chapter~\ref{chap-c-support-library} describes the RPP library.
513 Chapter~\ref{chap-simulink-coder-target} covers the Simulink code
514 generation target and finally Chapter~\ref{chap-rpp-test-software}
515 documents a tool for interactive testing of RPP functionality.
516
517 \chapter{Getting started}
518 \label{chap-getting-started}
519
520 \section{Software requirements}
521 \label{sec-software-requirements}
522 The RPP software stack has been developed to be functional on Windows and
523 Linux platforms. The following subsections mention the recommended
524 versions of the required software tools/packages.
525
526 \subsection{Linux environment} 
527 \label{sec-linux-environment}
528 \begin{itemize}
529         \item Debian based 64b Linux distribution (Debian 7.0 or Ubuntu 14.4 for
530 example).
531         \item Kernel version 3.11.0-12.
532         \item GCC version 4.8.1
533         \item GtkTerm 0.99.7-rc1
534         \item TI Code Composer Studio 5.5.0.00077
535         \item Matlab 2013b 64b
536         \item HalCoGen 4.00 (optionally)
537         \item Uncrustify 0.59 (optionally, see Section \ref{sec-compilation})
538         \item Doxygen 1.8.4 (optionally, see Section \ref{sec-compiling-api-documentation})
539     \item Git 1.7.10.4 (optionally)
540 \end{itemize}
541
542 \subsection{Windows environment}
543 \label{sec-windows-environment}
544 \begin{itemize}
545         \item Windows 7 Enterprise 64b Service Pack 1.
546         \item Microsoft Windows SDK v7.1
547         \item Bray Terminal v1.9b
548         \item TI Code Composer Studio 5.5.0.00077
549         \item Matlab 2013b 64b
550         \item HalCoGen 4.00 (optionally)
551         \item Doxygen 1.8.4 (optionally, see Section \ref{sec-compiling-api-documentation}) 
552         \item Uncrustify 0.59 (optionally, see Section \ref{sec-compilation})
553     \item Git 1.9.4.msysgit.2 (optionally)
554 \end{itemize}
555
556 \section{Software and tools} 
557 \label{sec-software-and-tools}
558
559 \subsection{TI Code Composer Studio}
560 \label{sec-ti-ccs}
561 Code Composer Studio (CCS) is the official Integrated Development Environment
562 (IDE) for developing applications for Texas Instruments embedded processors. CCS
563 is multiplatform Software based on
564 Eclipse Open Source IDE.
565
566 CCS includes Texas Instruments Code Generation Tools (CGT)
567 \cite{armoptimizingccppcompiler2012, armassemblylanguagetools2012}
568 (compiler, linker, etc). Simulink code generation requires the CGT to be
569 available in the system, and thus, even if no library development
570 will be done or the IDE is not going to be used CCS is still required.
571
572 You can find documentation for CGT compiler in \cite{armoptimizingccppcompiler2012} and
573 for CGT archiver in \cite{armassemblylanguagetools2012}.
574
575 \subsubsection{Installation on Linux} 
576 \label{sec-installation-on-linux}
577 Download CCS for Linux from:
578
579         \begin{quotation}
580 \url{http://processors.wiki.ti.com/index.php/Category:Code\_Composer\_Studio\_v5}
581         \end{quotation}
582
583 Once downloaded, add executable permission to the installation file and launch
584 the installation by executing it. Installation must be done as root in order to
585 install a driver set.
586
587 \lstset{language=bash}
588 \begin{lstlisting}
589 chmod +x ccs_setup_5.5.0.00077.bin
590 sudo ./ccs_setup_5.5.0.00077.bin
591 \end{lstlisting}
592
593 After installation the application can be executed with:
594
595 \lstset{language=bash}
596 \begin{lstlisting}
597 cd <ccs>/ccsv5/eclipse/
598 ./ccstudio
599 \end{lstlisting}
600
601 The first launch on 64bits systems might fail. This can happen because CCS5 is
602 32b application and thus requires 32bits libraries:
603
604 \lstset{language=bash}
605 \begin{lstlisting}
606 sudo apt-get install libgtk2.0-0:i386 libxtst6:i386
607 \end{lstlisting}
608
609 If the application crashes with a segmentation fault edit file:
610
611 \lstset{language=bash}
612 \begin{lstlisting}
613 nano
614 <ccs>/ccsv5/eclipse/plugins/com.ti.ccstudio.branding_<version>/plugin_customization.ini
615 \end{lstlisting}
616
617 And change key \textsc{org.eclipse.ui/showIntro} to false.
618
619 \subsubsection{Installation on Windows}
620 \label{sec-installation-on-windows}
621 The installation for Windows is more straightforward than the previous procedure
622 for Linux.
623
624 Download CCS for Windows from:
625
626         \begin{quotation}
627 \url{http://processors.wiki.ti.com/index.php/Category:Code\_Composer\_Studio\_v5}
628         \end{quotation}
629
630 Once downloaded run the ccs\_setup\_5.5.0.00077.exe and install the CCS.
631
632 \subsubsection{First launch} 
633 \label{sec-first-launch}
634 If no other licence is available, choose ``FREE License -- for use with XDS100
635 JTAG Emulators'' from the licensing options. Code download for the board is using
636 that particular hardware.
637
638 \subsection{Matlab/Simulink}
639 \label{sec-matlab-simulink}
640 Matlab Simulink is a set of tools, runtime environment and development
641 environment for Model--Based \cite{modelbasedwiki2013} applications development,
642 simulations and generation code for target platforms.  Supported Matlab Simulink
643 version is R2013b for 64 bits Linux and Windows.
644
645 \subsection{HalCoGen}
646 \label{sec-halcogen}
647 HalCoGen (HAL Code Generator) is a tool for graphical configuration of peripherals, clocks, interrupts and other MCU parameters. It generates C code which can be imported to the Code Composer Studio.
648
649 The tool is available for Windows at 
650         \begin{quotation}
651 \url{http://www.ti.com/tool/halcogen?keyMatch=halcogen&tisearch=Search-EN}
652         \end{quotation}
653
654 The HalCoGen has been used in early development stage to generate the base code for some of the peripheral. The trend is to not to use the HalCoGen any more, because the generated code is not reliable enough for safety application. Anyway it is sometimes helpful to use it as a reference.
655
656 The HalCoGen is distributed for Windows only, but can be run on Linux with Wine 1.6.2.
657
658 \subsection{GtkTerm and Bray Terminal}
659 \label{sec-gtkterm-bray-terminal}
660 Most of the interaction with the board is done through a RS-232 serial
661 connection. The terminal Software used for communication is called GtkTerm for
662 Linux and Bray terminal for Windows.
663
664 To install GtkTerm execute:
665
666 \lstset{language=bash}
667 \begin{lstlisting}
668 sudo apt-get install gtkterm
669 \end{lstlisting}
670
671 The Bray Terminal does not require any installation and the executable file is
672 available at 
673
674 \begin{quotation}
675 \url{https://sites.google.com/site/terminalbpp/}
676 \end{quotation}
677
678 \subsection{C Compiler}
679 \label{sec-c-compiler}
680 A C language compiler has to be available on the development system to be able to
681 compile Matlab Simulink blocks S-functions.
682
683 For Linux a GCC 4.8.1 compiler is recommended and can be installed with a
684 command
685
686 \lstset{language=bash}
687 \begin{lstlisting}
688 sudo apt-get install gcc
689 \end{lstlisting}
690
691 For Windows, the C/C++ compiler is a part of Windows SDK, which installation
692 file is available at 
693
694 \begin{quotation}
695 \url{http://www.microsoft.com/en-us/download/details.aspx?id=8279}
696 \end{quotation}
697
698 \section{Project Installation}
699 \label{sec-project-installation}
700 The RPP project is distributed in three packages and a standalone pdf file,
701 containing this documentation. Every package is named like
702 \textsc{package\_name-version.zip}. The three packages are: 
703
704 \begin{description}
705         \item[rpp-lib] Contains the source codes of the RPP Library,
706 described in Chapter \ref{chap-c-support-library}. If you want to make any
707 changes in the drivers or RPP API, this library has to be compiled and linked
708 with the other two applications in the other two packages. The compile procedure
709 can be found in Section \ref{sec-compilation}.  
710         \item[rpp-simulink] Contains source codes of the Matlab Simulink blocks, demo
711 models and scripts for downloading the resulting firmware to the target from the
712 Matlab Simulink. Details can be found in Chapter \ref{chap-simulink-coder-target}.
713
714 The package also contains the binary file of the RPP Library and all headers and
715 other files necessary for building and downloading the models.
716         \item[rpp-test-sw]  Contains an application for rapid testing and direct
717 controlling the RPP board over the Serial Interface.
718
719 The package also contains the binary file of the RPP Library and all headers and
720 other files necessary for building and downloading the application.
721 \end{description}
722
723 \subsection{rpp-lib}
724 \label{sec-rpp-lib-installation}
725 You may not need to deal with this package at all because the compiled library is
726 distributed with the applications. But in case of contributions or further
727 development done by your team, this subsection describes how to open the project
728 in development environment and how to use the resulting static library in an
729 application.
730
731 \begin{enumerate}
732         \item Unzip the \textsc{rpp-lib-version.zip} file.
733         \item Open the Code Composer Studio (see Section \ref{sec-ti-ccs}).
734         \item Follow the procedure for openning the projects in CCS in Section
735 \ref{sec-openning-of-existing-project} and open the rpp-lib project.  \item
736 Compile the static library using a procedure in Section \ref{sec-compilation}.
737 The binary file will appear in the project root directory.
738         \item Copy the binary file to the application, where you want to test
739 and use the new library version.  
740         \begin{itemize}
741                 \item In the rpp-simulink application the library binary file is
742 present in \textsc{rpp/lib} folder. 
743                 \item In the rpp-test-sw application the library binary file is
744 present in \textsc{rpp-lib} folder.  
745         \end{itemize}
746 \end{enumerate}
747
748 \subsection{rpp-simulink}
749 \label{sec-rpp-simulink-installation}
750 If you want to access the demo models or build your own models using the RPP blocks, if
751 you want to generate a C code from the models, build it to a binary firmware for the RPP board and download it to the real hardware, follow these steps.
752
753 \begin{enumerate}
754         \item Unzip the \textsc{rpp-simulink-version.zip} file.
755         \item Follow the procedure in Section
756 \ref{sec-configuration-simulink-for-rpp} for configuring the Matlab Simulink for
757 the RPP project.  
758         \item Follow the procedure in Section \ref{sec-crating-new-model} for
759 instruction about creating your own model which will be using the RPP Simulink
760 blocks or follow the instructions in Section \ref{sec-running-model-on-hw}
761 for downloading the firmware to the real RPP hardware.
762 \end{enumerate}
763
764 \subsection{rpp-test-sw}
765 \label{sec-test-sw-installation}
766 If you want a direct control over the hardware for example to test your
767 modifications in the RPP Library follow this procedure for the rpp-test-sw
768 application installation.
769
770 \begin{enumerate}
771         \item Unzip the \textsc{rpp-test-sw-version.zip} file.
772         \item Open the Code Composer Studio (see Section \ref{sec-ti-ccs}).
773         \item Follow the procedure for openning the projects in CCS in Section
774 \ref{sec-openning-of-existing-project} and open both, the \textsc{rpp-lib} and
775 the \textsc{rpp-test-sw} projects.  
776         \item Right click on the \textsc{rpp-test-sw} project in the
777 \textsc{Project Explorer} and select \textsc{Build Project}. Ignore any errors
778 in the \textsc{rpp-lib} project.  
779         \item Follow the instructions in Section
780 \ref{sec-running-software-on-hw} to download, debug and run the software on the
781 target hardware. CCS will ask you wether to proceed with the detected errors in
782 \textsc{rpp-lib} project. Do not mind them and click to the \textsc{Proceed} button
783 to continue.
784 \end{enumerate}
785
786 \section{Code Composer Studio usage}
787 \label{sec-code-composerpstudio-usage}
788
789 \subsection{Opening of existing project}
790 \label{sec-openning-of-existing-project}
791 The project opening procedure is similar to standard Eclipse project opening.
792
793 \begin{enumerate}
794         \item Launch Code Composer Studio
795         \item Select \textsc{File$\rightarrow$Import}
796         \item In the dialog window select \textsc{Code Composer
797 Studio$\rightarrow$Existing CCS Eclipse project} as an import source as depicted
798 in Figure \ref{fig-import-project}.  
799         \item In the next dialog window click on
800 \textsc{Browse} button and find the root directory of the project.
801         \item Select the requested project in the \textsc{Discovered project}
802 section so that the result looks like in Figure \ref{fig-select-project}.  
803         \item Click on \textsc{Finish} button.
804 \end{enumerate}
805
806 \begin{figure}[H]\begin{center}
807         \includegraphics[width=350px]{images/import_project.png}
808         \caption{Import project dialog}
809         \label{fig-import-project}
810 \end{center}\end{figure}
811
812 \begin{figure}[H]\begin{center}
813         \includegraphics[width=350px]{images/select_project.png}
814         \caption{Select project dialog}
815         \label{fig-select-project}
816 \end{center}\end{figure}
817
818 \subsection{Creating new project}
819 \label{sec-creating-new-project}
820 In \textsc{\repo/rpp/lib/apps/} there are two RPP based
821 applications, \textsc{helloworld} and \textsc{helloworld\_posix}, that are
822 already configured for the RPP Library. It is advised that new applications use
823 this project as a foundation.
824
825 To create a new application copy this directory and rename it. Now open files
826 \textsc{.project}, \textsc{.cproject} and \textsc{.ccsproject} (if available)
827 and change any occurrence of the work \textsc{helloworld}
828 with the name of your project. Use lower case ASCII letters and underscores only.
829
830 \textbf{Steps to configure a new CCS (ARM, using CGT) RPP application:}
831
832 \begin{compactenum}
833         \item Create a new CCS project. \newline{}
834 \noindent\includegraphics[width=400px]{images/base_1.png}
835         \item Create a normal folder \textsc{include}.
836         \item Create a source folder \textsc{src}.
837         \item Add common \textsc{.gitignore} to the root of that project:
838 \lstset{language=}
839 \begin{lstlisting}
840 Debug
841 Release
842 .settings/*
843 \end{lstlisting}
844 \newpage
845         \item Add new variable \textsc{RPP\_LIB\_ROOT} and point to this
846 repository branch root.\newline{}
847 \noindent\includegraphics[width=400px]{images/base_2.png}
848         \item Add \textsc{rpp-lib.lib} static library to linker libraries and
849 add \textsc{RPP\_LIB\_ROOT} to the library search path.\newline{}
850 \noindent\includegraphics[width=400px]{images/base_3.png}
851 \newpage
852         \item Configure linker to retain \textsc{.intvecs} from RPP static
853 library.\newline{} \noindent\includegraphics[width=350px]{images/base_4.png}
854         \item Configure compiler to include local includes, OS includes for
855 TMS570 and RPP includes, in that order\todo{Add lwip include paths as
856 well}.\newline{}
857 \noindent\includegraphics[width=350px]{images/base_5.png}
858 \newpage
859         \item Configure compiler to allow GCC extensions.\newline{}
860 \noindent\includegraphics[width=400px]{images/base_6.png}
861         \item Import and link (\underline{do not copy!}) linker file and board
862 upload descriptor.\newline{}
863 \noindent\includegraphics[width=200px]{images/base_7.png}
864 \end{compactenum}
865
866 \textbf{Steps to configure a new GCC (x86(\_64)) RPP simulated application:}
867
868 \begin{compactenum}
869         \item Create a new managed C project that uses Linux GCC toolchain.
870         \item Create a source folder \textsc{src}. Link all files from original
871 CCS application to this folder.
872         \item Create a normal folder \textsc{include}. Create a folder
873 \textsc{rpp} inside of it.  
874         \item Add common \textsc{.gitignore} to the root of that project:
875 \lstset{language=}
876 \begin{lstlisting}
877 Debug
878 Release
879 .settings/*
880 \end{lstlisting}
881 \newpage
882         \item Add new variable \textsc{RPP\_LIB\_ROOT} and point to this
883 repository branch root.\newline{}
884 \noindent\includegraphics[width=400px]{images/base_posix_1.png}
885         \item Configure compiler to include local includes, CCS application
886 includes, OS includes for POSIX and RPP includes, in that order.\newline{}
887 \noindent\includegraphics[width=400px]{images/base_posix_2.png}
888 \newpage
889         \item Add \textsc{rpp} and \textsc{pthread}to linker libraries and add
890 \textsc{RPP\_LIB\_ROOT} to the library search path.\newline{}
891 \noindent\includegraphics[width=400px]{images/base_posix_3.png}
892 \end{compactenum}
893
894 \textbf{In general any RPP application uses the layout/template:}
895
896 \begin{enumerate}
897         \item Include RPP library header file. You may also include only a
898 selected modules to save space.  \lstset{language=c++}
899 \begin{lstlisting}
900 #include "rpp/rpp.h"
901 \end{lstlisting}
902
903 You may not want to include the whole library to save space and compile time. In
904 this case you may include only those modules, that you want to use. Inclusion
905 selected modules only requires two more
906 header files to be included as well: base.h and, in case sci is used for printing, rpp/sci.h.
907 \begin{lstlisting}
908 #include "rpp/hbr.h" /* We want to use H-bridge */
909 #include <base.h>       /* This is a necessary base header file of the rpp library. */
910 #include "rpp/sci.h" /* This is needed, because we are using rpp_sci_printf in following examples. */
911 \end{lstlisting}
912
913 \newpage
914 \item Create one or as many FreeRTOS task function definitions as required. Those tasks should use
915   functions from this library.
916 \lstset{language=c++}
917 \begin{lstlisting}
918 void my_task(void* p)
919 {
920     static const portTickType freq_ticks = 1000 / portTICK_RATE_MS;
921     portTickType last_wake_time = xTaskGetTickCount();
922     while (TRUE) {
923         /* Wait until next step */
924         vTaskDelayUntil(&last_wake_time, freq_ticks);
925         rpp_sci_printf((const char*)"Hello RPP.\r\n");
926     }
927 }
928 \end{lstlisting}
929
930 \item Create the main function that will:
931  \begin{itemize}
932         \item Initialize the RPP board. If you have included only selected
933 modules in step 1, initialize only those modules by calling their init
934 functions, for
935 example rpp\_hbr\_init\(\).
936         \item Spawn the tasks the application requires. Refer to FreeRTOS API
937 for details.
938         \item Start the FreeRTOS Scheduler. Refer to FreeRTOS API for details.
939         \item Catch if idle task could not be created.
940
941 \lstset{language=c++}
942 \begin{lstlisting}
943 void main(void)
944 {
945     /* In case whole library is included: */
946         /* Initialize RPP board */
947         rpp_init();
948     /* In case only selected modules are included: */
949         /* Initialize HBR */
950             rpp_hbr_init();
951         /* Initialize sci for printf */
952         rpp_sci_init();
953         /* Enable interrups */
954         _enable_IRQ();
955
956     /* Spawn tasks */
957     if (xTaskCreate(my_task, (const signed char*)"my_task",
958             512, NULL, 0, NULL) != pdPASS) {
959         #ifdef DEBUG
960         rpp_sci_printf((const char*)
961             "ERROR: Cannot spawn control task.\r\n"
962         );
963         #endif
964         while (TRUE) { asm(" nop"); }
965     }
966
967     /* Start the FreeRTOS Scheduler */
968     vTaskStartScheduler();
969
970     /* Catch scheduler start error */
971     #ifdef DEBUG
972     rpp_sci_printf((const char*)
973             "ERROR: Problem allocating memory for idle task.\r\n"
974         );
975     #endif
976     while (TRUE) { asm(" nop"); }
977 }
978 \end{lstlisting}
979
980  \end{itemize}
981 \item Create hook functions for FreeRTOS:
982  \begin{itemize}
983  \item \textsc{vApplicationMallocFailedHook()} allows to catch memory allocation
984 errors.
985  \item \textsc{vApplicationStackOverflowHook()} allows to catch if a task
986 overflows it's stack.
987
988 \lstset{language=c++}
989 \begin{lstlisting}
990 #if configUSE_MALLOC_FAILED_HOOK == 1
991 /**
992  * FreeRTOS malloc() failed hook.
993  */
994 void vApplicationMallocFailedHook(void) {
995     #ifdef DEBUG
996     rpp_sci_printf((const char*)
997             "ERROR: manual memory allocation failed.\r\n"
998         );
999     #endif
1000 }
1001 #endif
1002
1003
1004 #if configCHECK_FOR_STACK_OVERFLOW > 0
1005 /**
1006  * FreeRTOS stack overflow hook.
1007  */
1008 void vApplicationStackOverflowHook(xTaskHandle xTask,
1009                                    signed portCHAR *pcTaskName) {
1010     #ifdef DEBUG
1011     rpp_sci_printf((const char*)
1012             "ERROR: Stack overflow : \"%s\".\r\n", pcTaskName
1013         );
1014     #endif
1015 }
1016 #endif
1017 \end{lstlisting}
1018
1019 \newpage
1020  \end{itemize}
1021 \end{enumerate}
1022
1023
1024 \subsection{Running the software on the HW}
1025 \label{sec-running-software-on-hw}
1026 \subsubsection{Code Composer Studio Project}
1027 \label{sec-ccs-run-project}
1028 When the application is distributed as a CCS project, you have to open the
1029 project in the CCS as described in the Section
1030 \ref{sec-openning-of-existing-project}. Once the project is opened and built, it
1031 can be easily downloaded to the target hardware with the following procedure:
1032
1033 \begin{enumerate}
1034         \item Connect the Texas Instruments XDS100v2 USB emulator to the JTAG
1035 port (see Figure \ref{pinout}, port 1).  
1036         \item Connect a USB cable to the XDS100v2 USB emulator and the
1037 development computer.
1038         \item Plug in the power supply.  
1039         \item In the Code Composer Studio click on the
1040 \textsc{Run$\rightarrow$Debug}. The project will  be optionally built and
1041 the download process will start. The Code Composer Studio will switch into the debug
1042 mode, when the download is finished.
1043         \item Run the program by clicking on the \textsc{Run} button, with the
1044 green arrow.  
1045 \end{enumerate}
1046
1047 \subsubsection{Binary File}
1048 \label{sec-binary-file}
1049 If the application is distributed as a binary file, without source codes and CCS
1050 project files, you can download and run just the binary file by creating a new
1051 empty CCS project and configuring the debug session according to the following
1052 procedure:
1053
1054 \begin{enumerate}
1055         \item In Code Composer Studio click on
1056 \textsc{File$\rightarrow$New$\rightarrow$CCS Project}.  
1057         \item In the dialog window, type in a project name, for example
1058 myBinaryLoad, Select \textsc{Device
1059 variant} (ARM, Cortex R, TMS570LS3137, Texas Instruments XDS100v2 USB Emulator)
1060 and select project template to \textsc{Empty Project}. The filled dialog should
1061 look like on the Figure \ref{fig-new-empty-project}
1062         \item Click on the \textsc{Finish} button and new empty project will be
1063 created.  
1064         \item In the \textsc{Project Explorer} click on the project with a right
1065 mouse button and in the context menu select \textsc{Debug
1066 as$\rightarrow$Debug configurations}.
1067         \item Click on a button \textsc{New launch configuration}
1068         \item Rename the New\_configuration, for example to myConfiguration.
1069         \item Select configuration target file by clicking the \textsc{File
1070 System} button, finding and selecting the TMS5703137.ccxml file. The result
1071 should look like on the Figure \ref{fig-debug-conf-main-diag}.  
1072         \item On the \textsc{program} pane select the binary file you want to
1073 download to the board.
1074 Click on the \textsc{File System} button, find and select the binary file.
1075 Rpp-test-sw.out for example. The result should look like on the Figure
1076 \ref{fig-debug-conf-program-diag}.
1077         \item You may also tune the target configuration like in the Section
1078 \ref{sec-target-configuration}. 
1079         \item Finish the configuration by clicking on the \textsc{Apply} button
1080 and download the code by clicking on the \textsc{Debug} button. You can later
1081 invoke the download also from the \textsc{Run$\rightarrow$Debug} CCS menu. You
1082 may not need to create more Debug configurations and CCS empty projects as you
1083 can easily change the binary file in the Debug configuration to load different
1084 binary file.  
1085 \end{enumerate}
1086
1087 \begin{figure}[H]\begin{center}
1088         \includegraphics[width=350px]{images/new_empty_project.png}
1089         \caption{New empty project dialog}
1090         \label{fig-new-empty-project}
1091 \end{center}\end{figure}
1092
1093 \begin{figure}[H]\begin{center}
1094         \includegraphics[width=350px]{images/debug_configuration_main.png}
1095         \caption{Debug Configuration Main dialog}
1096         \label{fig-debug-conf-main-diag}
1097 \end{center}\end{figure}
1098
1099 \subsection{Target configuration}
1100 \label{sec-target-configuration}
1101 Default target configuration erases the whole Flash memory, before downloading
1102 the code. This is however not needed in most cases. You may disable this feature
1103 by the following procedure: 
1104 \begin{enumerate}
1105         \item Right click on the project name in the \textsc{Project Browser}
1106         \item Select \textsc{Debug as$\rightarrow$Debug Configurations}
1107         \item In the dialog window select \textsc{Target} pane.
1108         \item In the \textsc{Flash Settings}, \textsc{Erase Options} select
1109 \textsc{Necessary sectors only}.
1110         \item Save the configuration by clicking on the \textsc{Apply} button
1111 and close the dialog.
1112 \end{enumerate}
1113
1114 \begin{figure}[H]\begin{center}
1115         \includegraphics[width=350px]{images/debug_configuration_program.png}
1116         \caption{Configuration Program dialog}
1117         \label{fig-debug-conf-program-diag}
1118 \end{center}\end{figure}
1119
1120 \section{Matlab Simulink usage}
1121 \label{sec-matlab-simulink-usage}
1122
1123 \subsection{Configuring Simulink for RPP}
1124 \label{sec-configuration-simulink-for-rpp}
1125 Before any work or experiments with the RPP blocks and models can be done, the RPP target has to be configured to be able to find the ARM compiler, C compiler and some necessary files. Also the S-Functions of the blocks have to be compiled by the mex tool.
1126 \begin{enumerate}
1127 \item Download and install CCS for Linux:
1128
1129 Details on how to setup CCS are available in Section \ref{sec-ti-ccs}.
1130
1131 \item On Windows you have to tell the \textsc{mex} which C compiler it should be using. Open the command line, run the \textsc{mex} tool from the Matlab installation folder and select the C compiler.
1132
1133 \begin{lstlisting}[language=bash]
1134 C:\Program Files\MATLAB\R2013b\bin>mex -setup
1135
1136 Welcome to mex -setup.  This utility will help you set up
1137 a default compiler.  For a list of supported compilers, see
1138 http://www.mathworks.com/support/compilers/R2013b/win64.html
1139
1140 Please choose your compiler for building MEX-files:
1141
1142 Would you like mex to locate installed compilers [y]/n? y
1143
1144 Select a compiler:
1145 [1] Microsoft Software Development Kit (SDK) 7.1 in c:\Program Files (x86)\Microsoft Visual Studio 10.0
1146
1147 [0] None
1148
1149 Compiler: 1
1150
1151 Please verify your choices:
1152
1153 Compiler: Microsoft Software Development Kit (SDK) 7.1
1154 Location: c:\Program Files (x86)\Microsoft Visual Studio 10.0
1155
1156 Are these correct [y]/n? y
1157
1158 ***************************************************************************
1159   Warning: MEX-files generated using Microsoft Windows Software Development
1160            Kit (SDK) require that Microsoft Visual Studio 2010 run-time
1161            libraries be available on the computer they are run on.
1162            If you plan to redistribute your MEX-files to other MATLAB
1163            users, be sure that they have the run-time libraries.
1164 ***************************************************************************
1165
1166
1167 Trying to update options file: C:\Users\Michal\AppData\Roaming\MathWorks\MATLAB\R2013b\mexopts.bat
1168 From template:              C:\PROGRA~1\MATLAB\R2013b\bin\win64\mexopts\mssdk71opts.bat
1169
1170 Done . . .
1171
1172 **************************************************************************
1173   Warning: The MATLAB C and Fortran API has changed to support MATLAB
1174            variables with more than 2^32-1 elements.  In the near future
1175            you will be required to update your code to utilize the new
1176            API. You can find more information about this at:
1177            http://www.mathworks.com/help/matlab/matlab_external/upgrading-mex-files-to-use-64-bit-api.html
1178            Building with the -largeArrayDims option enables the new API.
1179 **************************************************************************
1180
1181 C:\Program Files\MATLAB\R2013b\bin>
1182 \end{lstlisting}
1183
1184 \item Install RPP Target:
1185
1186 Open Matlab and type on command window:
1187
1188 \lstset{language=Matlab}
1189 \begin{lstlisting}
1190 cd <rpp-simulink>/rpp/rpp/
1191 rpp_setup
1192 \end{lstlisting}
1193
1194 This will launch the RPP setup script. This script will ask the user to provide
1195 the path to the CCS compiler root directory (the directory where \textsc{armcl}
1196 binary is located), normally:
1197
1198 \begin{verbatim}
1199 <ccs>/tools/compiler/arm_5.X.X/
1200 \end{verbatim}
1201
1202 This script will, among other things, ask the user to provide the location of
1203 the armcl parent directory, infer and save some relevant CCS paths, add paths to
1204 Matlab path and build S-Function
1205 blocks for user's architecture (using Matlab's mex command line tool).
1206
1207 \item Create new model or load a demo:
1208
1209 Demos are located on \textsc{\repo/rpp/demo} or you can start a new model and
1210 configure target to RPP.  For new models see Section \ref{sec-crating-new-model} below.
1211 \end{enumerate}
1212
1213
1214 \subsection{Working with demo models}
1215 \label{sec-openning-demo-models}
1216 The demo models are available from the directory \textsc{\repo/rpp/demos}. To
1217 access the demo models for reference or for downloading to the RPP board you
1218 have to change the directory to the one, containing the desired demo. For
1219 example to open the cantransmit demo you have to type these commands into the
1220 Matlab command line:
1221
1222 \begin{lstlisting}[language=Matlab]
1223 cd <rpp-simulink>/rpp/demos
1224 open cantransmit.slx
1225 \end{lstlisting}
1226
1227 The same procedure can be used to open any other models. To run the model on
1228 the target hardware see Section \ref{sec-running-model-on-hw}.
1229
1230 \subsection{Creating a new model}
1231 \label{sec-crating-new-model}
1232 \begin{enumerate}
1233         \item Create a model by clicking \textsc{New$\rightarrow$Simulink Model}.
1234         \item Open a configuration dialog by clicking \textsc{Simulation$\rightarrow$Model Configuration Parameters}.
1235         \item The new Simulink model needs to be configured in the following way:
1236         \begin{compactitem}
1237         \item Solver (Figure \ref{fig-solver}):
1238          \begin{compactitem}
1239          \item Options: \emph{Fixed-step, discrete}
1240          \item Tasking mode set to \textit{SingleTasking}.
1241            \begin{figure}
1242                  \centering
1243                  \includegraphics[width=400px]{images/simulink_solver.png}
1244                  \caption{Solver settings}
1245                  \label{fig-solver}
1246         \end{figure}
1247          \end{compactitem}
1248         \item Diagnostics $\rightarrow$ Sample Time (Figure~\ref{fig-sample-time-settings}):
1249          \begin{compactitem}
1250          \item Disable warning source block specifies -1 sampling time. It's ok for the
1251 source blocks to run once per tick.
1252            \begin{figure}
1253                  \centering
1254                  \includegraphics[width=400px]{images/simulink_diagnostics.png}
1255                  \caption{Sample Time settings}
1256                  \label{fig-sample-time-settings}
1257         \end{figure}
1258         \end{compactitem}
1259         \item Code generation (Figure~\ref{fig-code-gen-settings}):
1260          \begin{compactitem}
1261          \item Set to \textsc{rpp.tlc}.
1262            \begin{figure}
1263                  \centering
1264                  \includegraphics[width=400px]{images/simulink_code.png}
1265                  \caption{Code Generation settings}
1266                  \label{fig-code-gen-settings}
1267         \end{figure}
1268         \end{compactitem}
1269 \end{compactitem}
1270         \item From Matlab command window change the current directory to where
1271 you want your generated code to appear, e.g.:
1272 \begin{lstlisting}[language=Matlab]
1273 cd /tmp/my-code
1274 \end{lstlisting}
1275   The code will be generated in a subdirectory of that directory. The name of
1276 the subdirectory will be \textsc{<model>\_rpp}, where \textsc{model} is the name
1277 of the Simulink model.
1278         \item Generate the code by choosing \textsc{Code $\rightarrow$ C/C++
1279 Code  $\rightarrow$ Build Model}.
1280 \end{enumerate}
1281
1282 If you want to run the model on the RPP board, see Section
1283 \ref{sec-running-model-on-hw}.
1284
1285 \subsection{Running model on the RPP board}
1286 \label{sec-running-model-on-hw}
1287 To run the model on the target RPP hardware you have to enable the download
1288 feature and build the model by following this procedure: \begin{enumerate}
1289         \item Open the model you want to run (See Section
1290 \ref{sec-openning-demo-models}.)
1291         \item Click on \textsc{Simulation$\rightarrow$Model Configuration
1292 Parameters}.
1293         \item In the \textsc{Code Generation$\rightarrow$RPP Options} pane
1294 check \textsc{Download compiled binary to RPP} checkbox.
1295         \item Click on \textsc{OK} button, connect the target HW to the computer
1296 like in the Section \ref{sec-ccs-run-project} and build the model by \textsc{Code $\rightarrow$ C/C++
1297 Code  $\rightarrow$ Build Model}. If the build
1298 ends with a success, the download process will start and once the downloading is
1299 finished, the application will run immediatelly.
1300 \end{enumerate}
1301
1302 The code downloading is supported for Windows and Linux development systems. If
1303 you are using Linux, you may also try to use the OpenOCD by checking Use OpenOCD
1304 to download the compiled binary checkbox in addition. For more information about
1305 the OpenOCD configuration refer 
1306
1307 \begin{verbatim}
1308 http://rtime.felk.cvut.cz/hw/index.php/TMS570LS3137#OpenOCD_setup_and_Flashing
1309 \end{verbatim}
1310
1311 Note: You should end the Code Composer Studio debug session before
1312 downloading the generated code to the RPP board. Otherwise the
1313 download will fail.
1314  
1315 \section{Configuring serial interface}
1316 \label{sec-configuration-serial-interface}
1317 The main interface for communicating with the RPP board is the serial interface.
1318 The application may define its own interface settings, but the following
1319 settings is the default one:
1320
1321 \begin{itemize}
1322         \item Baudrate: 115200
1323         \item Parity: none
1324         \item Bits: 8
1325         \item Stopbits: 1
1326         \item Flow control: none
1327 \end{itemize}
1328
1329 Use GtkTerm in Linux or Bray Terminal for accessing the serial interface. See
1330 Section \ref{sec-hardware-description} for reference about the position of the
1331 serial interface connector on the RPP board.
1332
1333 \section{Bug reporting}
1334 \label{sec-bug-reporting}
1335
1336 % TODO: implement
1337
1338 \chapter{C Support Library}
1339 \label{chap-c-support-library}
1340
1341 This chapter describes the implementation of the C support library
1342 (RPP Library), which is used both for Simulink code generation target
1343 and command line testing tool.
1344
1345 \section{Description}
1346 \label{sec-description}
1347 The RPP C Support Library (also called RPP library) defines the API for
1348 working with the board. It includes drivers and an operating system.
1349 The library is
1350 designed from the board user perspective and exposes a simplified high-level API
1351 to handle the board's peripheral modules in a safe manner. The library is
1352 compiled as a static library named \texttt{rpp-lib.lib} and can be found in
1353 \textsc{\repo/rpp/lib}.
1354
1355 The RPP library can be used in any project, where the RPP hardware support is
1356 required and it is also used in two applications -- the Command line testing
1357 tool, described in Chapter \ref{chap-rpp-test-software}, and Simulink Coder
1358 target, described in Chapter \ref{chap-simulink-coder-target}.
1359
1360 For details about the library architecture, refer Section \ref{sec-software-architecture}.
1361
1362 \section{API development guidelines}
1363 \label{sec-api-development-guidlines}
1364
1365 The following are the development guidelines used for developing the RPP API:
1366
1367 \begin{compactitem}
1368         \item User documentation should be placed in header files, not in source
1369 code, and should be Doxygen formatted using autobrief. Documentation for each
1370 function present is mandatory.
1371         \item Function declarations in the headers files is for public functions
1372 only. Do not declare local/static/private functions in the header.
1373         \item Documentation in source code files should be non-doxygen formatted
1374 and intended for developers, not users. Documentation here is optional and at
1375 the discretion of the developer.
1376         \item Always use standard data types for IO when possible. Use custom
1377 structs as very last resort.  \item Use prefix based functions names to avoid
1378 clash. The prefix is of the form \textsc{$\langle$layer$\rangle$\_$\langle$module$\rangle$\_}, for example
1379 \textsc{rpp\_din\_update()} for the update function of the DIN module in the RPP
1380 Layer.  
1381         \item Be very careful about symbol export. Because it is used as a
1382 static library the modules should not export any symbol that is not intended to
1383 be used (function) or \textsc{extern}'ed (variable) from application. As a rule
1384 of thumb declare all global variables as static. 
1385         \item Only the RPP Layer symbols are available to user applications. All
1386 information related to lower layers is hidden for the application. This is
1387 accomplished by the inclusion of the rpp.h or rpp\_\{mnemonic\}.h file on the
1388 implementations files only and never on the interface files. Never expose any
1389 other layer to the application or to the whole system below the RPP layer. In
1390 other words, never \textsc{\#include "foo/foo.h"} in any RPP Layer interface
1391 file. 
1392 \end{compactitem}
1393
1394 \section{Coding style}
1395 \label{sec-coding-style}
1396 In order to keep the code as clean as possible, a unified coding style
1397 should be followed by any contributor to the code. The used coding
1398 style is based on the default configuration of Code Composer Studio
1399 editor. Most notable rule is that the Tab character is 4 spaces.
1400
1401 The RPP library project is prepared for a usage of a program named
1402 Uncrustify. The Uncrustify program checks the code and fixes those
1403 lines that does not match the coding style. However, keep in mind that
1404 the program is not perfect and sometimes some lines can be modified
1405 even when the suggested coding style has been followed. This does not
1406 causes problems as long as the contributor follows the committing
1407 procedure described in next paragraph.
1408
1409 When contributing to the code, the contributor should learn the current coding
1410 style from the existing code. When a new feature is implemented, before
1411 committing to the repository, a command: 
1412
1413 \lstset{language=bash}
1414 \begin{lstlisting}
1415 make uncrustify
1416 \end{lstlisting}
1417 in a Linux terminal should be called. This command fixes any coding style
1418 errors. After that all changes can be committed.
1419
1420 \section{Subdirectory content description}
1421 \label{sec-rpp-lib-subdirectory-content-description}
1422 \begin{description}
1423 \item[librpp.a and rpp-lib.lib] static RPP libraries.
1424
1425 The first one is for POSIX simulation, the second one for Simulink models and
1426 other ARM/TMS570 applications. This files are placed here by the Makefile, when
1427 the library is built.
1428
1429         \item[apps/] Demo applications related to the RPP library.
1430
1431 This include the CCS studio project for generating of the static library and
1432 a test suite. The test suit in this directory has nothing common with the test suite
1433 mentioned later in Chapter 5 and those two suits are going to be merged in the
1434 future. Also other Hello World applications are included as a reference about how 
1435 to create a TMS570 application.
1436         \item[os/] OS layers directory. See OS interchangeable layer in Section
1437 \ref{sec-software-architecture} for more information.  
1438         \item[rpp/] Main directory for the RPP Library.
1439         \item[rpp/doc/] Documentation directory for the RPP Library API documentation.
1440         \item[rpp/TMS570LS3137.ccxml] Descriptor for code download.
1441
1442 This file is used by all the projects including the Simulink RPP Target for code
1443 download. It is configured to use the Texas Instruments XDS100v2 USB Emulator.
1444         \item[rpp/TMS570LS313xFlashLnk.cmd] CGT Linker command file.
1445
1446 This file is used by all applications linked for the RPP board, including the
1447 Simulink models, static library and test suite. It includes instructions for the
1448 CGT Linker on where to place sections and sizes of some sections.
1449         \item[rpp/include/\{layer\} and rpp/src/\{layer\}] Interface files and
1450 implementations files for given \textsc{\{layer\}}. See Section
1451 \ref{sec-software-architecture} in Chapter \ref{chap-introduction} for details
1452 on the RPP Layer.  
1453         \item[rpp/include/rpp/rpp.h] Main library header file.
1454
1455 To use this library with all its modules, just include this file and this file
1456 only. Also, before using any library function call the \textsc{rpp\_init()}
1457 function for hardware initialization.
1458         \item[rpp/include/rpp/rpp\_\{mnemonic\}.h] Header file for
1459 \textsc{\{mnemonic\}} module.
1460
1461 This files includes function definitions, pin definitions, etc, specific to
1462 \{mnemonic\} module. See Section \ref{sec-api-development-guidlines}.
1463
1464 You may include only selected \textsc{rpp\_\{mnemonic\}.h} header files and call the
1465 specific \textsc{rpp\_\{mnemonic\}\_init} functions, instead of the \textsc{rpp.h} and
1466 \textsc{rpp\_init} function, if you want to use only a subset of the library functions.
1467         \item[rpp/src/rpp/rpp\_\{mnemonic\}.c] Module implementation.
1468
1469 Implementation of \textsc{rpp\_\{mnemonic\}.h}'s functions on top of the DRV
1470 library. 
1471         \item[rpp/src/rpp/rpp.c] Implementation of library-wide functions.
1472 \end{description}
1473
1474 \section{Compilation}
1475 \label{sec-compilation}
1476
1477 The RPP Library can be compiled as a static library using a Code
1478 Composer Studio project. The compilation process will automatically
1479 update the generated binary static library file in the library root
1480 directory.
1481
1482 For the compilation of the library as a static library open the Code
1483 Composer studio project \textsc{rpp-lib} (see
1484 Section~\ref{sec-openning-of-existing-project}) and build the project.
1485 If the build process is successful, the \textsc{rpp-lib.lib} file will
1486 appear in the library root directory.
1487
1488 Because compilation of the libraries in Eclipse IDE can be error
1489 prone, there is a \textsc{Makefile} that allows to compile the
1490 libraries from the Linux or Windows command line:
1491
1492 \begin{lstlisting}[language=bash]
1493 cd <library-root>
1494 make
1495 \end{lstlisting}
1496
1497 On Windows use \texttt{gmake.exe} supplied with CCS instead of
1498 \texttt{make}. The rpp-lib CCS project is configured to invoke this
1499 build procedure from IDE rather than using a building compilation
1500 procedure. One of the results is that the compilation is much faster
1501 this way.
1502
1503 Note that this Makefile still requires the Code Composer Studio (ARM
1504 compiler) to be installed.
1505
1506 The relevant aspects for compiling and linking an application using the static
1507 libraries are: 
1508
1509 \begin{itemize}
1510         \item \textbf{ARM compilation using CCS for the RPP board:}
1511         \begin{compactitem}
1512                 \item Include headers files of the OS for which the library was
1513 compiled against. At the time of this writing the OS is FreeRTOS 7.0.2. See
1514 Section \ref{sec-software-architecture}
1515                 \item Include header files for the RPP library or for modules
1516 you want to use rpp\_can.h for CAN module for example.  
1517                 \item Add library \textsc{rpp-lib.lib} to the linker libraries.
1518 The RPP library \textbf{MUST} be looked for  before Texas Instruments support
1519 library \textsc{rtsv7R4\_T\_be\_v3D16\_eabi.lib}.
1520                 \item Configure linker to retain \textsc{.intvecs} section from
1521 RPP Library:\newline{}
1522 \textsc{--retain="rpp-lib.lib$\langle$sys\_intvecs.obj$\rangle$(.intvecs)"}
1523                 \item Use the provided linker command file
1524 \textsc{TMS570LS313xFlashLnk.cmd}.  
1525         \end{compactitem}
1526         \item \textbf{x86(\_64) compilation using GCC for Simulation:}
1527         \begin{compactitem}
1528                 \item Include headers files of the OS for Simulation. At the
1529 time of this writing the OS is POSIX FreeRTOS 6.0.4.  
1530                 \item Include header files for the RPP library or for modules
1531 you want to use (rpp\_can.h for CAN module for example).  
1532                 \item Add library \textsc{librpp.a} to the linker libraries.
1533                 \item Add \textsc{pthread} to the linker libraries.
1534         \end{compactitem}
1535 \end{itemize}
1536
1537 As an important note, all the models compiled using Simulink will link against
1538 \textsc{rpp-lib.lib}.  When compiling a Simulink model, neither Simulink nor the
1539 \textsc{make} invoked during the build process, will update the generated binary
1540 if the model hasn't changed, and then if the source code hasn't changed. Static
1541 libraries changes are not considered for re-compilation and re-linking. If
1542 library development is being done and static library is updated, in order for
1543 the Simulink model to generate a newly linked version of the binary the whole
1544 code generation folder needs to be deleted in order to force code generation,
1545 compilation and linking with the new static library.
1546
1547 \section{Compiling API documentation}
1548 \label{sec-compiling-api-documentation}
1549 The RPP Layer is formatted using Doxygen documentation generator. This allows to
1550 generate a high quality API reference. To generate the API reference run in a
1551 Linux terminal:
1552
1553 \lstset{language=bash}
1554 \begin{lstlisting}
1555 cd <repo>/rpp/doc/api
1556 make
1557 xdg-open html/index.html
1558 \end{lstlisting}
1559
1560 The files under \textsc{\repo/rpp/lib/rpp/doc/api/content} are used for the API
1561 reference generation are their name is self-explanatory:
1562
1563 \begin{verbatim}
1564 blocks_map.html
1565 blocks.png
1566 cvut.png
1567 footer.html
1568 main_page.dox
1569 \end{verbatim}
1570
1571 \chapter{Simulink Coder Target}
1572 \label{chap-simulink-coder-target}
1573
1574 The Simulink Coder Target allows to convert Simulink models to a C code,
1575 compile it and download to the board.
1576
1577 \section{Introduction}
1578 \label{sec-introduction}
1579
1580 The Simulink RPP Target provides support for C source code generation from Simulink models and
1581 compilation of that code on top of the RPP library and the FreeRTOS operating system. This target
1582 uses Texas Instruments ARM compiler (\textsc{armcl}) included in the Code Generation Tools distributed with
1583 Code Composer Studio, and thus it depends on it for proper functioning.
1584
1585 This target also provides support for automatic download of the compiled binary to the RPP
1586 board.
1587
1588 \begin{figure}[H]\begin{center}
1589 \noindent
1590 \includegraphics[width=300px]{images/tlc_process.png}
1591 \caption{TLC code generation process. \cite[p. 1-6]{targetlanguagecompiler2013}}
1592 \end{center}\end{figure}
1593
1594 \section{Features and limitations}
1595 \label{sec-features}
1596
1597 \begin{itemize}
1598 \item Sampling frequencies up to 1\,kHz.
1599 \item Supports only single-tasking and single-rate systems. Support
1600   for single-rate systems will be available in the final version.
1601   Support for multitasking system will require careful audit of the
1602   RPP library with respect to thread-safe code.
1603 \item No External mode support yet. We work on it.
1604 \item Custom compiler options, available via OPTS variable in
1605   \emph{Make command} at \emph{Code Generation} tab (see Figure
1606   \ref{fig-code-gen-settings}). For example \textsc{make\_rtw
1607     OPTS="-O0 -g"}.
1608 \end{itemize}
1609
1610 \section{RPP Options pane}
1611 \label{sec-rpp-target-options}
1612
1613 The RPP Target includes the following configuration options, all of them
1614 configurable per model under  \textsc{Code Generation} \noindent$\rightarrow$
1615 \textsc{RPP Options}:
1616
1617 \begin{itemize}
1618 \item \textbf{C system stack size}: this parameter is passed directly
1619   to the linker for the allocation of the stack. Note that this stack
1620   is used only for initializing the application and FreeRTOS. Once
1621   everything is initialized, another stack is used by the generated
1622   code. See below. Default value is 4096.
1623
1624 \item \textbf{C system heap size}:
1625   \label{sec-rpp-target-options-heap-size} this parameter is passed
1626   directly to the linker for the allocation of the heap. Currently,
1627   the heap is not used, but will be used by the external mode in the future.
1628 Note that FreeRTOS uses its own heap whose size is independent of this
1629 parameter. 
1630 \item \textbf{Model step task stack size}: this parameter will be
1631 passed to the \textsc{xTaskCreate()} that
1632   creates the task for the model to run. In a Simulink model there are always two tasks:
1633  \begin{itemize}
1634  \item The worker task. This task is the one that executes the model
1635    step. This task requires enough stack memory to execute the step.
1636    If your model does not run, it might be caused by too small stack.
1637    The memory needed for the stack depends on the size and structure
1638    of the model.
1639  \item The control task. This task controls when the worker task should execute and controls overruns.
1640
1641  \end{itemize}
1642 \item \textbf{Download compiled binary to RPP}: if set, this option will download the generated binary to
1643   the board after the model is successfully built. Note that this option is unaware of the option
1644   \textit{Generate code only} in the \textit{Code Generation} options panel, so it will try to download even if
1645   only source code has been generated, failing graciously or uploading an old binary laying around
1646   in the build directory. This option calls the \textsc{rpp\_download.m} script, which is in turn a
1647   wrapper on the \textsc{loadti.sh}, \textsc{loadti.bat} and \textsc{loadopenocd.sh} script. More information on the \textsc{loadti.sh}
1648   script can be found in:
1649 \begin{verbatim}
1650 <css>/ccs_base/scripting/examples/loadti/readme.txt
1651 http://processors.wiki.ti.com/index.php/Loadti
1652 \end{verbatim}
1653
1654   The \textsc{loadti.sh} and \textsc{loadti.bat} script will close after the
1655 download of the generated program, leaving the loaded program running.
1656
1657   The \textsc{loadopenocd.sh} script will close after the download of the
1658 generated program as well, but the program will be stopped.  In order to run
1659 the loaded program a manual reset of the board is required.
1660
1661 \item \textbf{Download compiled binary to SDRAM}: This feature is not yet
1662 implemented for the simulink target.
1663
1664 \item \textbf{Use OpenOCD to download the compiled binary}: This option switches
1665 from Ti loading script \textsc{loadti.sh} to OpenOCD script
1666 \textsc{loadopenocd.sh}. The benefit of using OpenOCD, besides that it is open
1667 source
1668   software, is much shorter loading time. More information about the right
1669 OpenOCD version and its installation can be found at:
1670 \begin{verbatim}
1671 http://rtime.felk.cvut.cz/hw/index.php/TMS570LS3137#OpenOCD_setup_and_Flashing
1672 \end{verbatim}
1673 This feature is available for Linux system only.
1674
1675 \item \textbf{Print model metadata to SCI at start}: if set this option will
1676 print a message to the Serial Communication Interface when the model start
1677 execution on the board. This is very helpful to identify the model running on
1678 the board. The message is in the form: 
1679
1680 \begin{verbatim}
1681 `model_name' - generated_date (TLC tlc_version)
1682 \end{verbatim}
1683
1684   For example:
1685 \begin{verbatim}
1686 `hbridge_analog_control' - Wed Jun 19 14:10:44 2013 (TLC 8.3 (Jul 20 2012))
1687 \end{verbatim}
1688 \end{itemize}
1689
1690 \section{Subdirectory  content description}
1691 \label{sec-simulink-subdirectory-content-description}
1692 This section describes the directories of the Simulink Coder. If you are
1693 interested in particular file, refer the description at the beginning of the
1694 file.
1695
1696 \begin{description}
1697         \item[doc/] Contains the sources of the documentation, you are now
1698 reading.  
1699         \item[refs/] Contains third party references, which license allows the
1700 distribution.
1701         \item[rpp/blocks] Contains the TLC files, which defines the blocks for
1702 the Matlab Simulink and \textsc{rpp\_lib.slx}, which is the Simulink RPP
1703 Library, containing all the Simulink blocks for RPP.
1704         \item[rpp/blocks/tlc\_c]Contains the templates for C code generation from the
1705 Matlab Simulink model.
1706         \item[rpp/demos] Contains demo models, which purpose is to serve as a
1707 reference for the usage and for testing.  
1708         \item[rpp/lib] Contains the C Support Library. See Chapter
1709 \ref{chap-c-support-library}.  \item[rpp/loadopenocd] Contains download scripts
1710 for Linux support of the OpenOCD, for code downloading to the target.
1711         \item[rpp/loadti] Contains download scripts for Linux and Windows
1712 support for code downloading to the target, using Texas Instruments CCS code
1713 downloader.  
1714         \item[rpp/rpp] Contains set of support script for the Code Generator.
1715 \end{description}
1716
1717 \section{Block Library Overview}
1718 \label{sec-block-library-overview}
1719 The Simulink Block Library is a set of blocks that allows Simulink models to use
1720 board IO and communication peripherals. The available blocks are summarized in
1721 Table~\ref{tab:block-lib-status} and more detailed description is
1722 given in Section~\ref{sec-blocks-description}.
1723
1724 \begin{table}
1725 \begin{center}\begin{tabular}{|lp{5cm}lll|}
1726 \hline
1727 \textbf{Category} & \textbf{Name} & \textbf{Status} & \textbf{Mnemonic} & \textbf{Header} \\
1728 \hline
1729 \input{block_table.tex}
1730 \hline
1731 \end{tabular}\end{center}
1732
1733   \caption{Block library overview}
1734   \label{tab:block-lib-status}
1735 \end{table}
1736
1737 \label{sec-blocks-implementation}
1738 All of the blocks are implemented as manually created C Mex S-Function . In this section the 
1739 approach taken is briefly explained.
1740
1741 \subsection{C MEX S-Functions}
1742 \label{sec-c-mex-functions}
1743  \begin{compactitem}
1744  \item C : Implemented in C language. Other options are Fortran and Matlab language itself.
1745  \item MEX: Matlab Executable. They are compiled by Matlab - C compiler wrapper called MEX.
1746  \item S-Function: System Function, as opposed to standard functions, or user functions.
1747  \end{compactitem}
1748
1749 A C-MEX S-Function is a structured C file that implements some mandatory and
1750 optional  callbacks for a specification of a number of inputs, outputs, data
1751 types, parameters, rate, validity checking, etc.  A complete list of callbacks
1752 can be found in:
1753         \begin{quotation}
1754 \htmladdnormallink{http://www.mathworks.com/help/simulink/create-cc-s-functions.html}{http://www.mathworks.com/help/simulink/create-cc-s-functions.html}
1755 \end{quotation}
1756
1757 The way a C-MEX S-Function participates in a Simulink simulation is shown on the
1758 diagram \ref{fig-sfunctions-process}:
1759
1760 \begin{figure}[H]\begin{center}
1761 \noindent
1762 \includegraphics[width=250px]{images/sfunctions_process.png}
1763 \caption{Simulation cycle of a S-Function. \cite[p. 57]{simulinkdevelopingsfunctions2013}}
1764 \label{fig-sfunctions-process}
1765 \end{center}\end{figure}
1766
1767 In general, the S-Function can perform calculations, inputs and outputs for simulation. Because 
1768 the RPP blocks are for hardware peripherals control and IO the blocks are 
1769 implemented as pure sink or pure source, the S-Function is just a descriptor of
1770 the block and does not perform any calculation and does not provide any input or
1771 output for simulations. 
1772
1773 The implementation of the S-Functions in the RPP project has following layout:
1774
1775 \begin{itemize}
1776   \item Define S-Function name \textsc{S\_FUNCTION\_NAME}.
1777   \item Include header file \textsc{header.c}, which in connection with
1778 \textsc{trailer.c} creates a miniframework for writing S-Functions.  
1779   \item In \textsc{mdlInitializeSizes} define:
1780   \begin{itemize}
1781         \item Number of \textit{dialog} parameter.
1782         \item Number of input ports.
1783         \begin{compactitem}
1784                 \item Data type of each input port.
1785         \end{compactitem}
1786         \item Number of output ports.
1787         \begin{compactitem}
1788                 \item Data type of each output port.
1789         \end{compactitem}
1790         \item Standard options for driver blocks.
1791   \end{itemize}
1792   \item In \textsc{mdlCheckParameters}:
1793   \begin{itemize}
1794         \item Check data type of each parameter.
1795         \item Check range, if applicable, of each parameter.
1796   \end{itemize}
1797   \item In \textsc{mdlSetWorkWidths}:
1798   \begin{compactitem}
1799         \item Map \textit{dialog} parameter to \textit{runtime} parameters.
1800         \begin{itemize}
1801                 \item Data type of each \textit{runtime} parameter.
1802         \end{itemize}
1803   \end{compactitem}
1804   \item Define symbols for unused functions.
1805   \item Include trailer file \textsc{trailer.c}.
1806 \end{itemize}
1807
1808 The C-MEX S-Function implemented can be compiled with the following command:
1809
1810 \lstset{language=bash}
1811 \begin{lstlisting}
1812 <matlabroot>/bin/mex sfunction_{mnemonic}.c
1813 \end{lstlisting}
1814
1815 As noted the standard is to always prefix S-Function with \textsc{sfunction\_}
1816 and use lower case mnemonic of the block.
1817
1818 Also a script called \textsc{compile\_blocks.m} is included. The script that
1819 allows all \textsc{sfunctions\_*.c} to be fed to the \textsc{mex} compiler so
1820 all S-Functions are compiled at once. To use this script, in Matlab do:
1821
1822 \lstset{language=Matlab}
1823 \begin{lstlisting}
1824 cd <repo>/rpp/blocks/
1825 compile_blocks()
1826 \end{lstlisting}
1827
1828 \subsection{Target Language Compiler files}
1829 \label{sec-target-language-compiler-files}
1830
1831 In order to generate code for each one of the S-Functions, every S-Function implements a TLC file
1832 for \textit{inlining} the S-Function on the generated code. The TLC files describe how to 
1833 generate code for a specific C-MEX S-Function block. They are programmed using TLC own language and 
1834 include C code within TLC instructions, just like LaTeX files include normal text in between LaTeX 
1835 macros.
1836
1837 The standard for a TLC file is to be located under the \textsc{tlc\_c} subfolder from where the 
1838 S-Function is located and to use the very exact file name as the S-Function but with the \textsc{.tlc}
1839 extension: \textsc{sfunction\_foo.c} \noindent$\rightarrow$ \textsc{tlc\_c/sfunction\_foo.tlc}
1840
1841 The TLC files implemented for this project use 3 hook functions in particular (other are available, 
1842 see TLC reference documentation):
1843 \begin{itemize}
1844 \item \textsc{BlockTypeSetup}: \newline{}
1845   BlockTypeSetup executes once per block type before code generation begins.
1846   This function can be used to include elements required by this block type, like includes or
1847   definitions.
1848 \item \textsc{Start}: \newline{}
1849   Code here will be placed in the \textsc{void
1850 $\langle$modelname$\rangle$\_initialize(void)}. Code placed here will execute
1851 only once.
1852 \item \textsc{Outputs}: \newline{}
1853   Code here will be placed in the \textsc{void
1854 $\langle$modelname$\rangle$\_step(void)} function. Should be used to get the
1855 inputs o a block and/or to set the outputs of that block.
1856 \end{itemize}
1857
1858 The general layout of the TLC files implemented for this project are:
1859 \begin{itemize}
1860 \item In \textsc{BlockTypeSetup}: \newline{}
1861   Call common function \textsc{\%$<$RppCommonBlockTypeSetup(block, system)$>$} that will include the 
1862   \textsc{rpp/rpp\i\_mnemonic.h} header file (can be called multiple times but header is included only once).
1863 \item \textsc{Start}: \newline{}
1864   Call setup routines from RPP Layer for the specific block type, like HBR enable, DIN pin setup, 
1865   DAC value initialization, SCI baud rate setup, among others.
1866 \item \textsc{Outputs}: \newline{}
1867   Call common IO routines from RPP Layer, like DIN read, DAC set, etc. Success of this functions
1868   is checked and in case of failure error is reported to the block using ErrFlag.
1869 \end{itemize}
1870
1871 C code generated from a Simulink model is placed on a file called
1872 \textsc{$\langle$modelname$\rangle$.c} along with other support files in a
1873 folder called \textsc{$\langle$modelname$\rangle$\_$\langle$target$\rangle$/}.
1874 For example, the source code generated for model \textsc{foobar} will be placed
1875 in current Matlab directory \textsc{foobar\_rpp/foobar.c}.
1876
1877 The file \textsc{$\langle$modelname$\rangle$.c} has 3 main functions:
1878 \begin{compactitem}
1879 \item \textsc{void $\langle$modelname$\rangle$\_step(void)}: \newline{}
1880   This function recalculates all the outputs of the blocks and should be called once per step. This
1881   is the main working function.
1882 \item \textsc{void $\langle$modelname$\rangle$\_initialize(void)}: \newline{}
1883   This function is called only once before the first step is issued. Default values for blocks IOs
1884   should be placed here.
1885 \item \textsc{void $\langle$modelname$\rangle$\_terminate(void)}: \newline{}
1886   This function is called when terminating the model. This should be used to free memory of revert 
1887   other operations made on the initialization function. With current implementation this function
1888   should never be called unless an error is detected and in most models it is empty.
1889 \end{compactitem}
1890
1891 \section{Block reference}
1892 \label{sec-blocks-description}
1893
1894 This section describes each one of the Simulink blocks present in the Simulink
1895 RPP block library, shown in Figure \ref{fig-block-library}.
1896
1897 \begin{figure}
1898 \includegraphics[width=\textwidth]{images/block_library.png}
1899 \caption{Simulink RPP Block Library.}
1900 \label{fig-block-library}
1901 \end{figure}
1902 \clearpage
1903 \input{block_desc.tex}
1904
1905 \section{Demos}
1906 The Simulink RPP Demo Library is a set of Simulink models that use blocks from
1907 the Simulink RPP Block Library and generates code using the Simulink RPP Target.
1908
1909 This demos library is used as a test suite for the Simulink RPP Block Library
1910 but they are also intended to show basic programs built using it. Because of
1911 this, the demos try to use more than one
1912 type of block and more than one block per block type.
1913
1914 In the reference below you can find a complete description for each of the demos.
1915
1916 \subsection{Analog pass-through}
1917 \begin{figure}[H]\begin{center}
1918 \noindent
1919 \includegraphics[width=450px]{images/demo_analog_passthrough.png}
1920 \caption{Analog Passthrough Simulink demo for RPP.}
1921 \end{center}\end{figure}
1922
1923 \textbf{Description:}
1924 This demo will read analog input 1 and write it to analog output 1.
1925
1926 In laboratory the minimum read value for analog input a 0 volts is 107. The maximum read at 12
1927 volts is 2478. The map subsystem will map the input domain (ADC)\textsc{[110, 2400]} to the output domain
1928 (DAC)\textsc{[0, 4095]}.
1929
1930
1931 \subsection{Analog sinewave}
1932 \begin{figure}[H]\begin{center}
1933 \noindent
1934 \includegraphics[width=450px]{images/demo_analog_sinewave.png}
1935 \caption{Analog Sinewave Simulink demo for RPP.}
1936 \end{center}\end{figure}
1937
1938 \textbf{Description:}
1939 This demo will generate a sinewave on analog output 1. The frequency
1940 of the sine wave is 10Hz and sampling rate is set to
1941 1000Hz (driven from Simulink step of 1ms, same as operating system). Amplitude is set to use DAC
1942 full range [0-4095] which means output amplitude will be [0-12] volts.
1943
1944 The Software oscilloscope shown should match an external one connected to DAC 1.
1945
1946 Note that the driver configuration of the MCP4922 is set to unbuffered (which should eventually
1947 be changed to buffered) and thus the last resolution millivolts are lost.
1948
1949
1950 \subsection{CAN transmit}
1951 \begin{figure}[H]\begin{center}
1952 \noindent
1953 \includegraphics[width=450px]{images/demo_cantransmit.png}
1954 \caption{Example of the usage of the CAN blocks for RPP.}
1955 \end{center}\end{figure}
1956
1957 \textbf{Description:}
1958
1959 Demostrates how to use CAN Transmit blocks in order to:
1960
1961 \begin{compactenum}
1962 \item Send unpacked data with data type uint8, uint16 and uint32.
1963 \item Send single and multiple signals packed into CAN\_MESSAGE by CAN Pack block.
1964 \item Send a message as extended frame type to be received by CAN Receive
1965 configured to receive both, standard and extended frame types.
1966 \end{compactenum}
1967
1968 Demostrates how to use CAN Receive blocks in order to:
1969
1970 \begin{compactenum}
1971 \item Receive unpacked data of data types uint8, uint16 and uint32.
1972 \item Receive and unpack received CAN\_MESSAGE by CAN Unpack block.
1973 \item Configure CAN Receive block to receive Standard, Extended and both frame types.
1974 \item Use function-call mechanism to process received messages
1975 \end{compactenum}
1976
1977 \subsection{CAN demo}
1978
1979 \begin{figure}[H]\begin{center}
1980 \noindent
1981 \includegraphics[width=450px]{images/demo_can_demo.png}
1982 \caption{CAN bus demo for RPP.}
1983 \end{center}\end{figure}
1984
1985 \textbf{Description:}
1986
1987 This demo demonstrates simple processing of received messages.
1988
1989 \subsection{Digital pass-through}
1990 \begin{figure}[H]\begin{center}
1991 \noindent
1992 \includegraphics[width=400px]{images/demo_digital_passthrough.png}
1993 \caption{Digital Pass-through Simulink demo for RPP.}
1994 \end{center}\end{figure}
1995
1996 \textbf{Description:}
1997
1998 This demo will directly pass the digital values read on DIN [1-8] to LOUT [1-8], and thus acting
1999 as a digital pass-through or gateway.
2000
2001 Also note that all the ErrFlag are aggregated on a global ErrFlag.
2002
2003 \subsection{Echo char}
2004 \begin{figure}[H]\begin{center}
2005 \noindent
2006 \includegraphics[width=450px]{images/demo_echo_char.png}
2007 \caption{Echo Character Simulink demo for RPP.}
2008 \end{center}\end{figure}
2009
2010 \textbf{Description:}
2011
2012 This demo will echo twice (print back) any character received through the Serial Communication
2013 Interface (9600-8-N-1).
2014
2015 Note that the send subsystem is implemented a as \textit{triggered} subsystem and will execute only
2016 if data is received, that is, Serial Receive output is non-negative. Negative values are errors.
2017
2018
2019 \subsection{H-bridge analog control}
2020 \begin{figure}[H]\begin{center}
2021 \noindent
2022 \includegraphics[width=450px]{images/demo_hbridge_analog_control.png}
2023 \caption{H-Bridge Analog Control Simulink demo for RPP.}
2024 \end{center}\end{figure}
2025
2026 \textbf{Description:}
2027
2028 This demo will read values from the analog input, map them, and control the H-Bridge. This allows
2029 a motor connected to the H-Bridge to be controlled with a potentiometer connected to Analog Input 1.
2030
2031 Setting the potentiometer to output around 6 volts will stop the motor. Less (or greater) than 6
2032 volts will trigger the motor in one sense (or in the other sense) and speed proportional with 1\%
2033 resolution.
2034
2035 In laboratory the minimum read value for analog input is 107 at 0 volts. The maximum read at 12 volts
2036 is 2478. The map subsystem will map the input domain (ADC)\textsc{[110, 2400]} to the output domain
2037 (HBR)\textsc{[-1.0, 1.0]}.
2038
2039
2040 \subsection{H-bridge digital control}
2041 \begin{figure}[H]\begin{center}
2042 \noindent
2043 \includegraphics[width=450px]{images/demo_hbridge_digital_control.png}
2044 \caption{H-Bridge Digital Control Simulink demo for RPP.}
2045 \end{center}\end{figure}
2046
2047 \textbf{Description:}
2048
2049 This demo toggle the H-Bridge from stop to full speed in one direction using digital input 1.
2050 So basically is a ON/OFF switch on DIN 1 for a motor connected on the HBR. Note the data type
2051 conversion because the output of the DIN is a boolean and the input to the HBR is a double.
2052
2053 \subsection{H-bridge sine wave control}
2054 \begin{figure}[H]\begin{center}
2055 \noindent
2056 \includegraphics[width=300px]{images/demo_hbridge_sinewave_control.png}
2057 \caption{H-Bridge Sinewave Control Simulink demo for RPP.}
2058 \end{center}\end{figure}
2059
2060 \textbf{Description:}
2061
2062 This demo will generate a sine wave to control the H-Bridge. Sine wave is one period per 20
2063 seconds or 0.05Hz. Sampling rate is 20Hz or 100 samples per 1/4 of period (for 1\% speed
2064 resolution change).
2065
2066 Note that the Software oscilloscope should is not the output of the H-Bridge, the H-Bridge will
2067 change current sense and the duty cycle of the pulse that drive it (PWM), it does not output
2068 analog values. The Software oscilloscope just shows what the input to the HBR block is.
2069
2070 \subsection{Hello world}
2071 \begin{figure}[H]\begin{center}
2072 \noindent
2073 \includegraphics[width=450px]{images/demo_hello_world.png}
2074 \caption{Hello World Simulink demo for RPP.}
2075 \end{center}\end{figure}
2076
2077 \textbf{Description:}
2078
2079 This demo will print \textsc{"Hello Simulink"} to the Serial Communication Interface (9600-8-N-1) one
2080 character per second. The output speed is driven by the Simulink model step which is set to one
2081 second.
2082
2083 \subsection{IRC input}
2084 \begin{figure}[H]\begin{center}
2085
2086 \noindent
2087 \includegraphics[width=450px]{images/demo_irc_input.png}
2088 \caption{LED Blink Simulink demo for RPP.}
2089 \end{center}\end{figure}
2090
2091 \textbf{Description:}
2092
2093 This demo is printing IRC sensor (connected to DIN10 and DIN11) value to the Serial Communication
2094 Interface (115200-8-N-1) with six values to one line.
2095
2096 \subsection{LED blink}
2097 \begin{figure}[H]\begin{center}
2098 \noindent
2099 \includegraphics[width=450px]{images/demo_led_blink.png}
2100 \caption{LED Blink Simulink demo for RPP.}
2101 \end{center}\end{figure}
2102
2103 \textbf{Description:}
2104
2105 This the simplest demo of all that shows the basics of using the RPP target and blocks. The
2106 goal of this demo is to show the configuration of the model (not shown on the picture above),
2107 that is, how the RPP Simulink Coder Target is setup, general model setup and step setup.
2108
2109 This demo will toggle each second a LED connected on LOUT 1. The timing is set by the Simulink
2110 model step which is set to 1 second.
2111
2112 \subsection{LED blink all}
2113 \begin{figure}[H]\begin{center}
2114 \noindent
2115 \includegraphics[width=350px]{images/demo_led_blink_all.png}
2116 \caption{LED Blink All Simulink demo for RPP.}
2117 \end{center}\end{figure}
2118
2119 \textbf{Description:}
2120
2121 This demo will toggle all LEDs connected to the LOUT port. Even outputs pins will be negated.
2122 Toggle will happen each second. The timing is driven by Simulink model step configuration that
2123 is set to 1 second. All blocks ErrFlags are aggregated into one global ErrFlag.
2124
2125 \subsection{Log analog input}
2126 \begin{figure}[H]\begin{center}
2127 \noindent
2128 \includegraphics[width=450px]{images/demo_log_analog_input.png}
2129 \caption{Log Analog Input Simulink demo for RPP.}
2130 \end{center}\end{figure}
2131
2132 \textbf{Description:}
2133
2134 This demo will log once per second the value read on the analog input 1. User can read the log
2135 using the SCI logging integrated command processor (9600-8-N-1). Logging block ID set to 1. The
2136 timing is driven by Simulink model step configuration that is set to 1 second.
2137
2138 \subsection{Power toggle}
2139 \begin{figure}[H]\begin{center}
2140 \noindent
2141 \includegraphics[width=300px]{images/demo_power_toggle.png}
2142 \caption{Power Toggle Simulink demo for RPP.}
2143 \end{center}\end{figure}
2144
2145 \textbf{Description:}
2146
2147 This demo will toggle the power output once per second. If an error is detected on at least one of
2148 the outputs a generic error message is printed to the serial line. The timing is driven by Simulink
2149 model step configuration that is set to 1 second. Power outputs can drive a load up to 2A, so please
2150 take into account required safety considerations.
2151
2152 \subsection{Simulink Demo board}
2153 Model for demo board has 6 subsystems. Every subsystem will be described separately.
2154 \begin{figure}[H]\begin{center}
2155 \noindent
2156 \includegraphics[width=0.8\textwidth]{images/demo_board-connection_scheme.pdf}
2157 \caption{Demo board connection and usage scheme.}
2158 \end{center}\end{figure}
2159
2160 \subsubsection{Potentiometer regulation of motor speed}
2161 This is example of driving motor with input signal. Motor can be rotated in
2162 various speed in both directions and stopping motor means setting potentiometer
2163 to half of its range. Potentiometer value is also transmitted through CAN.
2164
2165 \subsubsection{Color music}
2166 This is showing abilities of RPP board to generate analog signals. Bargraphs on
2167 demo board are showing value of analog outputs. Speed of change can be changed
2168 with potentiometer and in one case is used motor 2 IRC. There are five different
2169 modes. Three of them are derived from sinus and rest of them are counter value
2170 and direct control. Modes can be changed with black button. First mod selected
2171 after board start is fifth.  
2172 \begin{enumerate}
2173 \item Sinus signal is sequential delayed by 10 steps for second and third bargraph.
2174 \item Sinus signal on second bargraph is shifted by 120° and on third one is shifted by 240°.
2175 \item Sinus signal for second and third bargraphs are shifted same as in
2176 previous mode, but as counter value is used IRC value with appropriate divider
2177 no potentiometer value.  
2178 \item Visualizing counter value which speed is changed
2179 with potentiometer.
2180 \item Potentiometer value is passed to all bargraphs with appropriate multiplier.
2181 \end{enumerate}
2182
2183 \subsubsection{Buttons and LEDs}
2184 This is example of digital input/output. LEDs on demo board can be driven with
2185 four different subprograms. These subprograms can be changed with red button and
2186 are influenced with green and blue buttons.  
2187 \begin{enumerate}
2188 \item One LED is always ON and others are OFF. Every 0.1 sec is neighborhood LED
2189 switched on and previous one is switched off. With buttons you can change
2190 direction.  
2191 \item Same as previous mode, but change is not done after 0.1 sec
2192 but only when button is pressed.
2193 \item In this mode you can record message in Morse code (max 64 chars including
2194 spaces) and after delay it is repetitively replayed. To record message use green
2195 button as dash and blue button as dot.  
2196 \item Simple game in which you must determine if light is moving left or right
2197 and press green or blue button according to it. Speed of movement is increasing
2198 and in case of wrong answer or long delay is game ends with lights flashing.
2199 \end{enumerate}
2200
2201 \subsubsection{IRC to CAN}
2202 IRC value from Motor 2 is sent every tenth step via CAN2 with message ID 0x4.
2203
2204 \subsubsection{CAN receive -- Button press emulation}
2205 You can simulate press of all four buttons by sending message through CAN2 to
2206 board with message ID 0x0 and value according to button number.
2207
2208 \subsubsection{Configuration and error handling}
2209 RPP supports some basic runtime error handling. Every block can set its error
2210 flag, all these error flags are joined in this demo together and when some
2211 problem is detected CAN2 message of ID 0x10 is transmitted. Also in case of
2212 board overrun (exhaustion of time quanta) is transmitted message through CAN2
2213 with ID 0x11.\\ When model is build without external mode, errors are also
2214 printed to SCI.
2215
2216 \subsubsection{Full list of CAN communication}
2217 The board produces CAN frames with the following IDs:
2218 \begin{itemize}
2219 \item 0x05: Potentiometer 1 value.
2220 \item 0x06: Potentiometer 2 value.
2221 \item 0x08: Selected mod of color music.
2222 \item 0x09: Active subprogram of buttons and LEDs.
2223 \item 0x10: Transmitted only in case of error flag of some block, error code.
2224 \item 0x11: Transmitted only in case of board overrun, no data.
2225 \end{itemize}
2226 The board reacts to CAN frames with following IDs:
2227 \begin{itemize}
2228 \item 0x00: Simulate button press, accepts value 1--4.
2229 \end{itemize}
2230
2231 \chapter{Command line testing tool}
2232 \label{chap-rpp-test-software}
2233 The \textsc{rpp-test-suite} is a RPP application developed testing and direct
2234 control of the RPP hardware. The test suite implements a command processor,
2235 which is listening for a commands and prints some output related to the commands
2236 on the serial interface. The command processor is modular and each peripheral
2237 has its commands in a separated module.
2238
2239 The command processor is implemented in \textsc{$\langle$rpp-test-sw$\rangle$/cmdproc} and commands
2240 modules are implemented in \textsc{$\langle$rpp-test-sw$\rangle$/commands} directory.
2241
2242 The application enables a command processor using the SCI at
2243 \textbf{115200-8-N-1}. When the software starts, the received welcome message
2244 and prompt should look like:
2245
2246 \begin{verbatim}
2247 TODO: FILL
2248 \end{verbatim}
2249
2250 Type in command help for a complete list of available command, or help command
2251 for a description of concrete command.
2252
2253 \section{Command description}
2254
2255 This section contains the description of the available commands. The
2256 same description is also available in the program itself via the
2257 \texttt{help} command.
2258
2259 \input{rpp-test-sw-cmds.tex}
2260
2261 \chapter{Glossary}
2262
2263 \begin{description}
2264 \item[ADC]
2265   \textit{Analog to Digital Converter.} \newline{}
2266   Hardware circuitry that converts a continuous physical quantity (usually voltage) to a
2267   digital number that represents the quantity's amplitude.
2268
2269 \item[AIN]
2270   \textit{Analog Input.} \newline{}
2271   Mnemonic to refer to or something related to the analog input (ADC) hardware module.
2272
2273 \item[AOUT]
2274   \textit{Analog Output.} \newline{}
2275   Mnemonic to refer to or something related to the analog output (DAC) hardware module.
2276
2277 \item[CAN]
2278   \textit{Controller Area Network.} \newline{}
2279   The CAN Bus is a vehicle bus standard designed to allow microcontrollers and devices to
2280   communicate with each other within a vehicle without a host computer.
2281   In this project it is also used as mnemonic to refer to or something related to the CAN
2282   hardware module.
2283
2284 \item[CGT]
2285   \textit{Code Generation Tools.} \newline{}
2286   Name given to the tool set produced by Texas Instruments used to compile, link, optimize,
2287   assemble, archive, among others. In this project is normally used as synonym for
2288   ``Texas Instruments ARM compiler and linker."
2289
2290 \item[DAC]
2291   \textit{Digital to Analog Converter.} \newline{}
2292   Hardware circuitry that converts a digital (usually binary) code to an analog signal
2293   (current, voltage, or electric charge).
2294
2295 \item[DIN]
2296   \textit{Digital Input.} \newline{}
2297   Mnemonic to refer to or something related to the digital input hardware module.
2298
2299 \item[ECU]
2300   \textit{Engine Control Unit.} \newline{}
2301   A type of electronic control unit that controls a series of actuators on an internal combustion
2302   engine to ensure the optimum running.
2303
2304 \item[ETH]
2305   \textit{Ethernet.} \newline{}
2306   Mnemonic to refer to or something related to the Ethernet hardware module.
2307
2308 \item[FR]
2309   \textit{FlexRay.} \newline{}
2310   FlexRay is an automotive network communications protocol developed to govern on-board automotive
2311   computing.
2312   In this project it is also used as mnemonic to refer to or something related to the FlexRay
2313   hardware module.
2314
2315 \item[GPIO]
2316   \textit{General Purpose Input/Output.} \newline{}
2317   Generic pin on a chip whose behavior (including whether it is an input or output pin) can be
2318   controlled (programmed) by the user at run time.
2319
2320 \item[HBR]
2321   \textit{H-Bridge.} \newline{}
2322   Mnemonic to refer to or something related to the H-Bridge hardware module. A H-Bridge is
2323   an electronic circuit that enables a voltage to be applied across a load in either direction.
2324
2325 \item[HOUT]
2326   \textit{High-Power Output.} \newline{}
2327   Mnemonic to refer to or something related to the 10A, PWM, with current sensing, high-power
2328   output hardware module.
2329
2330 \item[IDE]
2331   \textit{Integrated Development Environment.} \newline{}
2332   An IDE is a Software application that provides comprehensive facilities to computer programmers
2333   for software development.
2334
2335 \item[LCT]
2336   \textit{Legacy Code Tool.} \newline{}
2337   Matlab tool that allows to generate source code for S-Functions given the descriptor of a C 
2338   function call.
2339
2340 \item[LIN]
2341   \textit{Local Interconnect Network.} \newline{}
2342   The LIN is a serial network protocol used for communication between components in vehicles.
2343   In this project it is also used as mnemonic to refer to or something related to the LIN
2344   hardware module.
2345
2346 \item[LOUT]
2347   \textit{Logic Output.} \newline{}
2348   Mnemonic to refer to or something related to the digital output hardware module.
2349   It is logic output (100mA), as opposed to power outputs (2A, 10A).
2350
2351 \item[MBD]
2352   \textit{Model-Based Design.} \newline{}
2353   Model-Based Design (MBD) is a mathematical and visual method of addressing problems associated
2354   with designing complex control, signal processing and communication systems. \cite{modelbasedwiki2013}
2355
2356 \item[MEX]
2357   \textit{Matlab Executable.} \newline{}
2358   Type of binary executable that can be called within Matlab. In this document the common term
2359   used is `C MEX S-Function", which means Matlab executable written in C that implements a system
2360   function.
2361
2362 \item[MOUT]
2363   \textit{(Motor) Power Output.} \newline{}
2364   Mnemonic to refer to or something related to the 2A push/pull power output hardware module.
2365
2366 \item[PWM]
2367   \textit{Pulse-width modulation.} \newline{}
2368   Technique for getting analog results with digital means. Digital control is used to create a
2369   square wave, a signal switched between on and off. This on-off pattern can simulate voltages
2370   in between full on and off by changing the portion of the time the signal spends on versus
2371   the time that the signal spends off. The duration of ``on time" is called the pulse width or
2372   \textit{duty cycle}.
2373
2374 \item[RPP]
2375   \textit{Rapid Prototyping Platform.} \newline{}
2376   Name of the automotive hardware board. Also generic term to define something related
2377   to the board, like the RPP Library, RPP Layer, RPP API, etc.
2378
2379 \item[SCI]
2380   \textit{Serial Communication Interface.} \newline{}
2381   Serial Interface for communication through hardware's UART using communication standard RS-232.
2382   In this project it is also used as mnemonic to refer to or something related to the Serial
2383   Communication Interface hardware module.
2384
2385 \item[SDC]
2386   \textit{SD-Card.} \newline{}
2387   Mnemonic to refer to or something related to the SD-Card hardware module.
2388
2389 \item[SDR]
2390   \textit{SD-RAM.} \newline{}
2391   Mnemonic to refer to or something related to the SD-RAM hardware module for logging.
2392
2393 \item[TLC]
2394   \textit{Target Language Compiler.} \newline{}
2395   Technology and language used to generate code in Matlab/Simulink.
2396
2397 \item[UART]
2398   \textit{Universal Asynchronous Receiver/Transmitter.} \newline{}
2399   Hardware circuitry that translates data between parallel and serial forms.
2400 \end{description}
2401
2402 \bibliography{rpp_simulink}
2403 \bibliographystyle{plain}
2404
2405 \end{document}
2406
2407 %  LocalWords:  FreeRTOS RPP POSIX