Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
The goal of this lesson is to become familiar with writing interrupt handling
routines. We will be writing our code in the high level language, C, based on a
provided template.
The software…
Go to http://www.cs.duke.edu/courses/spring07/cps104/Altera/Local/interrupts.c and
open the file. (Later we’ll run this code on the DE2 board).
This file utilizes infrastructure already provided by Altera for interrupt/exception
handling on the NiosII. Specifically, the macros IORD... and IOWR… provide support
for reading and writing to specific devices. These take care of mapping to specific offsets
required to access the different registers of the PIO devices. In the end these translated to
ldwio and stwio instructions with the appropriate address (pointer) arithmetic required to
access the correct register for the PIO device. (For the curios these macros are defined in
the file C:\altera\61\ip\nios2_ip\altera_nios2\HAL\inc\io.h
The source file, interrupts.c has five functions defined: main, initial_message,
init_button_pio, handle_button_interrupts, and handle_interrupt. We’ll talk about each of
these briefly. On item to note is that a constant BUTTON_PIO_BASE is used in several
places. This value is defined in the include file system.h a copy of this is at
http://www.cs.duke.edu/courses/spring07/cps104/Altera/Local/system.h
You can use the following macro to write to the Red LEDs.
IOWR_ALTERA_AVALON_PIO_DATA(LED_RED_BASE, value);
In this case value is a 32-bit integer where each bit maps to the LED to light up. E.g., if
value contains 0x10 LED 4 would be enabled. If the direction is right to left, then after
LED 0 is enabled, the next LED to light up should be LED 16
while( 1 )
{
usleep(100000);
/* some of your code goes here */
}
A final question: Is your code always correct? If yes, prove it. If not,
why not?
See me with your answer.