DE1-SOC COMPUTER SYSTEM WITH NIOS II For Quartus II 15.0
/* start interval timer, enable its interrupts */
movi r15, 0b0111 /* START = 1, CONT = 1, ITO = 1 */
sthio r15, 4(r16)
/* write to the pushbutton port interrupt mask register */
movia r15, 0xFF200050 /* pushbutton key base address */
movi r7, 0b1111 /* set interrupt mask bits */
stwio r7, 8(r15) /* interrupt mask register is (base + 8) */
/* enable Nios II processor interrupts */
movi r7, 0b011 /* set interrupt mask bits for levels 0 (interval */
wrctl ienable, r7 /* timer) and level 1 (pushbuttons) */
movi r7, 1
wrctl status, r7 /* turn on Nios II interrupt processing */
IDLE:
br IDLE /* main program simply idles */
.data
/* The global variables used by the interrupt service routines for the interval timer and the
* pushbutton keys are declared below */
.global PATTERN
PATTERN:
.word 0x0000000F /* pattern to show on the HEX displays */
.global KEY_PRESSED
KEY_PRESSED:
.word KEY2 /* stores code representing pushbutton key pressed */
.global SHIFT_DIR
SHIFT_DIR:
.word 2 /* default shift direction (2 == right) */
.end
Figure 16. An example of assembly language code that uses interrupts (Part b).
The reset and exception handlers for the main program in Figure 16 are given in Figure 17. The reset handler simply
jumps to the _start symbol in the main program. The exception handler first checks if the exception that has occurred
is an external interrupt or an internal one. In the case of an internal exception, such as an illegal instruction opcode
or a trap instruction, the handler simply exits, because it does not handle these cases. For external exceptions, it
calls either the interval timer interrupt service routine, for a level 0 interrupt, or the pushbutton key interrupt service
routine for level 1. These routines are shown in Figures 18 and 19, respectively.
Altera Corporation - University Program
2015
17