You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

main.c 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #define _POSIX_C_SOURCE 199309L
  2. #include <sys/time.h>
  3. #include <time.h>
  4. #include <iostream>
  5. #include <stdlib.h>
  6. #include <stdio.h>
  7. #include <string.h>
  8. #include <stdlib.h>
  9. #include <pthread.h>
  10. #include <signal.h>
  11. #include "gpio-raw.h"
  12. bool thread_exit = false;
  13. static void signal_handler(int signo)
  14. {
  15. thread_exit = true;
  16. }
  17. void* worker(void*)
  18. {
  19. FILE* fd = fopen("clock.out", "w");
  20. while (!thread_exit)
  21. sleep(1);
  22. fclose(fd);
  23. return 0;
  24. }
  25. int main(int argc, char* argv[])
  26. {
  27. signal(SIGINT, signal_handler);
  28. setup_io();
  29. INP_GPIO(4); // must use INP_GPIO before we can use OUT_GPIO
  30. struct timeval t1, t2;
  31. const int n = argc == 2 ? atoi(argv[1]) : 1000000;
  32. pthread_t thread;
  33. pthread_create(&thread, 0, worker, 0);
  34. gettimeofday(&t1, NULL);
  35. for (int i = 0; !thread_exit; ++i)
  36. {
  37. //GPIO_VALUE(6);
  38. //tab[i] = GPIO_VALUE(6);
  39. printf("%i\n", GPIO_VALUE(6));
  40. //fprintf(fd, "%i\n", v);
  41. //GPIO_SET = 1<<4;
  42. //GPIO_CLR = 1<<4;
  43. }
  44. gettimeofday(&t2, NULL);
  45. pthread_join(thread, 0);
  46. unsigned long long ut1 = (__suseconds_t)(1000000L * t1.tv_sec + t1.tv_usec);
  47. unsigned long long ut2 = (__suseconds_t)(1000000L * t2.tv_sec + t2.tv_usec);
  48. std::cout << ut1 << " " << ut2 << " ";
  49. std::cout << (ut2 - ut1) << " " << (float)(ut2 - ut1) / n << std::endl;
  50. return 0;
  51. }