Skip to content

Commit

Permalink
more master changes
Browse files Browse the repository at this point in the history
  • Loading branch information
mattnite committed Feb 26, 2024
1 parent 3b9c542 commit 432bc85
Show file tree
Hide file tree
Showing 13 changed files with 61 additions and 70 deletions.
4 changes: 2 additions & 2 deletions bsp/nxp/lpc/src/tools/patchelf.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions bsp/raspberrypi/rp2040/src/boards/shared/bootrom.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
2 changes: 1 addition & 1 deletion bsp/raspberrypi/rp2040/src/hal/pins.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
4 changes: 2 additions & 2 deletions bsp/raspberrypi/rp2040/src/hal/pio/assembler/encoder.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand Down
2 changes: 1 addition & 1 deletion bsp/raspberrypi/rp2040/src/hal/pio/assembler/tokenizer.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion bsp/raspberrypi/rp2040/src/hal/time.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
24 changes: 0 additions & 24 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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| {
Expand All @@ -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);
}
4 changes: 2 additions & 2 deletions build/build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions core/src/cpus/avr5.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
Expand All @@ -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)) {
Expand Down
4 changes: 2 additions & 2 deletions core/src/cpus/cortex-m.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/interrupt.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
63 changes: 38 additions & 25 deletions core/src/start.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 4 additions & 2 deletions tools/regz/src/gen.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {},
\\ }
\\ }
Expand Down

0 comments on commit 432bc85

Please sign in to comment.