Skip to main content

Module interrupt

Module interrupt 

Source
Expand description

Interrupt control: the IME master switch and the IE / IF masks.

Two gates stand between the hardware and a handler. IME is the CPU’s master switch, flipped by enable and disable; IE picks which of the five sources may fire, and set_enabled writes it. Both must be open. The runtime enters main with IME off, so a program sees no interrupt until it opens them.

Handlers are not installed here: write one with #[gb::rt::interrupt], which binds it straight to a vector.

Turning interrupts on is unsafe throughout, since it introduces preemption that the surrounding code may have been written to rule out. With the critical-section-impl feature these functions are also the only sanctioned way to change IME, which the implementation mirrors in HRAM.

Structs§

CriticalSection
Critical section token.

Functions§

disable
Clear IME with di: interrupts stop being serviced.
enable
Set IME with ei, effective after the next instruction.
enable_and_halt
Sleep until an interrupt arrives, then service it.
enabled
Read IE: the interrupts that may fire.
free
Run f with interrupts disabled, handing it proof of that.
halt
Sleep until an interrupt arrives. Never returns if no enabled interrupt can fire.
pending
Read IF: the interrupts that have been requested.
set_enabled
Replace IE with mask.