-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathintblink.zig
More file actions
32 lines (28 loc) · 795 Bytes
/
intblink.zig
File metadata and controls
32 lines (28 loc) · 795 Bytes
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
const std = @import("std.zig");
const avr = @import("atmega328p.zig");
const led_pin: u8 = 5;
const loop_ms = 0x0a52;
const one_second = 63974;
fn bit(comptime b: u3) comptime u8 {
return (1 << b);
}
fn flipLed() void {
avr.portb.* ^= bit(led_pin);
}
// Timer interrupt
// When this uses callconv(.Interrupt) llvm emits an extra sei
// instruction. The callconv(.Signal) avoids that.
export fn __vector_13() callconv(.Signal) void {
flipLed();
avr.tcnt1.* = one_second;
}
export fn main() noreturn {
avr.ddrb.* = bit(led_pin);
avr.portb.* = bit(led_pin);
avr.tcnt1.* = one_second;
avr.tccr1a.* = 0;
avr.tccr1b.* = bit(0) | bit(2); // clock select: clkio/1024
avr.timsk1.* = bit(0); // Interrupt on overflow enable
avr.sei();
while (true) {}
}