]> rtime.felk.cvut.cz Git - jenkicar/rpp-simulink.git/blobdiff - doc/reports/report/publish/tex/report.tex
Finished documentation. Yay!
[jenkicar/rpp-simulink.git] / doc / reports / report / publish / tex / report.tex
index 55d19c55e3643b7e7cf87232f68b79479d52ef4d..dbf89bd7a981c71d1e4a08e5849dde959ce9a3bf 100644 (file)
@@ -1034,6 +1034,8 @@ In general, the following changes were applied to the source code base of all ke
 \hypertarget{api_development_guidelines}{}
 \subsubsection{API development guidelines}
 
+\vspace{-0.40cm}
+
 The following are the development guidelines use for developing the RPP API:
 
 \begin{compactitem}
@@ -1058,9 +1060,13 @@ The following are the development guidelines use for developing the RPP API:
   \texttt{RppConfig.h} configuration file.
 \end{compactitem}
 
+\vspace{-0.40cm}
+
 \hypertarget{further_improvements}{}
 \subsubsection{Further improvements}
 
+\vspace{-0.40cm}
+
 The following are recommendations for future improvements of the library:
 
 \begin{compactitem}
@@ -1076,6 +1082,8 @@ The following are recommendations for future improvements of the library:
   RPP layer (already implemented).
 \end{compactitem}
 
+\vspace{-0.40cm}
+
 Recommendations for changes on the electrical diagrams:
 
 \begin{compactitem}
@@ -1137,9 +1145,8 @@ and size of some sections.
 
 \noindent$\rightarrow$ \texttt{rpp/include/\{layer\}} and \texttt{rpp/src/\{layer\}}
 
-Interface files and implementations files for given \texttt{\{layer\}}.
-
-See below for details on the RPP Layer.
+Interface files and implementations files for given \texttt{\{layer\}}. See below for details on the RPP 
+Layer.
 
 \noindent$\rightarrow$ \texttt{rpp/include/rpp/rpp.h}
 
@@ -2352,7 +2359,73 @@ compile_blocks()
 \hypertarget{target_language_compiler_files}{}
 \subsubsection{Target Language Compiler files}
 
-Anatomy
+C code generated from a Simulink model is placed on a file called \texttt{$<$modelname$>$.c} along with 
+other support files in a folder called \texttt{$<$modelname$>$\_$<$target$>$/}. For example, the source code
+generated for model \texttt{foobar} will be placed in current Matlab directory \texttt{foobar\_rpp/foobar.c}.
+
+The file \texttt{$<$modelname$>$.c} has 3 main functions:
+
+\begin{compactitem}
+\item \texttt{void $<$modelname$>$\_step(void)}: \newline{}
+  This function recalculates all the outputs of the blocks and should be called once per step. This
+  is the main working function.
+\item \texttt{void $<$modelname$>$\_initialize(void)}: \newline{}
+  This function is called only once before the first step is issued. Default values for blocks IOs
+  should be placed here.
+\item \texttt{void $<$modelname$>$\_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
+  should never be called unless an errors is detected and in most models it is empty.
+\end{compactitem}
+
+In order to generate code for each one of those functions each S-Function implement a TLC file
+for \textit{inlining} the S-Function on the generated code. The TLC files are files that describe how to 
+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.
+
+TLC files are located under \texttt{$<$repo$>$/rpp/blocks/tlc\_c/} directory. For a diagram on how TLC files 
+work see \htmladdnormallink{Code generation process}{\#code\_generation\_process} section.
+
+The standard for a TLC file is to be located under the \texttt{tlc\_c} subfolder from where the 
+S-Function is located and to use the very exact file name as the S-Function but with the \texttt{.tlc}
+extension:
+
+\texttt{sfunction\_foo.c} \noindent$\rightarrow$ \texttt{tlc\_c/sfunction\_foo.tlc}
+
+The TLC files implemented for this project use 3 hook functions in particular (other are available, 
+see TLC reference documentation):
+
+\begin{itemize}
+\item \texttt{BlockTypeSetup}: \newline{}
+  BlockTypeSetup executes once per block type before code generation begins.
+  This function can be used to include elements required by this block type, like includes or
+  definitions.
+
+\item \texttt{Start}: \newline{}
+  Code here will be placed in the \texttt{void $<$modelname$>$\_initialize(void)}. Code placed here will
+  execute only once.
+
+\item \texttt{Outputs}: \newline{}
+  Code here will be placed in the \texttt{void $<$modelname$>$\_step(void)} function. Should be used to 
+  get the inputs o 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:
+
+\begin{itemize}
+\item In \texttt{BlockTypeSetup}: \newline{}
+  Call common function \texttt{\%$<$RppCommonBlockTypeSetup(block, system)$>$} that will include the 
+  \texttt{rpp/rpp.h} header file (can be called multiple times but header is included only once).
+
+\item \texttt{Start}: \newline{}
+  Call setup routines from RPP Layer for the specific block type, like HBR enable, DIN pin setup, 
+  AOUT value initialization, SCI baud rate setup, among others.
+
+\item \texttt{Outputs}: \newline{}
+  Call common IO routines from RPP Layer, like DIN read, AOUT set, etc. Success of this functions
+  is checked and in case of failure error is reported to the block using ErrFlag.
+\end{itemize}
 
 \newpage
 
@@ -2371,7 +2444,7 @@ optional functions and commented prototypes for optional model calls/hooks.
 \begin{compactitem}
 \item \underline{Reference:}
  \begin{compactitem}
- \item None.
+ \item See header of those files.
  \end{compactitem}
 \end{compactitem}
 
@@ -2379,8 +2452,8 @@ optional functions and commented prototypes for optional model calls/hooks.
 
 C-MEX S-Function implementation for \{mnemonic\} block.
 
-This file implements the \{mnemonic\} block using C-MEX S-Function API. See the reference for information
-about the S-Function API.
+This file implements the \{mnemonic\} block using C-MEX S-Function API. See the reference for 
+information about the S-Function API.
 
 \begin{compactitem}
 \item \underline{Reference:}
@@ -2393,8 +2466,8 @@ about the S-Function API.
 
 Target Language Compiler (TLC) file for \{mnemonic\} block.
 
-This file implements the C code inlining for \{mnemonic\} block. See the reference for information about
-the TLC API.
+This file implements the C code inlining for \{mnemonic\} block. See the reference for information 
+about the TLC API.
 
 \begin{compactitem}
 \item \underline{Reference:}
@@ -2416,6 +2489,7 @@ This file implements common TLC functions used by all the blocks.
  \end{compactitem}
 \end{compactitem}
 
+\newpage
 \noindent$\rightarrow$ \texttt{slblocks.m}
 
 Simulink library control file.