1 /* Copyright (C) 2013, 2014 Czech Technical University in Prague
4 * - Carlos Jenkins <carlos@jenkins.co.cr>
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
15 * The above copyright notice and this permission notice shall be
16 * included in all copies or substantial portions of the Software.
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.
27 * File : sfunction_din.c
29 * C-MEX S-function block for RPP digital input.
36 * <matlabroot>/bin/mex sfunction_din.c
50 - { name: "Digital Input", type: "bool" }
51 - { name: "ErrFlag", type: "bool" }
54 - { name: "Pin number", type: "uint8", range: "[0-15]" }
55 - { name: "Use variable threshold", type: "bool" }
56 - { name: "Pull", type: "Choice from Pull-down or Pull-up" }
57 - { name: "Active", type: "Choice from Active or Tri-stated" }
59 # Description and Help is in Markdown mark-up
62 Gets the digital value of the specified digital input pin on the RPP board.
64 If pin is high the output is 1, 0 if the pin is low.
66 If an error is detected while getting the pin, the ErrFlag is set high.
70 This block allows to read the digital inputs on the RPP board. For pins number 0-7 is not
71 relevant and not visible parameter 'Use variable threshold' and only one block for each pin
72 can be in model. And oppositely for other pins (8-15) are not relevant and visible parameters
73 of names 'Pull' and 'Active'. The variable threshold check change the read mode of the pin. For
74 setting it see Digital Input Configure block.
76 The ErrFlag should raise if `rpp_din_update()` or `rpp_din_get()` returns error. `rpp_din_update()`
77 is called just by the first DIN block in the model and thus only the first block could raise the
78 flag because of this. In case an errors occurs the return value will always be LOW (0). Because the
79 ErrFlag should never set, once set the following steps will never clear it back.
83 RPP API functions used:
90 - hbridge_digital_control
94 #define S_FUNCTION_NAME sfunction_din
98 static void mdlInitializeSizes(SimStruct *S)
101 * Configure parameters: 1
102 * - Pin number: [1-16]
103 * - Use variable threshold: [true|false]
104 * - Pull: [Pull-up|Pull-down]
105 * - Active: [Active|Tristate]
107 if (!rppSetNumParams(S, 4)) {
112 * Configure input ports: 0
114 if (!ssSetNumInputPorts(S, 0)) {
119 * Configure output ports: 2
123 if (!ssSetNumOutputPorts(S, 2)) {
126 rppAddOutputPort(S, 0, SS_BOOLEAN);
127 rppAddOutputPort(S, 1, SS_BOOLEAN);
129 /* Set standard options for this block */
130 rppSetStandardOptions(S);
134 #ifdef MATLAB_MEX_FILE
135 #define MDL_CHECK_PARAMETERS
136 static void mdlCheckParameters(SimStruct *S)
138 /* Check the parameter 1 */
139 if (!rppValidParamRange(S, 0, 0, 15)) {
143 /* Check the parameter 2 */
144 if (!rppValidParamBoolean(S, 1)) {
148 /* Check the parameter 3 */
149 if (!rppValidParamRange(S, 2, 0, 2)) {
153 /* Check the parameter 4 */
154 if (!rppValidParamRange(S, 3, 0, 2)) {
161 #ifdef MATLAB_MEX_FILE
162 #define MDL_SET_WORK_WIDTHS
163 static void mdlSetWorkWidths(SimStruct *S)
165 /* Set number of run-time parameters */
166 if (!ssSetNumRunTimeParams(S, 4)) {
170 /* Register the run-time parameter 1 */
171 ssRegDlgParamAsRunTimeParam(S, 0, 0, "p1", SS_INT8);
173 /* Register the run-time parameter 2 */
174 ssRegDlgParamAsRunTimeParam(S, 1, 1, "p2", SS_BOOLEAN);
176 /* Register the run-time parameter 3 */
177 ssRegDlgParamAsRunTimeParam(S, 2, 2, "p3", SS_UINT8);
179 /* Register the run-time parameter 4 */
180 ssRegDlgParamAsRunTimeParam(S, 3, 3, "p4", SS_UINT8);
185 #define COMMON_MDLINITIALIZESAMPLETIMES_INHERIT
186 #define UNUSED_MDLOUTPUTS
187 #define UNUSED_MDLTERMINATE