]> rtime.felk.cvut.cz Git - pes-rpp/rpp-simulink.git/blob - rpp/blocks/tlc_c/sfunction_gio_out.tlc
gio blocks: Allow users to select the pin from a list
[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 %% 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_out.tlc
13 %% Abstract:
14 %%     TLC file for inlining RPP digital output 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_out "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_out_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 config = SFcnParamSettings.OutType
52         %assign init_val = SFcnParamSettings.DefOut
53
54         %if !SLibCodeGenForSim()
55                 %if config == 1         %% Open drain
56             rpp_gio_setup(PIN_%<pin_name>, RPP_GIO_OUT, RPP_GIO_MODE_PULLDIS, TRUE);
57                 %elseif config == 2     %% push/pull
58             rpp_gio_setup(PIN_%<pin_name>, RPP_GIO_OUT, RPP_GIO_MODE_PULLDIS, FALSE);
59                 %else   %% error
60                         %<LibBlockReportError(block, "Bad configuration value: %<config>")>
61                 %endif
62                 %if init_val == 0
63                         rpp_gio_set(PIN_%<pin_name>, FALSE);
64                 %elseif init_val == 1
65                         rpp_gio_set(PIN_%<pin_name>, TRUE);
66                 %else
67                         %<LibBlockReportError(block, "Bad init output value: %<init_val>")>
68                 %endif
69         %endif
70
71 %endfunction
72
73
74 %% Function: Outputs ===========================================================
75 %function Outputs(block, system) Output
76   %if !SLibCodeGenForSim()
77     %assign pin_name = SFcnParamSettings.PinName
78     %assign digital_out = LibBlockInputSignal(0, "", "", 0)
79     rpp_gio_set(PIN_%<pin_name>, %<digital_out>);
80   %endif
81 %endfunction
82
83 %% [EOF]