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_gio_in.c
29 * C-MEX S-function block for reading from RPP GPIO ports.
36 * <matlabroot>/bin/mex sfunction_gio_in.c
42 Name: General Purpose Digital Input
50 - { name: "Digital Input value", type: "bool" }
52 - { name: "Pin", type: "Choice", range: "Target dependent pin names or '---'" }
53 - { name: "Pin name", type: "String", note: "Pin name as defined in gio_def.h. This parameter is only visible if *Pin* is '---'." }
54 - { name: "Input Type", type: "Choice", range: "Tri-state, Pull Up, Pull Down" }
56 # Description is in Markdown mark-up
58 Reads value from a GIO pin. Which pins are supported depends on the
59 target board. The selected pin can be configured as tri-state, pull
62 When the pin is used in multiple GIOIN or GIOOUT blocks, an error is
69 RPP API functions used:
79 * Block mask documentation
80 * ------------------------
82 * This S-function has only the PIN_NAME parameter, but the block mask
83 * has two parameters for pin selection: PIN and PIN_NAME. PIN
84 * parameter is shown as a popup list with pin names available on the
85 * given board. When a pin is selected from this list, the callback
86 * function copies the value from PIN to PIN_NAME parameter. By
87 * default, PIN_NAME is not shown in the dialog.
89 * It might happen that a model designed for one board is opened for
90 * another board (i.e. rpp_setup was called when the RPP C library was
91 * compiled for another board). If we had only the PIN popup and the
92 * other board had different pin names, than the value of the PIN
93 * parameter would be lost (Simulink would set the parameter to the
94 * default value). With our two parameters, PIN_NAME is not changed
95 * (it's an edit box) and PIN is set to the default value '---', which
96 * results in PIN_NAME to be shown to the user. This way, the user
97 * sees the original pin name and can select the appropriate pin on
98 * the new board from the PIN list.
102 #define S_FUNCTION_NAME sfunction_gio_in
105 /** Identifiers of the block parameters */
117 static void mdlInitializeSizes(SimStruct *S)
119 if (!rppSetNumParams(S, PARAMS_COUNT)) {
124 * Configure input ports: 0
126 if (!ssSetNumInputPorts(S, 0)) {
131 * Configure output ports: 1
133 if (!ssSetNumOutputPorts(S, OUTPUTS_COUNT)) {
136 rppAddOutputPort(S, OUT_PIN_VALUE, SS_BOOLEAN);
138 /* Set standard options for this block */
139 rppSetStandardOptions(S);
143 #ifdef MATLAB_MEX_FILE
144 #define MDL_CHECK_PARAMETERS
145 static void mdlCheckParameters(SimStruct *S)
147 if (!mxIsChar(ssGetSFcnParam(S, PARAM_PIN_NAME))) {
148 ssSetErrorStatus(S, "Parameter to S-function must be a string.");
154 #if defined(MATLAB_MEX_FILE)
156 static void mdlRTW(SimStruct *S)
159 int8_T pull_type = mxGetPr(ssGetSFcnParam(S, PARAM_INPUT_TYPE))[0];
161 if (mxGetString(ssGetSFcnParam(S, PARAM_PIN_NAME), pin_name, sizeof(pin_name)) != 0) {
162 ssSetErrorStatus(S,"mxGetString error in mdlRTW");
166 if (!ssWriteRTWParamSettings(S, 2,
167 SSWRITE_VALUE_STR, "PinName", pin_name,
168 SSWRITE_VALUE_DTYPE_NUM, "PullType", &pull_type, DTINFO(SS_INT8, COMPLEX_NO))) {
169 ssSetErrorStatus(S, "ssWriteRTWParamSettings failed");
176 #define COMMON_MDLINITIALIZESAMPLETIMES_INHERIT
177 #define UNUSED_MDLOUTPUTS
178 #define UNUSED_MDLTERMINATE