]> rtime.felk.cvut.cz Git - mf624-simulink.git/commitdiff
Allow build of m624 AnalogInput by C89 compiler - i.e. MS Visual C.
authorKvetoslav Belda <belda@utia.cas.cz>
Fri, 18 Apr 2014 14:05:32 +0000 (16:05 +0200)
committerKvetoslav Belda <belda@utia.cas.cz>
Fri, 18 Apr 2014 14:05:32 +0000 (16:05 +0200)
sfAnalogInput.c

index 70e4ca956d0307bfe47b5c5d30759567d9addfa6..fdc1722faf1f40b70c8040d92c43b3d473008f19 100644 (file)
 #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 */
@@ -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);
     }