1 %% Copyright (C) 2013, 2014 Czech Technical University in Prague
4 %% - Carlos Jenkins <carlos@jenkins.co.cr>
6 %% Permission is hereby granted, free of charge, to any person
7 %% obtaining a copy of this software and associated documentation
8 %% files (the "Software"), to deal in the Software without
9 %% restriction, including without limitation the rights to use,
10 %% copy, modify, merge, publish, distribute, sublicense, and/or sell
11 %% copies of the Software, and to permit persons to whom the
12 %% Software is furnished to do so, subject to the following
15 %% The above copyright notice and this permission notice shall be
16 %% included in all copies or substantial portions of the Software.
18 %% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 %% EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
20 %% OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 %% NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
22 %% HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23 %% WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24 %% FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25 %% OTHER DEALINGS IN THE SOFTWARE.
27 %% File : sfunction_din.tlc
29 %% TLC file for inlining RPP digital input block.
32 %% BlockTypeSetup() : rtw_tlc.pdf p. 277
33 %% Start() : rtw_tlc.pdf p. 279
34 %% Outputs() : rtw_tlc.pdf p. 281
37 %implements sfunction_din "C"
42 %% Function: BlockInstanceSetup ================================================
43 %function BlockInstanceSetup(block, system) void
44 %assign ::rpp_din_present=1
45 %assign pin_num = LibBlockParameterValue(p1, 0)
50 %if EXISTS("rpp_irc_1_used") == 1
51 %<LibBlockReportError(block, "Either IRC1 or Digital Input pin 10 and 11 blocks are allowed in one model, not both.")>
53 %assign ::rpp_din_10_11_used = 1
58 %if EXISTS("rpp_irc_2_used") == 1
59 %<LibBlockReportError(block, "Either IRC2 or Digital Input pin 14 and 15 blocks are allowed in one model, not both.")>
61 %assign ::rpp_din_14_15_used = 1
67 %% Create array if not exist
68 %if EXISTS("rpp_din_in_model_array") == 0
69 %assign ::rpp_din_in_model_array = [0, 0, 0, 0, 0, 0, 0, 0]
72 %if ::rpp_din_in_model_array[%<pin_num>] == 0
73 %assign ::rpp_din_in_model_array[%<pin_num>] = 1
75 %assign err_msg = "Only one Digital Input block of pin %<pin_num> is allowed in the model."
76 %<LibBlockReportError(block, err_msg)>
82 %% Function: BlockTypeSetup ====================================================
83 %function BlockTypeSetup(block, system) void
85 %% Ensure required header files are included
86 %<RppCommonBlockTypeSetup(block, system)>
87 %<LibAddToCommonIncludes("rpp/rpp.h")>
92 %% Function: Start =============================================================
93 %function Start(block, system) Output
95 %if !SLibCodeGenForSim()
96 %assign pin_num = LibBlockParameterValue(p1, 0)
98 %assign pull_up = LibBlockParameterValue(p3, 0) - 1
99 %assign active = LibBlockParameterValue(p4, 0) - 1
100 rpp_din_setup(%<pin_num>, %<pull_up>, %<active>, FALSE);
107 %% Function: Outputs ===========================================================
108 %function Outputs(block, system) Output
110 %if !SLibCodeGenForSim()
112 %% Declare temporal variables
113 %if EXISTS("_RPP_DIN_TMP_VARS_") == 0
114 %assign ::_RPP_DIN_TMP_VARS_ = 1
119 %assign err_flag = LibBlockOutputSignal(1, "", "", 0)
121 %% First executed block must update cached values
122 %if EXISTS("_RPP_DIN_UPDATE_") == 0
123 %assign ::_RPP_DIN_UPDATE_ = 1
124 if (rpp_din_update() != SUCCESS) {
129 %% Get pin number and if to use variable threshold
130 %assign pin_num = LibBlockParameterValue(p1, 0)
131 %assign var_thr = LibBlockParameterValue(p2, 0)
135 din_tmp = rpp_din_get(%<pin_num>);
137 din_tmp = rpp_din_get_tr(%<pin_num>);
145 %assign digital_in = LibBlockOutputSignal(0, "", "", 0)
146 %<digital_in> = din_tmp;