]> rtime.felk.cvut.cz Git - mf624-simulink.git/commitdiff
Add build mode WITHOUT_HW to edit model without MF624 hardware access.
authorPavel Pisa <pi@baree.pikron.com>
Sat, 22 Feb 2014 13:03:39 +0000 (14:03 +0100)
committerPavel Pisa <pi@baree.pikron.com>
Sat, 22 Feb 2014 13:03:39 +0000 (14:03 +0100)
Signed-off-by: Pavel Pisa <pi@baree.pikron.com>
Makefile
sfAnalogInput.c
sfAnalogOutput.c
sfDigitalInput.c
sfDigitalOutput.c
sfIRCInput.c
sfPWMOutput.c
sfPWMwDirOutput.c
sfReadPWM.c

index 620da701ed644602bb7d697cfacf40d17c8da438..7b294b30cabefaa3697a2cbe304743a7958e5010 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,11 +1,20 @@
 MEXFLAGS ?= -f ./mexopts.sh -g
 
+# Build MF624 MEX functions without dependency on hardware access
+#WITHOUT_HW=y
+
+ifeq ($(WITHOUT_HW),y)
+MEXFLAGS += -DWITHOUT_HW=1
+else
+MF624_COMMON_C_FILES=mf624_SIMULINK.c
+endif
+
 all:
-       mex $(MEXFLAGS) sfAnalogInput.c   mf624_SIMULINK.c
-       mex $(MEXFLAGS) sfAnalogOutput.c  mf624_SIMULINK.c
-       mex $(MEXFLAGS) sfDigitalOutput.c mf624_SIMULINK.c
-       mex $(MEXFLAGS) sfDigitalInput.c  mf624_SIMULINK.c
-       mex $(MEXFLAGS) sfReadPWM.c       mf624_SIMULINK.c
-       mex $(MEXFLAGS) sfIRCInput.c      mf624_SIMULINK.c
-       mex $(MEXFLAGS) sfPWMOutput.c     mf624_SIMULINK.c
-       mex $(MEXFLAGS) sfPWMwDirOutput.c mf624_SIMULINK.c
+       mex $(MEXFLAGS) sfAnalogInput.c   $(MF624_COMMON_C_FILES)
+       mex $(MEXFLAGS) sfAnalogOutput.c  $(MF624_COMMON_C_FILES)
+       mex $(MEXFLAGS) sfDigitalOutput.c $(MF624_COMMON_C_FILES)
+       mex $(MEXFLAGS) sfDigitalInput.c  $(MF624_COMMON_C_FILES)
+       mex $(MEXFLAGS) sfReadPWM.c       $(MF624_COMMON_C_FILES)
+       mex $(MEXFLAGS) sfIRCInput.c      $(MF624_COMMON_C_FILES)
+       mex $(MEXFLAGS) sfPWMOutput.c     $(MF624_COMMON_C_FILES)
+       mex $(MEXFLAGS) sfPWMwDirOutput.c $(MF624_COMMON_C_FILES)
index fe72ebf27d44d364190e70f9f1d56de63fbe7115..70e4ca956d0307bfe47b5c5d30759567d9addfa6 100644 (file)
  */
 #include "simstruc.h"
 
+#include <stdint.h>
+
+#ifndef WITHOUT_HW
 #include "mf624_SIMULINK.h"
