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