Forum Discussion
28 Replies
- Altera_Forum
Honored Contributor
I'm having the same problem. I found an App note about it that deals with the original Nios but the examples in it are not that good.
It appears that the HAL already has support for interrupts but I can't figure out how to actually use it. As a side not if anyone knows how to use the hardware handshaking I would like to know. Thanks - Altera_Forum
Honored Contributor
Chapter 6 of the Nios II Software Developer's Handbook is entitled Exception Handling and should help you.
- Altera_Forum
Honored Contributor
Hi!
I've write small program with interrupt handler. I can't see the result ot ISR. May be somebody can explain my errors. char uval=0; ALTERA_AVALON_UART_INSTANCE( UART_0, uart_0 ); //---------------------------------------------------------------------------- void isr (void* context, alt_u32 id) { uval++; IOWR_ALTERA_AVALON_PIO_DATA( PIO_1_BASE ,uval); } //---------------------------------------------------------------------------- int main() { char vv=1; alt_sys_init(); alt_irq_register( UART_0_IRQ, &uart_0 , isr ); alt_irq_enabled(); while(1) { } return 0; } - Altera_Forum
Honored Contributor
Kira,
There are a few things wrong with this code: 1. You should not be calling alt_sys_init in main. This has already been called before main gets called. Given that this function initialises hardware calling it twice might have unwanted results. 2. You are registerring for the IRQ belonging to the UART. I strongly suspect that you already have a driver in your system for the UART with it's own interrupt handler so I'm not surprised that your ISR is not getting called. 3. I'm not sure why you called alt_irq_enabled this only tells you if interrupts are enabled and as you do nothing with this result the call is not very useful. - Altera_Forum
Honored Contributor
Ok! I see. But there is another problem: what kind of steps I must do to enable interrupts, to define intterrupt handler? May be I must setup UART control register manually?
Thank you. - Altera_Forum
Honored Contributor
Kira,
You seem to be confused. There is no need for you to write an interrupt handler for the UART, one already exists in the UART driver. If you wish to write an interrupt handler for another piece of hardware your code should be fine if remove the errors I highlighted in my previous post. You should also read the documentation which can be found in the Nios II Software Developers Handbook, there is an entire section on Exception Handling including an entire section on ISRs from page 6-5 onwards. - Altera_Forum
Honored Contributor
hello
I also have the problem about interrupt. I want to service an interrupt from the key PIO. I see the example project such as "count_binary",and the program i write is same as the example.but there is no jump into my ISR when I press the key. when debuging ,i read the register only ienable=1, the status and the ipending register is always zero. THANKS. - Altera_Forum
Honored Contributor
I presume you are talking about register values read from within the interrupt handler.
Within the exception handler the value of status will be 0 because its value has been zeroed by the exception. Its previous value is in estatus. As for ipending, unfortunately there is a bug in version 1.0 of the Nios II kit which means that the debugger incorrectly displays ipending as zero when single stepping. This is fixed in 1.1. To work around this you should set a breakpoint and continue - the correct value of ipending will be displayed. - Altera_Forum
Honored Contributor
Hi again!
I'm sorry, may be I described my problem unclear. So I'll try again. I looked through HAL files, there are following files, which define all uart functions: altera_avalon_uart.h and (*.c), altera_avalon_uart_regs.h and (*.c). How can I use functions from these files - alt_avalon_uart_irq and e.t? I just want to catch the moment, when UART receives data - rxdata. How can I do it using interrupt handler or something else way? Thank you - Altera_Forum
Honored Contributor
code:
unsigned char val=0; /---------------------------------------------------------------------------- static void handle_uart_interrupt (void* context, alt_u32 id) { uval++; IOWR_ALTERA_AVALON_PIO_DATA( PIO_0_BASE ,uval); } //---------------------------------------------------------------------------- //static alt_avalon_uart_dev gS;; int main() { IOWR_ALTERA_AVALON_UART_CONTROL ( UART_0_BASE, 0x180); alt_irq_register( UART_0_IRQ , &uart_0, handle_uart_interrupt ); return 0; }