1 %% Copyright (C) 2013, 2014 Czech Technical University in Prague
4 %% - Carlos Jenkins <carlos@jenkins.co.cr>
6 %% This document contains proprietary information belonging to Czech
7 %% Technical University in Prague. Passing on and copying of this
8 %% document, and communication of its contents is not permitted
9 %% without prior written authorization.
11 %% File : sfunction_din.tlc
13 %% TLC file for inlining RPP digital input block.
16 %% BlockTypeSetup() : rtw_tlc.pdf p. 277
17 %% Start() : rtw_tlc.pdf p. 279
18 %% Outputs() : rtw_tlc.pdf p. 281
21 %implements sfunction_din "C"
26 %% Function: BlockInstanceSetup ================================================
27 %function BlockInstanceSetup(block, system) void
28 %assign ::rpp_din_present=1
29 %assign pin_num = LibBlockParameterValue(p1, 0)
34 %if EXISTS("rpp_irc_1_used") == 1
35 %<LibBlockReportError(block, "Either IRC1 or Digital Input pin 10 and 11 blocks are allowed in one model, not both.")>
37 %assign ::rpp_din_10_11_used = 1
42 %if EXISTS("rpp_irc_2_used") == 1
43 %<LibBlockReportError(block, "Either IRC2 or Digital Input pin 14 and 15 blocks are allowed in one model, not both.")>
45 %assign ::rpp_din_14_15_used = 1
51 %% Create array if not exist
52 %if EXISTS("rpp_din_in_model_array") == 0
53 %assign ::rpp_din_in_model_array = [0, 0, 0, 0, 0, 0, 0, 0]
56 %if ::rpp_din_in_model_array[%<pin_num>] == 0
57 %assign ::rpp_din_in_model_array[%<pin_num>] = 1
59 %assign err_msg = "Only one Digital Input block of pin %<pin_num> is allowed in the model."
60 %<LibBlockReportError(block, err_msg)>
66 %% Function: BlockTypeSetup ====================================================
67 %function BlockTypeSetup(block, system) void
69 %% Ensure required header files are included
70 %<RppCommonBlockTypeSetup(block, system)>
71 %<LibAddToCommonIncludes("rpp/rpp.h")>
76 %% Function: Start =============================================================
77 %function Start(block, system) Output
79 %if !SLibCodeGenForSim()
80 %assign pin_num = LibBlockParameterValue(p1, 0)
82 %assign pull_up = LibBlockParameterValue(p3, 0) - 1
83 %assign active = LibBlockParameterValue(p4, 0) - 1
84 rpp_din_setup(%<pin_num>, %<pull_up>, %<active>, FALSE);
91 %% Function: Outputs ===========================================================
92 %function Outputs(block, system) Output
94 %if !SLibCodeGenForSim()
96 %% Declare temporal variables
97 %if EXISTS("_RPP_DIN_TMP_VARS_") == 0
98 %assign ::_RPP_DIN_TMP_VARS_ = 1
103 %assign err_flag = LibBlockOutputSignal(1, "", "", 0)
105 %% First executed block must update cached values
106 %if EXISTS("_RPP_DIN_UPDATE_") == 0
107 %assign ::_RPP_DIN_UPDATE_ = 1
108 if (rpp_din_update() != SUCCESS) {
113 %% Get pin number and if to use variable threshold
114 %assign pin_num = LibBlockParameterValue(p1, 0)
115 %assign var_thr = LibBlockParameterValue(p2, 0)
119 din_tmp = rpp_din_get(%<pin_num>);
121 din_tmp = rpp_din_get_tr(%<pin_num>);
129 %assign digital_in = LibBlockOutputSignal(0, "", "", 0)
130 %<digital_in> = din_tmp;