Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++
12688 Discussions

Interruption problem with buttons

Altera_Forum
Honored Contributor II
989 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 I adapted from the program provided by Atlera (count_binary). 

when I press a button, 3 leds light on which corresponds to the default case of my function handle_button_press. 

Did I forget something in Quartus II for handling interruptions? 

 

Please help ! 

 

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
0 Replies
Reply