]> rtime.felk.cvut.cz Git - pes-rpp/rpp-simulink.git/blob - rpp/blocks/tlc_c/sfunction_aout.tlc
d979ea176a43876e6596892370c4e30f7909fdd0
[pes-rpp/rpp-simulink.git] / rpp / blocks / tlc_c / sfunction_aout.tlc
1 %% Copyright (C) 2013 Czech Technical University in Prague
2 %%
3 %% Authors:
4 %%     - Carlos Jenkins <carlos@jenkins.co.cr>
5 %%
6 %% This document contains proprietary information belonging to Czech
7 %% Technical University in Prague. Passing on and copying of this
8 %% document, and communication of its contents is not permitted
9 %% without prior written authorization.
10 %%
11 %% File : sfunction_aout.tlc
12 %% Abstract:
13 %%     TLC file for inlining RPP analog output block.
14 %%
15 %% References:
16 %%     BlockTypeSetup() : refs/rtw_tlc.pdf p. 277
17 %%     Start()          : refs/rtw_tlc.pdf p. 279
18 %%     Outputs()        : refs/rtw_tlc.pdf p. 281
19
20
21 %implements sfunction_aout "C"
22
23 %include "common.tlc"
24
25
26 %% Function: BlockTypeSetup ====================================================
27 %function BlockTypeSetup(block, system) void
28
29     %% Ensure required header files are included
30     %<RppCommonBlockTypeSetup(block, system)>
31     %<LibAddToCommonIncludes("rpp/rpp.h")>
32     %assign ::rpp_aout_present=1
33
34 %endfunction
35
36
37 %% Function: Start =============================================================
38 %function Start(block, system) Output
39
40     %if !SLibCodeGenForSim()
41         %assign pin_num = LibBlockParameterValue(p1, 0)
42         rpp_dac_setup(%<pin_num>, TRUE);
43         rpp_dac_set(%<pin_num>, 0);
44         /*
45          * Warning! This should be the correct way to initialize DAC.
46          * Nevertheless rpp_dac_update() has a known bug that if it is called
47          * before starting the FreeRTOS Scheduler the application will freeze.
48          * Check the RPP API documentation for more information.
49          * Not updating now is harmless though.
50          */
51         /* rpp_dac_update(); */
52     %endif
53
54 %endfunction
55
56
57 %% Function: Outputs ===========================================================
58 %function Outputs(block, system) Output
59
60     %if !SLibCodeGenForSim()
61
62         %% Get parameters
63         %assign pin_num = LibBlockParameterValue(p1, 0)
64         %assign use_voltage = LibBlockParameterValue(p2, 0)
65
66         %% Get IO signals
67         %assign analog_out = LibBlockInputSignal(0, "", "", 0)
68         %assign err_flag = LibBlockOutputSignal(0, "", "", 0)
69
70         %if use_voltage
71         if (rpp_dac_set_voltage(%<pin_num>, %<analog_out>) != SUCCESS) {
72         %else
73         if (rpp_dac_set(%<pin_num>, %<analog_out>) != SUCCESS) {
74         %endif
75
76             %<err_flag> = TRUE;
77
78         } else {
79             %% The call is smart enought to commit only the changed outputs
80             %% so it is efficient to call this at the end of each block.
81             if (rpp_dac_update() != SUCCESS) {
82                 %<err_flag> = TRUE;
83             }
84         }
85
86     %endif
87
88 %endfunction
89
90 %% [EOF]