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_out.c
29 * C-MEX S-function block for writting to RPP GPIO ports.
36 * <matlabroot>/bin/mex sfunction_gio_out.c
42 Name: General Purpose Digital Output
48 - { name: "Digital Output 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: "Initial output value", type: "uint8", range: "[0,1]" }
55 - { name: "Output Type", type: "Choice", range: "Open Drain, Push/Pull" }
57 # Description is in Markdown mark-up
60 Sets a GIO pin to a given value. Which pins are supported depends on
61 the target board. Any pin can be configured as open drain or
62 push/pull and initial output value can be specified. The initial
63 value is a value, which will appear on the pin when the GPIO module
64 is initialized and stays there until the first block execution.
66 When the pin is used in multiple GIOIN or GIOOUT blocks, an error is
73 RPP API functions used:
84 * Block mask documentation - see sfunction_gio_in.c
87 #define S_FUNCTION_NAME sfunction_gio_out
90 #define PARAM_NAME_PORT_TYPE "port_type"
91 #define PARAM_NAME_PIN_NUMBER "pin_number"
92 #define PARAM_NAME_DEFAULT_OUTPUT "default_output"
93 #define PARAM_NAME_OUTPUT_TYPE "output_type"
95 /** Identifiers of the block parameters */
108 static void mdlInitializeSizes(SimStruct *S)
110 if (!rppSetNumParams(S, PARAMS_COUNT)) {
115 * Configure output ports: 0
117 if (!ssSetNumOutputPorts(S, 0)) {
122 * Configure input ports: 1
124 if (!ssSetNumInputPorts(S, INPUTS_COUNT)) {
128 rppAddInputPort(S, IN_PIN_VALUE, SS_BOOLEAN);
130 /* Set standard options for this block */
131 rppSetStandardOptions(S);
135 #ifdef MATLAB_MEX_FILE
136 #define MDL_CHECK_PARAMETERS
137 static void mdlCheckParameters(SimStruct *S)
139 if (!mxIsChar(ssGetSFcnParam(S, PARAM_PIN_NAME))) {
140 ssSetErrorStatus(S, "Parameter to S-function must be a string.");
142 if (!rppValidParamRange(S, PARAM_DEFAULT_OUTPUT, 0, 1)) {
148 #if defined(MATLAB_MEX_FILE)
150 static void mdlRTW(SimStruct *S)
153 int8_T def_out = mxGetPr(ssGetSFcnParam(S, PARAM_DEFAULT_OUTPUT))[0];
154 int8_T out_type = mxGetPr(ssGetSFcnParam(S, PARAM_OUTPUT_TYPE))[0];
156 if (mxGetString(ssGetSFcnParam(S, PARAM_PIN_NAME), pin_name, sizeof(pin_name)) != 0) {
157 ssSetErrorStatus(S,"mxGetString error in mdlRTW");
161 if (!ssWriteRTWParamSettings(S, 3,
162 SSWRITE_VALUE_STR, "PinName", pin_name,
163 SSWRITE_VALUE_DTYPE_NUM, "DefOut", &def_out, DTINFO(SS_INT8, COMPLEX_NO),
164 SSWRITE_VALUE_DTYPE_NUM, "OutType", &out_type, DTINFO(SS_INT8, COMPLEX_NO))) {
165 ssSetErrorStatus(S, "ssWriteRTWParamSettings failed");
172 #define COMMON_MDLINITIALIZESAMPLETIMES_INHERIT
173 #define UNUSED_MDLOUTPUTS
174 #define UNUSED_MDLTERMINATE