Nick: icon E-mail: none Board: REF_TOGGLE Contents: #include #include #include int main(void) { if (ioperm(0x61, 1, 1) || ioperm(0x40, 4, 1)) { perror("No privileges"); return 1; } unsigned int i; outb(0x76, 0x43); outb(18, 0x41); outb(0, 0x41); unsigned int p; struct timespec ts; unsigned int cnt[2] = { 0 }; unsigned int t[2] = { 0 }; /* wait for 0/1 edge */ for (; (inb(0x61) & 0x10); ++i); for (; !(inb(0x61) & 0x10); ++i); clock_gettime(CLOCK_MONOTONIC, &ts); for (i = 0, p = 0; i < 1234567; p ^= 1) { /* wait for p */ for (; (inb(0x61) >> 4 & 1) != p; ++i); struct timespec now; clock_gettime(CLOCK_MONOTONIC, &now); const unsigned int ns = (now.tv_sec - ts.tv_sec) * 1000*1000*1000 + (now.tv_nsec - ts.tv_nsec); t[p] += ns / 1000; ++cnt[p]; ts = now; } if (cnt[1]) printf("0 avg: %u.%03uus (%u / %u)\n", t[1] / cnt[1], t[1] * 1000 / cnt[1] % 1000, t[1], cnt[1]); if (cnt[0]) printf("1 avg: %u.%03uus (%u / %u)\n", t[0] / cnt[0], t[0] * 1000 / cnt[0] % 1000, t[0], cnt[0]); cnt[0] = 0; /* wait for 0/1 edge */ for (; (inb(0x61) & 0x10); ++i); for (; !(inb(0x61) & 0x10); ++i); clock_gettime(CLOCK_MONOTONIC, &ts); for (i = 0; i < 1234567; ++cnt[0]) { /* wait for 0/1 edge */ for (; (inb(0x61) & 0x10); ++i); for (; !(inb(0x61) & 0x10); ++i); } struct timespec now; clock_gettime(CLOCK_MONOTONIC, &now); const unsigned long long ns = (now.tv_sec - ts.tv_sec) * 1000000000ull + (now.tv_nsec - ts.tv_nsec); if (cnt[0]) printf("avg: %u.%03uus (%u / %u)\n", ns / cnt[0] / 1000, ns / cnt[0] % 1000, ns / 1000, cnt[0]); return 0; }