]> rtime.felk.cvut.cz Git - pes-rpp/rpp-simulink.git/blob - doc/rpp_simulink.tex
doc: add HW description section
[pes-rpp/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.40\textwidth]{images/logo_ctu.pdf}\\[1cm]
88 \textsc{\LARGE Czech Technical University in Prague}\\[1.5cm]
89
90
91 % Document title
92 \HRule
93 \vspace{0.4cm}
94 {\huge \bfseries Simulink code generation target for Texas~Instruments
95   RM48 platform\par}
96 \vspace{0.4cm}
97 \HRule \\[1.5cm]
98
99
100 % Author
101 \emph{Authors:}\\
102 Carlos \textsc{Jenkins}\\
103 Michal \textsc{Horn}\\
104 Michal \textsc{Sojka}\\[\baselineskip]
105
106 \vfill
107
108 \emph{Version:}
109 \input{version.tex}
110
111 % Bottom of the page
112 {\large \today}
113
114 \end{center}
115 \end{titlepage}
116 % Title end
117
118 \tableofcontents
119
120 \newpage
121
122 \listoffigures
123
124 \newpage
125
126 %\addtolength{\parskip}{\baselineskip} % Paragraph spacing
127
128 \chapter{Introduction}
129 \label{chap-introduction}
130
131 This text serves as a documentation for the Rapid Prototyping Platform
132 (RPP) project based on Texas Instruments RM48 safety microcontroller.
133 Originally, the RPP project was created for TMS570 microcontroller and
134 the port to RM48 was derived from it under a contract with Eaton
135 Corporation. As this document is still in beta version, some
136 references to the original TMS570-based RPP remain in it.
137
138
139 The document contains step-by-step instructions for installation of
140 development tools, information about Simulink Coder configuration,
141 describes how to create new models as well as how to download the
142 resulting firmware to the hardware. It can also be used as a reference
143 for a testing tool, Matlab Simulink blocks and RPP Matlab Simulink
144 Code generator. The document also provides an overall description of
145 the hardware design and architecture of its control software.
146
147 \section{Background}
148 \label{sec-background}
149
150 The Rapid Prototyping Platform is an ECU (Electronic Control Unit) designed for
151 use in Automotive, thus requirements for Automotive communication interfaces,
152 durable IO ports and analog-digital converters were applied.
153
154 The ECU is controlled by TMS570LS5137ZWT MCU, which is an ARM Cortex R4 based
155 microcontroller developed by Texas Instruments. This MCU contains several
156 protective mechanisms (two cores in lockstep, error correction mechanisms for
157 SRAM and Flash memory, voltage monitoring, etc.) to fulfill the requirements for
158 safety critical applications. See~\cite{rm48xtechnicalreferencemanual2013}
159 for details.
160
161 In order to develop non-trivial applications for the RPP, an operating
162 system is necessary. The RPP is based on FreeRTOS -- an opensource operating
163 system real-time kernel, aimed not only at embedded systems. The FreeRTOS
164 provides an API for creation and managing multiple tasks, scheduler, memory
165 manager, semaphores, queues, mutexes, timers and lots of other features wich can
166 be used in the applications. See~\cite{usingthefreertos2009} for more details.
167
168 Even with the operating system it is quite hard and non-intuitive to
169 control the hardware directly. That is the point when abstraction
170 comes into the play. The RPP software is made of several layers
171 implementing, from the bottom to the top, low-level device drivers,
172 hardware abstraction for common functionality on different hardware
173 and an API which is easy for the use in applications. The operating
174 system and the control software, can be compiled as a library and
175 easily used in any project. More details about the library can be
176 found in Chapter~\ref{chap-c-support-library} and in~\cite{michalhorn2013}.
177
178 Because humans make mistakes and in safety critical applications any mistake can
179 cause damage, looses of money or in the worst case even death of other people,
180 the room for making mistakes has to be as small as possible. An approach called
181 Model-based \cite{modelbasedwiki2013} development has been introduced. In
182 Simulink  the application is developed as a model made of blocks connected
183 together. Every block implements some functionality. For example one block
184 receives a voltage from an analog-digital converter, provides the value as an
185 input to another block which implements some clever algorithm and the product is
186 passed as an input to another block, which sends the value as a CAN message to
187 some other MCU. The final model can be simulated and tested even before the real
188 hardware exists. Finally a C code is generated from the model by a Simulink Code
189 Generator. The code can be compiled by the MCU compatible compiler and
190 downloaded to the MCU Flash memory on the device. Because every block and code
191 generated from the block has to pass a series of tests during their development,
192 the room for making mistakes during the application development has
193 significantly decreased and developers can focus on the functionality instead of
194 the hardware and control software implementation. More information about Code
195 generation can be found in Chapter \ref{chap-simulink-coder-target}. For a
196 reference about Matlab Simulink, Embedded Coder and Simulink Coder,
197 refer to
198 \cite{embeddedcoderreference2013, ebmeddedcoderusersguide2013,
199   simulinkcoderreference2013, targetlanguagecompiler2013,
200   simulinkcoderusersguide2013, simulinkdevelopingsfunctions2013}.
201
202 \section{Software architecture}
203 \label{sec-software-architecture}
204 The basic RPP software, also called the RPP library, is structured
205 into 5 layers, depicted in Figure~\ref{fig-layers}. The architecture
206 design was driven by the following guidelines:
207
208 \begin{compactitem}
209         \item Top-down dependency only. No lower layer depends on anything from
210 upper layers.
211 %       \item 1-1 layer dependency only. The top layer depends
212 % exclusively on the bottom layer, not on any lower level layer (except for a
213 % couple of exceptions).
214         \item Each layer should provide a unified layer interface
215 (\textsc{rpp.h}, \textsc{drv.h}, \textsc {hal.h}, \textsc{sys.h} and
216 \textsc{os.h}), so top layers depends on that layer  interface and not on
217 individual elements from that layer.  \end{compactitem}
218
219 \begin{figure}[H]
220 \begin{center}
221 \noindent
222 \includegraphics[width=250px]{images/layers.pdf}
223 \caption{The RPP library layers.}
224 \label{fig-layers}
225 \end{center}
226 \end{figure}
227
228 As a consequence of this division the source code files and interface files are placed in
229 private directories like \textsc{drv/din.h}. With this organization user
230 applications only needs to include the top layer interface files (for example
231 \textsc{rpp/rpp\_can.h}) to be able to use the selected library API.
232
233 The rest of the section provides basic description of each layer.
234
235 \subsection{Operating System layer}
236 \label{sec-operating-system-layer}
237 This is an operating system interchangeable layer, containing the FreeRTOS
238 source files. The system can be easily replaced by another version thanks to
239 this layer. For example it is possible to compile the library for Linux (using
240 POSIX version of the FreeRTOS), which can be desirable for some testing. The
241 source files can be found in the \textsc{$\langle$rpp\_lib\_root$\rangle$/os}
242 folder.
243
244 The following FreeRTOS versions are distributed:
245 \begin{description}
246         \item[6.0.4\_posix] POSIX version, usable for compilation of the library
247 for Linux system.
248         \item[7.0.2] Prefered version of the FreeRTOS, distributed by
249 Texas Instruments. This version is in use in the current version of the
250 library.
251         \item[7.4.0] Newest version distributed by the Texas Instruments.
252         \item[7.4.2] Newer version available from FreeRTOS pages. Slightly
253 modified to run on RM48 MCU.
254 \end{description}
255
256 \subsection{System Layer} 
257 \label{sec-system-layer}
258 This layer contains system files with data types definitions, clock definitions,
259 interrupts mapping, MCU startup sequence, MCU selftests, and other low level
260 code for controlling some of the MCU peripherals. The source files can be found
261 in \textsc{$\langle$rpp\_lib\_root$\rangle$/rpp/src/sys}, the header files can
262 be found in \textsc{$\langle$rpp\_lib\_root$\rangle$/rpp/include/sys}
263 folder.
264
265 Large part of this layer was generated with the HalCoGen tool. % TODO ref
266
267 \subsection{HAL abstraction layer}
268 \label{sec-hal-abstraction-layer}
269 Hardware Abstraction Layer (HAL) creates an abstraction over the real hardware.
270 For example imagine an IO port with 8 pins. First four pins are connected to the
271 MCU directly to GPIO pins, another four pins are connected to an external
272 integrated circuit, communicating with the MCU via SPI. It would be annoying to
273 have to remember which group is which and to have two sets of control functions
274 for one peripheral. This layer maps every pin of the port to a control function
275 from the System Layer, groups the pins together, names them in a unified style
276 and provides common read, write and configure functions.
277
278 As a result, the higher layers do not have to know anything about the wiring of
279 the peripherals, they can just call read, write or configure function with a pin
280 name as a parameter and the HAL handles all the details.
281
282 The source files can be found in
283 \textsc{$\langle$rpp\_lib\_root$\rangle$/rpp/src/hal} and the header files can
284 be found in \textsc{$\langle$rpp\_lib\_root$\rangle$/rpp/include/hal} folder.
285
286 \subsection{Drivers layer} 
287 \label{sec-drivers-layer}
288 The Drivers layer contains code for controlling the RPP peripherals. The layer
289 benefits from the lower layers thus it is not too low level, but still there are
290 some peripherals like ADC or H-bridge, which needs some special procedure for
291 initialization and running, that would not be very intuitive for the user. For
292 example the H-bridge needs a watchdog reset task to be started before the bridge
293 is enabled.
294
295 The source files can be found in
296 \textsc{$\langle$rpp\_lib\_root$\rangle$/rpp/src/drv} and the header files can
297 be found in \textsc{$\langle$rpp\_lib\_root$\rangle$/rpp/include/drv} folder.
298
299 \subsection{RPP Layer}
300 \label{sec-rpp-layer} 
301 The RPP Layer is the highest layer of the control software. This layer provides
302 an easy to use set of functions for every peripheral and requires only basic
303 knowledge about them. For example, to control the H-bridge,
304 the user can  just call  \textsc{rpp\_hbr\_init()} function to enable the H-bridge
305 and the function calls a sequence of Drivers layer functions to start the
306 Watchdog and configure the peripheral.
307
308 The source files can be found in
309 \textsc{$\langle$rpp\_lib\_root$\rangle$/rpp/src/rpp} and the header files can
310 be found in \textsc{$\langle$rpp\_lib\_root$\rangle$/rpp/include/rpp}.
311
312 \section{Hardware description}
313 \label{sec-hardware-description}
314
315 This section provides reference documentation for the RPP board:
316
317 %%TODO: operating conditions as a reference to the Ti documentation
318
319 \begin{compactitem}
320         \item Layout description.
321         \item Connectors pinout.
322         \item Modules capabilities and features.
323 \end{compactitem}
324
325 The Rapid Prototyping Platform is based on a TMDSRM48HDK development kit developed and distributed by Texas Instruments. The kit is depicted in Figure \ref{fig-board_photo}.
326
327 \begin{figure}[H]\begin{center}
328         \noindent
329         \includegraphics[width=300px]{images/board.png}
330         \caption{The RPP board \cite[p. 8]{rm48hdkusersguide2013}}
331         \label{fig-board_photo}
332 \end{center}\end{figure}
333
334 Only a subset of the peripherals available on the kit is implemented in the control software. A block scheme in Figure \ref{fig-blocks} ilustrates the implemented peripherals and their connection with the MCU, expansion connectors and other components on the development kit.
335
336 \begin{figure}[H]\begin{center}
337         \noindent
338         \includegraphics[width=400px]{images/blocks.png}
339         \caption{The peripherals block scheme.}
340         \label{fig-blocks}
341 \end{center}\end{figure}
342
343 For pinout description of the implemented peripherals refer the RM48HDK User's Guide \cite{rm48hdkusersguide2013}.
344
345 \subsection{Logic IO}
346 \label{sec-logic-io}
347
348 \subsubsection{Digital Inputs and Outputs (DIN and DOUT)}
349 \label{par-digital-inputs-outputs}
350  \begin{compactitem}
351         \item 46 pins available on Expansion connector J11.
352         \item 8 pins available on GIOA
353         \item 8 pins available on GIOB
354         \item 30 pins available on NHET1. Pins NHET1 6 and NHET1 13 are disabled.
355         \item All the pins are configurable as inputs and outputs with different modes:
356          \begin{compactitem}
357                 \item Push/Pull or Open Drain for Output configuration.
358                 \item Pull up, Pull down or tri-stated for Input configuration.
359          \end{compactitem}
360         \item Some of the pins are connected to LEDs or to a button. See Figure \ref{fig-blocks} or refer \cite{rm48hdkusersguide2013} for the connection description.
361  \end{compactitem}
362
363 \subsubsection{Analog Input (ADC)}
364 \label{par-analog-input}
365  \begin{compactitem}
366         \item 16 channels available on the Expansion connector J9.
367         \item Range for 0-5 volts.
368         \item 12 bits resolution.
369         \item Using CPU ADC.
370  \end{compactitem}
371
372 \subsection{Communication}
373 \label{sec-communication}
374 \subsubsection{CAN bus (CAN)}
375 \label{par-can}
376 \begin{compactitem}
377         \item 2 ports available ready for connection to the CAN bus on connector J2 and J3.
378         \item 3 ports available as an interface for external CAN bus drivers on the Expansion connector J11.
379         \item High speed.
380         \item Recover from error.
381         \item Detection of network errors.
382 \end{compactitem}
383
384 \subsubsection{Serial Comm. Interface (SCI)}
385 \label{par-sci}
386 \begin{compactitem}
387         \item 1 port available on connector J7.
388         \item Variable baud rate. Tested on 9600 and 115200.
389         \item RS232 standard compatible.
390 \end{compactitem}
391
392 \section{Document structure}
393 \label{sec-document-structure}
394 The structure of this document is as follows:
395 Chapter~\ref{chap-getting-started} gets you started using the RPP.
396 Chapter~\ref{chap-c-support-library} describes the RPP library.
397 Chapter~\ref{chap-simulink-coder-target} covers the Simulink code
398 generation target and finally Chapter~\ref{chap-rpp-test-software}
399 documents a tool for interactive testing of RPP functionality.
400
401 \chapter{Getting started}
402 \label{chap-getting-started}
403
404 \section{Software requirements}
405 \label{sec-software-requirements}
406 The RPP software stack was developed to be functional on Windows and
407 Linux platforms. The following sections mention the recommended
408 versions of the required software tools/packages.
409
410 \subsection{Linux environment} 
411 \label{sec-linux-environment}
412 \begin{itemize}
413         \item Debian based 64b Linux distribution (Debian 7.0 or Ubuntu 14.4 for
414 example).
415         \item Kernel version 3.11.0-12.
416         \item GCC version 4.8.1
417         \item GtkTerm 0.99.7-rc1
418         \item TI Code Composer Studio 5.5.0.00077
419         \item Matlab 2013b 64b
420         \item Uncrustify 0.59 (optional, see Section \ref{sec-compilation})
421         \item Doxygen 1.8.4 (optional, see Section \ref{sec-compiling-api-documentation})
422         \item Git 1.7.10.4 (optional)
423 \end{itemize}
424
425 \subsection{Windows environment}
426 \label{sec-windows-environment}
427 \begin{itemize}
428         \item Windows 7 Enterprise 64b Service Pack 1.
429         \item Microsoft Windows SDK v7.1
430         \item Bray Terminal v1.9b
431         \item TI Code Composer Studio 5.5.0.00077
432         \item Matlab 2013b 64b
433         \item Doxygen 1.8.4 (optionaly, see Section \ref{sec-compiling-api-documentation}) 
434         \item Uncrustify 0.59 (optionally, see Section \ref{sec-compilation})
435         \item Git 1.9.4.msysgit.2 (optional)
436 \end{itemize}
437
438 \section{Software and tools} 
439 \label{sec-software-and-tools}
440
441 \subsection{TI Code Composer Studio}
442 \label{sec-ti-ccs}
443 Code Composer Studio (CCS) is the official Integrated Development Environment
444 (IDE) for developing applications for Texas Instruments embedded processors. CCS
445 is multiplatform Software based on
446 Eclipse Open Source IDE.
447
448 CCS includes Texas Instruments Code Generation Tools (CGT)
449 \cite{armoptimizingccppcompiler2012, armassemblylanguagetools2012}
450 (compiler, linker, etc). Simulink code generation requires the CGT to be
451 available in the system, and thus, even if no library development
452 will be done or the IDE is not going to be used CCS is still required.
453
454 You can find documentation for CGT compiler in \cite{armoptimizingccppcompiler2012} and
455 for CGT archiver in \cite{armassemblylanguagetools2012}.
456
457 \subsubsection{Installation on Linux} 
458 \label{sec-installation-on-linux}
459 Download CCS for Linux from:
460
461         \begin{quotation}
462 \url{http://processors.wiki.ti.com/index.php/Category:Code\_Composer\_Studio\_v5}
463         \end{quotation}
464
465 Once downloaded, add executable permission to the installation file and launch
466 the installation by executing it. Installation must be done as root in order to
467 install a driver set.
468
469 \lstset{language=bash}
470 \begin{lstlisting}
471 chmod +x ccs_setup_5.5.0.00077.bin
472 sudo ./ccs_setup_5.5.0.00077.bin
473 \end{lstlisting}
474
475 After installation the application can be executed with:
476
477 \lstset{language=bash}
478 \begin{lstlisting}
479 cd <ccs>/ccsv5/eclipse/
480 ./ccstudio
481 \end{lstlisting}
482
483 The first launch on 64bits systems might fail. This can happen because CCS5 is
484 32b application and thus requires 32bits libraries:
485
486 \lstset{language=bash}
487 \begin{lstlisting}
488 sudo apt-get install libgtk2.0-0:i386 libxtst6:i386
489 \end{lstlisting}
490
491 If the application crashes with a segmentation fault edit file:
492
493 \lstset{language=bash}
494 \begin{lstlisting}
495 nano
496 <ccs>/ccsv5/eclipse/plugins/com.ti.ccstudio.branding_<version>/plugin_customization.ini
497 \end{lstlisting}
498
499 And change key \textsc{org.eclipse.ui/showIntro} to false.
500
501 \subsubsection{Installation on Windows}
502 \label{sec-installation-on-windows}
503 The installation for Windows is more straightforward than the previous procedure
504 for Linux.
505
506 Download CCS for Windows from:
507
508         \begin{quotation}
509 \url{http://processors.wiki.ti.com/index.php/Category:Code\_Composer\_Studio\_v5}
510         \end{quotation}
511
512 Once downloaded run the ccs\_setup\_5.5.0.00077.exe and install the CCS.
513
514 \subsubsection{First launch} 
515 \label{sec-first-launch}
516 If another licence is not available, choose ``FREE License -- for use with XDS100
517 JTAG Emulators'' from the licensing options. Code download for the board is using
518 that particular hardware.
519
520 \subsection{Matlab/Simulink}
521 \label{sec-matlab-simulink}
522 Matlab Simulink is a set of tools, runtime environment and development
523 environment for Model-Based \cite{modelbasedwiki2013} applications development,
524 simulations and generation code for target platforms.  Supported Matlab Simulink
525 version is R2013b for 64 bits Linux and Windows.
526
527 \subsection{GtkTerm and Bray Terminal}
528 \label{sec-gtkterm-bray-terminal}
529 Most of the interaction with the board is done through a RS-232 serial
530 connection. The terminal Software used for communication is called GtkTerm for
531 Linux and Bray terminal for Windows.
532
533 To install GtkTerm execute:
534
535 \lstset{language=bash}
536 \begin{lstlisting}
537 sudo apt-get install gtkterm
538 \end{lstlisting}
539
540 The Bray Terminal does not require any installation and the executable file is
541 available at 
542
543 \begin{quotation}
544 \url{https://sites.google.com/site/terminalbpp/}
545 \end{quotation}
546
547 \subsection{C Compiler}
548 \label{sec-c-compiler}
549 In order to be able to compile Matlab Simulink blocks S-functions a C language
550 compiler has to be available on the development system.
551
552 For Linux a GCC 4.8.1 compiler is recommended and can be installed with a
553 command
554
555 \lstset{language=bash}
556 \begin{lstlisting}
557 sudo apt-get install gcc
558 \end{lstlisting}
559
560 For Windows, the C/C++ compiler is a part of Windows SDK, which installation
561 file is available at 
562
563 \begin{quotation}
564 \url{http://www.microsoft.com/en-us/download/details.aspx?id=8279}
565 \end{quotation}
566
567 \section{Code Composer Studio usage}
568 \label{sec-code-composerpstudio-usage}
569
570 \subsection{Opening of existing project}
571 \label{sec-openning-of-existing-project}
572 The project opening procedure is similar to standard Eclipse project opening.
573
574 \begin{enumerate}
575         \item Launch Code Composer Studio
576         \item Select \textsc{File$\rightarrow$Import}
577         \item In the dialog window select \textsc{Code Composer
578 Studio$\rightarrow$Existing CCS Eclipse project} as an import source as depicted
579 in Figure \ref{fig-import-project}.  
580         \item In the next dialog window click on
581 \textsc{Browse} button and find the root directory of the project.
582         \item Select the requested project in the \textsc{Discovered project}
583 section so that the result looks like in Figure \ref{fig-select-project}.  
584         \item Click on \textsc{Finish} button.
585 \end{enumerate}
586
587 \begin{center}
588         \includegraphics[width=350px]{images/import_project.png}
589         \captionof{figure}{Import project dialog}
590         \label{fig-import-project}
591 \end{center}
592
593 \begin{center}
594         \includegraphics[width=350px]{images/select_project.png}
595         \captionof{figure}{Select project dialog}
596         \label{fig-select-project}
597 \end{center}
598
599 \subsection{Creating new project}
600 \label{sec-creating-new-project}
601 In \textsc{\repo/rpp/lib/apps/} there are two RPP based
602 applications, \textsc{helloworld} and \textsc{helloworld\_posix}, that are
603 already configured for the RPP Library. It is advised that new applications use
604 this project as a foundation.
605
606 To create a new application copy this directory and rename it. Now open files
607 \textsc{.project}, \textsc{.cproject} and \textsc{.ccsproject} (if available)
608 and change any occurrence of the work \textsc{helloworld}
609 with the name of your project. Use lower case ASCII letters and underscores only.
610
611 \textbf{Steps to configure a new CCS (ARM, using CGT) RPP application:}
612
613 \begin{compactenum}
614         \item Create a new CCS project. \newline{}
615 \noindent\includegraphics[width=400px]{images/base_1.png}
616         \item Create a normal folder \textsc{include}.
617         \item Create a source folder \textsc{src}.
618         \item Add common \textsc{.gitignore} to the root of that project:
619 \lstset{language=}
620 \begin{lstlisting}
621 Debug
622 Release
623 .settings/*
624 \end{lstlisting}
625 \newpage
626         \item Add new variable \textsc{RPP\_LIB\_ROOT} and point to this
627 repository branch root.\newline{}
628 \noindent\includegraphics[width=400px]{images/base_2.png}
629         \item Add \textsc{rpp-lib.lib} static library to linker libraries and
630 add \textsc{RPP\_LIB\_ROOT} to the library search path.\newline{}
631 \noindent\includegraphics[width=400px]{images/base_3.png}
632 \newpage
633         \item Configure linker to retain \textsc{.intvecs} from RPP static
634 library.\newline{} \noindent\includegraphics[width=350px]{images/base_4.png}
635         \item Configure compiler to include local includes, OS includes for
636 RM48 and RPP includes, in that order.\newline{}
637 \noindent\includegraphics[width=350px]{images/base_5.png}
638 \newpage
639         \item Configure compiler to allow GCC extensions.\newline{}
640 \noindent\includegraphics[width=400px]{images/base_6.png}
641         \item Import and link (\underline{do not copy!}) linker file and board
642 upload descriptor.\newline{}
643 \noindent\includegraphics[width=200px]{images/base_7.png}
644 \end{compactenum}
645
646 \textbf{Steps to configure a new GCC (x86(\_64)) RPP simulated application:}
647
648 \begin{compactenum}
649         \item Create a new managed C project that uses Linux GCC toolchain.
650         \item Create a source folder \textsc{src}. Link all files from original
651 CCS application to this folder.
652         \item Create a normal folder \textsc{include}. Create a folder
653 \textsc{rpp} inside of it.  
654         \item Add common \textsc{.gitignore} to the root of that project:
655 \lstset{language=}
656 \begin{lstlisting}
657 Debug
658 Release
659 .settings/*
660 \end{lstlisting}
661 \newpage
662         \item Add new variable \textsc{RPP\_LIB\_ROOT} and point to this
663 repository branch root.\newline{}
664 \noindent\includegraphics[width=400px]{images/base_posix_1.png}
665         \item Configure compiler to include local includes, CCS application
666 includes, OS includes for POSIX and RPP includes, in that order.\newline{}
667 \noindent\includegraphics[width=400px]{images/base_posix_2.png}
668 \newpage
669         \item Add \textsc{rpp} and \textsc{pthread}to linker libraries and add
670 \textsc{RPP\_LIB\_ROOT} to the library search path.\newline{}
671 \noindent\includegraphics[width=400px]{images/base_posix_3.png}
672 \end{compactenum}
673
674 \textbf{In general any RPP application uses the layout/template:}
675
676 \begin{enumerate}
677         \item Include RPP library header file. You may also include only a
678 selected modules to save space.  \lstset{language=c++}
679 \begin{lstlisting}
680 #include "rpp/rpp.h"
681 \end{lstlisting}
682
683 You may not want to include the whole library to save space and compile time. In
684 this case you may include only those modules, that you want to use. Inclusion
685 selected modules only requires two more
686 header files to be included as well: base.h and, in case sci is used for printing, rpp/sci.h.
687 \begin{lstlisting}
688 #include "rpp/hbr.h" /* We want to use H-bridge */
689 #include <base.h>       /* This is a necessary base header file of the rpp library. */
690 #include "rpp/sci.h" /* This is needed, because we are using rpp_sci_printf in following examples. */
691 \end{lstlisting}
692
693 \newpage
694 \item Create one or as many FreeRTOS task function definitions as required. Those tasks should use
695   functions from this library.
696 \lstset{language=c++}
697 \begin{lstlisting}
698 void my_task(void* p)
699 {
700     static const portTickType freq_ticks = 1000 / portTICK_RATE_MS;
701     portTickType last_wake_time = xTaskGetTickCount();
702     while (TRUE) {
703         /* Wait until next step */
704         vTaskDelayUntil(&last_wake_time, freq_ticks);
705         rpp_sci_printf((const char*)"Hello RPP.\r\n");
706     }
707 }
708 \end{lstlisting}
709
710 \item Create the main function that will:
711  \begin{itemize}
712         \item Initialize the RPP board. If you have included only selected
713 modules in step 1, initialize only those modules by calling their init
714 functions, for
715 example rpp\_hbr\_init\(\).
716         \item Spawn the tasks the application requires. Refer to FreeRTOS API
717 for details.
718         \item Start the FreeRTOS Scheduler. Refer to FreeRTOS API for details.
719         \item Catch if idle task could not be created.
720
721 \lstset{language=c++}
722 \begin{lstlisting}
723 void main(void)
724 {
725     /* In case whole library is included: */
726         /* Initialize RPP board */
727         rpp_init();
728     /* In case only selected modules are included: */
729         /* Initialize HBR */
730             rpp_hbr_init();
731         /* Initialize sci for printf */
732         rpp_sci_init();
733         /* Enable interrups */
734         _enable_IRQ();
735
736     /* Spawn tasks */
737     if (xTaskCreate(my_task, (const signed char*)"my_task",
738             512, NULL, 0, NULL) != pdPASS) {
739         #ifdef DEBUG
740         rpp_sci_printf((const char*)
741             "ERROR: Cannot spawn control task.\r\n"
742         );
743         #endif
744         while (TRUE) { asm(" nop"); }
745     }
746
747     /* Start the FreeRTOS Scheduler */
748     vTaskStartScheduler();
749
750     /* Catch scheduler start error */
751     #ifdef DEBUG
752     rpp_sci_printf((const char*)
753             "ERROR: Problem allocating memory for idle task.\r\n"
754         );
755     #endif
756     while (TRUE) { asm(" nop"); }
757 }
758 \end{lstlisting}
759
760  \end{itemize}
761 \item Create hook functions for FreeRTOS:
762  \begin{itemize}
763  \item \textsc{vApplicationMallocFailedHook()} allows to catch memory allocation
764 errors.
765  \item \textsc{vApplicationStackOverflowHook()} allows to catch if a task
766 overflows it's stack.
767
768 \lstset{language=c++}
769 \begin{lstlisting}
770 #if configUSE_MALLOC_FAILED_HOOK == 1
771 /**
772  * FreeRTOS malloc() failed hook.
773  */
774 void vApplicationMallocFailedHook(void) {
775     #ifdef DEBUG
776     rpp_sci_printf((const char*)
777             "ERROR: manual memory allocation failed.\r\n"
778         );
779     #endif
780 }
781 #endif
782
783
784 #if configCHECK_FOR_STACK_OVERFLOW > 0
785 /**
786  * FreeRTOS stack overflow hook.
787  */
788 void vApplicationStackOverflowHook(xTaskHandle xTask,
789                                    signed portCHAR *pcTaskName) {
790     #ifdef DEBUG
791     rpp_sci_printf((const char*)
792             "ERROR: Stack overflow : \"%s\".\r\n", pcTaskName
793         );
794     #endif
795 }
796 #endif
797 \end{lstlisting}
798
799 \newpage
800  \end{itemize}
801 \end{enumerate}
802
803
804 \subsection{Running the software on the HW}
805 \label{sec-running-software-on-hw}
806 \subsubsection{Code Composer Studio Project}
807 \label{sec-ccs-run-project}
808 When the application is distributed as a CCS project, you have to open the
809 project in the CCS as described in the Section
810 \ref{sec-openning-of-existing-project}. Once the project is opened and built, it
811 can be easily downloaded to the target hardware with the following procedure:
812
813 \begin{enumerate}
814         \item Connect the Texas Instruments XDS100v2 USB emulator to the JTAG
815 port.  
816         \item Connect a USB cable to the XDS100v2 USB emulator and the
817 development computer.
818         \item Plug in the power supply.  
819         \item In the Code Composer Studio click on the
820 \textsc{Run$\rightarrow$Debug}. The project will  be optionaly built and
821 the download process will start. The Code Composer Studio will switch into debug
822 mode, when the download is finished.
823         \item Run the program by clicking on the \textsc{Run} button, with the
824 green arrow.  
825 \end{enumerate}
826
827 \subsubsection{Binary File}
828 \label{sec-binary-file}
829 If the application is distributed as a binary file, without source codes and CCS
830 project files, you can download and run just the binary file by creating a new
831 empty CCS project and configuring the debug session according the following
832 procedure:
833
834 \begin{enumerate}
835         \item In Code Composer Studio click on
836 \textsc{File$\rightarrow$New$\rightarrow$CCS Project}.  
837         \item In the dialog window, type in a project name, for example
838 myBinaryLoad, Select \textsc{Device
839 variant} (ARM, Cortex R, RM48L952, Texas Instruments XDS100v2 USB Emulator)
840 and select project template to \textsc{Empty Project}. The filled dialog should
841 look like on the Figure \ref{fig-new-empty-project}
842         \item Click on the \textsc{Finish} button and new empty project will be
843 created.  
844         \item In the \textsc{Project Explorer} click on the project with a right
845 mouse button and in the context menu select \textsc{Debug
846 as$\rightarrow$Debug configurations}.
847         \item Click on a button \textsc{New launch configuration}
848         \item Rename the New\_configuration, for example to myConfiguration.
849         \item Select configuration target file by clicking the \textsc{File
850 System} button, finding and selecting the TMS5703137.ccxml file. The result
851 should look like on the Figure \ref{fig-debug-conf-main-diag}.  
852         \item On the \textsc{program} pane select the binary file you want to
853 download to the board.
854 Click on the \textsc{File System} button, find and select the binary file.
855 Rpp-test-sw.out for example. The result should look like on the Figure
856 \ref{fig-debug-conf-program-diag}.
857         \item You may also tune the target configuration like in the Section
858 \ref{sec-target-configuration}. 
859         \item Finish the configuration by clicking on the \textsc{Apply} button
860 and download the code by clicking on the \textsc{Debug} button. You can later
861 invoke the download also from the \textsc{Run$\rightarrow$Debug} CCS menu. You
862 may not need to create more Debug configurations and CCS empty project as you
863 can easily change the binary file in the Debug configuration to load different
864 binary file.  
865 \end{enumerate}
866
867 \begin{center}
868         \includegraphics[width=350px]{images/new_empty_project.png}
869         \captionof{figure}{New empty project dialog}
870         \label{fig-new-empty-project}
871 \end{center}
872
873 \begin{center}
874         \includegraphics[width=350px]{images/debug_configuration_main.png}
875         \captionof{figure}{Debug Configuration Main dialog}
876         \label{fig-debug-conf-main-diag}
877 \end{center}
878
879 \subsubsection{Target configuration}
880 \label{sec-target-configuration}
881 Default target configuration erases the whole Flash memory, before downloading
882 the code. This is however not needed in most cases. You may disable this feature
883 by the following procedure: 
884 \begin{enumerate}
885         \item Right click on the project name in the \textsc{Project Browser}
886         \item Select \textsc{Debug as$\rightarrow$Debug Configurations}
887         \item In the dialog window select \textsc{Target} pane.
888         \item In the \textsc{Flash Settings}, \textsc{Erase Options} select
889 \textsc{Necessary sectors only}.
890         \item Save the configuration by clicking on the \textsc{Apply} button
891 and close the dialog.
892 \end{enumerate}
893
894 \begin{center}
895         \includegraphics[width=350px]{images/debug_configuration_program.png}
896         \captionof{figure}{Debug Configuration Program dialog}
897         \label{fig-debug-conf-program-diag}
898 \end{center}
899
900 \section{Matlab Simulink usage}
901 \label{sec-matlab-simulink-usage}
902
903 \subsection{Configuring Simulink for RPP}
904 \label{sec-configuration-simulink-for-rpp}
905 \begin{enumerate}
906 \item Download and install CCS for Linux:
907
908 Details on how to setup CCS are available in Section \ref{sec-ti-ccs}.
909
910 \item Install RPP Target:
911
912 Open Matlab and type on command window:
913
914 \lstset{language=Matlab}
915 \begin{lstlisting}
916 cd <repo>/rpp/rpp/
917 rpp_setup
918 \end{lstlisting}
919
920 This will launch the RPP setup script. This script will ask the user to provide
921 the path to the CCS compiler root directory (the directory where \textsc{armcl}
922 binary is located), normally:
923
924 \begin{verbatim}
925 <ccs>/tools/compiler/arm_5.X.X/
926 \end{verbatim}
927
928 This script will, among other things, ask the user to provide the location of
929 the armcl parent directory, infer and save some relevant CCS paths, add paths to
930 Matlab path and build S-Function
931 blocks for user's architecture (using Matlab's mex command line tool).
932
933 \item Create a new model or load a demo:
934
935 Demos are located on \textsc{\repo/rpp/demo} or you can start a new model and
936 configure target to RPP.  For new models see \htmladdnormallink{Target
937 Reference}{\#target\_reference} section below.
938 \end{enumerate}
939
940
941 \subsection{Working with demo models}
942 \label{sec-openning-demo-models}
943 The demo models are available from the directory \textsc{\repo/rpp/demos}. To
944 access the demo models for reference or for downloading to the RPP board you
945 have to change the directory to the one, containing the desired demo. For
946 example to open the cantransmit demo you have to type these commands into the
947 Matlab command line:
948
949 \begin{lstlisting}[language=Matlab]
950 cd <rpp-simulink-root>/rpp/demos
951 open cantransmit.slx
952 \end{lstlisting}
953
954 The same procedure can be used to open any other models.
955
956 \subsection{Creating a new model}
957 \label{sec-crating-new-model}
958 \begin{enumerate}
959         \item Open or create a model you want to generate code from.  \item Make
960 sure that the model is configured (\textsc{Simulation $\rightarrow$ Model
961 Configuration Parameters}) as described later in this section.
962         \item From Matlab command window change the current directory to where
963 you want your generated code to appear, e.g.:
964 \begin{lstlisting}[language=Matlab]
965 cd /tmp/my-code
966 \end{lstlisting}
967   The code will be generated in a subdirectory of that directory. The name of
968 the subdirectory will be \textsc{<model>\_rpp}, where \textsc{model} is the name
969 of the Simulink model.
970         \item Generate the code by choosing \textsc{Code $\rightarrow$ C/C++
971 Code  $\rightarrow$ Build Model}.  \end{enumerate}
972
973 If you want to run the model on the RPP board, see Section
974 \ref{sec-running-model-on-hw}.
975
976 The new Simulink model needs to be configured in the following way:
977
978 \begin{compactitem}
979 \item Solver (Figure \ref{fig-solver}):
980  \begin{compactitem}
981  \item Options: \emph{Fixed-step, discrete}
982  \item Tasking mode set to \textit{SingleTasking}.
983    \begin{figure}
984      \centering
985      \includegraphics[width=400px]{images/simulink_solver.png}
986      \caption{Solver settings}
987          \label{fig-solver}
988 \end{figure}
989  \end{compactitem}
990 \item Diagnostics $\rightarrow$ Sample Time (Figure~\ref{fig-sample-time-settings}):
991  \begin{compactitem}
992  \item Disable warning source block specifies -1 sampling time. It's ok for the source blocks to run
993    once per tick.
994    \begin{figure}
995      \centering
996      \includegraphics[width=400px]{images/simulink_diagnostics.png}
997      \caption{Sample Time settings}
998          \label{fig-sample-time-settings}
999 \end{figure}
1000 \end{compactitem}
1001 \item Code generation (Figure~\ref{fig-code-gen-settings}):
1002  \begin{compactitem}
1003  \item Set to \textsc{rpp.tlc}.
1004    \begin{figure}
1005      \centering
1006      \includegraphics[width=400px]{images/simulink_code.png}
1007      \caption{Code Generation settings}
1008          \label{fig-code-gen-settings}
1009 \end{figure}
1010 \end{compactitem}
1011 \end{compactitem}
1012
1013
1014 \subsection{Running model on the RPP board}
1015 \label{sec-running-model-on-hw}
1016 To run the model on the target RPP hardware you have to enable the download
1017 feature and build the model by following this procedure: \begin{enumerate}
1018         \item Open the model you want to run (See Section
1019 \ref{sec-openning-demo-models}.)
1020         \item Click on \textsc{Simulation$\rightarrow$Model Configuration
1021 Parameters}.
1022         \item In the \textsc{Code Generation$\rightarrow$RPP Options} pane
1023 check \textsc{Download compiled binary to RPP} checkbox.
1024         \item Click on \textsc{OK} button, connect the target HW to the computer
1025 like in the Section \ref{sec-ccs-run-project} and build the model. If the build
1026 ends with a success, the download process will start and once the downloading is
1027 finished, the application will run immediatelly.
1028 \end{enumerate}
1029
1030 The code downloading is supported for Windows and Linux development systems. If
1031 you are using Linux, you may also try to use the OpenOCD by checking Use OpenOCD
1032 to download the compiled binary checkbox in addition. Refer 
1033
1034 \begin{verbatim}
1035 http://rtime.felk.cvut.cz/hw/index.php/TMS570LS3137#OpenOCD_setup_and_Flashing
1036 \end{verbatim}
1037 fore more information about the OpenOCD configuration.
1038
1039   Note: You should end the Code Composer Studio debug session before
1040   downloading the generated code to the RPP board. Otherwise the
1041   download fails.
1042
1043  
1044 \section{Configuring serial interface}
1045 \label{sec-configuration-serial-interface}
1046 The main interface for communicating with the RPP board is the serial interface.
1047 The application may define its own interface settings, but the following
1048 settings is the default one:
1049
1050 \begin{itemize}
1051         \item Baudrate: 115200
1052         \item Parity: none
1053         \item Bits: 8
1054         \item Stopbits: 1
1055         \item Flow control: none
1056 \end{itemize}
1057
1058 Use GtkTerm in Linux or Bray Terminal for accessing the serial interface. See
1059 Section \ref{sec-hardware-description} for reference about the position of the
1060 serial interface connector on the RPP board.
1061
1062 \section{Bug reporting}
1063 \label{sec-bug-reporting}
1064
1065 Please report any problems at CTU's bug tracking system at
1066 \url{https://redmine.felk.cvut.cz/projects/eaton-rm48}. New users have
1067 to register in the system and notify Michal Sojka about their
1068 registration via $\langle{}sojkam1@fel.cvut.cz\rangle{}$ email
1069 address.
1070
1071 \chapter{C Support Library}
1072 \label{chap-c-support-library}
1073
1074 This chapter describes the implementation of the C support library
1075 (RPP Library), which is used both for Simulink code generation target
1076 and command line testing tool.
1077
1078 \section{Description}
1079 \label{sec-description}
1080 The RPP C Support Library (also called RPP library) defines the API for
1081 working with the board. It includes drivers and an operating system.
1082 The library is
1083 designed from the board user perspective and exposes a simplified high-level API
1084 to handle the board's peripheral modules in a safe manner. The library is
1085 compiled as a static library named \texttt{rpp-lib.lib} and can be found in
1086 \textsc{\repo/rpp/lib}.
1087
1088 The RPP library can be used in any project, where the RPP hardware support is
1089 required and it is also used in two modules, described later in this document. The
1090 Command line testing tool, described in Chapter \ref{chap-rpp-test-software} and
1091 Simulink Coder target, described in Chapter \ref{chap-simulink-coder-target}.
1092
1093 For details about the library architecture, refer to Section
1094 \ref{sec-software-architecture}.
1095
1096 \section{API development guidelines}
1097 \label{sec-api-development-guidlines}
1098
1099 The following are the development guidelines used for developing the RPP API:
1100
1101 \begin{compactitem}
1102         \item User documentation should be placed in header files, not in source
1103 code, and should be Doxygen formatted using autobrief. Documentation for each
1104 function present is mandatory.
1105         \item Function declarations in the headers files is for public functions
1106 only. Do not declare local/static/private functions in the header.
1107         \item Documentation in source code files should be non-doxygen formatted
1108 and intended for developers, not users. Documentation here is optional and at
1109 the discretion of the developer.
1110         \item Always use standard data types for IO when possible. Use custom
1111 structs as very last resort.  \item Use prefix based functions names to avoid
1112 clash. The prefix is of the form \textsc{$\langle$layer$\rangle$\_$\langle$module$\rangle$\_}, for example
1113 \textsc{rpp\_din\_update()} for the update function of the DIN module in the RPP
1114 Layer.  
1115         \item Be very careful about symbol export. Because it is used as a
1116 static library the modules should not export any symbol that is not intended to
1117 be used (function) or \textsc{extern}'ed (variable) from application. As a rule
1118 of thumb declare all global variables as static. 
1119         \item Only the RPP Layer symbols are available to user applications. All
1120 information related to lower layers is hidden for the application. This is
1121 accomplished by the inclusion of the rpp.h or rpp\_\{mnemonic\}.h file on the
1122 implementations files only and never on the interface files. Never expose any
1123 other layer to the application or to the whole system below the RPP layer. In
1124 other words, never \textsc{\#include "foo/foo.h"} in any RPP Layer interface
1125 file. 
1126 \end{compactitem}
1127
1128 \section{Coding style}
1129 \label{sec-coding-style}
1130 In order to keep the code as clean as possible, a unified coding style
1131 should be followed by any contributor to the code. The used coding
1132 style is based on the default configuration of Code Composer Studio
1133 editor. Most notable rule is that the Tab character is 4 spaces.
1134
1135 The RPP library project is prepared for a usage of a program named
1136 Uncrustify. The Uncrustify program checks the code and fixes those
1137 lines that does not match the coding style. However, keep in mind that
1138 the program is not perfect and sometimes some lines can be modified
1139 even when the suggested coding style has been followed. This does not
1140 causes problems as long as the contributor follows the committing
1141 procedure described in next paragraph.
1142
1143 When contributing to the code, the contributor should learn the current coding
1144 style from the existing code. When a new feature is implemented, before
1145 committing to the repository, a command: 
1146
1147 \lstset{language=bash}
1148 \begin{lstlisting}
1149 make uncrustify
1150 \end{lstlisting}
1151 in a Linux terminal should be called. This command fixes any coding style
1152 errors. After that all changes can be committed.
1153
1154 \section{Subdirectory content description}
1155 \label{sec-subdirectory-content-description}
1156 \begin{description}
1157 \item[librpp.a and rpp-lib.lib] static RPP libraries.
1158
1159 The first one is for POSIX simulation, the second one for Simulink models and
1160 other ARM/RM48 applications. This files are placed here by the Makefile, when
1161 the library is built.
1162
1163         \item[apps/] Demo applications related to the RPP library.
1164
1165 This include the CCS studio project for generation of the static library and the
1166 a test suite. The test suit in this directory does not match the test suite
1167 mentioned later in Chapter 5 and those two suits are going to be merged in the
1168 future. Also other demo Hello World like applications are included as a
1169 reference about how to create a RM48 application.
1170         \item[os/] OS layers directory. See OS interchangeable layer for more
1171 information.  
1172         \item[rpp/] Main directory for the RPP Library.
1173         \item[rpp/doc/] Documentation directory for the RPP Library.
1174         \item[rpp/TMS570LS3137.ccxml] Descriptor for code download.
1175
1176 This file is used by all the projects including the Simulink RPP Target for code
1177 download. It is configured to use the Texas Instruments XDS100v2 USB Emulator.
1178         \item[rpp/TMS570LS313xFlashLnk.cmd] CGT Linker command file.
1179
1180 This file is used by all applications linked for the board, including the
1181 Simulink models, static library and test suite. It includes instructions for the
1182 CGT Linker on where to place sections and size of some sections.
1183         \item[rpp/include/\{layer\} and rpp/src/\{layer\}] Interface files and
1184 implementations files for given \textsc{\{layer\}}. See Section
1185 \ref{sec-software-architecture} in Chapter \ref{chap-introduction} for details
1186 on the RPP Layer.  
1187         \item[rpp/include/rpp/rpp.h] Main library header file.
1188
1189 To use this library with all its modules, just include this file and this file
1190 only. Also, before using any library function please call \textsc{rpp\_init()}
1191 function for hardware initialization.
1192
1193         \item[rpp/include/rpp/rpp\_\{mnemonic\}.h] Header file for
1194 \textsc{\{mnemonic\}} module.
1195
1196 This files includes function definitions, pin definitions, etc, specific to
1197 \{mnemonic\} module. See Section \ref{sec-api-development-guidlines}.
1198
1199 You may include only selected rpp\_\{mnemonic\}.h header files and call the
1200 specific rpp\_\{mnemonic\}\_init functions, instead of the rpp.h and rpp\_init
1201 function, if you want to use only a subset of the library functions.
1202
1203         \item[rpp/src/rpp/rpp\_\{mnemonic\}.c] Module implementation.
1204
1205 Implementation of \textsc{rpp\_\{mnemonic\}.h}'s functions on top of the DRV
1206 library. 
1207         \item[rpp/src/rpp/rpp.c] Implementation of library-wide functions.
1208 \end{description}
1209
1210 \section{Compilation}
1211 \label{sec-compilation}
1212
1213 The RPP Library can be compiled as a static library using a Code
1214 Composer Studio project. The compilation process will automatically
1215 update the static library in the library root directory.
1216
1217 For the compilation of the library as a static library open the Code
1218 Composer studio project for the rpp-lib (see
1219 Section~\ref{sec-openning-of-existing-project}) and build the project.
1220 If the build process is successful, the \textsc{rpp-lib.lib} file will
1221 appear in the library root directory.
1222
1223 Because compilation of the libraries in Eclipse IDE can be error
1224 prone, there is a \textsc{Makefile} that allows to compile the
1225 libraries from the Linux or Windows command line:
1226
1227 \begin{lstlisting}[language=bash]
1228 cd <library-root>
1229 make
1230 \end{lstlisting}
1231
1232 On Windows use \texttt{gmake.exe} supplied with CCS instead of
1233 \texttt{make}. The rpp-lib CCS project is configured to invoke this
1234 build procedure from IDE rather than using a building compilation
1235 procedure. One of the results is that the compilation is much faster
1236 this way.
1237
1238 Note that this Makefile still requires the Code Composer Studio (ARM
1239 compiler) to be installed.
1240
1241 The relevant aspects for compiling and linking an application using the static
1242 libraries are: 
1243
1244 \begin{itemize}
1245         \item \textbf{ARM compilation using CCS for the RPP board:}
1246         \begin{compactitem}
1247                 \item Include headers files of the OS for which the library was
1248 compiled against. At the time of this writing the OS is FreeRTOS 7.0.2. See
1249 Section \ref{sec-software-architecture}
1250                 \item Include header files for the RPP library or for modules
1251 you want to use rpp\_can.h for CAN module for example.  
1252                 \item Add library \textsc{rpp-lib.lib} to the linker libraries.
1253 The RPP library \textbf{MUST} be looked for  before Texas Instruments support
1254 library \textsc{rtsv7R4\_T\_be\_v3D16\_eabi.lib}.
1255                 \item Configure linker to retain \textsc{.intvecs} section from
1256 RPP Library:\newline{}
1257 \textsc{--retain="rpp-lib.lib$\langle$sys\_intvecs.obj$\rangle$(.intvecs)"}
1258                 \item Use the provided linker command file
1259 \textsc{TMS570LS313xFlashLnk.cmd}.  
1260         \end{compactitem}
1261         \item \textbf{x86(\_64) compilation using GCC for Simulation:}
1262         \begin{compactitem}
1263                 \item Include headers files of the OS for Simulation. At the
1264 time of this writing the OS is POSIX FreeRTOS 6.0.4.  
1265                 \item Include header files for the RPP library or for modules
1266 you want to use (rpp\_can.h for CAN module for example).  
1267                 \item Add library \textsc{librpp.a} to the linker libraries.
1268                 \item Add \textsc{pthread} to the linker libraries.
1269         \end{compactitem}
1270 \end{itemize}
1271
1272 As an important note, all the models compiled using Simulink will link against
1273 \textsc{rpp-lib.lib}.  When compiling a Simulink model, neither Simulink nor the
1274 \textsc{make} invoked during the build process, will update the generated binary
1275 if the model hasn't changed, and then if the source code hasn't changed. Static
1276 libraries changes are not considered for re-compilation and re-linking. If
1277 library development is being done and static library is updated, in order for
1278 the Simulink model to generate a newly linked version of the binary the whole
1279 code generation folder needs to be deleted in order to force code generation,
1280 compilation and linking with the new static library.
1281
1282 \section{Compiling API documentation}
1283 \label{sec-compiling-api-documentation}
1284 The RPP Layer is formatted using Doxygen documentation generator. This allows to
1285 generate a high quality API reference. To generate the API reference run in a
1286 Linux terminal:
1287
1288 \lstset{language=bash}
1289 \begin{lstlisting}
1290 cd <repo>/rpp/doc/api
1291 make
1292 xdg-open html/index.html
1293 \end{lstlisting}
1294
1295 The files under \textsc{\repo/rpp/lib/rpp/doc/api/content} are used for the API
1296 reference generation are their name is self-explanatory:
1297
1298 \begin{verbatim}
1299 blocks_map.html
1300 blocks.png
1301 cvut.png
1302 footer.html
1303 main_page.dox
1304 \end{verbatim}
1305
1306 \chapter{Simulink Coder Target}
1307 \label{chap-simulink-coder-target}
1308
1309 The Simulink Coder Target allows to convert Simulink models to C code,
1310 compile it and download to the board.
1311
1312 \section{Introduction}
1313 \label{sec-introduction}
1314
1315 The Simulink RPP Target provides support for C source code generation from Simulink models and
1316 compilation of that code on top of the RPP library and the FreeRTOS operating system. This target
1317 uses Texas Instruments ARM compiler (\textsc{armcl}) included in the Code Generation Tools distributed with
1318 Code Composer Studio, and thus it depends on it for proper functioning.
1319
1320 This target also provides support for automatic download of the compiled binary to the RPP
1321 board.
1322
1323 \begin{figure}[H]\begin{center}
1324 \noindent
1325 \includegraphics[width=300px]{images/tlc_process.png}
1326 \caption{TLC code generation process. \cite[p. 1-6]{targetlanguagecompiler2013}}
1327 \end{center}\end{figure}
1328
1329 \section{Features and limitations}
1330 \label{sec-features}
1331
1332 \begin{itemize}
1333 \item Sampling frequencies up to 1\,kHz.
1334 \item Supports only single-tasking and single-rate systems. Support
1335   for single-rate systems will be available in the final version.
1336   Support for multitasking system will require careful audit of the
1337   RPP library with respect to thread-safe code.
1338 \item No External mode support yet. We work on it.
1339 \item Custom compiler options, available via OPTS variable in
1340   \emph{Make command} at \emph{Code Generation} tab (see Figure
1341   \ref{fig-code-gen-settings}). For example \textsc{make\_rtw
1342     OPTS="-O0 -g"}.
1343 \end{itemize}
1344
1345 \section{RPP Options pane}
1346 \label{sec-rpp-target-options}
1347
1348 The RPP Target includes the following configuration options, all of them
1349 configurable per model under  \textsc{Code Generation} \noindent$\rightarrow$
1350 \textsc{RPP Options}:
1351
1352 \begin{itemize}
1353 \item \textbf{C system stack size}: this parameter is passed directly
1354   to the linker for the allocation of the stack. Note that this stack
1355   is used only for initializing the application and FreeRTOS. Once
1356   everything is initialized, another stack is used by the generated
1357   code. See below. Default value is 4096.
1358
1359 \item \textbf{C system heap size}:
1360   \label{sec-rpp-target-options-heap-size} this parameter is passed
1361   directly to the linker for the allocation of the heap. Currently,
1362   the heap is not used, but will be used by the external mode in the future.
1363 Note that FreeRTOS uses its own heap whose size is independent of this
1364 parameter. 
1365 \item \textbf{Model step task stack size}: this parameter will be
1366 passed to the \textsc{xTaskCreate()} that
1367   creates the task for the model to run. In a Simulink model there are always two tasks:
1368  \begin{itemize}
1369  \item The worker task. This task is the one that executes the model
1370    step. This task requires enough stack memory to execute the step.
1371    If your model does not run, it might be caused by too small stack.
1372    The memory needed for the stack depends on the size and structure
1373    of the model.
1374  \item The control task. This task controls when the worker task should execute and controls overruns.
1375
1376  \end{itemize}
1377 \item \textbf{Download compiled binary to RPP}: if set, this option will download the generated binary to
1378   the board after the model is successfully built. Note that this option is unaware of the option
1379   \textit{Generate code only} in the \textit{Code Generation} options panel, so it will try to download even if
1380   only source code has been generated, failing graciously or uploading an old binary laying around
1381   in the build directory. This option calls the \textsc{rpp\_download.m} script, which is in turn a
1382   wrapper on the \textsc{loadti.sh}, \textsc{loadti.bat} and \textsc{loadopenocd.sh} script. More information on the \textsc{loadti.sh}
1383   script can be found in:
1384 \begin{verbatim}
1385 <css>/ccs_base/scripting/examples/loadti/readme.txt
1386 http://processors.wiki.ti.com/index.php/Loadti
1387 \end{verbatim}
1388
1389   The \textsc{loadti.sh} and\textsc{loadti.bat} script will close after the
1390 download of the generated program, leaving the loaded program running.
1391
1392   The \textsc{loadopenocd.sh} script will close after the download of the
1393 generated program as well, but the program will be stopped.  In order to test
1394 the loaded program a manual reset of the board is required.
1395
1396 \item \textbf{Download compiled binary to SDRAM}: This feature is not yet
1397 implemented for the simulink target.
1398
1399 \item \textbf{Use OpenOCD to download the compiled binary}: This option switches
1400 from Ti loading script \textsc{loadti.sh} to OpenOCD script
1401 \textsc{loadopenocd.sh}. The benefit of using OpenOCD, besides that it is open
1402 source
1403   software, is much shorter loading time. More information about the right
1404 OpenOCD version and its installation can be found at:
1405 \begin{verbatim}
1406 http://rtime.felk.cvut.cz/hw/index.php/TMS570LS3137#OpenOCD_setup_and_Flashing
1407 \end{verbatim}
1408 This feature is available for Linux system only.
1409
1410 \item \textbf{Print model metadata to SCI at start}: if set this option will
1411 print a message to the Serial Communication Interface when the model start
1412 execution on the board. This is very helpful to identify the model running on
1413 the board. The message is in the form: 
1414
1415 \begin{verbatim}
1416 `model_name' - generated_date (TLC tlc_version)
1417 \end{verbatim}
1418
1419   For example:
1420 \begin{verbatim}
1421 `hbridge_analog_control' - Wed Jun 19 14:10:44 2013 (TLC 8.3 (Jul 20 2012))
1422 \end{verbatim}
1423 \end{itemize}
1424
1425 \section{Subdirectory  content description}
1426 \label{sec-subdirectory-content-description}
1427 This section describes the directories of the Simulink Coder. If you are
1428 interested in particular file, refer the description at the beginning of the
1429 file.
1430
1431 \begin{description}
1432         \item[doc/] Contains the sources of the documentation, you are now
1433 reading.  
1434         \item[refs/] Contains third party references, which license allows the
1435 distribution.
1436         \item[rpp/blocks] Contains the TLC files, which defines the blocks for
1437 the Matlab Simulink and \textsc{rpp\_lib.slx}, which is the Simulink RPP
1438 Library, containing all the Simulink blocks for RPP.
1439         \item[rpp/blocks/tlc\_c]Contains the templates for C code generation from the
1440 Matlab Simulink model.
1441         \item[rpp/demos] Contains demo models, which purpose is to serve as a
1442 reference for the usage and for testing.  
1443         \item[rpp/lib] Contains the C Support Library. See Chapter
1444 \ref{chap-c-support-library}.  \item[rpp/loadopenocd] Contains download scripts
1445 for Linux support of the OpenOCD, for code downloading to the target.
1446         \item[rpp/loadti] Contains download scripts for Linux and Windows
1447 support for code downloading to the target, using Texas Instruments CCS code
1448 downloader.  
1449         \item[rpp/rpp] Contains set of support script for the Code Generator.
1450 \end{description}
1451
1452 \section{Block Library Overview}
1453 \label{sec-block-library-overview}
1454 The Simulink Block Library is a set of blocks that allows Simulink models to use
1455 board IO and communication peripherals. The available blocks are summarized in
1456 Table~\ref{tab:block-lib-status} and more detailed description is
1457 given in Section~\ref{sec-blocks-description}.
1458
1459 \begin{table}
1460 \begin{center}\begin{tabular}{|lp{5cm}lll|}
1461 \hline
1462 \textbf{Category} & \textbf{Name} & \textbf{Status} & \textbf{Mnemonic} & \textbf{Header} \\
1463 \hline
1464 \input{block_table.tex}
1465 \hline
1466 \end{tabular}\end{center}
1467
1468   \caption{Block library overview}
1469   \label{tab:block-lib-status}
1470 \end{table}
1471
1472 \label{sec-blocks-implementation}
1473 All of the blocks are implemented as manually created C Mex S-Function . In this section the 
1474 approach taken is briefly explained.
1475
1476 \subsection{C MEX S-Functions}
1477 \label{sec-c-mex-functions}
1478  \begin{compactitem}
1479  \item C : Implemented in C language. Other options are Fortran and Matlab language itself.
1480  \item MEX: Matlab Executable. They are compiled by Matlab - C compiler wrapper called MEX.
1481  \item S-Function: System Function, as opposed to standard functions, or user functions.
1482  \end{compactitem}
1483
1484 A C-MEX S-Function is a structured C file that implements some mandatory and
1485 optional  callbacks for a specification of a number of inputs, outputs, data
1486 types, parameters, rate, validity checking, etc.  A complete list of callbacks
1487 can be found in:
1488         \begin{quotation}
1489 \htmladdnormallink{http://www.mathworks.com/help/simulink/create-cc-s-functions.html}{http://www.mathworks.com/help/simulink/create-cc-s-functions.html}
1490 \end{quotation}
1491
1492 The way a C-MEX S-Function participates in a Simulink simulation is shown on the
1493 diagram \ref{fig-sfunctions-process}:
1494
1495 \begin{figure}[H]\begin{center}
1496 \noindent
1497 \includegraphics[width=250px]{images/sfunctions_process.png}
1498 \caption{Simulation cycle of a S-Function. \cite[p. 57]{simulinkdevelopingsfunctions2013}}
1499 \label{fig-sfunctions-process}
1500 \end{center}\end{figure}
1501
1502 In general, the S-Function can perform calculations, inputs and outputs for simulation. Because 
1503 the RPP blocks are for hardware peripherals control and IO the blocks are 
1504 implemented as pure sink or pure source, the S-Function is just a descriptor of
1505 the block and does not perform any calculation and does not provide any input or
1506 output for simulations. 
1507
1508 The implementation of the S-Functions in the RPP project has following layout:
1509
1510 \begin{itemize}
1511   \item Define S-Function name \textsc{S\_FUNCTION\_NAME}.
1512   \item Include header file \textsc{header.c}, which in connection with
1513 \textsc{trailer.c} creates a miniframework for writing S-Functions.  
1514   \item In \textsc{mdlInitializeSizes} define:
1515   \begin{itemize}
1516         \item Number of \textit{dialog} parameter.
1517         \item Number of input ports.
1518         \begin{compactitem}
1519                 \item Data type of each input port.
1520         \end{compactitem}
1521         \item Number of output ports.
1522         \begin{compactitem}
1523                 \item Data type of each output port.
1524         \end{compactitem}
1525         \item Standard options for driver blocks.
1526   \end{itemize}
1527   \item In \textsc{mdlCheckParameters}:
1528   \begin{itemize}
1529         \item Check data type of each parameter.
1530         \item Check range, if applicable, of each parameter.
1531   \end{itemize}
1532   \item In \textsc{mdlSetWorkWidths}:
1533   \begin{compactitem}
1534         \item Map \textit{dialog} parameter to \textit{runtime} parameters.
1535         \begin{itemize}
1536                 \item Data type of each \textit{runtime} parameter.
1537         \end{itemize}
1538   \end{compactitem}
1539   \item Define symbols for unused functions.
1540   \item Include trailer file \textsc{trailer.c}.
1541 \end{itemize}
1542
1543 The C-MEX S-Function implemented can be compiled with the following command:
1544
1545 \lstset{language=bash}
1546 \begin{lstlisting}
1547 <matlabroot>/bin/mex sfunction_{mnemonic}.c
1548 \end{lstlisting}
1549
1550 As noted the standard is to always prefix S-Function with \textsc{sfunction\_}
1551 and use lower case mnemonic of the block.
1552
1553 Also a script called \textsc{compile\_blocks.m} is included. The script that
1554 allows all \textsc{sfunctions\_*.c} to be fed to the \textsc{mex} compiler so
1555 all S-Functions are compiled at once. To use this script, in Matlab do:
1556
1557 \lstset{language=Matlab}
1558 \begin{lstlisting}
1559 cd <repo>/rpp/blocks/
1560 compile_blocks()
1561 \end{lstlisting}
1562
1563 \subsection{Target Language Compiler files}
1564 \label{sec-target-language-compiler-files}
1565
1566 In order to generate code for each one of the S-Functions, every S-Function implements a TLC file
1567 for \textit{inlining} the S-Function on the generated code. The TLC files describe how to 
1568 generate code for a specific C-MEX S-Function block. They are programmed using TLC own language and 
1569 include C code within TLC instructions, just like LaTeX files include normal text in between LaTeX 
1570 macros.
1571
1572 The standard for a TLC file is to be located under the \textsc{tlc\_c} subfolder from where the 
1573 S-Function is located and to use the very exact file name as the S-Function but with the \textsc{.tlc}
1574 extension: \textsc{sfunction\_foo.c} \noindent$\rightarrow$ \textsc{tlc\_c/sfunction\_foo.tlc}
1575
1576 The TLC files implemented for this project use 3 hook functions in particular (other are available, 
1577 see TLC reference documentation):
1578 \begin{itemize}
1579 \item \textsc{BlockTypeSetup}: \newline{}
1580   BlockTypeSetup executes once per block type before code generation begins.
1581   This function can be used to include elements required by this block type, like includes or
1582   definitions.
1583 \item \textsc{Start}: \newline{}
1584   Code here will be placed in the \textsc{void
1585 $\langle$modelname$\rangle$\_initialize(void)}. Code placed here will execute
1586 only once.
1587 \item \textsc{Outputs}: \newline{}
1588   Code here will be placed in the \textsc{void
1589 $\langle$modelname$\rangle$\_step(void)} function. Should be used to get the
1590 inputs o a block and/or to set the outputs of that block.
1591 \end{itemize}
1592
1593 The general layout of the TLC files implemented for this project are:
1594 \begin{itemize}
1595 \item In \textsc{BlockTypeSetup}: \newline{}
1596   Call common function \textsc{\%$<$RppCommonBlockTypeSetup(block, system)$>$} that will include the 
1597   \textsc{rpp/rpp\i\_mnemonic.h} header file (can be called multiple times but header is included only once).
1598 \item \textsc{Start}: \newline{}
1599   Call setup routines from RPP Layer for the specific block type, like HBR enable, DIN pin setup, 
1600   DAC value initialization, SCI baud rate setup, among others.
1601 \item \textsc{Outputs}: \newline{}
1602   Call common IO routines from RPP Layer, like DIN read, DAC set, etc. Success of this functions
1603   is checked and in case of failure error is reported to the block using ErrFlag.
1604 \end{itemize}
1605
1606 C code generated from a Simulink model is placed on a file called
1607 \textsc{$\langle$modelname$\rangle$.c} along with other support files in a
1608 folder called \textsc{$\langle$modelname$\rangle$\_$\langle$target$\rangle$/}.
1609 For example, the source code generated for model \textsc{foobar} will be placed
1610 in current Matlab directory \textsc{foobar\_rpp/foobar.c}.
1611
1612 The file \textsc{$\langle$modelname$\rangle$.c} has 3 main functions:
1613 \begin{compactitem}
1614 \item \textsc{void $\langle$modelname$\rangle$\_step(void)}: \newline{}
1615   This function recalculates all the outputs of the blocks and should be called once per step. This
1616   is the main working function.
1617 \item \textsc{void $\langle$modelname$\rangle$\_initialize(void)}: \newline{}
1618   This function is called only once before the first step is issued. Default values for blocks IOs
1619   should be placed here.
1620 \item \textsc{void $\langle$modelname$\rangle$\_terminate(void)}: \newline{}
1621   This function is called when terminating the model. This should be used to free memory of revert 
1622   other operations made on the initialization function. With current implementation this function
1623   should never be called unless an error is detected and in most models it is empty.
1624 \end{compactitem}
1625
1626 \section{Block reference}
1627 \label{sec-blocks-description}
1628
1629 This section describes each one of the Simulink blocks present in the Simulink
1630 RPP block library, shown in Figure \ref{fig-block-library}.
1631
1632 \begin{figure}[h]
1633   \begin{center}
1634     \includegraphics[width=\textwidth]{images/block_library.png}
1635   \end{center}
1636 \caption{Simulink RPP Block Library.}
1637 \label{fig-block-library}
1638 \end{figure}
1639 \clearpage
1640 \input{block_desc.tex}
1641
1642 \section{Demos}
1643 The Simulink RPP Demo Library is a set of Simulink models that use blocks from
1644 the Simulink RPP Block Library and generates code using the Simulink RPP Target.
1645
1646 This demos library is used as a test suite for the Simulink RPP Block Library
1647 but they are also intended to show basic programs built using it. Because of
1648 this, the demos try to use more than one
1649 type of block and more than one block per block type.
1650
1651 In the reference below you can find a complete description for each of the demos.
1652
1653 \subsection{ADC demo}
1654 \begin{figure}[H]\begin{center}
1655 \noindent
1656 \includegraphics[width=450px]{images/demo_adc.png}
1657 \caption{Example of the usage of the Analog Input blocks for RPP.}
1658 \end{center}\end{figure}
1659
1660 \textbf{Description:}
1661
1662 Demostrates how to use Analog Input blocks in order to measure voltage. This demo
1663 measures voltage on every available Analog Input and prints the values on the
1664 Serial Interface.
1665
1666 \subsection{Simple CAN demo}
1667 \begin{figure}[H]\begin{center}
1668 \noindent
1669 \includegraphics[width=450px]{images/demo_simple_can.png}
1670 \caption{The simplest CAN demonstration.}
1671 \end{center}\end{figure}
1672
1673 \textbf{Description:}
1674
1675 The simplest possible usage of the CAN bus. This demo is above all designed for
1676 testing the CAN configuration and transmission.
1677
1678 \subsection{CAN transmit}
1679 \begin{figure}[H]\begin{center}
1680 \noindent
1681 \includegraphics[width=450px]{images/demo_cantransmit.png}
1682 \caption{Example of the usage of the CAN blocks for RPP.}
1683 \end{center}\end{figure}
1684
1685 \textbf{Description:}
1686
1687 Demostrates how to use CAN Transmit blocks in order to:
1688
1689 \begin{compactenum}
1690 \item Send unpacked data with data type uint8, uint16 and uint32.
1691 \item Send single and multiple signals packed into CAN\_MESSAGE by CAN Pack block.
1692 \item Send a message as extended frame type to be received by CAN Receive
1693 configured to receive both, standard and extended frame types.
1694 \end{compactenum}
1695
1696 Demostrates how to use CAN Receive blocks in order to:
1697
1698 \begin{compactenum}
1699 \item Receive unpacked data of data types uint8, uint16 and uint32.
1700 \item Receive and unpack received CAN\_MESSAGE by CAN Unpack block.
1701 \item Configure CAN Receive block to receive Standard, Extended and both frame types.
1702 \item Use function-call mechanism to process received messages
1703 \end{compactenum}
1704
1705 \subsection{Simulink Demo model}
1706 \begin{figure}[H]\begin{center}
1707 \noindent
1708 \includegraphics[width=450px]{images/demo_board.png}
1709 \caption{Model of the complex demonstration of the boards peripherals.}
1710 \end{center}\end{figure}
1711
1712 \textbf{Description:}
1713
1714 This model demonstrates the usage of RPP Simulink blocks in a complex and interactive
1715 application. The Ti HDK kit has eight LEDs placed around the MCU. The application
1716 rotates the light around the MCU in one direction. Every time the user presses the button
1717 on the HDK, the direction is switched.
1718
1719 The state of the LEDs is sent on the CAN bus as a message with ID 0x1. The button can
1720 be emulated by CAN messages with ID 0x0. The message 0x00000000 simulates button release
1721 and the message 0xFFFFFFFF simulates the button press.
1722
1723 Information about the state of the application are printed on the Serial Interface. 
1724
1725 \subsection{Echo char}
1726 \begin{figure}[H]\begin{center}
1727 \noindent
1728 \includegraphics[width=450px]{images/demo_echo_char.png}
1729 \caption{Echo Character Simulink demo for RPP.}
1730 \end{center}\end{figure}
1731
1732 \textbf{Description:}
1733
1734 This demo will echo (print back) any character received through the Serial Communication
1735 Interface (115200-8-N-1).
1736
1737 Note that the send subsystem is implemented a as \textit{triggered} subsystem and will execute only
1738 if data is received, that is, Serial Receive output is non-negative. Negative values are errors.
1739
1740 \subsection{GIO demo}
1741 \begin{figure}[H]\begin{center}
1742 \noindent
1743 \includegraphics[width=450px]{images/demo_gio.png}
1744 \caption{Demonstration of DIN and DOUT blocks}
1745 \end{center}\end{figure}
1746
1747 \textbf{Description:}
1748
1749 The model demonstrates how to use the DIN blocks and DOUT blocks, configured in every mode. The DOUTs
1750 are pusched high and low with period 1 second. The DINs are reading inputs and printing the values
1751 on the Serial Interface with the same period.
1752
1753 \subsection{Hello world}
1754 \begin{figure}[H]\begin{center}
1755 \noindent
1756 \includegraphics[width=450px]{images/demo_hello_world.png}
1757 \caption{Hello World Simulink demo for RPP.}
1758 \end{center}\end{figure}
1759
1760 \textbf{Description:}
1761
1762 This demo will print \textsc{"Hello Simulink"} to the Serial Communication Interface (115200-8-N-1) one
1763 character per second. The output speed is driven by the Simulink model step which is set to one
1764 second.
1765
1766 \chapter{Command line testing tool}
1767 \label{chap-rpp-test-software}
1768 The \textsc{rpp-test-suite} is a RPP application developed testing and direct
1769 control of the RPP hardware. The test suite implements a command processor,
1770 which is listening for a commands and prints some output related to the commands
1771 on the serial interface. The command processor is modular and each peripheral
1772 has its commands in a separated module.
1773
1774 The command processor is implemented in <rpp-test-sw>/cmdproc and commands
1775 modules are implemented in <rpp-test-sw>/commands directory.
1776
1777 The application enables a command processor using the SCI at
1778 \textbf{115200-8-N-1}. When the software starts, the received welcome message
1779 and prompt should look like:
1780
1781 \begin{verbatim}
1782 TODO: FILL
1783 \end{verbatim}
1784
1785 Type in command help for a complete list of available command, or help command
1786 for a description of concrete command.
1787
1788 \section{Command description}
1789
1790 This section contains the description of the available commands. The
1791 same description is also available in the program itself via the
1792 \texttt{help} command.
1793
1794 \input{rpp-test-sw-cmds.tex}
1795
1796 \chapter{Glossary}
1797
1798 \begin{description}
1799 \item[ADC]
1800   \textit{Analog to Digital Converter.} \newline{}
1801   Hardware circuitry that converts a continuous physical quantity (usually voltage) to a
1802   digital number that represents the quantity's amplitude.
1803
1804 \item[AIN]
1805   \textit{Analog Input.} \newline{}
1806   Mnemonic to refer to or something related to the analog input (ADC) hardware module.
1807
1808 \item[AOUT]
1809   \textit{Analog Output.} \newline{}
1810   Mnemonic to refer to or something related to the analog output (DAC) hardware module.
1811
1812 \item[CAN]
1813   \textit{Controller Area Network.} \newline{}
1814   The CAN Bus is a vehicle bus standard designed to allow microcontrollers and devices to
1815   communicate with each other within a vehicle without a host computer.
1816   In this project it is also used as mnemonic to refer to or something related to the CAN
1817   hardware module.
1818
1819 \item[CGT]
1820   \textit{Code Generation Tools.} \newline{}
1821   Name given to the tool set produced by Texas Instruments used to compile, link, optimize,
1822   assemble, archive, among others. In this project is normally used as synonym for
1823   ``Texas Instruments ARM compiler and linker."
1824
1825 \item[DAC]
1826   \textit{Digital to Analog Converter.} \newline{}
1827   Hardware circuitry that converts a digital (usually binary) code to an analog signal
1828   (current, voltage, or electric charge).
1829
1830 \item[DIN]
1831   \textit{Digital Input.} \newline{}
1832   Mnemonic to refer to or something related to the digital input hardware module.
1833
1834 \item[ECU]
1835   \textit{Engine Control Unit.} \newline{}
1836   A type of electronic control unit that controls a series of actuators on an internal combustion
1837   engine to ensure the optimum running.
1838
1839 \item[ETH]
1840   \textit{Ethernet.} \newline{}
1841   Mnemonic to refer to or something related to the Ethernet hardware module.
1842
1843 \item[FR]
1844   \textit{FlexRay.} \newline{}
1845   FlexRay is an automotive network communications protocol developed to govern on-board automotive
1846   computing.
1847   In this project it is also used as mnemonic to refer to or something related to the FlexRay
1848   hardware module.
1849
1850 \item[GPIO]
1851   \textit{General Purpose Input/Output.} \newline{}
1852   Generic pin on a chip whose behavior (including whether it is an input or output pin) can be
1853   controlled (programmed) by the user at run time.
1854
1855 \item[HBR]
1856   \textit{H-Bridge.} \newline{}
1857   Mnemonic to refer to or something related to the H-Bridge hardware module. A H-Bridge is
1858   an electronic circuit that enables a voltage to be applied across a load in either direction.
1859
1860 \item[HOUT]
1861   \textit{High-Power Output.} \newline{}
1862   Mnemonic to refer to or something related to the 10A, PWM, with current sensing, high-power
1863   output hardware module.
1864
1865 \item[IDE]
1866   \textit{Integrated Development Environment.} \newline{}
1867   An IDE is a Software application that provides comprehensive facilities to computer programmers
1868   for software development.
1869
1870 \item[LCT]
1871   \textit{Legacy Code Tool.} \newline{}
1872   Matlab tool that allows to generate source code for S-Functions given the descriptor of a C 
1873   function call.
1874
1875 \item[LIN]
1876   \textit{Local Interconnect Network.} \newline{}
1877   The LIN is a serial network protocol used for communication between components in vehicles.
1878   In this project it is also used as mnemonic to refer to or something related to the LIN
1879   hardware module.
1880
1881 \item[LOUT]
1882   \textit{Logic Output.} \newline{}
1883   Mnemonic to refer to or something related to the digital output hardware module.
1884   It is logic output (100mA), as opposed to power outputs (2A, 10A).
1885
1886 \item[MBD]
1887   \textit{Model-Based Design.} \newline{}
1888   Model-Based Design (MBD) is a mathematical and visual method of addressing problems associated
1889   with designing complex control, signal processing and communication systems. \cite{modelbasedwiki2013}
1890
1891 \item[MEX]
1892   \textit{Matlab Executable.} \newline{}
1893   Type of binary executable that can be called within Matlab. In this document the common term
1894   used is `C MEX S-Function", which means Matlab executable written in C that implements a system
1895   function.
1896
1897 \item[MOUT]
1898   \textit{(Motor) Power Output.} \newline{}
1899   Mnemonic to refer to or something related to the 2A push/pull power output hardware module.
1900
1901 \item[PWM]
1902   \textit{Pulse-width modulation.} \newline{}
1903   Technique for getting analog results with digital means. Digital control is used to create a
1904   square wave, a signal switched between on and off. This on-off pattern can simulate voltages
1905   in between full on and off by changing the portion of the time the signal spends on versus
1906   the time that the signal spends off. The duration of ``on time" is called the pulse width or
1907   \textit{duty cycle}.
1908
1909 \item[RPP]
1910   \textit{Rapid Prototyping Platform.} \newline{}
1911   Name of the automotive hardware board. Also generic term to define something related
1912   to the board, like the RPP Library, RPP Layer, RPP API, etc.
1913
1914 \item[SCI]
1915   \textit{Serial Communication Interface.} \newline{}
1916   Serial Interface for communication through hardware's UART using communication standard RS-232.
1917   In this project it is also used as mnemonic to refer to or something related to the Serial
1918   Communication Interface hardware module.
1919
1920 \item[SDC]
1921   \textit{SD-Card.} \newline{}
1922   Mnemonic to refer to or something related to the SD-Card hardware module.
1923
1924 \item[SDR]
1925   \textit{SD-RAM.} \newline{}
1926   Mnemonic to refer to or something related to the SD-RAM hardware module for logging.
1927
1928 \item[TLC]
1929   \textit{Target Language Compiler.} \newline{}
1930   Technology and language used to generate code in Matlab/Simulink.
1931
1932 \item[UART]
1933   \textit{Universal Asynchronous Receiver/Transmitter.} \newline{}
1934   Hardware circuitry that translates data between parallel and serial forms.
1935 \end{description}
1936
1937 \bibliography{rpp_simulink}
1938 \bibliographystyle{plain}
1939
1940 \end{document}
1941
1942 %  LocalWords:  FreeRTOS RPP POSIX