systick driver

main
Clyne 3 months ago
parent 64df2e9f31
commit 294cf13209
Signed by: clyne
GPG Key ID: 3267C8EBF3F9AFC7

@ -1,5 +1,5 @@
const vector_table_type = [256] *const fn () void; const vector_table_type = [256] *const fn () void;
var vector_table: vector_table_type = undefined; var vector_table: vector_table_type align(256) = undefined;
var vtor: **volatile vector_table_type = @ptrFromInt(0xE000ED08); var vtor: **volatile vector_table_type = @ptrFromInt(0xE000ED08);
pub const vector = enum(u8) { pub const vector = enum(u8) {

@ -1,6 +1,7 @@
const cpu = @import("cpu.zig"); const cpu = @import("cpu.zig");
const gpio = @import("gpio.zig"); const gpio = @import("gpio.zig");
const interrupt = @import("interrupt.zig"); const interrupt = @import("interrupt.zig");
const timer = @import("timer.zig");
const rcc: *[39]u32 = @ptrFromInt(0x40021000); const rcc: *[39]u32 = @ptrFromInt(0x40021000);
const gpioa = gpio.gpioa; const gpioa = gpio.gpioa;
@ -10,6 +11,7 @@ export fn _start() callconv(.C) noreturn {
cpu.interrupt_disable(); cpu.interrupt_disable();
interrupt.initialize(); interrupt.initialize();
interrupt.register(.SVCall, svcall); interrupt.register(.SVCall, svcall);
timer.initialize(1000);
cpu.interrupt_enable(); cpu.interrupt_enable();
rcc[19] |= 5; // gpio a and c rcc[19] |= 5; // gpio a and c
@ -17,7 +19,12 @@ export fn _start() callconv(.C) noreturn {
gpioc.set_mode(13, .input); gpioc.set_mode(13, .input);
while (true) { while (true) {
asm volatile("svc 0"); //asm volatile("svc 0");
gpioa.toggle(5);
const next = timer.ticks() + 1000;
while (timer.ticks() < next) {
asm volatile("nop");
}
} }
} }

@ -0,0 +1,31 @@
const interrupt = @import("interrupt.zig");
const sys_tick_type = packed struct {
enable: u1,
tickint: u1,
unused: u30,
rvr: u32,
cvr: u32,
calib: u32,
};
var sys_tick: *volatile sys_tick_type = @ptrFromInt(0xE000E010);
pub var ticks_raw: u32 = 0;
pub fn initialize(freq: u32) void {
interrupt.register(.SysTick, tick);
sys_tick.rvr = 4000000 / 8 / freq;
sys_tick.tickint = 1;
sys_tick.enable = 1;
}
fn tick() void {
ticks_raw += 1;
}
pub fn ticks() u32 {
return @atomicLoad(u32, &ticks_raw, .acquire);
}
Loading…
Cancel
Save