1 /* Copyright (C) 2013, 2014, 2015 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_ain.c
29 * C-MEX S-function block for RPP analog input.
36 * <matlabroot>/bin/mex sfunction_ain.c
40 TODO: Change Pin number range to use macro SFUNCTION_AIN_PIN_COUNT, expanded by C preprocesor
51 - { name: "Analog Input Pin Number", type: "uint16" }
52 - { name: "ErrFlag", type: "bool" }
55 - { name: "AD1IN pin number", type: "uint8", range: "[1–16]" }
56 # TODO: Use this for RPP: - { name: "Pin number", type: "uint8", range: "[1–12]" }
58 # Description and Help is in Markdown mark-up
61 Gets the analog value of the specified analog input pin on the RPP
64 The value is an unsigned 16 bit integer between 0–4095 (12 bit ADC).
66 If an error is detected while reading the value, the ErrFlag is set
71 This block allows to read the analog inputs on the RPP board. The
72 ErrFlag should if raise `rpp_adc_update()` or `rpp_adc_get()`
73 returns error. `rpp_adc_update()` is called just by the first DIN
74 block in the model and thus only the first block could raise the
75 flag because of this. In case an error occurs the return value will
76 always be 0. Because the ErrFlag should never set, once set the
77 following steps will never clear it back.
81 RPP API functions used:
87 - hbridge_analog_control
93 #define S_FUNCTION_NAME sfunction_ain
97 static void mdlInitializeSizes(SimStruct *S)
100 * Configure parameters: 1
101 * - Pin number: [1-16]
103 if (!rppSetNumParams(S, 1)) {
108 * Configure input ports: 0
110 if (!ssSetNumInputPorts(S, 0)) {
115 * Configure output ports: 2
119 if (!ssSetNumOutputPorts(S, 2)) {
122 rppAddOutputPort(S, 0, SS_UINT16);
123 rppAddOutputPort(S, 1, SS_BOOLEAN);
125 /* Set standard options for this block */
126 rppSetStandardOptions(S);
130 #ifdef MATLAB_MEX_FILE
131 #define MDL_CHECK_PARAMETERS
132 static void mdlCheckParameters(SimStruct *S)
134 /* Check the parameter 1 */
135 if (!rppValidParamRange(S, 0, 1, 16)) {
142 #ifdef MATLAB_MEX_FILE
143 #define MDL_SET_WORK_WIDTHS
144 static void mdlSetWorkWidths(SimStruct *S)
146 /* Set number of run-time parameters */
147 if (!ssSetNumRunTimeParams(S, 1)) {
151 /* Register the run-time parameter 1 */
152 ssRegDlgParamAsRunTimeParam(S, 0, 0, "p1", SS_UINT8);
157 #define COMMON_MDLINITIALIZESAMPLETIMES_INHERIT
158 #define UNUSED_MDLOUTPUTS
159 #define UNUSED_MDLTERMINATE