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 pin_num = LibBlockParameterValue(p1, 0)
33 %if EXISTS("rpp_irc_1_used") == 1
34 %<LibBlockReportError(block, "Either IRC1 or Digital Input pin 10 and 11 blocks are allowed in one model, not both.")>
36 %assign ::rpp_din_10_11_used = 1
41 %if EXISTS("rpp_irc_2_used") == 1
42 %<LibBlockReportError(block, "Either IRC2 or Digital Input pin 14 and 15 blocks are allowed in one model, not both.")>
44 %assign ::rpp_din_14_15_used = 1
50 %% Create array if not exist
51 %if EXISTS("rpp_din_in_model_array") == 0
52 %assign ::rpp_din_in_model_array = [0, 0, 0, 0, 0, 0, 0, 0]
55 %if ::rpp_din_in_model_array[%<pin_num>] == 0
56 %assign ::rpp_din_in_model_array[%<pin_num>] = 1
58 %assign err_msg = "Only one Digital Input block of pin %<pin_num> is allowed in the model."
59 %<LibBlockReportError(block, err_msg)>
65 %% Function: BlockTypeSetup ====================================================
66 %function BlockTypeSetup(block, system) void
68 %% Ensure required header files are included
69 %<RppCommonBlockTypeSetup(block, system)>
74 %% Function: Start =============================================================
75 %function Start(block, system) Output
77 %if !SLibCodeGenForSim()
78 %assign pin_num = LibBlockParameterValue(p1, 0)
80 %assign pull_up = LibBlockParameterValue(p3, 0) - 1
81 %assign active = LibBlockParameterValue(p4, 0) - 1
82 rpp_din_setup(%<pin_num>, %<pull_up>, %<active>, FALSE);
89 %% Function: Outputs ===========================================================
90 %function Outputs(block, system) Output
92 %if !SLibCodeGenForSim()
94 %% Declare temporal variables
95 %if EXISTS("_RPP_DIN_TMP_VARS_") == 0
96 %assign ::_RPP_DIN_TMP_VARS_ = 1
101 %assign err_flag = LibBlockOutputSignal(1, "", "", 0)
103 %% First executed block must update cached values
104 %if EXISTS("_RPP_DIN_UPDATE_") == 0
105 %assign ::_RPP_DIN_UPDATE_ = 1
106 if (rpp_din_update() != SUCCESS) {
111 %% Get pin number and if to use variable threshold
112 %assign pin_num = LibBlockParameterValue(p1, 0)
113 %assign var_thr = LibBlockParameterValue(p2, 0)
117 din_tmp = rpp_din_get(%<pin_num>);
119 din_tmp = rpp_din_get_tr(%<pin_num>);
127 %assign digital_in = LibBlockOutputSignal(0, "", "", 0)
128 %<digital_in> = din_tmp;