How to solve this timer interrupt problem

18 views
Skip to first unread message

Xavier Barreto Tomeo

unread,
May 7, 2024, 12:00:00 PMMay 7
to RISC-V SW Dev
Hi! 
Im doing a project in RISC-V and im trying to enable timer interrupts and make a simple code running on it. I have this code that is called from a .c file and it returns to it and stays in while(1)
timern:
la t0, timer_handler
csrw mtvec, t0
csrw stvec, t0
csrs mstatus, 0x8
li t0, 0x80
csrs mie, t0
li t0, 500000
li t1, 0x2004000 #mtimecmp address
sd t0, 0(t1)
ret

timer_handler:
li t1, 0x2004000 #mtimecmp address
lw t0, 0(t1)
li t2, 500000
add t0, t0, t2
sd t0, 0(t1)
j writehello
ret

I try to make a program that every 500000 writes hello with a function that works correctly but it only says hello the first time and doesnt return correctly to the execution. 
I have tried to write with 0x00 the register mip in the handler or in the main but it seems it doesnt work
Can some one help me please?
Thanks!
Reply all
Reply to author
Forward
0 new messages