Forum Discussion
Altera_Forum
Honored Contributor
19 years agoHere is working example of edge capture
volatile int edge_capture_coin; static void handle_coin_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(COIN_IN_BASE); /* Reset the Button's edge capture register. */ IOWR_ALTERA_AVALON_PIO_EDGE_CAP(COIN_IN_BASE, 0); } static void init_coin_in_pio() { /* Recast the edge_capture pointer to match the alt_irq_register() function * prototype. */ void* edge_capture_ptr = (void*) &edge_capture_coin; /* Enable all 8 ways interrupts. */ IOWR_ALTERA_AVALON_PIO_IRQ_MASK(COIN_IN_BASE, 0xff); /* Reset the edge capture register. */ IOWR_ALTERA_AVALON_PIO_EDGE_CAP(COIN_IN_BASE, 0x0); /* Register the interrupt handler. */ alt_irq_register( COIN_IN_IRQ, edge_capture_ptr, handle_coin_interrupts ); } void coin() { int i,j; int exit=1; char ch; init_coin_in_pio(); while(1) { if (edge_capture_coin!=0) { switch (edge_capture_coin) { case ACC_COIN0 : printf("\ncoin_in0 - ok"); break; case ACC_COIN1 : printf("\ncoin_in1 - ok"); break; case ACC_COIN2 : printf("\ncoin_in2 - ok"); break; case ACC_COIN3 : printf("\ncoin_in3 - ok"); break; case ACC_COIN4 : printf("\ncoin_in4 - ok"); break; case ACC_COIN5 : printf("\ncoin_in5 - ok"); break; case ACC_COIN6 : printf("\ncoin_in6 - ok"); break; case ACC_COIN7 : printf("\ncoin_in7 - ok"); break; } edge_capture_coin=0; } } }