/*
* S-function to support IRC inputs on Humusoft MF624 card
*
- * Based on sfuntmpl_basic.c by The MathWorks, Inc.
+ * Copyright (C) 2014 Pavel Pisa <pisa@cmp.felk.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 PRM_COUNTER_GATING(S) (mxGetScalar(ssGetSFcnParam(S, 3)))
#define PRM_RESET_CONTROL(S) (mxGetScalar(ssGetSFcnParam(S, 4)))
#define PRM_DIGITAL_FILTER(S) (mxGetScalar(ssGetSFcnParam(S, 5)))
+#define PRM_RESET_AT_STARTUP(S) (mxGetScalar(ssGetSFcnParam(S, 6)))
-#define PRM_COUNT 6
+#define PRM_COUNT 7
#define IWORK_IDX_CHANNEL 0
#define IWORK_IDX_IRCCTRL 1
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");
+ if ((PRM_RESET_AT_STARTUP(S) != 0) && (PRM_RESET_AT_STARTUP(S) != 1))
+ ssSetErrorStatus(S, "Reset at startup can be only 0 or 1");
}
#endif /* MDL_CHECK_PARAMETERS */
* configured to reset states, it will be call when the enabled subsystem
* restarts execution to reset the states.
*/
- static void mdlInitializeConditions(SimStruct *S)
- {
- }
+static void mdlInitializeConditions(SimStruct *S)
+{
+ int_T shift;
+ int_T mask;
+ int_T reset_mode;
+ int_T reset_mode_save;
+
+ if (mf624_check(S) != 0)
+ return;
+
+ if (PRM_RESET_AT_STARTUP(S)) {
+ shift = IWORK_CHANNEL(S) * IRCCTRL_CHANNEL_SHIFT;
+
+ mask = IRCCTRL_IRC0RESET_mask << shift;
+ reset_mode = __val2mfld(IRCCTRL_IRC0RESET_mask, IRCCTRL_RESET_ALWAYS) << shift;
+
+ reset_mode_save = IRC_mode_change(mfst, 0, 0);
+ IRC_mode_change(mfst, mask, reset_mode);
+ IRC_mode_change(mfst, mask, reset_mode_save & mask);
+ }
+}
#endif /* MDL_INITIALIZE_CONDITIONS */
shift = IWORK_CHANNEL(S) * IRCCTRL_CHANNEL_SHIFT;
IRC_mode_change(mfst, mask << shift, IWORK_IRCCTRL(S) << shift);
+
+ mdlInitializeConditions(S);
}
#endif /* MDL_START */