]> rtime.felk.cvut.cz Git - jenkicar/rpp-simulink.git/blob - doc/rpp_simulink.tex
2a778eecfaa5788ba14de8a8e3aea1b5795db52c
[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 (optional)
537         \item Uncrustify 0.59 (optional, see Section \ref{sec-compilation})
538         \item Doxygen 1.8.4 (optional, see Section \ref{sec-compiling-api-documentation})
539     \item Git 1.7.10.4 (optional)
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 (optional)
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 \htmladdnormallink{Target
1211 Reference}{\#target\_reference} section below.
1212 \end{enumerate}
1213
1214
1215 \subsection{Working with demo models}
1216 \label{sec-openning-demo-models}
1217 The demo models are available from the directory \textsc{\repo/rpp/demos}. To
1218 access the demo models for reference or for downloading to the RPP board you
1219 have to change the directory to the one, containing the desired demo. For
1220 example to open the cantransmit demo you have to type these commands into the
1221 Matlab command line:
1222
1223 \begin{lstlisting}[language=Matlab]
1224 cd <rpp-simulink>/rpp/demos
1225 open cantransmit.slx
1226 \end{lstlisting}
1227
1228 The same procedure can be used to open any other models. To run the model on
1229 the target hardware see Section \ref{sec-running-model-on-hw}.
1230
1231 \subsection{Creating a new model}
1232 \label{sec-crating-new-model}
1233 \begin{enumerate}
1234         \item Create a model by clicking \textsc{New$\rightarrow$Simulink Model}.
1235         \item Open a configuration dialog by clicking \textsc{Simulation$\rightarrow$Model Configuration Parameters}.
1236         \item The new Simulink model needs to be configured in the following way:
1237         \begin{compactitem}
1238         \item Solver (Figure \ref{fig-solver}):
1239          \begin{compactitem}
1240          \item Options: \emph{Fixed-step, discrete}
1241          \item Tasking mode set to \textit{SingleTasking}.
1242            \begin{figure}
1243                  \centering
1244                  \includegraphics[width=400px]{images/simulink_solver.png}
1245                  \caption{Solver settings}
1246                  \label{fig-solver}
1247         \end{figure}
1248          \end{compactitem}
1249         \item Diagnostics $\rightarrow$ Sample Time (Figure~\ref{fig-sample-time-settings}):
1250          \begin{compactitem}
1251          \item Disable warning source block specifies -1 sampling time. It's ok for the
1252 source blocks to run once per tick.
1253            \begin{figure}
1254                  \centering
1255                  \includegraphics[width=400px]{images/simulink_diagnostics.png}
1256                  \caption{Sample Time settings}
1257                  \label{fig-sample-time-settings}
1258         \end{figure}
1259         \end{compactitem}
1260         \item Code generation (Figure~\ref{fig-code-gen-settings}):
1261          \begin{compactitem}
1262          \item Set to \textsc{rpp.tlc}.
1263            \begin{figure}
1264                  \centering
1265                  \includegraphics[width=400px]{images/simulink_code.png}
1266                  \caption{Code Generation settings}
1267                  \label{fig-code-gen-settings}
1268         \end{figure}
1269         \end{compactitem}
1270 \end{compactitem}
1271         \item From Matlab command window change the current directory to where
1272 you want your generated code to appear, e.g.:
1273 \begin{lstlisting}[language=Matlab]
1274 cd /tmp/my-code
1275 \end{lstlisting}
1276   The code will be generated in a subdirectory of that directory. The name of
1277 the subdirectory will be \textsc{<model>\_rpp}, where \textsc{model} is the name
1278 of the Simulink model.
1279         \item Generate the code by choosing \textsc{Code $\rightarrow$ C/C++
1280 Code  $\rightarrow$ Build Model}.
1281 \end{enumerate}
1282
1283 If you want to run the model on the RPP board, see Section
1284 \ref{sec-running-model-on-hw}.
1285
1286 \subsection{Running model on the RPP board}
1287 \label{sec-running-model-on-hw}
1288 To run the model on the target RPP hardware you have to enable the download
1289 feature and build the model by following this procedure: \begin{enumerate}
1290         \item Open the model you want to run (See Section
1291 \ref{sec-openning-demo-models}.)
1292         \item Click on \textsc{Simulation$\rightarrow$Model Configuration
1293 Parameters}.
1294         \item In the \textsc{Code Generation$\rightarrow$RPP Options} pane
1295 check \textsc{Download compiled binary to RPP} checkbox.
1296         \item Click on \textsc{OK} button, connect the target HW to the computer
1297 like in the Section \ref{sec-ccs-run-project} and build the model by \textsc{Code $\rightarrow$ C/C++
1298 Code  $\rightarrow$ Build Model}. If the build
1299 ends with a success, the download process will start and once the downloading is
1300 finished, the application will run immediatelly.
1301 \end{enumerate}
1302
1303 The code downloading is supported for Windows and Linux development systems. If
1304 you are using Linux, you may also try to use the OpenOCD by checking Use OpenOCD
1305 to download the compiled binary checkbox in addition. For more information about
1306 the OpenOCD configuration refer 
1307
1308 \begin{verbatim}
1309 http://rtime.felk.cvut.cz/hw/index.php/TMS570LS3137#OpenOCD_setup_and_Flashing
1310 \end{verbatim}
1311
1312 Note: You should end the Code Composer Studio debug session before
1313 downloading the generated code to the RPP board. Otherwise the
1314 download will fail.
1315  
1316 \section{Configuring serial interface}
1317 \label{sec-configuration-serial-interface}
1318 The main interface for communicating with the RPP board is the serial interface.
1319 The application may define its own interface settings, but the following
1320 settings is the default one:
1321
1322 \begin{itemize}
1323         \item Baudrate: 115200
1324         \item Parity: none
1325         \item Bits: 8
1326         \item Stopbits: 1
1327         \item Flow control: none
1328 \end{itemize}
1329
1330 Use GtkTerm in Linux or Bray Terminal for accessing the serial interface. See
1331 Section \ref{sec-hardware-description} for reference about the position of the
1332 serial interface connector on the RPP board.
1333
1334 \section{Bug reporting}
1335 \label{sec-bug-reporting}
1336
1337 % TODO: implement
1338
1339 \chapter{C Support Library}
1340 \label{chap-c-support-library}
1341
1342 This chapter describes the implementation of the C support library
1343 (RPP Library), which is used both for Simulink code generation target
1344 and command line testing tool.
1345
1346 \section{Description}
1347 \label{sec-description}
1348 The RPP C Support Library (also called RPP library) defines the API for
1349 working with the board. It includes drivers and an operating system.
1350 The library is
1351 designed from the board user perspective and exposes a simplified high-level API
1352 to handle the board's peripheral modules in a safe manner. The library is
1353 compiled as a static library named \texttt{rpp-lib.lib} and can be found in
1354 \textsc{\repo/rpp/lib}.
1355
1356 The RPP library can be used in any project, where the RPP hardware support is
1357 required and it is also used in two applications -- the Command line testing
1358 tool, described in Chapter \ref{chap-rpp-test-software}, and Simulink Coder
1359 target, described in Chapter \ref{chap-simulink-coder-target}.
1360
1361 For details about the library architecture, refer Section \ref{sec-software-architecture}.
1362
1363 \section{API development guidelines}
1364 \label{sec-api-development-guidlines}
1365
1366 The following are the development guidelines used for developing the RPP API:
1367
1368 \begin{compactitem}
1369         \item User documentation should be placed in header files, not in source
1370 code, and should be Doxygen formatted using autobrief. Documentation for each
1371 function present is mandatory.
1372         \item Function declarations in the headers files is for public functions
1373 only. Do not declare local/static/private functions in the header.
1374         \item Documentation in source code files should be non-doxygen formatted
1375 and intended for developers, not users. Documentation here is optional and at
1376 the discretion of the developer.
1377         \item Always use standard data types for IO when possible. Use custom
1378 structs as very last resort.  \item Use prefix based functions names to avoid
1379 clash. The prefix is of the form \textsc{$\langle$layer$\rangle$\_$\langle$module$\rangle$\_}, for example
1380 \textsc{rpp\_din\_update()} for the update function of the DIN module in the RPP
1381 Layer.  
1382         \item Be very careful about symbol export. Because it is used as a
1383 static library the modules should not export any symbol that is not intended to
1384 be used (function) or \textsc{extern}'ed (variable) from application. As a rule
1385 of thumb declare all global variables as static. 
1386         \item Only the RPP Layer symbols are available to user applications. All
1387 information related to lower layers is hidden for the application. This is
1388 accomplished by the inclusion of the rpp.h or rpp\_\{mnemonic\}.h file on the
1389 implementations files only and never on the interface files. Never expose any
1390 other layer to the application or to the whole system below the RPP layer. In
1391 other words, never \textsc{\#include "foo/foo.h"} in any RPP Layer interface
1392 file. 
1393 \end{compactitem}
1394
1395 \section{Coding style}
1396 \label{sec-coding-style}
1397 In order to keep the code as clean as possible, a unified coding style
1398 should be followed by any contributor to the code. The used coding
1399 style is based on the default configuration of Code Composer Studio
1400 editor. Most notable rule is that the Tab character is 4 spaces.
1401
1402 The RPP library project is prepared for a usage of a program named
1403 Uncrustify. The Uncrustify program checks the code and fixes those
1404 lines that does not match the coding style. However, keep in mind that
1405 the program is not perfect and sometimes some lines can be modified
1406 even when the suggested coding style has been followed. This does not
1407 causes problems as long as the contributor follows the committing
1408 procedure described in next paragraph.
1409
1410 When contributing to the code, the contributor should learn the current coding
1411 style from the existing code. When a new feature is implemented, before
1412 committing to the repository, a command: 
1413
1414 \lstset{language=bash}
1415 \begin{lstlisting}
1416 make uncrustify
1417 \end{lstlisting}
1418 in a Linux terminal should be called. This command fixes any coding style
1419 errors. After that all changes can be committed.
1420
1421 \section{Subdirectory content description}
1422 \label{sec-rpp-lib-subdirectory-content-description}
1423 \begin{description}
1424 \item[librpp.a and rpp-lib.lib] static RPP libraries.
1425
1426 The first one is for POSIX simulation, the second one for Simulink models and
1427 other ARM/TMS570 applications. This files are placed here by the Makefile, when
1428 the library is built.
1429
1430         \item[apps/] Demo applications related to the RPP library.
1431
1432 This include the CCS studio project for generating of the static library and
1433 a test suite. The test suit in this directory has nothing common with the test suite
1434 mentioned later in Chapter 5 and those two suits are going to be merged in the
1435 future. Also other Hello World applications are included as a reference about how 
1436 to create a TMS570 application.
1437         \item[os/] OS layers directory. See OS interchangeable layer in Section
1438 \ref{sec-software-architecture} for more information.  
1439         \item[rpp/] Main directory for the RPP Library.
1440         \item[rpp/doc/] Documentation directory for the RPP Library API documentation.
1441         \item[rpp/TMS570LS3137.ccxml] Descriptor for code download.
1442
1443 This file is used by all the projects including the Simulink RPP Target for code
1444 download. It is configured to use the Texas Instruments XDS100v2 USB Emulator.
1445         \item[rpp/TMS570LS313xFlashLnk.cmd] CGT Linker command file.
1446
1447 This file is used by all applications linked for the RPP board, including the
1448 Simulink models, static library and test suite. It includes instructions for the
1449 CGT Linker on where to place sections and sizes of some sections.
1450         \item[rpp/include/\{layer\} and rpp/src/\{layer\}] Interface files and
1451 implementations files for given \textsc{\{layer\}}. See Section
1452 \ref{sec-software-architecture} in Chapter \ref{chap-introduction} for details
1453 on the RPP Layer.  
1454         \item[rpp/include/rpp/rpp.h] Main library header file.
1455
1456 To use this library with all its modules, just include this file and this file
1457 only. Also, before using any library function call the \textsc{rpp\_init()}
1458 function for hardware initialization.
1459         \item[rpp/include/rpp/rpp\_\{mnemonic\}.h] Header file for
1460 \textsc{\{mnemonic\}} module.
1461
1462 This files includes function definitions, pin definitions, etc, specific to
1463 \{mnemonic\} module. See Section \ref{sec-api-development-guidlines}.
1464
1465 You may include only selected \textsc{rpp\_\{mnemonic\}.h} header files and call the
1466 specific \textsc{rpp\_\{mnemonic\}\_init} functions, instead of the \textsc{rpp.h} and
1467 \textsc{rpp\_init} function, if you want to use only a subset of the library functions.
1468         \item[rpp/src/rpp/rpp\_\{mnemonic\}.c] Module implementation.
1469
1470 Implementation of \textsc{rpp\_\{mnemonic\}.h}'s functions on top of the DRV
1471 library. 
1472         \item[rpp/src/rpp/rpp.c] Implementation of library-wide functions.
1473 \end{description}
1474
1475 \section{Compilation}
1476 \label{sec-compilation}
1477
1478 The RPP Library can be compiled as a static library using a Code
1479 Composer Studio project. The compilation process will automatically
1480 update the generated binary static library file in the library root
1481 directory.
1482
1483 For the compilation of the library as a static library open the Code
1484 Composer studio project \textsc{rpp-lib} (see
1485 Section~\ref{sec-openning-of-existing-project}) and build the project.
1486 If the build process is successful, the \textsc{rpp-lib.lib} file will
1487 appear in the library root directory.
1488
1489 Because compilation of the libraries in Eclipse IDE can be error
1490 prone, there is a \textsc{Makefile} that allows to compile the
1491 libraries from the Linux or Windows command line:
1492
1493 \begin{lstlisting}[language=bash]
1494 cd <library-root>
1495 make
1496 \end{lstlisting}
1497
1498 On Windows use \texttt{gmake.exe} supplied with CCS instead of
1499 \texttt{make}. The rpp-lib CCS project is configured to invoke this
1500 build procedure from IDE rather than using a building compilation
1501 procedure. One of the results is that the compilation is much faster
1502 this way.
1503
1504 Note that this Makefile still requires the Code Composer Studio (ARM
1505 compiler) to be installed.
1506
1507 The relevant aspects for compiling and linking an application using the static
1508 libraries are: 
1509
1510 \begin{itemize}
1511         \item \textbf{ARM compilation using CCS for the RPP board:}
1512         \begin{compactitem}
1513                 \item Include headers files of the OS for which the library was
1514 compiled against. At the time of this writing the OS is FreeRTOS 7.0.2. See
1515 Section \ref{sec-software-architecture}
1516                 \item Include header files for the RPP library or for modules
1517 you want to use rpp\_can.h for CAN module for example.  
1518                 \item Add library \textsc{rpp-lib.lib} to the linker libraries.
1519 The RPP library \textbf{MUST} be looked for  before Texas Instruments support
1520 library \textsc{rtsv7R4\_T\_be\_v3D16\_eabi.lib}.
1521                 \item Configure linker to retain \textsc{.intvecs} section from
1522 RPP Library:\newline{}
1523 \textsc{--retain="rpp-lib.lib$\langle$sys\_intvecs.obj$\rangle$(.intvecs)"}
1524                 \item Use the provided linker command file
1525 \textsc{TMS570LS313xFlashLnk.cmd}.  
1526         \end{compactitem}
1527         \item \textbf{x86(\_64) compilation using GCC for Simulation:}
1528         \begin{compactitem}
1529                 \item Include headers files of the OS for Simulation. At the
1530 time of this writing the OS is POSIX FreeRTOS 6.0.4.  
1531                 \item Include header files for the RPP library or for modules
1532 you want to use (rpp\_can.h for CAN module for example).  
1533                 \item Add library \textsc{librpp.a} to the linker libraries.
1534                 \item Add \textsc{pthread} to the linker libraries.
1535         \end{compactitem}
1536 \end{itemize}
1537
1538 As an important note, all the models compiled using Simulink will link against
1539 \textsc{rpp-lib.lib}.  When compiling a Simulink model, neither Simulink nor the
1540 \textsc{make} invoked during the build process, will update the generated binary
1541 if the model hasn't changed, and then if the source code hasn't changed. Static
1542 libraries changes are not considered for re-compilation and re-linking. If
1543 library development is being done and static library is updated, in order for
1544 the Simulink model to generate a newly linked version of the binary the whole
1545 code generation folder needs to be deleted in order to force code generation,
1546 compilation and linking with the new static library.
1547
1548 \section{Compiling API documentation}
1549 \label{sec-compiling-api-documentation}
1550 The RPP Layer is formatted using Doxygen documentation generator. This allows to
1551 generate a high quality API reference. To generate the API reference run in a
1552 Linux terminal:
1553
1554 \lstset{language=bash}
1555 \begin{lstlisting}
1556 cd <repo>/rpp/doc/api
1557 make
1558 xdg-open html/index.html
1559 \end{lstlisting}
1560
1561 The files under \textsc{\repo/rpp/lib/rpp/doc/api/content} are used for the API
1562 reference generation are their name is self-explanatory:
1563
1564 \begin{verbatim}
1565 blocks_map.html
1566 blocks.png
1567 cvut.png
1568 footer.html
1569 main_page.dox
1570 \end{verbatim}
1571
1572 \chapter{Simulink Coder Target}
1573 \label{chap-simulink-coder-target}
1574
1575 The Simulink Coder Target allows to convert Simulink models to a C code,
1576 compile it and download to the board.
1577
1578 \section{Introduction}
1579 \label{sec-introduction}
1580
1581 The Simulink RPP Target provides support for C source code generation from Simulink models and
1582 compilation of that code on top of the RPP library and the FreeRTOS operating system. This target
1583 uses Texas Instruments ARM compiler (\textsc{armcl}) included in the Code Generation Tools distributed with
1584 Code Composer Studio, and thus it depends on it for proper functioning.
1585
1586 This target also provides support for automatic download of the compiled binary to the RPP
1587 board.
1588
1589 \begin{figure}[H]\begin{center}
1590 \noindent
1591 \includegraphics[width=300px]{images/tlc_process.png}
1592 \caption{TLC code generation process. \cite[p. 1-6]{targetlanguagecompiler2013}}
1593 \end{center}\end{figure}
1594
1595 \section{Features and limitations}
1596 \label{sec-features}
1597
1598 \begin{itemize}
1599 \item Sampling frequencies up to 1\,kHz.
1600 \item Supports only single-tasking and single-rate systems. Support
1601   for single-rate systems will be available in the final version.
1602   Support for multitasking system will require careful audit of the
1603   RPP library with respect to thread-safe code.
1604 \item No External mode support yet. We work on it.
1605 \item Custom compiler options, available via OPTS variable in
1606   \emph{Make command} at \emph{Code Generation} tab (see Figure
1607   \ref{fig-code-gen-settings}). For example \textsc{make\_rtw
1608     OPTS="-O0 -g"}.
1609 \end{itemize}
1610
1611 \section{RPP Options pane}
1612 \label{sec-rpp-target-options}
1613
1614 The RPP Target includes the following configuration options, all of them
1615 configurable per model under  \textsc{Code Generation} \noindent$\rightarrow$
1616 \textsc{RPP Options}:
1617
1618 \begin{itemize}
1619 \item \textbf{C system stack size}: this parameter is passed directly
1620   to the linker for the allocation of the stack. Note that this stack
1621   is used only for initializing the application and FreeRTOS. Once
1622   everything is initialized, another stack is used by the generated
1623   code. See below. Default value is 4096.
1624
1625 \item \textbf{C system heap size}:
1626   \label{sec-rpp-target-options-heap-size} this parameter is passed
1627   directly to the linker for the allocation of the heap. Currently,
1628   the heap is not used, but will be used by the external mode in the future.
1629 Note that FreeRTOS uses its own heap whose size is independent of this
1630 parameter. 
1631 \item \textbf{Model step task stack size}: this parameter will be
1632 passed to the \textsc{xTaskCreate()} that
1633   creates the task for the model to run. In a Simulink model there are always two tasks:
1634  \begin{itemize}
1635  \item The worker task. This task is the one that executes the model
1636    step. This task requires enough stack memory to execute the step.
1637    If your model does not run, it might be caused by too small stack.
1638    The memory needed for the stack depends on the size and structure
1639    of the model.
1640  \item The control task. This task controls when the worker task should execute and controls overruns.
1641
1642  \end{itemize}
1643 \item \textbf{Download compiled binary to RPP}: if set, this option will download the generated binary to
1644   the board after the model is successfully built. Note that this option is unaware of the option
1645   \textit{Generate code only} in the \textit{Code Generation} options panel, so it will try to download even if
1646   only source code has been generated, failing graciously or uploading an old binary laying around
1647   in the build directory. This option calls the \textsc{rpp\_download.m} script, which is in turn a
1648   wrapper on the \textsc{loadti.sh}, \textsc{loadti.bat} and \textsc{loadopenocd.sh} script. More information on the \textsc{loadti.sh}
1649   script can be found in:
1650 \begin{verbatim}
1651 <css>/ccs_base/scripting/examples/loadti/readme.txt
1652 http://processors.wiki.ti.com/index.php/Loadti
1653 \end{verbatim}
1654
1655   The \textsc{loadti.sh} and \textsc{loadti.bat} script will close after the
1656 download of the generated program, leaving the loaded program running.
1657
1658   The \textsc{loadopenocd.sh} script will close after the download of the
1659 generated program as well, but the program will be stopped.  In order to run
1660 the loaded program a manual reset of the board is required.
1661
1662 \item \textbf{Download compiled binary to SDRAM}: This feature is not yet
1663 implemented for the simulink target.
1664
1665 \item \textbf{Use OpenOCD to download the compiled binary}: This option switches
1666 from Ti loading script \textsc{loadti.sh} to OpenOCD script
1667 \textsc{loadopenocd.sh}. The benefit of using OpenOCD, besides that it is open
1668 source
1669   software, is much shorter loading time. More information about the right
1670 OpenOCD version and its installation can be found at:
1671 \begin{verbatim}
1672 http://rtime.felk.cvut.cz/hw/index.php/TMS570LS3137#OpenOCD_setup_and_Flashing
1673 \end{verbatim}
1674 This feature is available for Linux system only.
1675
1676 \item \textbf{Print model metadata to SCI at start}: if set this option will
1677 print a message to the Serial Communication Interface when the model start
1678 execution on the board. This is very helpful to identify the model running on
1679 the board. The message is in the form: 
1680
1681 \begin{verbatim}
1682 `model_name' - generated_date (TLC tlc_version)
1683 \end{verbatim}
1684
1685   For example:
1686 \begin{verbatim}
1687 `hbridge_analog_control' - Wed Jun 19 14:10:44 2013 (TLC 8.3 (Jul 20 2012))
1688 \end{verbatim}
1689 \end{itemize}
1690
1691 \section{Subdirectory  content description}
1692 \label{sec-simulink-subdirectory-content-description}
1693 This section describes the directories of the Simulink Coder. If you are
1694 interested in particular file, refer the description at the beginning of the
1695 file.
1696
1697 \begin{description}
1698         \item[doc/] Contains the sources of the documentation, you are now
1699 reading.  
1700         \item[refs/] Contains third party references, which license allows the
1701 distribution.
1702         \item[rpp/blocks] Contains the TLC files, which defines the blocks for
1703 the Matlab Simulink and \textsc{rpp\_lib.slx}, which is the Simulink RPP
1704 Library, containing all the Simulink blocks for RPP.
1705         \item[rpp/blocks/tlc\_c]Contains the templates for C code generation from the
1706 Matlab Simulink model.
1707         \item[rpp/demos] Contains demo models, which purpose is to serve as a
1708 reference for the usage and for testing.  
1709         \item[rpp/lib] Contains the C Support Library. See Chapter
1710 \ref{chap-c-support-library}.  \item[rpp/loadopenocd] Contains download scripts
1711 for Linux support of the OpenOCD, for code downloading to the target.
1712         \item[rpp/loadti] Contains download scripts for Linux and Windows
1713 support for code downloading to the target, using Texas Instruments CCS code
1714 downloader.  
1715         \item[rpp/rpp] Contains set of support script for the Code Generator.
1716 \end{description}
1717
1718 \section{Block Library Overview}
1719 \label{sec-block-library-overview}
1720 The Simulink Block Library is a set of blocks that allows Simulink models to use
1721 board IO and communication peripherals. The available blocks are summarized in
1722 Table~\ref{tab:block-lib-status} and more detailed description is
1723 given in Section~\ref{sec-blocks-description}.
1724
1725 \begin{table}
1726 \begin{center}\begin{tabular}{|lp{5cm}lll|}
1727 \hline
1728 \textbf{Category} & \textbf{Name} & \textbf{Status} & \textbf{Mnemonic} & \textbf{Header} \\
1729 \hline
1730 \input{block_table.tex}
1731 \hline
1732 \end{tabular}\end{center}
1733
1734   \caption{Block library overview}
1735   \label{tab:block-lib-status}
1736 \end{table}
1737
1738 \label{sec-blocks-implementation}
1739 All of the blocks are implemented as manually created C Mex S-Function . In this section the 
1740 approach taken is briefly explained.
1741
1742 \subsection{C MEX S-Functions}
1743 \label{sec-c-mex-functions}
1744  \begin{compactitem}
1745  \item C : Implemented in C language. Other options are Fortran and Matlab language itself.
1746  \item MEX: Matlab Executable. They are compiled by Matlab - C compiler wrapper called MEX.
1747  \item S-Function: System Function, as opposed to standard functions, or user functions.
1748  \end{compactitem}
1749
1750 A C-MEX S-Function is a structured C file that implements some mandatory and
1751 optional  callbacks for a specification of a number of inputs, outputs, data
1752 types, parameters, rate, validity checking, etc.  A complete list of callbacks
1753 can be found in:
1754         \begin{quotation}
1755 \htmladdnormallink{http://www.mathworks.com/help/simulink/create-cc-s-functions.html}{http://www.mathworks.com/help/simulink/create-cc-s-functions.html}
1756 \end{quotation}
1757
1758 The way a C-MEX S-Function participates in a Simulink simulation is shown on the
1759 diagram \ref{fig-sfunctions-process}:
1760
1761 \begin{figure}[H]\begin{center}
1762 \noindent
1763 \includegraphics[width=250px]{images/sfunctions_process.png}
1764 \caption{Simulation cycle of a S-Function. \cite[p. 57]{simulinkdevelopingsfunctions2013}}
1765 \label{fig-sfunctions-process}
1766 \end{center}\end{figure}
1767
1768 In general, the S-Function can perform calculations, inputs and outputs for simulation. Because 
1769 the RPP blocks are for hardware peripherals control and IO the blocks are 
1770 implemented as pure sink or pure source, the S-Function is just a descriptor of
1771 the block and does not perform any calculation and does not provide any input or
1772 output for simulations. 
1773
1774 The implementation of the S-Functions in the RPP project has following layout:
1775
1776 \begin{itemize}
1777   \item Define S-Function name \textsc{S\_FUNCTION\_NAME}.
1778   \item Include header file \textsc{header.c}, which in connection with
1779 \textsc{trailer.c} creates a miniframework for writing S-Functions.  
1780   \item In \textsc{mdlInitializeSizes} define:
1781   \begin{itemize}
1782         \item Number of \textit{dialog} parameter.
1783         \item Number of input ports.
1784         \begin{compactitem}
1785                 \item Data type of each input port.
1786         \end{compactitem}
1787         \item Number of output ports.
1788         \begin{compactitem}
1789                 \item Data type of each output port.
1790         \end{compactitem}
1791         \item Standard options for driver blocks.
1792   \end{itemize}
1793   \item In \textsc{mdlCheckParameters}:
1794   \begin{itemize}
1795         \item Check data type of each parameter.
1796         \item Check range, if applicable, of each parameter.
1797   \end{itemize}
1798   \item In \textsc{mdlSetWorkWidths}:
1799   \begin{compactitem}
1800         \item Map \textit{dialog} parameter to \textit{runtime} parameters.
1801         \begin{itemize}
1802                 \item Data type of each \textit{runtime} parameter.
1803         \end{itemize}
1804   \end{compactitem}
1805   \item Define symbols for unused functions.
1806   \item Include trailer file \textsc{trailer.c}.
1807 \end{itemize}
1808
1809 The C-MEX S-Function implemented can be compiled with the following command:
1810
1811 \lstset{language=bash}
1812 \begin{lstlisting}
1813 <matlabroot>/bin/mex sfunction_{mnemonic}.c
1814 \end{lstlisting}
1815
1816 As noted the standard is to always prefix S-Function with \textsc{sfunction\_}
1817 and use lower case mnemonic of the block.
1818
1819 Also a script called \textsc{compile\_blocks.m} is included. The script that
1820 allows all \textsc{sfunctions\_*.c} to be fed to the \textsc{mex} compiler so
1821 all S-Functions are compiled at once. To use this script, in Matlab do:
1822
1823 \lstset{language=Matlab}
1824 \begin{lstlisting}
1825 cd <repo>/rpp/blocks/
1826 compile_blocks()
1827 \end{lstlisting}
1828
1829 \subsection{Target Language Compiler files}
1830 \label{sec-target-language-compiler-files}
1831
1832 In order to generate code for each one of the S-Functions, every S-Function implements a TLC file
1833 for \textit{inlining} the S-Function on the generated code. The TLC files describe how to 
1834 generate code for a specific C-MEX S-Function block. They are programmed using TLC own language and 
1835 include C code within TLC instructions, just like LaTeX files include normal text in between LaTeX 
1836 macros.
1837
1838 The standard for a TLC file is to be located under the \textsc{tlc\_c} subfolder from where the 
1839 S-Function is located and to use the very exact file name as the S-Function but with the \textsc{.tlc}
1840 extension: \textsc{sfunction\_foo.c} \noindent$\rightarrow$ \textsc{tlc\_c/sfunction\_foo.tlc}
1841
1842 The TLC files implemented for this project use 3 hook functions in particular (other are available, 
1843 see TLC reference documentation):
1844 \begin{itemize}
1845 \item \textsc{BlockTypeSetup}: \newline{}
1846   BlockTypeSetup executes once per block type before code generation begins.
1847   This function can be used to include elements required by this block type, like includes or
1848   definitions.
1849 \item \textsc{Start}: \newline{}
1850   Code here will be placed in the \textsc{void
1851 $\langle$modelname$\rangle$\_initialize(void)}. Code placed here will execute
1852 only once.
1853 \item \textsc{Outputs}: \newline{}
1854   Code here will be placed in the \textsc{void
1855 $\langle$modelname$\rangle$\_step(void)} function. Should be used to get the
1856 inputs o a block and/or to set the outputs of that block.
1857 \end{itemize}
1858
1859 The general layout of the TLC files implemented for this project are:
1860 \begin{itemize}
1861 \item In \textsc{BlockTypeSetup}: \newline{}
1862   Call common function \textsc{\%$<$RppCommonBlockTypeSetup(block, system)$>$} that will include the 
1863   \textsc{rpp/rpp\i\_mnemonic.h} header file (can be called multiple times but header is included only once).
1864 \item \textsc{Start}: \newline{}
1865   Call setup routines from RPP Layer for the specific block type, like HBR enable, DIN pin setup, 
1866   DAC value initialization, SCI baud rate setup, among others.
1867 \item \textsc{Outputs}: \newline{}
1868   Call common IO routines from RPP Layer, like DIN read, DAC set, etc. Success of this functions
1869   is checked and in case of failure error is reported to the block using ErrFlag.
1870 \end{itemize}
1871
1872 C code generated from a Simulink model is placed on a file called
1873 \textsc{$\langle$modelname$\rangle$.c} along with other support files in a
1874 folder called \textsc{$\langle$modelname$\rangle$\_$\langle$target$\rangle$/}.
1875 For example, the source code generated for model \textsc{foobar} will be placed
1876 in current Matlab directory \textsc{foobar\_rpp/foobar.c}.
1877
1878 The file \textsc{$\langle$modelname$\rangle$.c} has 3 main functions:
1879 \begin{compactitem}
1880 \item \textsc{void $\langle$modelname$\rangle$\_step(void)}: \newline{}
1881   This function recalculates all the outputs of the blocks and should be called once per step. This
1882   is the main working function.
1883 \item \textsc{void $\langle$modelname$\rangle$\_initialize(void)}: \newline{}
1884   This function is called only once before the first step is issued. Default values for blocks IOs
1885   should be placed here.
1886 \item \textsc{void $\langle$modelname$\rangle$\_terminate(void)}: \newline{}
1887   This function is called when terminating the model. This should be used to free memory of revert 
1888   other operations made on the initialization function. With current implementation this function
1889   should never be called unless an error is detected and in most models it is empty.
1890 \end{compactitem}
1891
1892 \section{Block reference}
1893 \label{sec-blocks-description}
1894
1895 This section describes each one of the Simulink blocks present in the Simulink
1896 RPP block library, shown in Figure \ref{fig-block-library}.
1897
1898 \begin{figure}
1899 \includegraphics[width=\textwidth]{images/block_library.png}
1900 \caption{Simulink RPP Block Library.}
1901 \label{fig-block-library}
1902 \end{figure}
1903 \clearpage
1904 \input{block_desc.tex}
1905
1906 \section{Demos}
1907 The Simulink RPP Demo Library is a set of Simulink models that use blocks from
1908 the Simulink RPP Block Library and generates code using the Simulink RPP Target.
1909
1910 This demos library is used as a test suite for the Simulink RPP Block Library
1911 but they are also intended to show basic programs built using it. Because of
1912 this, the demos try to use more than one
1913 type of block and more than one block per block type.
1914
1915 In the reference below you can find a complete description for each of the demos.
1916
1917 \subsection{Analog pass-through}
1918 \begin{figure}[H]\begin{center}
1919 \noindent
1920 \includegraphics[width=450px]{images/demo_analog_passthrough.png}
1921 \caption{Analog Passthrough Simulink demo for RPP.}
1922 \end{center}\end{figure}
1923
1924 \textbf{Description:}
1925 This demo will read analog input 1 and write it to analog output 1.
1926
1927 In laboratory the minimum read value for analog input a 0 volts is 107. The maximum read at 12
1928 volts is 2478. The map subsystem will map the input domain (ADC)\textsc{[110, 2400]} to the output domain
1929 (DAC)\textsc{[0, 4095]}.
1930
1931
1932 \subsection{Analog sinewave}
1933 \begin{figure}[H]\begin{center}
1934 \noindent
1935 \includegraphics[width=450px]{images/demo_analog_sinewave.png}
1936 \caption{Analog Sinewave Simulink demo for RPP.}
1937 \end{center}\end{figure}
1938
1939 \textbf{Description:}
1940 This demo will generate a sinewave on analog output 1. The frequency
1941 of the sine wave is 10Hz and sampling rate is set to
1942 1000Hz (driven from Simulink step of 1ms, same as operating system). Amplitude is set to use DAC
1943 full range [0-4095] which means output amplitude will be [0-12] volts.
1944
1945 The Software oscilloscope shown should match an external one connected to DAC 1.
1946
1947 Note that the driver configuration of the MCP4922 is set to unbuffered (which should eventually
1948 be changed to buffered) and thus the last resolution millivolts are lost.
1949
1950
1951 \subsection{CAN transmit}
1952 \begin{figure}[H]\begin{center}
1953 \noindent
1954 \includegraphics[width=450px]{images/demo_cantransmit.png}
1955 \caption{Example of the usage of the CAN blocks for RPP.}
1956 \end{center}\end{figure}
1957
1958 \textbf{Description:}
1959
1960 Demostrates how to use CAN Transmit blocks in order to:
1961
1962 \begin{compactenum}
1963 \item Send unpacked data with data type uint8, uint16 and uint32.
1964 \item Send single and multiple signals packed into CAN\_MESSAGE by CAN Pack block.
1965 \item Send a message as extended frame type to be received by CAN Receive
1966 configured to receive both, standard and extended frame types.
1967 \end{compactenum}
1968
1969 Demostrates how to use CAN Receive blocks in order to:
1970
1971 \begin{compactenum}
1972 \item Receive unpacked data of data types uint8, uint16 and uint32.
1973 \item Receive and unpack received CAN\_MESSAGE by CAN Unpack block.
1974 \item Configure CAN Receive block to receive Standard, Extended and both frame types.
1975 \item Use function-call mechanism to process received messages
1976 \end{compactenum}
1977
1978 \subsection{CAN demo}
1979
1980 \begin{figure}[H]\begin{center}
1981 \noindent
1982 \includegraphics[width=450px]{images/demo_can_demo.png}
1983 \caption{CAN bus demo for RPP.}
1984 \end{center}\end{figure}
1985
1986 \textbf{Description:}
1987
1988 This demo demonstrates simple processing of received messages.
1989
1990 \subsection{Digital pass-through}
1991 \begin{figure}[H]\begin{center}
1992 \noindent
1993 \includegraphics[width=400px]{images/demo_digital_passthrough.png}
1994 \caption{Digital Pass-through Simulink demo for RPP.}
1995 \end{center}\end{figure}
1996
1997 \textbf{Description:}
1998
1999 This demo will directly pass the digital values read on DIN [1-8] to LOUT [1-8], and thus acting
2000 as a digital pass-through or gateway.
2001
2002 Also note that all the ErrFlag are aggregated on a global ErrFlag.
2003
2004 \subsection{Echo char}
2005 \begin{figure}[H]\begin{center}
2006 \noindent
2007 \includegraphics[width=450px]{images/demo_echo_char.png}
2008 \caption{Echo Character Simulink demo for RPP.}
2009 \end{center}\end{figure}
2010
2011 \textbf{Description:}
2012
2013 This demo will echo twice (print back) any character received through the Serial Communication
2014 Interface (9600-8-N-1).
2015
2016 Note that the send subsystem is implemented a as \textit{triggered} subsystem and will execute only
2017 if data is received, that is, Serial Receive output is non-negative. Negative values are errors.
2018
2019
2020 \subsection{H-bridge analog control}
2021 \begin{figure}[H]\begin{center}
2022 \noindent
2023 \includegraphics[width=450px]{images/demo_hbridge_analog_control.png}
2024 \caption{H-Bridge Analog Control Simulink demo for RPP.}
2025 \end{center}\end{figure}
2026
2027 \textbf{Description:}
2028
2029 This demo will read values from the analog input, map them, and control the H-Bridge. This allows
2030 a motor connected to the H-Bridge to be controlled with a potentiometer connected to Analog Input 1.
2031
2032 Setting the potentiometer to output around 6 volts will stop the motor. Less (or greater) than 6
2033 volts will trigger the motor in one sense (or in the other sense) and speed proportional with 1\%
2034 resolution.
2035
2036 In laboratory the minimum read value for analog input is 107 at 0 volts. The maximum read at 12 volts
2037 is 2478. The map subsystem will map the input domain (ADC)\textsc{[110, 2400]} to the output domain
2038 (HBR)\textsc{[-1.0, 1.0]}.
2039
2040
2041 \subsection{H-bridge digital control}
2042 \begin{figure}[H]\begin{center}
2043 \noindent
2044 \includegraphics[width=450px]{images/demo_hbridge_digital_control.png}
2045 \caption{H-Bridge Digital Control Simulink demo for RPP.}
2046 \end{center}\end{figure}
2047
2048 \textbf{Description:}
2049
2050 This demo toggle the H-Bridge from stop to full speed in one direction using digital input 1.
2051 So basically is a ON/OFF switch on DIN 1 for a motor connected on the HBR. Note the data type
2052 conversion because the output of the DIN is a boolean and the input to the HBR is a double.
2053
2054 \subsection{H-bridge sine wave control}
2055 \begin{figure}[H]\begin{center}
2056 \noindent
2057 \includegraphics[width=300px]{images/demo_hbridge_sinewave_control.png}
2058 \caption{H-Bridge Sinewave Control Simulink demo for RPP.}
2059 \end{center}\end{figure}
2060
2061 \textbf{Description:}
2062
2063 This demo will generate a sine wave to control the H-Bridge. Sine wave is one period per 20
2064 seconds or 0.05Hz. Sampling rate is 20Hz or 100 samples per 1/4 of period (for 1\% speed
2065 resolution change).
2066
2067 Note that the Software oscilloscope should is not the output of the H-Bridge, the H-Bridge will
2068 change current sense and the duty cycle of the pulse that drive it (PWM), it does not output
2069 analog values. The Software oscilloscope just shows what the input to the HBR block is.
2070
2071 \subsection{Hello world}
2072 \begin{figure}[H]\begin{center}
2073 \noindent
2074 \includegraphics[width=450px]{images/demo_hello_world.png}
2075 \caption{Hello World Simulink demo for RPP.}
2076 \end{center}\end{figure}
2077
2078 \textbf{Description:}
2079
2080 This demo will print \textsc{"Hello Simulink"} to the Serial Communication Interface (9600-8-N-1) one
2081 character per second. The output speed is driven by the Simulink model step which is set to one
2082 second.
2083
2084 \subsection{IRC input}
2085 \begin{figure}[H]\begin{center}
2086
2087 \noindent
2088 \includegraphics[width=450px]{images/demo_irc_input.png}
2089 \caption{LED Blink Simulink demo for RPP.}
2090 \end{center}\end{figure}
2091
2092 \textbf{Description:}
2093
2094 This demo is printing IRC sensor (connected to DIN10 and DIN11) value to the Serial Communication
2095 Interface (115200-8-N-1) with six values to one line.
2096
2097 \subsection{LED blink}
2098 \begin{figure}[H]\begin{center}
2099 \noindent
2100 \includegraphics[width=450px]{images/demo_led_blink.png}
2101 \caption{LED Blink Simulink demo for RPP.}
2102 \end{center}\end{figure}
2103
2104 \textbf{Description:}
2105
2106 This the simplest demo of all that shows the basics of using the RPP target and blocks. The
2107 goal of this demo is to show the configuration of the model (not shown on the picture above),
2108 that is, how the RPP Simulink Coder Target is setup, general model setup and step setup.
2109
2110 This demo will toggle each second a LED connected on LOUT 1. The timing is set by the Simulink
2111 model step which is set to 1 second.
2112
2113 \subsection{LED blink all}
2114 \begin{figure}[H]\begin{center}
2115 \noindent
2116 \includegraphics[width=350px]{images/demo_led_blink_all.png}
2117 \caption{LED Blink All Simulink demo for RPP.}
2118 \end{center}\end{figure}
2119
2120 \textbf{Description:}
2121
2122 This demo will toggle all LEDs connected to the LOUT port. Even outputs pins will be negated.
2123 Toggle will happen each second. The timing is driven by Simulink model step configuration that
2124 is set to 1 second. All blocks ErrFlags are aggregated into one global ErrFlag.
2125
2126 \subsection{Log analog input}
2127 \begin{figure}[H]\begin{center}
2128 \noindent
2129 \includegraphics[width=450px]{images/demo_log_analog_input.png}
2130 \caption{Log Analog Input Simulink demo for RPP.}
2131 \end{center}\end{figure}
2132
2133 \textbf{Description:}
2134
2135 This demo will log once per second the value read on the analog input 1. User can read the log
2136 using the SCI logging integrated command processor (9600-8-N-1). Logging block ID set to 1. The
2137 timing is driven by Simulink model step configuration that is set to 1 second.
2138
2139 \subsection{Power toggle}
2140 \begin{figure}[H]\begin{center}
2141 \noindent
2142 \includegraphics[width=300px]{images/demo_power_toggle.png}
2143 \caption{Power Toggle Simulink demo for RPP.}
2144 \end{center}\end{figure}
2145
2146 \textbf{Description:}
2147
2148 This demo will toggle the power output once per second. If an error is detected on at least one of
2149 the outputs a generic error message is printed to the serial line. The timing is driven by Simulink
2150 model step configuration that is set to 1 second. Power outputs can drive a load up to 2A, so please
2151 take into account required safety considerations.
2152
2153 \subsection{Simulink Demo board}
2154 Model for demo board has 6 subsystems. Every subsystem will be described separately.
2155 \begin{figure}[H]\begin{center}
2156 \noindent
2157 \includegraphics[width=0.8\textwidth]{images/demo_board-connection_scheme.pdf}
2158 \caption{Demo board connection and usage scheme.}
2159 \end{center}\end{figure}
2160
2161 \subsubsection{Potentiometer regulation of motor speed}
2162 This is example of driving motor with input signal. Motor can be rotated in
2163 various speed in both directions and stopping motor means setting potentiometer
2164 to half of its range. Potentiometer value is also transmitted through CAN.
2165
2166 \subsubsection{Color music}
2167 This is showing abilities of RPP board to generate analog signals. Bargraphs on
2168 demo board are showing value of analog outputs. Speed of change can be changed
2169 with potentiometer and in one case is used motor 2 IRC. There are five different
2170 modes. Three of them are derived from sinus and rest of them are counter value
2171 and direct control. Modes can be changed with black button. First mod selected
2172 after board start is fifth.  
2173 \begin{enumerate}
2174 \item Sinus signal is sequential delayed by 10 steps for second and third bargraph.
2175 \item Sinus signal on second bargraph is shifted by 120° and on third one is shifted by 240°.
2176 \item Sinus signal for second and third bargraphs are shifted same as in
2177 previous mode, but as counter value is used IRC value with appropriate divider
2178 no potentiometer value.  
2179 \item Visualizing counter value which speed is changed
2180 with potentiometer.
2181 \item Potentiometer value is passed to all bargraphs with appropriate multiplier.
2182 \end{enumerate}
2183
2184 \subsubsection{Buttons and LEDs}
2185 This is example of digital input/output. LEDs on demo board can be driven with
2186 four different subprograms. These subprograms can be changed with red button and
2187 are influenced with green and blue buttons.  
2188 \begin{enumerate}
2189 \item One LED is always ON and others are OFF. Every 0.1 sec is neighborhood LED
2190 switched on and previous one is switched off. With buttons you can change
2191 direction.  
2192 \item Same as previous mode, but change is not done after 0.1 sec
2193 but only when button is pressed.
2194 \item In this mode you can record message in Morse code (max 64 chars including
2195 spaces) and after delay it is repetitively replayed. To record message use green
2196 button as dash and blue button as dot.  
2197 \item Simple game in which you must determine if light is moving left or right
2198 and press green or blue button according to it. Speed of movement is increasing
2199 and in case of wrong answer or long delay is game ends with lights flashing.
2200 \end{enumerate}
2201
2202 \subsubsection{IRC to CAN}
2203 IRC value from Motor 2 is sent every tenth step via CAN2 with message ID 0x4.
2204
2205 \subsubsection{CAN receive -- Button press emulation}
2206 You can simulate press of all four buttons by sending message through CAN2 to
2207 board with message ID 0x0 and value according to button number.
2208
2209 \subsubsection{Configuration and error handling}
2210 RPP supports some basic runtime error handling. Every block can set its error
2211 flag, all these error flags are joined in this demo together and when some
2212 problem is detected CAN2 message of ID 0x10 is transmitted. Also in case of
2213 board overrun (exhaustion of time quanta) is transmitted message through CAN2
2214 with ID 0x11.\\ When model is build without external mode, errors are also
2215 printed to SCI.
2216
2217 \subsubsection{Full list of CAN communication}
2218 The board produces CAN frames with the following IDs:
2219 \begin{itemize}
2220 \item 0x05: Potentiometer 1 value.
2221 \item 0x06: Potentiometer 2 value.
2222 \item 0x08: Selected mod of color music.
2223 \item 0x09: Active subprogram of buttons and LEDs.
2224 \item 0x10: Transmitted only in case of error flag of some block, error code.
2225 \item 0x11: Transmitted only in case of board overrun, no data.
2226 \end{itemize}
2227 The board reacts to CAN frames with following IDs:
2228 \begin{itemize}
2229 \item 0x00: Simulate button press, accepts value 1--4.
2230 \end{itemize}
2231
2232 \chapter{Command line testing tool}
2233 \label{chap-rpp-test-software}
2234 The \textsc{rpp-test-suite} is a RPP application developed testing and direct
2235 control of the RPP hardware. The test suite implements a command processor,
2236 which is listening for a commands and prints some output related to the commands
2237 on the serial interface. The command processor is modular and each peripheral
2238 has its commands in a separated module.
2239
2240 The command processor is implemented in \textsc{$\langle$rpp-test-sw$\rangle$/cmdproc} and commands
2241 modules are implemented in \textsc{$\langle$rpp-test-sw$\rangle$/commands} directory.
2242
2243 The application enables a command processor using the SCI at
2244 \textbf{115200-8-N-1}. When the software starts, the received welcome message
2245 and prompt should look like:
2246
2247 \begin{verbatim}
2248 TODO: FILL
2249 \end{verbatim}
2250
2251 Type in command help for a complete list of available command, or help command
2252 for a description of concrete command.
2253
2254 \section{Command description}
2255
2256 This section contains the description of the available commands. The
2257 same description is also available in the program itself via the
2258 \texttt{help} command.
2259
2260 \input{rpp-test-sw-cmds.tex}
2261
2262 \chapter{Glossary}
2263
2264 \begin{description}
2265 \item[ADC]
2266   \textit{Analog to Digital Converter.} \newline{}
2267   Hardware circuitry that converts a continuous physical quantity (usually voltage) to a
2268   digital number that represents the quantity's amplitude.
2269
2270 \item[AIN]
2271   \textit{Analog Input.} \newline{}
2272   Mnemonic to refer to or something related to the analog input (ADC) hardware module.
2273
2274 \item[AOUT]
2275   \textit{Analog Output.} \newline{}
2276   Mnemonic to refer to or something related to the analog output (DAC) hardware module.
2277
2278 \item[CAN]
2279   \textit{Controller Area Network.} \newline{}
2280   The CAN Bus is a vehicle bus standard designed to allow microcontrollers and devices to
2281   communicate with each other within a vehicle without a host computer.
2282   In this project it is also used as mnemonic to refer to or something related to the CAN
2283   hardware module.
2284
2285 \item[CGT]
2286   \textit{Code Generation Tools.} \newline{}
2287   Name given to the tool set produced by Texas Instruments used to compile, link, optimize,
2288   assemble, archive, among others. In this project is normally used as synonym for
2289   ``Texas Instruments ARM compiler and linker."
2290
2291 \item[DAC]
2292   \textit{Digital to Analog Converter.} \newline{}
2293   Hardware circuitry that converts a digital (usually binary) code to an analog signal
2294   (current, voltage, or electric charge).
2295
2296 \item[DIN]
2297   \textit{Digital Input.} \newline{}
2298   Mnemonic to refer to or something related to the digital input hardware module.
2299
2300 \item[ECU]
2301   \textit{Engine Control Unit.} \newline{}
2302   A type of electronic control unit that controls a series of actuators on an internal combustion
2303   engine to ensure the optimum running.
2304
2305 \item[ETH]
2306   \textit{Ethernet.} \newline{}
2307   Mnemonic to refer to or something related to the Ethernet hardware module.
2308
2309 \item[FR]
2310   \textit{FlexRay.} \newline{}
2311   FlexRay is an automotive network communications protocol developed to govern on-board automotive
2312   computing.
2313   In this project it is also used as mnemonic to refer to or something related to the FlexRay
2314   hardware module.
2315
2316 \item[GPIO]
2317   \textit{General Purpose Input/Output.} \newline{}
2318   Generic pin on a chip whose behavior (including whether it is an input or output pin) can be
2319   controlled (programmed) by the user at run time.
2320
2321 \item[HBR]
2322   \textit{H-Bridge.} \newline{}
2323   Mnemonic to refer to or something related to the H-Bridge hardware module. A H-Bridge is
2324   an electronic circuit that enables a voltage to be applied across a load in either direction.
2325
2326 \item[HOUT]
2327   \textit{High-Power Output.} \newline{}
2328   Mnemonic to refer to or something related to the 10A, PWM, with current sensing, high-power
2329   output hardware module.
2330
2331 \item[IDE]
2332   \textit{Integrated Development Environment.} \newline{}
2333   An IDE is a Software application that provides comprehensive facilities to computer programmers
2334   for software development.
2335
2336 \item[LCT]
2337   \textit{Legacy Code Tool.} \newline{}
2338   Matlab tool that allows to generate source code for S-Functions given the descriptor of a C 
2339   function call.
2340
2341 \item[LIN]
2342   \textit{Local Interconnect Network.} \newline{}
2343   The LIN is a serial network protocol used for communication between components in vehicles.
2344   In this project it is also used as mnemonic to refer to or something related to the LIN
2345   hardware module.
2346
2347 \item[LOUT]
2348   \textit{Logic Output.} \newline{}
2349   Mnemonic to refer to or something related to the digital output hardware module.
2350   It is logic output (100mA), as opposed to power outputs (2A, 10A).
2351
2352 \item[MBD]
2353   \textit{Model-Based Design.} \newline{}
2354   Model-Based Design (MBD) is a mathematical and visual method of addressing problems associated
2355   with designing complex control, signal processing and communication systems. \cite{modelbasedwiki2013}
2356
2357 \item[MEX]
2358   \textit{Matlab Executable.} \newline{}
2359   Type of binary executable that can be called within Matlab. In this document the common term
2360   used is `C MEX S-Function", which means Matlab executable written in C that implements a system
2361   function.
2362
2363 \item[MOUT]
2364   \textit{(Motor) Power Output.} \newline{}
2365   Mnemonic to refer to or something related to the 2A push/pull power output hardware module.
2366
2367 \item[PWM]
2368   \textit{Pulse-width modulation.} \newline{}
2369   Technique for getting analog results with digital means. Digital control is used to create a
2370   square wave, a signal switched between on and off. This on-off pattern can simulate voltages
2371   in between full on and off by changing the portion of the time the signal spends on versus
2372   the time that the signal spends off. The duration of ``on time" is called the pulse width or
2373   \textit{duty cycle}.
2374
2375 \item[RPP]
2376   \textit{Rapid Prototyping Platform.} \newline{}
2377   Name of the automotive hardware board. Also generic term to define something related
2378   to the board, like the RPP Library, RPP Layer, RPP API, etc.
2379
2380 \item[SCI]
2381   \textit{Serial Communication Interface.} \newline{}
2382   Serial Interface for communication through hardware's UART using communication standard RS-232.
2383   In this project it is also used as mnemonic to refer to or something related to the Serial
2384   Communication Interface hardware module.
2385
2386 \item[SDC]
2387   \textit{SD-Card.} \newline{}
2388   Mnemonic to refer to or something related to the SD-Card hardware module.
2389
2390 \item[SDR]
2391   \textit{SD-RAM.} \newline{}
2392   Mnemonic to refer to or something related to the SD-RAM hardware module for logging.
2393
2394 \item[TLC]
2395   \textit{Target Language Compiler.} \newline{}
2396   Technology and language used to generate code in Matlab/Simulink.
2397
2398 \item[UART]
2399   \textit{Universal Asynchronous Receiver/Transmitter.} \newline{}
2400   Hardware circuitry that translates data between parallel and serial forms.
2401 \end{description}
2402
2403 \bibliography{rpp_simulink}
2404 \bibliographystyle{plain}
2405
2406 \end{document}
2407
2408 %  LocalWords:  FreeRTOS RPP POSIX