summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSilvan Jegen <s.jegen@gmail.com>2019-08-17 17:54:22 +0200
committerSilvan Jegen <s.jegen@gmail.com>2019-08-17 17:54:22 +0200
commit6502be88d94aa1d5e3949832c12f47deb8329a4c (patch)
treee38e2217a1c8cede4ff53c4949937f401ffe185e
parent8fd7e5e623647866db88b632347261e5d9f30da1 (diff)
Call delay in ISR
-rw-r--r--software/first/setup_timer_irq.S31
1 files changed, 18 insertions, 13 deletions
diff --git a/software/first/setup_timer_irq.S b/software/first/setup_timer_irq.S
index 97b5f6c..c3e7513 100644
--- a/software/first/setup_timer_irq.S
+++ b/software/first/setup_timer_irq.S
@@ -13,7 +13,7 @@ setup_timer_irq:
csrw mtvec, t0 # write handler address and mode
# Here we cannot use csrsi because it can only set up to 5 bits
- li t0, 0x80 # set 7th bit (indexed from 0)
+ li t0, 0x88 # set 4rd and 8th bit
csrw mie, t0 # activate machine timer interrupt
# write high value to the timercmp just to be sure we don't
@@ -51,12 +51,13 @@ setup_timer_irq:
irq_handler:
# save only the registers we use in this function
- addi sp, sp, -24 # Allocate stack frame
- sw ra, 20(sp) # save return address to the stack
- sw t0, 16(sp) # save temporary
- sw t1, 12(sp) # save temporary
- sw t2, 8(sp) # save temporary
- sw t3, 4(sp) # save temporary
+ addi sp, sp, -28 # Allocate stack frame
+ sw ra, 24(sp) # save return address to the stack
+ sw t0, 20(sp) # save temporary
+ sw t1, 16(sp) # save temporary
+ sw t2, 12(sp) # save temporary
+ sw t3, 8(sp) # save temporary
+ sw a0, 4(sp) # save first argument to function
li t0, GPIO_CTRL_ADDR # load base GPIO address
lw t1, GPIO_OUTPUT_VAL(t0) # load state
@@ -85,10 +86,14 @@ switchOnGreen:
exit:
sw t2, GPIO_OUTPUT_VAL(t0) # write new LED values to the right address
- lw ra, 20(sp) # load return address
- lw t0, 16(sp) # restore temporary
- lw t1, 12(sp) # restore temporary
- lw t2, 8(sp) # restore temporary
- lw t3, 4(sp) # restore temporary
- addi sp, sp, 24 # deallocate stack frame
+ 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
+
+ lw ra, 24(sp) # load return address
+ lw t0, 20(sp) # restore temporary
+ lw t1, 16(sp) # restore temporary
+ lw t2, 12(sp) # restore temporary
+ lw t3, 8(sp) # restore temporary
+ lw a0, 4(sp) # restore first argument to function
+ addi sp, sp, 28 # deallocate stack frame
mret # exit IRQ handler