]> rtime.felk.cvut.cz Git - pes-rpp/rpp-simulink.git/blob - doc/reports/report/report.t2t
7211ca9fe6d4d7e1b0c77c356eda3a4a5f512850
[pes-rpp/rpp-simulink.git] / doc / reports / report / report.t2t
1 Final Report
2 Carlos Jenkins
3 %%date(%B, %Y)
4
5 %!target: tex
6 %!style(xhtmls): media/themes/Clean/style.css
7 %!postproc(xhtmls): 'NEWPAGE' ''
8 %!nested(xhtmls): --libs syntaxhighlighter
9 %!options(tex): --enum-title --toc --toc-level 5
10 %!postproc(tex): '\.pdf\.png' '.pdf'
11 %!postproc(tex): 'NEWPAGE' '\\newpage'
12 %!postproc(tex): '-\$>\$' '\\noindent$\\rightarrow$'
13 %!postproc(tex): 'TAB' '\\hspace{1.0em}'
14 %!nested(tex): --docclass {article} --pdf
15
16 %S = Table of contents =[table_of_contents]
17
18 %DONE
19
20 %Table of contents
21 %%toc
22
23 NEWPAGE
24
25 %Table of contents
26 %tex% ''' \listoffigures
27
28 NEWPAGE
29
30 = Introduction =[introduction]
31
32 %DONE
33
34 This document describes the final results of the project ``Code generation for automotive rapid 
35 prototyping platform using Matlab/Simulink".
36
37
38 == Background ==[background]
39
40 %DONE
41
42 Back in the beginning of 2012 a leading automotive company requested the Czech Technical University 
43 to develop a Engine Control Unit (ECU) for automotive applications. Real-Time Systems group at the 
44 Department of Control Engineering from the Faculty of Electrical Engineering developed a hardware 
45 and Software platform to the needs of this industry. The hardware uses Texas Instruments 
46 TMS570LS3137 CPU and is built with automotive standards and interfaces in mind. It uses a real-time 
47 operating system and was directly programmed in C.
48
49 Nevertheless, in accordance to company policies the Software developed for the engine control unit 
50 must be designed in a safe and auditable way. The company has the policy to implement the Software 
51 for their system using Model-Based Design:
52
53         Model-Based Design (MBD) is a mathematical and visual method of addressing 
54         problems associated with designing complex control, signal processing and 
55         communication systems. It is used in many motion control, industrial equipment, 
56         aerospace, and automotive applications. Model-based design is a methodology 
57         applied in designing embedded software.
58
59 In order to meet this requirement an interaction layer between the platform and the Software the 
60 company uses, Matlab/Simulink, must be implemented. This document describes the implementation of 
61 this interaction system.
62
63 == Technologies involved ==[technologies_involved]
64
65 %DONE
66
67 + Matlab/Simulink data flow graphical programming language tool for modeling, simulating and 
68   analyzing multidomain dynamic systems.
69 + Standard ANSI C programming.
70 + FreeRTOS real-time operating system.
71 + Texas Instruments TI Code Generation Tools (CGT).
72 + RPP in-house automotive hardware board using Texas Instruments TMS570LS3137 CPU.
73
74
75
76 NEWPAGE
77
78 == Objectives ==[objectives]
79
80 %DONE
81
82 Main objectives of this project are:
83
84 + Allow C code generation from Matlab/Simulink models for custom made hardware platform.
85 + Implement model blocks for some of the peripheral units of the board for use in Simulink 
86   programming.
87
88
89 At the time of this writing the objectives of this project are considered successfully achieved.
90
91 == Benefits ==[benefits]
92
93 %DONE
94
95 Expected benefits of this project are:
96
97 + Enabling faster implementation and rapid-prototyping of Software components through the use of 
98   model-based programming.
99 + Enabling better and clearer visualization of Software implementations for the hardware board 
100   through models.
101 + Improve auditability of Software system for automotive applications.
102
103
104 At the time of this writing the benefits of this project are considered enabled.
105
106 == Final outcome ==[final_outcome]
107
108 %DONE
109
110 The main products generated for this project are:
111
112 - **C Support Library**: @@
113   Define the API to communicate with the board. Include drivers and operating system.
114
115 - **Simulink Coder Target**: @@
116   Allows Simulink model's code generation, compilation and download for the board.
117
118 - **Simulink Block Library**: @@
119   Set of blocks that allows Simulink models to use board IO and communication peripherals.
120
121 - **Simulink Demos Library**: @@
122   Just a bunch of examples of control application in form of Simulink models.
123
124
125 Each of this product is described deeply in the following sections.
126
127 NEWPAGE
128
129 == Document layout ==[document_layout]
130
131 %DONE
132
133 The general layout of this document is as follows:
134
135 - Project description, objectives and outcome. This section.
136 - Software and Hardware setup for development, repository layout and programming standards.
137 - A section for each of the four products delivered, with:
138  - Implementation fundamentals.
139  - Repository branch description.
140  - Product specific aspects.
141  - Reference documentation.
142 - Glossary.
143 - References.
144 - Appendices.
145
146
147 NEWPAGE
148
149 = Project setup =[project_setup]
150
151 %DONE
152
153 This sections describes the Software and Hardware aspects required to undertake development for 
154 this project. It considers:
155
156 - Software development environment.
157 - Hardware reference documentation and wiring for development.
158 - Repository's general layout.
159
160
161 == Development environment ==[development_environment]
162
163 %DONE
164
165 This section describes the Software environment setup for development.
166
167 === Operating system ===[operating_system]
168
169 %DONE
170
171 This project was developed on a GNU/Linux operating system. For development it is recommended to 
172 use a Debian based operating system for development as most of the tools are easily available from 
173 repositories. 
174
175 Relevant OS information on which this project was developed:
176
177 - Ubuntu 12.04.2 LTS AMD64.
178 - Kernel 3.2.0-48-generic.
179 - GCC version 4.6.3.
180
181
182 No test for cross-platform interoperability was performed on the code developed. Although care was 
183 taken to try to provide platform independent code and tools there is elements known to be Linux 
184 dependent. For a list of this elements refer to 
185 [Appendix B: Known operating-system dependent files #appendix_b_known_operating_system_dependent_files].
186
187 === Version Control System ===[version_control_system]
188
189 %DONE
190
191 The version control system used for this project is **git**. The repository of this project 
192 contains all the files produced during development, including documentation, references, code and 
193 graphics. Also, the GUI application **giggle** was used to easily review changes. To install both 
194 execute on a terminal:
195
196 {{{ bash
197 sudo apt-get install git giggle
198 }}}
199
200 NEWPAGE
201
202 === TI Code Composer Studio ===[ti_code_composer_studio]
203
204 %DONE
205
206 Code Composer Studio (CCS) is the official Integrated Development Environment (IDE) for developing 
207 applications for Texas Instruments embedded processors. CCS is multiplatform Software based on 
208 Eclipse Open Source IDE.
209
210 The version used in this project is the 5.3.0. Download and install CCS for Linux from:
211
212         http://processors.wiki.ti.com/index.php/Category:Code_Composer_Studio_v5
213
214 CCS download requires a valid MyTI account. Tedious. CCS download is about 1.5GB. Once downloaded 
215 extract the content of the ``tar.gz`` archiver and run ``css_setup_<version>.bin`` script as 
216 __root__. Installation must done as root in order to install driver set.
217
218 After installation the application can be executed with:
219
220 {{{ bash
221 cd <ccs>/ccsv5/eclipse/
222 ./ccstudio
223 }}}
224
225 If the application fails to start on 64bits systems is because CCS5 is a 32bits application a thus 
226 requires 32bits libraries:
227
228 {{{ bash
229 sudo apt-get install libgtk2.0-0:i386 libxtst6:i386
230 }}}
231
232 If the application crashes with a segmentation fault edit file:
233
234 {{{ bash
235 nano <ccs>/ccsv5/eclipse/plugins/com.ti.ccstudio.branding_<version>/plugin_customization.ini
236 }}}
237
238 And change key ``org.eclipse.ui/showIntro`` to false.
239
240 Choose ``FREE License - for use with XDS100 JTAG Emulators" on the licensing options. Code download 
241 for the board is uses that particular hardware. See [Development wiring #development_wiring] for 
242 more details on this hardware.
243
244 CCS include Texas Instruments Code Generation Tools (CGT) (compiler, linker, etc). Simulink code 
245 generation requires the CGT to be available in the system, and thus, even if no library development 
246 will be done or the IDE is not going to be used CCS is still required. @@
247 See ``<repo>/rpp/rpp/README.txt`` file for more information.
248
249 You can find documentation for CGT compiler in ``<repo>/ref/armcl.pdf`` and for CGT archiver in 
250 ``<repo>/ref/armar.pdf``.
251
252
253 === Matlab/Simulink ===[matlabsimulink]
254
255 %DONE
256
257 Matlab/Simulink version used is R2012b for Linux 64 bits. For in-house development the CVUT should 
258 provide a network licensing server descriptor file.
259
260 === GtkTerm ===[gtkterm]
261
262 %DONE
263
264 Most of the interaction with the board for development is done through a RS-232 serial connection.
265 The terminal Software used for communication is called GtkTerm.
266
267 The default configuration for the board serial communication module is 9600-8-N-1. Note that the 
268 RPP Library test suite is setup to 115200-8-N-1.
269
270 To install GtkTerm execute:
271
272 {{{ bash
273 sudo apt-get install gtkterm
274 }}}
275
276         
277
278 === Doxygen ===[doxygen]
279
280 %DONE
281
282 Doxygen is the name of the documentation generator used to generate the RPP API documentation based 
283 on the source code files. The generated API include dependency graphs and thus it also requires 
284 Graphviz, a graph drawing tool. To install both execute:
285
286 {{{ bash
287 sudo apt-get install doxygen graphviz
288 }}}
289
290 See [API generation #api_generation] on how to use Doxygen to generate the API Reference 
291 documentation.
292
293 NEWPAGE
294
295 === Nested ===[nested]
296
297 %DONE
298
299 Nested is the documentation editor used to create the document you're reading. It features a plain 
300 text version control friendly simple to read non-cluttered format, WYSIWYM paradigm, divide and 
301 conquer document creation approach, a nested (non-linear) document tree and content/presentation 
302 separation scheme and thus documents can be published to LaTeX, PDF or HTML. Nested is a tool 
303 created by the author of this report.
304
305 To install Nested first install dependencies:
306
307 {{{ bash
308 sudo apt-get install python2.7 python-gtk2 python-webkit python-gtkspellcheck texlive-publishers texlive texlive-latex-extra rubber iso-codes subversion
309 }}}
310
311 Then get the latest revision from the stable repository:
312
313 {{{ bash
314 svn checkout svn://svn.code.sf.net/p/nestededitor/code/trunk nested
315 }}}
316
317 Run Nested with:
318
319 {{{ bash
320 cd nested/nested/
321 ./nested
322 }}}
323
324 Nested sources for this document can be found on the repository under 
325 ``<repo>/doc/reports/report/``.
326
327
328 === LMC1 ===[lmc1]
329
330 %DONE
331
332 The LMC1 is a simple script developed for this project written in Python 3 using Gtk+ 3.0 Python 
333 dynamic bindings PyGObject. This script, based on Michal Horn's command line script, allows to set 
334 or clear the outputs of the test board. 
335
336 This script includes both a GUI and command line tool. If no parameters are given to the script the 
337 GUI version is launched:
338
339 %tex% ''' \begin{figure}[H]\begin{center}
340 [350-lmc1.png]
341 %tex% ''' \caption{LMC1 GUI application.}\end{center}\end{figure}
342
343 To run the LMC1 application first install dependencies:
344
345 {{{ bash
346 apt-get install python3 python3-gi python3-serial
347 }}}
348
349 To launch LMC1 GUI version double click file:
350
351 ``<repo>/rpp/lib/apps/lmc1/lmc1.py``
352
353 To launch LMC1 command line version type:
354
355 ``<repo>/rpp/lib/apps/lmc1/lmc1.py --help``
356
357
358 NEWPAGE
359
360 == Hardware reference ==[hardware_reference]
361
362 This section provides reference documentation for the RPP board: 
363
364 - Connectors pinout.
365 - Modules capabilities and features.
366 - Wiring configuration for development and testing.
367
368
369 Please note that although this is a hardware reference documentation this is from a Software 
370 development perspective and __**NOT**__ Hardware development perspective. For full hardware details 
371 please refer to schematics and related documentation.
372
373 %tex% ''' \begin{figure}[H]\begin{center}
374 [300-board.png]
375 %tex% ''' \caption{The RPP board (signal connector missing).}\end{center}\end{figure}
376
377 === Connectors pinout ===[connectors_pinout]
378
379 %tex% ''' \begin{figure}[H]\advance\leftskip-1cm
380 [530-pinout.pdf.png]
381 %tex% ''' \caption{The RPP connectors pinout.}\end{figure}
382
383
384 === Modules description ===[modules_description]
385
386
387
388 ==== Logic IO ====[logic_io]
389
390
391
392 ===== 16x digital input (DIN) =====[16x_digital_input_din]
393
394 - Read status via GPIO pin (configurable threshold).
395 - Read status via SPI pin (fixed threshold).
396 - Setting pin programmable via SPI.
397
398
399 ===== 8x digital outputs for loads up to 100 mA (LOUT) =====[8x_digital_outputs_for_loads_up_to_100_ma_lout]
400
401 - Set pin ON.
402 - Set pin OFF.
403 - Reading the SPI status excitation.
404
405 ===== 12x analog-to-digital converter =====[12x_analog_to_digital_converter]
406
407 - Reading values on all channels.
408
409 ===== 4x digital-to-analog converter =====[4x_digital_to_analog_converter]
410
411 - Set the required voltage on all channels.
412
413 ==== Power Output ====[power_output]
414
415
416
417 ===== 1x H-Bridge =====[1x_h_bridge]
418
419 - Setting the direction.
420 - Switch on, off.
421 - Communication with excitation by SPI.
422 - Enable PWM.
423
424
425 ===== 6x outputs for loads up to 2 A (MOUT) =====[6x_outputs_for_loads_up_to_2_a_mout]
426
427 - Set pin ON.
428 - Set pin OFF.
429 - Reading diagnostics values (DIAG).
430
431 ===== 6x output up to 10 A with PWM (HOUT) =====[6x_output_up_to_10_a_with_pwm_hout]
432
433 - Set pin ON.
434 - Set pin OFF.
435 - Reading analog values of current flowing (IFBK).
436 - Reading diagnostics values (DIAG).
437 - Detection of a fault condition.
438 - Turn on the PWM pin.
439
440 ==== Communication ====[communication]
441
442
443
444 ===== 3x CAN High speed =====[3x_can_high_speed]
445
446 - Sending and receiving messages between the CAN bus interfaces.
447 - Recover from error.
448 - Detection of network errors.
449
450 ===== 2x LIN =====[2x_lin]
451
452 - Testing least one LIN using a loop. The second connector is shared with serial interface, which is tested alone communicate with the computer. Detailed testing makes sense to be no support for access to diagnostics unit via Ethernet or other interface.
453
454 ===== 1x FlexRay =====[1x_flexray]
455
456 - Sending and receiving messages between two plates JRVA.
457
458
459 ===== 1x Serial Comm. Interface =====[1x_serial_comm_interface]
460
461
462
463 ===== 1x Ethernet =====[1x_ethernet]
464
465 - To send a packet.
466 - Code for testing Ethernet is the result of this thesis and is therefore not analyzed.
467
468 ==== Data storage/logging ====[data_storagelogging]
469
470
471
472 ===== External Memory SDRAM =====[external_memory_sdram]
473
474 - Determine the total capacity of the module fitted.
475 - Performing a memory test module using the entire address range.
476
477
478 ===== SD Card =====[sd_card]
479
480
481
482 === Development wiring ===[development_wiring]
483
484 How to wire the board for testing.
485
486 === Test wiring ===[test_wiring]
487
488
489
490 == Project repository ==[project_repository]
491
492 %DONE
493
494 This git repository holds all the work done on this project.
495
496 To get the repository:
497
498         ``git clone ssh://git@rtime.felk.cvut.cz/jenkicar/rpp-simulink.git``
499
500 This is a private repository, you require your SSH private key to be authorized. For access please 
501 consult the Real-Time Systems Group, Department of Control Engineering, Faculty of Electrical 
502 Engineering, Czech Technical University in Prague. For details about this git server refer to:
503
504         http://rtime.felk.cvut.cz/hw/index.php/Git_repository_on_this_server
505
506 The general layout of the repository is:
507
508 ```
509         .
510         |__ doc         - Documentation created for this project.
511         |__ refs        - Official reference documentation.
512         \__ rpp
513             |__ blocks  - Simulink Block Set.
514             |__ demos   - Simulink Demos Library.
515             |__ lib     - C support Library and API.
516             \__ rpp     - Simulink Coder Target.
517 ```
518
519 A detailed description of the content of each subfolder under ``rpp/`` can be found in the section
520 //Subdirectory content description// on each dedicated section for the products developed.
521
522 In this document, the root folder on this repository is used as reference for file location and is 
523 referred with the token ``<repo>``.
524
525
526 == Programming standards ==[programming_standards]
527
528
529
530 === TLC files ===[tlc_files]
531
532
533
534 === RPP API ===[rpp_api]
535
536
537
538 === S-Functions ===[s_functions]
539
540 NEWPAGE
541
542 = C Support Library =[c_support_library]
543
544 %DONE
545
546 The RPP C Support Library define the API to communicate with the board. It include drivers and 
547 operating system. This section documents the implementation of this library.
548
549 == Description ==[description]
550
551 %DONE
552
553 The RPP Library is the support library used by Simulink models. It is designed from the board user 
554 perspective and exposes a simplified high-level API to handle the board's peripheral modules in a 
555 safe manner.
556
557 The library as a concept and as a functional unit was introduced by this project. At the beginning 
558 of this project the RPP board had just one application developed for. This application intended for 
559 board testing allows the user to issue low-level commands to control and test the peripherals of 
560 the board. This application was created using a combination of custom code, contributed drivers and 
561 generated code from TI tool HalCoGen. Library functionality, like drivers and hardware access, and 
562 application logic, like command processor and test routines, was largely merged in a single layer, 
563 166 source code files long highly coupled application. In order to develop independent applications 
564 for the RPP board, as it was expected to be each Simulink model, the library logic needed to be 
565 separated from the application logic. This work implied a heavy refactoring on the testing 
566 application in order extract from it the library functionality. Because the application files were 
567 highly coupled in a single layer the refactoring and testing of the library implied roughly 70% of 
568 the work done on this project.
569
570 %tex% ''' \begin{figure}[H]\advance\leftskip-1cm
571 [500-adc_dep_before.png]
572 %tex% ''' \caption{Dependency graph of the ADC driver before refactoring.}\end{figure}
573
574 The above graph shows the dependencies of the ADC driver before the refactoring. Please note the 
575 dependency on ``cmdproc_io_tisci.h`` and ``cmdproc.h``, both application level modules. Also, note 
576 the indirect dependency on the Operating System is being resolved through the application modules.
577
578 %tex% ''' \begin{figure}[H]\begin{center}
579 [150-adc_dep_after.png]
580 %tex% ''' \caption{Dependency graph of the ADC driver after refactoring.}\end{center}\end{figure}
581
582 The above graph shows the current dependencies for the ADC driver in the RPP Library. Please note 
583 that it dependents only on the system layer low-level driver and that the Operating System indirect 
584 dependency is resolved through the library foundations ``base.h``.
585
586 Some other relevant changes introduced with the refactoring are:
587
588 - ADC driver was completely rewritten.
589 - MOUT driver was implemented.
590 - DIN driver was slightly modified and extended.
591 - DAC driver was slightly modified.
592 - HBR driver was largely modified (in particular watchdog functionality).
593 - SCI driver was refactored and extended.
594 - SDR driver was implemented.
595
596
597 Also, once the library functionality could be isolated, the resulting API was too low-level to be 
598 used by applications, in consequence one of the contributions of this projects was the 
599 implementation of a high-level API on top of this low level API: the RPP Layer.
600
601
602 NEWPAGE
603
604 === Architecture ===[architecture]
605
606 %DONE
607
608 The RPP library was structured into 5 layers with the following guidelines:
609
610 - Top-down dependency only. No lower layer depends on anything from upper layers.
611 - 1-1 layer dependency only. The top layer depends exclusively on the bottom layer, not on any 
612   lower level layer (except for a couple of exceptions).
613 - Each layer should provide a unified layer interface (``rpp.h``, ``drv.h``, ``hal.h``, ``sys.h`` 
614   and ``os.h``), so top layers depends on that layer interface and not on individual elements from 
615   that layer.
616
617
618 %tex% ''' \begin{figure}[H]\begin{center}
619 [250-layers.pdf.png]
620 %tex% ''' \caption{The RPP library layers.}\end{center}\end{figure}
621
622
623 As a consequence of this division the source code files and interface files are now placed on 
624 private directories so the previous prefix based inclusion ``drv_din.h`` is replaced by 
625 ``drv/din.h``. With this organization user applications only needs to include the top layer 
626 interface file (``rpp/rpp.h``) to be able to use the library API.
627
628 Please note the sublayer uLut, which is used only by the SPI driver in order to use thread safe 
629 queue mechanisms. Because the FreeRTOS already provides thread safe queues and in order to match 
630 the order parts of the system it would be advisable to drop this dependency in the future.
631
632 NEWPAGE
633
634 === RPP Layer Modules ===[rpp_layer_modules]
635
636 %DONE
637
638 The RPP Layer was structured into 14 different modules from 4 different categories that match the 
639 hardware modules on the board:
640
641 || Category      | Description                        | MNEMONIC 
642  | Logic IO      | Digital Input                      | ``[DIN ]``   |
643  |               | Digital (Logic) Output             | ``[LOUT]``   |
644  |               | Analog Input                       | ``[AIN ]``   |
645  |               | Analog Output                      | ``[AOUT]``   |
646  | Power output  | H-Bridge output                    | ``[HBR ]``   |
647  |               | Power output (12V, 2A)             | ``[MOUT]``   |
648  |               | High-Power output (12V, 10A)       | ``[HOUT]``   |
649  | Communication | CAN Bus                            | ``[CAN ]``   |
650  |               | LIN (Local Interconnect Network)   | ``[LIN ]``   |
651  |               | FlexRay                            | ``[FR  ]``   |
652  |               | Serial Communication Interface     | ``[SCI ]``   |
653  |               | Ethernet                           | ``[ETH ]``   |
654  | Logging       | SD Card                            | ``[SDC ]``   |
655  |               | SD-RAM                             | ``[SDR ]``   |
656
657
658 Please note the mnemonic of each module, as they are constantly used on the Software and 
659 documentation. Also note that only the following modules where implemented as part of this project:
660
661 %tex% ''' \begin{multicols}{2}
662 - DIN.
663 - LOUT.
664 - AIN.
665 - AOUT.
666 - HBR.
667 - MOUT.
668 - SCI.
669 - SDR.
670
671
672 %tex% ''' \end{multicols}
673
674 Modules for which there is a low-level API available on the library but no high-level module was 
675 implemented:
676
677 %tex% ''' \begin{multicols}{2}
678 - CAN.
679 - LIN.
680 - FR.
681
682
683 %tex% ''' \end{multicols}
684
685 Modules that are not yet available on the library at all:
686
687 %tex% ''' \begin{multicols}{2}
688 - ETH (in the works).
689 - SDC.
690 - HOUT (partial).
691
692
693 %tex% ''' \end{multicols}
694
695 The following graphic shows the library modules and the connectors on the hardware they map to.
696
697 %tex% ''' \begin{figure}[H]\advance\leftskip-1cm
698 [500-blocks.pdf.png]
699 %tex% ''' \caption{The RPP Library modules.}\end{figure}
700
701 NEWPAGE
702
703 === OS interchangeable layer ===[os_interchangeable_layer]
704
705 %DONE
706
707 The OS Layer is composed by the FreeRTOS source code files. Because the FreeRTOS exposes an stable
708 API the OS layer can be changed in order to upgrade the Operating System or use a different port of 
709 the OS, without changing the upper layers source code. The OS Layers currently available for the 
710 RPP Library at ``<repo>/rpp/lib/os/`` at the time of this writing are:
711
712 - Version 6.0.4 using POSIX port. This layer is the one that should be used when compiling a 
713   program for x86(_64) simulation. The port uses the ``pthread`` library and because of this the 
714   port is not true real time and this is considered a simulator.
715 - Version 7.0.2 using HalCoGen port for TMS570. This layer is the one currently supported and 
716   tested. It was originally included in the testing application and was generated by an older 
717   version of TI code generation tool HalCoGen.
718 - Version 7.4.0 using HalCoGen port for TMS570. This layer was extracted from a newly generated 
719   project using a newer version of HalCoGen. This layer is untested but //should// work out of the 
720   box.
721 - Version 7.4.2 using ARM Cortex R4 official port for CCS. This layer was created from vanilla 
722   FreeRTOS 7.4.2 release. It is tested but non-working. Ticks are proved to be executed in time but 
723   applications using this kernel runs at full-speed. The reason if this is currently unknown.
724
725
726 The general layout of all the layers are as following:
727
728 - Common source code (kernel):
729
730 ```
731     src/os/croutine.c (Optional)
732     src/os/list.c
733     src/os/queue.c
734     src/os/tasks.c
735     src/os/timers.c (Optional)
736 ```
737
738 Originally found in vanilla distribution in: ``<FreeRTOSRoot>/FreeRTOS/Source``
739
740 - Common interface files:
741
742 ```
743     include/os/croutine.h
744     include/os/FreeRTOS.h
745     include/os/list.h
746     include/os/mpu_wrappers.h
747     include/os/portable.h (with minor editions)
748     include/os/projdefs.h
749     include/os/queue.h
750     include/os/semphr.h
751     include/os/StackMacros.h
752     include/os/task.h
753     include/os/timers.h
754 ```
755
756 Originally found in vanilla distribution in: ``<FreeRTOSRoot>/FreeRTOS/Source/include``
757
758 - Memory management file:
759
760 ```
761     src/os/heap.c (One of 4 version available, see Appendix A).
762 ```
763
764 Originally found in vanilla distribution in: ``<FreeRTOSRoot>/FreeRTOS/Source/portable/MemMang``
765
766 - Port specific files:
767
768 ```
769     src/os/port.c
770     src/os/portASM.asm
771     include/os/portmacro.h
772     include/os/FreeRTOSConfig.h
773 ```
774
775 This depend of the port. In the case of the 7.4.2 TMS570 / ARM Cortex R4 for CCS port:
776
777  - First three files can be found in vanilla distribution in @@
778    ``<FreeRTOSRoot>/FreeRTOS/Source/portable/CCS/ARM_Cortex-R4``.
779  - Last file in ``<FreeRTOSRoot>/FreeRTOS/Demo/CORTEX_R4_RM48_TMS570_CCS5``.
780
781
782 In general, the following changes were applied to the source code base of all kernels:
783
784 - Replaced include directives to adapt to RPP library standard:
785
786 ``#include "`` with ``#include "os/``
787
788 - Line ending character set to UNIX '\n' and tabs replaced by 4 spaces.
789
790
791 NEWPAGE
792
793 === API development guidelines ===[api_development_guidelines]
794
795 %DONE
796
797 The following are the development guidelines use for developing the RPP API:
798
799 - User documentation should be placed in header files, not in source code, and should be Doxygen 
800   formatted using autobrief. Documentation for each function present is mandatory.
801 - Function declarations on the headers files is for public functions only. Do not declare 
802   local/static/private functions on the header.
803 - Documentation on source code files should be non-doxygen formatted and intended for developers, 
804   not users. Documentation here is optional and at the discretion of the developer.
805 - Always use standard data types for IO when possible. Use custom structs as very last resort.
806 - Use prefix based functions names to avoid clash. The prefix is of the form ``[layer]_[module]_``, 
807   for example ``rpp_din_update()`` for the update function of the DIN module in the RPP Layer.
808 - To be very careful about symbol export. Because it is used as a static library the modules should 
809   not export any symbol that is not intended to be used (function) or ``extern``'ed (variable) from 
810   application. As a rule of thumb declare all global variables as static.
811 - Only the RPP Layer symbols are available to user applications. All information related to lower
812   layers is hidden for the application. This is accomplished by conditionally including the layers 
813   elements on the implementations files only and never on the interface files. Never expose any 
814   other layer to the application or the the whole system below that layer will be exposed. In other
815   words, never ``#include "foo/foo.h"`` in any RPP Layer interface file.
816 - Any module is conditionally included by using ``rppCONFIG_INCLUDE_{MNEMONIC}`` directive on the
817   ``RppConfig.h`` configuration file.
818
819
820
821 === Further improvements ===[further_improvements]
822
823 %DONE
824
825 The following are recommendations for future improvements of the library:
826
827 - General code revision to remove local-only methods and variables from being exported.
828 - General code revision and refactoring to normalize the functions naming scheme. Normalize DRV and 
829   HAL to use prefix based scheme, not all the functions and exported variables do. Refactor the SYS 
830   layer, most of it generated by HalCoGen and that uses ``thisNamingScheme`` to use library 
831   standards (see [RPP API #rpp_api] programming standards).
832 - Simplify doxygen documentation on the SYS layer, because is clunky, doesn't add any value and is 
833   repetitive. Move it the header files.
834 - Remove error throwing from wrong parameter input in the DRV layer and assume a 
835   //correct parameter and continue// safe approach. Move all error throwing and validation to the 
836   RPP layer (already implemented).
837
838
839 Recommendations for changes on the electrical diagrams:
840
841 - Change name of GPIO MOUT1_EN to MOUT1_DIAG. 
842 - Change name of GPIO MOUT1_IN to MOUT1_EN.
843
844
845 The current names are misleading.
846
847 == Subdirectory  content description ==[subdirectory__content_description]
848
849 %DONE
850
851 -> ``librpp.a`` and ``rpp-lib.lib``
852
853 Version controlled RPP static libraries.
854
855 The first one is for POSIX simulation, the second one for Simulink models and other ARM/TMS570 
856 applications. This files are placed here by the projects ``apps/rpp-lib_posix`` and 
857 ``apps/rpp-lib`` when built.
858
859
860 -> ``apps/``
861
862 Applications related to the RPP library.
863
864 This include the CCS studio project for generation of the static library and the test suite. See 
865 [Static libraries #static_libraries], [Test Suite #test_suite] and  
866 [Base application #base_application] for more information.
867
868
869 -> ``os/``
870
871 OS layers directory.
872
873 See [OS interchangeable layer #os_interchangeable_layer] for more information.
874
875
876 -> ``rpp/`` 
877
878 Main directory for the RPP Library.
879
880
881 -> ``rpp/doc/`` 
882
883 Documentation directory for the RPP Library. See [API generation #api_generation] for more 
884 information.
885
886
887 -> ``rpp/TMS570LS3137.ccxml``
888
889 Descriptor for code download. 
890
891 This file is used by all the projects including the Simulink RPP Target for code download. It is 
892 configured to use the Texas Instruments XDS100v2 USB Emulator. See 
893 [Development wiring #development_wiring] for information about this hardware.
894
895
896 -> ``rpp/TMS570LS313xFlashLnk.cmd``
897
898 CGT Linker command file.
899
900 This file is used by all applications linking for the board, including the Simulink models, static
901 library and test suite. It includes instructions for the CGT Linker on where to place sections
902 and size of some sections.
903
904
905 -> ``rpp/include/{layer}`` and ``rpp/src/{layer}``
906
907 Interface files and implementations files for given ``{layer}``. 
908
909 See below for details on the RPP Layer.
910
911
912 -> ``rpp/include/rpp/rpp.h``
913
914 Main library header file.
915
916 To use this library just include this file and this file only. Also, before using any library 
917 function please call ``rpp_init()`` function for hardware initialization.
918
919
920 -> ``rpp/include/rpp/RppConfig.h``
921
922 Library configuration file.
923
924 Please refer to the API documentation and header file comments for specific documentation for each 
925 configuration parameter.
926
927
928 -> ``rpp/include/rpp/rpp_{mnemonic}.h``
929
930 Header file for ``{mnemonic}`` module.
931
932 This files includes function definitions, pin definitions, etc, specific to {mnemonic} module. The 
933 inclusion of this header can be configured in ``RppConfig.h`` using 
934 ``rppCONFIG_INCLUDE_{MNEMONIC}`` directive. See 
935 [API development guidelines #api_development_guidelines].
936
937
938 -> ``rpp/src/rpp/rpp_{mnemonic}.c``
939
940 Module implementation.
941
942 Implementation of ``rpp_{mnemonic}.h``'s functions on top of the DRV library. See 
943 [API development guidelines #api_development_guidelines].
944
945
946 -> ``rpp/src/rpp/rpp.c``
947
948 Implementation of library-wide functions.
949
950
951 NEWPAGE
952
953
954 == Test Suite ==[test_suite]
955
956 %DONE
957
958 The ``rpp-test-suite`` is a RPP application developed as part of this project that includes a 
959 series of test tasks or test commands to verify the correct behavior and functionality of the RPP 
960 layer modules. There is one command per module, and the command use the same mnemonic that the 
961 module.
962
963 This test suite can be found in ``<repo>/rpp/lib/apps/rpp-test-suite`` for the ARM version and in 
964 ``<repo>/rpp/lib/apps/rpp-test-suite_posix`` for the simulated version.
965
966 The application enables a command processor using the SCI at **115200-8-N-1**:
967
968 ```
969 RPP Library Test Suite.
970 ===========================================================
971 [Type a module to test or 'help']
972 --> help
973 Available commands:
974         help - Display this help.
975         ain  - Test Analog Input.
976         aout - Test Analog Output.
977         can  - Test CAN communication.
978         din  - Test Digital Inputs.
979         eth  - Test Ethernet communication.
980         fr   - Test Frame Relay communication.
981         hbr  - Test H-Bridge.
982         hout - Test High Power Output.
983         lin  - Test LIN communication.
984         lout - Test Digital Outputs.
985         mout - Test Power Outputs.
986         sci  - Test Serial Communication Interface.
987         sdc  - Test SD-Card.
988         sdr  - Test SD-RAM.
989 ```
990
991 Current modules with tests implemented are:
992
993 %tex% ''' \begin{multicols}{2}
994 - AIN.
995 - AOUT.
996 - DIN.
997 - HBR.
998 - LOUT.
999 - MOUT.
1000 - SCI. (the test-suite itself)
1001 - SDR.
1002
1003
1004 %tex% ''' \end{multicols}
1005
1006 A note of warning: tests spawn OS tasks at the beginning of the test and deletes them at the end. 
1007 Because current memory memory management implementation cannot free memory the test suite will
1008 fill all the memory and tests will be unable to start. In this case just reset the board. See
1009 [Appendix A: Notes on FreeRTOS memory management #appendix_a_notes_on_freertos_memory_management]
1010 for more information.
1011
1012 NEWPAGE
1013
1014 === AIN test description ===[ain_test_description]
1015
1016 %DONE
1017
1018 This test will read all the analog inputs at a rate of 100 times per second and print the result.
1019
1020 ```
1021 --> ain
1022 Analog Inputs Test [1-12]:
1023 ===========================================================
1024    1    2    3    4    5    6    7    8    9   10   11   12
1025    0    0    0    0    0    0    0    0    0    0    0    0
1026 ```
1027
1028 Status: **PASSED** for channels 1-5. 6-12 remain untested but they //should// work.
1029
1030 === AOUT test description ===[aout_test_description]
1031
1032 %DONE
1033
1034 This test will generate a 10Hz sinus wave on all the analog outputs with a sampling rate of 1kHz. 
1035 The sinus wave of each analog output channel is sifted by (1/4)pi.
1036
1037 ```
1038 --> aout
1039 Analog Output Test at 10 Hz:
1040 ===========================================================
1041 Samples: 7331
1042 ```
1043
1044 Status: **PASSED**.
1045
1046 === DIN test description ===[din_test_description]
1047
1048 %DONE
1049
1050 This test will read all 16 + 8 digital inputs at a rate of 100 times per second, using both low 
1051 speed SPI chip and variable threshold high-speed inputs.
1052
1053 ```
1054 --> din
1055 Digital Inputs Test [1-16]:
1056 ===========================================================
1057  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16  A  B  C  D  E  F  G  H
1058  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 
1059 ```
1060
1061 Status: 
1062  - Low speed fixed threshold [1-16]: **PASSED**.
1063  - High speed variable threshold [A-H]: **PASSED**.
1064
1065 === HBR test description ===[hbr_test_description]
1066
1067 %DONE
1068
1069 This test will generate a sinus wave to control the H-Bridge of one period per 20 seconds (0.05Hz) 
1070 at a sampling rate of 20Hz.
1071
1072 ```
1073 --> hbr
1074 H-Bridge Test at 0.05 Hz:
1075 ===========================================================
1076 Samples: 72
1077 ```
1078
1079 Status: **PASSED**.
1080
1081 === LOUT test description ===[lout_test_description]
1082
1083 %DONE
1084
1085 This test will show in the digital outputs the value in binary of a counter, incrementing the 
1086 counter once per second. The counter is 8 bits, the same as the outputs, so 255 seconds are 
1087 required for an overflow/restart of the counting.
1088
1089 ```
1090 --> lout
1091 Digital Output Test:
1092 ===========================================================
1093 Counter:   40 
1094 ```
1095
1096 Status: **PASSED**.
1097
1098 === MOUT test description ===[mout_test_description]
1099
1100 %DONE
1101
1102 This test will toggle the power outputs one by one per second, then wait 10 seconds in that state 
1103 while constantly verifying the diagnostics.
1104
1105 ```
1106 --> mout
1107 Power Output Test:
1108 ===========================================================
1109 1     2     3     4     5     6
1110 1: OK 1: OK 1: OK 1: OK 1: OK 1: OK 
1111 ```
1112
1113 Status: **PASSED**.
1114
1115 === SCI test description ===[sci_test_description]
1116
1117 %DONE
1118
1119 A more comprehensive test is not implemented. The very use of this test-suite implies the correct 
1120 function of the SCI module. Nevertheless, as a future improvement, a test that will verify run-time 
1121 baud rate changes and test some other RPP SCI functions is desirable.
1122
1123 ```
1124 --> sci
1125 You're using the SCI, reading this and typing this command.
1126 Press any key to continue...
1127 ```
1128
1129 Status: **PASSED**.
1130
1131 === SDR test description ===[sdr_test_description]
1132
1133 %DONE
1134
1135 This test will launch a noise generator task that will log noise and then start the library 
1136 included SD-RAM logging command processor, allowing the user to see and handle the log on the 
1137 SD-RAM.
1138
1139 ```
1140 --> sdr
1141 Log control: 1024kB available.
1142 ===========================================================
1143 --> log
1144 [   1239864] This is the noise generator at iteration 1 putting some noise value 279735017.
1145 [   1240779] This is the noise generator at iteration 2 putting some noise value 1943579783.
1146
1147 --> available
1148 1023 kB of 1024 kB available.
1149
1150 --> clear
1151 Done.
1152
1153 --> exit
1154 ```
1155
1156 Status: **PASSED**.
1157
1158 NEWPAGE
1159
1160 == Static libraries ==[static_libraries]
1161
1162 %DONE
1163
1164 The RPP Library can be compiled as a static library for ARM using TI CGT and for x86(_64) using 
1165 GCC. CCS projects ``rpp-lib`` and ``rpp-lib_posix`` in ``<repo>/rpp/lib/apps/`` allows to generate 
1166 the static libraries. After compilation, as part of the build process, both projects will 
1167 automatically update the version-controlled static libraries in ``<repo>/rpp/lib/``:
1168
1169 - ``rpp-lib.lib``, static library for ARM using TI naming scheme.
1170 - ``librpp.a``, static library for x86(_64) using standard Linux naming scheme.
1171
1172
1173 One future improvement would be the creation of a Makefile for each compilation scheme in order to 
1174 not depend on CCS managed build system. For ARM manual compilation or makefile creation using Texas 
1175 CGT see the ``target_tools.mk`` file under the Simulink RPP Target folder. The relevant aspects for 
1176 compiling and linking an application using the static libraries are:
1177
1178 **ARM compilation using CCS for the RPP board:**
1179
1180 - Include headers files of the OS for which the library was compiled against. At the time of this 
1181   writing the OS is FreeRTOS 7.0.2. See [OS interchangeable layer #os_interchangeable_layer] 
1182   section above.
1183 - Include header files for the RPP library.
1184 - Add library ``rpp-lib.lib`` to the linker libraries. The RPP library **MUST** be looked for 
1185   before Texas Instruments support library ``rtsv7R4_T_be_v3D16_eabi.lib``.
1186 - Configure linker to retain ``.intvecs`` section from RPP Library:@@
1187   ``--retain="rpp-lib.lib<sys_intvecs.obj>(.intvecs)"``
1188 - Use the provided linker command file ``TMS570LS313xFlashLnk.cmd``.
1189
1190
1191 **x86(_64) compilation using GCC for Simulation:**
1192
1193 - Include headers files of the OS for Simulation. At the time of this writing the OS is POSIX 
1194   FreeRTOS 6.0.4.
1195 - Include header files for the RPP library.
1196 - Create a ``RppConfig.h`` override file and drop DRV layer dependency: ``rppCONFIG_DRV 0``.
1197 - Includes must be configured in a way that the ``RppConfig.h`` taken under consideration is the 
1198   override and not the library one.
1199 - Add library ``librpp.a`` to the linker libraries.
1200 - Add ``pthread`` to the linker libraries.
1201
1202
1203 As an important note, all the models compiled using Simulink will link against ``rpp-lib.lib``. 
1204 When compiling a Simulink model, Simulink, and then ``make``, will not update the generated binary 
1205 if the model hasn't changed, and then if the source code hasn't changed. Static libraries changes 
1206 are not considered for re-compilation and re-linking. If library development is being done and 
1207 static library is updated, in order for the Simulink model to generate a newly linked version of 
1208 the binary the whole code generation folder needs to be deleted in order to force code generation, 
1209 compilation and linking with the new static library.
1210
1211
1212 NEWPAGE
1213
1214 == Base application ==[base_application]
1215
1216 %DONE
1217
1218 In ``<repo>/rpp/lib/apps/`` there is two RPP base applications, ``base`` and ``base_posix``, that
1219 already configured for the RPP Library. It is advised that new applications uses this projects a 
1220 foundations. 
1221
1222 To create a new application copy this directory and rename it. Now open files ``.project``, 
1223 ``.cproject`` and ``.ccsproject`` (if available) and change any occurrence of the work ``base`` 
1224 with the name of your project. Use lower case ASCII letters and underscores only.
1225
1226 **Steps to configure a new CCS (ARM, using CGT) RPP application:**
1227
1228 + Create a new CCS project. @@
1229 [400-base_1.png]
1230 + Create a normal folder ``include``.
1231 + Create a source folder ``src``.
1232 + Add common ``.gitignore`` to the root of that project:
1233 {{{ plain
1234 Debug
1235 Release
1236 .settings/*
1237 }}}
1238 NEWPAGE
1239 + Add new variable ``RPP_LIB_ROOT`` and point to this repository branch root.@@
1240 [400-base_2.png]
1241 + Add ``rpp-lib.lib`` static library to linker libraries and add ``RPP_LIB_ROOT`` to the library 
1242   search path.@@
1243 [400-base_3.png]
1244 NEWPAGE
1245 + Configure linker to retain ``.intvecs`` from RPP static library.@@
1246 [350-base_4.png]
1247 + Configure compiler to include local includes, OS includes for TMS570 and RPP includes, in that 
1248   order.@@
1249 [350-base_5.png]
1250 NEWPAGE
1251 + Configure compiler to allow GCC extensions.@@
1252 [400-base_6.png]
1253 + Import and link (__do not copy!__) linker file and board upload descriptor.@@
1254 [200-base_7.png]
1255
1256
1257 **Steps to configure a new GCC (x86(_64)) RPP simulated application:**
1258
1259 + Create a new managed C project that uses Linux GCC toolchain.
1260 + Create a source folder ``src``. Link all files from original CCS application to this folder.
1261 + Create a normal folder ``include``. Create a folder ``rpp`` inside of it.
1262 + Add common ``.gitignore`` to the root of that project:
1263 {{{ plain
1264 Debug
1265 Release
1266 .settings/*
1267 }}}
1268 NEWPAGE
1269 + Add new variable ``RPP_LIB_ROOT`` and point to this repository branch root.@@
1270 [400-base_posix_1.png]
1271 + Configure compiler to include local includes, CCS application includes, OS includes for POSIX and 
1272   RPP includes, in that order.@@
1273 [400-base_posix_2.png]
1274 NEWPAGE
1275 + Add ``rpp`` and ``pthread``to linker libraries and add ``RPP_LIB_ROOT`` to the library search 
1276   path.@@
1277 [400-base_posix_3.png]
1278 + Copy ``RppConfig.h`` from RPP Library to a new folder ``include/rpp`` and configure it drop DRV 
1279   layer dependency: ``rppCONFIG_DRV 0``.@@
1280 [200-base_posix_4.png]
1281
1282
1283 **In general any RPP application uses the layout/template:**
1284
1285 + Include RPP library header file.
1286 {{{ cpp
1287 #include "rpp/rpp.h"
1288 }}}
1289
1290 NEWPAGE
1291 + Create one or as many FreeRTOS task function definitions as required. Those tasks should use 
1292   functions from this library.
1293 {{{ cpp
1294 void my_task(void* p)
1295 {
1296     static const portTickType freq_ticks = 1000 / portTICK_RATE_MS;
1297     portTickType last_wake_time = xTaskGetTickCount();
1298     while(TRUE) {
1299         /* Wait until next step */
1300         vTaskDelayUntil(&last_wake_time, freq_ticks);
1301         rpp_sci_printf((const char*)"Hello RPP.\r\n");
1302     }
1303 }
1304 }}}
1305
1306 + Create the main function that will:
1307  - Initialize the RPP board.
1308  - Spawn the tasks the application requires. Refer to FreeRTOS API for
1309    details.
1310  - Start the FreeRTOS Scheduler. Refer to FreeRTOS API for details.
1311  - Catch if idle task could not be created.
1312 +
1313 {{{ cpp
1314 void main(void)
1315 {
1316     /* Initialize RPP board */
1317     rpp_init();
1318
1319     /* Spawn tasks */
1320     if(xTaskCreate(my_task, (const signed char*)"my_task",
1321             512, NULL, 0, NULL) != pdPASS) {
1322         #ifdef DEBUG
1323         rpp_sci_printf((const char*)
1324             "ERROR: Cannot spawn control task.\r\n"
1325         );
1326         #endif
1327         while(TRUE) { asm(" nop"); }
1328     }
1329
1330     /* Start the FreeRTOS Scheduler */
1331     vTaskStartScheduler();
1332
1333     /* Catch scheduler start error */
1334     #ifdef DEBUG
1335     rpp_sci_printf((const char*)
1336             "ERROR: Problem allocating memory for idle task.\r\n"
1337         );
1338     #endif
1339     while(TRUE) { asm(" nop"); }
1340 }
1341 }}}
1342
1343 + Create hook functions for FreeRTOS:
1344  - ``vApplicationMallocFailedHook()`` allows to catch memory allocation errors.
1345  - ``vApplicationStackOverflowHook()`` allows to catch if a task overflows it's
1346    stack.
1347 +
1348 {{{ cpp
1349 #if configUSE_MALLOC_FAILED_HOOK == 1
1350 /**
1351  * FreeRTOS malloc() failed hook.
1352  */
1353 void vApplicationMallocFailedHook(void) {
1354     #ifdef DEBUG
1355     rpp_sci_printf((const char*)
1356             "ERROR: manual memory allocation failed.\r\n"
1357         );
1358     #endif
1359 }
1360 #endif
1361
1362
1363 #if configCHECK_FOR_STACK_OVERFLOW > 0
1364 /**
1365  * FreeRTOS stack overflow hook.
1366  */
1367 void vApplicationStackOverflowHook(xTaskHandle xTask,
1368                                    signed portCHAR *pcTaskName) {
1369     #ifdef DEBUG
1370     rpp_sci_printf((const char*)
1371             "ERROR: Stack overflow : \"%s\".\r\n", pcTaskName
1372         );
1373     #endif
1374 }
1375 #endif
1376 }}}
1377
1378 NEWPAGE
1379
1380
1381 == API generation ==[api_generation]
1382
1383 %DONE
1384
1385 The RPP Layer is formatted using Doxygen documentation generator. This allows to generate a high 
1386 quality API reference. To generate the API reference do in a terminal:
1387
1388 {{{ bash
1389 cd <repo>/rpp/lib/rpp/doc/api
1390 doxygen doxygen.conf
1391 xdg-open html/index.html
1392 }}}
1393
1394 The files under ``<repo>/rpp/lib/rpp/doc/api/content`` are used for the API reference generation 
1395 are their name is self-explanatory:
1396
1397 ```
1398 blocks_map.html
1399 blocks.png
1400 cvut.png
1401 footer.html
1402 main_page.dox
1403 ```
1404
1405 To install Doxygen see [Development environment #development_environment] section.
1406
1407 == API Reference ==[api_reference]
1408
1409 %DONE
1410
1411 For the complete API reference please generate the HTML version using the above section 
1412 instructions. Here is listed the index of functions of each module and their brief.
1413
1414 Please note that not all modules were implemented as part of this project. See 
1415 [RPP Layer Modules #rpp_layer_modules] for a list of the modules implemented.
1416
1417 NEWPAGE
1418
1419 === DIN API Reference ===[din_api_reference]
1420
1421 %DONE
1422
1423 ``int8_t rpp_din_init();`` @@ -> DIN module initialization. @@ @@
1424 ``int8_t rpp_din_ref(uint16_t refA, uint16_t refB);`` @@ -> Configure voltage reference levels for digital inputs using variable reference threshold. @@ @@
1425 ``int8_t rpp_din_setup(uint8_t pin, boolean_t pull_type, boolean_t active, boolean_t can_wake);`` @@ -> Configure given pin. @@ @@
1426 ``int8_t rpp_din_get(uint8_t pin, boolean_t var_thr);`` @@ -> Get the current cached value of the given pin. @@ @@
1427 ``int8_t rpp_din_diag(uint8_t pin);`` @@ -> Get the diagnostic cached value for given pin. @@ @@
1428 ``int8_t rpp_din_update();`` @@ -> Read and update cached values and diagnostic values of all pins. Also commit configuration changes.
1429
1430 === LOUT API Reference ===[lout_api_reference]
1431
1432 %DONE
1433
1434 ``int8_t rpp_lout_init();`` @@ -> LOUT module initialization. @@ @@
1435 ``int8_t rpp_lout_set(uint8_t pin, uint8_t val);`` @@ -> Set the output cache of given pin to given value. @@ @@
1436 ``int8_t rpp_lout_diag(uint8_t pin);`` @@ -> Get the diagnostic cached value for given pin. @@ @@
1437 ``int8_t rpp_lout_update();`` @@ -> Flush cached output values and read back diagnostic values of all pins.
1438
1439 === AIN API Reference ===[ain_api_reference]
1440
1441 %DONE
1442
1443 ``int8_t rpp_ain_init();`` @@ -> AIN module initialization. @@ @@
1444 ``int16_t rpp_ain_get(uint8_t pin);`` @@ -> Get the current analog value on the given pin. @@ @@
1445 ``int8_t rpp_ain_update();`` @@ -> Read and update analog cached values.
1446
1447
1448 === AOUT API Reference ===[aout_api_reference]
1449
1450 %DONE
1451
1452 ``#define RPP_DAC_OA   5.6`` @@ -> DAC output operational amplifier multiplication constant. @@ @@
1453 ``#define RPP_DAC_VREF 2.5`` @@ -> DAC hardware reference voltage. @@ @@
1454 ``int8_t rpp_aout_init();`` @@ -> AOUT module initialization. @@ @@
1455 ``int8_t rpp_aout_setup(uint8_t pin, boolean_t enabled);`` @@ -> Configure enabled/disabled state for given pin. @@ @@
1456 ``int8_t rpp_aout_set(uint8_t pin, uint16_t val);`` @@ -> Set the output cache of given pin to given value. @@ @@
1457 ``int8_t rpp_aout_set_voltage(uint8_t pin, uint16_t mv);`` @@ -> Set output to given voltage. @@ @@
1458 ``int8_t rpp_aout_update();`` @@ -> Flush cached output values and configuration changes.
1459
1460 === HBR API Reference ===[hbr_api_reference]
1461
1462 %DONE
1463
1464 ``int8_t rpp_hbr_init();`` @@ -> HBR module initialization. @@ @@
1465 ``int8_t rpp_hbr_enable(int32_t period);`` @@ -> Enable the H-Bridge for control. @@ @@
1466 ``int8_t rpp_hbr_control(double cmd);`` @@ -> Control the H-Bridge direction, enabled/disabled and PWM. @@ @@
1467 ``int8_t rpp_hbr_disable();`` @@ -> Disable the H-Bridge.
1468
1469 NEWPAGE
1470
1471 === MOUT API Reference ===[mout_api_reference]
1472
1473 %DONE
1474
1475 ``int8_t rpp_hbr_init();`` @@ -> HBR module initialization. @@ @@
1476 ``int8_t rpp_mout_init();`` @@ -> MOUT module initialization. @@ @@
1477 ``int8_t rpp_mout_set(uint8_t pin, uint8_t val);`` @@ -> Set the output of given pin to given value. @@ @@
1478 ``int8_t rpp_mout_get(uint8_t pin);`` @@ -> Get the cached value of the given pin set by rpp_mout_set(). @@ @@
1479 ``int8_t rpp_mout_diag(uint8_t pin);`` @@ -> Reads the value on the given diagnostic pin.
1480
1481 === HOUT API Reference ===[hout_api_reference]
1482
1483 %DONE
1484
1485 ``int8_t rpp_hout_init();`` @@ -> HOUT module initialization.
1486
1487 === CAN API Reference ===[can_api_reference]
1488
1489 %DONE
1490
1491 ``int8_t rpp_can_init();`` @@ -> CAN module initialization.
1492
1493 === LIN API Reference ===[lin_api_reference]
1494
1495 %DONE
1496
1497 ``int8_t rpp_lin_init();`` @@ -> LIN module initialization.
1498
1499 === FR API Reference ===[fr_api_reference]
1500
1501 %DONE
1502
1503 ``int8_t rpp_fr_init();`` @@ -> FR module initialization.
1504
1505 NEWPAGE
1506
1507 === SCI API Reference ===[sci_api_reference]
1508
1509 %DONE
1510
1511 ``int8_t rpp_sci_init();`` @@ -> SCI module initialization. @@ @@
1512 ``boolean_t rpp_sci_setup(uint32_t baud);`` @@ -> SCI module setup. @@ @@
1513 ``uint16_t rpp_sci_available();`` @@ -> Number of bytes available on input buffer. @@ @@
1514 ``int8_t rpp_sci_read(uint32_t amount, uint8_t* buffer);`` @@ -> Read n number of bytes from input buffer. @@ @@
1515 ``int8_t rpp_sci_read_nb(uint32_t amount, uint8_t* buffer);`` @@ -> Read n number of bytes from input buffer if possible. @@ @@
1516 ``int8_t rpp_sci_write(uint32_t amount, uint8_t* data);`` @@ -> Write n number of bytes to the output buffer. @@ @@
1517 ``int8_t rpp_sci_write_nb(uint32_t amount, uint8_t* data);`` @@ -> Write n number of bytes to the output buffer if possible. @@ @@
1518 ``int8_t rpp_sci_flush(boolean_t buff);`` @@ -> Flush incomming or outgoing buffers. @@ @@
1519 ``int32_t rpp_sci_printf(const char* format, ...);`` @@ -> C style printf using RPP SCI module. @@ @@
1520 ``int8_t rpp_sci_putc(uint8_t byte);`` @@ -> C style putc (put character) using RPP SCI module. @@ @@
1521 ``int16_t rpp_sci_getc();`` @@ -> C style getc (get character) using RPP SCI module.
1522
1523 === ETH API Reference ===[eth_api_reference]
1524
1525 %DONE
1526
1527 ``int8_t rpp_eth_init();`` @@ -> ETH module initialization.
1528
1529 === SDC API Reference ===[sdc_api_reference]
1530
1531 %DONE
1532
1533 ``int8_t rpp_sdc_init();`` @@ -> SDC module initialization.
1534
1535 === SDR API Reference ===[sdr_api_reference]
1536
1537 %DONE
1538
1539 ``#define RPP_SDR_ADDR_START 0x80000000U`` @@ -> SDRAM start address on RPP board. @@ @@
1540 ``#define RPP_SDR_ADDR_END   0x83FFFFFFU`` @@ -> SDRAM end address on RPP board. @@ @@
1541 ``int8_t rpp_sdr_init();`` @@ -> SDR module initialization. @@ @@
1542 ``int8_t rpp_sdr_setup(boolean_t enable);`` @@ -> Configure SD-RAM logging. @@ @@
1543 ``uint32_t rpp_sdr_available();`` @@ -> Query for the amount of space free on the SD-RAM. @@ @@
1544 ``int32_t rpp_sdr_printf(const char* format, ...);`` @@ -> Store a formatted user string on the log, if logging is enabled. @@ @@
1545 ``int8_t rpp_sdr_clear();`` @@ -> Clear log. @@ @@
1546 ``int8_t rpp_sdr_show(boolean_t start);`` @@ -> Start/Stop the task that sends the log to the SCI.
1547
1548 NEWPAGE
1549
1550 = Simulink Coder Target =[simulink_coder_target]
1551
1552 % FALTA
1553
1554 == Description ==[description]
1555
1556 The Simulink RPP Target provides support for C source code generation from Simulink models and 
1557 compilation of that code on top of the RPP library and the FreeRTOS operating system. This target 
1558 uses Texas Instrument ARM compiler (armcl) included in the Code Generation Tools available with 
1559 Code Composer Studio, and thus it depends on it for proper functioning.
1560
1561 This library also provides support for automatically download the compiled machine code to the RPP 
1562 board.
1563
1564 === Code generation process ===[code_generation_process]
1565
1566 %tex% ''' \begin{figure}[H]\advance\leftskip-1cm
1567 [350-tlc_process.png]
1568 %tex% ''' \caption{TLC code generation process.}\end{figure}
1569
1570 == Subdirectory  content description ==[subdirectory__content_description]
1571
1572 %DONE
1573 -> ``rpp_setup.m``
1574
1575 RPP Target install script.
1576
1577 This script will, among other things, ask the user to provide the location of the armcl parent 
1578 directory, infer and save some relevant CCS paths, add paths to Matlab path and build S-Function 
1579 blocks for user's architecture (using Matlab's mex command line tool).
1580
1581 - __Reference:__
1582  - ``<repo>/refs/rtw_ug.pdf`` p. 1137.
1583
1584
1585 -> ``rpp.tlc``
1586
1587 Embedded real-time system target file for RPP.
1588
1589 This file is the system target file (STF), or target manifest file. Functions of the STF include:
1590
1591 - Making the target visible in the System Target File Browser.
1592 - Definition of code generation options for the target (inherited and target-specific).
1593 - Providing an entry point for the top-level control of the TLC code generation process.
1594
1595
1596 - __Reference:__
1597  - ``<repo>/refs/rtw_ug.pdf`` p. 1129 and __1144__.
1598
1599
1600 -> ``rpp.tmf``
1601
1602 Embedded Coder Template Makefile.
1603
1604 This is just standard Embedded Coder Template Makefile, provided by Matlab. It was slightly 
1605 modified to support ``armcl`` particularities and added template rules for assembler files (which 
1606 were included by the ``rpp_lib_support.m`` script, but is no longer the case).
1607
1608 - __Reference:__
1609  - ``<repo>/refs/rtw_ug.pdf`` p. 1130 and __1183__.
1610
1611
1612 -> ``rpp_download.m``
1613
1614 Code download utility for Simulink RPP Target.
1615
1616 This function is optionally executed at the end of the build process if it is successful and the 
1617 user selected //Download compiled binary to RPP// option on the build configuration panel. This 
1618 function calls ``loadti.sh`` script with the generated binary and using configuration for the 
1619 XDS100v2 JTAG Emulators. The board should be powered and correctly wired. @@
1620 See [Development wiring #development_wiring].
1621
1622
1623 NEWPAGE
1624 -> ``rpp_file_process.tlc``
1625
1626 Code generation custom file processing template.
1627
1628 This file should decide which //main// to generate according to configuration, in particular which 
1629 mode, Single Tasking or Multitasking, is chosen. The RPP Target ignores this settings because it 
1630 uses a tasking system based on tasking features provided by FreeRTOS. In consequence is only a 
1631 wrapper to the //Single Tasking// main, which clearly is not for single tasking.
1632
1633 - __Reference:__
1634  - ``<repo>/refs/ecoder_ug.pdf`` p. 556.
1635  - ``<repo>/refs/ecoder_ref.pdf`` p. 1347.
1636
1637
1638 -> ``rpp_lib_support.m``
1639
1640 **DEPRECATED**. Simulink support for RPP library and operating system setup.
1641
1642 This files used to add the source code from the RPP library and operating to the build. This is no 
1643 longer required when using the static library. This is left for future reference in case new source 
1644 code needs to be included to the build.
1645
1646 - __Reference:__
1647  - ``<repo>/refs/rtw_ug.pdf`` p. 1058.
1648  - ``<repo>/refs/rtw_ref.pdf`` p. 56.
1649
1650
1651 -> ``rpp_make_rtw_hook.m``
1652
1653 Build process hooks file.
1654
1655 This file is hook file that invoke target-specific functions or executables at specified points in 
1656 the build process. In particular, this file handle the copying of required files before the 
1657 compilation stage.
1658
1659 - __Reference:__
1660  - ``<repo>/refs/rtw_ug.pdf`` p. 1066-1072 and 1131.
1661
1662
1663 -> ``rpp_select_callback_handler.m``
1664
1665 RPP Target select callback handler.
1666
1667 This callback function is triggered whenever the user selects the target in the System Target File 
1668 Browser. Default values for Simulation and configurations parameters are set. Some options are 
1669 disabled if it is not allowed to be changed by user.
1670
1671 - __Reference:__
1672  - ``<repo>/refs/rtw_ug.pdf`` p. 1211.
1673
1674
1675 NEWPAGE
1676 -> ``rpp_srmain.tlc``
1677
1678 Custom file processing to generate a //main// file.
1679
1680 This file generated the //main// file for the RPP target on top of the RPP library and the FreeRTOS 
1681 operating system. The ``sr`` prefix is standard to mark Single Tasking main, which is the case. 
1682 See ``rpp_file_process.m`` description above for more information about this.
1683
1684 - __Reference:__
1685  - Example in ``<matlab>/rtw/c/tlc/mw/bareboard_srmain.tlc``.
1686
1687
1688 -> ``target_tools.mk``
1689
1690 Makefile for CCS (``armcl``) toolchain support.
1691
1692 This file set variables to CCS tools to support build for this toolchain. This file is included by 
1693 ``rpp.tmf`` before declaring the rules for source code.
1694
1695 - __Reference:__
1696  - //Include a tool specification settings// comment block in ``rpp.tmf``.
1697  - Compiler options documentation available in ``armcl.pdf``.
1698
1699
1700 NEWPAGE
1701
1702 == Installation procedure ==[installation_procedure]
1703
1704 %DONE
1705
1706 **1) Download and install CCS for Linux:**
1707
1708 Details on how to setup CCS are available in section 
1709 [TI Code Composer Studio #ti_code_composer_studio].
1710
1711
1712 **2) Install RPP Target:**
1713
1714 Open Matlab and type on command window:
1715
1716 {{{ plain
1717 cd <repo>/rpp/rpp/
1718 rpp_setup()
1719 }}}
1720
1721 This will launch the RPP setup script. This script will ask the user to provide the path to the CCS 
1722 compiler root directory (the directory where ``armcl`` binary is located), normally:
1723
1724 ```
1725 <ccs>/tools/compiler/arm_5.X.X/
1726 ```
1727
1728 This script will, among other things, ask the user to provide the location of the armcl parent 
1729 directory, infer and save some relevant CCS paths, add paths to Matlab path and build S-Function 
1730 blocks for user's architecture (using Matlab's mex command line tool).
1731
1732
1733 **3) Create a new model or load a demo:**
1734
1735 Demos are located on ``<repo>/rpp/demo`` or you can start a new model and configure target to RPP. 
1736 For new models see [Target Reference #target_reference] section below.
1737
1738 NEWPAGE
1739
1740 == Target Reference ==[target_reference]
1741
1742 %DONE
1743
1744 This section describes the options required or available for running a Simulink model with the RPP 
1745 Target.
1746
1747 === Simulink model options ===[simulink_model_options]
1748
1749 %DONE
1750
1751 The Simulink model needs to be configured in the following way:
1752
1753 - Solver: 
1754  - //fixed-step discrete//.
1755  - Tasking mode set to //SingleTasking//. @@
1756 [400-simulink_solver.png]
1757 NEWPAGE
1758 - Diagnostics - Sample Time:
1759  - Disable warning source block specifies -1 sampling time. It's ok for the source blocks to run 
1760    once per tick. @@
1761 [400-simulink_diagnostics.png]
1762 - Code generation:
1763  - Set to ``rpp.tlc``. @@
1764 [400-simulink_code.png]
1765
1766
1767 Note: Single Tasking is the only currently supported mode. If multitasking is required to be 
1768       implemented in the future create a new file ``rpp_mrmain.tlc`` in ``<repo>/rpp/rpp/`` and 
1769       edit ``rpp_file_process.tlc`` to use that file instead when multitasking is selected.
1770
1771
1772 === RPP Target options ===[rpp_target_options]
1773
1774 %DONE
1775
1776 The RPP Target include the following configuration options, all of them configurable per model 
1777 under  ``Code Generation`` -> ``RPP Options``:
1778
1779 - **C system stack size**: this parameter is passed directly to the linker for the allocation of 
1780   the stack. Note that this is the stack for the application when running outside a FreeRTOS task, 
1781   normally before the scheduler has started and for system routines. Default value is 4096.
1782
1783 - **C system heap size**: this parameter is passed directly to the linker for the allocation of the 
1784   heap. See 
1785   [Appendix A: Notes on FreeRTOS memory management #appendix_a_notes_on_freertos_memory_management]
1786   for an important information about this parameter.
1787
1788 - **Model step task stack size**: this parameter will be passed to the ``xTaskCreate()`` that 
1789   creates the task for the model to run. In a Simulink model there is always two tasks: 
1790  - The worker task. This task is the one that executes the model step. This task requires enough 
1791    stack memory to execute the step. Take into account for example than only a single call to 
1792    ``rpp_sci_printf()`` requires, with current configuration, 128 bytes from the stack. This value 
1793    should be minor than the C system heap and leaving enough heap for the system tasks. See 
1794    [Appendix A: Notes on FreeRTOS memory management #appendix_a_notes_on_freertos_memory_management]
1795    for more information.
1796  - The control task. This task controls when the worker task should execute and controls overruns.
1797
1798 - **Download compiled binary to RPP**: if set, this option will download the generated binary to 
1799   the board after the model is successfully built. Note that this option is unaware of the option 
1800   //Generate code only// in the //Code Generation// options panel, so it will try to upload even if 
1801   only source code has being generated, failing graciously or uploading an old binary laying around 
1802   in the build directory. This option calls the ``rpp_download.m`` script, which is in turn a 
1803   wrapper on the ``loadti.sh`` script. More information on the ``loadti.sh`` script can be found 
1804   in:
1805 ```
1806 <css>/ccs_base/scripting/examples/loadti/readme.txt
1807 http://processors.wiki.ti.com/index.php/Loadti
1808 ```
1809   The ``loadti.sh`` script will close after the download of the generated program and in 
1810   consequence the execution of the loaded program will stop (because it work as the CCS debug 
1811   server). In order to test the loaded model a manual reset of the board is always required after a 
1812   successful download.
1813
1814 - **Print model metadata to SCI at start**: if set this option will print a message to the Serial 
1815   Communication Interface when the model start execution on the board. This is very helpful to 
1816   identify the model running on the board. The message is in the form:
1817 ```
1818 `model_name' - generated_date (TLC tlc_version)
1819 ```
1820   For example:
1821 ```
1822 `hbridge_analog_control' - Wed Jun 19 14:10:44 2013 (TLC 8.3 (Jul 20 2012))
1823 ```
1824
1825 NEWPAGE
1826
1827 = Simulink Block Library =[simulink_block_library]
1828
1829
1830
1831 == Description ==[description]
1832
1833 The Simulink RPP Block Library is the ideal set of blocks that should be implemented for the RPP 
1834 board. As part of this project this ideal set was defined, but not all blocks were implemented. The 
1835 following table shows the current status of the block library.
1836
1837 || CATEGORY                | NAME                           | STATUS*  | MNEMONIC    | LRH* 
1838  | System blocks           | Configuration block            | ``X``    | ``[CONF]``  | ``RppConfig.h``  |
1839  | Logic IO blocks         | Digital Input block            | ``T``    | ``[DIN ]``  | ``rpp_din.h``    |
1840  |                         | Digital Output block           | ``T``    | ``[LOUT]``  | ``rpp_lout.h``   |
1841  |                         | Analog Input block             | ``T``    | ``[AIN ]``  | ``rpp_ain.h``    |
1842  |                         | Analog Output block            | ``T``    | ``[AOUT]``  | ``rpp_aout.h``   |
1843  | Power output blocks     | H-Bridge Control block         | ``T``    | ``[HBR ]``  | ``rpp_hbr.h``    |
1844  |                         | Power output block             | ``T``    | ``[MOUT]``  | ``rpp_mout.h``   |
1845  |                         | High-Power output block        | ``X``    | ``[HOUT]``  | ``rpp_hout.h``   |
1846  | Communication blocks    | CAN Bus receive block          | ``X``    | ``[CANR]``  | ``rpp_can.h``    |
1847  |                         | CAN Bus send msg block         | ``X``    | ``[CANS]``  | - Idem -         |
1848  |                         | LIN receive block              | ``X``    | ``[LINR]``  | ``rpp_lin.h``    |
1849  |                         | LIN send msg block             | ``X``    | ``[LINS]``  | - Idem -         |
1850  |                         | FlexRay receive block          | ``X``    | ``[FRR ]``  | ``rpp_fr.h``     |
1851  |                         | FlexRay send msg block         | ``X``    | ``[FRS ]``  | - Idem -         |
1852  |                         | SCI receive block              | ``T``    | ``[SCIR]``  | ``rpp_sci.h``    |
1853  |                         | SCI send msg block             | ``T``    | ``[SCIS]``  | - Idem -         |
1854  |                         | SCI configure block            | ``T``    | ``[SCIC]``  | - Idem -         |
1855  |                         | Ethernet receive block         | ``X``    | ``[ETHR]``  | ``rpp_eth.h``    |
1856  |                         | Ethernet send msg block        | ``X``    | ``[ETHS]``  | - Idem -         |
1857  | Logging/Storage blocks  | SD Card write block            | ``T``    | ``[SDCW]``  | ``rpp_sdc.h``    |
1858  |                         | SDRAM write block              | ``X``    | ``[SDRW]``  | ``rpp_sdr.h``    |
1859  | Trigger blocks          | Overrun detected block         | ``X``    | ``[TROR]``  | - None -         |
1860  |                         | Stack overflow detected block  | ``X``    | ``[TRSO]``  | - None -         |
1861  |                         | Malloc Failed detected block   | ``X``    | ``[TRMF]``  | - None -         |
1862
1863 **Legend:**
1864 - *LRH    : Library Reference Header.
1865 - *STATUS : 
1866  - ``X`` - Unimplemented. Files non present.
1867  - ``P`` - Unimplemented. Files present.
1868  - ``W`` - Work in progress.
1869  - ``I`` - Implemented.
1870  - ``T`` - Implemented and tested.
1871
1872
1873 __Notes__: Each block that can detect fault condition should have a trigger output. @@
1874            High-power output provides current flow as an input to the model.
1875
1876
1877
1878 === C MEX S-Functions ===[c_mex_s_functions]
1879
1880 All of the blocks are implemented as a C Mex S-Function coded by hand. In the this section this 
1881 approach is explained.
1882
1883 Anatomy
1884 Compilation
1885
1886 === Target Language Compiler files ===[target_language_compiler_files]
1887
1888 Anatomy
1889
1890
1891 NEWPAGE
1892
1893 == Subdirectory  content description ==[subdirectory__content_description]
1894
1895 -> ``header.c`` and ``trailer.c``
1896
1897 RPP framework for simple S-Functions.
1898
1899 This files are included at the head and tail of each S-Function file. They include refactored and 
1900 commonly repeated structures that pollute S-Functions implementations. They include basic includes, 
1901 required definitions, macro definitions, common functions implementations and documentation on 
1902 optional functions and commented prototypes for optional model calls/hooks.
1903
1904 - __Reference:__
1905  - None.
1906
1907
1908 -> ``sfunction_{mnemonic}.c``
1909
1910 C-MEX S-Function implementation for {mnemonic} block.
1911
1912 This file implements the {mnemonic} block using C-MEX S-Function API. See the reference for information 
1913 about the S-Function API.
1914
1915 - __Reference:__
1916  - ``<repo>/refs/sfunctions.pdf``
1917
1918
1919 -> ``tlc_c/sfunction_{mnemonic}.tlc``
1920
1921 Target Language Compiler (TLC) file for {mnemonic} block.
1922
1923 This file implements the C code inlining for {mnemonic} block. See the reference for information about 
1924 the TLC API.
1925
1926 - __Reference:__
1927  - ``<repo>/refs/rtw_tlc.pdf``
1928
1929
1930 -> ``tlc_c/common.tlc``
1931
1932 Common TLC functions.
1933
1934 This file implements common TLC functions used by all the blocks.
1935
1936 - __Reference:__
1937  - None.
1938
1939
1940 -> ``slblocks.m``
1941
1942 Simulink library control file.
1943
1944 This file allows a group of blocks to be integrated into the Simulink Library and Simulink Library 
1945 Browser. This file is required by Simulink in order to interpret this folder as a block library. 
1946 For information about this file see the references.
1947
1948 - __Reference:__
1949  - ``<repo>/refs/rtw_ug.pdf`` p. 1127
1950
1951
1952 -> ``rpp_lib.slx``
1953
1954 RPP Simulink block library.
1955
1956 Simulink block library that includes all the blocks. This file is referenced by ``slblocks.m``
1957
1958 - __Reference:__
1959  - None.
1960
1961
1962 -> compile_blocks.m
1963
1964 Blocks compilation script.
1965
1966 This script compiles all the sfunction blocks to MEX executables. This script is called by the 
1967 ``rpp_setup()`` function in order make all the blocks available to the Simulink environment or it 
1968 can be called independently when developing S-Functions.
1969
1970 - __Reference:__
1971  - None.
1972
1973
1974 NEWPAGE
1975
1976 == Block Library Reference ==[block_library_reference]
1977
1978 This section describes each one of the Simulink blocks implements as part of this project:
1979
1980 %tex% ''' \begin{figure}[H]\advance\leftskip-1cm
1981 [530-block_library.png]
1982 %tex% ''' \caption{Simulink RPP Block Library.}\end{figure}
1983
1984 NEWPAGE
1985
1986 === DIN Digital Input block ===[din_digital_input_block]
1987
1988 ```
1989     Inputs      : 0
1990         None
1991
1992     Outputs     : 2
1993         bool    Digital Input
1994         bool    ErrFlag
1995
1996     Parameters  : 2
1997         uint8   Pin number [1-16]
1998         bool    Use variable threshold
1999 ```
2000
2001 This block allows to read the digital inputs on the RPP board. The variable threshold check change the read
2002 mode of the pin (from the block size this is working, library call is not working though). The ErrFlag should
2003 raise if ``rpp_din_update()`` or ``rpp_din_get()`` returns error. ``rpp_din_update()`` is called just by the
2004 first DIN block in the model and thus only the first block could raise the flag because of this. In case an 
2005 errors occurs the return value will always be LOW (0). Because the ErrFlag should never set, once set the
2006 following steps will never clear it back.
2007
2008
2009 %tex% ''' \begin{multicols}{3}
2010 - **Tested**:
2011  - Changing the pin.
2012  - Compilation and general use.
2013
2014
2015 %tex% ''' \vfill\columnbreak
2016 - **Untested**:
2017  - Faulty situation for the ErrFlag to set.
2018
2019
2020 %tex% ''' \vfill\columnbreak
2021 - **Not working**:
2022  - Using variable threshold.
2023
2024
2025 %tex% ''' \end{multicols}
2026
2027
2028 **RPP API functions used:**
2029 - ``rpp_din_setup()``.
2030 - ``rpp_din_update()``.
2031 - ``rpp_din_get()``.
2032
2033
2034 **Relevant demos:**
2035 - ``digital_passthrough``.
2036 - ``hbridge_digital_control``.
2037
2038
2039 NEWPAGE
2040
2041 === LOUT Digital Output block ===[lout_digital_output_block]
2042
2043 ```
2044     Inputs      : 1
2045         bool    Digital Output
2046
2047     Outputs     : 1
2048         bool    ErrFlag
2049
2050     Parameters  : 1
2051         uint8   Pin number [1-8]
2052 ```
2053
2054 This block allows to write to the digital outputs on the RPP board. The ErrFlag should raise if ``rpp_lout_set()`` 
2055 or ``rpp_lout_update()`` returns error. Because the ErrFlag should never set, once set the following steps will 
2056 never clear it back. ``rpp_lout_update()`` is called on each block, which is not the most efficient but guaranties 
2057 consistent behavior.
2058
2059
2060 **Status:**
2061 %tex% ''' \begin{multicols}{3}
2062 - **Tested**:
2063  - Changing the pin.
2064  - Compilation and general use.
2065
2066
2067 %tex% ''' \vfill\columnbreak
2068 - **Untested**:
2069  - Faulty situation for the ErrFlag to set.
2070
2071
2072 %tex% ''' \vfill\columnbreak
2073 - **Not working**:
2074
2075
2076 %tex% ''' \end{multicols}
2077
2078
2079 **RPP API functions used:**
2080 - ``rpp_lout_set()``.
2081 - ``rpp_lout_update()``.
2082
2083
2084 **Relevant demos:**
2085 - ``digital_passthrough``.
2086 - ``led_blink_all``.
2087 - ``led_blink``.
2088
2089
2090 NEWPAGE
2091
2092 === AIN Analog Input block ===[ain_analog_input_block]
2093
2094 ```
2095     Inputs      : 0
2096         None
2097
2098     Outputs     : 2
2099         uint16  Analog Input
2100         bool    ErrFlag
2101
2102     Parameters  : 1
2103         uint8   Pin number [1-12]
2104 ```
2105
2106 This block allows to read the analog inputs on the RPP board. The ErrFlag should if raise ``rpp_ain_update()`` 
2107 or ``rpp_ain_get()`` returns error. ``rpp_ain_update()`` is called just by the first DIN block in the model and 
2108 thus only the first block could raise the flag because of this. In case an errors occurs the return value will 
2109 always be 0. Because the ErrFlag should never set, once set the following steps will never clear it back.
2110
2111
2112 **Status:**
2113 %tex% ''' \begin{multicols}{3}
2114 - **Tested**:
2115  - Changing the pin.
2116  - Compilation and general use.
2117
2118
2119 %tex% ''' \vfill\columnbreak
2120 - **Untested**:
2121  - Faulty situation for the ErrFlag to set.
2122
2123
2124 %tex% ''' \vfill\columnbreak
2125 - **Not working**:
2126
2127
2128 %tex% ''' \end{multicols}
2129
2130
2131 **RPP API functions used:**
2132 - ``rpp_ain_update()``.
2133 - ``rpp_ain_get()``.
2134
2135
2136 **Relevant demos:**
2137 - ``analog_passthrough``.
2138 - ``hbridge_analog_control``.
2139 - ``log_analog_input``.
2140
2141
2142 NEWPAGE
2143
2144 === AOUT Analog Output block ===[aout_analog_output_block]
2145
2146 ```
2147     Inputs      : 1
2148         uint16  Analog Output
2149
2150     Outputs     : 1
2151         bool    ErrFlag
2152
2153     Parameters  : 1
2154         uint8   Pin number [1-4]
2155         bool    UseVoltage
2156 ```
2157
2158 This block allows to write to the analog outputs on the RPP board. The UseVoltage flag allows the user to
2159 configure if block inputs should be interpreted as raw DAC value or millivolts. The ErrFlag should raise 
2160 if ``rpp_aout_update()`` or ``rpp_aout_set()`` (or ``rpp_aout_set_voltage()`` depending on block configuration) 
2161 returns error. Because the ErrFlag should never set, once set the following steps will never clear it back.
2162
2163 ``rpp_aout_update()`` is called on each block but the implementation provides this to be efficient.
2164
2165 There is a know bug on the RPP Library, check ``rpp_aout_update()`` on the RPP API for details. Because of this, 
2166 the outputs of the DACs are initialized on the first step of the model and not on the model initialization.
2167
2168
2169 **Status:**
2170 %tex% ''' \begin{multicols}{3}
2171 - **Tested**:
2172  - Changing the pin.
2173  - Changing voltage/value flag.
2174  - Compilation and general use.
2175
2176
2177 %tex% ''' \vfill\columnbreak
2178 - **Untested**:
2179  - Faulty situation for the ErrFlag to set.
2180
2181
2182 %tex% ''' \vfill\columnbreak
2183 - **Not working**:
2184  - Initializing DACs on model's initialization.
2185
2186
2187 %tex% ''' \end{multicols}
2188
2189
2190 **RPP API functions used:**
2191 - ``rpp_aout_setup()``.
2192 - ``rpp_aout_set()``, or
2193 - ``rpp_aout_set_voltage()``.
2194 - ``rpp_aout_update()``.
2195
2196
2197 **Relevant demos:**
2198 - ``analog_passthrough``.
2199 - ``analog_sinewave``.
2200
2201
2202 NEWPAGE
2203
2204 === HBR H-Bridge Control block ===[hbr_h_bridge_control_block]
2205
2206 ```
2207     Inputs      : 1
2208         double  Control
2209
2210     Outputs     : 1
2211         bool    ErrFlag
2212
2213     Parameters  : 0
2214         None
2215 ```
2216
2217 This block allows to control the H-Bridge on the RPP board. The ErrFlag should raise only if 
2218 ``rpp_hbr_control()`` returns error. The H-Bridge is initialized with the default frequency (~18kHz). 
2219 A future improvement could include a parameter to set the frequency. Because the ErrFlag should never
2220 set, once set the following steps will never clear it back.
2221
2222
2223 **Status:**
2224 %tex% ''' \begin{multicols}{3}
2225 - **Tested**:
2226  - Compilation and general use.
2227
2228
2229 %tex% ''' \vfill\columnbreak
2230 - **Untested**:
2231  - Faulty situation for the ErrFlag to set.
2232
2233
2234 %tex% ''' \vfill\columnbreak
2235 - **Not working**:
2236
2237
2238 %tex% ''' \end{multicols}
2239
2240
2241 **RPP API functions used:**
2242 - ``rpp_hbr_enable()``.
2243 - ``rpp_hbr_control()``.
2244
2245
2246 **Relevant demos:**
2247 - ``hbridge_analog_control``.
2248 - ``hbridge_digital_control``.
2249 - ``hbridge_sinewave_control``.
2250
2251
2252 NEWPAGE
2253
2254 === MOUT Power Output block ===[mout_power_output_block]
2255
2256 ```
2257     Inputs      : 1
2258         bool    Power Output
2259
2260     Outputs     : 1
2261         bool    ErrFlag
2262
2263     Parameters  : 1
2264         uint8   Pin number [1-6]
2265 ```
2266
2267 This block allows to write the power outputs (2A) on the RPP board. The ErrFlag should raise only if 
2268 ``rpp_mout_set()``returns error. Note that ``rpp_mout_set()`` returns error only if some bad parameter
2269 or in case it could detect a faulty condition on the pin in a very very short period of time after 
2270 setting the value, see the function API for details. If the faulty condition persist on the next step
2271 the call will successfully detect the faulty condition and ErrFlag should set. Because the ErrFlag should 
2272 never set, once set the following steps will never clear it back.
2273
2274
2275 **Status:**
2276 %tex% ''' \begin{multicols}{3}
2277 - **Tested**:
2278  - Changing the pin.
2279  - Compilation and general use.
2280
2281
2282 %tex% ''' \vfill\columnbreak
2283 - **Untested**:
2284  - Faulty situation for the ErrFlag to set.
2285
2286
2287 %tex% ''' \vfill\columnbreak
2288 - **Not working**:
2289
2290
2291 %tex% ''' \end{multicols}
2292
2293
2294 **RPP API functions used:**
2295 - ``rpp_mout_set()``.
2296
2297
2298 **Relevant demos:**
2299 - ``power_toggle``.
2300
2301
2302 NEWPAGE
2303
2304 === SCIR Serial Comm. Interface Receive ===[scir_serial_comm_interface_receive]
2305
2306 ```
2307     Inputs      : 0
2308         None
2309
2310     Outputs     : 2
2311         uint8   Data
2312         bool    ErrFlag
2313
2314     Parameters  : 0
2315         None
2316 ```
2317
2318 This block allows to receive a byte from the SCI. The ErrFlag should raise if ``rpp_sci_read_nb()`` 
2319 doesn't succeed. The behavior of the ErrFlag is different from others blocks in that this block will 
2320 set or clear the flag if the call fails of success at each step. Note that this block uses the 
2321 non-blocking call to read the SCI and thus will never cause an overrun.
2322
2323
2324 **Status:**
2325 %tex% ''' \begin{multicols}{3}
2326 - **Tested**:
2327  - Receiving data.
2328  - Compilation and general use.
2329  - Faulty situation for the ErrFlag to set.
2330
2331
2332 %tex% ''' \vfill\columnbreak
2333 - **Untested**:
2334
2335
2336 %tex% ''' \vfill\columnbreak
2337 - **Not working**:
2338
2339
2340 %tex% ''' \end{multicols}
2341
2342
2343 **RPP API functions used:**
2344 - ``rpp_sci_read_nb()``.
2345
2346
2347 **Relevant demos:**
2348 - ``echo_char``.
2349
2350
2351 NEWPAGE
2352
2353 === SCIS Serial Comm. Interface Send ===[scis_serial_comm_interface_send]
2354
2355 ```
2356     Inputs      : 1
2357         uint8   Data
2358
2359     Outputs     : 1
2360         bool    ErrFlag
2361
2362     Parameters  : 2
2363         bool    UsePrintf
2364         string  PrintFormat [SETTING]
2365 ```
2366
2367 This block allows to send a byte to the SCI or to print a formatted string that uses that byte. The 
2368 UsePrintf flag allows to user to select ``rpp_sci_write_nb()`` (raw send) or ``rpp_sci_printf()`` 
2369 (formatted print) as the function the block should use on code generation. If UsePrintf is set the 
2370 PrintFormat string parameters SETTING is used as the format specifier. Note that this value is 
2371 inserted raw between quotes on code generation and thus there is no validation on it. User should
2372 always put any valid integer specifier for the value on the input of the block.
2373
2374 The behavior of this block depends if UsePrintf is set or not. If set, the call ``rpp_sci_printf()``
2375 (a blocking call) could potentially overrun the step. Also, the ErrFlag will set only if 
2376 ``rpp_sci_printf()`` returns an error, and because it should never set, once set it will never
2377 clear back. On the contrary, if UsePrintf is clear, the call ``rpp_sci_write_nb()`` (non-blocking) 
2378 is used and thus the step cannot be overrun, but because is a best-effort call it cannot guarantee that 
2379 all the data will be sent. In the case that not all data could be sent, the ErrFlag will set, but it
2380 will clear back if the next step is able to send all it's data (which with the current implementation
2381 is just one byte).
2382
2383 A possible future improvement for this block is to allow input to be non-scalar so user can print a whole
2384 string in one step using raw non-blocking write. This is currently possible if input configuration is 
2385 adapted in S-Function and TLC. The problem this could pose is is that for printf user should include
2386 specifiers for all the cells in the non-scalar input, and if unknown, then printf cannot be used.
2387
2388
2389 **Status:**
2390 %tex% ''' \begin{multicols}{3}
2391 - **Tested**:
2392  - Sending data.
2393  - Compilation and general use.
2394
2395
2396 %tex% ''' \vfill\columnbreak
2397 - **Untested**:
2398  - Faulty situation for the ErrFlag to set.
2399
2400
2401 %tex% ''' \vfill\columnbreak
2402 - **Not working**:
2403
2404
2405 %tex% ''' \end{multicols}
2406
2407
2408 **RPP API functions used:**
2409 - ``rpp_sci_write_nb()``, or ``rpp_sci_printf()``.
2410
2411
2412 **Relevant demos:**
2413 - ``echo_char`` and ``hello_world``.
2414
2415
2416 NEWPAGE
2417
2418 === SCIC Serial Comm. Interface Configure ===[scic_serial_comm_interface_configure]
2419
2420 ```
2421     Inputs      : 0
2422         None
2423
2424     Outputs     : 0
2425         None
2426
2427     Parameters  : 1
2428         uint32  Baud rate
2429 ```
2430
2431 This block allows to configure the baud rate of the SCI. There should only one block of this type per
2432 model, and this requirement is not validated, but the inclusion of several blocks is harmless and will
2433 just produce the baud rate to be changed several times, being the final baud rate to be the one of the 
2434 last executed block. This block just executes on model initialization and not on each step.
2435
2436
2437 **Status:**
2438 %tex% ''' \begin{multicols}{3}
2439 - **Tested**:
2440  - Changing baud rate.
2441  - Compilation and general use.
2442
2443
2444 %tex% ''' \vfill\columnbreak
2445 - **Untested**:
2446  - Using more than one block in a model.
2447
2448
2449 %tex% ''' \vfill\columnbreak
2450 - **Not working**:
2451
2452
2453 %tex% ''' \end{multicols}
2454
2455
2456 **RPP API functions used:**
2457 - ``rpp_sci_setup()``.
2458
2459
2460 **Relevant demos:**
2461 - ``echo_char``.
2462 - ``hello_world``.
2463
2464
2465 NEWPAGE
2466
2467 === SDRW SD-RAM Write ===[sdrw_sd_ram_write]
2468
2469 ```
2470     Inputs      : 1
2471         double  Data
2472
2473     Outputs     : 1
2474         bool    ErrFlag
2475
2476     Parameters  : 2
2477         uint8   Block ID
2478         string  PrintFormat [SETTING]
2479 ```
2480
2481 This block allows to log a double value to the SD-RAM. User needs to provide a valid PrintFormat string to
2482 format and register the double value on the log. The PrintFormat string should include two specifiers:
2483
2484 - For the block ID. Any valid integer specifier.
2485 - For the value to log. Any valid double specifier.
2486
2487
2488 Note that the value of PrintFormat is inserted raw between quotes on code generation and thus there is no 
2489 validation on it. Error to provide a valid PrintFormat could generate compilation errors on even run-time 
2490 errors (normally this generates a warning on compile time). Note that the function for logging used is
2491 ``rpp_sdr_printf()``, which is a blocking call, and can potentially overrun the step. The ErrFlag will set
2492 if ``rpp_sdr_printf()`` returns an error (for example out of memory), but will clear back if the next step 
2493 the call to this function is successful.
2494
2495
2496 **Status:**
2497 %tex% ''' \begin{multicols}{3}
2498 - **Tested**:
2499  - Logging data.
2500  - Compilation and general use.
2501
2502
2503 %tex% ''' \vfill\columnbreak
2504 - **Untested**:
2505  - Faulty situation for the ErrFlag to set.
2506
2507
2508 %tex% ''' \vfill\columnbreak
2509 - **Not working**:
2510
2511
2512 %tex% ''' \end{multicols}
2513
2514
2515 **RPP API functions used:**
2516 - ``rpp_sdr_printf()``.
2517
2518
2519 **Relevant demos:**
2520 - ``log_analog_input``.
2521
2522
2523 NEWPAGE
2524
2525 = Simulink Demos Library =[simulink_demos_library]
2526
2527
2528
2529 == Description ==[description]
2530
2531 %DONE
2532
2533 The Simulink RPP Demo Library is a set of Simulink models that use blocks from the Simulink RPP Block Library
2534 and generates code using the Simulink RPP Target. It is used as a test suite for the Simulink RPP Block Library 
2535 but they are also intended to show basic programs built using it. Because of this, the demos try to use more than 
2536 one type of block and more than one block per block type.
2537
2538 The following table shows the current status of the demos:
2539
2540 || Name                         | Implemented | Tested   |
2541  | analog_passthrough           |     YES     |  SUCCESS | 
2542  | analog_sinewave              |     YES     |  SUCCESS | 
2543  | digital_passthrough          |     YES     |  SUCCESS | 
2544  | echo_char                    |     YES     |  SUCCESS | 
2545  | hbridge_analog_control       |     YES     |  SUCCESS | 
2546  | hbridge_digital_control      |     YES     |  SUCCESS | 
2547  | hbridge_sinewave_control     |     YES     |  SUCCESS | 
2548  | hello_world                  |     YES     |  SUCCESS | 
2549  | led_blink_all                |     YES     |  SUCCESS | 
2550  | led_blink                    |     YES     |  SUCCESS | 
2551  | log_analog_input             |     YES     |  SUCCESS | 
2552  | power_toggle                 |     YES     |  SUCCESS | 
2553
2554 In the reference below you can find a complete description for each of the demos.
2555
2556 == Subdirectory  content description ==[subdirectory__content_description]
2557
2558
2559 NEWPAGE
2560
2561 == Demos Reference ==[demos_reference]
2562
2563 This section describes the demos implemented as part of this project that uses the Simulink RRP Block 
2564 Library and generates code using the RPP Simulink Target.
2565
2566 === Analog pass-through ===[analog_pass_through]
2567
2568 %tex% ''' \begin{figure}[H]\begin{center}
2569 [450-demo_analog_passthrough.png]
2570 %tex% ''' \caption{Analog Passthrough Simulink demo for RPP.}\end{center}\end{figure}
2571
2572 **Description:**
2573
2574 This demo will read analog input 1 and write it to analog output 1.
2575
2576 In laboratory the minimum read value for analog input a 0 volts is 107. The maximum read at 12 
2577 volts is 2478. The map subsystem will map the input domain (AIN)``[110, 2400]`` to the output domain 
2578 (AOUT)``[0, 4095]``.
2579
2580 NEWPAGE
2581
2582 === Analog sinewave ===[analog_sinewave]
2583
2584 %tex% ''' \begin{figure}[H]\begin{center}
2585 [450-demo_analog_sinewave.png]
2586 %tex% ''' \caption{Analog Sinewave Simulink demo for RPP.}\end{center}\end{figure}
2587
2588 **Description:**
2589
2590 This demo will generate a sinewave on analog output 1. Siwave is 10Hz and sampling rate is set to
2591 1000Hz (driven from Simulink step of 1ms, same as operating system). Amplitude is set to use AOUT
2592 full range [0-4095] which means output amplitude will be [0-12] volts. 
2593
2594 The Software oscilloscope shown should match an external one connected to AOUT 1.
2595
2596 Note that the driver configuration of the MCP4922 is set to unbuffered (which should eventually 
2597 be changed to buffered) and thus the last resolution millivolts are lost.
2598
2599 NEWPAGE
2600
2601 === Digital pass-through ===[digital_pass_through]
2602
2603 %tex% ''' \begin{figure}[H]\begin{center}
2604 [400-demo_digital_passthrough.png]
2605 %tex% ''' \caption{Digital Pass-through Simulink demo for RPP.}\end{center}\end{figure}
2606
2607 **Description:**
2608
2609 This demo will directly pass the digital values read on DIN [1-8] to LOUT [1-8], and thus acting
2610 as a digital pass-through or gateway.
2611
2612 Also note that all the ErrFlag are aggregated on a global ErrFlag.
2613
2614 NEWPAGE
2615
2616 === Echo char ===[echo_char]
2617
2618 %tex% ''' \begin{figure}[H]\begin{center}
2619 [450-demo_echo_char.png]
2620 %tex% ''' \caption{Echo Character Simulink demo for RPP.}\end{center}\end{figure}
2621
2622 **Description:**
2623
2624 This demo will echo twice (print back) any character received through the Serial Communication
2625 Interface (9600-8-N-1).
2626
2627 Note that the send subsystem is implemented a as //triggered// subsystem and will execute only
2628 if data is received, that is, Serial Receive output is non-negative. Negative values are errors.
2629
2630 NEWPAGE
2631
2632 === H-bridge analog control ===[h_bridge_analog_control]
2633
2634 %tex% ''' \begin{figure}[H]\begin{center}
2635 [450-demo_hbridge_analog_control.png]
2636 %tex% ''' \caption{H-Bridge Analog Control Simulink demo for RPP.}\end{center}\end{figure}
2637
2638 **Description:**
2639
2640 This demo will read values from the analog input, map them, and control the H-Bridge. This allows
2641 a motor connected to the H-Bridge to be controlled with a potentiometer connected to Analog Input 1.
2642
2643 Setting the potentiometer to output around 6 volts will stop the motor. Less (or greater) than 6 
2644 volts will trigger the motor in one sense (or in the other sense) and speed proportional with 1%
2645 resolution.
2646
2647 In laboratory the minimum read value for analog input is 107 at 0 volts. The maximum read at 12 volts
2648 is 2478. The map subsystem will map the input domain (AIN)``[110, 2400]`` to the output domain 
2649 (HBR)``[-1.0, 1.0]``.
2650
2651 NEWPAGE
2652
2653 === H-bridge digital control ===[h_bridge_digital_control]
2654
2655 %tex% ''' \begin{figure}[H]\begin{center}
2656 [450-demo_hbridge_digital_control.png]
2657 %tex% ''' \caption{H-Bridge Digital Control Simulink demo for RPP.}\end{center}\end{figure}
2658
2659 **Description:**
2660
2661 This demo toggle the H-Bridge from stop to full speed in one direction using digital input 1.
2662 So basically is a ON/OFF switch on DIN 1 for a motor connected on the HBR. Note the data type
2663 conversion because the output of the DIN is a boolean and the input to the HBR is a double.
2664
2665 NEWPAGE
2666
2667 === H-bridge sinewave control ===[h_bridge_sinewave_control]
2668
2669 %tex% ''' \begin{figure}[H]\begin{center}
2670 [300-demo_hbridge_sinewave_control.png]
2671 %tex% ''' \caption{H-Bridge Sinewave Control Simulink demo for RPP.}\end{center}\end{figure}
2672
2673 **Description:**
2674
2675 This demo will generate a sine wave to control the H-Bridge. Sine wave is one period per 20
2676 seconds or 0.05Hz. Sampling rate is 20Hz or 100 samples per 1/4 of period (for 1% speed 
2677 resolution change).
2678
2679 Note that the Software oscilloscope should is not the output of the H-Bridge, the H-Bridge will
2680 change current sense and the duty cycle of the pulse that drive it (PWM), it does not output
2681 analog values. The Software oscilloscope just shows what the input to the HBR block is.
2682
2683 NEWPAGE
2684
2685 === Hello world ===[hello_world]
2686
2687 %tex% ''' \begin{figure}[H]\begin{center}
2688 [450-demo_hello_world.png]
2689 %tex% ''' \caption{Hello World Simulink demo for RPP.}\end{center}\end{figure}
2690
2691 **Description:**
2692
2693 This demo will print ``"Hello Simulink"`` to the Serial Communication Interface (9600-8-N-1) one
2694 character per second. The output speed is driven by the Simulink model step which is set to one
2695 second.
2696
2697 NEWPAGE
2698
2699 === LED blink ===[led_blink]
2700
2701 %tex% ''' \begin{figure}[H]\begin{center}
2702 [450-demo_led_blink.png]
2703 %tex% ''' \caption{LED Blink Simulink demo for RPP.}\end{center}\end{figure}
2704
2705 **Description:**
2706
2707 This the simplest demo of all that shows the basics of using the RPP target and blocks. The 
2708 goal of this demo is to show the configuration of the model (not shown on the picture above),
2709 that is, how the RPP Simulink Coder Target is setup, general model setup and step setup.
2710
2711 This demo will toggle each second a LED connected on LOUT 1. The timing is set by the Simulink 
2712 model step which is set to 1 second.
2713
2714 NEWPAGE
2715
2716 === LED blink all ===[led_blink_all]
2717
2718 %tex% ''' \begin{figure}[H]\begin{center}
2719 [350-demo_led_blink_all.png]
2720 %tex% ''' \caption{LED Blink All Simulink demo for RPP.}\end{center}\end{figure}
2721
2722 **Description:**
2723
2724 This demo will toggle all LEDs connected to the LOUT port. Even outputs pins will be negated.
2725 Toggle will happen each second. The timing is driven by Simulink model step configuration that
2726 is set to 1 second. All blocks ErrFlags are aggregated into one global ErrFlag.
2727
2728 NEWPAGE
2729
2730 === Log analog input ===[log_analog_input]
2731
2732 %tex% ''' \begin{figure}[H]\begin{center}
2733 [450-demo_log_analog_input.png]
2734 %tex% ''' \caption{Log Analog Input Simulink demo for RPP.}\end{center}\end{figure}
2735
2736 **Description:**
2737
2738 This demo will log once per second the value read on the analog input 1. User can read the log 
2739 using the SCI logging integrated command processor (9600-8-N-1). Logging block ID set to 1. The 
2740 timing is driven by Simulink model step configuration that is set to 1 second.
2741
2742 NEWPAGE
2743
2744 === Power toggle ===[power_toggle]
2745
2746 %tex% ''' \begin{figure}[H]\begin{center}
2747 [300-demo_power_toggle.png]
2748 %tex% ''' \caption{Power Toggle Simulink demo for RPP.}\end{center}\end{figure}
2749
2750 **Description:**
2751
2752 This demo will toggle the power output once per second. If an error is detected on at least one of
2753 the outputs a generic error message is printed to the serial line. The timing is driven by Simulink 
2754 model step configuration that is set to 1 second. Power outputs can drive a load up to 2A, so please
2755 take into account required safety considerations.
2756
2757 NEWPAGE
2758
2759 = Glossary =[glossary]
2760
2761 : ADC
2762   //Analog to Digital Converter.// @@
2763   Hardware circuitry that converts a continuous physical quantity (usually voltage) to a
2764   digital number that represents the quantity's amplitude.
2765
2766 : AIN
2767   //Analog Input.// @@
2768   Mnemonic to refer to or something related to the analog input (ADC) hardware module.
2769
2770 : AOUT
2771   //Analog Output.// @@
2772   Mnemonic to refer to or something related to the analog output (DAC) hardware module.
2773
2774 : CAN
2775   //Controller Area Network.// @@
2776   The CAN Bus is a vehicle bus standard designed to allow microcontrollers and devices to
2777   communicate with each other within a vehicle without a host computer.
2778   In this project it is also used as mnemonic to refer to or something related to the CAN
2779   hardware module.
2780
2781 : CGT
2782   //Code Generation Tools.// @@
2783   Name given to the tool set produced by Texas Instruments used to compile, link, optimize,
2784   assemble, archive, among others. In this project is normally used as synonym for 
2785   ``Texas Instruments ARM compiler and linker."
2786
2787 : DAC
2788   //Digital to Analog Converter.// @@
2789   Hardware circuitry that converts a digital (usually binary) code to an analog signal
2790   (current, voltage, or electric charge).
2791
2792 : DIN
2793   //Digital Input.// @@
2794   Mnemonic to refer to or something related to the digital input hardware module.
2795
2796 : ECU
2797   //Engine Control Unit.// @@
2798   A type of electronic control unit that controls a series of actuators on an internal combustion 
2799   engine to ensure the optimum running.
2800
2801 : ETH
2802   //Ethernet.// @@
2803   Mnemonic to refer to or something related to the Ethernet hardware module.
2804
2805 : FR
2806   //FlexRay.// @@
2807   FlexRay is an automotive network communications protocol developed to govern on-board automotive
2808   computing.
2809   In this project it is also used as mnemonic to refer to or something related to the FlexRay
2810   hardware module.
2811
2812 : HBR
2813   //H-Bridge.// @@
2814   Mnemonic to refer to or something related to the H-Bridge hardware module. A H-Bridge is
2815   an electronic circuit that enables a voltage to be applied across a load in either direction.
2816
2817 : HOUT
2818   //High-Power Output.// @@
2819   Mnemonic to refer to or something related to the 10A, PWM, with current sensing, high-power
2820   output hardware module.
2821
2822 : IDE
2823   //Integrated Development Environment.// @@
2824   An IDE is a Software application that provides comprehensive facilities to computer programmers 
2825   for software development.
2826
2827 : LIN
2828   //Local Interconnect Network.// @@
2829   The LIN is a serial network protocol used for communication between components in vehicles.
2830   In this project it is also used as mnemonic to refer to or something related to the LIN
2831   hardware module.
2832
2833 : LOUT
2834   //Logic Output.// @@
2835   Mnemonic to refer to or something related to the digital output hardware module.
2836   It is logic output (100mA), as opposed to power outputs (2A, 10A).
2837
2838 : MBD
2839   //Model-Based Design.// @@
2840   Model-Based Design (MBD) is a mathematical and visual method of addressing problems associated 
2841   with designing complex control, signal processing and communication systems.
2842
2843 : MEX
2844   //Matlab Executable.// @@
2845   Type of binary executable that can be called within Matlab. In this document the common term
2846   used is `C MEX S-Function", which means Matlab executable written in C that implements a system 
2847   function.
2848
2849 : MOUT
2850   //(Motor) Power Output.// @@
2851   Mnemonic to refer to or something related to the 2A push/pull power output hardware module.
2852
2853 : PWM
2854   //Pulse-width modulation.// @@
2855   Technique for getting analog results with digital means. Digital control is used to create a 
2856   square wave, a signal switched between on and off. This on-off pattern can simulate voltages 
2857   in between full on and off by changing the portion of the time the signal spends on versus 
2858   the time that the signal spends off. The duration of ``on time" is called the pulse width or
2859   //duty cycle//.
2860
2861 : RPP
2862   //Rapid Prototyping Platform.// @@
2863   Name of the automotive hardware board. Also generic term to define something related
2864   to the board, like the RPP Library, RPP Layer, RPP API, etc.
2865
2866 : SCI
2867   //Serial Communication Interface.// @@
2868   Serial Interface for communication through hardware's UART using communication standard RS-232.
2869   In this project it is also used as mnemonic to refer to or something related to the Serial
2870   Communication Interface hardware module.
2871
2872 : SDC
2873   //SD-Card.// @@
2874   Mnemonic to refer to or something related to the SD-Card hardware module.
2875
2876 : SDR
2877   //SD-RAM.// @@
2878   Mnemonic to refer to or something related to the SD-RAM hardware module for logging.
2879
2880 : TLC
2881   //Target Language Compiler.// @@
2882   Technology and language used to generate code in Matlab/Simulink.
2883
2884 : UART
2885   //Universal Asynchronous Receiver/Transmitter.// @@
2886   Hardware circuitry that translates data between parallel and serial forms.
2887
2888
2889
2890 NEWPAGE
2891
2892 = References =[references]
2893
2894 - Horn, M. (2013). //Software obsluhující periferie a flexray na automobilové rídicí jednotce//.
2895   (Unpublished master's thesis, Czech Technical University in Prague, Prague, Czech Republic).
2896
2897 - //Model-based design//. (n.d.). In Wikipedia. Retrieved March 10, 2013, from @@
2898   http://en.wikipedia.org/wiki/Model-based_design
2899
2900
2901 NEWPAGE
2902
2903 = Appendix A: Notes on FreeRTOS memory management =[appendix_a_notes_on_freertos_memory_management]
2904
2905 FreeRTOS provides 4 different (at the time of this writing) memory management implementations.
2906 On vanilla distribution of FreeRTOS these can be found in 
2907 ``<FreeRTOSRoot>/FreeRTOS/Source/portable/MemMang`` with the names ``heap_1.c``, ``heap_2.c``, 
2908 ``heap_3.c`` and ``heap_4.c``. The user is supposed to choose one and rename it to ``heap.c``
2909 and include it in the port for the target processor. Memory management implementation of each file 
2910 is explained in depth in:
2911
2912         [Memory Management http://www.freertos.org/a00111.html]
2913
2914 The above is a must read documentation. In summary:
2915
2916 -> ``heap_1.c``
2917
2918 - Use a static allocated array for memory and thus will be placed on the ``.bss`` section.
2919 - Subdivides the array into smaller blocks as RAM is requested.
2920 - Memory cannot be freed.
2921 - Array is as large as ``configTOTAL_HEAP_SIZE`` option in ``FreeRTOSConfig.h``.
2922
2923
2924 -> ``heap_2.c``
2925
2926 - Use a static allocated array for memory and thus will be placed on the ``.bss`` section.
2927 - Uses a best fit algorithm and allows previously allocated blocks to be freed. 
2928 - It does **not** however combine adjacent free blocks into a single large block.
2929 - Array is as large as ``configTOTAL_HEAP_SIZE`` option in ``FreeRTOSConfig.h``.
2930
2931
2932 -> ``heap_3.c``
2933
2934 - Wrapper around standard C library ``malloc()`` and ``free()``.
2935 - Wrapper makes ``malloc()`` and ``free()`` functions thread safe.
2936 - Memory is as large as defined in linker for C system heap.
2937 - ``configTOTAL_HEAP_SIZE`` option in ``FreeRTOSConfig.h`` is ignored.
2938
2939
2940 -> ``heap_4.c``
2941
2942 - Use a static allocated array for memory and thus will be placed on the ``.bss`` section.
2943 - Uses a first fit algorithm.
2944 - It **does** combine adjacent free memory blocks into a single large block (it does include a 
2945   coalescence algorithm).
2946 - Array is as large as ``configTOTAL_HEAP_SIZE`` option in ``FreeRTOSConfig.h``.
2947
2948
2949 Not all kernels available for the RPP C Library use the same implementation. This is what each
2950 kernel is currently configured to use:
2951
2952 ||        Kernel |               Origin                |  Implementation  |
2953  |   6.0.4 Posix |    Simulator from OpenPilot.org     |   ``heap_3.c``   |
2954  |  7.0.2 TMS570 |              HalCoGen               |   ``heap_1.c``   |
2955  |  7.4.0 TMS570 |              HalCoGen               |   ``heap_4.c``   |
2956  |  7.4.2 TMS570 |  Adapted from vanilla distribution  |   ``heap_4.c``   |
2957
2958 The relevant implications of this are:
2959
2960 - If a kernel with ``heap_3.c`` is used the Simulink model //C system heap size// and 
2961   //Model step task stack size// should be tightly related and the first should be large enough to 
2962   allocate system tasks and the stack for the stepping task.
2963
2964 - If a kernel with ``heap_1.c`` is used the programs should not delete tasks, queues or semaphores.
2965   If the application spawn and deletes tasks it will eventually deplete the memory available. This
2966   is the case with the //rpp-test-suite//. Note that failure to allocated memory from the array
2967   will trigger the //Malloc Failed Hook Function// ``vApplicationMallocFailedHook()``, even if the
2968   implementation doesn't use the C system ``malloc()`` function. @@
2969   Also, //Model step task stack size// should never be set larger than ``configTOTAL_HEAP_SIZE`` 
2970   option in ``FreeRTOSConfig.h``. Currently the RPP Target doesn't include a GUI option for setting
2971   ``configTOTAL_HEAP_SIZE`` because the library is statically linked and thus memory will be of the
2972   size specified when built. The RPP Target **doesn't** check that the requested memory for the
2973   step task is less than the ``configTOTAL_HEAP_SIZE``, and if greater then the application will
2974   fail at runtime and trigger the //Malloc Failed Hook Function//.
2975
2976
2977 NEWPAGE
2978
2979 = Appendix B: Known operating-system dependent files =[appendix_b_known_operating_system_dependent_files]
2980
2981 %DONE
2982
2983 This project was developed on a GNU/Linux operating system. No test for cross-platform 
2984 interoperability was performed on the code developed. Although care was taken to try to provide 
2985 platform independent code and tools this are the elements that are know to be Linux dependent:
2986
2987 - LCM1 hardware control tool ``lmc1.py``. @@
2988   This tool is both GUI and command line capable, the following just affects the GUI part. @@
2989   Command line should be usable under Windows systems.
2990
2991   __Cause__: Serial port search algorithm is Linux dependent and Gtk 3.0 dynamic Python bindings 
2992              are not yet available on other operating systems.
2993
2994 - TI CGT support file for RPP Simulink Target ``target_tools.mk``.
2995
2996   __Cause__: Use UNIX path separator ``/``.
2997
2998 - Simulink RPP Target download script ``rpp_download.m``.
2999
3000   __Cause__: Use UNIX path separator ``/``.
3001
3002 - Simulink RPP Target install script ``rpp_setup.m``.
3003
3004   __Cause__: Use UNIX path separator ``/``.
3005
3006 - Simulink RPP Block Library block compilation script ``compile_blocks.m``.
3007
3008   __Cause__: Call Matlab MEX executable with Unix name.
3009
3010 - All CCS projects under ``<repo>/rpp/lib/apps/``.
3011   __Cause__: Paths are configure using UNIX path separator ``/``.
3012
3013
3014