Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
13 years ago

Generating PS2 Interrupts

Hi,

I am trying to write a simple interrupt service routine for interrupts from a PS2 mouse on a DE2 board, but the following assembly code never executes the ISR. I am quite certain that the code is correct but I can't figure out why I am not catching any interrupts. Any advice is appreciated.

Regards.

 
.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
No RepliesBe the first to reply