]> rtime.felk.cvut.cz Git - pes-rpp/rpp-simulink.git/blob - rpp/blocks/sfunction_din.c
Whitespace changes in DIN and DOUT documentation
[pes-rpp/rpp-simulink.git] / rpp / blocks / sfunction_din.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 reading from RPP GPIO ports.
14  *
15  * References:
16  *     header.c
17  *     trailer.c
18  *
19  * Compile with:
20  *     <matlabroot>/bin/mex sfunction_din.c
21  */
22
23 /*
24 %YAML 1.2
25 ---
26 Name: Digital input
27 Category: IO blocks
28 Header: rpp/gio.h
29 Mnemonic: DIN
30
31 Inputs:
32
33 Outputs:
34   - { name: "Digital Input value", type: "bool" }
35 Parameters:
36   - { name: "Port type", type: "Choice", range: "GIOA, GIOB, NHET1" }
37   - { name: "Pin number", type: "int8", range: "Depends on selected port" }
38   - { name: "Input Type", type: "Choice", range: "Tri-state, Pull Up, Pull Down" }
39
40 # Description is in Markdown mark-up
41 Description:
42   Reads a value from a GPIO pin. The block supports GIOA, GIOB and NHET1 ports.
43   Any pin can be configured as tri-state, pull up or pull down.
44
45 Status:
46   Tested:
47   Untested:
48   Not working:
49
50 RPP API functions used:
51   - hal_gpio_pin_get_dsc
52   - hal_gpio_pin_get_value
53   - hal_gpio_pin_conf_set
54
55 Relevant demos:
56   - gio_demo
57 ...
58 */
59
60
61 #define S_FUNCTION_NAME sfunction_din
62 #include "header.c"
63
64 #define PARAM_NAME_PORT_TYPE            "port_type"
65 #define PARAM_NAME_PIN_NUMBER           "pin_number"
66 #define PARAM_NAME_INPUT_TYPE           "input_type"
67
68 /** Identifiers of the block parameters */
69 enum params{
70         PARAM_PORT_TYPE,
71         PARAM_PIN_NUMBER,
72         PARAM_INPUT_TYPE,
73         PARAMS_COUNT
74 };
75
76 enum port_types{
77         PORT_UNKNOWN,
78         PORT_GIOA,
79         PORT_GIOB,
80         PORT_NHET1
81 };
82
83 enum outputs{
84         OUT_PIN_VALUE,
85         OUTPUTS_COUNT
86 };
87
88 static void mdlInitializeSizes(SimStruct *S)
89 {
90         /*
91         * Configure parameters: 3
92         *  - Port type
93         *  - Pin number
94         *  - Input type
95         */
96         if (!rppSetNumParams(S, PARAMS_COUNT)) {
97                 return;
98         }
99
100         /*
101         * Configure input ports: 0
102         */
103         if (!ssSetNumInputPorts(S, 0)) {
104                 return;
105         }
106
107         /*
108         * Configure output ports: 1
109         */
110         if (!ssSetNumOutputPorts(S, OUTPUTS_COUNT)) {
111                 return;
112         }
113         rppAddOutputPort(S, OUT_PIN_VALUE, SS_BOOLEAN);
114
115         /* Set standard options for this block */
116         rppSetStandardOptions(S);
117 }
118
119
120 #ifdef MATLAB_MEX_FILE
121 #define MDL_CHECK_PARAMETERS
122 static void mdlCheckParameters(SimStruct *S)
123 {
124         if ((int_T)mxGetPr(ssGetSFcnParam(S, PARAM_PORT_TYPE))[0] == PORT_GIOA) {
125                 if (!rppValidParamRange(S, PARAM_PIN_NUMBER, 0, 7)) {
126                         return;
127                 }
128         }
129         else if ((int_T)mxGetPr(ssGetSFcnParam(S, PARAM_PORT_TYPE))[0] == PORT_GIOB) {
130                 if (!rppValidParamRange(S, PARAM_PIN_NUMBER, 0, 7)) {
131                         return;
132                 }
133         }
134         else if ((int_T)mxGetPr(ssGetSFcnParam(S, PARAM_PORT_TYPE))[0] == PORT_NHET1) {
135                 if (!rppValidParamRange(S, PARAM_PIN_NUMBER, 0, 31)) {
136                         return;
137                 }
138         }
139         else {
140                 return;
141         }
142 }
143 #endif
144
145
146 #ifdef MATLAB_MEX_FILE
147 #define MDL_SET_WORK_WIDTHS
148 static void mdlSetWorkWidths(SimStruct *S)
149 {
150         /* Set number of run-time parameters */
151         if (!ssSetNumRunTimeParams(S, PARAMS_COUNT)) {
152                 return;
153         }
154         /* Register the run-time parameter 1 */
155         ssRegDlgParamAsRunTimeParam(S, PARAM_PORT_TYPE,      PARAM_PORT_TYPE,      PARAM_NAME_PORT_TYPE,      SS_INT8);
156         ssRegDlgParamAsRunTimeParam(S, PARAM_PIN_NUMBER,     PARAM_PIN_NUMBER,     PARAM_NAME_PIN_NUMBER,     SS_INT8);
157         ssRegDlgParamAsRunTimeParam(S, PARAM_INPUT_TYPE,     PARAM_INPUT_TYPE,     PARAM_NAME_INPUT_TYPE,     SS_INT8);
158 }
159 #endif
160
161
162 #define COMMON_MDLINITIALIZESAMPLETIMES_INHERIT
163 #define UNUSED_MDLOUTPUTS
164 #define UNUSED_MDLTERMINATE
165 #include "trailer.c"