%% Copyright (C) 2013, 2014 Czech Technical University in Prague %% %% Authors: %% - Carlos Jenkins %% %% Permission is hereby granted, free of charge, to any person %% obtaining a copy of this software and associated documentation %% files (the "Software"), to deal in the Software without %% restriction, including without limitation the rights to use, %% copy, modify, merge, publish, distribute, sublicense, and/or sell %% copies of the Software, and to permit persons to whom the %% Software is furnished to do so, subject to the following %% conditions: %% The above copyright notice and this permission notice shall be %% included in all copies or substantial portions of the Software. %% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, %% EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES %% OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND %% NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT %% HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, %% WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING %% FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR %% OTHER DEALINGS IN THE SOFTWARE. %% %% File : sfunction_din.tlc %% Abstract: %% TLC file for inlining RPP digital input block. %% %% References: %% BlockTypeSetup() : rtw_tlc.pdf p. 277 %% Start() : rtw_tlc.pdf p. 279 %% Outputs() : rtw_tlc.pdf p. 281 %implements sfunction_din "C" %include "common.tlc" %% Function: BlockInstanceSetup ================================================ %function BlockInstanceSetup(block, system) void %assign ::rpp_din_present=1 %assign pin_num = LibBlockParameterValue(p1, 0) %switch (%) %case 10 %case 11 %if EXISTS("rpp_irc_1_used") == 1 % %else %assign ::rpp_din_10_11_used = 1 %endif %break %case 14 %case 15 %if EXISTS("rpp_irc_2_used") == 1 % %else %assign ::rpp_din_14_15_used = 1 %endif %break %endswitch %if % < 8 %% Create array if not exist %if EXISTS("rpp_din_in_model_array") == 0 %assign ::rpp_din_in_model_array = [0, 0, 0, 0, 0, 0, 0, 0] %endif %if ::rpp_din_in_model_array[%] == 0 %assign ::rpp_din_in_model_array[%] = 1 %else %assign err_msg = "Only one Digital Input block of pin % is allowed in the model." % %endif %endif %endfunction %% Function: BlockTypeSetup ==================================================== %function BlockTypeSetup(block, system) void %% Ensure required header files are included % % %endfunction %% Function: Start ============================================================= %function Start(block, system) Output %if !SLibCodeGenForSim() %assign pin_num = LibBlockParameterValue(p1, 0) %if pin_num < 8 %assign pull_up = LibBlockParameterValue(p3, 0) - 1 %assign active = LibBlockParameterValue(p4, 0) - 1 rpp_din_setup(%, %, %, FALSE); %endif %endif %endfunction %% Function: Outputs =========================================================== %function Outputs(block, system) Output %if !SLibCodeGenForSim() %% Declare temporal variables %if EXISTS("_RPP_DIN_TMP_VARS_") == 0 %assign ::_RPP_DIN_TMP_VARS_ = 1 int8_t din_tmp; %endif %% Error flag %assign err_flag = LibBlockOutputSignal(1, "", "", 0) %% First executed block must update cached values %if EXISTS("_RPP_DIN_UPDATE_") == 0 %assign ::_RPP_DIN_UPDATE_ = 1 if (rpp_din_update() != SUCCESS) { % = TRUE; } %endif %% Get pin number and if to use variable threshold %assign pin_num = LibBlockParameterValue(p1, 0) %assign var_thr = LibBlockParameterValue(p2, 0) %% Get pin value %if var_thr == 0 din_tmp = rpp_din_get(%); %else din_tmp = rpp_din_get_tr(%); %endif if (din_tmp < 0) { % = TRUE; din_tmp = LOW; } %% Return input %assign digital_in = LibBlockOutputSignal(0, "", "", 0) % = din_tmp; %endif %endfunction %% [EOF]