]> rtime.felk.cvut.cz Git - pes-rpp/rpp-simulink.git/blob - rpp/blocks/sfunction_sdrw.c
Move documentation from Tex to s-function source files.
[pes-rpp/rpp-simulink.git] / rpp / blocks / sfunction_sdrw.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_sdrw.c
12  * Abstract:
13  *     C-MEX S-function block for RPP SD-RAM log write.
14  *
15  * References:
16  *     header.c
17  *     trailer.c
18  *
19  * Compile with:
20  *     <matlabroot>/bin/mex sfunction_sdrw.c
21  */
22
23 /*
24 %YAML 1.2
25 ---
26 Name: SD-RAM Write
27 Category: Loging
28 Header: rpp/sdc.h
29 Mnemonic: SDRW
30
31 Inputs:
32   - name: Data
33     type: double
34
35 Outputs:
36   - name: ErrFlag
37     type: bool
38
39 Parameters:
40   - name: Block ID
41     type: uint8
42   - name: PrintFormat [SETTING]
43     type: string
44
45 # Description is in Markdown mark-up
46 Description: >
47
48   This block allows to log a double value to the SD-RAM. User needs to provide a valid PrintFormat 
49   string to format and register the double value on the log. The PrintFormat string should include 
50   two specifiers:  
51     1. For the block ID. Any valid integer specifier.  
52     2. For the value to log. Any valid double specifier.  
53
54   Note that the value of PrintFormat is inserted raw between quotes on code generation and thus there 
55   is no validation on it. Error to provide a valid PrintFormat could generate compilation errors or 
56   even run-time errors (normally this generates a warning on compile time). Note that the function 
57   for logging used is `rpp_sdr_printf()`, which is a blocking call, and can potentially overrun the 
58   step. The ErrFlag will set if `rpp_sdr_printf()` returns an error (for example out of memory), 
59   but will clear back if the next step the call to this function is successful.
60
61 Status:
62   Tested:
63     - Logging data.
64     - Compilation and general use.
65   Untested:
66     - Faulty situation for the ErrFlag to set.
67   Not working:
68
69 RPP API functions used:
70     - rpp_sdr_printf()
71
72 Relevant demos:
73     - log_analog_input
74 ...
75 */
76
77 #define S_FUNCTION_NAME sfunction_sdrw
78 #include "header.c"
79
80
81 static void mdlInitializeSizes(SimStruct *S)
82 {
83     /*
84      * Configure parameters: 2
85      *  - Block ID.
86      *  - Printf format [setting].
87      */
88     if (!rppSetNumParams(S, 2)) {
89         return;
90     }
91
92     /*
93      * Configure input ports: 1
94      *  - Data.
95      */
96     if (!ssSetNumInputPorts(S, 1)) {
97         return;
98     }
99     rppAddInputPort(S, 0, SS_DOUBLE);
100
101     /*
102      * Configure output ports: 1
103      *  - Error flag.
104      */
105     if (!ssSetNumOutputPorts(S, 1)) {
106         return;
107     }
108     rppAddOutputPort(S, 0, SS_BOOLEAN);
109
110     /* Set standard options for this block */
111     rppSetStandardOptions(S);
112 }
113
114
115 #ifdef MATLAB_MEX_FILE
116 #define MDL_CHECK_PARAMETERS
117 static void mdlCheckParameters(SimStruct *S)
118 {
119     /* Check the parameter 1 */
120     if (!rppValidParamRange(S, 0, 0, 255)) {
121         return;
122     }
123 }
124 #endif
125
126
127 #ifdef MATLAB_MEX_FILE
128 #define MDL_SET_WORK_WIDTHS
129 static void mdlSetWorkWidths(SimStruct *S)
130 {
131     /* Set number of run-time parameters */
132     if (!ssSetNumRunTimeParams(S, 1)) {
133         return;
134     }
135
136     /* Register the run-time parameter 1 */
137     ssRegDlgParamAsRunTimeParam(S, 0, 0, "p1", SS_UINT8);
138 }
139 #endif
140
141
142 #ifdef MATLAB_MEX_FILE
143 #define MDL_RTW
144 static void mdlRTW(SimStruct* S)
145 {
146     /* Register parameter 2 as a parameter setting */
147     static char_T str[128];
148     mxGetString(ssGetSFcnParam(S, 1), (char*)&str, sizeof(str)); /* Get string */
149     if (!ssWriteRTWParamSettings(S, 1,
150             SSWRITE_VALUE_QSTR, "PrintfFormat", (const char_T*)&str)) {
151         /* An error ocurred */
152         return;
153     }
154 }
155 #endif
156
157
158 #define COMMON_MDLINITIALIZESAMPLETIMES_INHERIT
159 #define UNUSED_MDLOUTPUTS
160 #define UNUSED_MDLTERMINATE
161 #include "trailer.c"