// The interrupt service routine static void Key_InterruptHandler(void* context, alt_u32 id) { pollkey(); /* Write to the edge capture register to reset it. */ IOWR_ALTERA_AVALON_PIO_EDGE_CAP(DE2_PIO_KEYS4_BASE, 0); /* reset interrupt capability for the Button PIO. */ IOWR_ALTERA_AVALON_PIO_IRQ_MASK(DE2_PIO_KEYS4_BASE, 0xf); }
void mydelay_half() /* sleep until the half-second mark. also works via polling. also close enough for government work. */ { static struct timeval curr; while (1) { gettimeofday(&curr, NULL); if (curr.tv_usec >= 500000) return; pollkey(); } }
void mydelay() /* sleep until second changes. works via polling. close enough for government work. */ { static struct timeval prev; static struct timeval curr; gettimeofday(&prev, NULL); while (1) { gettimeofday(&curr, NULL); if (curr.tv_sec > prev.tv_sec) return; pollkey(); prev = curr; } }