aboutsummaryrefslogtreecommitdiff
path: root/include/arch/timer.h
blob: 8f235e6dd9d765c10bea494f1ce83e92627241fa (plain) (blame)
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
47
48
49
50
51
52
53
54
55
56
57
58
59
/* SPDX-License-Identifier: copyleft-next-0.3.1 */
/* Copyright 2021 - 2022, Kim Kuparinen < kimi.h.kuparinen@gmail.com > */

#ifndef KMI_ARCH_TIMER_H
#define KMI_ARCH_TIMER_H

/**
 * @file timer.h
 * Arch-specific timer handling, generally implemented in
 * arch/whatever/timer.c
 */

#include <kmi/timer.h>

#if defined(__riscv)
# if __riscv_xlen == 64
#include "../../arch/riscv64/include/timer.h"
# else
#include "../../arch/riscv32/include/timer.h"
# endif
#endif

/**
 * Get hardware timer frequency.
 *
 * @param fdt Global FDT pointer.
 * @return Hardware timer frequency, ticks/sec.
 */
ticks_t stat_timer(const void *fdt);

/**
 * Set up timer interrupt for absolute ticks.
 * At least currently assumes there is only one global timer, the kernel will
 * ensure that the timer is scheduled to handle events in order.
 *
 * When setting a new timer, the current timer (if one is set) will
 * not trigger an interrupt. For instance, if called from the interrupt handler
 * of the existing interrupt, it won't re-trigger.
 *
 * @param ticks Time point for timer to trigger.
 * \todo Should maybe be stat_t?
 */
void set_timer(ticks_t ticks);

/**
 * Stop the timer interrupts from happening altogether. Mainly called during
 * init to avoid spurious interrupts and when all userspace timers have been
 * handled.
 */
void clear_timer();

/**
 * Get current ticks.
 *
 * @return Current tick count.
 */
ticks_t current_ticks();

#endif /* KMI_ARCH_TIMER_H */