]> rtime.felk.cvut.cz Git - jenkicar/rpp-simulink.git/blob - rpp/blocks/sfunction_ain.c
Generate block status table automatically
[jenkicar/rpp-simulink.git] / rpp / blocks / sfunction_ain.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 RPP analog input.
14  *
15  * References:
16  *     header.c
17  *     trailer.c
18  *
19  * Compile with:
20  *     <matlabroot>/bin/mex sfunction_ain.c
21  */
22
23 /*
24 %YAML 1.2
25 ---
26 Name: Analog Input block
27 Category: IO blocks
28 Header: rpp_adc.h
29 Mnemonic: ADC
30
31 Inputs:
32
33 Outputs:
34   - name: Analog Input Pin Number
35     type: uint16
36   - name: ErrFlag
37     type: bool
38
39 Parameters:
40   - name: Pin number
41     type: uint8
42     range: "[1–12]"
43
44 # Description is in Markdown mark-up
45 Description: >
46
47   This block allows to read the analog inputs on the RPP board. The
48   ErrFlag should if raise `rpp_adc_update()` or `rpp_adc_get()`
49   returns error. `rpp_adc_update()` is called just by the first DIN
50   block in the model and thus only the first block could raise the
51   flag because of this. In case an error occurs the return value will
52   always be 0. Because the ErrFlag should never set, once set the
53   following steps will never clear it back.
54
55 Status:
56   Tested:
57     - Changing the pin.
58     - Compilation and general use.
59   Untested:
60     - Faulty situation for the ErrFlag to set.
61   Not working:
62
63 RPP API functions used:
64   - rpp_adc_update()
65   - rpp_adc_get()
66
67 Relevant demos:
68   - analog_passthrough
69   - hbridge_analog_control
70   - log_analog_input
71 ...
72 */
73
74
75 #define S_FUNCTION_NAME sfunction_ain
76 #include "header.c"
77
78
79 static void mdlInitializeSizes(SimStruct *S)
80 {
81     /*
82      * Configure parameters: 1
83      *  - Pin number: [1-12]
84      */
85     if (!rppSetNumParams(S, 1)) {
86         return;
87     }
88
89     /*
90      * Configure input ports: 0
91      */
92     if (!ssSetNumInputPorts(S, 0)) {
93         return;
94     }
95
96     /*
97      * Configure output ports: 2
98      *  - Analog input.
99      *  - Error flag.
100      */
101     if (!ssSetNumOutputPorts(S, 2)) {
102         return;
103     }
104     rppAddOutputPort(S, 0, SS_UINT16);
105     rppAddOutputPort(S, 1, SS_BOOLEAN);
106
107     /* Set standard options for this block */
108     rppSetStandardOptions(S);
109 }
110
111
112 #ifdef MATLAB_MEX_FILE
113 #define MDL_CHECK_PARAMETERS
114 static void mdlCheckParameters(SimStruct *S)
115 {
116     /* Check the parameter 1 */
117     if (!rppValidParamRange(S, 0, 1, 12)) {
118         return;
119     }
120 }
121 #endif
122
123
124 #ifdef MATLAB_MEX_FILE
125 #define MDL_SET_WORK_WIDTHS
126 static void mdlSetWorkWidths(SimStruct *S)
127 {
128     /* Set number of run-time parameters */
129     if (!ssSetNumRunTimeParams(S, 1)) {
130         return;
131     }
132
133     /* Register the run-time parameter 1 */
134     ssRegDlgParamAsRunTimeParam(S, 0, 0, "p1", SS_UINT8);
135 }
136 #endif
137
138
139 #define COMMON_MDLINITIALIZESAMPLETIMES_INHERIT
140 #define UNUSED_MDLOUTPUTS
141 #define UNUSED_MDLTERMINATE
142 #include "trailer.c"