@@ -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-
5019var _fast_blink : bool = false ;
5120/// Access underlying _sleep_time via volatile * to prevent reads from being optimized away
5221var 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
6835pub 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