1 /* Copyright (C) 2013, 2014 Czech Technical University in Prague
4 * - Carlos Jenkins <carlos@jenkins.co.cr>
6 * This document contains proprietary information belonging to Czech
7 * Technical University in Prague. Passing on and copying of this
8 * document, and communication of its contents is not permitted
9 * without prior written authorization.
11 * File : sfunction_ain.c
13 * C-MEX S-function block for RPP analog input.
20 * <matlabroot>/bin/mex sfunction_ain.c
34 - { name: "Analog Input Pin Number", type: "uint16" }
35 - { name: "ErrFlag", type: "bool" }
38 - { name: "Pin number", type: "uint8", range: "[1–16]" }
40 # Description and Help is in Markdown mark-up
43 Gets the analog value of the specified analog input pin on the RPP
46 The value is an unsigned 16 bit integer between 0–4095 (12 bit ADC).
48 If an error is detected while reading the value, the ErrFlag is set
53 This block allows to read the analog inputs on the RPP board. The
54 ErrFlag should if raise `rpp_adc_update()` or `rpp_adc_get()`
55 returns error. `rpp_adc_update()` is called just by the first DIN
56 block in the model and thus only the first block could raise the
57 flag because of this. In case an error occurs the return value will
58 always be 0. Because the ErrFlag should never set, once set the
59 following steps will never clear it back.
63 RPP API functions used:
69 - hbridge_analog_control
75 #define S_FUNCTION_NAME sfunction_ain
79 static void mdlInitializeSizes(SimStruct *S)
82 * Configure parameters: 1
83 * - Pin number: [1-16]
85 if (!rppSetNumParams(S, 1)) {
90 * Configure input ports: 0
92 if (!ssSetNumInputPorts(S, 0)) {
97 * Configure output ports: 2
101 if (!ssSetNumOutputPorts(S, 2)) {
104 rppAddOutputPort(S, 0, SS_UINT16);
105 rppAddOutputPort(S, 1, SS_BOOLEAN);
107 /* Set standard options for this block */
108 rppSetStandardOptions(S);
112 #ifdef MATLAB_MEX_FILE
113 #define MDL_CHECK_PARAMETERS
114 static void mdlCheckParameters(SimStruct *S)
116 /* Check the parameter 1 */
117 if (!rppValidParamRange(S, 0, 1, 16)) {
124 #ifdef MATLAB_MEX_FILE
125 #define MDL_SET_WORK_WIDTHS
126 static void mdlSetWorkWidths(SimStruct *S)
128 /* Set number of run-time parameters */
129 if (!ssSetNumRunTimeParams(S, 1)) {
133 /* Register the run-time parameter 1 */
134 ssRegDlgParamAsRunTimeParam(S, 0, 0, "p1", SS_UINT8);
139 #define COMMON_MDLINITIALIZESAMPLETIMES_INHERIT
140 #define UNUSED_MDLOUTPUTS
141 #define UNUSED_MDLTERMINATE