]> rtime.felk.cvut.cz Git - pes-rpp/rpp-simulink.git/blob - rpp/blocks/tlc_c/sfunction_gio_in.tlc
gio blocks: Allow users to select the pin from a list
[pes-rpp/rpp-simulink.git] / rpp / blocks / tlc_c / sfunction_gio_in.tlc
1 %% Copyright (C) 2013, 2015 Czech Technical University in Prague
2 %%
3 %% Authors:
4 %%     - Carlos Jenkins <carlos@jenkins.co.cr>
5 %%     - Michal Horn <hornmich@fel.cvut.cz>
6 %%
7 %% This document contains proprietary information belonging to Czech
8 %% Technical University in Prague. Passing on and copying of this
9 %% document, and communication of its contents is not permitted
10 %% without prior written authorization.
11 %%
12 %% File : sfunction_gio_in.tlc
13 %% Abstract:
14 %%     TLC file for inlining RPP digital input block.
15 %%
16 %% References:
17 %%     BlockTypeSetup() : rtw_tlc.pdf p. 277
18 %%     Start()          : rtw_tlc.pdf p. 279
19 %%     Outputs()        : rtw_tlc.pdf p. 281
20
21
22 %implements sfunction_gio_in "C"
23
24 %include "common.tlc"
25
26
27 %% Function: BlockTypeSetup ====================================================
28 %function BlockTypeSetup(block, system) void
29
30         %% Ensure required header files are included
31         %<RppCommonBlockTypeSetup(block, system)>
32         %<LibAddToCommonIncludes("rpp/rpp.h")>
33         %assign ::rpp_gio_in_present = 1
34
35 %endfunction
36
37 %function BlockInstanceSetup(block, system) void
38     %assign pin_name = SFcnParamSettings.PinName
39
40         %% Ensure that every pin is configured only once
41         %if EXISTS("::rpp_gio_%<pin_name>_present") == 0
42                 %assign ::rpp_gio_%<pin_name>_present = 1
43         %else
44                 %<LibBlockReportError(block, "GIO pin %<pin_name> has already been configured.")>
45         %endif
46 %endfunction
47
48 %% Function: Start =============================================================
49 %function Start(block, system) Output
50     %assign pin_name = SFcnParamSettings.PinName
51     %assign pull_type   = SFcnParamSettings.PullType
52
53         %if !SLibCodeGenForSim()
54                 %if pull_type == 1              %% Tri-state
55             rpp_gio_setup(PIN_%<pin_name>, RPP_GIO_IN, RPP_GIO_MODE_PULLDIS, FALSE);
56                 %elseif pull_type == 2  %% Pull up
57             rpp_gio_setup(PIN_%<pin_name>, RPP_GIO_IN, RPP_GIO_MODE_PULLUP, FALSE);
58                 %elseif pull_type == 3  %% Pull down
59             rpp_gio_setup(PIN_%<pin_name>, RPP_GIO_IN, RPP_GIO_MODE_PULLDOWN, FALSE);
60                 %else   %% error
61                         %<LibBlockReportError(block, "Bad pull_type value: %<pull_type>")>
62                 %endif
63         %endif
64
65 %endfunction
66
67
68 %% Function: Outputs ===========================================================
69 %function Outputs(block, system) Output
70
71         %if !SLibCodeGenForSim()
72                 %assign digital_in = LibBlockOutputSignal(0, "", "", 0)
73         %assign pin_name = SFcnParamSettings.PinName
74         /% TODO: Handle FAILURE (add error output?) %/
75                 %<digital_in> = rpp_gio_get(PIN_%<pin_name>) ? TRUE : FALSE;
76         %endif
77
78 %endfunction
79
80 %% [EOF]