Freshen things up (#6)

* catch up to some of master's changes, getting prepped to anchor to 0.9.0

* found fix for lpc board
wch-ch32v003
Matthew Knight 3 years ago committed by GitHub
parent 2a6bedfcca
commit af7aa777f9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,28 @@
name: Build
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
schedule:
- cron: "0 7 * * *"
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
submodules: recursive
fetch-depth: 0
# only using master until 0.9.0 is released
- name: Setup Zig
uses: goto-bus-stop/setup-zig@v1.3.0
with:
version: master
- name: Build tests
run: zig build -Drelease-small

@ -4,17 +4,17 @@
const std = @import("std"); const std = @import("std");
pub fn build(b: *std.build.Builder) void { pub fn build(b: *std.build.Builder) !void {
const mode = b.standardReleaseOptions(); const mode = b.standardReleaseOptions();
const test_step = b.step("test", "Builds and runs the library test suite"); const test_step = b.step("test", "Builds and runs the library test suite");
const BuildConfig = struct { name: []const u8, backing: Backing }; const BuildConfig = struct { name: []const u8, backing: Backing };
const all_backings = [_]BuildConfig{ const all_backings = [_]BuildConfig{
BuildConfig{ .name = "boards.arduino_nano", .backing = Backing{ .board = pkgs.boards.arduino_nano } }, //BuildConfig{ .name = "boards.arduino_nano", .backing = Backing{ .board = pkgs.boards.arduino_nano } },
BuildConfig{ .name = "boards.mbed_lpc1768", .backing = Backing{ .board = pkgs.boards.mbed_lpc1768 } }, BuildConfig{ .name = "boards.mbed_lpc1768", .backing = Backing{ .board = pkgs.boards.mbed_lpc1768 } },
BuildConfig{ .name = "chips.atmega328p", .backing = Backing{ .chip = pkgs.chips.atmega328p } }, //BuildConfig{ .name = "chips.atmega328p", .backing = Backing{ .chip = pkgs.chips.atmega328p } },
BuildConfig{ .name = "chips.lpc1768", .backing = Backing{ .chip = pkgs.chips.lpc1768 } }, //BuildConfig{ .name = "chips.lpc1768", .backing = Backing{ .chip = pkgs.chips.lpc1768 } },
}; };
const Test = struct { name: []const u8, source: []const u8 }; const Test = struct { name: []const u8, source: []const u8 };
@ -28,7 +28,7 @@ pub fn build(b: *std.build.Builder) void {
inline for (all_backings) |cfg| { inline for (all_backings) |cfg| {
inline for (all_tests) |tst| { inline for (all_tests) |tst| {
const exe = addEmbeddedExecutable( const exe = try addEmbeddedExecutable(
b, b,
"test-" ++ tst.name ++ "-" ++ cfg.name, "test-" ++ tst.name ++ "-" ++ cfg.name,
tst.source, tst.source,
@ -45,12 +45,12 @@ pub fn build(b: *std.build.Builder) void {
} }
} }
fn addEmbeddedExecutable(builder: *std.build.Builder, name: []const u8, source: []const u8, backing: Backing) *std.build.LibExeObjStep { fn addEmbeddedExecutable(builder: *std.build.Builder, name: []const u8, source: []const u8, backing: Backing) !*std.build.LibExeObjStep {
const Pkg = std.build.Pkg; const Pkg = std.build.Pkg;
const microzig_base = Pkg{ const microzig_base = Pkg{
.name = "microzig", .name = "microzig",
.path = "src/core/microzig.zig", .path = .{ .path = "src/core/microzig.zig" },
}; };
const chip = switch (backing) { const chip = switch (backing) {
@ -62,18 +62,18 @@ fn addEmbeddedExecutable(builder: *std.build.Builder, name: []const u8, source:
const chip_package = Pkg{ const chip_package = Pkg{
.name = "chip", .name = "chip",
.path = chip.path, .path = .{ .path = chip.path },
.dependencies = &[_]Pkg{ .dependencies = &[_]Pkg{
microzig_base, microzig_base,
pkgs.mmio, pkgs.mmio,
Pkg{ Pkg{
.name = "cpu", .name = "cpu",
.path = chip.cpu.path, .path = .{ .path = chip.cpu.path },
.dependencies = &[_]Pkg{ microzig_base, pkgs.mmio }, .dependencies = &[_]Pkg{ microzig_base, pkgs.mmio },
}, },
Pkg{ Pkg{
.name = "microzig-linker", .name = "microzig-linker",
.path = "src/modules/linker/linker.zig", .path = .{ .path = "src/modules/linker/linker.zig" },
}, },
}, },
}; };
@ -96,11 +96,11 @@ fn addEmbeddedExecutable(builder: *std.build.Builder, name: []const u8, source:
const file_suffix = ".ld"; const file_suffix = ".ld";
var ld_file_name: [file_prefix.len + 2 * hash.len + file_suffix.len]u8 = undefined; var ld_file_name: [file_prefix.len + 2 * hash.len + file_suffix.len]u8 = undefined;
const filename = std.fmt.bufPrint(&ld_file_name, "{s}{}{s}", .{ const filename = try std.fmt.bufPrint(&ld_file_name, "{s}{}{s}", .{
file_prefix, file_prefix,
std.fmt.fmtSliceHexLower(&hash), std.fmt.fmtSliceHexLower(&hash),
file_suffix, file_suffix,
}) catch unreachable; });
break :blk builder.dupe(filename); break :blk builder.dupe(filename);
}; };
@ -128,44 +128,46 @@ fn addEmbeddedExecutable(builder: *std.build.Builder, name: []const u8, source:
const file_suffix = ".zig"; const file_suffix = ".zig";
var ld_file_name: [file_prefix.len + 2 * hash.len + file_suffix.len]u8 = undefined; var ld_file_name: [file_prefix.len + 2 * hash.len + file_suffix.len]u8 = undefined;
const filename = std.fmt.bufPrint(&ld_file_name, "{s}{}{s}", .{ const filename = try std.fmt.bufPrint(&ld_file_name, "{s}{}{s}", .{
file_prefix, file_prefix,
std.fmt.fmtSliceHexLower(&hash), std.fmt.fmtSliceHexLower(&hash),
file_suffix, file_suffix,
}) catch unreachable; });
break :blk builder.dupe(filename); break :blk builder.dupe(filename);
}; };
{ {
var config_file = std.fs.cwd().createFile(config_file_name, .{}) catch unreachable; std.fs.cwd().makeDir(std.fs.path.dirname(config_file_name).?) catch {};
var config_file = try std.fs.cwd().createFile(config_file_name, .{});
defer config_file.close(); defer config_file.close();
var writer = config_file.writer(); var writer = config_file.writer();
try writer.print("pub const has_board = {};\n", .{has_board});
if (has_board)
try writer.print("pub const board_name = .@\"{}\";\n", .{std.fmt.fmtSliceEscapeUpper(backing.board.name)});
writer.print("pub const has_board = {};\n", .{has_board}) catch unreachable; try writer.print("pub const chip_name = .@\"{}\";\n", .{std.fmt.fmtSliceEscapeUpper(chip.name)});
if (has_board) { try writer.print("pub const cpu_name = .@\"{}\";\n", .{std.fmt.fmtSliceEscapeUpper(chip.cpu.name)});
writer.print("pub const board_name = .@\"{}\";\n", .{std.fmt.fmtSliceEscapeUpper(backing.board.name)}) catch unreachable;
}
writer.print("pub const chip_name = .@\"{}\";\n", .{std.fmt.fmtSliceEscapeUpper(chip.name)}) catch unreachable;
writer.print("pub const cpu_name = .@\"{}\";\n", .{std.fmt.fmtSliceEscapeUpper(chip.cpu.name)}) catch unreachable;
} }
const config_pkg = Pkg{ const config_pkg = Pkg{
.name = "microzig-config", .name = "microzig-config",
.path = config_file_name, .path = .{ .path = config_file_name },
}; };
const build_options = builder.addOptions();
build_options.addOption([]const u8, "microzig_chip_name", chip.name);
build_options.addOption([]const u8, "microzig_cpu_name", chip.cpu.name);
build_options.addOption([]const u8, "microzig_target_triple", try chip.cpu.target.zigTriple(builder.allocator));
const linkerscript_gen = builder.addExecutable("linkerscript-gen", "src/tools/linkerscript-gen.zig"); const linkerscript_gen = builder.addExecutable("linkerscript-gen", "src/tools/linkerscript-gen.zig");
linkerscript_gen.addPackage(chip_package); linkerscript_gen.addPackage(chip_package);
linkerscript_gen.addPackage(Pkg{ linkerscript_gen.addPackage(Pkg{
.name = "microzig-linker", .name = "microzig-linker",
.path = "src/modules/linker/linker.zig", .path = .{ .path = "src/modules/linker/linker.zig" },
}); });
linkerscript_gen.addBuildOption([]const u8, "microzig_chip_name", chip.name); linkerscript_gen.addOptions("build_options", build_options);
linkerscript_gen.addBuildOption([]const u8, "microzig_cpu_name", chip.cpu.name);
linkerscript_gen.addBuildOption([]const u8, "microzig_target_triple", chip.cpu.target.zigTriple(builder.allocator) catch unreachable);
const linkerscript_invocation = linkerscript_gen.run(); const linkerscript_invocation = linkerscript_gen.run();
linkerscript_invocation.addArg(linker_script_name); linkerscript_invocation.addArg(linker_script_name);
@ -177,7 +179,7 @@ fn addEmbeddedExecutable(builder: *std.build.Builder, name: []const u8, source:
exe.single_threaded = true; exe.single_threaded = true;
exe.setTarget(chip.cpu.target); exe.setTarget(chip.cpu.target);
exe.setLinkerScriptPath(linker_script_name); exe.setLinkerScriptPath(.{ .path = linker_script_name });
exe.step.dependOn(&linkerscript_invocation.step); exe.step.dependOn(&linkerscript_invocation.step);
// TODO: // TODO:
@ -185,7 +187,7 @@ fn addEmbeddedExecutable(builder: *std.build.Builder, name: []const u8, source:
// - This requires building another tool that runs on the host that compiles those files and emits the linker script. // - This requires building another tool that runs on the host that compiles those files and emits the linker script.
// - src/tools/linkerscript-gen.zig is the source file for this // - src/tools/linkerscript-gen.zig is the source file for this
// exe.bundle_compiler_rt = false; exe.bundle_compiler_rt = false;
switch (backing) { switch (backing) {
.chip => { .chip => {
@ -204,7 +206,7 @@ fn addEmbeddedExecutable(builder: *std.build.Builder, name: []const u8, source:
chip_package, chip_package,
Pkg{ Pkg{
.name = "board", .name = "board",
.path = board.path, .path = .{ .path = board.path },
.dependencies = &[_]Pkg{ microzig_base, chip_package, pkgs.mmio }, .dependencies = &[_]Pkg{ microzig_base, chip_package, pkgs.mmio },
}, },
}, },
@ -241,7 +243,7 @@ pub const Backing = union(enum) {
const pkgs = struct { const pkgs = struct {
const mmio = std.build.Pkg{ const mmio = std.build.Pkg{
.name = "microzig-mmio", .name = "microzig-mmio",
.path = "src/core/mmio.zig", .path = .{ .path = "src/core/mmio.zig" },
}; };
const cpus = struct { const cpus = struct {
@ -264,7 +266,7 @@ const pkgs = struct {
.cpu_arch = .arm, .cpu_arch = .arm,
.cpu_model = .{ .explicit = &std.Target.arm.cpu.cortex_m3 }, .cpu_model = .{ .explicit = &std.Target.arm.cpu.cortex_m3 },
.os_tag = .freestanding, .os_tag = .freestanding,
.abi = .eabi, .abi = .none,
}, },
}; };
}; };

@ -19,6 +19,7 @@ pub fn busySleep(comptime limit: comptime_int) void {
const DebugErr = error{}; const DebugErr = error{};
fn writerWrite(ctx: void, string: []const u8) DebugErr!usize { fn writerWrite(ctx: void, string: []const u8) DebugErr!usize {
_ = ctx;
write(string); write(string);
return string.len; return string.len;
} }
@ -26,10 +27,9 @@ fn writerWrite(ctx: void, string: []const u8) DebugErr!usize {
const DebugWriter = std.io.Writer(void, DebugErr, writerWrite); const DebugWriter = std.io.Writer(void, DebugErr, writerWrite);
pub fn write(string: []const u8) void { pub fn write(string: []const u8) void {
if (!micro.config.has_board) if (!micro.config.has_board and !@hasDecl(micro.board, "debugWrite"))
return;
if (!@hasDecl(micro.board, "debugWrite"))
return; return;
micro.board.debugWrite(string); micro.board.debugWrite(string);
} }

@ -102,6 +102,7 @@ pub fn Gpio(comptime pin: type, config: anytype) type {
// open drain // open drain
fn setDrive(drive: Drive) void { fn setDrive(drive: Drive) void {
_ = drive;
@compileError("open drain not implemented yet!"); @compileError("open drain not implemented yet!");
} }
fn getDrive() Drive { fn getDrive() Drive {

@ -4,16 +4,19 @@ const micro = @import("microzig.zig");
/// Unmasks the given interrupt and enables its execution. /// Unmasks the given interrupt and enables its execution.
/// Note that interrupts must be globally enabled with `sei()` as well. /// Note that interrupts must be globally enabled with `sei()` as well.
pub fn enable(comptime interrupt: anytype) void { pub fn enable(comptime interrupt: anytype) void {
_ = interrupt;
@compileError("not implemented yet!"); @compileError("not implemented yet!");
} }
/// Masks the given interrupt and disables its execution. /// Masks the given interrupt and disables its execution.
pub fn disable(comptime interrupt: anytype) void { pub fn disable(comptime interrupt: anytype) void {
_ = interrupt;
@compileError("not implemented yet!"); @compileError("not implemented yet!");
} }
/// Returns true when the given interrupt is unmasked. /// Returns true when the given interrupt is unmasked.
pub fn isEnabled(comptime interrupt: anytype) bool { pub fn isEnabled(comptime interrupt: anytype) bool {
_ = interrupt;
@compileError("not implemented yet!"); @compileError("not implemented yet!");
} }

@ -174,6 +174,7 @@ pub fn Uart(comptime index: usize) type {
} }
pub fn canWrite(self: Self) bool { pub fn canWrite(self: Self) bool {
_ = self;
return switch (UARTn.LSR.read().THRE) { return switch (UARTn.LSR.read().THRE) {
.VALID => true, .VALID => true,
.THR_IS_EMPTY_ => false, .THR_IS_EMPTY_ => false,
@ -185,6 +186,7 @@ pub fn Uart(comptime index: usize) type {
} }
pub fn canRead(self: Self) bool { pub fn canRead(self: Self) bool {
_ = self;
return switch (UARTn.LSR.read().RDR) { return switch (UARTn.LSR.read().RDR) {
.EMPTY => false, .EMPTY => false,
.NOTEMPTY => true, .NOTEMPTY => true,

@ -31,7 +31,7 @@ const PLL = struct {
.FLASHTIM = @intToEnum(@TypeOf(micro.chip.registers.SYSCON.FLASHCFG.read().FLASHTIM), @intCast(u4, timing - 1)), .FLASHTIM = @intToEnum(@TypeOf(micro.chip.registers.SYSCON.FLASHCFG.read().FLASHTIM), @intCast(u4, timing - 1)),
}); });
} }
fn feed_pll() callconv(.Inline) void { inline fn feed_pll() void {
micro.chip.registers.SYSCON.PLL0FEED.write(.{ .PLL0FEED = 0xAA }); micro.chip.registers.SYSCON.PLL0FEED.write(.{ .PLL0FEED = 0xAA });
micro.chip.registers.SYSCON.PLL0FEED.write(.{ .PLL0FEED = 0x55 }); micro.chip.registers.SYSCON.PLL0FEED.write(.{ .PLL0FEED = 0x55 });
} }
@ -109,6 +109,7 @@ pub fn main() !void {
var out = debug_port.writer(); var out = debug_port.writer();
var in = debug_port.reader(); var in = debug_port.reader();
_ = in;
try out.writeAll("Please enter a sentence:\r\n"); try out.writeAll("Please enter a sentence:\r\n");

Loading…
Cancel
Save