commit fc147bd13d0e1850703542bc73cf4f06f39b4b9b
parent c68ab508f8259acdb1757731aa6dcdc551b30e97
Author: Sylvia Ivory <git@sivory.net>
Date: Thu, 12 Mar 2026 19:22:39 -0700
Delete old labs
Diffstat:
7 files changed, 0 insertions(+), 413 deletions(-)
diff --git a/src/labs/2-gpio.zig b/src/labs/2-gpio.zig
@@ -1,101 +0,0 @@
-const std = @import("std");
-
-const gpio = @import("../devices/gpio.zig");
-
-const led0 = 20;
-const led1 = 21;
-const led2 = 27;
-const act = 47;
-
-// TODO; replace with actual cycles
-fn delay_cycles(count: usize) void {
- for (0..count) |_| {
- std.atomic.spinLoopHint();
- }
-}
-
-pub fn blink_1() !void {
- try gpio.set_output(led0);
-
- for (0..10) |_| {
- try gpio.set_on(led0);
- delay_cycles(1000000);
-
- try gpio.set_off(led0);
- delay_cycles(1000000);
- }
-
- try gpio.set_on(led0);
-}
-
-pub fn blink_2() !void {
- try gpio.set_output(led0);
- try gpio.set_output(led1);
-
- for (0..10) |_| {
- try gpio.set_on(led0);
- try gpio.set_off(led1);
- delay_cycles(3000000);
-
- try gpio.set_off(led0);
- try gpio.set_on(led1);
- delay_cycles(3000000);
- }
-}
-
-pub fn loopback() !void {
- const input = 9;
- const output = 10;
-
- try gpio.set_output(led0);
- try gpio.set_input(input);
- try gpio.set_output(led1);
- try gpio.set_output(output);
-
- var v = false;
- for (0..20) |_| {
- try gpio.write(led0, v);
- try gpio.write(output, v);
- try gpio.write(led1, try gpio.read(input));
-
- delay_cycles(1500000);
- v = !v;
- }
-}
-
-pub fn act_blink() !void {
- try gpio.set_output(act);
-
- for (0..10) |_| {
- try gpio.set_on(act);
- delay_cycles(1000000);
-
- try gpio.set_off(act);
- delay_cycles(1000000);
- }
-
- try gpio.set_on(act);
-}
-
-pub fn all() !void {
- try gpio.set_output(led0);
- try gpio.set_output(led1);
- try gpio.set_output(led2);
- try gpio.set_output(act);
-
- for (0..10) |_| {
- try gpio.set_on(led0);
- try gpio.set_on(led1);
- try gpio.set_on(led2);
- try gpio.set_off(act);
- delay_cycles(1000000);
-
- try gpio.set_off(led0);
- try gpio.set_off(led1);
- try gpio.set_off(led2);
- try gpio.set_on(act);
- delay_cycles(1000000);
- }
-
- try gpio.set_on(act);
-}
diff --git a/src/labs/4-measure.zig b/src/labs/4-measure.zig
@@ -1,32 +0,0 @@
-const std = @import("std");
-const pi = @import("pi");
-
-const uart = @import("../devices/mini-uart.zig");
-const clock = @import("../devices/clock.zig");
-
-pub fn main() !void {
- try uart.initialize(115200, .Gpio14, .Gpio15);
- pi.cycle_counter_init();
-
- const start = pi.cycle_counter_read();
-
- const s = clock.current_count();
- while ((clock.current_count() - s) < 1000 * 1000) {}
-
- const end = pi.cycle_counter_read();
- const total = end - start;
-
- var buffer: [1024]u8 = undefined;
-
- {
- const slice = try std.fmt.bufPrint(&buffer, "cycles per second = {}\n", .{total});
- uart.write_slice(slice);
- }
-
- const exp = 700 * 1000 * 1000;
-
- {
- const slice = try std.fmt.bufPrint(&buffer, "expected - measured = {} cycles of error\n", .{exp - total});
- uart.write_slice(slice);
- }
-}
diff --git a/src/labs/4-profiler.zig b/src/labs/4-profiler.zig
@@ -1,55 +0,0 @@
-const std = @import("std");
-const interrupts = @import("pi").interrupts;
-
-const uart = @import("devices/mini-uart.zig");
-const clock = @import("devices/clock.zig");
-const timer = @import("devices/timer.zig");
-
-// 1Mb
-var buffer: [1024 * 1024]u8 = undefined;
-var fba: std.heap.FixedBufferAllocator = undefined;
-var hist: std.AutoHashMap(usize, usize) = undefined;
-var enabled = true;
-
-extern const __code_start__: u32;
-extern const __code_end__: u32;
-
-fn tick(pc: usize) void {
- if (!enabled) return;
-
- const res = hist.getOrPutValue(pc, 0) catch unreachable;
- const new_value = res.value_ptr.* + 1;
-
- hist.put(pc, new_value) catch unreachable;
-}
-
-fn dump(min: usize) void {
- enabled = false;
- uart.writer.print("call profile:\n", .{}) catch {};
- var iterator = hist.iterator();
-
- while (iterator.next()) |entry| {
- if (entry.value_ptr.* < min) continue;
- uart.writer.print(" 0x{X}: {d}\n", .{ entry.key_ptr.*, entry.value_ptr.* }) catch {};
- }
- enabled = true;
-}
-
-pub fn main() !void {
- timer.initialize(.Sixteen, 0x100);
- timer.set_tick(tick);
-
- fba = .init(&buffer);
- hist = .init(fba.allocator());
-
- interrupts.enable_interrupts();
-
- var iter: usize = 0;
- while (timer.get_count() < 200) {
- try uart.writer.print("iter={d}: count = {d}, period = {d}us, 0x{x}\n", .{ iter, timer.get_count(), timer.get_period(), timer.get_period() });
- iter += 1;
- if (iter % 10 == 0) {
- dump(2);
- }
- }
-}
diff --git a/src/labs/4-syscall-1.zig b/src/labs/4-syscall-1.zig
@@ -1,72 +0,0 @@
-const pi = @import("pi");
-
-const uart = @import("devices/mini-uart.zig");
-
-comptime {
- asm (
- \\ .global syscall_hello;
- \\ .type syscall_hello, %function;
- \\ syscall_hello:
- \\ push {lr}
- \\ swi 1
- \\ pop {lr}
- \\ bx lr
- \\
- \\ .global syscall_illegal;
- \\ .type syscall_illegal, %function;
- \\ syscall_illegal:
- \\ push {lr}
- \\ swi 2
- \\ pop {lr}
- \\ bx lr
- );
-}
-
-extern fn syscall_hello(msg: *const u8) i32;
-extern fn syscall_illegal() i32;
-
-const Syscall = packed struct(u32) {
- num: u24,
- _: u4,
- cond: u4,
-};
-
-export fn syscall_handler(pc: u32, r0: u32) i32 {
- const syscall: Syscall = @bitCast(pi.mem.get_u32(@ptrFromInt(pc)));
-
- uart.writer.print("instruction=0x{X}, number={d}\n", .{ @as(u32, @bitCast(syscall)), syscall.num }) catch {};
-
- switch (syscall.num) {
- 1 => {
- uart.write_slice("syscall: ");
- const str: [*]const u8 = @ptrFromInt(r0);
- var i: usize = 0;
-
- while (str[i] != 0) {
- uart.write_byte(str[i]);
- i += 1;
- }
-
- return 0;
- },
- else => {
- uart.writer.print("illegal system call: {d}!\n", .{syscall.num}) catch {};
- return -1;
- },
- }
-}
-
-pub fn main() !void {
- try uart.writer.print("current stack pointer = 0x{x}\n", .{pi.get_sp()});
-
- pi.interrupts.set_software_interrupt(syscall_handler);
- pi.interrupts.enable_interrupts();
-
- try uart.writer.print("running syscall hello\n", .{});
- const res_hello = syscall_hello(@ptrCast("hello world!\n"));
- try uart.writer.print("result of calling syscall: {d}\n", .{res_hello});
-
- try uart.writer.print("running illegal call\n", .{});
- const res_illegal = syscall_illegal();
- try uart.writer.print("result of illegal syscall: {d}\n", .{res_illegal});
-}
diff --git a/src/labs/4-syscall-2.zig b/src/labs/4-syscall-2.zig
@@ -1,78 +0,0 @@
-const pi = @import("pi");
-
-const uart = @import("devices/mini-uart.zig");
-
-comptime {
- asm (
- \\ .global syscall_hello;
- \\ .type syscall_hello, %function;
- \\ syscall_hello:
- \\ push {lr}
- \\ swi 1
- \\ pop {lr}
- \\ bx lr
- \\
- \\ .global syscall_illegal;
- \\ .type syscall_illegal, %function;
- \\ syscall_illegal:
- \\ push {lr}
- \\ swi 2
- \\ pop {lr}
- \\ bx lr
- );
-}
-
-extern fn syscall_hello(msg: *const u8) i32;
-extern fn syscall_illegal() i32;
-
-const Syscall = packed struct(u32) {
- num: u24,
- _: u4,
- cond: u4,
-};
-
-export fn syscall_handler(pc: u32, r0: u32) i32 {
- const syscall: Syscall = @bitCast(pi.mem.get_u32(@ptrFromInt(pc)));
-
- uart.writer.print("instruction=0x{X}, number={d}\n", .{ @as(u32, @bitCast(syscall)), syscall.num }) catch {};
-
- const spsr = pi.cpsr.get_s();
- uart.writer.print("saved spsr mode = {t}\n", .{spsr.mode}) catch {};
-
- switch (syscall.num) {
- 1 => {
- uart.write_slice("syscall: ");
- const str: [*]const u8 = @ptrFromInt(r0);
- var i: usize = 0;
-
- while (str[i] != 0) {
- uart.write_byte(str[i]);
- i += 1;
- }
-
- return 0;
- },
- else => {
- uart.writer.print("illegal system call: {d}!\n", .{syscall.num}) catch {};
- return -1;
- },
- }
-}
-
-pub fn main() !void {
- // Switch to user
- var cpsr = pi.cpsr.get();
- cpsr.mode = .User;
- pi.cpsr.set(cpsr);
-
- try uart.writer.print("current stack pointer = 0x{x}\n", .{pi.get_sp()});
- try uart.writer.print("current cpsr mode = {t}\n", .{cpsr.mode});
-
- try uart.writer.print("running syscall hello\n", .{});
- const res_hello = syscall_hello(@ptrCast("hello world!\n"));
- try uart.writer.print("result of calling syscall: {d}\n", .{res_hello});
-
- try uart.writer.print("running illegal call\n", .{});
- const res_illegal = syscall_illegal();
- try uart.writer.print("result of illegal syscall: {d}\n", .{res_illegal});
-}
diff --git a/src/labs/4-timer.zig b/src/labs/4-timer.zig
@@ -1,44 +0,0 @@
-const interrupts = @import("pi").interrupts;
-
-const uart = @import("devices/mini-uart.zig");
-const clock = @import("devices/clock.zig");
-const timer = @import("devices/timer.zig");
-
-pub fn main() !void {
- try uart.writer.print("entered main safely...\n", .{});
-
- timer.initialize(.Sixteen, 0x100);
-
- try uart.writer.print("initialized timer...\n", .{});
-
- interrupts.enable_interrupts();
-
- try uart.writer.print("enabled interrupts...\n", .{});
-
- const start = clock.current_count();
- var iter: u32 = 0;
- const N = 20;
-
- while (timer.get_count() < N) {
- try uart.writer.print("iter={d}: count={d}, time between interrupts = {d} usec (0x{x})\n", .{
- iter,
- timer.get_count(),
- timer.get_period(),
- timer.get_period(),
- });
- iter += 1;
- }
-
- const total = clock.current_count() - start;
- const total_sec = total / (1000 * 1000);
- const total_ms = (total / 1000) % 10000;
- const total_us = (total % 1000);
-
- try uart.writer.print(
- \\ total iterations: {}
- \\ total interrupts: {}
- \\ iterations / interrupt: {}
- \\ average period: {}
- \\ total execution time: {}s.{}ms.{}us
- , .{ iter, N, iter / N, timer.get_period_sum() / (N - 1), total_sec, total_ms, total_us });
-}
diff --git a/src/labs/5-coroutine.zig b/src/labs/5-coroutine.zig
@@ -1,31 +0,0 @@
-const std = @import("std");
-
-const uart = @import("devices/mini-uart.zig");
-const Tasks = @import("tasks.zig");
-
-export fn syscall_handler() void {}
-
-fn thread_test(scheduler: *Tasks, arg: ?*anyopaque) callconv(.c) void {
- _ = arg;
-
- while (true) {
- uart.writer.print("in thread tid={d}!\n", .{scheduler.get_tid()}) catch {};
- scheduler.yield();
- }
-}
-
-pub fn main() !void {
- var buffer: [1024 * 1024]u8 = undefined;
- var fba: std.heap.FixedBufferAllocator = .init(&buffer);
-
- var scheduler = Tasks.new(fba.allocator());
-
- try scheduler.fork(thread_test, null);
- try scheduler.fork(thread_test, null);
- try scheduler.fork(thread_test, null);
- try scheduler.fork(thread_test, null);
- try scheduler.fork(thread_test, null);
- try scheduler.fork(thread_test, null);
-
- try scheduler.join();
-}