-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
157 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
const std = @import("std"); | ||
const Build = std.Build; | ||
|
||
const MicroZig = @import("microzig/build"); | ||
const Target = MicroZig.Target; | ||
const Firmware = MicroZig.Firmware; | ||
|
||
fn root() []const u8 { | ||
return comptime (std.fs.path.dirname(@src().file) orelse "."); | ||
} | ||
const build_root = root(); | ||
|
||
pub fn build(b: *Build) !void { | ||
_ = b; | ||
} | ||
|
||
pub const chips = struct { | ||
pub const posix = Target{ | ||
.preferred_format = .{ .elf = {} }, | ||
.chip = chip, | ||
.hal = hal, | ||
.linker_script = .{ .none = {} }, | ||
.board = null, | ||
}; | ||
}; | ||
pub const boards = struct {}; | ||
|
||
const hal = .{ | ||
.root_source_file = .{ .cwd_relative = build_root ++ "/src/hal.zig" }, | ||
}; | ||
|
||
const chip = .{ | ||
.name = "POSIX", | ||
.url = "TODO", | ||
.cpu = .{ .name = "native-posix4", .root_source_file = .{ .path = build_root ++ "/src/startup.zig" }, .target = .{} }, | ||
.register_definition = .{ .zig = .{ .path = build_root ++ "/src/empty.zig" } }, | ||
.memory_regions = &.{}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
.{ | ||
.name = "bsp/posix", | ||
.version = "0.0.0", | ||
.dependencies = .{ | ||
.@"microzig/build" = .{ | ||
.path = "../../build", | ||
}, | ||
}, | ||
.paths = .{ | ||
"build.zig.zon", | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
pub const devices = struct { | ||
pub const POSIX = struct { | ||
// | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
const std = @import("std"); | ||
const microzig = @import("microzig"); | ||
|
||
pub fn init() void {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
pub fn disable_interrupts() void {} | ||
pub const startup_logic = struct { | ||
extern fn microzig_main() noreturn; | ||
pub fn _start() callconv(.C) noreturn { | ||
microzig_main(); | ||
} | ||
}; | ||
|
||
pub fn export_startup_logic() void {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
const std = @import("std"); | ||
const MicroZig = @import("microzig/build"); | ||
const posix = @import("microzig/bsp/posix"); | ||
|
||
const available_examples = [_]Example{ | ||
.{ .target = posix.chips.posix, .name = "posix_uart", .file = "src/uart.zig" }, | ||
}; | ||
|
||
pub fn build(b: *std.Build) void { | ||
const mz = MicroZig.init(b, .{}); | ||
const optimize = b.standardOptimizeOption(.{}); | ||
|
||
for (available_examples) |example| { | ||
|
||
// `add_firmware` basically works like addExecutable, but takes a | ||
// `microzig.Target` for target instead of a `std.zig.CrossTarget`. | ||
// | ||
// The target will convey all necessary information on the chip, | ||
// cpu and potentially the board as well. | ||
const firmware = mz.add_firmware(b, .{ | ||
.name = example.name, | ||
.target = example.target, | ||
.optimize = optimize, | ||
.root_source_file = .{ .path = example.file }, | ||
}); | ||
|
||
// `install_firmware()` is the MicroZig pendant to `Build.installArtifact()` | ||
// and allows installing the firmware as a typical firmware file. | ||
// | ||
// This will also install into `$prefix/firmware` instead of `$prefix/bin`. | ||
mz.install_firmware(b, firmware, .{}); | ||
|
||
// For debugging, we also always install the firmware as an ELF file | ||
mz.install_firmware(b, firmware, .{ .format = .elf }); | ||
} | ||
} | ||
|
||
const Example = struct { | ||
target: MicroZig.Target, | ||
name: []const u8, | ||
file: []const u8, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
.{ | ||
.name = "examples/posix", | ||
.version = "0.0.0", | ||
.dependencies = .{ | ||
.@"microzig/build" = .{ .path = "../../build" }, | ||
.@"microzig/bsp/posix" = .{ .path = "../../bsp/posix" }, | ||
}, | ||
|
||
.paths = .{ | ||
"build.zig", | ||
"build.zig.zon", | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
const std = @import("std"); | ||
const microzig = @import("microzig"); | ||
|
||
pub fn panic(message: []const u8, _: ?*std.builtin.StackTrace, _: ?usize) noreturn { | ||
std.log.err("panic: {s}", .{message}); | ||
@breakpoint(); | ||
while (true) {} | ||
} | ||
|
||
pub const microzig_options = .{ | ||
.log_level = .debug, | ||
// .logFn = rp2040.uart.log, | ||
}; | ||
|
||
pub fn main() !void {} |