Skip to content

Commit 6a2b4be

Browse files
committed
- Minor fixes to IRQ + example to utilize microzig.cpu interface
1 parent b07430e commit 6a2b4be

File tree

2 files changed

+4
-37
lines changed

2 files changed

+4
-37
lines changed

core/src/cpus/cortex_m.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ const cortex_m = std.meta.stringToEnum(Core, microzig.config.cpu_name) orelse
169169

170170
const core = blk: {
171171
break :blk switch (cortex_m) {
172-
.cortex_m0 => @import("cortex_m/m0"),
172+
.cortex_m0 => @import("cortex_m/m0.zig"),
173173
.cortex_m0plus => @import("cortex_m/m0plus.zig"),
174174
.cortex_m3 => @import("cortex_m/m3.zig"),
175175
.cortex_m33 => @import("cortex_m/m33.zig"),

examples/raspberrypi/rp2xxx/src/rp2040_only/rtc.zig

Lines changed: 3 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -16,37 +16,6 @@ pub const microzig_options = .{
1616
},
1717
};
1818

19-
/// Enables/disables interrupts to prevent data-races with variables
20-
/// shared between ISRs and normal code
21-
///
22-
/// TODO: microzig/core/src/interrupt.zig might provide a more general implementation
23-
/// for this in the future.
24-
const CriticalSection = struct {
25-
isr_reg_value: usize = 0,
26-
27-
pub fn enter(self: *CriticalSection) void {
28-
var val: usize = undefined;
29-
asm volatile (
30-
\\mrs %[val], primask
31-
\\movs r1, #1
32-
\\msr primask, r1
33-
: [val] "=r" (val),
34-
:
35-
: "r1", "cc"
36-
);
37-
self.isr_reg_value = val;
38-
}
39-
40-
pub fn exit(self: *CriticalSection) void {
41-
const val = self.isr_reg_value;
42-
asm volatile ("msr primask, %[val]"
43-
:
44-
: [val] "r" (val),
45-
);
46-
}
47-
};
48-
var critical_section: CriticalSection = .{};
49-
5019
var _fast_blink: bool = false;
5120
/// Access underlying _sleep_time via volatile * to prevent reads from being optimized away
5221
var fast_blink_vp: *volatile bool = &_fast_blink;
@@ -60,13 +29,11 @@ fn rtc_isr() callconv(.C) void {
6029
rp2xxx.rtc.alarm.enable();
6130

6231
// Every 1 minute, alternate between fast and slow blinking
63-
critical_section.enter();
6432
fast_blink_vp.* = !fast_blink_vp.*;
65-
critical_section.exit();
6633
}
6734

6835
pub fn main() !void {
69-
const pins = pin_config.apply();
36+
const pins = pin_config.pins();
7037

7138
// Configure initial datetime for RTC
7239
rp2xxx.rtc.set_datetime(.{
@@ -92,9 +59,9 @@ pub fn main() !void {
9259
while (true) {
9360

9461
// Disable interrupts during volatile read of fast_blink to prevent data races
95-
critical_section.enter();
62+
microzig.cpu.disable_interrupts();
9663
const fast_blink = fast_blink_vp.*;
97-
critical_section.exit();
64+
microzig.cpu.enable_interrupts();
9865

9966
pins.led.toggle();
10067
time.sleep_ms(if (fast_blink) 500 else 1000);

0 commit comments

Comments
 (0)