summaryrefslogtreecommitdiff
path: root/kc/core/timer.h
blob: b70cd70c3eec0b90a03f5ad66eee3d3b3b7c352b (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
#pragma once
#include <stdint.h>

#define TIMER_MILLISECOND 1000ULL
#define TIMER_MICROSECOND 1000000ULL
#define TIMER_NANOSECOND 1000000000ULL

struct timer_source
{
    const char *name;
    void (*init)(void);
    void (*start)(void);
    void (*stop)(void);

    void (*set_frequency)(uint32_t frequency);
    uint32_t (*get_frequency)(void);

    uint64_t (*nanoseconds_elapsed)(void);
    uint64_t (*nanoseconds_delta)(void);
};

uint64_t timer_ticks(void);
void timer_sleep(uint64_t usec);
void timer_sleep_until(uint64_t ticks);