]> rtime.felk.cvut.cz Git - pes-rpp/rpp-simulink.git/blob - rpp/blocks/tlc_c/sfunction_din.tlc
Fixed small bug in library and fixed TLCs to support multiple block code generation...
[pes-rpp/rpp-simulink.git] / rpp / blocks / tlc_c / sfunction_din.tlc
1 %% Copyright (C) 2013 Czech Technical University in Prague
2 %%
3 %% Authors:
4 %%     - Carlos Jenkins <carlos@jenkins.co.cr>
5 %%
6 %% This program is free software; you can redistribute it and/or modify
7 %% it under the terms of the GNU General Public License as published by
8 %% the Free Software Foundation; either version 2 of the License, or
9 %% (at your option) any later version.
10 %%
11 %% This program is distributed in the hope that it will be useful,
12 %% but WITHOUT ANY WARRANTY; without even the implied warranty of
13 %% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 %% GNU General Public License for more details.
15 %%
16 %% You should have received a copy of the GNU General Public License
17 %% along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 %%
19 %% File : sfunction_din.tlc
20 %% Abstract:
21 %%     TLC file for inlining RPP digital input block.
22 %%
23 %% References:
24 %%     BlockTypeSetup() : rtw_tlc.pdf p. 277
25 %%     Start()          : rtw_tlc.pdf p. 279
26 %%     Outputs()        : rtw_tlc.pdf p. 281
27
28
29 %implements sfunction_din "C"
30
31 %include "common.tlc"
32
33
34 %% Function: BlockTypeSetup ====================================================
35 %function BlockTypeSetup(block, system) void
36
37     %% Ensure required header files are included
38     %<RppCommonBlockTypeSetup(block, system)>
39
40 %endfunction
41
42
43 %% Function: Start =============================================================
44 %function Start(block, system) Output
45
46     %if !SLibCodeGenForSim()
47         %assign pin_num = LibBlockParameterValue(p1, 0)
48         rpp_din_setup(%<pin_num>, FALSE, TRUE, FALSE);
49     %endif
50
51 %endfunction
52
53
54 %% Function: Outputs ===========================================================
55 %function Outputs(block, system) Output
56
57     %if !SLibCodeGenForSim()
58
59         %% Declare temporal variables
60         %if EXISTS("_RPP_DIN_TMP_VARS_") == 0
61             %assign ::_RPP_DIN_TMP_VARS_ = 1
62             int8_t din_tmp;
63         %endif
64
65         %% Error flag
66         %assign err_flag = LibBlockOutputSignal(1, "", "", 0)
67
68         %% First executed block must update cached values
69         %if EXISTS("_RPP_DIN_UPDATE_") == 0
70             %assign ::_RPP_DIN_UPDATE_ = 1
71             if(rpp_din_update() != SUCCESS) {
72                 %<err_flag> = TRUE;
73             }
74         %endif
75
76         %% Get pin number and if to use variable threshold
77         %assign pin_num = LibBlockParameterValue(p1, 0)
78         %assign var_thr = LibBlockParameterValue(p2, 0)
79
80         %% Get pin value
81         din_tmp = rpp_din_get(%<pin_num>, %<var_thr>);
82         if(din_tmp < 0) {
83             %<err_flag> = TRUE;
84             din_tmp = LOW;
85         }
86
87         %% Return input
88         %assign digital_in = LibBlockOutputSignal(0, "", "", 0)
89         %<digital_in> = din_tmp;
90
91     %endif
92
93 %endfunction
94
95 %% [EOF]