+#endif /*WITHOUT_HW*/
 
 
 /* Error handling
@@ -175,26 +179,27 @@ static void mdlInitializeSampleTimes(SimStruct *S)
    */
   static void mdlStart(SimStruct *S)
   {
+
+  #ifndef WITHOUT_HW
     if (mf624_init(NULL) != 0)
        return;
-            
+  #endif /*WITHOUT_HW*/
+
     int ADCCMask = (int)MASK_PRM(S);
 
     if(ADCCMask > 255 || ADCCMask < 0) {
         ssSetErrorStatus(S,"Invalid parameter mask, set to 0-255");
     }
-    
+
     int ADCChannels = __builtin_popcount((uint32_t)ADCCMask);           //Counts number of set bits in ADCCMask
-    
+
     ssSetIWorkValue(S, 0, ADCChannels);
-    
+  #ifndef WITHOUT_HW
     mfst->ADC_enabled = ADCCMask;
     mfst->ADC_enabled &= 0xFF;
-    
+
     mf624_write16(mfst->ADC_enabled, MFST2REG(mfst, 2, ADCTRL_reg));
-    
-    
-    
+  #endif /*WITHOUT_HW*/
   }
 #endif /*  MDL_START */
 
@@ -212,35 +217,41 @@ static void mdlOutputs(SimStruct *S, int_T tid)
     real_T*       y[ADCChannels];
     int i;
     int res,res1;
-    
+  #ifndef WITHOUT_HW
     if (mf624_check(S) != 0)
-           return;
+        return;
 
     // Activate trigger to start conversion
-       mf624_read16(MFST2REG(mfst, 2, ADSTART_reg));
-    
+    mf624_read16(MFST2REG(mfst, 2, ADSTART_reg));
+  #endif /*WITHOUT_HW*/
+
     for(i=0; i < ADCChannels;i++){
         y[i]=ssGetOutputPortSignal(S,i);
     }
-    
+
+  #ifndef WITHOUT_HW
     // Check if conversion has finished
-       while((mf624_read32(MFST2REG(mfst, 0, GPIOC_reg)) & GPIOC_EOLC_mask)) { 
-               for (i = 0; i < 1000; i++) {} // small wait
-       }
-    
-    
-     for(i=1; i < ADCChannels;i+=2){
+    while((mf624_read32(MFST2REG(mfst, 0, GPIOC_reg)) & GPIOC_EOLC_mask)) { 
+        for (i = 0; i < 1000; i++) {} // small wait
+    }
+
+    for(i=1; i < ADCChannels;i+=2){
         res = mf624_read32(MFST2REG(mfst, 2, ADDATA0_reg));
         res1= res >> 16;
         res = res & 0xFFFF;
         *y[i-1] = (real_T) (10.0 * ((int16_t) (res << 2)) / (double) 0x8000);
         *y[i] = (real_T) (10.0 * ((int16_t) (res1 << 2)) / (double) 0x8000);
     }
-    
+
     if(i == ADCChannels){
         res = mf624_read16(MFST2REG(mfst, 2, ADDATA0_reg));
         *y[ADCChannels-1]=(real_T)(10.0 * ((int16_t) (res << 2)) / (double) 0x8000);
     }
+  #else /*WITHOUT_HW*/
+    for(i=0; i < ADCChannels; i++){
+        *y[i] = 0;
+    }
+  #endif /*WITHOUT_HW*/
 }
 
 
@@ -283,7 +294,9 @@ static void mdlOutputs(SimStruct *S, int_T tid)
  */
 static void mdlTerminate(SimStruct *S)
 {
+  #ifndef WITHOUT_HW
     mf624_done(S);
+  #endif /*WITHOUT_HW*/
 }
 
 
index 3056060fac1d170a90b51b8d42cbc9b601659df6..d2d0ad0634f19adfa6e7c06d05af7bb7164b3929 100644 (file)
  * its associated macro definitions.
  */
 #include "simstruc.h"
+
+#ifndef WITHOUT_HW
 #include "mf624_SIMULINK.h"
+#endif /*WITHOUT_HW*/
 
 /* Error handling
  * --------------
@@ -168,9 +171,11 @@ static void mdlInitializeSampleTimes(SimStruct *S)
    */
   static void mdlStart(SimStruct *S)
   {
+  #ifndef WITHOUT_HW
         if (mf624_init(NULL) != 0)
            return;
        DAC_enable(mfst);
+  #endif /*WITHOUT_HW*/
     //ssSetPWorkValue(S, 0, mfst);
   }
 #endif /*  MDL_START */
