/* pps-edgetest - a program for measuring interrupt latency when using PPS input. For ISA/PCI (16x50) serial ports only. Beerware License 2011-2012 Kasper Pedersen TO COMPILE: gcc -O2 -o edgetest edgetest.c ABOUT: This program time stamps the PPS input through polling, and does it in a way that put hard upper and lower bounds on the timing of the event. This allows one to find the interrupt processing time incurred before the PPS timestamp is taken, as well as any interrupt generation delays in the hardware. On my 5000-series server, the delay is a constant 14us. */ #include #include #include #define PADDR 0x3F8 #define PBIT 7 #define PAOFFS 6 inline unsigned char rrr(void) { return inb(PADDR+PAOFFS)&(1<500000) t1-=1000000; if (t3>500000) t3-=1000000; if (t5>500000) t5-=1000000; printf("Rising edge:\n\ ___________________\n\ / /\n\ / /\n\ ____________/_________/\n\ \n\ | | |\n\ %7i -------+ | |\n\ %7i --------------+ |\n\ %7i ---------------------+\n\ \n",t1,t3,t5); t1=rrr(); gettimeofday(&tv,0); t1=tv.tv_usec; b2=rrr(); gettimeofday(&tv,0); t3=tv.tv_usec; b4=rrr(); gettimeofday(&tv,0); t5=tv.tv_usec; do { t1=t3; b2=b4; t3=t5; b4=rrr(); gettimeofday(&tv,0); t5=tv.tv_usec; } while (!(b2&&!b4)); if (t1>500000) t1-=1000000; if (t3>500000) t3-=1000000; if (t5>500000) t5-=1000000; printf("Falling edge:\n\ ______________________\n\ \\ \\ \n\ \\ \\\n\ \\_________\\_________\n\ \n\ | | |\n\ %7i -------+ | |\n\ %7i --------------+ |\n\ %7i ---------------------+\n\ ",t1,t3,t5); }