]> rtime.felk.cvut.cz Git - pes-rpp/rpp-simulink.git/blob - rpp/blocks/sfunction_gio_in.c
00238c68af677728cb22bd07426b049e1c2a250c
[pes-rpp/rpp-simulink.git] / rpp / blocks / sfunction_gio_in.c
1 /* Copyright (C) 2013, 2014, 2015 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_gio_in.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_gio_in.c
21  */
22
23 /*
24 %YAML 1.2
25 ---
26 Name: General Purpose Digital Input
27 Category: IO blocks
28 Header: rpp/gio.h
29 Mnemonic: GIOIN
30
31 Inputs:
32
33 Outputs:
34   - { name: "Digital Input value", type: "bool" }
35 Parameters:
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: "Input Type", type: "Choice", range: "Tri-state, Pull Up, Pull Down" }
39
40 # Description is in Markdown mark-up
41 Description: &desc |
42   Reads value from a GIO pin. Which pins are supported depends on the
43   target board. The selected pin can be configured as tri-state, pull
44   up or pull down.
45
46   When the pin is used in multiple GIOIN or GIOOUT blocks, an error is
47   signaled.
48
49 Help: *desc
50
51 Status: Stable
52
53 RPP API functions used:
54   - rpp_gio_setup
55   - rpp_gio_get
56
57 Relevant demos:
58   - gio_demo
59 ...
60 */
61
62
63 #define S_FUNCTION_NAME sfunction_gio_in
64 #include "header.c"
65
66 /** Identifiers of the block parameters */
67 enum params{
68         PARAM_PIN_NAME,
69         PARAM_INPUT_TYPE,
70         PARAMS_COUNT
71 };
72
73 enum outputs{
74         OUT_PIN_VALUE,
75         OUTPUTS_COUNT
76 };
77
78 static void mdlInitializeSizes(SimStruct *S)
79 {
80         if (!rppSetNumParams(S, PARAMS_COUNT)) {
81                 return;
82         }
83
84         /*
85         * Configure input ports: 0
86         */
87         if (!ssSetNumInputPorts(S, 0)) {
88                 return;
89         }
90
91         /*
92         * Configure output ports: 1
93         */
94         if (!ssSetNumOutputPorts(S, OUTPUTS_COUNT)) {
95                 return;
96         }
97         rppAddOutputPort(S, OUT_PIN_VALUE, SS_BOOLEAN);
98
99         /* Set standard options for this block */
100         rppSetStandardOptions(S);
101 }
102
103
104 #ifdef MATLAB_MEX_FILE
105 #define MDL_CHECK_PARAMETERS
106 static void mdlCheckParameters(SimStruct *S)
107 {
108     if (!mxIsChar(ssGetSFcnParam(S, PARAM_PIN_NAME))) {
109         ssSetErrorStatus(S, "Parameter to S-function must be a string.");
110     }
111 }
112 #endif
113
114
115 #if defined(MATLAB_MEX_FILE)
116 #define MDL_RTW
117 static void mdlRTW(SimStruct *S)
118 {
119     char_T pin_name[80];
120     int8_T pull_type = mxGetPr(ssGetSFcnParam(S, PARAM_INPUT_TYPE))[0];
121
122     if (mxGetString(ssGetSFcnParam(S, PARAM_PIN_NAME), pin_name, sizeof(pin_name)) != 0) {
123         ssSetErrorStatus(S,"mxGetString error in mdlRTW");
124         return;
125     }
126
127     if (!ssWriteRTWParamSettings(S, 2,
128                                  SSWRITE_VALUE_STR, "PinName", pin_name,
129                                  SSWRITE_VALUE_DTYPE_NUM, "PullType", &pull_type, DTINFO(SS_INT8, COMPLEX_NO))) {
130         ssSetErrorStatus(S, "ssWriteRTWParamSettings failed");
131     }
132 }
133 #endif /* MDL_RTW */
134
135
136
137 #define COMMON_MDLINITIALIZESAMPLETIMES_INHERIT
138 #define UNUSED_MDLOUTPUTS
139 #define UNUSED_MDLTERMINATE
140 #include "trailer.c"