Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
21 years ago

why cann't it recive interrupt

why cann't it recive interrupt,when the key is pressed, the led shows nothing

# include "system.h"# include "altera_avalon_pio_regs.h"# include "alt_types.h"# include "D:\document\nios\low_cost\h\alt_irq.h"# include <stdio.h># include <unistd.h>

volatile int edge_capture;

static void handle_button_interrupts(void* context, alt_u32 id)

{

volatile int* edge_capture_ptr = (volatile int*) context;

*edge_capture_ptr = IORD_ALTERA_AVALON_PIO_EDGE_CAP(BUTTON_PIO_BASE);

IOWR_ALTERA_AVALON_PIO_EDGE_CAP(BUTTON_PIO_BASE, 0);

}

static void init_button_pio()

{

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 );

}

int main (void)

{

IOWR_ALTERA_AVALON_PIO_DATA(LED_PIO_BASE, 0); # ifdef BUTTON_PIO_BASE

init_button_pio();# endif

//

while( 1 )

{

if (edge_capture != 0)

{

IOWR_ALTERA_AVALON_PIO_DATA(LED_PIO_BASE, 0xf);

}

}

return 0;

}

5 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    If you take a look at a Nios reference design like standard or full, there are interupt buttons as well. Then if you look at the board diagnostic software example you&#39;ll see how the buttons are handled.

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    1. I use quartus

    //

    2. I refred to the software example,but the button can not handled.

    //

    3. is my program error ????
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    I have the same problem

    my system consists of button_pio led_pio onchip_ram

    the capture register can catch the rising edge and capture&#39;s value can change but the interrup funtionstatic void handle_button_interrupts(void* context, alt_u32 id) can not respone

    i need help

    thank!!!!!!