Test debugging code with interrupts.
[riscv-tests.git] / debug / programs / interrupt.c
1 #include "init.h"
2 #include "encoding.h"
3
4 static volatile unsigned interrupt_count;
5 static volatile unsigned local;
6
7 static unsigned delta = 0x100;
8 void *increment_count(unsigned hartid, unsigned mcause, void *mepc, void *sp)
9 {
10 interrupt_count++;
11 // There is no guarantee that the interrupt is cleared immediately when
12 // MTIMECMP is written, so stick around here until that happens.
13 while (csr_read(mip) & MIP_MTIP) {
14 MTIMECMP[hartid] = MTIME + delta;
15 }
16 return mepc;
17 }
18
19 int main()
20 {
21 interrupt_count = 0;
22 local = 0;
23 unsigned hartid = csr_read(mhartid);
24
25 set_trap_handler(increment_count);
26 MTIMECMP[hartid] = MTIME - 1;
27 enable_timer_interrupts();
28
29 while (1) {
30 local++;
31 }
32 }