@@ -188,6 +193,7 @@ static void mdlOutputs(SimStruct *S, int_T tid)
     //mf624_state_t* mfst = ssGetPWorkValue(S,0);
     int out;
 
+  #ifndef WITHOUT_HW
     if (mf624_check(S) != 0)
            return;
 
@@ -201,6 +207,7 @@ static void mdlOutputs(SimStruct *S, int_T tid)
         out = (int) ((u[0] + 10) * 8192 / 10 + 0.5);
     }
     mf624_write16(out, MFST2REG(mfst, 2, dac_channel2reg[(int)CHNL_PRM(S)-1]));
+  #endif /*WITHOUT_HW*/
 }
 
 
@@ -243,6 +250,7 @@ static void mdlOutputs(SimStruct *S, int_T tid)
  */
 static void mdlTerminate(SimStruct *S)
 {
+  #ifndef WITHOUT_HW
     //mf624_state_t* mfst = ssGetPWorkValue(S,0);
     if (mf624_check(NULL) != 0)
            return;
@@ -253,6 +261,7 @@ static void mdlTerminate(SimStruct *S)
                  MFST2REG(mfst, 0, GPIOC_reg));
 
     mf624_done();
+  #endif /*WITHOUT_HW*/
 }
 
 
index d5fca66c47eadafbd9093b88afa5e583fef4ec76..a6294c6d719bb2eb83467b15ca4e47c3d38c030a 100644 (file)
  * its associated macro definitions.
  */
 #include "simstruc.h"
+
+#ifndef WITHOUT_HW
 #include "mf624_SIMULINK.h"
+#endif /*WITHOUT_HW*/
 
 /* Error handling
  * --------------
@@ -159,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 */
 
@@ -174,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*/
 }
 
 
@@ -226,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*/
 }
 
 
index b768d9cac5ead578d495c68cf4c8dae22e573d62..f3fd8899bde6a8ab24ecdbe0e7c8b4438f0eba53 100644 (file)
  * its associated macro definitions.
  */
 #include "simstruc.h"
+
+#ifndef WITHOUT_HW
 #include "mf624_SIMULINK.h"
+#endif /*WITHOUT_HW*/
 
 /* Error handling
  * --------------
@@ -168,10 +171,11 @@ static void mdlInitializeSampleTimes(SimStruct *S)
    */
   static void mdlStart(SimStruct *S)
   {
+  #ifndef WITHOUT_HW
     if (mf624_init(NULL) != 0)
        return;
     mfst->DOut=0;
-    
+  #endif /*WITHOUT_HW*/
   }
 #endif /*  MDL_START */
 
@@ -186,6 +190,7 @@ static void mdlOutputs(SimStruct *S, int_T tid)
 {
     const real_T *u = (const real_T*) ssGetInputPortSignal(S,0);
 
+  #ifndef WITHOUT_HW
     if (mf624_check(S) != 0)
            return;
 
@@ -199,6 +204,7 @@ static void mdlOutputs(SimStruct *S, int_T tid)
     }
     
     mf624_write16(mfst->DOut, MFST2REG(mfst, 2, DOUT_reg));
+  #endif /*WITHOUT_HW*/
 }
 
 
@@ -241,7 +247,9 @@ static void mdlOutputs(SimStruct *S, int_T tid)
  */
 static void mdlTerminate(SimStruct *S)
 {
-       mf624_done();
+  #ifndef WITHOUT_HW
+    mf624_done();
+  #endif /*WITHOUT_HW*/
 }
 
 
index b9d4655dcaca0f57fd50b6f13c9d52df552155dd..86ae04d4fe8fbcb8e5d46a801703c4257bac123f 100644 (file)
@@ -75,6 +75,8 @@
  * its associated macro definitions.
  */
 #include "simstruc.h"
