]> rtime.felk.cvut.cz Git - pes-rpp/rpp-simulink.git/blob - rpp/blocks/tlc_c/sfunction_gio_out.tlc
Change license to MIT
[pes-rpp/rpp-simulink.git] / rpp / blocks / tlc_c / sfunction_gio_out.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 %% Permission is hereby granted, free of charge, to any person
8 %% obtaining a copy of this software and associated documentation
9 %% files (the "Software"), to deal in the Software without
10 %% restriction, including without limitation the rights to use,
11 %% copy, modify, merge, publish, distribute, sublicense, and/or sell
12 %% copies of the Software, and to permit persons to whom the
13 %% Software is furnished to do so, subject to the following
14 %% conditions:
15
16 %% The above copyright notice and this permission notice shall be
17 %% included in all copies or substantial portions of the Software.
18
19 %% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20 %% EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
21 %% OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22 %% NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
23 %% HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
24 %% WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25 %% FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
26 %% OTHER DEALINGS IN THE SOFTWARE.
27 %%
28 %% File : sfunction_gio_out.tlc
29 %% Abstract:
30 %%     TLC file for inlining RPP digital output block.
31 %%
32 %% References:
33 %%     BlockTypeSetup() : rtw_tlc.pdf p. 277
34 %%     Start()          : rtw_tlc.pdf p. 279
35 %%     Outputs()        : rtw_tlc.pdf p. 281
36
37
38 %implements sfunction_gio_out "C"
39
40 %include "common.tlc"
41
42
43 %% Function: BlockTypeSetup ====================================================
44 %function BlockTypeSetup(block, system) void
45
46         %% Ensure required header files are included
47         %<RppCommonBlockTypeSetup(block, system)>
48         %<LibAddToCommonIncludes("rpp/rpp.h")>
49         %assign ::rpp_gio_out_present = 1
50
51 %endfunction
52
53 %function BlockInstanceSetup(block, system) void
54     %assign pin_name = SFcnParamSettings.PinName
55
56         %% Ensure that every pin is configured only once
57         %if EXISTS("::rpp_gio_%<pin_name>_present") == 0
58                 %assign ::rpp_gio_%<pin_name>_present = 1
59         %else
60                 %<LibBlockReportError(block, "GIO pin %<pin_name> has already been configured.")>
61         %endif
62 %endfunction
63
64 %% Function: Start =============================================================
65 %function Start(block, system) Output
66     %assign pin_name = SFcnParamSettings.PinName
67         %assign config = SFcnParamSettings.OutType
68         %assign init_val = SFcnParamSettings.DefOut
69
70         %if !SLibCodeGenForSim()
71                 %if config == 1         %% Open drain
72             rpp_gio_setup(PIN_%<pin_name>, RPP_GIO_OUT, RPP_GIO_MODE_PULLDIS, TRUE);
73                 %elseif config == 2     %% push/pull
74             rpp_gio_setup(PIN_%<pin_name>, RPP_GIO_OUT, RPP_GIO_MODE_PULLDIS, FALSE);
75                 %else   %% error
76                         %<LibBlockReportError(block, "Bad configuration value: %<config>")>
77                 %endif
78                 %if init_val == 0
79                         rpp_gio_set(PIN_%<pin_name>, FALSE);
80                 %elseif init_val == 1
81                         rpp_gio_set(PIN_%<pin_name>, TRUE);
82                 %else
83                         %<LibBlockReportError(block, "Bad init output value: %<init_val>")>
84                 %endif
85         %endif
86
87 %endfunction
88
89
90 %% Function: Outputs ===========================================================
91 %function Outputs(block, system) Output
92   %if !SLibCodeGenForSim()
93     %assign pin_name = SFcnParamSettings.PinName
94     %assign digital_out = LibBlockInputSignal(0, "", "", 0)
95     rpp_gio_set(PIN_%<pin_name>, %<digital_out>);
96   %endif
97 %endfunction
98
99 %% [EOF]