summaryrefslogtreecommitdiff
path: root/bsp/qemu-virt64-aarch64/drivers/drv_timer.c
blob: 99eaa7b18c7144dae3a9c4ec3dc4769d7862b63a (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
36
37
38
39
40
41
42
43
44
45
46
/*
 * Copyright (c) 2006-2022, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2018-11-22     Jesven       first version
 */

#include <rthw.h>
#include <rtthread.h>
#include <stdint.h>
#include "cp15.h"
#include "board.h"
#include "gtimer.h"

#define TIMER_IRQ   30

static rt_uint64_t timerStep = 0;

static void rt_hw_timer_isr(int vector, void *param)
{
    rt_hw_set_gtimer_val(timerStep);
    rt_tick_increase();
}

void rt_hw_timer_enable(void)
{
    rt_hw_set_gtimer_val(timerStep);
    rt_hw_interrupt_umask(TIMER_IRQ);
    rt_hw_gtimer_enable();
}

int rt_hw_timer_init(void)
{
    rt_hw_interrupt_install(TIMER_IRQ, rt_hw_timer_isr, RT_NULL, "tick");
    __ISB();
    timerStep = rt_hw_get_gtimer_frq();
    __DSB();
    timerStep /= RT_TICK_PER_SECOND;
    rt_hw_timer_enable();

    return 0;
}
INIT_BOARD_EXPORT(rt_hw_timer_init);