ssSetErrorStatus(S,"Invalid parameter mask, set to 0-255");
}
- int ADCChannels = __builtin_popcount((uint)ADCCMask); //Counts number of set bits in ADCCMask
+ int ADCChannels = __builtin_popcount((uint32_t)ADCCMask); //Counts number of set bits in ADCCMask
- if (!ssSetNumInputPorts(S, 1)) return;
- ssSetInputPortWidth(S, 0, 1);
- ssSetInputPortRequiredContiguous(S, 0, true); /*direct input signal access*/
- /*
- * Set direct feedthrough flag (1=yes, 0=no).
- * A port has direct feedthrough if the input is used in either
- * the mdlOutputs or mdlGetTimeOfNextVarHit functions.
- * See matlabroot/simulink/src/sfuntmpl_directfeed.txt.
- */
- ssSetInputPortDirectFeedThrough(S, 0, 1);
+ if (!ssSetNumInputPorts(S, 0)) return;
+
+
if (!ssSetNumOutputPorts(S, ADCChannels)) return;
for(i=0; i < ADCChannels;i++){
ssSetNumSampleTimes(S, 1);
ssSetNumRWork(S, 0);
ssSetNumIWork(S, 1);
- ssSetNumPWork(S, 1);
+ ssSetNumPWork(S, 0);
ssSetNumModes(S, 0);
ssSetNumNonsampledZCs(S, 0);
static void mdlInitializeSampleTimes(SimStruct *S)
{
ssSetSampleTime(S, 0, CONTINUOUS_SAMPLE_TIME);
- ssSetOffsetTime(S, 0, 0.0);
+ ssSetOffsetTime(S, 0, FIXED_IN_MINOR_STEP_OFFSET);
}
*/
static void mdlStart(SimStruct *S)
{
- //TODO: get pointer to mfst state structure and store it in pwork
- #define TEST
- #if defined(TEST)
- #define BUFF_SMALL 32
- mf624_state_t* mfst = malloc(sizeof(mf624_state_t));
- char buff[BUFF_SMALL];
- memset(buff, '\0', BUFF_SMALL);
- mfst->uio_dev = "uio0";
-
- strncat(buff, "/dev/", 5);
- strncat(buff, mfst->uio_dev, sizeof(buff) - 6);
-
- mfst->device_fd = open_device(buff);
-
- if (mfst->device_fd < 0) {
- ssSetErrorStatus(S,"open failed");
- return;
- }
-
- if (mmap_regions(mfst) < 0) {
- ssSetErrorStatus(S,"mmap_regions failed");
- return;
- }
-
- #endif
+ if (mf624_init(NULL) != 0)
+ return;
int ADCCMask = (int)MASK_PRM(S);
- int i;
+
if(ADCCMask > 255 || ADCCMask < 0) {
ssSetErrorStatus(S,"Invalid parameter mask, set to 0-255");
}
- int ADCChannels = __builtin_popcount((uint)ADCCMask); //Counts number of set bits in ADCCMask
+ int ADCChannels = __builtin_popcount((uint32_t)ADCCMask); //Counts number of set bits in ADCCMask
ssSetIWorkValue(S, 0, ADCChannels);
mf624_write16(mfst->ADC_enabled, MFST2REG(mfst, 2, ADCTRL_reg));
- ssSetPWorkValue(S, 0, mfst);
+
}
#endif /* MDL_START */
static void mdlOutputs(SimStruct *S, int_T tid)
{
- mf624_state_t* mfst = ssGetPWorkValue(S, 0);
int ADCChannels = ssGetIWorkValue(S, 0);
real_T* y[ADCChannels];
int i;
int res,res1;
+ if (mf624_check(S) != 0)
+ return;
+
// Activate trigger to start conversion
mf624_read16(MFST2REG(mfst, 2, ADSTART_reg));
*/
static void mdlTerminate(SimStruct *S)
{
- #if defined(TEST)
- free(ssGetPWorkValue(S,0));
- #endif
+ mf624_done(S);
}