+
+#ifndef WITHOUT_HW
 #include "mf624_SIMULINK.h"
 
 static const int32_T irc_channel2reg[] = {
@@ -83,6 +85,7 @@ static const int32_T irc_channel2reg[] = {
     IRC2_reg,
     IRC3_reg
 };
+#endif /*WITHOUT_HW*/
 
 /* Error handling
  * --------------
@@ -127,6 +130,7 @@ static void mdlCheckParameters(SimStruct *S)
         ssSetErrorStatus(S, "Ts has to be positive or -1 for automatic step");
     if ((PRM_CHANNEL(S) < 0) || (PRM_CHANNEL(S) > 3))
         ssSetErrorStatus(S, "valid IRC channel is 0, 1, 2, or 3");
+  #ifndef WITHOUT_HW
     if ((PRM_COUNTER_MODE(S) < 0) || PRM_COUNTER_MODE(S) >
             __mfld2val(IRCCTRL_IRC0MODE_mask, IRCCTRL_IRC0MODE_mask))
         ssSetErrorStatus(S, "Counter Mode out of valid range");
@@ -141,6 +145,7 @@ static void mdlCheckParameters(SimStruct *S)
     if ((PRM_DIGITAL_FILTER(S) < 0) || PRM_DIGITAL_FILTER(S) >
             __mfld2val(IRCCTRL_IRC0FILTER_mask, IRCCTRL_IRC0FILTER_mask))
         ssSetErrorStatus(S, "Digital Filter out of valid range");
+  #endif /*WITHOUT_HW*/
     if ((PRM_RESET_AT_STARTUP(S) != 0) && (PRM_RESET_AT_STARTUP(S) != 1))
         ssSetErrorStatus(S, "Reset at startup can be only 0 or 1");
 }
@@ -249,6 +254,7 @@ static void mdlInitializeConditions(SimStruct *S)
     int_T reset_mode;
     int_T reset_mode_save;
 
+  #ifndef WITHOUT_HW
     if (mf624_check(S) != 0)
         return;
 
@@ -262,6 +268,7 @@ static void mdlInitializeConditions(SimStruct *S)
         IRC_mode_change(mfst, mask, reset_mode);
         IRC_mode_change(mfst, mask, reset_mode_save & mask);
     }
+  #endif /*WITHOUT_HW*/
 }
 #endif /* MDL_INITIALIZE_CONDITIONS */
 
@@ -282,6 +289,7 @@ static void mdlStart(SimStruct *S)
     int_T filter;
     int_T mask;
 
+  #ifndef WITHOUT_HW
     if (mf624_init(NULL) != 0)
         return;
 
@@ -309,6 +317,8 @@ static void mdlStart(SimStruct *S)
 
     IRC_mode_change(mfst, mask << shift, IWORK_IRCCTRL(S) << shift);
 
+  #endif /*WITHOUT_HW*/
+
     mdlInitializeConditions(S);
 }
 #endif /*  MDL_START */
@@ -324,10 +334,14 @@ static void mdlOutputs(SimStruct *S, int_T tid)
 {
     int32_T *y = ssGetOutputPortSignal(S,0);
 
+  #ifndef WITHOUT_HW
     if (mf624_check(S) != 0)
         return;
 
     y[0] = mf624_read32(MFST2REG(mfst, 4, irc_channel2reg[IWORK_CHANNEL(S)]));
+  #else /*WITHOUT_HW*/
+    y[0] = 0;
+  #endif /*WITHOUT_HW*/
 }
 
 
@@ -347,6 +361,7 @@ static void mdlUpdate(SimStruct *S, int_T tid)
     int_T shift;
     int_T inp_num = 0;
 
+  #ifndef WITHOUT_HW
     if (mf624_check(S) != 0)
         return;
 
@@ -376,6 +391,7 @@ static void mdlUpdate(SimStruct *S, int_T tid)
         shift = IWORK_CHANNEL(S) * IRCCTRL_CHANNEL_SHIFT;
         IRC_mode_change(mfst, mask << shift, IWORK_IRCCTRL(S) << shift);
     }
