Skip to content

Commit

Permalink
rename disable/enable interrupt functions (#126)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattnite committed Apr 26, 2023
1 parent 658648b commit d1f1374
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
12 changes: 6 additions & 6 deletions src/interrupt.zig
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ pub fn is_enabled(comptime interrupt: anytype) bool {

/// *Set Enable Interrupt*, will enable IRQs globally, but keep the masking done via
/// `enable` and `disable` intact.
pub fn sei() void {
micro.cpu.sei();
pub fn enable_interrupts() void {
micro.cpu.enable_interrupts();
}

/// *Clear Enable Interrupt*, will disable IRQs globally, but keep the masking done via
/// `enable` and `disable` intact.
pub fn cli() void {
micro.cpu.cli();
pub fn disable_interrupts() void {
micro.cpu.disable_interrupts();
}

/// Returns true, when interrupts are globally enabled via `sei()`.
Expand All @@ -43,7 +43,7 @@ pub fn enter_critical_section() CriticalSection {
var section = CriticalSection{
.enable_on_leave = globally_enabled(),
};
cli();
disable_interrupts();
return section;
}

Expand All @@ -55,7 +55,7 @@ const CriticalSection = struct {
/// Leaves the critical section and restores the interrupt state.
pub fn leave(self: @This()) void {
if (self.enable_on_leave) {
sei();
enable_interrupts();
}
}
};
Expand Down
3 changes: 1 addition & 2 deletions src/microzig.zig
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,8 @@ pub fn panic(message: []const u8, _: ?*std.builtin.StackTrace, _: ?usize) noretu

/// Hangs the processor and will stop doing anything useful. Use with caution!
pub fn hang() noreturn {
cpu.disable_interrupts();
while (true) {
interrupt.cli();

// "this loop has side effects, don't optimize the endless loop away please. thanks!"
asm volatile ("" ::: "memory");
}
Expand Down
4 changes: 2 additions & 2 deletions src/modules/cpus/cortex-m.zig
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ pub fn executing_isr() bool {
return regs.ICSR.read().VECTACTIVE != 0;
}

pub fn sei() void {
pub fn enable_interrupts() void {
asm volatile ("cpsie i");
}

pub fn cli() void {
pub fn disable_interrupts() void {
asm volatile ("cpsid i");
}

Expand Down
3 changes: 2 additions & 1 deletion test/cpu.zig
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub const startup_logic = struct {};

pub fn cli() void {}
pub fn enable_interrupts() void {}
pub fn disable_interrupts() void {}

0 comments on commit d1f1374

Please sign in to comment.