]> rtime.felk.cvut.cz Git - mf624-simulink.git/blobdiff - sfDigitalInput.c
Use correct header file for alloca for Linux build.
[mf624-simulink.git] / sfDigitalInput.c
index 3919e98f82cb5da09491560661ed6c3b12617f1c..a6294c6d719bb2eb83467b15ca4e47c3d38c030a 100644 (file)
@@ -1,12 +1,33 @@
 /*
- * sfuntmpl_basic.c: Basic 'C' template for a level 2 S-function.
+ * S-function to support digital input Humusoft MF624 card
  *
- *  -------------------------------------------------------------------------
- *  | See matlabroot/simulink/src/sfuntmpl_doc.c for a more detailed template |
- *  -------------------------------------------------------------------------
+ * Copyright (C) 2014 Pavel Pisa <pisa@cmp.felk.cvut.cz>
  *
- * Copyright 1990-2002 The MathWorks, Inc.
- * $Revision: 1.27.4.2 $
+ * Department of Control Engineering
+ * Faculty of Electrical Engineering
+ * Czech Technical University in Prague (CTU)
+ *
+ * The S-Function for ERT Linux can be distributed in compliance
+ * with GNU General Public License (GPL) version 2 or later.
+ * Other licence can negotiated with CTU.
+ *
+ * Next exception is granted in addition to GPL.
+ * Instantiating or linking compiled version of this code
+ * to produce an application image/executable, does not
+ * by itself cause the resulting application image/executable
+ * to be covered by the GNU General Public License.
+ * This exception does not however invalidate any other reasons
+ * why the executable file might be covered by the GNU Public License.
+ * Publication of enhanced or derived S-function files is required
+ * although.
+ *
+ * Linux ERT code is available from
+ *    http://rtime.felk.cvut.cz/gitweb/ert_linux.git
+ * More CTU Linux target for Simulink components are available at
+ *    http://lintarget.sourceforge.net/
+ *
+ * sfuntmpl_basic.c by The MathWorks, Inc. has been used to accomplish
+ * required S-function structure.
  */
 
 
  * its associated macro definitions.
  */
 #include "simstruc.h"
+
+#ifndef WITHOUT_HW
 #include "mf624_SIMULINK.h"
+#endif /*WITHOUT_HW*/
 
 /* Error handling
  * --------------
@@ -103,7 +127,7 @@ static void mdlInitializeSizes(SimStruct *S)
 static void mdlInitializeSampleTimes(SimStruct *S)
 {
     ssSetSampleTime(S, 0, CONTINUOUS_SAMPLE_TIME);
-    ssSetOffsetTime(S, 0, 0.0);
+    ssSetOffsetTime(S, 0, FIXED_IN_MINOR_STEP_OFFSET);
 }
 
 
@@ -138,8 +162,10 @@ static void mdlInitializeSampleTimes(SimStruct *S)
    */
   static void mdlStart(SimStruct *S)
   {
+  #ifndef WITHOUT_HW
     if (mf624_init(NULL) != 0)
-         return;
+        return;
+  #endif /*WITHOUT_HW*/
   }
 #endif /*  MDL_START */
 
@@ -153,16 +179,20 @@ static void mdlInitializeSampleTimes(SimStruct *S)
 static void mdlOutputs(SimStruct *S, int_T tid)
 {
     real_T *y;
-    uint16_t din;
+    uint_T din;
+
+    y = (real_T *)ssGetOutputPortSignal(S, 0);
 
+  #ifndef WITHOUT_HW
     if (mf624_check(S) != 0)
            return;
 
-    y = (real_T *)ssGetOutputPortSignal(S, 0);
-
     din = mf624_read16(MFST2REG(mfst, 2, DIN_reg));
 
     *y = din & (1 << (int)(CHNL_PRM(S)-1)) ? 0.0 : 1.0;
+  #else /*WITHOUT_HW*/
+    *y = 0;
+  #endif /*WITHOUT_HW*/
 }
 
 
@@ -205,7 +235,9 @@ static void mdlOutputs(SimStruct *S, int_T tid)
  */
 static void mdlTerminate(SimStruct *S)
 {
-       mf624_done();
+  #ifndef WITHOUT_HW
+    mf624_done();
+  #endif /*WITHOUT_HW*/
 }