Forum Discussion
Altera_Forum
Honored Contributor
16 years agoI also tried the code provided by Altera which does not work either. that's why I think the problem comes from Quartus II.
Thanks !! Myriam Program : static void handle_button_interrupts(void* context, alt_u32 id) { /* Cast context to edge_capture's type. It is important that this be * declared volatile to avoid unwanted compiler optimization. */ volatile int* edge_capture_ptr = (volatile int*) context; /* Store the value in the Button's edge capture register in *context. */ *edge_capture_ptr = IORD_ALTERA_AVALON_PIO_EDGE_CAP(BUTTON_PIO_BASE); /* Reset the Button's edge capture register. */ IOWR_ALTERA_AVALON_PIO_EDGE_CAP(BUTTON_PIO_BASE, 0); IORD_ALTERA_AVALON_PIO_EDGE_CAP(BUTTON_PIO_BASE); //An extra read call to clear of delay through the bridge } /* Initialize the button_pio. */ static void init_button_pio() { /* Recast the edge_capture pointer to match the alt_irq_register() function * prototype. */ void* edge_capture_ptr = (void*) &edge_capture; /* Enable all 4 button interrupts. */ IOWR_ALTERA_AVALON_PIO_IRQ_MASK(BUTTON_PIO_BASE, 0xf); /* Reset the edge capture register. */ IOWR_ALTERA_AVALON_PIO_EDGE_CAP(BUTTON_PIO_BASE, 0x0); /* Register the interrupt handler. */ alt_irq_register( BUTTON_PIO_IRQ, edge_capture_ptr, handle_button_interrupts ); } static void handle_button_press() { if (edge_capture!=0) printf ("Gloupix : %d",edge_capture); switch (edge_capture) { case 0x1: IOWR_ALTERA_AVALON_PIO_DATA(LED_PIO_BASE, 0x1); break; case 0x2: IOWR_ALTERA_AVALON_PIO_DATA(LED_PIO_BASE, 0x2); break; case 0x4: IOWR_ALTERA_AVALON_PIO_DATA(LED_PIO_BASE, 0x4); break; case 0x8: IOWR_ALTERA_AVALON_PIO_DATA(LED_PIO_BASE, 0x8); break; default: IOWR_ALTERA_AVALON_PIO_DATA(LED_PIO_BASE, 0xE); break; } } int main(void) { init_button_pio(); while( 1 ) { handle_button_press(); } return 0; }