Programmable Devices
CPLDs, FPGAs, SoC FPGAs, Configuration, and Transceivers
21611 Discussions

Interruption problem with buttons

Altera_Forum
Honored Contributor II
1,530 Views

Hello, 

 

I have a problem generating interruptions. I had a design which was working with buttons on pooling. I then changed conditions in SOPC and put synchronously capture on rising edge and generate irq on edge. The number of my irq is 1. I compiled my design again and put the following program which was on the NIOS II forum.  

when I press a button, nothing changes and the Nios console keeps displaying "main runing..." 

Did I forget something in Quartus II for handling interruptions? 

 

Thank you, 

 

Myriam 

 

 

Program : 

# include <stdio.h># include "sys/alt_irq.h" 

 

 

static void my_isr(void* context, alt_u32 id) 

int* button = (int *)context; 

if( id == 1 ) //test interruption id 

*button = 1; 

else 

*button = 0; 

 

int main(){ 

 

alt_u32 id = 1; 

volatile int button=0; 

 

printf("start:\n"); 

alt_irq_register( id, (void*)&button, my_isr ); 

 

while(1){ 

if(button!=0) 

printf("exception runing...\n"); 

button=0; 

else  

printf("main runing...\n"); 

return 0; 

}
0 Kudos
3 Replies
Altera_Forum
Honored Contributor II
616 Views

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

}
0 Kudos
Altera_Forum
Honored Contributor II
616 Views

Hello, 

 

For your first program you missed to acknowledge the interruption. So you have to write on the edgecapture register in the ISR. 

 

You can find more information on this in the Quartus II Handbook Volume 5 : Embedded Peripherals. In the section I.9. page 9-6 and 9-7. 

 

Jérôme
0 Kudos
Altera_Forum
Honored Contributor II
616 Views

It's working. Thank you !

0 Kudos
Reply