#include "simstruc.h"
#include <stdint.h>
+#include <malloc.h>
#ifndef WITHOUT_HW
#include "mf624_SIMULINK.h"
#endif /*WITHOUT_HW*/
+ #ifdef __GNUC__
+ #define my_popcount __builtin_popcount
+ #else
+ int my_popcount(uint32_t patt)
+ {
+ int pops = 0;
+ while (patt) {
+ if (patt & 1)
+ pops++;
+ patt >>= 1;
+ }
+ return pops;
+ }
+ #endif
+
/* Error handling
* --------------
*/
static void mdlInitializeSizes(SimStruct *S)
{
+ int ADCCMask;
+ int i;
+ int ADCChannels;
/* See sfuntmpl_doc.c for more details on the macros below */
ssSetNumSFcnParams(S, 1); /* Number of expected parameters */
ssSetNumContStates(S, 0);
ssSetNumDiscStates(S, 0);
- int ADCCMask = (int)MASK_PRM(S);
- int i;
+ 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
-
-
+ ADCChannels = my_popcount((uint32_t)ADCCMask); //Counts number of set bits in ADCCMask
+
if (!ssSetNumInputPorts(S, 0)) return;
*/
static void mdlStart(SimStruct *S)
{
+ int ADCChannels;
#ifndef WITHOUT_HW
if (mf624_init(NULL) != 0)
ssSetErrorStatus(S,"Invalid parameter mask, set to 0-255");
}
- int ADCChannels = __builtin_popcount((uint32_t)ADCCMask); //Counts number of set bits in ADCCMask
+ ADCChannels = my_popcount((uint32_t)ADCCMask); //Counts number of set bits in ADCCMask
ssSetIWorkValue(S, 0, ADCChannels);
#ifndef WITHOUT_HW
{
int ADCChannels = ssGetIWorkValue(S, 0);
- real_T* y[ADCChannels];
+ real_T** y;
int i;
int res,res1;
#ifndef WITHOUT_HW
mf624_read16(MFST2REG(mfst, 2, ADSTART_reg));
#endif /*WITHOUT_HW*/
+ y = alloca(ADCChannels * sizeof(*y));
+
for(i=0; i < ADCChannels;i++){
y[i]=ssGetOutputPortSignal(S,i);
}