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 #define S_FUNCTION_NAME sfunction_gio_in
66 /** Identifiers of the block parameters */
78 static void mdlInitializeSizes(SimStruct *S)
80 if (!rppSetNumParams(S, PARAMS_COUNT)) {
85 * Configure input ports: 0
87 if (!ssSetNumInputPorts(S, 0)) {
92 * Configure output ports: 1
94 if (!ssSetNumOutputPorts(S, OUTPUTS_COUNT)) {
97 rppAddOutputPort(S, OUT_PIN_VALUE, SS_BOOLEAN);
99 /* Set standard options for this block */
100 rppSetStandardOptions(S);
104 #ifdef MATLAB_MEX_FILE
105 #define MDL_CHECK_PARAMETERS
106 static void mdlCheckParameters(SimStruct *S)
108 if (!mxIsChar(ssGetSFcnParam(S, PARAM_PIN_NAME))) {
109 ssSetErrorStatus(S, "Parameter to S-function must be a string.");
115 #if defined(MATLAB_MEX_FILE)
117 static void mdlRTW(SimStruct *S)
120 int8_T pull_type = mxGetPr(ssGetSFcnParam(S, PARAM_INPUT_TYPE))[0];
122 if (mxGetString(ssGetSFcnParam(S, PARAM_PIN_NAME), pin_name, sizeof(pin_name)) != 0) {
123 ssSetErrorStatus(S,"mxGetString error in mdlRTW");
127 if (!ssWriteRTWParamSettings(S, 2,
128 SSWRITE_VALUE_STR, "PinName", pin_name,
129 SSWRITE_VALUE_DTYPE_NUM, "PullType", &pull_type, DTINFO(SS_INT8, COMPLEX_NO))) {
130 ssSetErrorStatus(S, "ssWriteRTWParamSettings failed");
137 #define COMMON_MDLINITIALIZESAMPLETIMES_INHERIT
138 #define UNUSED_MDLOUTPUTS
139 #define UNUSED_MDLTERMINATE