#define _POSIX_C_SOURCE 199309L #include #include #include #include #include #include #include #include #include #include "gpio-raw.h" bool thread_exit = false; static void signal_handler(int signo) { thread_exit = true; } void* worker(void*) { FILE* fd = fopen("clock.out", "w"); while (!thread_exit) sleep(1); fclose(fd); return 0; } int main(int argc, char* argv[]) { signal(SIGINT, signal_handler); setup_io(); INP_GPIO(4); // must use INP_GPIO before we can use OUT_GPIO struct timeval t1, t2; const int n = argc == 2 ? atoi(argv[1]) : 1000000; pthread_t thread; pthread_create(&thread, 0, worker, 0); gettimeofday(&t1, NULL); for (int i = 0; !thread_exit; ++i) { //GPIO_VALUE(6); //tab[i] = GPIO_VALUE(6); printf("%i\n", GPIO_VALUE(6)); //fprintf(fd, "%i\n", v); //GPIO_SET = 1<<4; //GPIO_CLR = 1<<4; } gettimeofday(&t2, NULL); pthread_join(thread, 0); unsigned long long ut1 = (__suseconds_t)(1000000L * t1.tv_sec + t1.tv_usec); unsigned long long ut2 = (__suseconds_t)(1000000L * t2.tv_sec + t2.tv_usec); std::cout << ut1 << " " << ut2 << " "; std::cout << (ut2 - ut1) << " " << (float)(ut2 - ut1) / n << std::endl; return 0; }