Forum Discussion

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

Why Nios II don't execute my ISR?

Hi All:

I want implement a ISR in Nios II system, however, if I implement it with Nios HAL, everything is OK, the Isr call successfully, but if I implement it in alt_main(), without HAL, the interrupt never appear. I want to know whta's the problem here?. My C Code show below, thanks

//------------------------# include "system.h"# include "altera_avalon_pio_regs.h"# include "alt_types.h"# include "altera_avalon_uart_regs.h"# include "sys/alt_irq.h"

static void handle_key_interrupt(void* context,alt_u32 id)

{

/* Reset the edge capture register. */

IOWR_ALTERA_AVALON_PIO_EDGE_CAP(BUTTON_PIO_BASE, 0x0);

IOWR_ALTERA_AVALON_PIO_DATA(LED_PIO_BASE, 0x55);

}

static void init_key_pio()

{

/* Recast the edge_capture pointer to match the alt_irq_register() function

* prototype. */

/* Enable all 4 button interrupts. */

IOWR_ALTERA_AVALON_PIO_IRQ_MASK(BUTTON_PIO_BASE, 0x1);

/* 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, 0x0, handle_key_interrupt );

}

int main (void) __attribute__ ((weak, alias ("alt_main")));

int alt_main (void)

{

volatile int i;

i=0;

// alt_u8 led=0x01;

// alt_u8 key;

IOWR_ALTERA_AVALON_PIO_DATA(LED_PIO_BASE, 0xf0);

init_key_pio();

i=alt_irq_enabled();

while (1)

{

}

return 0;

}

//--------------------------

yyd999

4 Replies

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

    If you write an application using the alt_main() rather than main() entry point then the HAL will not automatically perform any device initialisation for you. This includes initialisation of the interrupt controller. Take a look in alt_main.c that comes with the kit. This contains the code that would have run if you'd used the main() entry point instead.

    The line that is of interest to you is the one that initialises the interrupt controller:

    alt_irq_init (ALT_IRQ_BASE);

    If you add that to the top of your alt_main(), that should do the job.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Also take a look at the "Hello Freestanding" software example in the IDE. Basically this is the same as what monkeyboy is suggesting (that is, the example source code performs the same functions that our alt_main.c does), but is provided as a ready-to-modify documented software example. The code in Hello Freestanding performs all the normal stuff you get with starting in main() -- you can then modify it as you see fit to reduce code size. One of the things in the freestanding example is calling alt_irq_init() as monkeyboy mentioned.

    Have fun!