From 432bc85e0fe690bc33be1e62f5e0b0f09f0595ce Mon Sep 17 00:00:00 2001 From: Matt Knight Date: Sun, 25 Feb 2024 19:43:28 -0800 Subject: [PATCH] more master changes --- bsp/nxp/lpc/src/tools/patchelf.zig | 4 +- .../rp2040/src/boards/shared/bootrom.zig | 8 +-- bsp/raspberrypi/rp2040/src/hal/pins.zig | 2 +- .../rp2040/src/hal/pio/assembler/encoder.zig | 4 +- .../src/hal/pio/assembler/tokenizer.zig | 2 +- bsp/raspberrypi/rp2040/src/hal/time.zig | 2 +- build.zig | 24 ------- build/build.zig | 4 +- core/src/cpus/avr5.zig | 6 +- core/src/cpus/cortex-m.zig | 4 +- core/src/interrupt.zig | 2 +- core/src/start.zig | 63 +++++++++++-------- tools/regz/src/gen.zig | 6 +- 13 files changed, 61 insertions(+), 70 deletions(-) diff --git a/bsp/nxp/lpc/src/tools/patchelf.zig b/bsp/nxp/lpc/src/tools/patchelf.zig index 8961bf8b6..60736f9b0 100644 --- a/bsp/nxp/lpc/src/tools/patchelf.zig +++ b/bsp/nxp/lpc/src/tools/patchelf.zig @@ -55,11 +55,11 @@ pub fn main() !u8 { var i: usize = 0; while (i < boot_sector_items - 1) : (i += 1) { - const item = try reader.readIntLittle(u32); + const item = try reader.readInt(u32, .little); checksum -%= item; } - try writer.writeIntLittle(u32, checksum); + try writer.writeInt(u32, checksum, .little); } return 0; diff --git a/bsp/raspberrypi/rp2040/src/boards/shared/bootrom.zig b/bsp/raspberrypi/rp2040/src/boards/shared/bootrom.zig index e6e32af6a..71e5e5e13 100644 --- a/bsp/raspberrypi/rp2040/src/boards/shared/bootrom.zig +++ b/bsp/raspberrypi/rp2040/src/boards/shared/bootrom.zig @@ -4,12 +4,12 @@ comptime { _ = stage2_bootloader; } -export const stage2_bootloader: [256]u8 linksection(".boot2") = prepareBootSector( +export const stage2_bootloader: [256]u8 linksection(".boot2") = prepare_boot_sector( @embedFile("bootloader"), ); -/// Create a new -fn prepareBootSector(comptime stage2_rom: []const u8) [256]u8 { +/// Create a new +fn prepare_boot_sector(comptime stage2_rom: []const u8) [256]u8 { @setEvalBranchQuota(10_000); var bootrom: [256]u8 = .{0xFF} ** 256; @@ -35,7 +35,7 @@ fn prepareBootSector(comptime stage2_rom: []const u8) [256]u8 { .xor_output = 0x00000000, }); - std.mem.writeIntLittle(u32, bootrom[252..256], Hash.hash(bootrom[0..252])); + std.mem.writeInt(u32, bootrom[252..256], Hash.hash(bootrom[0..252]), .little); return bootrom; } diff --git a/bsp/raspberrypi/rp2040/src/hal/pins.zig b/bsp/raspberrypi/rp2040/src/hal/pins.zig index 3ca323865..c17ada0f1 100644 --- a/bsp/raspberrypi/rp2040/src/hal/pins.zig +++ b/bsp/raspberrypi/rp2040/src/hal/pins.zig @@ -448,7 +448,7 @@ pub const GlobalConfiguration = struct { // validate selected function comptime { - inline for (@typeInfo(GlobalConfiguration).Struct.fields) |field| + for (@typeInfo(GlobalConfiguration).Struct.fields) |field| if (@field(config, field.name)) |pin_config| { const gpio_num = @intFromEnum(@field(Pin, field.name)); if (0 == function_table[@intFromEnum(pin_config.function)][gpio_num]) diff --git a/bsp/raspberrypi/rp2040/src/hal/pio/assembler/encoder.zig b/bsp/raspberrypi/rp2040/src/hal/pio/assembler/encoder.zig index 0d13c1b46..cc994cd3d 100644 --- a/bsp/raspberrypi/rp2040/src/hal/pio/assembler/encoder.zig +++ b/bsp/raspberrypi/rp2040/src/hal/pio/assembler/encoder.zig @@ -77,14 +77,14 @@ pub fn Encoder(comptime options: Options) type { pub fn to_exported_program(comptime bounded: BoundedProgram) assembler.Program { comptime var program_name: [bounded.name.len]u8 = undefined; - std.mem.copy(u8, &program_name, bounded.name); + std.mem.copyForwards(u8, &program_name, bounded.name); return assembler.Program{ .name = &program_name, .defines = blk: { var tmp = std.BoundedArray(assembler.Define, options.max_defines).init(0) catch unreachable; for (bounded.defines.slice()) |define| { comptime var define_name: [define.name.len]u8 = undefined; - std.mem.copy(u8, &define_name, define.name); + std.mem.copyForwards(u8, &define_name, define.name); tmp.append(.{ .name = &define_name, .value = @as(i64, @intCast(define.value)), diff --git a/bsp/raspberrypi/rp2040/src/hal/pio/assembler/tokenizer.zig b/bsp/raspberrypi/rp2040/src/hal/pio/assembler/tokenizer.zig index 2aef42830..b43f085ff 100644 --- a/bsp/raspberrypi/rp2040/src/hal/pio/assembler/tokenizer.zig +++ b/bsp/raspberrypi/rp2040/src/hal/pio/assembler/tokenizer.zig @@ -336,7 +336,7 @@ pub const Tokenizer = struct { fn get_define(self: *Tokenizer, index: u32, diags: *?Diagnostics) TokenizeError!Token { const maybe_public = try self.get_identifier(); - var is_public = eql_lower("public", maybe_public.str); + const is_public = eql_lower("public", maybe_public.str); const name = if (is_public) try self.get_identifier() diff --git a/bsp/raspberrypi/rp2040/src/hal/time.zig b/bsp/raspberrypi/rp2040/src/hal/time.zig index 6bf69323d..593235e37 100644 --- a/bsp/raspberrypi/rp2040/src/hal/time.zig +++ b/bsp/raspberrypi/rp2040/src/hal/time.zig @@ -64,7 +64,7 @@ pub fn get_time_since_boot() Absolute { var high_word = TIMER.TIMERAWH; return while (true) { - var low_word = TIMER.TIMERAWL; + const low_word = TIMER.TIMERAWL; const next_high_word = TIMER.TIMERAWH; if (next_high_word == high_word) break @as(Absolute, @enumFromInt(@as(u64, @intCast(high_word)) << 32 | low_word)); diff --git a/build.zig b/build.zig index 6c2d100a4..e57043f2c 100644 --- a/build.zig +++ b/build.zig @@ -13,7 +13,6 @@ const example_dep_names: []const []const u8 = &.{ pub fn build(b: *std.Build) void { const optimize = b.standardOptimizeOption(.{}); - buildTools(b); // Build all examples for (example_dep_names) |example_dep_name| { @@ -34,26 +33,3 @@ pub fn build(b: *std.Build) void { const package_step = b.step("package", "Package monorepo using boxzer"); package_step.dependOn(&boxzer_run.step); } - -fn buildTools(b: *std.Build) void { - const tools_step = b.step("tools", "Only build the development tools"); - b.getInstallStep().dependOn(tools_step); - - const eggzon_dep = b.dependency("eggzon", .{}); - const eggzon_mod = eggzon_dep.module("eggzon"); - - const create_build_meta = b.addExecutable(.{ - .name = "create-pkg-descriptor", - .root_source_file = .{ .path = "tools/create-pkg-descriptor.zig" }, - .optimize = .ReleaseSafe, - .target = b.host, - }); - create_build_meta.root_module.addImport("eggzon", eggzon_mod); - installTool(tools_step, create_build_meta); -} - -fn installTool(tools_step: *std.Build.Step, exe: *std.Build.Step.Compile) void { - tools_step.dependOn(&tools_step.owner.addInstallArtifact(exe, .{ - .dest_dir = .{ .override = .{ .custom = "tools" } }, - }).step); -} diff --git a/build/build.zig b/build/build.zig index 39ad38c78..72e593086 100644 --- a/build/build.zig +++ b/build/build.zig @@ -187,8 +187,8 @@ pub fn add_firmware( }, }); - const umm = mz.microzig_core.builder.dependency("umm-zig", .{}).module("umm"); - fw.modules.microzig.addImport("umm", umm); + //const umm = mz.microzig_core.builder.dependency("umm-zig", .{}).module("umm"); + //fw.modules.microzig.addImport("umm", umm); fw.artifact.root_module.addImport("app", fw.modules.app); fw.artifact.root_module.addImport("microzig", fw.modules.microzig); diff --git a/core/src/cpus/avr5.zig b/core/src/cpus/avr5.zig index 478a7d3d0..c86b936a3 100644 --- a/core/src/cpus/avr5.zig +++ b/core/src/cpus/avr5.zig @@ -36,10 +36,10 @@ pub const vector_table = blk: { if (@hasDecl(interrupts, "RESET")) @compileError("Not allowed to overload the reset vector"); - inline for (std.meta.declarations(interrupts)) |decl| { + for (std.meta.declarations(interrupts)) |decl| { if (!@hasField(microzig.chip.VectorTable, decl.name)) { var msg: []const u8 = "There is no such interrupt as '" ++ decl.name ++ "'. ISRs the 'interrupts' namespace must be one of:\n"; - inline for (std.meta.fields(microzig.chip.VectorTable)) |field| { + for (std.meta.fields(microzig.chip.VectorTable)) |field| { if (!std.mem.eql(u8, "RESET", field.name)) { msg = msg ++ " " ++ field.name ++ "\n"; } @@ -50,7 +50,7 @@ pub const vector_table = blk: { } } - inline for (std.meta.fields(microzig.chip.VectorTable)[1..]) |field| { + for (std.meta.fields(microzig.chip.VectorTable)[1..]) |field| { const new_insn = if (has_interrupts) overload: { const interrupts = root.microzig_options.interrupts; if (@hasDecl(interrupts, field.name)) { diff --git a/core/src/cpus/cortex-m.zig b/core/src/cpus/cortex-m.zig index b9b582897..4baec1bc1 100644 --- a/core/src/cpus/cortex-m.zig +++ b/core/src/cpus/cortex-m.zig @@ -128,12 +128,12 @@ pub var vector_table: VectorTable = blk: { if (@typeInfo(interrupts) != .Struct) @compileLog("root.interrupts must be a struct"); - inline for (@typeInfo(interrupts).Struct.decls) |decl| { + for (@typeInfo(interrupts).Struct.decls) |decl| { const function = @field(interrupts, decl.name); if (!@hasField(VectorTable, decl.name)) { var msg: []const u8 = "There is no such interrupt as '" ++ decl.name ++ "'. Declarations in 'interrupts' must be one of:\n"; - inline for (std.meta.fields(VectorTable)) |field| { + for (std.meta.fields(VectorTable)) |field| { if (is_valid_field(field.name)) { msg = msg ++ " " ++ field.name ++ "\n"; } diff --git a/core/src/interrupt.zig b/core/src/interrupt.zig index 1be5c91d7..a675d105e 100644 --- a/core/src/interrupt.zig +++ b/core/src/interrupt.zig @@ -40,7 +40,7 @@ pub fn globally_enabled() bool { /// Enters a critical section and disables interrupts globally. /// Call `.leave()` on the return value to restore the previous state. pub fn enter_critical_section() CriticalSection { - var section = CriticalSection{ + const section = CriticalSection{ .enable_on_leave = globally_enabled(), }; disable_interrupts(); diff --git a/core/src/start.zig b/core/src/start.zig index 7271ad29d..ad7d86d54 100644 --- a/core/src/start.zig +++ b/core/src/start.zig @@ -16,32 +16,45 @@ else // defined. Parts of microzig use the stdlib logging facility and // compilations will now fail on freestanding systems that use it but do // not explicitly set `root.std_options.logFn` -pub usingnamespace if (!@hasDecl(app, "std_options")) - struct { - pub const std_options = struct { - pub fn logFn( - comptime message_level: std.log.Level, - comptime scope: @Type(.EnumLiteral), - comptime format: []const u8, - args: anytype, - ) void { - _ = message_level; - _ = scope; - _ = format; - _ = args; - } - }; - } -else - struct { - comptime { - // Technically the compiler's errors should be good enough that we - // shouldn't include errors like this, but since we add default - // behavior we should clarify the situation for the user. - if (!@hasDecl(app.std_options, "logFn")) - @compileError("By default MicroZig provides a no-op logging function. Since you are exporting `std_options`, you must export the stdlib logging function yourself."); + +pub const std_options = .{ + .logFn = struct { + fn log( + comptime message_level: std.log.Level, + comptime scope: @Type(.EnumLiteral), + comptime format: []const u8, + args: anytype, + ) void { + _ = message_level; + _ = scope; + _ = format; + _ = args; } - }; + }.log, +}; + +//pub usingnamespace if (!@hasDecl(app, "std_options")) +// struct { +// pub const std_options = std.Options{ +// .logFn = struct { +// fn log( +// comptime message_level: std.log.Level, +// comptime scope: @Type(.EnumLiteral), +// comptime format: []const u8, +// args: anytype, +// ) void { +// _ = message_level; +// _ = scope; +// _ = format; +// _ = args; +// } +// }.log, +// }; +// } +//else +// struct { +// pub const std_options = app.std_options; +// }; // Startup logic: comptime { diff --git a/tools/regz/src/gen.zig b/tools/regz/src/gen.zig index b7c8b58be..e66a40c0c 100644 --- a/tools/regz/src/gen.zig +++ b/tools/regz/src/gen.zig @@ -990,14 +990,16 @@ test "gen.peripheral with modes" { \\ { \\ const value = self.TEST_MODE1.COMMON_REGISTER.read().TEST_FIELD; \\ switch (value) { - \\ 0 => return .TEST_MODE1, + \\ 0, + \\ => return .TEST_MODE1, \\ else => {}, \\ } \\ } \\ { \\ const value = self.TEST_MODE2.COMMON_REGISTER.read().TEST_FIELD; \\ switch (value) { - \\ 1 => return .TEST_MODE2, + \\ 1, + \\ => return .TEST_MODE2, \\ else => {}, \\ } \\ }