From: Kvetoslav Belda Date: Fri, 18 Apr 2014 14:05:32 +0000 (+0200) Subject: Allow build of m624 AnalogInput by C89 compiler - i.e. MS Visual C. X-Git-Url: http://rtime.felk.cvut.cz/gitweb/mf624-simulink.git/commitdiff_plain/a2b0c2e846459ae30cf85ac287b19c7b275ab16f Allow build of m624 AnalogInput by C89 compiler - i.e. MS Visual C. --- diff --git a/sfAnalogInput.c b/sfAnalogInput.c index 70e4ca9..fdc1722 100644 --- a/sfAnalogInput.c +++ b/sfAnalogInput.c @@ -47,11 +47,27 @@ #include "simstruc.h" #include +#include #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 * -------------- @@ -88,6 +104,9 @@ */ 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 */ @@ -100,15 +119,14 @@ static void mdlInitializeSizes(SimStruct *S) 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; @@ -179,6 +197,7 @@ static void mdlInitializeSampleTimes(SimStruct *S) */ static void mdlStart(SimStruct *S) { + int ADCChannels; #ifndef WITHOUT_HW if (mf624_init(NULL) != 0) @@ -191,7 +210,7 @@ static void mdlInitializeSampleTimes(SimStruct *S) 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 @@ -214,7 +233,7 @@ static void mdlOutputs(SimStruct *S, int_T tid) { int ADCChannels = ssGetIWorkValue(S, 0); - real_T* y[ADCChannels]; + real_T** y; int i; int res,res1; #ifndef WITHOUT_HW @@ -225,6 +244,8 @@ static void mdlOutputs(SimStruct *S, int_T tid) 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); }