1 /* Copyright (C) 2013, 2014 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_ain.c
13 * C-MEX S-function block for writting to RPP GPIO ports.
20 * <matlabroot>/bin/mex sfunction_dout.c
32 - { name: "Digital Output value", type: "bool" }
36 - { name: "Port type", type: "Choice", range: "GIOA, GIOB, NHET1" }
37 - { name: "Pin number", type: "int8", range: "Depends on selected port" }
38 - { name: "Initial output value", type: "bool" }
39 - { name: "Output Type", type: "Choice", range: "Open Drain, Push/Pull" }
41 # Description is in Markdown mark-up
43 Writes a value to a GPIO pin. The block supports GIOA, GIOB and NHET1 ports.
44 Any pin can be configured as open drain or push/pull and initial output value
45 can be specified. The initial value is a value, which will appear on the pin
46 after gpio module is initialized and persists here until the first write.
53 RPP API functions used:
54 - hal_gpio_pin_get_dsc
55 - hal_gpio_pin_set_value
56 - hal_gpio_pin_conf_set
64 #define S_FUNCTION_NAME sfunction_dout
67 #define PARAM_NAME_PORT_TYPE "port_type"
68 #define PARAM_NAME_PIN_NUMBER "pin_number"
69 #define PARAM_NAME_DEFAULT_OUTPUT "default_output"
70 #define PARAM_NAME_OUTPUT_TYPE "output_type"
72 /** Identifiers of the block parameters */
93 static void mdlInitializeSizes(SimStruct *S)
96 * Configure parameters: 4
99 * - Default output value
102 if (!rppSetNumParams(S, PARAMS_COUNT)) {
107 * Configure output ports: 0
109 if (!ssSetNumOutputPorts(S, 0)) {
114 * Configure input ports: 1
116 if (!ssSetNumInputPorts(S, INPUTS_COUNT)) {
120 rppAddInputPort(S, IN_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 ((int_T)mxGetPr(ssGetSFcnParam(S, PARAM_PORT_TYPE))[0] == PORT_GIOA) {
132 if (!rppValidParamRange(S, PARAM_PIN_NUMBER, 0, 7)) {
136 else if ((int_T)mxGetPr(ssGetSFcnParam(S, PARAM_PORT_TYPE))[0] == PORT_GIOB) {
137 if (!rppValidParamRange(S, PARAM_PIN_NUMBER, 0, 7)) {
141 else if ((int_T)mxGetPr(ssGetSFcnParam(S, PARAM_PORT_TYPE))[0] == PORT_NHET1) {
142 if (!rppValidParamRange(S, PARAM_PIN_NUMBER, 0, 31)) {
150 if (!rppValidParamRange(S, PARAM_DEFAULT_OUTPUT, 0, 1)) {
157 #ifdef MATLAB_MEX_FILE
158 #define MDL_SET_WORK_WIDTHS
159 static void mdlSetWorkWidths(SimStruct *S)
161 /* Set number of run-time parameters */
162 if (!ssSetNumRunTimeParams(S, PARAMS_COUNT)) {
165 /* Register the run-time parameter 1 */
166 ssRegDlgParamAsRunTimeParam(S, PARAM_PORT_TYPE, PARAM_PORT_TYPE, PARAM_NAME_PORT_TYPE, SS_INT8);
167 ssRegDlgParamAsRunTimeParam(S, PARAM_PIN_NUMBER, PARAM_PIN_NUMBER, PARAM_NAME_PIN_NUMBER, SS_INT8);
168 ssRegDlgParamAsRunTimeParam(S, PARAM_DEFAULT_OUTPUT, PARAM_DEFAULT_OUTPUT, PARAM_NAME_DEFAULT_OUTPUT, SS_BOOLEAN);
169 ssRegDlgParamAsRunTimeParam(S, PARAM_OUTPUT_TYPE, PARAM_OUTPUT_TYPE, PARAM_NAME_OUTPUT_TYPE, SS_INT8);
174 #define COMMON_MDLINITIALIZESAMPLETIMES_INHERIT
175 #define UNUSED_MDLOUTPUTS
176 #define UNUSED_MDLTERMINATE