]> rtime.felk.cvut.cz Git - pes-rpp/rpp-simulink.git/blobdiff - rpp/blocks/tlc_c/sfunction_din.tlc
Change license to MIT
[pes-rpp/rpp-simulink.git] / rpp / blocks / tlc_c / sfunction_din.tlc
index e38c91000660f90f87e4a9cdd6c91ac30c7d769d..907393204dc4d6a2b8c97d4561a21840d3a6f4eb 100644 (file)
@@ -1,12 +1,28 @@
-%% Copyright (C) 2013 Czech Technical University in Prague
+%% Copyright (C) 2013, 2014 Czech Technical University in Prague
 %%
 %% Authors:
 %%     - Carlos Jenkins <carlos@jenkins.co.cr>
 %%
-%% This document contains proprietary information belonging to Czech
-%% Technical University in Prague. Passing on and copying of this
-%% document, and communication of its contents is not permitted
-%% without prior written authorization.
+%% 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:
 %include "common.tlc"
 
 
+%% Function: BlockInstanceSetup ================================================
+%function BlockInstanceSetup(block, system) void
+    %assign ::rpp_din_present=1
+    %assign pin_num = LibBlockParameterValue(p1, 0)
+    
+    %switch (%<pin_num>)
+        %case 10
+        %case 11
+            %if EXISTS("rpp_irc_1_used") == 1
+                %<LibBlockReportError(block, "Either IRC1 or Digital Input pin 10 and 11 blocks are allowed in one model, not both.")>
+            %else
+                %assign ::rpp_din_10_11_used = 1
+            %endif
+            %break
+        %case 14
+        %case 15
+            %if EXISTS("rpp_irc_2_used") == 1
+                %<LibBlockReportError(block, "Either IRC2 or Digital Input pin 14 and 15 blocks are allowed in one model, not both.")>
+            %else
+                %assign ::rpp_din_14_15_used = 1
+            %endif
+            %break
+    %endswitch
+
+    %if %<pin_num> < 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[%<pin_num>] == 0
+            %assign ::rpp_din_in_model_array[%<pin_num>] = 1
+        %else
+            %assign err_msg = "Only one Digital Input block of pin %<pin_num> is allowed in the model."
+            %<LibBlockReportError(block, err_msg)>
+        %endif
+    %endif
+
+%endfunction
+
 %% Function: BlockTypeSetup ====================================================
 %function BlockTypeSetup(block, system) void
 
     %% Ensure required header files are included
     %<RppCommonBlockTypeSetup(block, system)>
+    %<LibAddToCommonIncludes("rpp/rpp.h")>
 
 %endfunction
 
 
     %if !SLibCodeGenForSim()
         %assign pin_num = LibBlockParameterValue(p1, 0)
-        rpp_din_setup(%<pin_num>, FALSE, TRUE, FALSE);
+        %if pin_num < 8
+            %assign pull_up = LibBlockParameterValue(p3, 0) - 1
+            %assign active = LibBlockParameterValue(p4, 0) - 1
+            rpp_din_setup(%<pin_num>, %<pull_up>, %<active>, FALSE);
+        %endif
     %endif
 
 %endfunction