]> rtime.felk.cvut.cz Git - pes-rpp/rpp-simulink.git/blob - rpp/blocks/sfunction_dinc.c
Change license to MIT
[pes-rpp/rpp-simulink.git] / rpp / blocks / sfunction_dinc.c
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_dinc.c
28  * Abstract:
29  *     C-MEX S-function block for RPP digital input configuration.
30  *
31  * References:
32  *     header.c
33  *     trailer.c
34  *
35  * Compile with:
36  *     <matlabroot>/bin/mex sfunction_dinc.c
37  */
38
39 /*
40 %YAML 1.2
41 ---
42 Name: Digital Input Configure
43 Category: IO blocks
44 Header: rpp/din.h
45 Mnemonic: DINC
46
47 Inputs:
48
49 Outputs:
50
51 Parameters:
52   - { name: "Reference voltage for pins 8-11",  type: "uint16", range: "[0-4095]" }
53   - { name: "Reference voltage for pins 12-15", type: "uint16", range: "[0-4095]" }
54
55 # Description and Help is in Markdown mark-up
56 Description: &desc |
57
58   This block allows one to set reference voltage (threshold) for DIN pins. The block have two parameters,
59   one for pins 8 - 11 and the other for pins 12 - 15.
60
61 Help: *desc
62
63 Status: Stable
64
65 RPP API functions used:
66     - rpp_din_ref()
67
68 Relevant demos:
69 ...
70 */
71
72 #define S_FUNCTION_NAME sfunction_dinc
73 #include "header.c"
74
75
76 static void mdlInitializeSizes(SimStruct *S)
77 {
78     /*
79      * Configure parameters: 2
80      *  - Reference voltage for pins 8-11:  [0-4095]
81      *  - Reference voltage for pins 12-15: [0-4095]
82      */
83     if (!rppSetNumParams(S, 2)) {
84         return;
85     }
86
87     /*
88      * Configure input ports: 0
89      */
90     if (!ssSetNumInputPorts(S, 0)) {
91         return;
92     }
93
94     /*
95      * Configure output ports: 0
96      */
97     if (!ssSetNumOutputPorts(S, 0)) {
98         return;
99     }
100     
101     /* Set standard options for this block */
102     rppSetStandardOptions(S);
103 }
104
105
106 #ifdef MATLAB_MEX_FILE
107 #define MDL_CHECK_PARAMETERS
108 static void mdlCheckParameters(SimStruct *S)
109 {
110     /* Check the parameter 1 */
111     if (!rppValidParamRange(S, 0, 0, 4095)) {
112         return;
113     }
114     
115     /* Check the parameter 2 */
116     if (!rppValidParamRange(S, 1, 0, 4095)) {
117         return;
118     }
119 }
120 #endif
121
122
123 #ifdef MATLAB_MEX_FILE
124 #define MDL_SET_WORK_WIDTHS
125 static void mdlSetWorkWidths(SimStruct *S)
126 {
127     /* Set number of run-time parameters */
128     if (!ssSetNumRunTimeParams(S, 2)) {
129         return;
130     }
131
132     /* Register the run-time parameter 1 */
133     ssRegDlgParamAsRunTimeParam(S, 0, 0, "p1", SS_UINT16);
134     ssRegDlgParamAsRunTimeParam(S, 1, 1, "p2", SS_UINT16);
135 }
136 #endif
137
138
139 #define COMMON_MDLINITIALIZESAMPLETIMES_INHERIT
140 #define UNUSED_MDLOUTPUTS
141 #define UNUSED_MDLTERMINATE
142 #include "trailer.c"