From 6502be88d94aa1d5e3949832c12f47deb8329a4c Mon Sep 17 00:00:00 2001 From: Silvan Jegen Date: Sat, 17 Aug 2019 17:54:22 +0200 Subject: Call delay in ISR --- software/first/setup_timer_irq.S | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) (limited to 'software/first') 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 -- cgit v1.2.3