1 /* Copyright (C) 2013, 2014, 2015 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_gio_in.c
13 * C-MEX S-function block for reading from RPP GPIO ports.
20 * <matlabroot>/bin/mex sfunction_gio_in.c
26 Name: General Purpose Digital Input
34 - { name: "Digital Input value", type: "bool" }
36 - { name: "Pin", type: "Choice", range: "Target dependent pin names or '---'" }
37 - { name: "Pin name", type: "String", note: "Pin name as defined in gio_def.h. This parameter is only visible if *Pin* is '---'." }
38 - { name: "Input Type", type: "Choice", range: "Tri-state, Pull Up, Pull Down" }
40 # Description is in Markdown mark-up
42 Reads value from a GIO pin. Which pins are supported depends on the
43 target board. The selected pin can be configured as tri-state, pull
46 When the pin is used in multiple GIOIN or GIOOUT blocks, an error is
53 RPP API functions used:
63 * Block mask documentation
64 * ------------------------
66 * This S-function has only the PIN_NAME parameter, but the block mask
67 * has two parameters for pin selection: PIN and PIN_NAME. PIN
68 * parameter is shown as a popup list with pin names available on the
69 * given board. When a pin is selected from this list, the callback
70 * function copies the value from PIN to PIN_NAME parameter. By
71 * default, PIN_NAME is not shown in the dialog.
73 * It might happen that a model designed for one board is opened for
74 * another board (i.e. rpp_setup was called when the RPP C library was
75 * compiled for another board). If we had only the PIN popup and the
76 * other board had different pin names, than the value of the PIN
77 * parameter would be lost (Simulink would set the parameter to the
78 * default value). With our two parameters, PIN_NAME is not changed
79 * (it's an edit box) and PIN is set to the default value '---', which
80 * results in PIN_NAME to be shown to the user. This way, the user
81 * sees the original pin name and can select the appropriate pin on
82 * the new board from the PIN list.
86 #define S_FUNCTION_NAME sfunction_gio_in
89 /** Identifiers of the block parameters */
101 static void mdlInitializeSizes(SimStruct *S)
103 if (!rppSetNumParams(S, PARAMS_COUNT)) {
108 * Configure input ports: 0
110 if (!ssSetNumInputPorts(S, 0)) {
115 * Configure output ports: 1
117 if (!ssSetNumOutputPorts(S, OUTPUTS_COUNT)) {
120 rppAddOutputPort(S, OUT_PIN_VALUE, SS_BOOLEAN);
122 /* Set standard options for this block */
123 rppSetStandardOptions(S);
127 #ifdef MATLAB_MEX_FILE
128 #define MDL_CHECK_PARAMETERS
129 static void mdlCheckParameters(SimStruct *S)
131 if (!mxIsChar(ssGetSFcnParam(S, PARAM_PIN_NAME))) {
132 ssSetErrorStatus(S, "Parameter to S-function must be a string.");
138 #if defined(MATLAB_MEX_FILE)
140 static void mdlRTW(SimStruct *S)
143 int8_T pull_type = mxGetPr(ssGetSFcnParam(S, PARAM_INPUT_TYPE))[0];
145 if (mxGetString(ssGetSFcnParam(S, PARAM_PIN_NAME), pin_name, sizeof(pin_name)) != 0) {
146 ssSetErrorStatus(S,"mxGetString error in mdlRTW");
150 if (!ssWriteRTWParamSettings(S, 2,
151 SSWRITE_VALUE_STR, "PinName", pin_name,
152 SSWRITE_VALUE_DTYPE_NUM, "PullType", &pull_type, DTINFO(SS_INT8, COMPLEX_NO))) {
153 ssSetErrorStatus(S, "ssWriteRTWParamSettings failed");
160 #define COMMON_MDLINITIALIZESAMPLETIMES_INHERIT
161 #define UNUSED_MDLOUTPUTS
162 #define UNUSED_MDLTERMINATE