+  #endif /*WITHOUT_HW*/
 }
 #endif /* MDL_UPDATE */
 
@@ -403,7 +419,9 @@ static void mdlUpdate(SimStruct *S, int_T tid)
  */
 static void mdlTerminate(SimStruct *S)
 {
+  #ifndef WITHOUT_HW
     mf624_done();
+  #endif /*WITHOUT_HW*/
 }
 
 
index 605ff763fc46eb062f1927fcc4d0b77d27e5d52e..787dba1c7b94c8b5d7da2716ba3db346672d6780 100644 (file)
@@ -71,10 +71,15 @@ enum {CTR_LAST_MODE_OUT0, CTR_LAST_MODE_OUT1, CTR_LAST_MODE_PWM};
  * its associated macro definitions.
  */
 #include "simstruc.h"
+
+
+#ifndef WITHOUT_HW
 #include "mf624_SIMULINK.h"
+#endif /*WITHOUT_HW*/
 
 #define CTR_MAX_PWM_CHANNEL            3
 
+#ifndef WITHOUT_HW
 typedef struct {
     int32_T STATUS_reg;
     int32_T MODE_reg;
@@ -91,6 +96,7 @@ static const ctr_channel_regs_t ctr_channel2regs[] = {
     {CTR3STATUS_reg, CTR3MODE_reg, CTR3_reg, CTR3A_reg, CTR3B_reg, CTRXCTRL_reg},
     {CTR4STATUS_reg, CTR4MODE_reg, CTR4_reg, CTR4A_reg, -1,        CTRXCTRL_reg}
 };
+#endif /*WITHOUT_HW*/
 
 /* Error handling
  * --------------
@@ -247,6 +253,7 @@ static void mdlStart(SimStruct *S)
 {
     int32_T ctr_mode;
 
+  #ifndef WITHOUT_HW
     if (mf624_init(NULL) != 0)
         return;
 
@@ -263,6 +270,7 @@ static void mdlStart(SimStruct *S)
     /* Force output low during startup */
     ctr_mode = __val2mfld(CTR_MODE_OUTPUT_CONTROL_mask, CTR_MODE_OUTPUT_CONTROL_FORCE_LO);
     mf624_write32(ctr_mode, MFST2REG(mfst, 4, ctr_channel2regs[IWORK_CHANNEL(S)].MODE_reg));
+  #endif /*WITHOUT_HW*/
 }
 #endif /*  MDL_START */
 
@@ -284,6 +292,7 @@ static void mdlOutputs(SimStruct *S, int_T tid)
     uint32_T T1_uint;
     uint32_T T2_uint;
 
+  #ifndef WITHOUT_HW
     if (mf624_check(S) != 0)
             return;
 
@@ -363,6 +372,7 @@ static void mdlOutputs(SimStruct *S, int_T tid)
         ctr_ctrl <<= IWORK_CHANNEL(S) * CTRXCTRL_CHANNEL_SHIFT;
         mf624_write32(ctr_ctrl, MFST2REG(mfst, 4, ctr_channel2regs[IWORK_CHANNEL(S)].CTRL_reg));
     }
+  #endif /*WITHOUT_HW*/
 }
 
 
@@ -407,6 +417,7 @@ static void mdlTerminate(SimStruct *S)
 {
     int32_T ctr_mode;
 
+  #ifndef WITHOUT_HW
     if (mf624_check(S) == 0) {
         /* Force output low when finished */
         ctr_mode = __val2mfld(CTR_MODE_OUTPUT_CONTROL_mask, CTR_MODE_OUTPUT_CONTROL_FORCE_LO);
@@ -414,6 +425,7 @@ static void mdlTerminate(SimStruct *S)
     }
 
     mf624_done();
+  #endif /*WITHOUT_HW*/
 }
 
 
