aboutsummaryrefslogtreecommitdiff
path: root/debug/programs/interrupt.c
blob: 847644ca4fd2293c30d0e5a0c45a6a8594be3a9e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include "init.h"
#include "encoding.h"

static volatile unsigned interrupt_count;
static volatile unsigned local;
static volatile unsigned keep_running;

static unsigned delta = 0x100;
void *increment_count(unsigned hartid, unsigned mcause, void *mepc, void *sp)
{
    interrupt_count++;
    // There is no guarantee that the interrupt is cleared immediately when
    // MTIMECMP is written, so stick around here until that happens.
    while (read_csr(mip) & MIP_MTIP) {
        MTIMECMP[hartid] = MTIME + delta;
    }
    return mepc;
}

int main()
{
    interrupt_count = 0;
    local = 0;
    keep_running = 1;
    unsigned hartid = read_csr(mhartid);

    set_trap_handler(increment_count);
    MTIMECMP[hartid] = MTIME - 1;
    enable_timer_interrupts();

    while (keep_running) {
        local++;
    }
    return 10;
}