diff options
Diffstat (limited to 'examples/minimal.zig')
| -rw-r--r-- | examples/minimal.zig | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/examples/minimal.zig b/examples/minimal.zig new file mode 100644 index 0000000..a70f0ef --- /dev/null +++ b/examples/minimal.zig @@ -0,0 +1,42 @@ +//! The floor: the smallest thing that can boot on this chip and prove it is alive. +//! No printing, no descriptor text - just a pin that toggles. Build it with +//! zig build -Dapp=examples/minimal.zig size + +const std = @import("std"); +const config = @import("config"); +const soc = @import("soc"); + +/// Even the floor needs a panic handler: the default one formats and would pull in half of std. +pub const panic = std.debug.FullPanic(struct { + fn call(_: []const u8, _: ?usize) noreturn { + while (true) {} + } +}.call); +const led: u6 = @intCast(config.led_pin); + +export fn zig_main() noreturn { + soc.gpio.configureOutput(led); + while (true) { + soc.gpio.setHigh(led); + soc.rom.ets_delay_us(100_000); + soc.gpio.setLow(led); + soc.rom.ets_delay_us(100_000); + } +} + +export fn _start() linksection(".text.entry") callconv(.naked) noreturn { + asm volatile ( + \\ li t0, 1 << 13 + \\ csrs mstatus, t0 + \\ la sp, __stack_top + \\ la t0, __bss_start + \\ la t1, __bss_end + \\ bgeu t0, t1, 2f + \\1: + \\ sw zero, 0(t0) + \\ addi t0, t0, 4 + \\ bltu t0, t1, 1b + \\2: + \\ j zig_main + ); +} |
