]> rtime.felk.cvut.cz Git - pes-rpp/rpp-simulink.git/blob - rpp/blocks/sfunction_scic.c
Change license to MIT
[pes-rpp/rpp-simulink.git] / rpp / blocks / sfunction_scic.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_scic.c
28  * Abstract:
29  *     C-MEX S-function block for configuring RPP Serial Communication.
30  *
31  * References:
32  *     header.c
33  *     trailer.c
34  *
35  * Compile with:
36  *     <matlabroot>/bin/mex sfunction_scic.c
37  */
38
39 /*
40 %YAML 1.2
41 ---
42 Name: Serial Configure
43 Category: Communication
44 Header: rpp/sci.h
45 Mnemonic: SCIC
46
47 Inputs:
48
49 Outputs:
50
51 Parameters:
52   - { name: "Baud rate", type: "uint32" }
53
54 # Description and Help is in Markdown mark-up
55 Description: &desc |
56
57   This block configures the baud rate of the Serial Communication
58   Interface (SCI). Only one block of this type per model is alloved.
59
60 Help: *desc
61
62 Status: Stable
63
64 RPP API functions used:
65     - rpp_sci_setup()
66
67 Relevant demos:
68     - echo_char
69     - hello_world
70     - irc_input
71 ...
72 */
73
74 #define S_FUNCTION_NAME sfunction_scic
75 #include "header.c"
76
77
78 static void mdlInitializeSizes(SimStruct *S)
79 {
80     /*
81      * Configure parameters: 1
82      *  - Baud rate.
83      */
84     if (!rppSetNumParams(S, 1)) {
85         return;
86     }
87
88     /*
89      * Configure input ports: 0
90      */
91     if (!ssSetNumInputPorts(S, 0)) {
92         return;
93     }
94
95     /*
96      * Configure output ports: 0
97      */
98     if (!ssSetNumOutputPorts(S, 0)) {
99         return;
100     }
101
102     /* Set standard options for this block */
103     rppSetStandardOptions(S);
104 }
105
106
107 #ifdef MATLAB_MEX_FILE
108 #define MDL_CHECK_PARAMETERS
109 static void mdlCheckParameters(SimStruct *S)
110 {
111     /* Check the parameter 1 (top baud rate is arbitrary) */
112     if (!rppValidParamRange(S, 0, 0, 1000000)) {
113         return;
114     }
115 }
116 #endif
117
118
119 #ifdef MATLAB_MEX_FILE
120 #define MDL_SET_WORK_WIDTHS
121 static void mdlSetWorkWidths(SimStruct *S)
122 {
123     /* Set number of run-time parameters */
124     if (!ssSetNumRunTimeParams(S, 1)) {
125         return;
126     }
127
128     /* Register the run-time parameter 1 */
129     ssRegDlgParamAsRunTimeParam(S, 0, 0, "p1", SS_UINT32);
130 }
131 #endif
132
133
134 #define COMMON_MDLINITIALIZESAMPLETIMES_INHERIT
135 #define UNUSED_MDLOUTPUTS
136 #define UNUSED_MDLTERMINATE
137 #include "trailer.c"