]> rtime.felk.cvut.cz Git - jenkicar/rpp-simulink.git/blob - rpp/blocks/sfunction_dout.c
doc: Update YAML blocks
[jenkicar/rpp-simulink.git] / rpp / blocks / sfunction_dout.c
1 /* Copyright (C) 2013, 2014 Czech Technical University in Prague
2  *
3  * Authors:
4  *     - Carlos Jenkins <carlos@jenkins.co.cr>
5  *
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.
10  *
11  * File : sfunction_ain.c
12  * Abstract:
13  *     C-MEX S-function block for writting to RPP GPIO ports.
14  *
15  * References:
16  *     header.c
17  *     trailer.c
18  *
19  * Compile with:
20  *     <matlabroot>/bin/mex sfunction_dout.c
21  */
22
23 /*
24 %YAML 1.2
25 ---
26 Name: Digital output
27 Category: IO blocks
28 Header: rpp/gio.h
29 Mnemonic: DOUT
30
31 Inputs:
32   - { name: "Digital Output value", type: "bool" }
33 Outputs:
34
35 Parameters:
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" }
40
41 # Description is in Markdown mark-up
42 Description: &desc |
43
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
48   block execution.
49
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.
52
53 Help: *desc
54
55 Status: Stable
56
57 RPP API functions used:
58   - hal_gpio_pin_get_dsc
59   - hal_gpio_pin_set_value
60   - hal_gpio_pin_conf_set
61
62 Relevant demos:
63   - gio_demo
64 ...
65 */
66
67
68 #define S_FUNCTION_NAME sfunction_dout
69 #include "header.c"
70
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"
75
76 /** Identifiers of the block parameters */
77 enum params{
78         PARAM_PORT_TYPE,
79         PARAM_PIN_NUMBER,
80         PARAM_DEFAULT_OUTPUT,
81         PARAM_OUTPUT_TYPE,
82         PARAMS_COUNT
83 };
84
85 enum port_types{
86         PORT_UNKNOWN,
87         PORT_GIOA,
88         PORT_GIOB,
89         PORT_NHET1
90 };
91
92 enum inputs{
93         IN_PIN_VALUE,
94         INPUTS_COUNT
95 };
96
97 static void mdlInitializeSizes(SimStruct *S)
98 {
99         /*
100         * Configure parameters: 4
101         *  - Port type
102         *  - Pin number
103         *  - Default output value
104         *  - Output type
105         */
106         if (!rppSetNumParams(S, PARAMS_COUNT)) {
107                 return;
108         }
109
110         /*
111         * Configure output ports: 0
112         */
113         if (!ssSetNumOutputPorts(S, 0)) {
114                 return;
115         }
116
117         /*
118         * Configure input ports: 1
119         */
120         if (!ssSetNumInputPorts(S, INPUTS_COUNT)) {
121                 return;
122         }
123
124         rppAddInputPort(S, IN_PIN_VALUE, SS_BOOLEAN);
125
126         /* Set standard options for this block */
127         rppSetStandardOptions(S);
128 }
129
130
131 #ifdef MATLAB_MEX_FILE
132 #define MDL_CHECK_PARAMETERS
133 static void mdlCheckParameters(SimStruct *S)
134 {
135         if ((int_T)mxGetPr(ssGetSFcnParam(S, PARAM_PORT_TYPE))[0] == PORT_GIOA) {
136                 if (!rppValidParamRange(S, PARAM_PIN_NUMBER, 0, 7)) {
137                         return;
138                 }
139         }
140         else if ((int_T)mxGetPr(ssGetSFcnParam(S, PARAM_PORT_TYPE))[0] == PORT_GIOB) {
141                 if (!rppValidParamRange(S, PARAM_PIN_NUMBER, 0, 7)) {
142                         return;
143                 }
144         }
145         else if ((int_T)mxGetPr(ssGetSFcnParam(S, PARAM_PORT_TYPE))[0] == PORT_NHET1) {
146                 if (!rppValidParamRange(S, PARAM_PIN_NUMBER, 0, 31)) {
147                         return;
148                 }
149         }
150         else {
151                 return;
152         }
153
154         if (!rppValidParamRange(S, PARAM_DEFAULT_OUTPUT, 0, 1)) {
155                 return;
156         }
157 }
158 #endif
159
160
161 #ifdef MATLAB_MEX_FILE
162 #define MDL_SET_WORK_WIDTHS
163 static void mdlSetWorkWidths(SimStruct *S)
164 {
165         /* Set number of run-time parameters */
166         if (!ssSetNumRunTimeParams(S, PARAMS_COUNT)) {
167                 return;
168         }
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);
174 }
175 #endif
176
177
178 #define COMMON_MDLINITIALIZESAMPLETIMES_INHERIT
179 #define UNUSED_MDLOUTPUTS
180 #define UNUSED_MDLTERMINATE
181 #include "trailer.c"