index 3751f623901320de35baebd34f163637bf029cf1..24bf21ade0687bfe1f1ae9e680a29adb11a830c2 100644 (file)
@@ -76,10 +76,14 @@ enum {CTR_MODE_ZERO = 0, CTR_MODE_PLUS_PWM = 1, CTR_MODE_PLUS_FULL = 2,
  * its associated macro definitions.
  */
 #include "simstruc.h"
+
+#ifndef WITHOUT_HW
 #include "mf624_SIMULINK.h"
+#endif /*WITHOUT_HW*/
 
 #define CTR_MAX_PWM_CHANNEL            3
 
+#ifndef WITHOUT_HW
 typedef struct {
     int32_T STATUS_reg;
     int32_T MODE_reg;
@@ -96,6 +100,7 @@ static const ctr_channel_regs_t ctr_channel2regs[] = {
     {CTR3STATUS_reg, CTR3MODE_reg, CTR3_reg, CTR3A_reg, CTR3B_reg, CTRXCTRL_reg},
     {CTR4STATUS_reg, CTR4MODE_reg, CTR4_reg, CTR4A_reg, -1,        CTRXCTRL_reg}
 };
+#endif /*WITHOUT_HW*/
 
 /* Error handling
  * --------------
@@ -121,6 +126,7 @@ static const ctr_channel_regs_t ctr_channel2regs[] = {
  * See matlabroot/simulink/src/sfuntmpl_doc.c for more details.
  */
 
+#ifndef WITHOUT_HW
 static void fncSetDirOutput(SimStruct *S, int_T direction_mode)
 {
     if (mf624_check(S) != 0)
@@ -135,6 +141,7 @@ static void fncSetDirOutput(SimStruct *S, int_T direction_mode)
 
     mf624_write16(mfst->DOut, MFST2REG(mfst, 2, DOUT_reg));
 }
+#endif /*WITHOUT_HW*/
 
 /*====================*
  * S-function methods *
@@ -269,6 +276,7 @@ static void mdlStart(SimStruct *S)
 {
     int32_T ctr_mode;
 
+  #ifndef WITHOUT_HW
     if (mf624_init(NULL) != 0)
         return;
 
@@ -286,6 +294,7 @@ static void mdlStart(SimStruct *S)
     /* Force output low during startup */
     ctr_mode = __val2mfld(CTR_MODE_OUTPUT_CONTROL_mask, CTR_MODE_OUTPUT_CONTROL_FORCE_LO);
     mf624_write32(ctr_mode, MFST2REG(mfst, 4, ctr_channel2regs[IWORK_CHANNEL(S)].MODE_reg));
+  #endif /*WITHOUT_HW*/
 }
 #endif /*  MDL_START */
 
@@ -308,6 +317,7 @@ static void mdlOutputs(SimStruct *S, int_T tid)
     uint32_T T2_uint;
     int_T new_mode;
 
+  #ifndef WITHOUT_HW
     if (mf624_check(S) != 0)
             return;
 
@@ -410,6 +420,7 @@ static void mdlOutputs(SimStruct *S, int_T tid)
         ctr_ctrl <<= IWORK_CHANNEL(S) * CTRXCTRL_CHANNEL_SHIFT;
         mf624_write32(ctr_ctrl, MFST2REG(mfst, 4, ctr_channel2regs[IWORK_CHANNEL(S)].CTRL_reg));
     }
+  #endif /*WITHOUT_HW*/
 }
 
 
@@ -454,6 +465,7 @@ static void mdlTerminate(SimStruct *S)
 {
     int32_T ctr_mode;
 
+  #ifndef WITHOUT_HW
     if (mf624_check(S) == 0) {
         /* Force output low when finished */
         ctr_mode = __val2mfld(CTR_MODE_OUTPUT_CONTROL_mask, CTR_MODE_OUTPUT_CONTROL_FORCE_LO);
@@ -461,6 +473,7 @@ static void mdlTerminate(SimStruct *S)
     }
 
     mf624_done();
+  #endif /*WITHOUT_HW*/
 }
 
 
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*/
 }