Problems with NIOS II PIO interrupt

Hi, I've some trouble with NIOS II PIO interrupts and need some help. The pio port is configured as follows: Width= 2 bits Both input and output ports (not tri-state) Synchronously capture: Rising Edge IRQ= edge sensitiv

I dont want to use HAL to keep the code size small, that's why I use alt_main.

static void AudioCodecInISR(void* context, alt_u32 id) { volatile int inChL = 0; inChL = IORD_ALTERA_AVALON_PIO_EDGE_CAP(CodecIRQRegBase); /* Reset the Button's edge capture register. */ IOWR_ALTERA_AVALON_PIO_EDGE_CAP(CodecIRQRegBase, 0); }

int main (void) __attribute__ ((weak, alias ("alt_main"))); int alt_main (void) { void * context; alt_irq_init(ALT_IRQ_BASE); IOWR_ALTERA_AVALON_PIO_IRQ_MASK(CodecIRQRegBase, 0x3); /* Reset the Button's edge capture register. */ IOWR_ALTERA_AVALON_PIO_EDGE_CAP(CodecIRQRegBase, 0x0); /* Register the interrupt handler. */ alt_irq_register( CodecIRQRegBase, context, AudioCodecInISR );

while (1) { } return 0; }

Does anybody has any clue where the bug is?

Thanks, Horst

Reply to
horst
Loading thread data ...

The order of the calls after alt_irq_init() need to be reversed. In particular, you want to register the ISR before enabling interrupts.

Could you give more details on how the bug manifests? The code posted here doesn't do much of anything even if the interrupt occurs.

Mark

Reply to
nobody

Thanks for your answer.

I tried it that way

alt_irq_init(ALT_IRQ_BASE); /* Register the interrupt handler. */ alt_irq_register( CodecIRQRegBase, context, AudioCodecInISR ); IOWR_ALTERA_AVALON_PIO_IRQ_MASK(CodecIRQRegBase, 0x3); /* Reset the Button's edge capture register. */ IOWR_ALTERA_AVALON_PIO_EDGE_CAP(CodecIRQRegBase, 0x0);

but it isn't working.

You're right the code doesn't have any effect. I shortened it to post it here. I set a Breakpoint inside the ISR but the breakpoint never breaks the running debugging execution, so I know that the interrupt newer gets triggered.

Reply to
horst

The next thing I'd try is to read the edge capture and data in registers in the while loop, printing the contents when they change. That way you can drive the IRQ inputs manually and see if the signals are actually getting to the PIO.

Mark

Reply to
nobody

The signals getting to the pio and the edge capture register responds to the inputs. I really don't have any idea why the interrupt doesn't work.

Reply to
horst

Do you have the interrupt assigned to the PIO in SOPC builder?

Mark

Reply to
Mark

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.