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_out.c
13 * C-MEX S-function block for writting to RPP GPIO ports.
20 * <matlabroot>/bin/mex sfunction_gio_out.c
26 Name: General Purpose Digital Output
32 - { name: "Digital Output 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: "Initial output value", type: "uint8", range: "[0,1]" }
39 - { name: "Output Type", type: "Choice", range: "Open Drain, Push/Pull" }
41 # Description is in Markdown mark-up
44 Sets a GIO pin to a given value. Which pins are supported depends on
45 the target board. Any pin can be configured as open drain or
46 push/pull and initial output value can be specified. The initial
47 value is a value, which will appear on the pin when the GPIO module
48 is initialized and stays there until the first block execution.
50 When the pin is used in multiple GIOIN or GIOOUT blocks, an error is
57 RPP API functions used:
68 #define S_FUNCTION_NAME sfunction_gio_out
71 #define PARAM_NAME_PORT_TYPE "port_type"
72 #define PARAM_NAME_PIN_NUMBER "pin_number"
73 #define PARAM_NAME_DEFAULT_OUTPUT "default_output"
74 #define PARAM_NAME_OUTPUT_TYPE "output_type"
76 /** Identifiers of the block parameters */
89 static void mdlInitializeSizes(SimStruct *S)
91 if (!rppSetNumParams(S, PARAMS_COUNT)) {
96 * Configure output ports: 0
98 if (!ssSetNumOutputPorts(S, 0)) {
103 * Configure input ports: 1
105 if (!ssSetNumInputPorts(S, INPUTS_COUNT)) {
109 rppAddInputPort(S, IN_PIN_VALUE, SS_BOOLEAN);
111 /* Set standard options for this block */
112 rppSetStandardOptions(S);
116 #ifdef MATLAB_MEX_FILE
117 #define MDL_CHECK_PARAMETERS
118 static void mdlCheckParameters(SimStruct *S)
120 if (!mxIsChar(ssGetSFcnParam(S, PARAM_PIN_NAME))) {
121 ssSetErrorStatus(S, "Parameter to S-function must be a string.");
123 if (!rppValidParamRange(S, PARAM_DEFAULT_OUTPUT, 0, 1)) {
129 #if defined(MATLAB_MEX_FILE)
131 static void mdlRTW(SimStruct *S)
134 int8_T def_out = mxGetPr(ssGetSFcnParam(S, PARAM_DEFAULT_OUTPUT))[0];
135 int8_T out_type = mxGetPr(ssGetSFcnParam(S, PARAM_OUTPUT_TYPE))[0];
137 if (mxGetString(ssGetSFcnParam(S, PARAM_PIN_NAME), pin_name, sizeof(pin_name)) != 0) {
138 ssSetErrorStatus(S,"mxGetString error in mdlRTW");
142 if (!ssWriteRTWParamSettings(S, 3,
143 SSWRITE_VALUE_STR, "PinName", pin_name,
144 SSWRITE_VALUE_DTYPE_NUM, "DefOut", &def_out, DTINFO(SS_INT8, COMPLEX_NO),
145 SSWRITE_VALUE_DTYPE_NUM, "OutType", &out_type, DTINFO(SS_INT8, COMPLEX_NO))) {
146 ssSetErrorStatus(S, "ssWriteRTWParamSettings failed");
153 #define COMMON_MDLINITIALIZESAMPLETIMES_INHERIT
154 #define UNUSED_MDLOUTPUTS
155 #define UNUSED_MDLTERMINATE