blob: 00fd6bae44fb422cfc7973ca3c7336dda75e0382 (
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
47
48
|
const interrupt = @import("interrupt.zig");
const driver_armcortex = packed struct {
enable: u1,
tickint: u1,
unused: u30,
rvr: u32,
cvr: u32,
calib: u32,
pub fn initialize(self: *driver_armcortex, freq: u32) void {
self.rvr = 4000000 / 8 / freq;
self.tickint = 1;
self.enable = 1;
}
};
var ticks_raw: u32 = 0;
fn tick() void {
ticks_raw += 1;
}
const driver = struct {
const lld_type = driver_armcortex;
lld: *driver_armcortex,
pub fn initialize(self: driver, freq: u32) void {
interrupt.register(.SysTick, tick);
self.lld.initialize(freq);
}
pub fn count(self: driver) u32 {
_ = self;
return @atomicLoad(u32, &ticks_raw, .acquire);
}
pub fn delay(self: driver, ticks: u32) void {
const now = self.count();
while (self.count() - now < ticks) {}
}
};
pub const systick = driver { .lld = @ptrFromInt(0xE000E010) };
|