1 %% Copyright (C) 2013, 2015 Czech Technical University in Prague
4 %% - Carlos Jenkins <carlos@jenkins.co.cr>
5 %% - Michal Horn <hornmich@fel.cvut.cz>
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
16 %% The above copyright notice and this permission notice shall be
17 %% included in all copies or substantial portions of the Software.
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.
28 %% File : sfunction_gio_out.tlc
30 %% TLC file for inlining RPP digital output block.
33 %% BlockTypeSetup() : rtw_tlc.pdf p. 277
34 %% Start() : rtw_tlc.pdf p. 279
35 %% Outputs() : rtw_tlc.pdf p. 281
38 %implements sfunction_gio_out "C"
43 %% Function: BlockTypeSetup ====================================================
44 %function BlockTypeSetup(block, system) void
46 %% Ensure required header files are included
47 %<RppCommonBlockTypeSetup(block, system)>
48 %<LibAddToCommonIncludes("rpp/rpp.h")>
49 %assign ::rpp_gio_out_present = 1
53 %function BlockInstanceSetup(block, system) void
54 %assign pin_name = SFcnParamSettings.PinName
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
60 %<LibBlockReportError(block, "GIO pin %<pin_name> has already been configured.")>
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
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);
76 %<LibBlockReportError(block, "Bad configuration value: %<config>")>
79 rpp_gio_set(PIN_%<pin_name>, FALSE);
81 rpp_gio_set(PIN_%<pin_name>, TRUE);
83 %<LibBlockReportError(block, "Bad init output value: %<init_val>")>
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>);