]> rtime.felk.cvut.cz Git - jenkicar/rpp-simulink.git/blob - rpp/blocks/tlc_c/sfunction_din.tlc
Merge branch 'master' of rtime:jenkicar/rpp-simulink
[jenkicar/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 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_din.tlc
12 %% Abstract:
13 %%     TLC file for inlining RPP digital input block.
14 %%
15 %% References:
16 %%     BlockTypeSetup() : rtw_tlc.pdf p. 277
17 %%     Start()          : rtw_tlc.pdf p. 279
18 %%     Outputs()        : rtw_tlc.pdf p. 281
19
20
21 %implements sfunction_din "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
32 %endfunction
33
34
35 %% Function: Start =============================================================
36 %function Start(block, system) Output
37
38     %if !SLibCodeGenForSim()
39         %assign pin_num = LibBlockParameterValue(p1, 0)
40         rpp_din_setup(%<pin_num>, FALSE, TRUE, FALSE);
41     %endif
42
43 %endfunction
44
45
46 %% Function: Outputs ===========================================================
47 %function Outputs(block, system) Output
48
49     %if !SLibCodeGenForSim()
50
51         %% Declare temporal variables
52         %if EXISTS("_RPP_DIN_TMP_VARS_") == 0
53             %assign ::_RPP_DIN_TMP_VARS_ = 1
54             int8_t din_tmp;
55         %endif
56
57         %% Error flag
58         %assign err_flag = LibBlockOutputSignal(1, "", "", 0)
59
60         %% First executed block must update cached values
61         %if EXISTS("_RPP_DIN_UPDATE_") == 0
62             %assign ::_RPP_DIN_UPDATE_ = 1
63             if (rpp_din_update() != SUCCESS) {
64                 %<err_flag> = TRUE;
65             }
66         %endif
67
68         %% Get pin number and if to use variable threshold
69         %assign pin_num = LibBlockParameterValue(p1, 0)
70         %assign var_thr = LibBlockParameterValue(p2, 0)
71
72         %% Get pin value
73         %if var_thr == 0
74           din_tmp = rpp_din_get(%<pin_num>);
75         %else
76           din_tmp = rpp_din_get_tr(%<pin_num>);
77         %endif
78         if (din_tmp < 0) {
79             %<err_flag> = TRUE;
80             din_tmp = LOW;
81         }
82
83         %% Return input
84         %assign digital_in = LibBlockOutputSignal(0, "", "", 0)
85         %<digital_in> = din_tmp;
86
87     %endif
88
89 %endfunction
90
91 %% [EOF]