]> rtime.felk.cvut.cz Git - pes-rpp/rpp-simulink.git/blob - rpp/blocks/sfunction_scir.c
2f8e0cbe119f43be2ae82d58310cccf9cc8f21ba
[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  * 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_scir.c
12  * Abstract:
13  *     C-MEX S-function block for RPP Serial Communication receive.
14  *
15  * References:
16  *     header.c
17  *     trailer.c
18  *
19  * Compile with:
20  *     <matlabroot>/bin/mex sfunction_scir.c
21  */
22
23 /*
24 %YAML 1.2
25 ---
26 Name: Serial Receive
27 Category: Communication
28 Header: rpp/sci.h
29 Mnemonic: SCIR
30
31 Inputs:
32
33 Outputs:
34   - { name: "Data", type: "uint8" }
35   - { name: "ErrFlag", type: "bool" }
36
37 Parameters:
38
39 # Description and Help is in Markdown mark-up
40 Description: &desc |
41
42   This block receives a byte from the SCI by calling
43   `rpp_sci_read_nb()`. The ErrFlag raises if the call returns an
44   error. The behavior of the ErrFlag is different from others blocks
45   in that this block will set or clear the flag in each step depending
46   on the result. Note that this block uses a non-blocking function to
47   read the SCI and thus it will work even if nothing is received.
48
49 Help: *desc
50
51 Status: Stable
52
53 RPP API functions used:
54     - rpp_sci_read_nb()
55
56 Relevant demos:
57     - echo_char
58 ...
59 */
60
61
62 #define S_FUNCTION_NAME sfunction_scir
63 #include "header.c"
64
65
66 static void mdlInitializeSizes(SimStruct *S)
67 {
68     /*
69      * Configure parameters: 0
70      */
71     if (!rppSetNumParams(S, 0)) {
72         return;
73     }
74
75     /*
76      * Configure input ports: 0
77      */
78     if (!ssSetNumInputPorts(S, 0)) {
79         return;
80     }
81
82     /*
83      * Configure output ports: 2
84      *  - Data receive.
85      *  - Error flag.
86      */
87     if (!ssSetNumOutputPorts(S, 2)) {
88         return;
89     }
90     rppAddOutputPort(S, 0, SS_INT16);
91     rppAddOutputPort(S, 1, SS_BOOLEAN);
92
93     /* Set standard options for this block */
94     rppSetStandardOptions(S);
95 }
96
97
98 #define COMMON_MDLINITIALIZESAMPLETIMES_INHERIT
99 #define UNUSED_MDLCHECKPARAMETERS
100 #define UNUSED_MDLOUTPUTS
101 #define UNUSED_MDLTERMINATE
102 #include "trailer.c"