1 /* Copyright (C) 2013, 2014 Czech Technical University in Prague
4 * - Carlos Jenkins <carlos@jenkins.co.cr>
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.
11 * File : sfunction_sdrw.c
13 * C-MEX S-function block for RPP SD-RAM log write.
20 * <matlabroot>/bin/mex sfunction_sdrw.c
32 - { name: "Data", type: "double" }
35 - { name: "ErrFlag", type: "bool" }
38 - { name: "Block ID", type: "uint8" }
39 - { name: "PrintFormat [SETTING]", type: "string" }
41 # Description is in Markdown mark-up
44 This block allows to log a double value to the SD-RAM. User needs to provide a valid PrintFormat
45 string to format and register the double value on the log. The PrintFormat string should include
47 1. For the block ID. Any valid integer specifier.
48 2. For the value to log. Any valid double specifier.
50 Note that the value of PrintFormat is inserted raw between quotes on code generation and thus there
51 is no validation on it. Error to provide a valid PrintFormat could generate compilation errors or
52 even run-time errors (normally this generates a warning on compile time). Note that the function
53 for logging used is `rpp_sdr_printf()`, which is a blocking call, and can potentially overrun the
54 step. The ErrFlag will set if `rpp_sdr_printf()` returns an error (for example out of memory),
55 but will clear back if the next step the call to this function is successful.
60 - Compilation and general use.
62 - Faulty situation for the ErrFlag to set.
65 RPP API functions used:
73 #define S_FUNCTION_NAME sfunction_sdrw
77 static void mdlInitializeSizes(SimStruct *S)
80 * Configure parameters: 2
82 * - Printf format [setting].
84 if (!rppSetNumParams(S, 2)) {
89 * Configure input ports: 1
92 if (!ssSetNumInputPorts(S, 1)) {
95 rppAddInputPort(S, 0, SS_DOUBLE);
98 * Configure output ports: 1
101 if (!ssSetNumOutputPorts(S, 1)) {
104 rppAddOutputPort(S, 0, SS_BOOLEAN);
106 /* Set standard options for this block */
107 rppSetStandardOptions(S);
111 #ifdef MATLAB_MEX_FILE
112 #define MDL_CHECK_PARAMETERS
113 static void mdlCheckParameters(SimStruct *S)
115 /* Check the parameter 1 */
116 if (!rppValidParamRange(S, 0, 0, 255)) {
123 #ifdef MATLAB_MEX_FILE
124 #define MDL_SET_WORK_WIDTHS
125 static void mdlSetWorkWidths(SimStruct *S)
127 /* Set number of run-time parameters */
128 if (!ssSetNumRunTimeParams(S, 1)) {
132 /* Register the run-time parameter 1 */
133 ssRegDlgParamAsRunTimeParam(S, 0, 0, "p1", SS_UINT8);
138 #ifdef MATLAB_MEX_FILE
140 static void mdlRTW(SimStruct* S)
142 /* Register parameter 2 as a parameter setting */
143 static char_T str[128];
144 mxGetString(ssGetSFcnParam(S, 1), (char*)&str, sizeof(str)); /* Get string */
145 if (!ssWriteRTWParamSettings(S, 1,
146 SSWRITE_VALUE_QSTR, "PrintfFormat", (const char_T*)&str)) {
147 /* An error ocurred */
154 #define COMMON_MDLINITIALIZESAMPLETIMES_INHERIT
155 #define UNUSED_MDLOUTPUTS
156 #define UNUSED_MDLTERMINATE