\usepackage[bottom]{footmisc} % footnotes
\usepackage{todonotes}
\usepackage[backend=biber,style=alphabetic,sortcites=true]{biblatex}
+\usepackage{tabularx}
+\usepackage{textcomp}
\addbibresource{rpp_simulink.bib}
% header
% Prettify code documentation
\usepackage{color}
+\usepackage{colortbl}
+% \usepackage[table]{xcolor}
+
\definecolor{gray97}{gray}{.97}
\definecolor{gray75}{gray}{.75}
\definecolor{gray45}{gray}{.45}
\newcommand{\superscript}[1]{\ensuremath{^{\textrm{\small#1}}}}
\newcommand{\subscript}[1]{\ensuremath{_{\textrm{\small#1}}}}
+% Supported targets - to be used with \ifx\tgtId\tgtIdXXX
+\def\tgtIdTMSHDK{tms570\_hdk}
+\def\tgtIdRMHDK{rm48\_hdk}
+\def\tgtIdTMSRPP{tms570\_rpp}
+\def\tgtIdHydCtr{tms570\_hydctr}
+
+% Include target specific macros etc.
+\input{target_def}
+
\begin{document}
% Title
\HRule
\vspace{0.4cm}
{\huge \bfseries Simulink code generation target for Texas~Instruments
- RM48 platform\par}
+ \tgname{} platform\par}
+\vspace{0.8cm}
+{\Large Version for \tgtBoardName{} board\par}
\vspace{0.4cm}
\HRule \\[1.5cm]
\end{titlepage}
% Title end
+\section*{Revision history}
+
+\noindent\begin{tabularx}{\linewidth}{|l|l|l|X|}
+ \rowcolor[gray]{0.9}\hline
+ Revision & Date & Author(s) & Comments \\ \hline
+
+ 0.1 beta & 2014-12-04 & Sojka, Horn & Initial version \\ \hline
+
+ 0.2 & 2015-02-16 & Sojka, Horn & Improvements, clarifications,
+ cleanup \\ \hline
+
+ 0.3 & 2015-03-31 & Sojka, Horn & Added sections
+ \ref{sec-changing-os}, \ref{sec:adding-new-funct} and
+ \ref{sec:mult-single-thre}. Minor
+ updates. \\ \hline
+
+ 0.4 & 2015-04-30 & Sojka, Horn & Added support for TMS570 HDK
+ platform. All RPP software
+ supports multiple
+ platforms by
+ recompilation. \\ \hline
+
+ 0.5 beta & 2015-07-03 & Sojka & Updated section \ref{sec:adding-new-funct}.
+ Added support for Eaton Hydraulics
+ Controller board (TMS570LS1227).
+ \\\hline
+
+ 0.5.5 & 2015-08-27 & Sojka, Horn & rpp-lib: HAL merged into DRV
+ layer, FreeRTOS upgraded to version 8.2.2.
+ \\\hline
+
+ 0.6 & 2015-09-03 & Sojka & Multi-rate models can be
+ compiled in multi-tasking mode
+ (see
+ sec.~\ref{sec-singlet-multit-modes}
+ and \ref{sec:mult-multi-thre}).
+ Added board init block (sec.
+ \ref{sec:block:sfunction_hydctr_init.c}).
+ Documented halcogen directory in
+ sec.~\ref{sec-rpp-lib-subdirectory-content-description}.
+ \\\hline
+
+ 0.6a & 2015-09-11 & Sojka & Removed reference of
+ Simulink blocks that are not
+ part of Eaton distribution.
+ \\\hline
+
+ 0.7 & 2015-10-05 & Sojka & Simulink GIO blocks
+ (sec.
+ \ref{sec:block:sfunction_gio_in.c},
+ \ref{sec:block:sfunction_gio_out.c})
+ have different parameters and
+ support certain SPI5 pins on the
+ tms570\_hydctr board. Parameters
+ of old GIO blocks are
+ automatically transformed to the
+ new ones.
+
+ Added section \ref{sec:board-init-hydctr}: ``Hydraulics controller
+ initialization demo''.
+ \\\hline
+\end{tabularx}
+
\tableofcontents
\newpage
\label{chap-introduction}
This text documents software part of Rapid Prototyping Platform (RPP)
-project for Texas Instruments RM48 safety microcontroller. The
-software consists of code generation target for Simulink Embedded
-Coder, a low-level run-time C library and a tool for interactive
-testing of hardware and software functionality.
-
-Originally, the RPP project was created for TMS570 microcontroller and
-the port to RM48 was derived from it under a contract with Eaton
-Corporation.
-% TODO remove it
-As this document is still in beta version, some
-references to the original TMS570-based RPP remain in it.
+project for Texas Instruments \tgname{} safety microcontroller
+developed by Czech Technical University in Prague (CTU). The software
+consists of code generation target for Simulink Embedded Coder, a
+low-level run-time C library and a tool for interactive testing of
+hardware and software functionality.
+
+Originally, the RPP project was created for a custom TMS570-based board
+and the port to other platforms such as RM48 HDK and TMS570 HDK
+development kits. Porting to other platforms was done under a contract
+from Eaton Corporation.
The document contains step-by-step instructions for installation of
development tools, information about Simulink Coder configuration,
\section{Background}
\label{sec-background}
-The Rapid Prototyping Platform is an control unit based on TMDSRM48HDK
-development kit from Texas Instruments. Cental to the kit is the
-RM48L952 MCU -- an ARM Cortex R4 based microcontroller developed by
-Texas Instruments. This MCU contains several protective mechanisms
-(two cores in lockstep, error correction mechanisms for SRAM and Flash
-memory, voltage monitoring, etc.) to fulfill the requirements for
-safety critical applications.
-See~\cite{rm48xtechnicalreferencemanual2013} for details.
+In this document, the term \emph{Rapid Prototyping Platform} denotes a
+hardware board and accompanying software. The hardware board is
+\tgtBoardName{} based on ARM Cortex R4 safety microcontroller
+\mcuname{}. This MCU contains several protective mechanisms (two cores
+in lockstep, error correction mechanisms for SRAM and Flash memory,
+voltage monitoring, etc.) to fulfill the requirements for safety
+critical applications. See~\cite{\tgrefman} for details.
In order to develop non-trivial applications for the RPP, an operating
system is necessary. The RPP is based on FreeRTOS -- a simple
another block. This block can implement some clever algorithm and its
output is passed to another block, which sends the computed value as a
message over CAN bus to some other MCU. Such a model can be simulated
-and tested even before the real hardware is available by replacinf the
+and tested even before the real hardware is available by replacing the
input and output blocks with simulated ones. Once the hardware is
ready, C code is automatically generated from the model by a Simulink
Coder. The code is then compiled by the MCU compatible compiler and
\section{Hardware description}
\label{sec-hardware-description}
-This section provides a brief description of the Texas Instrument
-TMDSRM48HDK development kit. For a more detailed information refer to
-\cite{rm48hdkusersguide2013}. The kit is depicted in
-Figure~\ref{fig-board_photo}.
-
-\begin{figure}\begin{center}
- \noindent
- \includegraphics[width=300px]{images/board.png}
- \caption{The TMDSRM48HDK kit \cite[p. 8]{rm48hdkusersguide2013}}
- \label{fig-board_photo}
-\end{center}\end{figure}
-
-Only a subset of peripherals available on the kit is currently
-supported by the RPP software. A block diagram in
-Figure~\ref{fig-blocks} ilustrates the supported peripherals and their
-connection to the MCU, expansion connectors and other components on
-the development kit. For pinout description of the implemented
-peripherals refer the RM48HDK User's Guide
-\cite{rm48hdkusersguide2013}. The main features of supported
-peripherals are provided in the following subsections.
-
-\begin{figure}\begin{center}
- \noindent
- \includegraphics[width=400px]{images/blocks.png}
- \caption{Block diagram of supported peripherals}
- \label{fig-blocks}
-\end{center}\end{figure}
-
-\subsection{Digital Inputs and Outputs (DIN and DOUT)}
-\label{par-digital-inputs-outputs}
- \begin{compactitem}
- \item 46 pins available on Expansion connector J11.
- \item 8 pins available on GIOA
- \item 8 pins available on GIOB
- \item 30 pins available on NHET1. Pins NHET1 6 and NHET1 13 are disabled.
- \item All the pins are configurable as inputs and outputs with different modes:
- \begin{compactitem}
- \item Push/Pull or Open Drain for Output configuration.
- \item Pull up, Pull down or tri-stated for Input configuration.
- \end{compactitem}
- \item Some of the pins are connected to LEDs or to a button. See
- Figure~\ref{fig-blocks} or refer to~\cite{rm48hdkusersguide2013}.
- \end{compactitem}
-
-\subsection{Analog Input (ADC)}
-\label{par-analog-input}
-\vbox{% Keep this on the same page
- \begin{compactitem}
- \item 16 channels available on the Expansion connector J9.
- \item Range for 0 -- 5 Volts.
- \item 12 bits resolution.
- \end{compactitem}
-}
-\subsection{CAN bus (CAN)}
-\label{par-can}
-\begin{compactitem}
- \item Up to three CAN ports
- \begin{compactitem}
- \item 2 ports equipped with physical layer CAN transciever
- connected to J2 and J3 connectors.
- \item All 3 ports available as link-level interface on the
- Expansion connector J11.
- \end{compactitem}
- \item High speed.
- \item Recovery from errors.
- \item Detection of network errors.
-\end{compactitem}
-
-\subsection{Serial Communication Interface (SCI)}
-\label{par-sci}
-\begin{compactitem}
- \item 1 port available on connector J7.
- \item Configurable baud rate. Tested with 9600 and 115200 bps.
- \item RS232 compatible.
-\end{compactitem}
+\input{hwdesc}
\section{Software architecture}
\label{sec-software-architecture}
% couple of exceptions).
\item Each layer should provide a unified layer interface
(\texttt{rpp.h}, \texttt{drv.h}, \texttt {hal.h}, \texttt{sys.h} and
- \texttt{os.h}), so that top layers depends on the layer interface
+ \texttt{os.h}), so that higher layers depend on the lower layer's interface
and not on individual elements from that layer.
\end{compactitem}
\subsection{Operating System layer}
\label{sec-operating-system-layer}
-This is an interchangeable operating system layer, containing the
+This is an interchangeable operating system (OS) layer containing the
FreeRTOS source files. The system can be easily replaced by another
version. For example it is possible to compile the RPP library for
Linux (using POSIX version of the FreeRTOS), which can be desirable
The following FreeRTOS versions are distributed:
\begin{description}
- \item[6.0.4\_posix] POSIX version, usable for compilation of the library
-for Linux system.
- \item[7.0.2] Preferred version of the FreeRTOS, distributed by
-Texas Instruments. This version has been tested and is used in the current
-version of the library.
- \item[7.4.0] Newest version distributed by the Texas Instruments.
- \item[7.4.2] Newer version available from FreeRTOS pages. Slightly
-modified to run on RM48 MCU.
+\item[6.0.4\_posix] POSIX version, usable for compilation of the
+ library for Linux system.
+\item[8.2.2] Currently used FreeRTOS version. This is the version
+ downloaded from FreeRTOS.org with changes in directory structure.
+ Namely, include files have added the \emph{os/} prefix and platform
+ dependent code (portable) for \tgname{} is copied to the same
+ directory as platform independent code.
\end{description}
-\noindent
-Both 7.4.x version were tested and work, but the testing was not so
-extensive as with the used 7.0.2 version.
-
\subsection{System Layer}
\label{sec-system-layer}
This layer contains system files with data types definitions, clock definitions,
folder.
Large part of this layer was generated by the HalCoGen tool (see
-Section~\ref{sec-halcogen}).
-
-\subsection{HAL abstraction layer}
-\label{sec-hal-abstraction-layer}
-Hardware Abstraction Layer (HAL) provides an abstraction over the real
-hardware. For example imagine an IO port with 8 pins. First four pins
-are connected directly to the GPIO pins on the MCU, another four pins
-are connected to an external integrated circuit, communicating with
-the MCU via SPI. This layer allows to control the IO pins
-independently of how that are connected to the MCU, providing a single
-unified API.
-
-Note that this functionality is not needed in the current version of
-for TMDSRM48HDK, because all IOs are controlled directly by GPIO pins.
-
-As a result, the higher layers do not have to know anything about the
-wiring of the peripherals, they can just call read, write or configure
-function with a pin name as a parameter and the HAL handles all the
-details.
-
-The source files can be found in
-\texttt{$\langle$rpp\_lib$\rangle$/rpp/src/hal} and the header files can
-be found in \texttt{$\langle$rpp\_lib$\rangle$/rpp/include/hal} folder.
+Section~\ref{sec-halcogen}). Some files were then modified by hand.
\subsection{Drivers layer}
\label{sec-drivers-layer}
The Drivers layer contains code for controlling the RPP peripherals.
Typically, it contains code implementing IRQ handling, software
queues, management threads, etc. The layer benefits from the lower
-layers thus it is not too low level, but still there are some
+layer thus it is not too low level, but still there are some
peripherals like ADC, which need some special procedure for
initialization and running, that would not be very intuitive for the
-user.
+typical end user.
The source files can be found in
\texttt{$\langle$rpp\_lib$\rangle$/rpp/src/drv} and the header files can
\item GtkTerm 0.99.7-rc1
\item TI Code Composer Studio 5.5.0.00077
\item Matlab 2013b 64b with Embedded Coder
- \item HalCoGen 4.00 (optionally)
- \item Uncrustify 0.59 (optionally, see Section \ref{sec-compilation})
- \item Doxygen 1.8.4 (optionally, see Section \ref{sec-compiling-api-documentation})
- \item Git 1.7.10.4 (optionally)
+ \item HalCoGen 4.00 (optional)
+ \item Uncrustify 0.59 (optional, see Section \ref{sec-compilation})
+ \item Doxygen 1.8.4 (optional, see Section \ref{sec-compiling-api-documentation})
+ \item Git 1.7.10.4 (optional)
\end{itemize}
\subsection{Windows environment}
\item Bray Terminal v1.9b
\item TI Code Composer Studio 5.5.0.00077
\item Matlab 2013b 64b with Embedded Coder
- \item HalCoGen 4.00 (optionally)
- \item Doxygen 1.8.4 (optionally, see Section \ref{sec-compiling-api-documentation})
- \item Uncrustify 0.59 (optionally, see Section \ref{sec-compilation})
- \item Git 1.9.4.msysgit.2 (optionally)
+ \item HalCoGen 4.00 (optional)
+ \item Doxygen 1.8.4 (optional, see Section \ref{sec-compiling-api-documentation})
+ \item Uncrustify 0.59 (optional, see Section \ref{sec-compilation})
+ \item Git 1.9.4.msysgit.2 (optional)
\end{itemize}
-\section{Software and tools}
+\section{Software tools}
\label{sec-software-and-tools}
+This section covers tool which are needed or recommended for work with
+the RPP project.
+
\subsection{TI Code Composer Studio}
\label{sec-ti-ccs}
Code Composer Studio (CCS) is the official Integrated Development Environment
\label{sec-matlab-simulink}
Matlab Simulink is a set of tools, runtime environment and development
environment for Model--Based \cite{modelbasedwiki2013} applications development,
-simulations and generation code for target platforms. Supported Matlab Simulink
+simulations and code generation for target platforms. Supported Matlab Simulink
version is R2013b for 64 bits Linux and Windows. A licence for an Embedded Coder is
necessary to be able to generate code from Simulink models, containing RPP blocks.
The tool is available for Windows at
\begin{quotation}
-\url{http://www.ti.com/tool/halcogen?keyMatch=halcogen&tisearch=Search-EN}
+\url{http://www.ti.com/tool/halcogen}
\end{quotation}
The HalCoGen has been used in early development stage of the RPP
project to generate the base code for some of the peripheral. The
trend is to not to use the HalCoGen any more, because the generated
-code is not reliable enough for safety application. Anyway it is
+code is not reliable enough for safety critical applications. Anyway it is
sometimes helpful to use it as a reference.
The HalCoGen is distributed for Windows only, but can be run on Linux
-under Wine (test with version 1.6.2).
+under Wine (tested with Wine version 1.6.2).
\subsection{GtkTerm and Bray Terminal}
\label{sec-gtkterm-bray-terminal}
are:
\begin{description}
-\item[rpp-lib] Contains the source code of the RPP library, described
- in Chapter \ref{chap-c-support-library}. If you want to make any
- changes in the drivers or RPP API, this library has to be compiled
- and linked with applications in the other two packages. The compile
- procedure can be found in Section \ref{sec-compilation}.
\item[rpp-simulink] Contains the source code of Matlab Simulink
blocks, demo models and scripts for downloading the generated
- firmware to the target from Matlab/Simulink. Details can be
+ firmware to the target board from Matlab/Simulink. Details can be
found in Chapter \ref{chap-simulink-coder-target}.
- The package also contains the binary of the RPP Library and all
- headers and other files necessary for building and downloading the
- models.
+ The package also contains the binary of the RPP Library and all its
+ headers and other files necessary for building and downloading
+ Simulink models.
\item[rpp-test-sw] Contains an application for interactive testing and
- control of the RPP board over the serial interface. Details can be
+ control of the \tgtBoardName{} board over the serial interface. Details can be
found in Chapter~\ref{chap-rpp-test-software}.
The package also contains the binary of the RPP Library and all
headers and other files necessary for building and downloading the
application.
+\item[rpp-lib] Contains the source code of the RPP library, described
+ in Chapter \ref{chap-c-support-library}. If you want to make any
+ changes in the drivers or the RPP API, this library has to be
+ compiled and linked with applications in the other two packages.
+ Library compilation is described in Section \ref{sec-compilation}.
\end{description}
The following sections describe how to start working with individual
packages.
-\subsection{rpp-lib}
-\label{sec-rpp-lib-installation}
-
-This section describes how to open the rpp-lib project in Code
-Composer Studio and how to use the resulting static library in an
-application. This is only necessary if you need to modify the library
-for some reason.
-
-\begin{enumerate}
- \item Unzip the \texttt{rpp-lib-version.zip} file.
- \item Open the Code Composer Studio (see Section \ref{sec-ti-ccs}).
- \item Import the rpp-lib project as described in
- Section~\ref{sec-openning-of-existing-project}.
- \item Compile the static library using the procedure from Section
- \ref{sec-compilation}. The compiled library \texttt{rpp-lib.lib}
- will appear in the project root directory.
- \item Copy the compiled library to the application, where you want
- to test and use the new library version.
- \begin{itemize}
- \item In the rpp-simulink application the library is located in
- the \texttt{rpp/lib} folder.
- \item In the rpp-test-sw application the library is located in
- \texttt{rpp-lib} folder.
- \end{itemize}
-\end{enumerate}
+\ifx\tgtId\tgtIdTMSRPP
+\subsection{Getting sources from git repository}
+\begin{verbatim}
+git clone --recursive git@rtime.felk.cvut.cz:jenkicar/rpp-simulink
+\end{verbatim}
+If you get release packages, follow the instructions in the next sections.
+\fi
\subsection{rpp-simulink}
\label{sec-rpp-simulink-installation}
-This section describes how install the rpp-simulink project, which is
-needed to try the demo models or to build your own models that use RPP
-blocks.
+This section describes how to install the rpp-simulink project, which
+is needed to try the demo models or to build your own models that use
+the RPP blocks.
\begin{enumerate}
\item Unzip the \texttt{rpp-simulink-version.zip} file.
\ref{sec-configuration-simulink-for-rpp} for configuring Matlab
Simulink for the RPP project.
\item Follow the procedure from Section \ref{sec-crating-new-model}
- for instruction about creating your own model which will use the RPP
- Simulink blocks or follow the instructions in
- Section~\ref{sec-running-model-on-hw} for downloading the firmware
- to the real RPP hardware.
+ for instructions about creating your own model which will use the
+ RPP Simulink blocks or follow the instructions in
+ Section~\ref{sec-running-model-on-hw} for downloading the firmware to the RPP hardware.
\end{enumerate}
\subsection{rpp-test-sw}
\begin{enumerate}
\item Unzip the \texttt{rpp-test-sw-version.zip} file.
\item Open the Code Composer Studio (see Section \ref{sec-ti-ccs}).
- \item Follow the procedure for opening the projects in CCS in
- Section \ref{sec-openning-of-existing-project} and open both
- \texttt{rpp-lib} and \texttt{rpp-test-sw} projects.
+ \item Import the \texttt{rpp-test-sw} project as described in
+ Section \ref{sec-openning-of-existing-project}.
\item Right click on the \texttt{rpp-test-sw} project in the
\textsc{Project Explorer} and select \textsc{Build Project}.
\item Follow the instructions in
Section~\ref{sec-running-software-on-hw} to download, debug and
- run the software on the target hardware. If CCS asks you whether
- to proceed with the detected errors in \texttt{rpp-lib} project.
- Ignore them and click the \textsc{Proceed} button to continue.
+ run the software on the target hardware.
+\end{enumerate}
+
+\subsection{rpp-lib}
+\label{sec-rpp-lib-installation}
+
+This section describes how to open the rpp-lib project in Code
+Composer Studio and how to use the resulting static library in an
+application. This is only necessary if you need to modify the library
+for some reason.
+
+\begin{enumerate}
+ \item Unzip the \texttt{rpp-lib-version.zip} file.
+ \item Open the Code Composer Studio (see Section \ref{sec-ti-ccs}).
+ \item Import the rpp-lib project from directory
+ \texttt{rpp-lib-XXX/build/\tgtId} as described in
+ Section~\ref{sec-openning-of-existing-project}.
+ \item Compile the static library by selecting \textsc{Project
+ $\rightarrow$ Build Project} (see Section
+ \ref{sec-compilation} for more information). The compiled
+ library \texttt{rpp-lib.lib} and file
+ \texttt{Makefile.config} will appear in the
+ \texttt{rpp-lib-XXX} directory.
+ \item Either copy the compiled library and the content of the
+ \texttt{rpp/include} directory to the application, where you
+ want to use it or use the library in place, as described in
+ Section~\ref{sec:creating-new-project}.
+ \begin{itemize}
+ \item In the rpp-simulink application the library is located in
+ the \texttt{rpp/lib} folder.
+ \item In the rpp-test-sw application the library is located in
+ the \texttt{rpp-lib} folder.
+ \end{itemize}
\end{enumerate}
\section{Code Composer Studio usage}
\label{sec-code-composerpstudio-usage}
-\subsection{Opening of existing project}
+\subsection{Opening an existing project}
\label{sec-openning-of-existing-project}
The procedure for opening a project is similar to opening a project in
the standard Eclipse IDE.
\label{fig-select-project}
\end{center}\end{figure}
+\newpage
\subsection{Creating new project}
-\label{sec-creating-new-project}
-In \texttt{\repo/rpp/lib/apps/}, there are two simple RPP applications
-\texttt{helloworld} and \texttt{helloworld\_posix}, that are already
-configured for the RPP Library. It is advised that new applications
-use this project as a template.
+\label{sec:creating-new-project}
+Follow these steps to create an application for \tgname{} MCU compiled with
+CGT.
-To create a new application copy \texttt{helloworld} directory to a
-new location and rename it. Now open files \texttt{.project},
-\texttt{.cproject} and \texttt{.ccsproject} (if available) and change
-any occurrence of the word \texttt{helloworld} to the name of your new
-project. Use lower case ASCII letters and underscores only.
+\begin{compactenum}
+\item Create a new empty CCS project. Select \mcuname{} device, XDS100v2
+ connection and set Linker command file to
+ \texttt{rpp-lib/build/\tgtId/\ldscriptname}.
-\subsubsection{Steps to configure new RPP application in CCS:}
+ \noindent\includegraphics[scale=0.45]{images/base_1.png}
-Follow these steps to create an application for RM48 MCU compiled with
-CGT.
-\newpage
-\begin{compactenum}
-\item Create a new CCS project.\\
- \noindent\includegraphics[width=400px]{images/base_1.png}
\item In \textsc{Project Explorer}, create normal folders
named \texttt{include} and \texttt{src}.
+
\item If you use Git version control system, add \texttt{.gitignore}
file with the following content to the root of that project:
\lstset{language=}
Release
.settings/*
\end{lstlisting}
+
\newpage
-\item In project \textsc{Properties}, add new variable
- \texttt{RPP\_LIB\_ROOT} and point to this repository branch
- root.\\
- \noindent\includegraphics[width=400px]{images/base_2.png}
-\item Add \texttt{rpp-lib.lib} static library to list of linked
- libraries and add \texttt{RPP\_LIB\_ROOT} to the library search
- path.\newline{}
-\noindent\includegraphics[width=400px]{images/base_3.png}
-\newpage
-\item Configure linker to retain the \texttt{.intvecs} section
- from the RPP library.\\
- \noindent\includegraphics[width=350px]{images/base_4.png}
- \item Configure compiler to include local includes, OS includes for
-RM48 and RPP includes, in that order.\newline{}
-\noindent\includegraphics[width=350px]{images/base_5.png}
+\item In project \textsc{Properties}, add new variable of type
+ \texttt{Directory} named \texttt{RPP\_LIB\_ROOT} and set it to the
+ rpp-lib directory
+ root.
+
+ \noindent\includegraphics[scale=.45]{images/base_2.png}
+
+\item Configure the compiler \#include search path to contain
+ project's \texttt{include} directory, \penalty-100
+ \texttt{\$\{RPP\_LIB\_ROOT\}/os/8.2.2/include} and
+ \texttt{\$\{RPP\_LIB\_ROOT\}/rpp/include}, in that order.
+
+ \includegraphics[scale=.43]{images/base_5.png}
+
+ \newpage
+\item Add \texttt{\$\{RPP\_LIB\_ROOT\}/rpp-lib.lib} to the list of
+ linked libraries before the runtime support library
+ (\texttt{\tgtRtlib}).
+
+ \noindent\includegraphics[scale=.45]{images/base_3.png}
+
+\item Configure the compiler to allow GCC extensions.
+
+ \noindent\includegraphics[scale=.45]{images/base_6.png}
+
\newpage
- \item Configure compiler to allow GCC extensions.\newline{}
-\noindent\includegraphics[width=400px]{images/base_6.png}
-\item Import and link (\emph{do not copy!}) linker file
- \texttt{RM48L952FlashLnk.cmd} and board upload
- descriptor.\\ % TODO Ktere soubory to jsou a jak se
- % na windows linkuje?
-\noindent\includegraphics[width=200px]{images/base_7.png}
-\end{compactenum}
+\item Create \texttt{main.c} file with the following content:
+\begin{lstlisting}[language=C]
+#include <rpp/rpp.h>
-\subsubsection{Steps to configure new POSIX application:}
-Such an application can be used to test certain FreeRTOS features on
-Linux and can be compiled with a native GCC compiler.
+int main(void)
+{
+ rpp_init();
+ rpp_sci_printf("Hello world\n");
+ vTaskStartScheduler();
+ return 0; /* not reached */
+}
-\begin{compactenum}
- \item Create a new managed C project that uses Linux GCC toolchain.
- \item Create a source folder \texttt{src}. Link all files from original
-CCS application to this folder.
- \item Create a normal folder \texttt{include}. Create a folder
-\texttt{rpp} inside of it.
- \item Add common \texttt{.gitignore} to the root of that project:
-\lstset{language=}
-\begin{lstlisting}
-Debug
-Release
-.settings/*
+void vApplicationMallocFailedHook()
+{}
+void vApplicationStackOverflowHook()
+{}
\end{lstlisting}
-\newpage
- \item Add new variable \texttt{RPP\_LIB\_ROOT} and point to this
-repository branch root.\newline{}
-\noindent\includegraphics[width=400px]{images/base_posix_1.png}
- \item Configure compiler to include local includes, CCS application
-includes, OS includes for POSIX and RPP includes, in that order.\newline{}
-\noindent\includegraphics[width=400px]{images/base_posix_2.png}
-\newpage
- \item Add \texttt{rpp} and \texttt{pthread} to linker libraries and add
-\texttt{RPP\_LIB\_ROOT} to the library search path.\newline{}
-\noindent\includegraphics[width=400px]{images/base_posix_3.png}
+
+\item Compile the application by e.g. \textsc{Project $\rightarrow$
+ Build All}.
+\item Select \textsc{Run} $\rightarrow$ \textsc{Debug}. The
+ application will be downloaded to the processor and run. A
+ breakpoint is automatically placed at \texttt{main()} entry. To
+ continue executing the application select \textsc{Run} $\rightarrow$
+ \textsc{Resume}.
+\item If your application fails to run with a \texttt{\_dabort} interrupt, check
+that the linker script selected in step 1 is not excluded from the build.
+You can do this by right clicking the \texttt{\ldscriptname} file
+in the \textsc{Project Explorer} and unchecking the \textsc{Exclude from build}
+item. The Code Composer Studio sometimes automaticaly excludes this file from
+the build process when creating a new project.
+
+% \item If not already created for another project, create new target
+% configuration. Select \textsc{Windows $\rightarrow$ Show View
+% $\rightarrow$ Target Configurations}. In the shown window, click
+% on \textsc{New Target Configuration} icon and configure XDS100v2
+% connection and \mcuname{} device as shown below. Click \textsc{Save},
+% connect your board and click \textsc{Test Connection}.
+
+% \medskip
+% \includegraphics[width=\linewidth]{images/target_conf.png}
+
+% \newpage
+\item Optionally, you can change debugger configuration by selecting
+ \textsc{Run $\rightarrow$ Debug Configurations}. In the
+ \textsc{Target} tab, you can configure not to break at \texttt{main}
+ or not to erase the whole flash, but necessary sectors only (see the
+ figure below).
+
+ \includegraphics[width=\linewidth]{images/debug_conf_flash.png}
+
+
\end{compactenum}
+%% Comment this out for Eaton
+% \subsubsection{Steps to configure new POSIX application:}
+% Such an application can be used to test certain FreeRTOS features on
+% Linux and can be compiled with a native GCC compiler.
+
+% \begin{compactenum}
+% \item Create a new managed C project that uses Linux GCC toolchain.
+% \item Create a source folder \texttt{src}. Link all files from original
+% CCS application to this folder.
+% \item Create a normal folder \texttt{include}. Create a folder
+% \texttt{rpp} inside of it.
+% \item Add common \texttt{.gitignore} to the root of that project:
+% \lstset{language=}
+% \begin{lstlisting}
+% Debug
+% Release
+% .settings/*
+% \end{lstlisting}
+% \item Add new variable \texttt{RPP\_LIB\_ROOT} and point to this
+% repository branch root.\newline{}
+% \noindent\includegraphics[width=\linewidth]{images/base_posix_1.png}
+% \item Configure compiler to include local includes, CCS application
+% includes, OS includes for POSIX and RPP includes, in that order.\newline{}
+% \noindent\includegraphics[width=\linewidth]{images/base_posix_2.png}
+% \newpage
+% \item Add \texttt{rpp} and \texttt{pthread} to linker libraries and add
+% \texttt{RPP\_LIB\_ROOT} to the library search path.\newline{}
+% \noindent\includegraphics[width=\linewidth]{images/base_posix_3.png}
+% \end{compactenum}
+
\subsubsection{Content of the application}
\begin{enumerate}
"ERROR: Cannot spawn control task.\r\n"
);
#endif
- while (TRUE) { asm(" nop"); }
+ while (TRUE) { ; }
}
/* Start the FreeRTOS Scheduler */
"ERROR: Problem allocating memory for idle task.\r\n"
);
#endif
- while (TRUE) { asm(" nop"); }
+ while (TRUE) { ; }
}
\end{lstlisting}
\label{sec-running-software-on-hw}
\subsubsection{Code Composer Studio Project}
\label{sec-ccs-run-project}
-When the application is distributed as a CCS project, you have to open the
+When an application is distributed as a CCS project, you have to open the
project in the CCS as described in the Section
\ref{sec-openning-of-existing-project}. Once the project is opened and built, it
can be easily downloaded to the target hardware with the following procedure:
\begin{enumerate}
- \item Connect the Texas Instruments XDS100v2 USB emulator to the JTAG
-port.
- \item Connect a USB cable to the XDS100v2 USB emulator and the
-development computer.
+\ifx\tgtId\tgtIdTMSRPP
+ \item Connect the Texas Instruments XDS100v2 USB emulator to the JTAG port.
+ \item Connect a USB cable to the XDS100v2 USB emulator and the development computer.
+\else
+ \item Connect the USB cable to the \tgtBoardName{} board.
+\fi
\item Plug in the power supply.
\item In the Code Composer Studio click on the
\textsc{Run$\rightarrow$Debug}. The project will be optionally built and
\textsc{File$\rightarrow$New$\rightarrow$CCS Project}.
\item In the dialog window, type in a project name, for example
myBinaryLoad, Select \textsc{Device
-variant} (ARM, Cortex R, RM48L952, Texas Instruments XDS100v2 USB Emulator)
+variant} (ARM, Cortex R, \mcuname, Texas Instruments XDS100v2 USB Emulator)
and select project template to \textsc{Empty Project}. The filled dialog should
look like in Figure~\ref{fig-new-empty-project}
-\item Click on the \textsc{Finish} button and a new empty project will
+\item Click the \textsc{Finish} button and a new empty project will
be created.
\item In the \textsc{Project Explorer} right-click on the project and
select \textsc{Debug as$\rightarrow$Debug configurations}.
\item Click \textsc{New launch configuration} button
\item Rename the New\_configuration to, for example, myConfiguration.
\item Select configuration target file by clicking the \textsc{File
-System} button, finding and selecting the \texttt{RM48L952.ccxml} file. The result
+System} button, finding and selecting the \texttt{rpp-lib-XXX/build/\tgtId/\tgconfigfilename} file. The result
should look like in Figure~\ref{fig-debug-conf-main-diag}.
\item In the \textsc{program} pane select the binary file you want to
download to the board. Click on the \textsc{File System} button,
find and select the binary file. Try, for example
\texttt{rpp-test-sw.out}. The result should look like in
Figure~\ref{fig-debug-conf-program-diag}.
- \item You may also tune the target configuration like in the Section
-\ref{sec-target-configuration}.
-\item Finish the configuration by clicking on the \textsc{Apply}
- button and download the code by clicking on the \textsc{Debug}
- button. You can later invoke the download also from the
+\item You may also tune the target configuration as described in
+ Section \ref{sec-target-configuration}.
+\item Finish the configuration by clicking the \textsc{Apply} button
+ and download the code by clicking the \textsc{Debug} button. You can
+ later invoke the download also from the
\textsc{Run$\rightarrow$Debug} CCS menu. It is not necessary to
create more Debug configurations and CCS empty projects as you can
easily change the binary file in the Debug configuration to load a
\end{enumerate}
\begin{figure}[H]\begin{center}
- \includegraphics[width=350px]{images/new_empty_project.png}
+ \includegraphics[scale=.45]{images/new_empty_project.png}
\caption{New empty project dialog}
\label{fig-new-empty-project}
\end{center}\end{figure}
\begin{figure}[H]\begin{center}
- \includegraphics[width=350px]{images/debug_configuration_main.png}
+ \includegraphics[scale=.45]{images/debug_configuration_main.png}
\caption{Debug Configuration Main dialog}
\label{fig-debug-conf-main-diag}
\end{center}\end{figure}
\label{sec-target-configuration}
Default target configuration erases the whole Flash memory, before
downloading the code. This takes long time and in most cases it is
-necessary. You may disable this feature by the following procedure:
+not necessary. You may disable this feature by the following procedure:
\begin{enumerate}
\item Right click on the project name in the \textsc{Project Browser}
\item Select \textsc{Debug as$\rightarrow$Debug Configurations}
\item In the dialog window select \textsc{Target} pane.
\item In the \textsc{Flash Settings}, \textsc{Erase Options} select
\textsc{Necessary sectors only}.
- \item Save the configuration by clicking on the \textsc{Apply} button
+ \item Save the configuration by clicking the \textsc{Apply} button
and close the dialog.
\end{enumerate}
\begin{figure}[H]\begin{center}
- \includegraphics[width=350px]{images/debug_configuration_program.png}
+ \includegraphics[scale=.45]{images/debug_configuration_program.png}
\caption{Configuration Program dialog}
\label{fig-debug-conf-program-diag}
\end{center}\end{figure}
\section{Matlab Simulink usage}
\label{sec-matlab-simulink-usage}
-This section describes the basic tasks for working with the RPP code
+This section describes the basics of working with the RPP code
generation target for Simulink. For a more detailed description of the
code generation target refer to
Chapter~\ref{chap-simulink-coder-target}.
\item Download and install Code Composer Studio CCS (see
Section~\ref{sec-ti-ccs}).
\item Install a C compiler. On Windows follow Section~\ref{sec-c-compiler}.
-\item On Windows you have to tell the \texttt{mex} which C compiler it
- should use. In the Matlab command window run the \texttt{mex -setup}
+\item On Windows you have to tell the \texttt{mex} which C compiler to
+ use. In the Matlab command window run the \texttt{mex -setup}
command and select the native C compiler.
\begin{lstlisting}[basicstyle=\tt\footnotesize]
\item Create new model or load a demo:
- Demos are located in \texttt{\repo/rpp/demos} or you can start a new
- model and configure target to RPP. For new models see Section
- \ref{sec-crating-new-model} below.
+ Demos are located in \texttt{\repo/rpp/demos}. Creation of new
+ models is described in Section~\ref{sec-crating-new-model} below.
\end{enumerate}
\item Solver: \emph{discrete}
\item Fixed-step size: \emph{Sampling period in seconds. Minimum
is 0.001.}
- \item Tasking mode: \textit{SingleTasking}.
+ \item Tasking mode -- choose between the following:
+ \begin{compactitem}
+ \item \textit{Auto} selects SingleTasking modes for
+ single-rate model or MultiTasking mode for multi-rate
+ models. See Section \ref{sec-singlet-multit-modes}
+ \item \textit{SingleTasking} selects SingleTasking mode. See
+ Section \ref{sec-singlet-mode} for details.
+ \item \textit{MultiTasking} select MultiTasking mode. In
+ this mode \textit{Higher priority value indicates higher
+ task priority} should be checked. See Section
+ \ref{sec-multit-mode} for details.
+ \end{compactitem}
+
\begin{figure}
\centering
- \includegraphics[width=400px]{images/simulink_solver.png}
+ \includegraphics[scale=.45]{images/simulink_solver.png}
\caption{Solver settings}
\label{fig-solver}
\end{figure}
% time''. It's ok for the source blocks to run once per tick.
% \begin{figure}
% \centering
-% \includegraphics[width=400px]{images/simulink_diagnostics.png}
+% \includegraphics[scale=.45]{images/simulink_diagnostics.png}
% \caption{Sample Time settings}
% \label{fig-sample-time-settings}
% \end{figure}
\item Set ``System target file'' to \texttt{rpp.tlc}.
\begin{figure}
\centering
- \includegraphics[width=400px]{images/simulink_code.png}
+ \includegraphics[scale=.45]{images/simulink_code.png}
\caption{Code Generation settings}
\label{fig-code-gen-settings}
\end{figure}
\end{compactitem}
\end{compactitem}
+\item Once the model is configured, you can open the Library Browser
+ (\textsc{View $\rightarrow$ Library Browser}) and add the necessary
+ blocks to create the model. The RPP-specific blocks are located in
+ the RPP Block Library.
\item From Matlab command window change the current directory to where
you want your generated code to appear, e.g.:
\begin{lstlisting}[language=Matlab]
cd /tmp/my-code
\end{lstlisting}
- The code will be generated in a subdirectory of that directory. The name of
-the subdirectory will be \texttt{<model>\_rpp}, where \texttt{model} is the name
-of the Simulink model.
+The code will be generated in a subdirectory named
+\texttt{<model>\_rpp}, where \texttt{model} is the name of the
+Simulink model.
\item Generate the code by choosing \textsc{Code $\rightarrow$ C/C++
Code $\rightarrow$ Build Model}.
\end{enumerate}
-If you want to run the model on the RPP board, see Section
+To run the model on the \tgtBoardName{} board continue with Section
\ref{sec-running-model-on-hw}.
\subsection{Running models on the RPP board}
\label{sec-running-model-on-hw}
-To run the model on the target RPP hardware you have to enable the download
+To run the model on the \tgtBoardName{} hardware you have to enable the download
feature and build the model by following this procedure:
\begin{enumerate}
- \item Open the model you want to run (see Section~\ref{sec-openning-demo-models}.)
- \item Click on \textsc{Simulation$\rightarrow$Model Configuration
-Parameters}.
- \item In the \textsc{Code Generation$\rightarrow$RPP Options} pane
-check \textsc{Download compiled binary to RPP} checkbox.
- \item Click the \textsc{OK} button, connect the target HW to the computer
-like in the Section \ref{sec-ccs-run-project} and build the model by \textsc{Code $\rightarrow$ C/C++
-Code $\rightarrow$ Build Model}. If the build
-ends with a success, the download process will start and once the downloading is
-finished, the application will run immediatelly.
+ \item Open the model you want to run (see
+ Section~\ref{sec-openning-demo-models} for example with demo
+ models).
+ \item Click on \textsc{Simulation$\rightarrow$Model Configuration
+ Parameters}.
+ \item In the \textsc{Code Generation$\rightarrow$RPP Options} pane
+ check the \textsc{Download compiled binary to RPP} checkbox. Click
+ the \textsc{OK} button
+ \item Connect the target hardware to the computer (see Section
+ \ref{sec-ccs-run-project}) and build the model by \textsc{Code
+ $\rightarrow$ C/C++ Code $\rightarrow$ Build Model}. If the build
+ succeeds, the download process will start automatically and once
+ the downloading is finished, the application will run immediately.
\end{enumerate}
-\subsubsection{Using OpenOCD for downloading}
-\label{sec:using-open-downl}
-
-On Linux systems, it is possible to use an alternative download
-mechanism based on the OpenOCD tool. This results in much shorter
-download times. Using OpenOCD is enabled by checking ``Use OpenOCD to
-download the compiled binary'' checkbox. For more information about
-the OpenOCD configuration refer to our
-wiki\footnote{\url{http://rtime.felk.cvut.cz/hw/index.php/TMS570LS3137#OpenOCD_setup_and_Flashing}}.
-
-Note: You should close any ongoing Code Composer Studio debug sessions
-before downloading the generated code to the RPP board. Otherwise the
-download fails.
+%%\subsubsection{Using OpenOCD for downloading}
+%%\label{sec:using-open-downl}
+%%
+%%On Linux systems, it is possible to use an alternative download
+%%mechanism based on the OpenOCD tool. This results in much shorter
+%%download times. Using OpenOCD is enabled by checking ``Use OpenOCD to
+%%download the compiled binary'' checkbox. For more information about
+%%the OpenOCD configuration refer to our
+%%wiki\footnote{\url{http://rtime.felk.cvut.cz/hw/index.php/TMS570LS3137\#OpenOCD_setup_and_Flashing}}.
+%%
+%%Note: You should close any ongoing Code Composer Studio debug sessions
+%%before downloading the generated code to the RPP board. Otherwise the
+%%download fails.
\section{Configuring serial interface}
\label{sec-configuration-serial-interface}
The main mean for communication with the RPP board is the serial line.
Each application may define its own serial line settings, but the
-following settings is the default one:
+following settings are the default:
\begin{itemize}
\item Baudrate: 115200
\item Flow control: none
\end{itemize}
-Use GtkTerm in Linux or Bray Terminal for accessing the serial
-interface. On TMDSRM48HDK, the serial line is tunneled over the USB
-cable. % See Section \ref{sec-hardware-description} for reference about
+Use GtkTerm on Linux or Bray Terminal on Windows for accessing the
+serial interface. On \tgtBoardName{} board, the serial line is tunneled over
+the USB.
+% TODO: Conditional compilation
+ % See Section \ref{sec-hardware-description} for reference about
% the position of the serial interface connector on the RPP board.
\section{Bug reporting}
(RPP Library), which is used both for Simulink code generation target
and command line testing tool.
-\section{Description}
+\section{Introduction}
\label{sec-description}
The RPP C Support Library (also called RPP library) defines the API for
-working with the board. It includes drivers and an operating system.
+working with the board. It includes drivers and the operating system.
The library is
designed from the board user perspective and exposes a simplified high-level API
to handle the board's peripheral modules in a safe manner. The library is
-compiled as a static library named \texttt{rpp-lib.lib} and can be found in
+compiled as static library named \texttt{rpp-lib.lib} and can be found in
\texttt{\repo/rpp/lib}.
-The RPP library can be used in any project, where the RPP hardware support is
-required and it is also used in two applications -- the Command line testing
-tool, described in Chapter \ref{chap-rpp-test-software}, and Simulink Coder
-target, described in Chapter \ref{chap-simulink-coder-target}.
+The RPP library can be used in any project, where the RPP hardware
+support is required and it is also used in two applications --
+Simulink Coder Target, described in Chapter
+\ref{chap-simulink-coder-target}, and the command line testing tool,
+described in Chapter \ref{chap-rpp-test-software}.
-For details about the library architecture, refer Section \ref{sec-software-architecture}.
+For details about the library architecture, refer to Section~\ref{sec-software-architecture}.
\section{API development guidelines}
\label{sec-api-development-guidlines}
\begin{compactitem}
\item User documentation should be placed in header files, not in source
code, and should be Doxygen formatted using autobrief. Documentation for each
-function present is mandatory.
+function present is mandatory and must mention whether the function is
+thread safe or not.
\item Function declarations in the headers files is for public functions
only. Do not declare local/static/private functions in the header.
\item Documentation in source code files should be non-doxygen formatted
accomplished by the inclusion of the rpp.h or rpp\_\{mnemonic\}.h file on the
implementations files only and never on the interface files. Never expose any
other layer to the application or to the whole system below the RPP layer. In
-other words, never \texttt{\#include "foo/foo.h"} in any RPP Layer interface
-file.
+other words, never \texttt{\#include "foo/bar.h"} in any RPP Layer header
+file.
\end{compactitem}
\section{Coding style}
\label{sec-coding-style}
-In order to keep the code as clean as possible, a unified coding style
+In order to keep the code as clean as possible, unified coding style
should be followed by any contributor to the code. The used coding
style is based on the default configuration of Code Composer Studio
editor. Most notable rule is that the Tab character is 4 spaces.
-The RPP library project is prepared for a usage of a program named
-Uncrustify. The Uncrustify program checks the code and fixes those
-lines that does not match the coding style. However, keep in mind that
-the program is not perfect and sometimes some lines can be modified
-even when the suggested coding style has been followed. This does not
-causes problems as long as the contributor follows the committing
-procedure described in next paragraph.
+The RPP library project is prepared for use of a tool named
+Uncrustify. The Uncrustify tool checks the code and fixes those lines
+that do not match the coding style. However, keep in mind that the
+program is not perfect and sometimes it can modify code where the
+suggested coding style has been followed. This does not causes
+problems as long as the contributor follows the committing procedure
+described in next paragraph.
-When contributing to the code, the contributor should learn the current coding
-style from the existing code. When a new feature is implemented, before
-committing to the repository, a command:
+When contributing to the code, the contributor should learn the
+current coding style from existing code. When a new feature is
+implemented and committed to the local repository, the following
+commands should be called in Linux terminal:
-\lstset{language=bash}
-\begin{lstlisting}
+\begin{lstlisting}[language=bash]
make uncrustify
+git diff
+\end{lstlisting}
+The first line command corrects many found coding style violations and
+the second command displays them. If the user agree with the
+modification, he/she should amend the last commit, for example by:
+\begin{lstlisting}[language=bash]
+git add --update
+git commit --amend
\end{lstlisting}
-in a Linux terminal should be called. This command fixes any coding style
-errors. After that all changes can be committed.
\section{Subdirectory content description}
\label{sec-rpp-lib-subdirectory-content-description}
+
+The following files and directories are present in the library source
+code package:
+
\begin{description}
-\item[librpp.a and rpp-lib.lib] static RPP libraries.
-
-The first one is for POSIX simulation, the second one for Simulink models and
-other ARM/RM48 applications. This files are placed here by the Makefile, when
-the library is built.
-
- \item[apps/] Demo applications related to the RPP library.
-
-This include the CCS studio project for generating of the static library and
-a test suite. The test suit in this directory has nothing common with the test suite
-mentioned later in Chapter 5 and those two suits are going to be merged in the
-future. Also other Hello World applications are included as a reference about how
-to create a RM48 application.
- \item[os/] OS layers directory. See OS interchangeable layer in Section
-\ref{sec-software-architecture} for more information.
-information.
- \item[rpp/] Main directory for the RPP Library.
- \item[rpp/doc/] Documentation directory for the RPP Library API documentation.
-
-This file is used by all the projects including the Simulink RPP Target for code
-download. It is configured to use the Texas Instruments XDS100v2 USB Emulator.
- \item[rpp/RM48L952FlashLnk.cmd] CGT Linker command file.
-
-This file is used by all applications linked for the RPP board, including the
-Simulink models, static library and test suite. It includes instructions for the
-CGT Linker on where to place sections and sizes of some sections.
- \item[rpp/include/\{layer\} and rpp/src/\{layer\}] Interface files and
-implementations files for given \texttt{\{layer\}}. See Section
-\ref{sec-software-architecture} in Chapter \ref{chap-introduction} for details
-on the RPP Layer.
- \item[rpp/include/rpp/rpp.h] Main library header file.
-
-To use this library with all its modules, just include this file and this file
-only. Also, before using any library function call the \texttt{rpp\_init()}
-function for hardware initialization.
- \item[rpp/include/rpp/rpp\_\{mnemonic\}.h] Header file for
-\texttt{\{mnemonic\}} module.
-
-This files includes function definitions, pin definitions, etc, specific to
-\{mnemonic\} module. See Section \ref{sec-api-development-guidlines}.
-
-You may include only selected \texttt{rpp\_\{mnemonic\}.h} header files and call the
-specific \texttt{rpp\_\{mnemonic\}\_init} functions, instead of the \texttt{rpp.h} and
-\texttt{rpp\_init} function, if you want to use only a subset of the library functions.
+\item[rpp-lib.lib] Compiled RPP library.
+
+ The library is needed for Simulink models and other ARM/\tgname{}
+ applications. It is placed here by the Makefile, when the library is
+ compiled.
+
+\item[apps/] Various applications related to the RPP library.
+
+ This include the CCS studio project for generating of the static
+ library and a test suite. The test suit in this directory has
+ nothing common with the test suite described later in
+ Chapter~\ref{chap-rpp-test-software} and those two suits are going
+ to be merged in the future. Also other Hello World applications are
+ included as a reference about how to create an \tgname{}
+ application.
+\item[build] The library can be compiled for multiple targets. Each
+ supported target has a subdirectory here, which stores configuration
+ of how to compile the library and applications for different target.
+ Each subdirectory contains a CCS project and Makefiles to build the
+ library for the particular target.
+\item[build/$\langle$target$\rangle$/Makefile.config] Configuration
+ for the particular target. This includes compiler and linker
+ switches etc.
+\item[build/$\langle$target$\rangle$/*.cmd]
+CGT Linker command file.
+
+This file is used by all applications that need to tun on the RPP
+board, including the Simulink models and test suite. It includes
+instructions for the CGT Linker about target memory layout and where
+to place various code sections.
+
+\item[halcogen/] HalCoGen project files for the supported boards and
+ scripts for automated conversion of HalCoGen-generated files for use
+ in rpp-lib.
+
+ Note: This is work in progress. Currently only ``pinmux'' files for
+ tms570\_hydctr board were produced by the scripts here.
+
+\item[os/] OS layers directory. See
+ Section~\ref{sec-operating-system-layer} for more information about
+ currently available operating system versions and
+ Section~\ref{sec-changing-os} for information how to replace the
+ operating system.
+\item[rpp/] Main directory for the RPP library.
+\item[rpp/doc/] RPP Library API
+ documentation.
+\item[rpp/include/\{layer\} and rpp/src/\{layer\}] Interface files and
+ implementations files for given \texttt{\{layer\}}. See
+ Section~\ref{sec-software-architecture} for details on the RPP
+ Layer.
+\item[rpp/include/rpp/rpp.h] Main library header file.
+
+ To use this library with all its modules, just include this file
+ only. Also, before using any library function call the
+ \texttt{rpp\_init()} function for hardware initialization.
+\item[rpp/include/rpp/rpp\_\{mnemonic\}.h] Header file for
+ \texttt{\{mnemonic\}} module.
+
+ These files includes function definitions, pin definitions, etc,
+ specific to \{mnemonic\} module. See also
+ Section~\ref{sec-api-development-guidlines}.
+
+ If you want to use only a subset of library functions and make the
+ resulting binary smaller, you may include only selected
+ \texttt{rpp\_\{mnemonic\}.h} header files and call the specific
+ \texttt{rpp\_\{mnemonic\}\_init} functions, instead of the
+ \texttt{rpp.h} and \texttt{rpp\_init} function.
\item[rpp/src/rpp/rpp\_\{mnemonic\}.c] Module implementation.
-Implementation of \texttt{rpp\_\{mnemonic\}.h}'s functions on top of the DRV
-library.
+ Implementation of \texttt{rpp\_\{mnemonic\}.h}'s functions on
+ top of the DRV library.
\item[rpp/src/rpp/rpp.c] Implementation of library-wide functions.
\end{description}
\label{sec-compilation}
To compile the library open the Code Composer studio project
-\texttt{rpp-lib} (see Section~\ref{sec-openning-of-existing-project})
-and build the project (\textsc{Project $\rightarrow$ Build Project}).
-If the build process is successful, the \texttt{rpp-lib.lib} file will
-appear in the library root directory.
+\texttt{rpp-lib} from appropriate \texttt{build/<target>} directory
+(see Section~\ref{sec-openning-of-existing-project}) and build the
+project (\textsc{Project $\rightarrow$ Build Project}). If the build
+process is successful, the \texttt{rpp-lib.lib} and
+\texttt{Makefile.config} files will appear in the library root
+directory.
It is also possible to compile the library using the included
\texttt{Makefile}. From the Linux command line run:
\begin{lstlisting}[language=bash]
-cd <library-root>
-make lib
+cd <library-root>/build/<target>/Debug #or Release
+make
\end{lstlisting}
Note that this only works if Code Composer Studio is installed in
\texttt{/opt/ti} directory. Otherwise, you have to set
On Windows command line run:
\begin{lstlisting}[language=bash]
-cd <library-root>
+cd <library-root>\build\<target>\Debug
set CCS_UTILS_DIR=C:\ti\ccsv5\utils
-"C:\ti\ccsv5\utils\bin\"gmake.exe lib
+C:\ti\ccsv5\utils\bin\gmake.exe lib
\end{lstlisting}
-You have to use \texttt{gmake.exe} is instead of \texttt{make} and it
-is necessary to set variable \texttt{CCS\_UTILS\_DIR} manually. You
-can also edit \texttt{\repo/Debug/GNUmakefile} and set the variable
+You have to use \texttt{gmake.exe} instead of \texttt{make} and it is
+necessary to set variable \texttt{CCS\_UTILS\_DIR} manually. You can
+also edit \texttt{\repo/build/Makefile.rules.arm} and set the variable
there.
Note that the Makefile still requires the Code Composer Studio (ARM
compiler) to be installed because of the CGT.
-\section{Compiling applications using the library}
+\section{Compiling applications using the RPP library}
\label{sec:comp-appl-using}
The relevant aspects for compiling and linking an application using
the RPP library are summarized below.
-\subsection{ARM target (RPP board)}
-\label{sec:arm-target-rpp}
+% \subsection{ARM target (RPP board)}
+% \label{sec:arm-target-rpp}
+
+The detailed instructions are presented in
+Section~\ref{sec:creating-new-project}. Here we briefly repeat the
+main steps.
\begin{compactitem}
\item Configure include search path to contain the directory of
used FreeRTOS version, e.g.
- \texttt{\repo/os/7.0.2\_rm48/include}. See Section
+ \texttt{\repo/os/8.2.2/include}. See Section
\ref{sec-software-architecture}.
\item Include \texttt{rpp/rpp.h} header file or just the needed
peripheral specific header files such as \texttt{rpp/can.h}.
\item Add library \texttt{rpp-lib.lib} to the linker libraries.
- The RPP library must be looked for before Texas Instruments
- support library \texttt{rtsv7R4\_T\_le\_v3D16\_eabi.lib}.
+ The RPP library must be placed before Texas Instruments
+ support library \tgtRtlib.
\item Use the provided linker command file
- \texttt{RM48L952FlashLnk.cmd}.
+ \texttt{\ldscriptname}.
\end{compactitem}
-\subsection{POSIX target}
-\label{sec:posix-target}
+% \subsection{POSIX target}
+% \label{sec:posix-target}
- \begin{compactitem}
- \item Include headers files of the OS for Simulation. At the time
- of this writing the OS is POSIX FreeRTOS 6.0.4.
- \item Include header files for the RPP library or for modules you
- want to use (rpp\_can.h for CAN module for example).
- \item Add library \texttt{librpp.a} to the linker libraries.
- \item Add \texttt{pthread} to the linker libraries.
- \end{compactitem}
+% \begin{compactitem}
+% \item Include headers files of the OS for Simulation. At the time
+% of this writing the OS is POSIX FreeRTOS 6.0.4.
+% \item Include header files for the RPP library or for modules you
+% want to use (rpp\_can.h for CAN module for example).
+% \item Add library \texttt{librpp.a} to the linker libraries.
+% \item Add \texttt{pthread} to the linker libraries.
+% \end{compactitem}
\section{Compiling API documentation}
\label{sec-compiling-api-documentation}
main_page.dox
\end{verbatim}
+\section{Changing operating system}
+\label{sec-changing-os}
+The C Support Library contains by default the FreeRTOS operating
+system in version 8.2.2. This section describes what is necessary to
+change in the library and other packages in order to replace the
+operating system.
+
+\subsection{Operating system code and API}
+
+The source and header files of the current operating system (OS) are
+stored in directory \texttt{\repo/rpp/lib/os}. The files of the new
+operating system should also be placed in this directory.
+
+To make the methods and resources of the new OS available to the C Support
+Library, modify the \texttt{\repo/rpp/lib/rpp/include/base.h} file to include
+the operating system header files.
+
+Current implementation for FreeRTOS includes a header file
+\texttt{\repo/rpp/lib/os/\-8.2.2\-include/os.h}, which
+contains all necessary declarations and definitions for the FreeRTOS.
+We suggest to provide a similar header file for your operating system as
+well.
+
+In order to compile another operating system into the library, it is
+necessary to modify \texttt{\repo/rpp/lib/Makefile.var} file, which
+contains a list of files that are compiled into the library. All lines
+starting with \texttt{os/} should be updated.
+
+\subsection{Device drivers}
+Drivers for SCI and ADC depend on the FreeRTOS features. These
+features need to be replaced by equivalent features of the new
+operating system. Those files should be modified:
+\begin{description}
+\item[\repo/rpp/lib/rpp/include/sys/ti\_drv\_sci.h] Defines a data
+ structure, referring to FreeRTOS queue and semaphore.
+\item[\repo/rpp/lib/rpp/src/sys/ti\_drv\_sci.c] Uses FreeRTOS queues
+ and semaphores.
+\item[\repo/rpp/lib/rpp/include/drv/sci.h] Declaration of
+ \texttt{drv\_sci\_receive()} contains \texttt{portTick\-Type}. We
+ suggest replacing this with OS independent type, e.g. number of
+ milliseconds to wait, with $-1$ meaning infinite waiting time.
+\item[\repo/rpp/lib/rpp/src/drv/sci.c] Uses the following FreeRTOS
+ specific features: semaphores, queues, data types
+ (\texttt{portBASE\_TYPE}) and
+ critical sections (\texttt{taskENTER\_CRITICAL} and
+ \texttt{task\-EXIT\_CRITICAL}). Inside FreeRTOS critical sections,
+ task preemption is disabled. The same should be ensured by the other
+ operating system or the driver should be rewritten to use other
+ synchronization primitives.
+\item[\repo/rpp/lib/rpp/src/drv/adc.c] Uses FreeRTOS semaphores.
+\end{description}
+
+\subsection{System start}
+The initialization of the MCU and the system is in the
+\texttt{\repo/rpp/lib/rpp/src/sys/sys\_startup.c} file. If the new
+operating system needs to handle interrupts generated by the Real-Time
+Interrupt module, the pointer to the Interrupt Service Routine (ISR)
+\texttt{vPreemptiveTick} has to be replaced.
+
+\subsection{Simulink template for main function}
+
+When the operating system in the library is replaced, the users of the
+library must be changed as well. In case of Simulink code generation
+target, described in Chapter~\ref{chap-simulink-coder-target}, the
+template for generation of the \texttt{ert\_main.c} file, containing
+the main function, has to be modified to use proper functions for task
+creation, task timing and semaphores. The template is stored in
+\texttt{\repo/rpp/rpp/rpp\_mrmain.tlc} file.
+
\chapter{Simulink Coder Target}
\label{chap-simulink-coder-target}
-The Simulink Coder Target allows to convert Simulink models to a C code,
+The Simulink Coder Target allows to convert Simulink models to C code,
compile it and download to the board.
\section{Introduction}
This target also provides support for automatic download of the compiled binary to the RPP
board.
-\begin{figure}[H]\begin{center}
+\begin{figure}\begin{center}
\noindent
-\includegraphics[width=300px]{images/tlc_process.png}
+\includegraphics[scale=.45]{images/tlc_process.png}
\caption{TLC code generation process. \cite[p. 1-6]{targetlanguagecompiler2013}}
\end{center}\end{figure}
\begin{itemize}
\item Sampling frequencies up to 1\,kHz.
-\item Supports only single-tasking and single-rate systems. Support
- for single-rate systems will be available in the final version.
- Support for multitasking system will require careful audit of the
- RPP library with respect to thread-safe code.
+\item Multi-rate models can be executed in a single or multiple OS
+ tasks. Multi-tasking mode allows high-rate tasks to preempt low-rate
+ tasks. See Section \ref{sec-singlet-multit-modes} for more details.
\item No External mode support yet. We work on it.
\item Custom compiler options, available via OPTS variable in
\emph{Make command} at \emph{Code Generation} tab (see Figure
wrapper on the \texttt{loadti.sh}, \texttt{loadti.bat} and \texttt{loadopenocd.sh} script. More information on the \texttt{loadti.sh}
script can be found in:
\begin{verbatim}
-<css>/ccs_base/scripting/examples/loadti/readme.txt
+<ccs>/ccs_base/scripting/examples/loadti/readme.txt
http://processors.wiki.ti.com/index.php/Loadti
\end{verbatim}
\item \textbf{Download compiled binary to SDRAM}: This feature is not yet
implemented for the simulink target.
-\item \textbf{Use OpenOCD to download the compiled binary}: This option switches
-from Ti loading script \texttt{loadti.sh} to OpenOCD script
-\texttt{loadopenocd.sh}. The benefit of using OpenOCD, besides that it is open
-source
- software, is much shorter loading time. More information about the right
-OpenOCD version and its installation can be found at:
-\begin{verbatim}
-http://rtime.felk.cvut.cz/hw/index.php/TMS570LS3137#OpenOCD_setup_and_Flashing
-\end{verbatim}
-This feature is available for Linux system only.
+\item \textbf{Use OpenOCD to download the compiled binary}: This feature is not yet
+implemented for the \mcuname{} simulink target.
+% TODO Not true - use conditional compilation here.
\item \textbf{Print model metadata to SCI at start}: if set this option will
print a message to the Serial Communication Interface when the model start
reading.
\item[refs/] Contains third party references, which license allows the
distribution.
- \item[rpp/blocks] Contains the TLC files, which defines the blocks for
-the Matlab Simulink and \texttt{rpp\_lib.slx}, which is the Simulink RPP
-Library, containing all the Simulink blocks for RPP.
+\item[rpp/blocks] Contains the Simulink blocks specific to the
+ \tgtBoardName{} board and their sources (.c and .tlc files). When an
+ user calls \texttt{rpp\_setup.m}, these files are processed and
+ Simulink block library \texttt{rpp\_lib.slx} is created.
\item[rpp/blocks/tlc\_c]Contains the templates for C code generation from the
Matlab Simulink model.
\item[rpp/demos] Contains demo models, which purpose is to serve as a
\item[rpp/rpp] Contains set of support script for the Code Generator.
\end{description}
+\section{Tasking modes}
+\label{sec-singlet-multit-modes}
+
+This section describes two different modes (single- and multi-tasking)
+of how generated code of multi-rate models can be executed. Tasking
+mode can be selected for every model in the configuration dialog as
+described in Section \ref{sec-crating-new-model}.
+
+For single-rate models, the mode selection does not matter. For
+multi-rate models, the mode selection becomes important as it may
+influence certain system properties such as safety or performance.
+
+\subsection{SingleTasking mode}
+\label{sec-singlet-mode}
+In this mode all Simulink tasks, defined by their sampling rate, run
+in a single operating system task (thread). This means that the period
+of the highest rate Simulink task cannot be greater than the
+worst-case execution time of all Simulink tasks together. On the other
+hand, using this mode reduces the risk of failures caused by task
+synchronization errors, e.g. race conditions, deadlocks.
+
+\subsection{MultiTasking mode}
+\label{sec-multit-mode}
+
+In this mode every Simulink task, defined by its sampling rate, runs
+in its own operating system task (thread). Thread priorities are
+assigned based on task rates in such a way that tasks with higher
+rates can preempt tasks with lower rates. This means that the period
+of the fastest sampling rate is limited only by the execution time of
+this task and not of all the tasks in the system.
+
+This mode offers more efficient use of system resources (CPU) but
+there is a possibility of failures caused by task synchronization
+errors.
+
\section{Block Library Overview}
\label{sec-block-library-overview}
The Simulink Block Library is a set of blocks that allows Simulink models to use
\item S-Function: System Function, as opposed to standard functions, or user functions.
\end{compactitem}
-A C-MEX S-Function is a structured C file that implements some mandatory and
+A C MEX S-Function is a structured C file that implements some mandatory and
optional callbacks for a specification of a number of inputs, outputs, data
types, parameters, rate, validity checking, etc. A complete list of callbacks
can be found in:
\htmladdnormallink{http://www.mathworks.com/help/simulink/create-cc-s-functions.html}{http://www.mathworks.com/help/simulink/create-cc-s-functions.html}
\end{quotation}
-The way a C-MEX S-Function participates in a Simulink simulation is shown on the
+The way a C MEX S-Function participates in a Simulink simulation is shown on the
diagram \ref{fig-sfunctions-process}:
\begin{figure}[H]\begin{center}
\noindent
-\includegraphics[width=250px]{images/sfunctions_process.png}
+\includegraphics[scale=.45]{images/sfunctions_process.png}
\caption{Simulation cycle of a S-Function. \cite[p. 57]{simulinkdevelopingsfunctions2013}}
\label{fig-sfunctions-process}
\end{center}\end{figure}
\item Include trailer file \texttt{trailer.c}.
\end{itemize}
-The C-MEX S-Function implemented can be compiled with the following command:
+The C MEX S-Function implemented can be compiled with the following command:
\lstset{language=bash}
\begin{lstlisting}
In order to generate code for each one of the S-Functions, every S-Function implements a TLC file
for \textit{inlining} the S-Function on the generated code. The TLC files describe how to
-generate code for a specific C-MEX S-Function block. They are programmed using TLC own language and
+generate code for a specific C MEX S-Function block. They are programmed using TLC own language and
include C code within TLC instructions, just like LaTeX files include normal text in between LaTeX
macros.
\item \texttt{Outputs}: \newline{}
Code here will be placed in the \texttt{void
$\langle$modelname$\rangle$\_step(void)} function. Should be used to get the
-inputs o a block and/or to set the outputs of that block.
+inputs of a block and/or to set the outputs of that block.
\end{itemize}
-The general layout of the TLC files implemented for this project are:
+The general layout of the TLC files implemented for this project is:
\begin{itemize}
\item In \texttt{BlockTypeSetup}: \newline{}
Call common function \texttt{\%$<$RppCommonBlockTypeSetup(block, system)$>$} that will include the
This function is called only once before the first step is issued. Default values for blocks IOs
should be placed here.
\item \texttt{void $\langle$modelname$\rangle$\_terminate(void)}: \newline{}
- This function is called when terminating the model. This should be used to free memory of revert
- other operations made on the initialization function. With current implementation this function
+ This function is called when terminating the model. This should be used to free memory or revert
+ other operations made in the initialization function. With current implementation this function
should never be called unless an error is detected and in most models it is empty.
\end{compactitem}
"C:\ti\ccsv5\utils\bin\"gmake.exe lib
\end{lstlisting}
-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}.
+Both commands will create a directory for each compiled demo, which will contain 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}.
\end{enumerate}
+ \section{Adding new functionality}
+\label{sec:adding-new-funct}
+This section describes how to create new Simulink blocks and how to add them to the RPP
+blocks library. The new block creation process consists of several steps:
+\begin{enumerate}
+ \item Addition of the new functionality to the RPP C support library.
+ \item Definition of the block interface as a C MEX S-Function
+ (Section~\ref{sec:block-definition-c})
+ \item Compilation of the block definition to MEX file
+ (Section~\ref{sec:c-mex-file})
+ \item Creation of the code generator template (TLC) file
+ (Section~\ref{sec:tlc-file-creation}).
+ \item Creation of an S-Function block in the RPP block library
+ and ``connecting'' this block with the C MEX and TLC files
+ (Section~\ref{sec:creation-an-s})
+ \item Optional: Creation of the mask for the new block. The mask
+ specifies graphical representation of the block as well as
+ the content of the block parameters dialog box.
+\end{enumerate}
+The following subsections demonstrate the procedure on an example of a simple user defined block.
+
+\subsection{Block interface definition in a C MEX S-function}
+\label{sec:block-definition-c}
+In order to use a custom block in the Simulink model, Simulink must know
+a certain number of block attributes, such as the number and type of
+block inputs, outputs and parameters. These attributes are specified
+by a set of functions in a C file. This C file gets compiled by the MEX
+compiler into a MEX file and is then used in an S-Function block.
+Simulink calls the functions in the C MEX file to obtain the above
+mentioned block attributes. In case of RPP blocks, no other
+functionality is present in the C MEX file.
+
+The C files are stored in \texttt{\repo/rpp/blocks} directory and are named as
+\texttt{sfunction\_$\langle$name$\rangle$.c}. Feel free to open any of
+the C files as a reference.
+
+Every C file that will be used with the RPP library should begin with
+a comment in YAML\footnote{\url{http://yaml.org/},
+ \url{https://en.wikipedia.org/wiki/YAML}} format. The information in
+this block is used to automatically generate both printed and on-line
+documentation. Although this block is not mandatory, it is highly
+recommended, as it helps keeping the documentation consistent and
+up-to-date.
+
+The YAML documentation block may look like this:
+\begin{lstlisting}[language=c,basicstyle=\tt\footnotesize]
+/*
+%YAML 1.2
+---
+Name: Name Of The Block
+Category: IO blocks
+Header: rpp/sci.h
+Mnemonic: MBLK
+
+Inputs:
+ - { name: "Some Input Signal", type: "bool" }
+
+Outputs:
+ - { name: "Some Output Signal", type: "bool" }
+
+Parameters:
+
+# Description and Help is in Markdown mark-up
+Description: |
+
+ This is a stub of an example block.
+
+Help: |
+
+ This block is a part of an example about how to create
+ new Matlab Simulink blocks for RPP board.
+
+Status: Unstable
+
+RPP API functions used:
+ - rpp_sci_print()
+
+Relevant demos:
+...
+*/
+\end{lstlisting}
+
+Following parts are obligatory and the block will not work without them. It starts with a
+definition of the block name and inclusion of a common source file:
+
+\begin{lstlisting}[language=c]
+#define S_FUNCTION_NAME sfunction_myblock
+#include "header.c"
+\end{lstlisting}
+
+To let Simulink know the type of the inputs, outputs and how many parameters
+will the block have, the \texttt{mdlInitializeSizes()} function has to be defined like this:
+
+\begin{lstlisting}[language=c]
+static void mdlInitializeSizes(SimStruct *S)
+{
+ /* The block will have no parameters. */
+ if (!rppSetNumParams(S, 0)) {
+ return;
+ }
+ /* The block will have one input signal. */
+ if (!ssSetNumInputPorts(S, 1)) {
+ return;
+ }
+ /* The input signal will be of type boolean */
+ rppAddInputPort(S, 0, SS_BOOLEAN);
+ /* The block will have one output signal */
+ if (!ssSetNumOutputPorts(S, 1)) {
+ return;
+ }
+ /* The output signal will be of type boolean */
+ rppAddOutputPort(S, 0, SS_BOOLEAN);
+
+ rppSetStandardOptions(S);
+}
+\end{lstlisting}
+
+The C file may contain several other optional functions definitions for parameters check,
+run-time parameters definition and so on. For information about those functions refer the comments
+in the header.c file, trailer.c file and documentation of Simulink S-Functions.
+
+The minimal C file compilable into C MEX has to contain following
+macros to avoid linker error messages about some of the optional
+functions not being defined:
+\begin{lstlisting}[language=c]
+#define COMMON_MDLINITIALIZESAMPLETIMES_INHERIT
+#define UNUSED_MDLCHECKPARAMETERS
+#define UNUSED_MDLOUTPUTS
+#define UNUSED_MDLTERMINATE
+\end{lstlisting}
+
+Every C file should end by inclusion of a common trailer source file:
+
+\begin{lstlisting}[language=c]
+#include "trailer.c"
+\end{lstlisting}
+
+\subsection{C MEX file compilation}
+\label{sec:c-mex-file}
+In order to compile the created C file, the development environment
+has to be configured first as described in
+Section~\ref{sec-matlab-simulink-usage}.
+
+All C files in the directory \texttt{\repo/rpp/blocks} can be compiled
+into C MEX by running script
+\texttt{\repo/rpp/blocks/compile\_blocks.m} from Matlab command
+prompt. If your block requires some special compiler options, edit the
+script and add a branch for your block.
+
+To compile only one block run the \texttt{mex sfunction\_myblock.c}
+from Matlab command prompt.
+
+\subsection{TLC file creation}
+\label{sec:tlc-file-creation}
+The TLC file is a template used by the code generator to generate the
+C code for the RPP board. The TLC files are stored in
+\texttt{\repo/rpp/blocks/tlc\_c} folder and their names must be the
+same (except for the extension) as the names of the corresponding
+S-Functions, i.e. \texttt{sfunction\_$\langle$name$\rangle$.tlc}. Feel
+free to open any of the TLC files as a reference.
+
+TLC files for RPP blocks should contain a header:
+\begin{lstlisting}[language=c]
+%implements sfunction_myblock "C"
+%include "common.tlc"
+\end{lstlisting}
+
+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:
+\begin{enumerate}
+ \item BlockTypeSetup
+ \item BlockInstanceSetup
+ \item Start
+ \item Outputs
+\end{enumerate}
+
+For detailed description about each one of those functions, refer to
+\cite{targetlanguagecompiler2013}. A simple TLC file, which generates
+some code may look like this:
+\begin{lstlisting}[language=c]
+%implements sfunction_myblock "C"
+%include "common.tlc"
+
+%function BlockTypeSetup(block, system) void
+ %% Ensure required header files are included
+ %<RppCommonBlockTypeSetup(block, system)>
+ %<LibAddToCommonIncludes("rpp/sci.h")>
+%endfunction
+
+%function Outputs(block, system) Output
+ %if !SLibCodeGenForSim()
+ %assign in_signal = LibBlockInputSignal(0, "", "", 0)
+ %assign out_signal = LibBlockOutputSignal(0, "", "", 0)
+
+ %<out_signal> = !%<in_signal>;
+ rpp_sci_printf("Value: %d\r\n", %<in_signal>);
+%endif
+%endfunction
+%% [EOF]
+\end{lstlisting}
+
+The above template causes the generated code to contain
+\texttt{\#include "rpp/sci.h"} line and whenever the block is
+executed, its output will be the negation of its input and the value
+of the input signal will be printed to the serial line.
+
+\subsection{Creation of an S-Function block in the RPP block library}
+\label{sec:creation-an-s}
+User defined Simulink blocks can be included in the model as
+S-Function blocks. Follow this procedure to create a new block in the
+RPP block library:
+\begin{enumerate}
+\item Create a new Simulink library by selecting
+ \textsc{File$\rightarrow$New$\rightarrow$Library} and save it as
+ \texttt{\repo\-/rpp/blocks/rpp\_$\langle$name$\rangle$.slx}.
+ Alternatively, open an existing library.
+\item In case of opening an existing library, unlock it for editing by
+ choosing \textsc{Diagram$\rightarrow$Unlock Library}.
+\item Open a Simulink Library Browser
+ (\textsc{View$\rightarrow$Library Browser}) open
+ \textsc{Simulink$\rightarrow$User-Defined Functions} and drag the
+ \textsc{S-Function} block into the newly created library.
+\item Double click on the just created \textsc{S-Function} block and
+ fill in the \textsc{S-function name} field. Put there the name
+ (without the extension) of the created C MEX S-Function, e.g.
+ sfunction\_myblock. The result should like like in
+ Figure~\ref{fig-simulink_s_fun_cfg}.
+ \begin{figure}[h]\begin{center}
+ \noindent
+ \includegraphics[scale=.45]{images/simulink_s_fun_config.png}
+ \caption{Configuration dialog for user defined S-function.}
+ \label{fig-simulink_s_fun_cfg}
+ \end{center}\end{figure}
+\item If your block has some parameters, write their names (you can
+ choose them arbitrarily) in the \textsc{S-function parameters}
+ field, separated by commas. \label{item:1}
+\item Now you should see the new Simulink block with the right number
+ of inputs and outputs.
+\item Optional: Every user-defined block can have a \emph{mask}, which
+ provides some useful information about the name of the block,
+ configuration dialog for parameters and names of the IO signals. The
+ block can be used even without the mask, but it is not as user
+ friendly as with proper mask. Right-click the block and select
+ \textsc{Mask$\rightarrow$Create Mask...}. In the definition of
+ parameters, use the same names as in step~\ref{item:1}. See
+ \cite[Section ``Block Masks'']{mathworks13:simul_2013b} for more
+ information.
+\item Save the library and run \texttt{rpp\_setup} (or just
+ \texttt{rpp\_generate\_lib}) from Matlab command line to add the newly
+ created block to RPP block library (\texttt{rpp\_lib.slx}).
+\end{enumerate}
+
+Now, you can start using the new block in Simulink models as described
+in Section~\ref{sec-crating-new-model}.
+
+
\section{Demos reference}
The Simulink RPP Demo Library is a set of Simulink models that use blocks from
the Simulink RPP Block Library and generates code using the Simulink RPP Target.
\subsection{ADC demo}
\begin{figure}[H]\begin{center}
\noindent
-\includegraphics[width=450px]{images/demo_adc.png}
+\includegraphics[scale=.45]{images/demo_adc.png}
\caption{Example of the usage of the Analog Input blocks for RPP.}
\end{center}\end{figure}
\subsection{Simple CAN demo}
\begin{figure}[H]\begin{center}
\noindent
-\includegraphics[width=450px]{images/demo_simple_can.png}
+\includegraphics[scale=.45]{images/demo_simple_can.png}
\caption{The simplest CAN demonstration.}
\end{center}\end{figure}
\subsection{CAN transmit}
\begin{figure}[H]\begin{center}
\noindent
-\includegraphics[width=450px]{images/demo_cantransmit.png}
+\includegraphics[scale=.45]{images/demo_cantransmit.png}
\caption{Example of the usage of the CAN blocks for RPP.}
\end{center}\end{figure}
\item Use function-call mechanism to process received messages
\end{compactenum}
+\subsection{Continuous time demo}
+\begin{figure}[H]\begin{center}
+\noindent
+\includegraphics[scale=.45]{images/demo_continuous.png}
+\caption{The demonstration of contiuous time.}
+\end{center}\end{figure}
+
+\textbf{Description:}
+
+This demo contains two integrators, which are running at continuous time. The main goal
+of this demo is to verify that the generated code is compilable and is working even when
+discrete and continuous time blocks are combined together.
+
\subsection{Simulink Demo model}
\begin{figure}[H]\begin{center}
\noindent
-\includegraphics[width=450px]{images/demo_board.png}
+\includegraphics[scale=.45]{images/demo_board.png}
\caption{Model of the complex demonstration of the boards peripherals.}
\end{center}\end{figure}
\subsection{Echo char}
\begin{figure}[H]\begin{center}
\noindent
-\includegraphics[width=450px]{images/demo_echo_char.png}
+\includegraphics[scale=.45]{images/demo_echo_char.png}
\caption{Echo Character Simulink demo for RPP.}
\end{center}\end{figure}
\subsection{GIO demo}
\begin{figure}[H]\begin{center}
\noindent
-\includegraphics[width=450px]{images/demo_gio.png}
+\includegraphics[scale=.45]{images/demo_gio.png}
\caption{Demonstration of DIN and DOUT blocks}
\end{center}\end{figure}
\subsection{Hello world}
\begin{figure}[H]\begin{center}
\noindent
-\includegraphics[width=450px]{images/demo_hello_world.png}
+\includegraphics[scale=.45]{images/demo_hello_world.png}
\caption{Hello World Simulink demo for RPP.}
\end{center}\end{figure}
character per second. The output speed is driven by the Simulink model step which is set to one
second.
+\subsection{Multi-rate SingleTasking demo}
+\label{sec:mult-single-thre}
+
+\begin{figure}[H]\begin{center}
+\noindent
+\includegraphics[scale=.45]{images/demo_multirate_st.png}
+\caption{Multi-rate SingleTasking Simulink demo for RPP.}
+\end{center}\end{figure}
+
+\textbf{Description:}
+
+This demo will toggle LEDs on the Hercules Development Kit with
+different rate. This is implemented with multiple Simulink tasks, each
+running at different rate. In the generated code, these tasks are
+called from a singe thread and therefore no task can preempt another
+one. See Section \ref{sec-singlet-mode} for more details.
+
+The state of each LED is printed to the Serial Communication Interface
+(115200-8-N-1) when toggled.
+
+\begin{center}
+ \begin{tabular}{lll}
+ \rowcolor[gray]{0.9}
+ LED & pin & rate [s] \\
+ 1 & NHET1\_25 & 0.3 \\
+ 2 & NHET1\_05 & 0.5 \\
+ 3 & NHET1\_00 & 1.0 \\
+ \end{tabular}
+ \captionof{table}{LEDs connection and rate}
+ \label{tab:multirate_st_led_desc}
+\end{center}
+
+\subsection{Multi-rate MultiTasking demo}
+\label{sec:mult-multi-thre}
+
+\begin{figure}[H]\begin{center}
+\noindent
+\includegraphics[scale=.45]{images/demo_multirate_mt.png}
+\caption{Multi-rate MultiTasking Simulink demo for RPP.}
+\label{fig:multitasking-demo}
+\end{center}\end{figure}
+
+\textbf{Description:}
+
+This demo toggles LEDs on the Hercules Development Kit with different
+rate (different colors in Figure~\ref{fig:multitasking-demo}). This is
+implemented with multiple Simulink tasks, each running at different
+rate. In the generated code, every subrate task runs in its own
+operating system thread. See Section \ref{sec-multit-mode} for more
+details.
+
+The state of each LED is also printed to the Serial Communication
+Interface (115200-8-N-1) when toggled.
+
+\begin{center}
+ \begin{tabular}{lll}
+ \rowcolor[gray]{0.9}
+ LED & pin & rate [s] \\
+ 1 & NHET1\_25 & 0.3 \\
+ 2 & NHET1\_05 & 0.5 \\
+ 3 & NHET1\_00 & 1.0 \\
+ \end{tabular}
+ \captionof{table}{LEDs connection and rate}
+ \label{tab:multirate_mt_led_desc}
+\end{center}
+
+\subsection{Hydraulics controller initialization demo}
+\label{sec:board-init-hydctr}
+\begin{figure}[H]
+ \centering
+ \includegraphics[scale=0.45]{images/demo_board_init_hydctr.png}
+ \caption{board\_init\_hydctr demo}
+ \label{fig:board_init_hydctr}
+\end{figure}
+
+\paragraph{Description}
+
+This demo shows how to use the \emph{Board Init} block to initialize
+SPI devices on the Hydraulics Controller board. Additionally, it shows
+how to use unused SPI pins on the MCU as general-purpose IOs. If both
+Board Init and GIO SPI blocks are used together, care must be taken
+about the order in which the blocks are initialized. GIO blocks that
+represent SPI pins must be initialized \emph{after} the Board Init
+block. This can be ensured by giving the GIO blocks higher priority
+than the Board Init block.
+
\chapter{Command line testing tool}
\label{chap-rpp-test-software}
\section{Introduction}
\label{sec-rpp-test-sw-intro}
The \texttt{rpp-test-suite} is a RPP application developed testing and direct
control of the RPP hardware. The test suite implements a command processor,
-which is listening for a commands and prints some output related to the commands
+which is listening for commands and prints some output related to the commands
on the serial interface. The command processor is modular and each peripheral
-has its commands in a separated module.
+has its commands in a separate module.
The command processor is implemented in \texttt{$\langle$rpp-test-sw$\rangle$/cmdproc} and commands
modules are implemented in \texttt{$\langle$rpp-test-sw$\rangle$/commands} directory.
\textbf{115200-8-N-1}. When the software starts, the received welcome message
and prompt should look like:
+
+\ifx\tgtId\tgtIdTMSRPP
+\begin{verbatim}
+Rapid Prototyping Platform v00.01-001
+Test Software version v0.2-261-gb6361ca
+CTU in Prague 2014
+-->
+\end{verbatim}
+\else
\begin{verbatim}
-TODO: FILL
+Ti HDK \mcuname, FreeRTOS 7.0.2
+Test Software version eaton-0.1-beta-8-g91419f5
+CTU in Prague 10/2014
+-->
\end{verbatim}
+\fi
Type in command help for a complete list of available command, or help command
for a description of concrete command.
\textit{Analog Output.} \newline{}
Mnemonic to refer to or something related to the analog output (DAC) hardware module.
+\item[API] \textit{Application Programming Interface}
+
\item[CAN]
\textit{Controller Area Network.} \newline{}
The CAN Bus is a vehicle bus standard designed to allow microcontrollers and devices to
In this project it is also used as mnemonic to refer to or something related to the CAN
hardware module.
+\item[CCS] \textit{Code Composer Studio} \\
+ Eclipse-based IDE provided by Texas Instruments.
+
\item[CGT]
\textit{Code Generation Tools.} \newline{}
Name given to the tool set produced by Texas Instruments used to compile, link, optimize,
Matlab tool that allows to generate source code for S-Functions given the descriptor of a C
function call.
-\item[LIN]
- \textit{Local Interconnect Network.} \newline{}
- The LIN is a serial network protocol used for communication between components in vehicles.
- In this project it is also used as mnemonic to refer to or something related to the LIN
- hardware module.
-
-\item[LOUT]
- \textit{Logic Output.} \newline{}
- Mnemonic to refer to or something related to the digital output hardware module.
- It is logic output (100mA), as opposed to power outputs (2A, 10A).
-
\item[MBD]
\textit{Model-Based Design.} \newline{}
Model-Based Design (MBD) is a mathematical and visual method of addressing problems associated
used is `C MEX S-Function", which means Matlab executable written in C that implements a system
function.
-\item[MOUT]
- \textit{(Motor) Power Output.} \newline{}
- Mnemonic to refer to or something related to the 2A push/pull power output hardware module.
-
\item[PWM]
\textit{Pulse-width modulation.} \newline{}
Technique for getting analog results with digital means. Digital control is used to create a
the time that the signal spends off. The duration of ``on time" is called the pulse width or
\textit{duty cycle}.
-\item[RPP]
- \textit{Rapid Prototyping Platform.} \newline{}
- Name of the automotive hardware board. Also generic term to define something related
- to the board, like the RPP Library, RPP Layer, RPP API, etc.
+\item[RPP] \textit{Rapid Prototyping Platform.} \newline{} Name of the
+ developed platform, that includes both hardware and software.
\item[SCI]
\textit{Serial Communication Interface.} \newline{}