]> rtime.felk.cvut.cz Git - pes-rpp/rpp-simulink.git/blob - rpp/blocks/sfunction_din.c
Update to the new version of the RPP library
[pes-rpp/rpp-simulink.git] / rpp / blocks / sfunction_din.c
1 /* Copyright (C) 2013 Czech Technical University in Prague
2  *
3  * Authors:
4  *     - Carlos Jenkins <carlos@jenkins.co.cr>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  *
19  * File : sfunction_din.c
20  * Abstract:
21  *     C-MEX S-function block for RPP digital input.
22  *
23  * References:
24  *     header.c
25  *     trailer.c
26  *
27  * Compile with:
28  *     <matlabroot>/bin/mex sfunction_din.c
29  */
30
31
32 #define S_FUNCTION_NAME sfunction_din
33 #include "header.c"
34
35
36 static void mdlInitializeSizes(SimStruct *S)
37 {
38     /*
39      * Configure parameters: 1
40      *  - Pin number: [1-16]
41      *  - Use variable threshold: [true|false]
42      */
43     if(!rppSetNumParams(S, 2)) {
44         return;
45     }
46
47     /*
48      * Configure input ports: 0
49      */
50     if(!ssSetNumInputPorts(S, 0)) {
51         return;
52     }
53
54     /*
55      * Configure output ports: 2
56      *  - Digital input.
57      *  - Error flag.
58      */
59     if(!ssSetNumOutputPorts(S, 2)) {
60         return;
61     }
62     rppAddOutputPort(S, 0, SS_BOOLEAN);
63     rppAddOutputPort(S, 1, SS_BOOLEAN);
64
65     /* Set standard options for this block */
66     rppSetStandardOptions(S);
67 }
68
69
70 #ifdef MATLAB_MEX_FILE
71 #define MDL_CHECK_PARAMETERS
72 static void mdlCheckParameters(SimStruct *S)
73 {
74     /* Check the parameter 1 */
75     if(!rppValidParamRange(S, 0, 0, 15)) {
76         return;
77     }
78
79     /* Check the parameter 2 */
80     if(!rppValidParamBoolean(S, 1)) {
81         return;
82     }
83 }
84 #endif
85
86
87 #ifdef MATLAB_MEX_FILE
88 #define MDL_SET_WORK_WIDTHS
89 static void mdlSetWorkWidths(SimStruct *S)
90 {
91     /* Set number of run-time parameters */
92     if(!ssSetNumRunTimeParams(S, 2)) {
93         return;
94     }
95
96     /* Register the run-time parameter 1 */
97     ssRegDlgParamAsRunTimeParam(S, 0, 0, "p1", SS_UINT8);
98
99     /* Register the run-time parameter 2 */
100     ssRegDlgParamAsRunTimeParam(S, 1, 1, "p2", SS_BOOLEAN);
101 }
102 #endif
103
104
105 #define COMMON_MDLINITIALIZESAMPLETIMES_INHERIT
106 #define UNUSED_MDLOUTPUTS
107 #define UNUSED_MDLTERMINATE
108 #include "trailer.c"