1 /* Copyright (C) 2013, 2014 Czech Technical University in Prague
4 * - Carlos Jenkins <carlos@jenkins.co.cr>
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
15 * The above copyright notice and this permission notice shall be
16 * included in all copies or substantial portions of the Software.
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.
27 * File : sfunction_sdrw.c
29 * C-MEX S-function block for RPP SD-RAM log write.
36 * <matlabroot>/bin/mex sfunction_sdrw.c
48 - { name: "Data", type: "double" }
51 - { name: "ErrFlag", type: "bool" }
54 - { name: "Block ID", type: "uint8", range: "[0-255]" }
55 - { name: "Printf format for logging", type: "string", range: "(include specifiers)" }
57 # Description and Help is in Markdown mark-up
60 This block allows to log a double value to the SD-RAM. User needs to provide a valid PrintFormat
61 string to format and register the double value on the log. The PrintFormat string should include
63 1. For the block ID. Any valid integer specifier.
64 2. For the value to log. Any valid double specifier.
66 Note that the value of PrintFormat is inserted raw between quotes on code generation and thus there
67 is no validation on it. Error to provide a valid PrintFormat could generate compilation errors or
68 even run-time errors (normally this generates a warning on compile time). Note that the function
69 for logging used is `rpp_sdr_printf()`, which is a blocking call, and can potentially overrun the
70 step. The ErrFlag will set if `rpp_sdr_printf()` returns an error (for example out of memory),
71 but will clear back if the next step the call to this function is successful.
77 RPP API functions used:
85 #define S_FUNCTION_NAME sfunction_sdrw
89 static void mdlInitializeSizes(SimStruct *S)
92 * Configure parameters: 2
94 * - Printf format [setting].
96 if (!rppSetNumParams(S, 2)) {
101 * Configure input ports: 1
104 if (!ssSetNumInputPorts(S, 1)) {
107 rppAddInputPort(S, 0, SS_DOUBLE);
110 * Configure output ports: 1
113 if (!ssSetNumOutputPorts(S, 1)) {
116 rppAddOutputPort(S, 0, SS_BOOLEAN);
118 /* Set standard options for this block */
119 rppSetStandardOptions(S);
123 #ifdef MATLAB_MEX_FILE
124 #define MDL_CHECK_PARAMETERS
125 static void mdlCheckParameters(SimStruct *S)
127 /* Check the parameter 1 */
128 if (!rppValidParamRange(S, 0, 0, 255)) {
135 #ifdef MATLAB_MEX_FILE
136 #define MDL_SET_WORK_WIDTHS
137 static void mdlSetWorkWidths(SimStruct *S)
139 /* Set number of run-time parameters */
140 if (!ssSetNumRunTimeParams(S, 1)) {
144 /* Register the run-time parameter 1 */
145 ssRegDlgParamAsRunTimeParam(S, 0, 0, "p1", SS_UINT8);
150 #ifdef MATLAB_MEX_FILE
152 static void mdlRTW(SimStruct* S)
154 /* Register parameter 2 as a parameter setting */
155 static char_T str[128];
156 mxGetString(ssGetSFcnParam(S, 1), (char*)&str, sizeof(str)); /* Get string */
157 if (!ssWriteRTWParamSettings(S, 1,
158 SSWRITE_VALUE_QSTR, "PrintfFormat", (const char_T*)&str)) {
159 /* An error ocurred */
166 #define COMMON_MDLINITIALIZESAMPLETIMES_INHERIT
167 #define UNUSED_MDLOUTPUTS
168 #define UNUSED_MDLTERMINATE