]> rtime.felk.cvut.cz Git - socketcan-simulink.git/blobdiff - blocks/sfunction_printf.c
Include printf block with same interface as RPP SCI block is.
[socketcan-simulink.git] / blocks / sfunction_printf.c
diff --git a/blocks/sfunction_printf.c b/blocks/sfunction_printf.c
new file mode 100644 (file)
index 0000000..0dcbe90
--- /dev/null
@@ -0,0 +1,133 @@
+/* Copyright (C) 2013 Czech Technical University in Prague
+ *
+ * Authors:
+ *     - Carlos Jenkins <carlos@jenkins.co.cr>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * File : sfunction_printf.c
+ * Abstract:
+ *     C-MEX S-function block for RPP Serial Communication Printf.
+ *
+ * References:
+ *     header.c
+ *     trailer.c
+ *
+ * Compile with:
+ *     <matlabroot>/bin/mex sfunction_printf.c
+ */
+
+
+#define S_FUNCTION_NAME sfunction_printf
+#include "header.c"
+
+
+static void mdlInitializeSizes(SimStruct *S)
+{
+    /*
+     * Configure parameters: 2
+     *  - Printf format [setting].
+     */
+    if (!rppSetNumParams(S, 1)) {
+        return;
+    }
+
+    /*
+     * Configure input ports: 1
+     *  - Data send.
+     */
+    if (!ssSetNumInputPorts(S, 1)) {
+        return;
+    }
+    rppAddInputVectorPort(S, 0, DYNAMICALLY_TYPED, DYNAMICALLY_SIZED);
+
+    /*
+     * Configure output ports: 1
+     *  - Error flag.
+     */
+    if (!ssSetNumOutputPorts(S, 1)) {
+        return;
+    }
+    rppAddOutputPort(S, 0, SS_BOOLEAN);
+
+    /* Set standard options for this block */
+    rppSetStandardOptions(S);
+}
+
+
+#ifdef MATLAB_MEX_FILE
+#define MDL_CHECK_PARAMETERS
+static void mdlCheckParameters(SimStruct *S)
+{
+    /* Check the parameter 1 */
+    /*if (!rppValidParamBoolean(S, 0)) {
+        return;
+    }
+
+    /* Note that parameter 2 is not checked */
+}
+#endif
+
+
+#ifdef MATLAB_MEX_FILE
+#define MDL_SET_WORK_WIDTHS
+static void mdlSetWorkWidths(SimStruct *S)
+{
+    /* Set number of run-time parameters */
+    /*if (!ssSetNumRunTimeParams(S, 1)) {
+        return;
+    }
+
+    /* Register the run-time parameter 1 */
+    /*ssRegDlgParamAsRunTimeParam(S, 0, 0, "p1", SS_BOOLEAN);*/
+}
+#endif
+
+
+#ifdef MATLAB_MEX_FILE
+#define MDL_RTW
+static void mdlRTW(SimStruct* S)
+{
+    /* Register parameter as a parameter setting */
+    static char_T str[128];
+    mxGetString(ssGetSFcnParam(S, 0), (char*)&str, sizeof(str)); /* Get string */
+    if (!ssWriteRTWParamSettings(S, 1,
+            SSWRITE_VALUE_QSTR, "PrintfFormat", (const char_T*)&str)) {
+        /* An error ocurred */
+        return;
+    }
+}
+#endif
+
+
+
+#define COMMON_MDLINITIALIZESAMPLETIMES_INHERIT
+#define UNUSED_MDLOUTPUTS
+#define UNUSED_MDLTERMINATE
+#include "trailer.c"