]> rtime.felk.cvut.cz Git - pes-rpp/rpp-simulink.git/blob - rpp/blocks/sfunction_gio_out.c
Add comments to GIO blocks
[pes-rpp/rpp-simulink.git] / rpp / blocks / sfunction_gio_out.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_out.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_gio_out.c
21  */
22
23 /*
24 %YAML 1.2
25 ---
26 Name: General Purpose Digital Output
27 Category: IO blocks
28 Header: rpp/gio.h
29 Mnemonic: GIOOUT
30
31 Inputs:
32   - { name: "Digital Output value", type: "bool" }
33 Outputs:
34
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: "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   Sets a GIO pin to a given value. Which pins are supported depends on
45   the target board. Any pin can be configured as open drain or
46   push/pull and initial output value can be specified. The initial
47   value is a value, which will appear on the pin when the GPIO module
48   is initialized and stays there until the first block execution.
49
50   When the pin is used in multiple GIOIN or GIOOUT blocks, an error is
51   signaled.
52
53 Help: *desc
54
55 Status: Stable
56
57 RPP API functions used:
58   - rpp_gio_setup
59   - rpp_gio_set
60
61 Relevant demos:
62   - gio_demo
63   - board_init_hydctr
64 ...
65 */
66
67 /*
68  * Block mask documentation - see sfunction_gio_in.c
69  */
70
71 #define S_FUNCTION_NAME sfunction_gio_out
72 #include "header.c"
73
74 #define PARAM_NAME_PORT_TYPE            "port_type"
75 #define PARAM_NAME_PIN_NUMBER           "pin_number"
76 #define PARAM_NAME_DEFAULT_OUTPUT       "default_output"
77 #define PARAM_NAME_OUTPUT_TYPE          "output_type"
78
79 /** Identifiers of the block parameters */
80 enum params{
81         PARAM_PIN_NAME,
82         PARAM_DEFAULT_OUTPUT,
83         PARAM_OUTPUT_TYPE,
84         PARAMS_COUNT
85 };
86
87 enum inputs{
88         IN_PIN_VALUE,
89         INPUTS_COUNT
90 };
91
92 static void mdlInitializeSizes(SimStruct *S)
93 {
94         if (!rppSetNumParams(S, PARAMS_COUNT)) {
95                 return;
96         }
97
98         /*
99         * Configure output ports: 0
100         */
101         if (!ssSetNumOutputPorts(S, 0)) {
102                 return;
103         }
104
105         /*
106         * Configure input ports: 1
107         */
108         if (!ssSetNumInputPorts(S, INPUTS_COUNT)) {
109                 return;
110         }
111
112         rppAddInputPort(S, IN_PIN_VALUE, SS_BOOLEAN);
113
114         /* Set standard options for this block */
115         rppSetStandardOptions(S);
116 }
117
118
119 #ifdef MATLAB_MEX_FILE
120 #define MDL_CHECK_PARAMETERS
121 static void mdlCheckParameters(SimStruct *S)
122 {
123     if (!mxIsChar(ssGetSFcnParam(S, PARAM_PIN_NAME))) {
124         ssSetErrorStatus(S, "Parameter to S-function must be a string.");
125     }
126         if (!rppValidParamRange(S, PARAM_DEFAULT_OUTPUT, 0, 1)) {
127                 return;
128         }
129 }
130 #endif
131
132 #if defined(MATLAB_MEX_FILE)
133 #define MDL_RTW
134 static void mdlRTW(SimStruct *S)
135 {
136     char_T pin_name[80];
137     int8_T def_out = mxGetPr(ssGetSFcnParam(S, PARAM_DEFAULT_OUTPUT))[0];
138     int8_T out_type = mxGetPr(ssGetSFcnParam(S, PARAM_OUTPUT_TYPE))[0];
139
140     if (mxGetString(ssGetSFcnParam(S, PARAM_PIN_NAME), pin_name, sizeof(pin_name)) != 0) {
141         ssSetErrorStatus(S,"mxGetString error in mdlRTW");
142         return;
143     }
144
145     if (!ssWriteRTWParamSettings(S, 3,
146                                  SSWRITE_VALUE_STR, "PinName", pin_name,
147                                  SSWRITE_VALUE_DTYPE_NUM, "DefOut", &def_out, DTINFO(SS_INT8, COMPLEX_NO),
148                                  SSWRITE_VALUE_DTYPE_NUM, "OutType", &out_type, DTINFO(SS_INT8, COMPLEX_NO))) {
149         ssSetErrorStatus(S, "ssWriteRTWParamSettings failed");
150     }
151 }
152 #endif /* MDL_RTW */
153
154
155
156 #define COMMON_MDLINITIALIZESAMPLETIMES_INHERIT
157 #define UNUSED_MDLOUTPUTS
158 #define UNUSED_MDLTERMINATE
159 #include "trailer.c"