Advertisement
Guest User

Untitled

a guest
Jul 30th, 2015
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.26 KB | None | 0 0
  1. //All needed includes for GPIO operation are here.
  2. #include "EInterface.h"
  3. #include <sys/time.h>
  4.  
  5. #define ITERATIONS 15000.f
  6.  
  7. int main()
  8. {
  9.     //Initialize GPIO Interface, and check if it returns any error code.
  10.     //IF success (if errorCode is -1, it's bad!)
  11.     if (StartInterface() == 1)
  12.     {
  13.         printf("Starting %f x 4 pin switch operations\n", ITERATIONS);
  14.         struct timeval t1, t2;
  15.         gettimeofday(&t1, NULL);
  16.         //If interface was properly initialized, blink the PD1 and PD2 pins five times in 0.2 second intervals:
  17.         int i;
  18.         for (i = 0; i < ITERATIONS; i++)
  19.         {      
  20.             SetPinValue(PD1, HIGH);
  21.             SetPinValue(PD2, LOW); 
  22.             //printf("-------------\n");
  23.            
  24.             //usleep(200000);
  25.  
  26.             SetPinValue(PD1, LOW);
  27.             SetPinValue(PD2, HIGH);
  28.             //printf("-------------\n");
  29.            
  30.             //usleep(200000);          
  31.  
  32.         }
  33.        
  34.         gettimeofday(&t2, NULL);
  35.  
  36.         double elapsedTime = (t2.tv_sec - t1.tv_sec) * 1000.f;
  37.         elapsedTime += (t2.tv_usec - t1.tv_usec) / 1000.f;
  38.  
  39.         double timePerIteration = elapsedTime / ITERATIONS;
  40.         double timePerSwitch = timePerIteration / 4.f;
  41.  
  42.  
  43.         printf("Time total: %fms\n", elapsedTime);
  44.         printf("Time per iteration: %fms\n", timePerIteration);
  45.         printf("Time per switch: %fms\n", timePerSwitch);
  46.  
  47.         CloseInterface();
  48.  
  49.     }
  50.  
  51.     return 0;
  52.  
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement