]> rtime.felk.cvut.cz Git - jenkicar/rpp-simulink.git/blob - rpp/blocks/tlc_c/sfunction_irc.tlc
Change license to MIT
[jenkicar/rpp-simulink.git] / rpp / blocks / tlc_c / sfunction_irc.tlc
1 %% Copyright (C) 2013, 2014 Czech Technical University in Prague
2 %%
3 %% Authors:
4 %%     - Karel Kočí
5 %%
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
13 %% conditions:
14
15 %% The above copyright notice and this permission notice shall be
16 %% included in all copies or substantial portions of the Software.
17
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.
26 %%
27 %% File : sfunction_irc.tlc
28 %% Abstract:
29 %%     TLC file for inlining RPP IRC input block.
30 %%
31 %% References:
32 %%     BlockTypeSetup() : rtw_tlc.pdf p. 277
33 %%     Start()          : rtw_tlc.pdf p. 279
34 %%     Outputs()        : rtw_tlc.pdf p. 281
35
36
37 %implements sfunction_irc "C"
38
39 %include "common.tlc"
40
41
42 %% Function: BlockInstanceSetup ================================================
43 %function BlockInstanceSetup(block, system) void
44     %assign irc_num = LibBlockParameterValue(p1, 0)
45     
46     %switch (%<irc_num>)
47         %case 1
48             %if EXISTS("rpp_din_10_11_used") == 1
49                 %<LibBlockReportError(block, "Either IRC1 or Digital Input pin 10 and 11 blocks are allowed in one model, not both.")>
50             %else
51                 %assign ::rpp_irc_1_used = 1
52             %endif
53             %break
54         %case 2
55             %if EXISTS("rpp_din_14_15_used") == 1
56                 %<LibBlockReportError(block, "Either IRC2 or Digital Input pin 14 and 15 blocks are allowed in one model, not both.")>
57             %else
58                 %assign ::rpp_irc_2_used = 1
59             %endif
60             %break
61     %endswitch
62 %endfunction
63
64 %% Function: BlockTypeSetup ====================================================
65 %function BlockTypeSetup(block, system) void
66
67     %% Ensure required header files are included
68     %<RppCommonBlockTypeSetup(block, system)>
69     %<LibAddToCommonIncludes("rpp/rpp.h")>
70     %assign ::rpp_irc_present=1
71
72 %endfunction
73
74
75 %% Function: Start =============================================================
76 %function Start(block, system) Output
77
78     %if !SLibCodeGenForSim()
79         %assign irc_num = LibBlockParameterValue(p1, 0)
80         rpp_irc_enable(%<irc_num>);
81     %endif
82
83 %endfunction
84
85
86 %% Function: Outputs ===========================================================
87 %function Outputs(block, system) Output
88
89     %if !SLibCodeGenForSim()
90
91         %% Error flag
92         %assign err_flag = LibBlockOutputSignal(1, "", "", 0)
93
94         %% Get irc number
95         %assign irc_num = LibBlockParameterValue(p1, 0)
96
97         %% Control if irc running
98         if (rpp_irc_status(%<irc_num>) != 1) {
99             %<err_flag> = TRUE;
100         } else {
101             %% Return input
102             %assign irc_val = LibBlockOutputSignal(0, "", "", 0)
103             %<irc_val> = rpp_irc_get(%<irc_num>);
104         }
105
106     %endif
107
108 %endfunction
109
110 %% [EOF]