]> rtime.felk.cvut.cz Git - mf624-simulink.git/blobdiff - sfIRCInput.c
Add build mode WITHOUT_HW to edit model without MF624 hardware access.
[mf624-simulink.git] / sfIRCInput.c
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*/
 }