Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
mattnite authored Feb 4, 2025
2 parents bb009ba + bbb0b2d commit 58365fd
Show file tree
Hide file tree
Showing 7 changed files with 177 additions and 28 deletions.
13 changes: 3 additions & 10 deletions port/raspberrypi/rp2xxx/build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,14 @@ pub fn init(dep: *std.Build.Dependency) Self {
.cpu_arch = .thumb,
.cpu_model = .{ .explicit = &std.Target.arm.cpu.cortex_m33 },
.os_tag = .freestanding,
.abi = .eabi,
.abi = .eabihf,
},
.register_definition = .{ .svd = b.path("src/chips/rp2350.svd") },
.memory_regions = &.{
.{ .kind = .flash, .offset = 0x10000000, .length = 2048 * 1024 },
.{ .kind = .ram, .offset = 0x20000000, .length = 256 * 1024 },
},
.patches = @import("patches/rp2350.zig").patches,
.patches = @import("patches/rp2350_arm.zig").patches,
},
.hal = hal,
.linker_script = b.path("rp2350_arm.ld"),
Expand Down Expand Up @@ -105,14 +105,7 @@ pub fn init(dep: *std.Build.Dependency) Self {
.{ .kind = .flash, .offset = 0x10000000, .length = 256 },
.{ .kind = .ram, .offset = 0x20000000, .length = 256 * 1024 },
},
.patches = &.{
.{
.override_arch = .{
.device_name = "RP2350",
.arch = .hazard3,
},
},
},
.patches = @import("patches/rp2350_riscv.zig").patches,
},
.hal = hal,
.linker_script = b.path("rp2350_riscv.ld"),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
pub const patches = &.{
.{
.add_enum = .{
.parent = "types.peripherals.USB_DPRAM",
.@"enum" = .{
.name = "EndpointType",
.bitsize = 2,
.fields = &.{
.{ .value = 0x0, .name = "control" },
.{ .value = 0x1, .name = "isochronous" },
.{ .value = 0x2, .name = "bulk" },
.{ .value = 0x3, .name = "interrupt" },
},
.{ .add_enum = .{
.parent = "types.peripherals.USB_DPRAM",
.@"enum" = .{
.name = "EndpointType",
.bitsize = 2,
.fields = &.{
.{ .value = 0x0, .name = "control" },
.{ .value = 0x1, .name = "isochronous" },
.{ .value = 0x2, .name = "bulk" },
.{ .value = 0x3, .name = "interrupt" },
},
},
},
} },
.{ .set_enum_type = .{ .of = "types.peripherals.USB_DPRAM.EP1_IN_CONTROL.ENDPOINT_TYPE", .to = "types.peripherals.USB_DPRAM.EndpointType" } },
.{ .set_enum_type = .{ .of = "types.peripherals.USB_DPRAM.EP1_OUT_CONTROL.ENDPOINT_TYPE", .to = "types.peripherals.USB_DPRAM.EndpointType" } },
.{ .set_enum_type = .{ .of = "types.peripherals.USB_DPRAM.EP2_IN_CONTROL.ENDPOINT_TYPE", .to = "types.peripherals.USB_DPRAM.EndpointType" } },
Expand Down Expand Up @@ -44,4 +42,49 @@ pub const patches = &.{
.{ .set_enum_type = .{ .of = "types.peripherals.USB_DPRAM.EP14_OUT_CONTROL.ENDPOINT_TYPE", .to = "types.peripherals.USB_DPRAM.EndpointType" } },
.{ .set_enum_type = .{ .of = "types.peripherals.USB_DPRAM.EP15_IN_CONTROL.ENDPOINT_TYPE", .to = "types.peripherals.USB_DPRAM.EndpointType" } },
.{ .set_enum_type = .{ .of = "types.peripherals.USB_DPRAM.EP15_OUT_CONTROL.ENDPOINT_TYPE", .to = "types.peripherals.USB_DPRAM.EndpointType" } },
.{ .add_interrupt = .{
.device_name = "RP2350",
.idx = 40,
.name = "PROC0_IRQ_CTI",
} },
.{ .add_interrupt = .{
.device_name = "RP2350",
.idx = 41,
.name = "PROC1_IRQ_CTI",
} },
.{ .add_interrupt = .{
.device_name = "RP2350",
.idx = 46,
.name = "SPAREIRQ_IRQ_0",
} },
.{ .add_interrupt = .{
.device_name = "RP2350",
.idx = 47,
.name = "SPAREIRQ_IRQ_1",
.description = "Spare interrupt 1 (triggered only by software)",
} },
.{ .add_interrupt = .{
.device_name = "RP2350",
.idx = 48,
.name = "SPAREIRQ_IRQ_2",
.description = "Spare interrupt 2 (triggered only by software)",
} },
.{ .add_interrupt = .{
.device_name = "RP2350",
.idx = 49,
.name = "SPAREIRQ_IRQ_3",
.description = "Spare interrupt 3 (triggered only by software)",
} },
.{ .add_interrupt = .{
.device_name = "RP2350",
.idx = 50,
.name = "SPAREIRQ_IRQ_4",
.description = "Spare interrupt 4 (triggered only by software)",
} },
.{ .add_interrupt = .{
.device_name = "RP2350",
.idx = 51,
.name = "SPAREIRQ_IRQ_5",
.description = "Spare interrupt 5 (triggered only by software)",
} },
};
95 changes: 95 additions & 0 deletions port/raspberrypi/rp2xxx/patches/rp2350_riscv.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
pub const patches = &.{
.{ .override_arch = .{
.device_name = "RP2350",
.arch = .hazard3,
} },
.{ .add_enum = .{
.parent = "types.peripherals.USB_DPRAM",
.@"enum" = .{
.name = "EndpointType",
.bitsize = 2,
.fields = &.{
.{ .value = 0x0, .name = "control" },
.{ .value = 0x1, .name = "isochronous" },
.{ .value = 0x2, .name = "bulk" },
.{ .value = 0x3, .name = "interrupt" },
},
},
} },
.{ .set_enum_type = .{ .of = "types.peripherals.USB_DPRAM.EP1_IN_CONTROL.ENDPOINT_TYPE", .to = "types.peripherals.USB_DPRAM.EndpointType" } },
.{ .set_enum_type = .{ .of = "types.peripherals.USB_DPRAM.EP1_OUT_CONTROL.ENDPOINT_TYPE", .to = "types.peripherals.USB_DPRAM.EndpointType" } },
.{ .set_enum_type = .{ .of = "types.peripherals.USB_DPRAM.EP2_IN_CONTROL.ENDPOINT_TYPE", .to = "types.peripherals.USB_DPRAM.EndpointType" } },
.{ .set_enum_type = .{ .of = "types.peripherals.USB_DPRAM.EP2_OUT_CONTROL.ENDPOINT_TYPE", .to = "types.peripherals.USB_DPRAM.EndpointType" } },
.{ .set_enum_type = .{ .of = "types.peripherals.USB_DPRAM.EP3_IN_CONTROL.ENDPOINT_TYPE", .to = "types.peripherals.USB_DPRAM.EndpointType" } },
.{ .set_enum_type = .{ .of = "types.peripherals.USB_DPRAM.EP3_OUT_CONTROL.ENDPOINT_TYPE", .to = "types.peripherals.USB_DPRAM.EndpointType" } },
.{ .set_enum_type = .{ .of = "types.peripherals.USB_DPRAM.EP4_IN_CONTROL.ENDPOINT_TYPE", .to = "types.peripherals.USB_DPRAM.EndpointType" } },
.{ .set_enum_type = .{ .of = "types.peripherals.USB_DPRAM.EP4_OUT_CONTROL.ENDPOINT_TYPE", .to = "types.peripherals.USB_DPRAM.EndpointType" } },
.{ .set_enum_type = .{ .of = "types.peripherals.USB_DPRAM.EP5_IN_CONTROL.ENDPOINT_TYPE", .to = "types.peripherals.USB_DPRAM.EndpointType" } },
.{ .set_enum_type = .{ .of = "types.peripherals.USB_DPRAM.EP5_OUT_CONTROL.ENDPOINT_TYPE", .to = "types.peripherals.USB_DPRAM.EndpointType" } },
.{ .set_enum_type = .{ .of = "types.peripherals.USB_DPRAM.EP6_IN_CONTROL.ENDPOINT_TYPE", .to = "types.peripherals.USB_DPRAM.EndpointType" } },
.{ .set_enum_type = .{ .of = "types.peripherals.USB_DPRAM.EP6_OUT_CONTROL.ENDPOINT_TYPE", .to = "types.peripherals.USB_DPRAM.EndpointType" } },
.{ .set_enum_type = .{ .of = "types.peripherals.USB_DPRAM.EP7_IN_CONTROL.ENDPOINT_TYPE", .to = "types.peripherals.USB_DPRAM.EndpointType" } },
.{ .set_enum_type = .{ .of = "types.peripherals.USB_DPRAM.EP7_OUT_CONTROL.ENDPOINT_TYPE", .to = "types.peripherals.USB_DPRAM.EndpointType" } },
.{ .set_enum_type = .{ .of = "types.peripherals.USB_DPRAM.EP8_IN_CONTROL.ENDPOINT_TYPE", .to = "types.peripherals.USB_DPRAM.EndpointType" } },
.{ .set_enum_type = .{ .of = "types.peripherals.USB_DPRAM.EP8_OUT_CONTROL.ENDPOINT_TYPE", .to = "types.peripherals.USB_DPRAM.EndpointType" } },
.{ .set_enum_type = .{ .of = "types.peripherals.USB_DPRAM.EP9_IN_CONTROL.ENDPOINT_TYPE", .to = "types.peripherals.USB_DPRAM.EndpointType" } },
.{ .set_enum_type = .{ .of = "types.peripherals.USB_DPRAM.EP9_OUT_CONTROL.ENDPOINT_TYPE", .to = "types.peripherals.USB_DPRAM.EndpointType" } },
.{ .set_enum_type = .{ .of = "types.peripherals.USB_DPRAM.EP10_IN_CONTROL.ENDPOINT_TYPE", .to = "types.peripherals.USB_DPRAM.EndpointType" } },
.{ .set_enum_type = .{ .of = "types.peripherals.USB_DPRAM.EP10_OUT_CONTROL.ENDPOINT_TYPE", .to = "types.peripherals.USB_DPRAM.EndpointType" } },
.{ .set_enum_type = .{ .of = "types.peripherals.USB_DPRAM.EP11_IN_CONTROL.ENDPOINT_TYPE", .to = "types.peripherals.USB_DPRAM.EndpointType" } },
.{ .set_enum_type = .{ .of = "types.peripherals.USB_DPRAM.EP11_OUT_CONTROL.ENDPOINT_TYPE", .to = "types.peripherals.USB_DPRAM.EndpointType" } },
.{ .set_enum_type = .{ .of = "types.peripherals.USB_DPRAM.EP12_IN_CONTROL.ENDPOINT_TYPE", .to = "types.peripherals.USB_DPRAM.EndpointType" } },
.{ .set_enum_type = .{ .of = "types.peripherals.USB_DPRAM.EP12_OUT_CONTROL.ENDPOINT_TYPE", .to = "types.peripherals.USB_DPRAM.EndpointType" } },
.{ .set_enum_type = .{ .of = "types.peripherals.USB_DPRAM.EP13_IN_CONTROL.ENDPOINT_TYPE", .to = "types.peripherals.USB_DPRAM.EndpointType" } },
.{ .set_enum_type = .{ .of = "types.peripherals.USB_DPRAM.EP13_OUT_CONTROL.ENDPOINT_TYPE", .to = "types.peripherals.USB_DPRAM.EndpointType" } },
.{ .set_enum_type = .{ .of = "types.peripherals.USB_DPRAM.EP14_IN_CONTROL.ENDPOINT_TYPE", .to = "types.peripherals.USB_DPRAM.EndpointType" } },
.{ .set_enum_type = .{ .of = "types.peripherals.USB_DPRAM.EP14_OUT_CONTROL.ENDPOINT_TYPE", .to = "types.peripherals.USB_DPRAM.EndpointType" } },
.{ .set_enum_type = .{ .of = "types.peripherals.USB_DPRAM.EP15_IN_CONTROL.ENDPOINT_TYPE", .to = "types.peripherals.USB_DPRAM.EndpointType" } },
.{ .set_enum_type = .{ .of = "types.peripherals.USB_DPRAM.EP15_OUT_CONTROL.ENDPOINT_TYPE", .to = "types.peripherals.USB_DPRAM.EndpointType" } },
.{ .add_interrupt = .{
.device_name = "RP2350",
.idx = 40,
.name = "PROC0_IRQ_CTI",
} },
.{ .add_interrupt = .{
.device_name = "RP2350",
.idx = 41,
.name = "PROC1_IRQ_CTI",
} },
.{ .add_interrupt = .{
.device_name = "RP2350",
.idx = 46,
.name = "SPAREIRQ_IRQ_0",
.description = "Spare interrupt 0 (triggered only by software)",
} },
.{ .add_interrupt = .{
.device_name = "RP2350",
.idx = 47,
.name = "SPAREIRQ_IRQ_1",
.description = "Spare interrupt 1 (triggered only by software)",
} },
.{ .add_interrupt = .{
.device_name = "RP2350",
.idx = 48,
.name = "SPAREIRQ_IRQ_2",
.description = "Spare interrupt 2 (triggered only by software)",
} },
.{ .add_interrupt = .{
.device_name = "RP2350",
.idx = 49,
.name = "SPAREIRQ_IRQ_3",
.description = "Spare interrupt 3 (triggered only by software)",
} },
.{ .add_interrupt = .{
.device_name = "RP2350",
.idx = 50,
.name = "SPAREIRQ_IRQ_4",
.description = "Spare interrupt 4 (triggered only by software)",
} },
.{ .add_interrupt = .{
.device_name = "RP2350",
.idx = 51,
.name = "SPAREIRQ_IRQ_5",
.description = "Spare interrupt 5 (triggered only by software)",
} },
};
2 changes: 1 addition & 1 deletion port/raspberrypi/rp2xxx/rp2350_arm.ld
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ SECTIONS
*(.bss*)
microzig_bss_end = .;
} > ram0

.flash_end :
{
microzig_flash_end = .;
Expand Down
11 changes: 11 additions & 0 deletions tools/regz/src/Database.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2027,6 +2027,17 @@ pub fn apply_patch(db: *Database, ndjson: []const u8) !void {
try db.set_register_field_enum_id(register_id, field_name, enum_id);
try db.cleanup_unused_enums();
},
.add_interrupt => |add_interrupt| {
const device_id = try db.get_device_id_by_name(add_interrupt.device_name) orelse {
return error.DeviceNotFound;
};

_ = try db.create_interrupt(device_id, .{
.name = add_interrupt.name,
.description = add_interrupt.description,
.idx = add_interrupt.idx,
});
},
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions tools/regz/src/patch.zig
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ pub const Patch = union(enum) {
of: []const u8,
to: []const u8,
},
add_interrupt: struct {
device_name: []const u8,
idx: i32,
name: []const u8,
description: ?[]const u8 = null,
},

pub fn from_json_str(allocator: Allocator, json_str: []const u8) !std.json.Parsed(Patch) {
return std.json.parseFromSlice(Patch, allocator, json_str, .{});
Expand Down
9 changes: 5 additions & 4 deletions tools/regz/src/svd.zig
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,11 @@ fn arch_from_str(str: []const u8) Database.Arch {
pub fn load_peripheral(ctx: *Context, node: xml.Node, device_id: DeviceID) !void {
const db = ctx.db;

// load interrupts regardless of the fact that the peripheral is derived
var interrupt_it = node.iterate(&.{}, &.{"interrupt"});
while (interrupt_it.next()) |interrupt_node|
try load_interrupt(db, interrupt_node, device_id);

if (node.get_attribute("derivedFrom")) |derived_from| {
try ctx.derived_peripherals.put(ctx.arena.allocator(), node, derived_from);
return;
Expand Down Expand Up @@ -304,10 +309,6 @@ pub fn load_peripheral(ctx: *Context, node: xml.Node, device_id: DeviceID) !void
});
_ = instance_id;

var interrupt_it = node.iterate(&.{}, &.{"interrupt"});
while (interrupt_it.next()) |interrupt_node|
try load_interrupt(db, interrupt_node, device_id);

//if (node.get_value("version")) |version|
// try db.add_version(instance_id, version);

Expand Down

0 comments on commit 58365fd

Please sign in to comment.