]> rtime.felk.cvut.cz Git - pes-rpp/rpp-simulink.git/blob - rpp/blocks/sfunction_irc.c
3b305ede1b077032066680ac57f8e93dd9f6e8ee
[pes-rpp/rpp-simulink.git] / rpp / blocks / sfunction_irc.c
1 /* Copyright (C) 2013, 2014 Czech Technical University in Prague
2  *
3  * Authors:
4  *     - Karel Kočí
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_irc.c
12  * Abstract:
13  *     C-MEX S-function block for RPP IRC input.
14  *
15  * References:
16  *     header.c
17  *     trailer.c
18  *
19  * Compile with:
20  *     <matlabroot>/bin/mex sfunction_irc.c
21  */
22
23 /*
24 %YAML 1.2
25 ---
26 Name: IRC Input
27 Category: IO blocks
28 Header: rpp/irc.h
29 Mnemonic: IRC
30
31 Inputs:
32
33 Outputs:
34   - { name: "IRC value", type: "int32" }
35   - { name: "ErrFlag", type: "bool" }
36
37 Parameters:
38   - { name: "IRC number [1-2]", type: "uint8" }
39
40 # Description and Help is in Markdown mark-up
41 Description: &desc |
42
43   This block allows to read a value of an IRC sensors. Two
44   configurations are supported: IRC is connected to pins DIN10 and DIN11
45   and/or pins DIN14 and DIN15. The ErrFlag output raises if an error is
46   detected, which should normally not happen.
47
48 Help: *desc
49
50 Status: Stable
51
52 RPP API functions used:
53     - rpp_irc_enable()
54     - rpp_irc_status()
55     - rpp_irc_get()
56
57 Relevant demos:
58     - irc_input
59 ...
60 */
61
62 #define S_FUNCTION_NAME sfunction_irc
63 #include "header.c"
64
65
66 static void mdlInitializeSizes(SimStruct *S)
67 {
68     /*
69      * Configure parameters: 1
70      *  - IRC number: [1-2]
71      */
72     if (!rppSetNumParams(S, 1)) {
73         return;
74     }
75
76     /*
77      * Configure input ports: 0
78      */
79     if (!ssSetNumInputPorts(S, 0)) {
80         return;
81     }
82
83     /*
84      * Configure output ports: 2
85      *  - IRC input.
86      *  - Error flag.
87      */
88     if (!ssSetNumOutputPorts(S, 2)) {
89         return;
90     }
91     rppAddOutputPort(S, 0, SS_INT32);
92     rppAddOutputPort(S, 1, SS_BOOLEAN);
93
94     /* Set standard options for this block */
95     rppSetStandardOptions(S);
96 }
97
98
99 #ifdef MATLAB_MEX_FILE
100 #define MDL_CHECK_PARAMETERS
101 static void mdlCheckParameters(SimStruct *S)
102 {
103     /* Check the parameter 1 */
104     if (!rppValidParamRange(S, 0, 1, 2)) {
105         return;
106     }
107 }
108 #endif
109
110
111 #ifdef MATLAB_MEX_FILE
112 #define MDL_SET_WORK_WIDTHS
113 static void mdlSetWorkWidths(SimStruct *S)
114 {
115     /* Set number of run-time parameters */
116     if (!ssSetNumRunTimeParams(S, 1)) {
117         return;
118     }
119
120     /* Register the run-time parameter 1 */
121     ssRegDlgParamAsRunTimeParam(S, 0, 0, "p1", SS_UINT8);
122 }
123 #endif
124
125
126 #define COMMON_MDLINITIALIZESAMPLETIMES_INHERIT
127 #define UNUSED_MDLOUTPUTS
128 #define UNUSED_MDLTERMINATE
129 #include "trailer.c"