aboutsummaryrefslogtreecommitdiff
path: root/mirai/drivers/pit/handler.zig
blob: 4d3d3b06ec3915be5f11b4bb7a713f060310c62a (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
//! PIT IRQ Handler

const constants = @import("constants.zig");
const pic = @import("../../interrupts/pic/pic.zig");
const idt = @import("../../interrupts/idt.zig");

var ticks: u64 = 0;
var tick_callback: ?*const fn () void = null;

pub fn handler(_: u8) void {
    ticks += 1;

    if (tick_callback) |callback| {
        callback();
    }

    pic.send_eoi(constants.irq);
}

pub fn register() void {
    idt.register_irq(constants.irq, &handler);
    pic.enable_irq(constants.irq);
}

pub fn set_callback(callback: *const fn () void) void {
    tick_callback = callback;
}

pub fn clear_callback() void {
    tick_callback = null;
}

pub fn get_ticks() u64 {
    return ticks;
}