1

I am trying to generate PS/2 interrupts on a DE2 board with a Nios II processor. The following assembly language code is a very simple interrupt service routine, but it never gets executed. I have checked and checked the code and I can't figure out the problem. Attached is a link to the PS/2 interface.

NIOS II PS/2 Documentation

.text

.global _start

_start:

  .equ ADDR_PS2, 0x10000100
  .equ ADDR_PS2_CONTROL, 0x10000104

  /* Enable interrupts for PS2 by writing to bit 0 of the control register */
  movia r2, ADDR_PS2_CONTROL
  movia r3, 0x1
  stw r3, (r2)

  /* Set the PIE bit */
  movia r2, 0x1
  wrctl ctl0, r2

  /* Configure ienable: PS2 IRQ = 7 */
  movia r2, 0x80
  wrctl ienable, r2

  MAIN:
    br MAIN

  .section .exceptions, "ax"

  ISR:
    subi sp, sp, 56
    stw r14, 52(sp)
    stw r13, 48(sp)
    stw r12, 44(sp)
    stw r11, 40(sp)
    stw r10, 36(sp)
    stw r9, 32(sp)
    stw r8, 28(sp)
    stw r7, 24(sp)
    stw r6, 20(sp)
    stw r5, 16(sp)
    stw r4, 12(sp)
    stw r3, 8(sp)
    stw r2, 4(sp)
    stw r1, 0(sp)
    rdctl r2, ipending
    movia r3, 0x80
    and r2, r2, r3
    bne r0, r2, PS2_HANDLER
    br ISR_RETURN

 PS2_HANDLER:
   /* Acknowledge the interrupt */
   movia r2, ADDR_PS2
   ldb r3, (r2)

   /* Turn on the green LEDs */
   .equ ADDR_GREEN_LEDS, 0x10000010
   movia r2, ADDR_GREEN_LEDS
   movi  r3, 0xff
   stwio r3, (r2)

   /* Wait for a moment */
   movia r2, 25000000
   PS2_WAIT:
   subi r2, r2, 1
   bne r0, r2, PS2_WAIT

   /* Turn off the green LEDs */
   movia r2, ADDR_GREEN_LEDS
   movi  r3, 0x0
   stwio r3, (r2)
   br ISR_RETURN

 ISR_RETURN:
   ldw r14, 52(sp)
   ldw r13, 48(sp)
   ldw r12, 44(sp)
   ldw r11, 40(sp)
   ldw r10, 36(sp)
   ldw r9, 32(sp)
   ldw r8, 28(sp)
   ldw r7, 24(sp)
   ldw r6, 20(sp)
   ldw r5, 16(sp)
   ldw r4, 12(sp)
   ldw r3, 8(sp)
   ldw r2, 4(sp)
   ldw r1, 0(sp)
   addi sp, sp, 56
   subi ea, ea, 4
   eret
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Schemer
  • 1,635
  • 4
  • 19
  • 39

0 Answers0