info.zig (2603B)
1 const std = @import("std"); 2 const pi = @import("pi"); 3 4 const uart = pi.devices.mini_uart; 5 const mailbox = pi.devices.mailbox; 6 const clock = pi.devices.clock; 7 8 fn benchmark(iters: u32) !void { 9 const start: i64 = pi.cycle_counter_read(); 10 11 const s = clock.current_count(); 12 while ((clock.current_count() - s) < 1000 * 1000) {} 13 14 const end: i64 = pi.cycle_counter_read(); 15 16 try uart.writer.print(" cycles per second = {d}\n", .{end - start}); 17 uart.flush(); 18 19 var buffer: [1024 * 1024]u8 = .{0} ** (1024 * 1024); 20 for (0..buffer.len) |i| { 21 buffer[i] = @truncate(i % 256); 22 } 23 24 const now = clock.current_count(); 25 26 for (0..iters) |_| { 27 std.mem.doNotOptimizeAway(std.hash.Crc32.hash(&buffer)); 28 } 29 30 try uart.writer.print(" Crc32 1Mb * {d} = {D}\n", .{ iters, (clock.current_count() - now) * 1000 }); 31 uart.flush(); 32 } 33 34 pub fn main() !void { 35 const serial_number = try mailbox.get_serial_number(); 36 const memory_info = try mailbox.get_arm_memory_info(); 37 const board_model = try mailbox.get_board_model(); 38 const board_revision = try mailbox.get_board_revision(); 39 const temperature = try mailbox.get_temperature(.ARM); 40 const clock_current = try mailbox.get_clock_rate(.ARM, .Current); 41 const clock_real = try mailbox.get_clock_rate(.ARM, .Real); 42 const clock_min = try mailbox.get_clock_rate(.ARM, .Min); 43 const clock_max = try mailbox.get_clock_rate(.ARM, .Max); 44 45 try uart.writer.print("serial number: {d}\n", .{serial_number}); 46 uart.flush(); 47 48 try uart.writer.print("memory size: {d}\n", .{memory_info.memory_size}); 49 uart.flush(); 50 51 try uart.writer.print("memory base address: 0x{X}\n", .{memory_info.base_address}); 52 uart.flush(); 53 54 try uart.writer.print("board model: {d}\n", .{board_model}); 55 uart.flush(); 56 57 try uart.writer.print("board revision: {X}\n", .{board_revision}); 58 uart.flush(); 59 60 try uart.writer.print("temperature: {d}C\n", .{temperature / 1000}); 61 uart.flush(); 62 63 try uart.writer.print("clock current: {d}hz\n", .{clock_current}); 64 uart.flush(); 65 66 try uart.writer.print("clock real: {d}hz\n", .{clock_real}); 67 uart.flush(); 68 69 try uart.writer.print("clock min: {d}hz\n", .{clock_min}); 70 uart.flush(); 71 72 try uart.writer.print("clock max: {d}hz\n", .{clock_max}); 73 uart.flush(); 74 75 try uart.writer.print("before overclock:\n", .{}); 76 uart.flush(); 77 78 try benchmark(10); 79 80 _ = try mailbox.set_clock_rate(.ARM, 1_000_000_000, true); 81 82 try uart.writer.print("after overclock:\n", .{}); 83 uart.flush(); 84 85 try benchmark(10); 86 }