]> rtime.felk.cvut.cz Git - pes-rpp/rpp-simulink.git/blob - rpp/blocks/sfunction_scir.c
Change license to MIT
[pes-rpp/rpp-simulink.git] / rpp / blocks / sfunction_scir.c
1 /* Copyright (C) 2013, 2014 Czech Technical University in Prague
2  *
3  * Authors:
4  *     - Carlos Jenkins <carlos@jenkins.co.cr>
5  *
6  * Permission is hereby granted, free of charge, to any person
7  * obtaining a copy of this software and associated documentation
8  * files (the "Software"), to deal in the Software without
9  * restriction, including without limitation the rights to use,
10  * copy, modify, merge, publish, distribute, sublicense, and/or sell
11  * copies of the Software, and to permit persons to whom the
12  * Software is furnished to do so, subject to the following
13  * conditions:
14  *
15  * The above copyright notice and this permission notice shall be
16  * included in all copies or substantial portions of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
20  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
22  * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25  * OTHER DEALINGS IN THE SOFTWARE.
26  *
27  * File : sfunction_scir.c
28  * Abstract:
29  *     C-MEX S-function block for RPP Serial Communication receive.
30  *
31  * References:
32  *     header.c
33  *     trailer.c
34  *
35  * Compile with:
36  *     <matlabroot>/bin/mex sfunction_scir.c
37  */
38
39 /*
40 %YAML 1.2
41 ---
42 Name: Serial Receive
43 Category: Communication
44 Header: rpp/sci.h
45 Mnemonic: SCIR
46
47 Inputs:
48
49 Outputs:
50   - { name: "Data", type: "uint8" }
51   - { name: "ErrFlag", type: "bool" }
52
53 Parameters:
54
55 # Description and Help is in Markdown mark-up
56 Description: &desc |
57
58   This block receives a byte from the SCI by calling
59   `rpp_sci_read_nb()`. The ErrFlag raises if the call returns an
60   error. The behavior of the ErrFlag is different from others blocks
61   in that this block will set or clear the flag in each step depending
62   on the result. Note that this block uses a non-blocking function to
63   read the SCI and thus it will work even if nothing is received.
64
65 Help: *desc
66
67 Status: Stable
68
69 RPP API functions used:
70     - rpp_sci_read_nb()
71
72 Relevant demos:
73     - echo_char
74 ...
75 */
76
77
78 #define S_FUNCTION_NAME sfunction_scir
79 #include "header.c"
80
81
82 static void mdlInitializeSizes(SimStruct *S)
83 {
84     /*
85      * Configure parameters: 0
86      */
87     if (!rppSetNumParams(S, 0)) {
88         return;
89     }
90
91     /*
92      * Configure input ports: 0
93      */
94     if (!ssSetNumInputPorts(S, 0)) {
95         return;
96     }
97
98     /*
99      * Configure output ports: 2
100      *  - Data receive.
101      *  - Error flag.
102      */
103     if (!ssSetNumOutputPorts(S, 2)) {
104         return;
105     }
106     rppAddOutputPort(S, 0, SS_INT16);
107     rppAddOutputPort(S, 1, SS_BOOLEAN);
108
109     /* Set standard options for this block */
110     rppSetStandardOptions(S);
111 }
112
113
114 #define COMMON_MDLINITIALIZESAMPLETIMES_INHERIT
115 #define UNUSED_MDLCHECKPARAMETERS
116 #define UNUSED_MDLOUTPUTS
117 #define UNUSED_MDLTERMINATE
118 #include "trailer.c"