1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- #define _POSIX_C_SOURCE 199309L
- #include <sys/time.h>
- #include <time.h>
- #include <iostream>
- #include <stdlib.h>
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- #include <signal.h>
-
- #include "gpio-raw.h"
-
-
- volatile unsigned n = 350000000 / sizeof(unsigned char);
-
- void signal_handler(int signo)
- {
- std::cout << "signal catched" << std::endl;
- n = 0;
- }
-
- int main(int argc, char* argv[])
- {
- setup_io();
- INP_GPIO(4);
-
- struct timeval t1, t2;
- unsigned char* v = new unsigned char[n];
- unsigned count = 0;
- std::cout << "Ready to sniff. Press enter...";
- getchar();
-
- signal(SIGINT, signal_handler);
- gettimeofday(&t1, NULL);
- for (; count < n; ++count)
- {
- const unsigned value = GPIO_LEV;
- v[count] = GPIO_VALUE_R(value, 6) | (GPIO_VALUE_R(value, 26) << 1);
- }
- gettimeofday(&t2, NULL);
- signal(SIGINT, SIG_DFL);
-
- 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);
- unsigned long long diff = ut2 - ut1;
- double unit = (double)diff / count;
- double mhz = (1000000.0 / unit) / 1000000.0;
- std::cout << "count: " << count << " diff: " << diff << " unit: "
- << unit << " Mhz: " << mhz << std::endl;
-
- std::cout << "Saving file..." << std::endl;
- int fd = open("gpio.out", O_CREAT | O_WRONLY);
- write(fd, (void*)v, count * sizeof(*v));
- close(fd);
- return 0;
- }
|