July 22nd, 2010

Deal With NIOS II – Interrupt

Application Note, by ITead.

5 Interrupt

5.1 Intro

In this chapter we will introduce the hardware interrupt of NIOS II and the online debug method either.

Before this, we should know some about the hardware interrupt of NIOS II. ISR(Interrupt Service Routine) is the routine that for hardware interrupt. NIOS II support 32 interrupts, each one match an ISR. When the interrupt happened, interrupt handler will call the corresponding ISR for it.

Here we need to do two things first:

1. Enroll the ISR, its function:

Int alt_irq_register(alt_u32 id, void* context, void(*handler) (void*,alt_u32));

id: Interrupt Priority, configure the ISR for which priority interrupt .We have auto assign the interrupt priority in chapter one.

image002

 

The assigned IRQ is shown below:

image003

Next we talk about Contex and Handler:

Context: ISR register transfer parameters

Handler: ISR interrupt service function pointer

If the return value is 0, it means enroll interrupt success, if return negative,

2. Write the ISR function.

void ISR_handler( void* context, alt_u32 id );

contex: Parameter to ISR

id: Interrupt Priority

5.2 Hardware

We build a PIO module for the button first. You can find this section in previous chapter.

Open the Quartus II, double click the KERNEL, enter SOPC BUILDER. Here we can build a PIO module. Input 1 on the position 1, because we just need 1 button (there are 5 buttons in Black Gold). Choose Input ports only at position 2, and press Next button.

image004

And enter a new interface, we select the General IRQ where marked 2.Leave other selection as default. There are two types of interrupt: level and edge. If you need the edge interrupt, you need to select the Synchronously capture marked 1.

Press the Finish button, the PIO module finished.

image005

Go on to modify the name, here we named it KEY as marked 1.See the position 2, we can find two 0 interrupt, they are jtag_uart and the KEY we build.

image006

To modify the Interrupt Priority, we auto assign the interrupt again, now we can see the KEY change to 1.

image007

Compile it again, and go back to Quartus. Here we add the pin for KEY. We named it KEY[4], it’s the middle button on the Black Gold. Note that NIOS just can catch the high level.

image008

If you want to use the low level interrupt, you need to add a Non-gate before your pin. Double click the position where is blank, and fill the not in the Name marked below, you can get a non-gate.

image009

Assign pins, compile it again.

5.3 Software

Open the NIOS II 9.0 IDE, compile it first. We can see the change in system.h. The extra content below is for KEY, and position 1 is home address, position 2 is interrupt.

image010

Add something in the sopc.h now. It’s the same as last chapter.

………… omission  …………

Download the complete chapter of <<Deal with NIOS II>> here:

  Deal with NIOS II -- Interrupt (607.8 KiB, 479 hits)

You may also be interested in these posts:

  1. Deal With NIOS II — Software Developing
  2. Deal with NIOS II — Build the project and NIOS core
  3. Deal With NIOS II — Download code into Black Gold
  4. Deal With NIOS II – GPIO Operation: Drive LEDs
  5. Deal with NIOS II – Compiling NIOS II Core

Back Top

Responses to “Deal With NIOS II – Interrupt”

  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Back Top


SEO Powered by Platinum SEO from Techblissonline