+/*
+ * S-function to measure external PWM signal duty cycle on Humusoft MF624 card
+ *
+ * Copyright (C) 2013 Michal Kreč <krecmich@fel.cvut.cz>
+ * Copyright (C) 2013 Michal Sojka <sojkam1@fel.cvut.cz>
+ *
+ * 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.
+ */
#define S_FUNCTION_NAME sfReadPWM
#define S_FUNCTION_LEVEL 2
*/
#include "simstruc.h"
+#ifndef WITHOUT_HW
#include "mf624_SIMULINK.h"
+#endif /*WITHOUT_HW*/
/* Error handling
* --------------
*/
static void mdlStart(SimStruct *S)
{
+ #ifndef WITHOUT_HW
if (mf624_init(NULL) != 0)
return;
/*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 */
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*/
}
*/
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*/
}