]> rtime.felk.cvut.cz Git - mf624-simulink.git/blobdiff - sfReadPWM.c
Add build mode WITHOUT_HW to edit model without MF624 hardware access.
[mf624-simulink.git] / sfReadPWM.c
index 33399aef6aab0a38b2206ed33fd7e43228a36069..979f046b22e678c2150444b60a8cf817bd9d1d62 100644 (file)
@@ -46,7 +46,9 @@
  */
 #include "simstruc.h"
 
+#ifndef WITHOUT_HW
 #include "mf624_SIMULINK.h"
+#endif /*WITHOUT_HW*/
 
 /* Error handling
  * --------------
@@ -162,6 +164,7 @@ static void mdlInitializeSampleTimes(SimStruct *S)
    */
   static void mdlStart(SimStruct *S)
   {
+  #ifndef WITHOUT_HW
     if (mf624_init(NULL) != 0)
        return;
             
@@ -185,8 +188,7 @@ static void mdlInitializeSampleTimes(SimStruct *S)
     
     /*Start counters 0,1,2, tehy are gated with their inputs so no worries about premature start*/
     mf624_write32(CTR_START,MFST2REG(mfst,4,CTRXCTRL_reg));
-            
-    
+  #endif /*WITHOUT_HW*/
   }
 #endif /*  MDL_START */
 
@@ -204,25 +206,28 @@ static void mdlOutputs(SimStruct *S, int_T tid)
     real_T       *y2 = ssGetOutputPortSignal(S,2);
     unsigned int period;
     unsigned int c0,c1,c2,c4;
-    
+  #ifndef WITHOUT_HW
     if (mf624_check(S) != 0)
-           return;
-       
+        return;
+
     c0 = mf624_read32(MFST2REG(mfst,4,CTR0_reg));
     c1 = mf624_read32(MFST2REG(mfst,4,CTR1_reg));
     c2 = mf624_read32(MFST2REG(mfst,4,CTR2_reg));
     c4 = mf624_read32(MFST2REG(mfst,4,CTR4_reg));
-    
+
     period = (unsigned int)(c4-(unsigned int)ssGetIWorkValue(S,3));
-    
+
     y0[0] = (real_T)(c0-(unsigned int)ssGetIWorkValue(S,0))/(real_T)period;
     y1[0] = (real_T)(c1-(unsigned int)ssGetIWorkValue(S,1))/(real_T)period;
     y2[0] = (real_T)(c2-(unsigned int)ssGetIWorkValue(S,2))/(real_T)period;
-    
+
     ssSetIWorkValue(S,0,c0);
     ssSetIWorkValue(S,1,c1);
     ssSetIWorkValue(S,2,c2);
     ssSetIWorkValue(S,3,c4);
+  #else /*WITHOUT_HW*/
+    y0[0] = y1[0] = y2[0] = 0;
+  #endif /*WITHOUT_HW*/
 }
 
 
@@ -265,11 +270,13 @@ static void mdlOutputs(SimStruct *S, int_T tid)
  */
 static void mdlTerminate(SimStruct *S)
 {
+  #ifndef WITHOUT_HW
     if (mf624_check(NULL) != 0)
-           return;
+        return;
 
     mf624_write32(CTR_STOP,MFST2REG(mfst,4,CTRXCTRL_reg));
     mf624_done();
+  #endif /*WITHOUT_HW*/
 }