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++

about interrupt

Altera_Forum
Honored Contributor II
1,627 Views

I don't know how to use interrupt correctlly.Can anybody help me?

0 Kudos
6 Replies
Altera_Forum
Honored Contributor II
861 Views

Hello yoland, 

 

Please give some more details about what you want to do and which system are using? It is necessary to know if you are using Nios, Nios II, RTOS, Linux, … 

 

 

Bye, 

niosIIuser
0 Kudos
Altera_Forum
Honored Contributor II
861 Views

I use nios2 .And I build a system with a on-chip ram and a key . I want to servise an interrupt from the key. 

the following is my code:# include "system.h"# include "altera_avalon_pio_regs.h"# include "alt_types.h"# include "altera_avalon_uart_regs.h"# include "sys/alt_irq.h" 

 

volatile int edge_capture; 

 

 

static void handle_key_interrupt(void* context,alt_u32 id) 

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

// IOWR_ALTERA_AVALON_PIO_EDGE_CAP(KEY_PIO_BASE); 

IOWR_ALTERA_AVALON_PIO_IRQ_MASK(KEY_PIO_BASE, 0xf); 

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. */ 

void* edge_capture_ptr = (void*) &edge_capture; 

/* Enable all 4 button interrupts. */ 

IOWR_ALTERA_AVALON_PIO_IRQ_MASK(KEY_PIO_BASE, 0x1); 

/* Reset the edge capture register. */ 

IOWR_ALTERA_AVALON_PIO_EDGE_CAP(KEY_PIO_BASE, 0x0); 

/* Register the interrupt handler. */ 

alt_irq_register( KEY_PIO_IRQ, edge_capture_ptr, 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;  

# ifdef KEY_PIO_BASE 

init_key_pio();# endif 

 

i=alt_irq_enabled(); 

IOWR_ALTERA_AVALON_PIO_DATA(LED_PIO_BASE, 0xf0); 

while (1)  

 

}  

return 0; 

}
0 Kudos
Altera_Forum
Honored Contributor II
861 Views

Hello yoland, 

 

Ok, now tell us your problem please. Does the code not work or not work correctly? Which behaviour is incorrect? 

 

 

Bye, 

niosIIuser
0 Kudos
Altera_Forum
Honored Contributor II
861 Views

Hello niosIIuser 

 

I set the interrupt,but it can't response,that is when i press the key,it couldn't generate an irq. 

1. i=alt_irq_enabled(); why the value 'i' is always zero. 

2.static void handle_key_interrupt(void* context,alt_u32 id); can't access to this ISR function 

 

THANKS
0 Kudos
Altera_Forum
Honored Contributor II
861 Views

Hello yoland, 

 

Try the following code if you would like that your LED register is changing from 0xf0 to 0x55 after pressing the button. Please tell me the state of your LED register after executing the code. 

# 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(KEY_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(KEY_PIO_BASE, 0x1); 

/* Reset the edge capture register. */ 

IOWR_ALTERA_AVALON_PIO_EDGE_CAP(KEY_PIO_BASE, 0x0); 

/* Register the interrupt handler. */ 

alt_irq_register( KEY_PIO_IRQ, NULL, 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; 

}
0 Kudos
Altera_Forum
Honored Contributor II
861 Views

thanks. 

I will see the handbook and hope find the way to solve it.
0 Kudos
Reply