fix(rp2040) apply broken codegen workaround to both busy loop (#219)

wch-ch32v003
Vesim 2 months ago committed by GitHub
parent fca0bf2bff
commit 063ade2a3c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -20,27 +20,27 @@ const set_bits = @as(u32, 0x2) << 12;
const clear_bits = @as(u32, 0x3) << 12;
pub fn clear_alias_raw(ptr: anytype) *volatile u32 {
return @as(*volatile u32, @ptrFromInt(@intFromPtr(ptr) | clear_bits));
return @ptrFromInt(@intFromPtr(ptr) | clear_bits);
}
pub fn set_alias_raw(ptr: anytype) *volatile u32 {
return @as(*volatile u32, @ptrFromInt(@intFromPtr(ptr) | set_bits));
return @ptrFromInt(@intFromPtr(ptr) | set_bits);
}
pub fn xor_alias_raw(ptr: anytype) *volatile u32 {
return @as(*volatile u32, @ptrFromInt(@intFromPtr(ptr) | xor_bits));
return @ptrFromInt(@intFromPtr(ptr) | xor_bits);
}
pub fn clear_alias(ptr: anytype) @TypeOf(ptr) {
return @as(@TypeOf(ptr), @ptrFromInt(@intFromPtr(ptr) | clear_bits));
return @ptrFromInt(@intFromPtr(ptr) | clear_bits);
}
pub fn set_alias(ptr: anytype) @TypeOf(ptr) {
return @as(@TypeOf(ptr), @ptrFromInt(@intFromPtr(ptr) | set_bits));
return @ptrFromInt(@intFromPtr(ptr) | set_bits);
}
pub fn xor_alias(ptr: anytype) @TypeOf(ptr) {
return @as(@TypeOf(ptr), @ptrFromInt(@intFromPtr(ptr) | xor_bits));
return @ptrFromInt(@intFromPtr(ptr) | xor_bits);
}
pub inline fn tight_loop_contents() void {

@ -36,25 +36,32 @@ pub const Mask = packed struct(u32) {
};
pub fn reset(mask: Mask) void {
const raw_mask = @as(u32, @bitCast(mask));
const raw_mask: u32 = @bitCast(mask);
RESETS.RESET.raw = raw_mask;
RESETS.RESET.raw = 0;
RESETS.RESET.write_raw(raw_mask);
RESETS.RESET.write_raw(0);
while ((RESETS.RESET_DONE.raw & raw_mask) != raw_mask) {}
wait_for_reset_done(mask);
}
pub inline fn reset_block(mask: Mask) void {
hw.set_alias_raw(&RESETS.RESET).* = @as(u32, @bitCast(mask));
hw.set_alias(RESETS).RESET.write_raw(@bitCast(mask));
}
pub inline fn unreset_block(mask: Mask) void {
hw.clear_alias_raw(&RESETS.RESET).* = @as(u32, @bitCast(mask));
hw.clear_alias(RESETS).RESET.write_raw(@bitCast(mask));
}
pub fn unreset_block_wait(mask: Mask) void {
const raw_mask = @as(u32, @bitCast(mask));
hw.clear_alias_raw(&RESETS.RESET).* = raw_mask;
const raw_mask: u32 = @bitCast(mask);
hw.clear_alias(RESETS).RESET.write_raw(raw_mask);
wait_for_reset_done(mask);
}
inline fn wait_for_reset_done(mask: Mask) void {
const raw_mask: u32 = @bitCast(mask);
// have to bitcast after a read() instead of `RESETS.RESET_DONE.raw` due to
// some optimization bug. While loops will not be optimzed away if the

Loading…
Cancel
Save