]> rtime.felk.cvut.cz Git - pes-rpp/rpp-simulink.git/commitdiff
Added S-Functions for AIN and AOUT.
authorCarlos Jenkins <carlos@jenkins.co.cr>
Tue, 4 Jun 2013 22:24:18 +0000 (00:24 +0200)
committerCarlos Jenkins <carlos@jenkins.co.cr>
Tue, 4 Jun 2013 22:24:18 +0000 (00:24 +0200)
rpp/blocks/sfunction_ain.c [new file with mode: 0644]
rpp/blocks/sfunction_aout.c [new file with mode: 0644]
rpp/blocks/sfunction_din.c
rpp/blocks/sfunction_lout.c

diff --git a/rpp/blocks/sfunction_ain.c b/rpp/blocks/sfunction_ain.c
new file mode 100644 (file)
index 0000000..5295fa4
--- /dev/null
@@ -0,0 +1,99 @@
+/* Copyright (C) 2013 Czech Technical University in Prague
+ *
+ * Authors:
+ *     - Carlos Jenkins <carlos@jenkins.co.cr>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * File : sfunction_ain.c
+ * Abstract:
+ *     C-MEX S-function block for RPP analog input.
+ *
+ * References:
+ *     header.c
+ *     trailer.c
+ *
+ * Compile with:
+ *     <matlabroot>/bin/mex sfunction_ain.c
+ */
+
+
+#define S_FUNCTION_NAME sfunction_ain
+#include "header.c"
+
+
+static void mdlInitializeSizes(SimStruct *S)
+{
+    /*
+     * Configure parameters: 1
+     *  - Pin number: [1-12]
+     */
+    if(!rppSetNumParams(S, 1)) {
+        return;
+    }
+
+    /*
+     * Configure input ports: 0
+     */
+    if(!ssSetNumInputPorts(S, 0)) {
+        return;
+    }
+
+    /*
+     * Configure output ports: 2
+     *  - Analog input.
+     *  - Error flag.
+     */
+    if(!ssSetNumOutputPorts(S, 2)) {
+        return;
+    }
+    rppAddOutputPort(S, 0, SS_UINT16);
+    rppAddOutputPort(S, 1, 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(!rppValidParamRange(S, 0, 1, 12)) {
+        return;
+    }
+}
+#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_UINT8);
+}
+#endif
+
+
+#define COMMON_MDLINITIALIZESAMPLETIMES_INHERIT
+#define UNUSED_MDLOUTPUTS
+#define UNUSED_MDLTERMINATE
+#include "trailer.c"
diff --git a/rpp/blocks/sfunction_aout.c b/rpp/blocks/sfunction_aout.c
new file mode 100644 (file)
index 0000000..b132389
--- /dev/null
@@ -0,0 +1,99 @@
+/* Copyright (C) 2013 Czech Technical University in Prague
+ *
+ * Authors:
+ *     - Carlos Jenkins <carlos@jenkins.co.cr>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * File : sfunction_aout.c
+ * Abstract:
+ *     C-MEX S-function block for RPP analog output.
+ *
+ * References:
+ *     header.c
+ *     trailer.c
+ *
+ * Compile with:
+ *     <matlabroot>/bin/mex sfunction_aout.c
+ */
+
+
+#define S_FUNCTION_NAME sfunction_aout
+#include "header.c"
+
+
+static void mdlInitializeSizes(SimStruct *S)
+{
+    /*
+     * Configure parameters: 1
+     *  - Pin number: [1-4]
+     */
+    if(!rppSetNumParams(S, 1)) {
+        return;
+    }
+
+    /*
+     * Configure input ports: 1
+     *  - Analog output.
+     */
+    if(!ssSetNumInputPorts(S, 1)) {
+        return;
+    }
+    rppAddInputPort(S, 0, SS_UINT16);
+
+    /*
+     * 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(!rppValidParamRange(S, 0, 1, 4)) {
+        return;
+    }
+}
+#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_UINT8);
+}
+#endif
+
+
+#define COMMON_MDLINITIALIZESAMPLETIMES_INHERIT
+#define UNUSED_MDLOUTPUTS
+#define UNUSED_MDLTERMINATE
+#include "trailer.c"
index 40951fe23eab08563719b9b8befdb72308d7836f..051e585024d8d4d4a128b9faf67cfdc04e00648d 100644 (file)
@@ -53,7 +53,7 @@ static void mdlInitializeSizes(SimStruct *S)
 
     /*
      * Configure output ports: 2
-     *  - Digital output.
+     *  - Digital input.
      *  - Error flag.
      */
     if(!ssSetNumOutputPorts(S, 2)) {
index 6cb1d89300e70b4d1e0fb965d08e8473717513c2..1f7ad77ee2c50263dd1cea044a5c199d8d09764b 100644 (file)
@@ -45,7 +45,7 @@ static void mdlInitializeSizes(SimStruct *S)
 
     /*
      * Configure input ports: 1
-     *  - Digital out.
+     *  - Digital output.
      */
     if(!ssSetNumInputPorts(S, 1)) {
         return;