summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--software/first/setup_timer_irq.S14
1 files changed, 10 insertions, 4 deletions
diff --git a/software/first/setup_timer_irq.S b/software/first/setup_timer_irq.S
index 6c75d67..8ca0370 100644
--- a/software/first/setup_timer_irq.S
+++ b/software/first/setup_timer_irq.S
@@ -60,6 +60,11 @@ irq_handler:
sw t3, 8(sp) # save temporary
sw a0, 4(sp) # save first argument to function
+ li t0, 0x80000007 # irqcause + 7 (machine timer interrupt)
+ csrr t1, mcause # load cause CSR
+ and t1, t1, t0 # check if it's a timer interrupt
+ bne t1, t0, exit
+
li t0, GPIO_CTRL_ADDR # load base GPIO address
lw t1, GPIO_OUTPUT_VAL(t0) # load state
@@ -74,22 +79,23 @@ irq_handler:
switchOnRed:
li t2, GPIO_RED_LED # load value indicating red LED
- j exit
+ j setAndexit
switchOnBlue:
li t2, GPIO_BLUE_LED # load value indicating blue LED
- j exit
+ j setAndexit
switchOnGreen:
li t2, GPIO_GREEN_LED # load value indicating green LED
- j exit
+ j setAndexit
-exit:
+setAndexit:
sw t2, GPIO_OUTPUT_VAL(t0) # write new LED values to the right address
li a0, 200 # load the desired delay value (in ms) as the first arg to the function
jal delay # call delay function to set new delay
+exit:
lw ra, 24(sp) # load return address
lw t0, 20(sp) # restore temporary
lw t1, 16(sp) # restore temporary