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: "[0–7] (depends on selected port)" }
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 Writes a value to a GPIO pin. The block supports GIOA, GIOB and NHET1 ports.
45 Any pin can be configured as open drain or push/pull and initial output value
46 can be specified. The initial value is a value, which will appear on the pin
47 when the GPIO module is initialized and stays there until the first
50 It is not allowed to write to one pin by using more then one DOUT blocks.
51 It is not allowed to use DOUT and DIN blocks on one GPIO pin.
57 RPP API functions used:
58 - hal_gpio_pin_get_dsc
59 - hal_gpio_pin_set_value
60 - hal_gpio_pin_conf_set
68 #define S_FUNCTION_NAME sfunction_dout
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 */
97 static void mdlInitializeSizes(SimStruct *S)
100 * Configure parameters: 4
103 * - Default output value
106 if (!rppSetNumParams(S, PARAMS_COUNT)) {
111 * Configure output ports: 0
113 if (!ssSetNumOutputPorts(S, 0)) {
118 * Configure input ports: 1
120 if (!ssSetNumInputPorts(S, INPUTS_COUNT)) {
124 rppAddInputPort(S, IN_PIN_VALUE, SS_BOOLEAN);
126 /* Set standard options for this block */
127 rppSetStandardOptions(S);
131 #ifdef MATLAB_MEX_FILE
132 #define MDL_CHECK_PARAMETERS
133 static void mdlCheckParameters(SimStruct *S)
135 if ((int_T)mxGetPr(ssGetSFcnParam(S, PARAM_PORT_TYPE))[0] == PORT_GIOA) {
136 if (!rppValidParamRange(S, PARAM_PIN_NUMBER, 0, 7)) {
140 else if ((int_T)mxGetPr(ssGetSFcnParam(S, PARAM_PORT_TYPE))[0] == PORT_GIOB) {
141 if (!rppValidParamRange(S, PARAM_PIN_NUMBER, 0, 7)) {
145 else if ((int_T)mxGetPr(ssGetSFcnParam(S, PARAM_PORT_TYPE))[0] == PORT_NHET1) {
146 if (!rppValidParamRange(S, PARAM_PIN_NUMBER, 0, 31)) {
154 if (!rppValidParamRange(S, PARAM_DEFAULT_OUTPUT, 0, 1)) {
161 #ifdef MATLAB_MEX_FILE
162 #define MDL_SET_WORK_WIDTHS
163 static void mdlSetWorkWidths(SimStruct *S)
165 /* Set number of run-time parameters */
166 if (!ssSetNumRunTimeParams(S, PARAMS_COUNT)) {
169 /* Register the run-time parameter 1 */
170 ssRegDlgParamAsRunTimeParam(S, PARAM_PORT_TYPE, PARAM_PORT_TYPE, PARAM_NAME_PORT_TYPE, SS_INT8);
171 ssRegDlgParamAsRunTimeParam(S, PARAM_PIN_NUMBER, PARAM_PIN_NUMBER, PARAM_NAME_PIN_NUMBER, SS_INT8);
172 ssRegDlgParamAsRunTimeParam(S, PARAM_DEFAULT_OUTPUT, PARAM_DEFAULT_OUTPUT, PARAM_NAME_DEFAULT_OUTPUT, SS_BOOLEAN);
173 ssRegDlgParamAsRunTimeParam(S, PARAM_OUTPUT_TYPE, PARAM_OUTPUT_TYPE, PARAM_NAME_OUTPUT_TYPE, SS_INT8);
178 #define COMMON_MDLINITIALIZESAMPLETIMES_INHERIT
179 #define UNUSED_MDLOUTPUTS
180 #define UNUSED_MDLTERMINATE